FileDocCategorySizeDatePackage
CommandTest.javaAPI DocGlassfish v2 API9995Fri May 04 22:25:30 BST 2007com.sun.enterprise.cli.framework

CommandTest

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

Fields Summary
Command
testCommand
Constructors Summary
public CommandTest(String name)

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

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

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


       
        testCommand = new Command() {
                public void runCommand()
                    throws CommandException, CommandValidationException
                {
                }
                public boolean validateOptions() throws CommandValidationException
                {
                    return true;
                }
            };
        testCommand.setName("sampleCommand");
    
public static junit.framework.Testsuite()

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

    
public voidtestBooleanOptions()

        assertTrue(!testCommand.getBooleanOption("bool"));
        testCommand.setOption("bool", "true");
        assertEquals("true", testCommand.getOption("bool"));
    
public voidtestConstructorAndAccessors()

        assertEquals("sampleCommand", testCommand.getName());
        assertTrue(testCommand.getOperands().isEmpty());
        assertTrue(testCommand.getOptions().isEmpty());
        assertEquals(null, testCommand.getUsageText());
        assertNull(testCommand.getProperties(""));
        assertEquals("Key not found", testCommand.getLocalizedString("fargle"));
        assertEquals("sampleCommand", testCommand.toString());
        
    
public voidtestGetDelimeterIndex()

        assertEquals(3, testCommand.getDelimeterIndex("0123", "3", 0));
    
public voidtestGetSetOptions()

        testCommand.setOption("key", "value");
        assertEquals("value", testCommand.getOption("key"));
        assertNull(testCommand.getOption("foo"));
        
    
public voidtestGetSetProperty()

        testCommand.setProperties(new Properties());
        assertEquals(null, testCommand.getProperty("prop"));
    
public voidtestGetSetProperty1()

        testCommand.setProperties(new Properties());
        testCommand.setProperty("prop", "value");
        assertEquals("value", testCommand.getProperty("prop"));
    
public voidtestGetSetProperty2()

        testCommand.setProperties(new Properties());
        testCommand.setProperty("prop", "value");
        assertEquals("value", testCommand.getProperty("prop"));
    
public voidtestLocalizedString()

        assertEquals("Key not found", testCommand.getLocalizedString("a", (Object []) null));
        assertEquals("Key not found", testCommand.getLocalizedString("InvalidCommand"));
    
public voidtestReplacePatternOperands()

        final String[] operands = new String[] {"abc=xyz", "$123", "#123", "", "//////", "abc:xyz=123:456$888=\"99:99\"", "foo-bar"};
        testCommand.setOperands(new Vector(Arrays.asList(operands)));
        assertEquals("first operand should be abc=xyz", "abc=xyz", testCommand.replacePattern("{#1}"));
        assertEquals("second operand should be $123", "$123", testCommand.replacePattern("{#2}"));
        assertEquals("third operand should be #123", "#123", testCommand.replacePattern("{#3}"));
        assertEquals("fourth operand should be empty", null, testCommand.replacePattern("{#4}"));
        assertEquals("fifth operand should be //////", "//////", testCommand.replacePattern("{#5}"));
        assertEquals("sixth operand should be abc:xyz=123:456$888=\"99:99\"", 
                     "abc:xyz=123:456$888=\"99:99\"", testCommand.replacePattern("{#6}"));
        assertEquals("seventh operand should be foo-bar", "foo-bar", testCommand.replacePattern("{#7}"));
        assertEquals("all operands should be",
                     "7=foo-bar," +
                     "6=abc:xyz=123:456$888=\"99:99\"," +
                     "5=//////,"+ 
                     "4=,"+
                     "3=#123,"+
                     "2=$123,"+
                     "1=abc=xyz", testCommand.replacePattern("7={#7},"+
                                                             "6={#6},"+
                                                             "5={#5},"+
                                                             "4={#4},"+
                                                             "3={#3},"+
                                                             "2={#2},"+
                                                             "1={#1}"));
    
public voidtestReplacePatternOptions()

        OptionsMap options = new OptionsMap();
        options.addOptionValue("user", "admin");
        options.addCLValue("password", "adminadmin");
        options.addEnvValue("host", "fuyako");
        options.addDefaultValue("port", "4848");
        options.addOptionValue("property", "--D:${abc.xyz}=123:\"456\":88:99$01");
        options.addCLValue("empty", "");
        options.addEnvValue("foo-bar", "foobar");
        testCommand.setOptionsMap(options);

        assertEquals("first option should be admin", "admin", testCommand.replacePattern("{$user}"));
        assertEquals("second option should be adminadmin", "adminadmin", testCommand.replacePattern("{$password}"));
        assertEquals("third option should be fuyako", "fuyako", testCommand.replacePattern("{$host}"));
        assertEquals("fourth option should be 4848", "4848", testCommand.replacePattern("{$port}"));
        assertEquals("fifth option should be --D:${abc.xyz}=123:\"456\":88:99$01", 
                     "--D:${abc.xyz}=123:\"456\":88:99$01", testCommand.replacePattern("{$property}"));
        assertEquals("sixth option should be empty", null, testCommand.replacePattern("{$empty}"));
        assertEquals("seventh option should be foobar", "foobar", testCommand.replacePattern("{$foo-bar}"));
        assertEquals("all options", "user=admin,password=adminadmin,host=fuyako,port=4848,"+
                     "property=--D:${abc.xyz}=123:\"456\":88:99$01,empty=,foo-bar=foobar",
                     testCommand.replacePattern("user={$user},password={$password},host={$host},"+
                                                "port={$port},property={$property},empty={$empty},foo-bar={$foo-bar}"));

    
public voidtestSetGetIntegerOptions()

        testCommand.setOption("number 1", "1");
        assertEquals(1, testCommand.getIntegerOption("number 1"));
    
public voidtestSetOptionsMap()

        OptionsMap om = new OptionsMap();
        om.addCLValue("bool", "true");
        om.addEnvValue("port", "1234");
        om.addDefaultValue("secure", "false");
        om.addOptionValue("foo", "bar");
        om.addCLValue("key", "value");
        testCommand.setOptionsMap(om);
        assertEquals("sampleCommand --foo bar --key value --secure=false --bool=true --port 1234", testCommand.toString());