1 16 package org.apache.commons.chain.impl; 17 18 19 import junit.framework.Test; 20 import junit.framework.TestCase; 21 import junit.framework.TestSuite; 22 import org.apache.commons.chain.Catalog; 23 import org.apache.commons.chain.Command; 24 25 import java.util.Iterator ; 26 27 28 34 35 public class CatalogBaseTestCase extends TestCase { 36 37 38 40 41 44 protected CatalogBase catalog = null; 45 46 47 49 54 public CatalogBaseTestCase(String name) { 55 super(name); 56 } 57 58 59 61 62 65 public void setUp() { 66 catalog = new CatalogBase(); 67 } 68 69 70 73 public static Test suite() { 74 return (new TestSuite(CatalogBaseTestCase.class)); 75 } 76 77 80 public void tearDown() { 81 catalog = null; 82 } 83 84 85 87 88 public void testAddCommand() { 90 addCommands(); 91 checkCommandCount(8); 92 } 93 94 95 public void testGetCommand() { 97 98 addCommands(); 99 Command command = null; 100 101 command = catalog.getCommand("AddingCommand"); 102 assertNotNull(command); 103 assertTrue(command instanceof AddingCommand); 104 105 command = catalog.getCommand("DelegatingCommand"); 106 assertNotNull(command); 107 assertTrue(command instanceof DelegatingCommand); 108 109 command = catalog.getCommand("DelegatingFilter"); 110 assertNotNull(command); 111 assertTrue(command instanceof DelegatingFilter); 112 113 command = catalog.getCommand("ExceptionCommand"); 114 assertNotNull(command); 115 assertTrue(command instanceof ExceptionCommand); 116 117 command = catalog.getCommand("ExceptionFilter"); 118 assertNotNull(command); 119 assertTrue(command instanceof ExceptionFilter); 120 121 command = catalog.getCommand("NonDelegatingCommand"); 122 assertNotNull(command); 123 assertTrue(command instanceof NonDelegatingCommand); 124 125 command = catalog.getCommand("NonDelegatingFilter"); 126 assertNotNull(command); 127 assertTrue(command instanceof NonDelegatingFilter); 128 129 command = catalog.getCommand("ChainBase"); 130 assertNotNull(command); 131 assertTrue(command instanceof ChainBase); 132 133 } 134 135 136 138 139 public void testPristine() { 141 checkCommandCount(0); 142 assertNull(catalog.getCommand("AddingCommand")); 143 assertNull(catalog.getCommand("DelegatingCommand")); 144 assertNull(catalog.getCommand("DelegatingFilter")); 145 assertNull(catalog.getCommand("ExceptionCommand")); 146 assertNull(catalog.getCommand("ExceptionFilter")); 147 assertNull(catalog.getCommand("NonDelegatingCommand")); 148 assertNull(catalog.getCommand("NonDelegatingFilter")); 149 assertNull(catalog.getCommand("ChainBase")); 150 } 151 152 153 154 155 157 158 protected void addCommands() { 160 catalog.addCommand("AddingCommand", new AddingCommand("", null)); 161 catalog.addCommand("DelegatingCommand", new DelegatingCommand("")); 162 catalog.addCommand("DelegatingFilter", new DelegatingFilter("", "")); 163 catalog.addCommand("ExceptionCommand", new ExceptionCommand("")); 164 catalog.addCommand("ExceptionFilter", new ExceptionFilter("", "")); 165 catalog.addCommand("NonDelegatingCommand", new NonDelegatingCommand("")); 166 catalog.addCommand("NonDelegatingFilter", new NonDelegatingFilter("", "")); 167 catalog.addCommand("ChainBase", new ChainBase()); 168 } 169 170 171 protected void checkCommandCount(int expected) { 173 int n = 0; 174 Iterator names = catalog.getNames(); 175 while (names.hasNext()) { 176 String name = (String ) names.next(); 177 n++; 178 assertNotNull(name + " exists", catalog.getCommand(name)); 179 } 180 assertEquals("Correct command count", expected, n); 181 } 182 183 184 } 185 | Popular Tags |