1 23 24 package com.sun.enterprise.cli.framework; 25 26 import java.util.HashMap ; 27 import java.util.Vector ; 28 import junit.framework.*; 29 34 35 public class CommandFactoryTest extends TestCase { 36 public void testInvalidClass(){ 37 final ValidCommand vc = new ValidCommand(); 38 vc.setName("vc"); 39 vc.setNumberOfOperands("three"); 40 vc.setUsageText("vc 1 2 3"); 41 vc.setClassName("foobar"); 42 try { 43 CommandFactory.createCommand(vc, new HashMap (), new Vector ()); 44 fail("Expected a CommandValidationException indicating that the class could not be found"); 45 } 46 catch (CommandValidationException cve){ 47 assertEquals("CLI002 Unable to create command object, vc.", cve.getMessage()); 48 assertEquals(ClassNotFoundException .class, cve.getCause().getClass()); 49 assertEquals("foobar", cve.getCause().getMessage()); } 50 } 51 52 public void testNullClass() { 53 final ValidCommand vc = new ValidCommand(); 54 vc.setName("vc"); 55 vc.setNumberOfOperands("three"); 56 vc.setUsageText("vc 1 2 3"); 57 try { 58 CommandFactory.createCommand(vc, new HashMap (), new Vector ()); 59 fail("Expected a CommandValidationException indicating that no classname was given"); 60 } 61 catch (CommandValidationException cve){ 62 assertEquals("CLI001 Invalid Command, vc.", cve.getMessage()); 63 } 64 } 65 66 public void testSimpleCommandCreation() throws Exception { 67 final ValidCommand vc = new ValidCommand(); 68 vc.setName("vc"); 69 vc.setNumberOfOperands("three"); 70 vc.setUsageText("vc 1 2 3"); 71 vc.setClassName("com.sun.enterprise.cli.framework.TestCommand"); 72 assertNotNull(vc.getClassName()); 73 final Command c = CommandFactory.createCommand(vc, new HashMap (), new Vector ()); 74 assertNotNull(c); 75 } 76 77 public void testNoArgsConstructor(){ 78 final CommandFactory c = new CommandFactory(); 79 } 80 81 public CommandFactoryTest(String name){ 82 super(name); 83 } 84 85 protected void setUp() { 86 } 87 88 protected void tearDown() { 89 } 90 91 private void nyi(){ 92 fail("Not Yet Implemented"); 93 } 94 95 public static void main(String args[]){ 96 if (args.length == 0){ 97 junit.textui.TestRunner.run(CommandFactoryTest.class); 98 } else { 99 junit.textui.TestRunner.run(makeSuite(args)); 100 } 101 } 102 private static TestSuite makeSuite(String args[]){ 103 final TestSuite ts = new TestSuite(); 104 for (int i = 0; i < args.length; i++){ 105 ts.addTest(new CommandFactoryTest(args[i])); 106 } 107 return ts; 108 } 109 } 110 111 class TestCommand extends Command 112 { 113 public void runCommand() throws com.sun.enterprise.cli.framework.CommandException, com.sun.enterprise.cli.framework.CommandValidationException{} 114 public boolean validateOptions() throws com.sun.enterprise.cli.framework.CommandValidationException{ 115 return true; 116 } 117 118 } 119 120 | Popular Tags |