CommandLineParserTestpublic class CommandLineParserTest extends TestCase Execute these tests using gmake (and Ant) by:
cd
gmake ANT_TARGETS=CommandLineParserTest |
(Omit source code)
Fields Summary |
---|
ValidCommand | vc1 |
Constructors Summary |
---|
public CommandLineParserTest(String name)
super(name);
|
Methods Summary |
---|
public static void | main(java.lang.String[] args)
final TestRunner runner= new TestRunner();
final TestResult result = runner.doRun(CommandLineParserTest.suite(), false);
System.exit(result.errorCount() + result.failureCount());
| private void | nyi()
fail("Not Yet Implemented");
| protected void | setUp()
ValidOption vo1 = new ValidOption("user", "string", 1, "");
ValidOption vo2 = new ValidOption("password", "string", 1, "");
ValidOption vo3 = new ValidOption("host", "string", 1, "");
ValidOption vo4 = new ValidOption("port", "string", 1, "");
ValidOption vo5 = new ValidOption("interactive", "boolean", 3, "true");
vo5.setShortName("i");
ValidOption vo6 = new ValidOption("terse", "boolean", 3, "false");
vo6.setShortName("t");
ValidOption vo7 = new ValidOption("foo", "string", 1, "");
vo7.setShortName("f");
ValidOption[] validOptions = new ValidOption[] {vo3, vo4, vo6, vo7};
ValidOption[] requiredOptions = new ValidOption[] {vo1, vo2, vo5};
vc1 = new ValidCommand("sampleCommand",
"1",
new Vector(Arrays.asList(validOptions)),
new Vector(Arrays.asList(requiredOptions)),
new Vector(),
"sampleCommand");
| public static junit.framework.Test | suite()
TestSuite suite = new TestSuite(CommandLineParserTest.class);
return suite;
| protected void | tearDown()
| public void | testDefaultBooleanOptions()
String [] args = {"samplecommand", "--user", "admin", "--password", "adminadmin"};
CommandLineParser clp = new CLP(args, vc1);
Map options = clp.getOptionsList();
assertEquals("terse option is by default is false", "false", (String)options.get("terse"));
assertEquals("interactive option is by default is true", "true", (String)options.get("interactive"));
| public void | testInsertOperands()
String [] args = {"samplecommand", "--user", "admin", "--password", "adminadmin", "-t=false", "operand"};
CommandLineParser clp = new CLP(args, vc1);
Map options = clp.getOptionsList();
assertTrue(clp.getOperands().contains("operand"));
| public void | testLocalizedString()
CommandLineParser clp = new CLP();
assertEquals("Key not found (this key)", clp.getLocalizedString("this key", (Object []) null));
| public void | testLongBooleanOptions()
String [] args = {"samplecommand", "--user", "admin", "--password", "adminadmin", "--interactive", "--terse"};
CommandLineParser clp = new CLP(args, vc1);
Map options = clp.getOptionsList();
assertEquals("long option for terse if true", "true", (String)options.get("terse"));
assertEquals("long option for interactive is true", "true", (String)options.get("interactive"));
| public void | testNullCommand()
CommandLineParser clp = new CLP(vc1);
String [] args = {"samplecommand", "--user", "admin", "--password", "adminadmin"};
clp.parseCommandLine(args);
Map options = clp.getOptionsList();
assertEquals("terse option is by default is false", "false", (String)options.get("terse"));
assertEquals("interactive option is by default is true", "true", (String)options.get("interactive"));
assertTrue(clp.getOperands().isEmpty());
| public void | testOptionWithEqualsSign()
String [] args = {"samplecommand", "--user", "admin", "--password", "adminadmin", "--terse=false"};
CommandLineParser clp = new CLP(args, vc1);
Map options = clp.getOptionsList();
assertEquals("short option for terse if true", "false", (String)options.get("terse"));
| public void | testShortBooleanOptions()
String [] args = {"samplecommand", "--user", "admin", "--password", "adminadmin", "-i", "-t"};
CommandLineParser clp = new CLP(args, vc1);
Map options = clp.getOptionsList();
assertEquals("short option for terse if true", "true", (String)options.get("terse"));
assertEquals("short option for interactive is true", "true", (String)options.get("interactive"));
| public void | testShortOptionsGroup()
String [] args = {"samplecommand", "--user", "admin", "--password", "adminadmin", "-ti"};
CommandLineParser clp = new CLP(args, vc1);
Map options = clp.getOptionsList();
assertEquals("short option for terse if true", "true", (String)options.get("terse"));
assertEquals("short option for interactive is true", "true", (String)options.get("interactive"));
| public void | testShortOptionsWithEqual()
String [] args = {"samplecommand", "--user", "admin", "-f=oo.bar.com", "--password", "adminadmin", "--terse=false"};
CommandLineParser clp = new CLP(args, vc1);
Map options = clp.getOptionsList();
assertEquals("short option for terse if false", "false", (String)options.get("terse"));
assertEquals("short option for f", "oo.bar.com", (String)options.get("foo"));
| public void | testSimpleConstruction()
CommandLineParser clp = new CLP();
String [] args = {"samplecommand", "--user", "admin", "--password", "adminadmin"};
try {
clp.parseCommandLine(args);
fail("Expected to get a CommandValidationException saying that there was no command");
}
catch (CommandValidationException cve){
assertEquals("CLI001 Invalid Command, samplecommand.", cve.getMessage());
}
| public void | testToString()
CommandLineParser clp = new CLP();
assertEquals("\n**********\nname = null\nOptions = \nOperands = []\n**********\n", clp.toString());
|
|