FileDocCategorySizeDatePackage
CommandLineParserTest.javaAPI DocGlassfish v2 API9502Fri May 04 22:25:28 BST 2007com.sun.enterprise.cli.framework

CommandLineParserTest

public class CommandLineParserTest extends TestCase
Execute these tests using gmake (and Ant) by: cd gmake ANT_TARGETS=CommandLineParserTest

Fields Summary
ValidCommand
vc1
Constructors Summary
public CommandLineParserTest(String name)

        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        final TestRunner runner= new TestRunner();
        final TestResult result = runner.doRun(CommandLineParserTest.suite(), false);
        System.exit(result.errorCount() + result.failureCount());
    
private voidnyi()

        fail("Not Yet Implemented");
    
protected voidsetUp()

        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.Testsuite()

        TestSuite suite = new TestSuite(CommandLineParserTest.class);
        return suite;
    
protected voidtearDown()

    
public voidtestDefaultBooleanOptions()

        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 voidtestInsertOperands()

        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 voidtestLocalizedString()

        CommandLineParser clp = new CLP();
        assertEquals("Key not found (this key)", clp.getLocalizedString("this key", (Object []) null));
    
public voidtestLongBooleanOptions()

        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 voidtestNullCommand()

        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 voidtestOptionWithEqualsSign()

        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 voidtestShortBooleanOptions()

        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 voidtestShortOptionsGroup()

        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 voidtestShortOptionsWithEqual()

        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 voidtestSimpleConstruction()

        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 voidtestToString()

        CommandLineParser clp = new CLP();
        assertEquals("\n**********\nname = null\nOptions = \nOperands = []\n**********\n", clp.toString());