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

CommandFactoryTest

public class CommandFactoryTest extends TestCase
author
Toby H Ferguson
version
$Revision: 1.7 $

Fields Summary
Constructors Summary
public CommandFactoryTest(String name)

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

        if (args.length == 0){
            junit.textui.TestRunner.run(CommandFactoryTest.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 CommandFactoryTest(args[i]));
        }
        return ts;
    
private voidnyi()

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

    
protected voidtearDown()

    
public voidtestInvalidClass()

        final ValidCommand vc = new ValidCommand();
        vc.setName("vc");
        vc.setNumberOfOperands("three");
        vc.setUsageText("vc 1 2 3");
        vc.setClassName("foobar");
        try {
            CommandFactory.createCommand(vc, new OptionsMap(), new Vector());
            fail("Expected a CommandValidationException indicating that the class could not be found");
        }
        catch (CommandValidationException cve){
            assertEquals("CLI002 Unable to create command object, vc.", cve.getMessage());
            assertEquals(ClassNotFoundException.class, cve.getCause().getClass());
            assertEquals("foobar", cve.getCause().getMessage());        }
    
public voidtestNoArgsConstructor()

        final CommandFactory c = new CommandFactory();
    
public voidtestNullClass()

        final ValidCommand vc = new ValidCommand();
        vc.setName("vc");
        vc.setNumberOfOperands("three");
        vc.setUsageText("vc 1 2 3");
        try {
            CommandFactory.createCommand(vc, new OptionsMap(), new Vector());
            fail("Expected a CommandValidationException indicating that no classname was given");
        }
        catch (CommandValidationException cve){
            assertEquals("CLI001 Invalid Command, vc.", cve.getMessage());
        }
    
public voidtestSimpleCommandCreation()

        final ValidCommand vc = new ValidCommand();
        vc.setName("vc");
        vc.setNumberOfOperands("three");
        vc.setUsageText("vc 1 2 3");
        vc.setClassName("com.sun.enterprise.cli.framework.TestCommand");
        assertNotNull(vc.getClassName());
        final Command c = CommandFactory.createCommand(vc, new OptionsMap(), new Vector());
        assertNotNull(c);