1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 /***
29 * <p>Test case for the <code>CatalogBase</code> class.</p>
30 *
31 * @author Craig R. McClanahan
32 * @version $Revision: 1.4 $ $Date: 2004/02/25 00:01:05 $
33 */
34
35 public class CatalogBaseTestCase extends TestCase {
36
37
38
39
40
41 /***
42 * The {@link Catalog} instance under test.
43 */
44 protected CatalogBase catalog = null;
45
46
47
48
49 /***
50 * Construct a new instance of this test case.
51 *
52 * @param name Name of the test case
53 */
54 public CatalogBaseTestCase(String name) {
55 super(name);
56 }
57
58
59
60
61
62 /***
63 * Set up instance variables required by this test case.
64 */
65 public void setUp() {
66 catalog = new CatalogBase();
67 }
68
69
70 /***
71 * Return the tests included in this test suite.
72 */
73 public static Test suite() {
74 return (new TestSuite(CatalogBaseTestCase.class));
75 }
76
77 /***
78 * Tear down instance variables required by this test case.
79 */
80 public void tearDown() {
81 catalog = null;
82 }
83
84
85
86
87
88
89 public void testAddCommand() {
90 addCommands();
91 checkCommandCount(8);
92 }
93
94
95
96 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
137
138
139
140 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
156
157
158
159 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
172 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 }