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