Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to testNG, improve error handling, change package structure an…
…d group id
- Loading branch information
Showing
10 changed files
with
157 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ tomcat.8080 | |
.project | ||
.settings/ | ||
tomcat.*/ | ||
test-output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...oku/launch/ArgumentNotFoundException.java → ...ner/launch/ArgumentNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package tomcat.runner.launch; | ||
|
||
public class MissingAppException extends Exception { | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/test/tomcat/runner/launch/ArgParserNegativeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package tomcat.runner.launch; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import tomcat.runner.launch.ArgParser; | ||
import tomcat.runner.launch.Argument; | ||
import tomcat.runner.launch.ArgumentNotFoundException; | ||
import tomcat.runner.launch.MissingAppException; | ||
|
||
public class ArgParserNegativeTest { | ||
|
||
@DataProvider(name = "Negative-Test-Provider") | ||
public Object[][] parameterIntTestProvider() { | ||
return new Object[][]{ | ||
{ new String[] {"--fake-arg", "45", "/path/to/project"}, ArgumentNotFoundException.class }, | ||
{ new String[] {Argument.SESSION_TIMEOUT.argName(), "45", "--fake-arg", "test", "/path/to/project"}, ArgumentNotFoundException.class }, | ||
{ new String[] {Argument.SESSION_TIMEOUT.argName(), "45", "--fake-arg", "/path/to/project"}, ArgumentNotFoundException.class }, | ||
{ new String[] {Argument.SESSION_TIMEOUT.argName(), "45", "test", "/path/to/project"}, ArgumentNotFoundException.class }, | ||
{ new String[] {Argument.SESSION_TIMEOUT.argName(), "--fake-arg", "test", "/path/to/project"}, ArgumentNotFoundException.class }, | ||
{ new String[] {"/path/to/project", Argument.SESSION_TIMEOUT.argName()}, ArgumentNotFoundException.class }, | ||
{ new String[] {Argument.SESSION_TIMEOUT.argName(), "--fake-arg", "45", "test", "/path/to/project"}, ArgumentNotFoundException.class }, | ||
{ new String[] {Argument.SESSION_TIMEOUT.argName(), "45", Argument.PORT.argName(), "9090"}, MissingAppException.class }, | ||
{ new String[] {Argument.SESSION_TIMEOUT.argName(), "45", Argument.PORT.argName()}, MissingAppException.class } | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "Negative-Test-Provider") | ||
public void testFakeArgument(String[] args, Class<Exception> excpectedException) { | ||
try { | ||
ArgParser.parseArgs(args); | ||
Assert.fail("Parsing of arguments should have thrown exception"); | ||
} catch (Exception e) { | ||
Assert.assertTrue(e.getClass().isAssignableFrom(excpectedException), "Wrong exception thrown for negative test"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package tomcat.runner.launch; | ||
|
||
import java.util.Map; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import tomcat.runner.launch.ArgParser; | ||
import tomcat.runner.launch.Argument; | ||
import tomcat.runner.launch.ArgumentNotFoundException; | ||
import tomcat.runner.launch.MissingAppException; | ||
|
||
|
||
public class ArgParserTest { | ||
|
||
@Test | ||
public void testArgumentParsingWithArg() throws ArgumentNotFoundException, MissingAppException { | ||
String[] args = {Argument.SESSION_TIMEOUT.argName(), "45", Argument.PORT.argName(), "8888", "/path/to/project"}; | ||
Map<Argument, String> argMap = ArgParser.parseArgs(args); | ||
|
||
Assert.assertEquals(argMap.get(Argument.SESSION_TIMEOUT), "45", "Expected session timeout to match that which was set"); | ||
Assert.assertEquals(argMap.get(Argument.PORT), "8888", "Expected port to match that which was set"); | ||
Assert.assertEquals(argMap.get(Argument.APPLICATION_DIR), "/path/to/project", "Expected directory to math that which was set"); | ||
} | ||
|
||
@Test | ||
public void testArgumentParsingNoArg() throws ArgumentNotFoundException, MissingAppException { | ||
String[] args = {"/path/to/project"}; | ||
Map<Argument, String> argMap = ArgParser.parseArgs(args); | ||
|
||
Assert.assertEquals(argMap.get(Argument.APPLICATION_DIR), "/path/to/project", "Expected directory to math that which was set"); | ||
} | ||
|
||
} |