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

ValidCommandTest

public class ValidCommandTest extends TestCase
author
Toby H Ferguson
version
$Revision: 1.5 $

Fields Summary
Constructors Summary
public ValidCommandTest(String name)

        super(name);
    
Methods Summary
public static voidassertFalse(boolean v)

         assertTrue(!v);
    
public static voidmain(java.lang.String[] args)

        if (args.length == 0){
            junit.textui.TestRunner.run(ValidCommandTest.class);
        } else {
            junit.textui.TestRunner.run(makeSuite(args));
        }
    
private static junit.framework.TestSuitemakeSuite(java.lang.String[] args)

        final TestSuite ts = new TestSuite();
        for (int i = 0; i < args.length; i++){
            ts.addTest(new ValidCommandTest(args[i]));
        }
        return ts;
    
private voidnyi()

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

    
protected voidtearDown()

    
public voidtestAddNullRequiredOption()

        final ValidCommand vc = new ValidCommand();
        vc.addRequiredOption(null);
        assertEquals(0, vc.getRequiredOptions().size());
    
public voidtestAddNullValidOption()

        final ValidCommand vc = new ValidCommand();
        vc.addValidOption(null);
        assertEquals(0, vc.getValidOptions().size());
    
public voidtestAddRequiredOption()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        vc.addRequiredOption(vo);
        assertTrue(vc.getRequiredOptions().contains(vo));
        assertEquals(1, vc.getRequiredOptions().size());
        assertTrue(vc.getValidOptions().isEmpty());
    
public voidtestAddRequiredOptionTwice()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        vc.addRequiredOption(vo);
        vc.addRequiredOption(vo);
        assertTrue(vc.getRequiredOptions().contains(vo));
        assertEquals(1, vc.getRequiredOptions().size());
        assertTrue(vc.getValidOptions().isEmpty());
    
public voidtestAddSimpleValidOption()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption();
        vc.addValidOption(vo);
        assertTrue(vc.getValidOptions().contains(vo));
        assertEquals(1, vc.getValidOptions().size());
        assertTrue(vc.getRequiredOptions().isEmpty());
    
public voidtestAddValidOptionTwice()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        vc.addValidOption(vo);
        vc.addValidOption(vo);
        assertTrue(vc.getValidOptions().contains(vo));
        assertEquals(1, vc.getValidOptions().size());
        assertTrue(vc.getRequiredOptions().isEmpty());
    
public voidtestAddValidOptionWithNamedOption()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        vc.addValidOption(vo);
        assertTrue(vc.getValidOptions().contains(vo));
        assertEquals(1, vc.getValidOptions().size());
        assertTrue(vc.getRequiredOptions().isEmpty());
    
public voidtestBasicConstruction()

        final ValidCommand vc = new ValidCommand();
        assertNotNull(vc.getValidOptions());
        assertTrue(vc.getValidOptions().isEmpty());
        assertNotNull(vc.getRequiredOptions());
        assertTrue(vc.getRequiredOptions().isEmpty());
        assertNotNull(vc.getProperties());
        assertTrue(vc.getProperties().isEmpty());
    
public voidtestCantDeleteRequiredOption()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        vc.addValidOption(vo);
        vc.addRequiredOption(vo);
        assertTrue(vc.getValidOptions().contains(vo));
        assertTrue(vc.getRequiredOptions().contains(vo));
        vc.deleteOption(vo);
        assertTrue(vc.getValidOptions().isEmpty());
        assertTrue(vc.getRequiredOptions().contains(vo));
    
public voidtestComplexConstruction()

        final Vector vo = new Vector();
        final Vector ro = new Vector();
        final Vector dos = new Vector();
		
        final ValidCommand vc = new ValidCommand("name", "number of ops", vo, ro, dos, "usage");
        assertEquals("name", vc.getName());
        assertEquals("number of ops", vc.getNumberOfOperands());
        assertEquals(vo, vc.getValidOptions());
        assertEquals(ro, vc.getRequiredOptions());
        assertEquals("usage", vc.getUsageText());
    
public voidtestDeleteNullOption()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        vc.addValidOption(vo);
        assertTrue(vc.getValidOptions().contains(vo));
        vc.deleteOption(null);
        assertTrue(vc.getValidOptions().contains(vo));
    
public voidtestDeleteOption()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        vc.addValidOption(vo);
        assertTrue(vc.getValidOptions().contains(vo));
        vc.deleteOption(vo);
        assertTrue(vc.getValidOptions().isEmpty());
    
public voidtestGetNonExistentOption()

        final ValidCommand vc = new ValidCommand();
        final Vector v = new Vector();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        v.add(vo);
        vc.setValidOptions(v);
        assertNull(vc.getOption("Name"));
    
public voidtestGetOptionFromEmptySet()

        final ValidCommand vc = new ValidCommand();
        final Vector v = new Vector();
        assertNull(vc.getOption("anything"));
    
public voidtestGetOptionsContainsOptions()

        final ValidCommand vc = new ValidCommand();
        final Vector v = new Vector();
        final ValidOption vo = new ValidOption();
        v.add(vo);
        vc.setValidOptions(v);
        final Vector r = new Vector();
        final ValidOption ro = new ValidOption();
        r.add(ro);
        vc.setRequiredOptions(r);
        assertTrue(vc.getOptions().contains(vo));
        assertTrue(vc.getOptions().contains(ro));
        assertEquals(2, vc.getOptions().size());
    
public voidtestGetOptionsIsEmpty()

        final ValidCommand vc = new ValidCommand();
        final Vector v = new Vector();
        final Vector r = new Vector();
        vc.setValidOptions(v);
        vc.setRequiredOptions(r);
        assertTrue(vc.getOptions().isEmpty());
    
public voidtestGetOptionsSameVector()

        final ValidCommand vc = new ValidCommand();
        final Vector v = new Vector();
        vc.setValidOptions(v);
        vc.setRequiredOptions(v);
        assertTrue(vc.getOptions().isEmpty());
    
public voidtestHasProperty()

        final ValidCommand vc = new ValidCommand();
        vc.setProperty("key", "name");
        assertTrue(vc.hasProperty("key"));
        assertFalse(vc.hasProperty("name"));
    
public voidtestHasRequiredObject()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        final ValidOption ro = new ValidOption("req", "type", 0, "default");
        vc.addValidOption(vo);
        vc.addRequiredOption(ro);
        assertTrue(vc.hasRequiredOption(ro));
        assertFalse(vc.hasRequiredOption(vo));
    
public voidtestHasRequiredObjectByName()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        final ValidOption ro = new ValidOption("req", "type", 0, "default");
        vc.addValidOption(vo);
        vc.addRequiredOption(ro);
        vc.addRequiredOption(new ValidOption("np", "t", 0, "d"));
        assertTrue(vc.hasRequiredOption("req"));
        assertFalse(vc.hasRequiredOption("name"));
    
public voidtestHasValidObject()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        vc.addValidOption(vo);
        assertTrue(vc.hasValidOption(vo));
        assertFalse(vc.hasValidOption(new ValidOption()));
        assertFalse(vc.hasValidOption((ValidOption) null));
    
public voidtestHasValidObjectByName()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        vc.addValidOption(vo);
        vc.addValidOption(new ValidOption("np", "far", 0, "default"));
        assertTrue(vc.hasValidOption("name"));
        assertFalse(vc.hasValidOption("foo"));
        assertFalse(vc.hasValidOption((String) null));
    
public voidtestHasValidObjectByNameNoOptions()

        final ValidCommand vc = new ValidCommand();
        assertFalse(vc.hasValidOption("name"));
    
public voidtestHasValidObjectNullName()

        final ValidCommand vc = new ValidCommand();
        final ValidOption vo = new ValidOption();
        vc.addValidOption(vo);
        assertFalse(vc.hasValidOption((String) null));
    
public voidtestMutatorsAndAccessors()

        final ValidCommand vc = new ValidCommand();
        final String name = "name";
        vc.setName(name);
        assertEquals(name, vc.getName());
        final String nops = "nops";
        vc.setNumberOfOperands(nops);
        assertEquals(nops, vc.getNumberOfOperands());
        final Vector vo = new Vector();
        vc.setValidOptions(vo);
        assertEquals(vo, vc.getValidOptions());
        final Vector ro = new Vector();
        vc.setRequiredOptions(ro);
        assertEquals(ro, vc.getRequiredOptions());
        final String clazz = "class";
        vc.setClassName(clazz);
        assertEquals(clazz, vc.getClassName());
        final String use = "use";
        vc.setUsageText(use);
        assertEquals(use, vc.getUsageText());
        vc.setProperty("key", "value");
        assertEquals("value", vc.getProperty("key"));
    
public voidtestReplaceAllOptionsWithDeprecatedOption()

        final ValidCommand vc = new ValidCommand();
        vc.addValidOption(new ValidOption("option1", "string", 1, "default"));
        vc.addValidOption(new ValidOption("option2", "boolean", 0, "true"));
        vc.addRequiredOption(new ValidOption("option3", "string", 1, "default"));
        vc.addRequiredOption(new ValidOption("option4", "string", 1, "4848"));
        vc.addDeprecatedOption(new ValidOption("option5", "string", 1, "admin"));
        vc.addDeprecatedOption(new ValidOption("option6", "string", 1, "test"));

        ValidOption ro = new ValidOption("option5", "boolean", 2, "true");
        vc.replaceAllOptions(ro);
        Vector vtr = vc.getDeprecatedOptions();
        ValidOption vo = (ValidOption)vtr.get(0);
        assertEquals("boolean", vo.getType());
        assertEquals(2, vo.isValueRequired());
        assertEquals("true", vo.getDefaultValue());
    
public voidtestReplaceAllOptionsWithRquiredOption()

        final ValidCommand vc = new ValidCommand();
        vc.addValidOption(new ValidOption("option1", "string", 1, "default"));
        vc.addValidOption(new ValidOption("option2", "boolean", 0, "true"));
        vc.addRequiredOption(new ValidOption("option3", "string", 1, "default"));
        vc.addRequiredOption(new ValidOption("option4", "string", 1, "4848"));
        ValidOption ro = new ValidOption("option4", "string", 0, "4949");
        vc.replaceAllOptions(ro);
        Vector vtr = vc.getRequiredOptions();
        ValidOption vo = (ValidOption)vtr.get(1);
        assertEquals("4949", vo.getDefaultValue());
    
public voidtestReplaceAllOptionsWithValidOption()

        final ValidCommand vc = new ValidCommand();
        vc.addValidOption(new ValidOption("option1", "string", 1, "default"));
        vc.addValidOption(new ValidOption("option2", "boolean", 0, "true"));
        vc.addRequiredOption(new ValidOption("option3", "string", 1, "default"));
        vc.addRequiredOption(new ValidOption("option4", "string", 1, "4848"));
        ValidOption ro = new ValidOption("option2", "boolean", 0, "false");
        vc.replaceAllOptions(ro);
        Vector vtr = vc.getValidOptions();
        ValidOption vo = (ValidOption)vtr.get(1);
        assertEquals("false", vo.getDefaultValue());
    
public voidtestToString()

        final ValidCommand vc = new ValidCommand();
        assertEquals("null null | {} | } |  | } | null {}", vc.toString());
    
public voidtestToStringNonEmpty()

        final ValidCommand vc = new ValidCommand();
        vc.addValidOption(new ValidOption("vo", "type", 0, "default"));
        vc.addRequiredOption(new ValidOption("ro", "type", 0, "default"));
//         vc.setProperty("key", "value");
        assertEquals("null null | {vo type  default,} | ro type  default,} |  | } | null {}", vc.toString());        
    
public voidtestValidOptionsFromMany()

        final ValidCommand vc = new ValidCommand();
        final Vector v = new Vector();
        final ValidOption vo = new ValidOption("name", "type", 0, "default");
        v.add(vo);
        v.add(new ValidOption("foo", "far", 1, "default"));
        vc.setValidOptions(v);
        assertEquals(vo, vc.getOption("name"));
    
public voidtestValidOptionsNullCase()

        final ValidCommand vc = new ValidCommand();
        final Vector v = new Vector();
        final ValidOption vo = new ValidOption();
        v.add(vo);
        vc.setValidOptions(v);
        assertEquals(null, vc.getOption((String)null));
    
public voidtestValidOptionsWithAString()

        final ValidCommand vc = new ValidCommand();
        final Vector v = new Vector();
        final ValidOption vo = new ValidOption("opt1", "string", 1, "opt1");
        v.add(vo);
        vc.setValidOptions(v);
        assertEquals(vo, vc.getOption("opt1"));