1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.chain.impl;
17
18 import junit.framework.Test;
19 import junit.framework.TestCase;
20 import junit.framework.TestSuite;
21 import org.apache.commons.chain.Catalog;
22 import org.apache.commons.chain.CatalogFactory;
23 import org.apache.commons.chain.Command;
24 import org.apache.commons.chain.impl.CatalogBase;
25 import java.util.Iterator;
26
27 /***
28 * <p>Test case for the <code>CatalogFactoryBase</code> class.</p>
29 *
30 * @author Craig R. McClanahan
31 * @version $Revision: 1.3 $ $Date: 2004/12/09 05:23:14 $
32 */
33
34 public class CatalogFactoryBaseTestCase extends TestCase {
35
36
37
38
39
40 /***
41 * <p>The {@link CatalogFactory} instance under test.</p>
42 */
43 protected CatalogFactory factory = null;
44
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 CatalogFactoryBaseTestCase(String name) {
55 super(name);
56 }
57
58
59
60
61
62 /***
63 * <p>Set up instance variables required by this test case.</p>
64 */
65 public void setUp() {
66 factory = CatalogFactory.getInstance();
67 }
68
69
70 /***
71 * <p>Return the tests included in this test suite.</p>
72 */
73 public static Test suite() {
74 return (new TestSuite(CatalogFactoryBaseTestCase.class));
75 }
76
77 /***
78 * <p>Tear down instance variables required by this test case.</p>
79 */
80 public void tearDown() {
81 factory = null;
82 }
83
84
85
86
87
88 /***
89 * <p>Test a pristine instance of {@link CatalogFactory}.</p>
90 */
91 public void testPristine() {
92
93 assertNotNull(factory);
94 assertNull(factory.getCatalog());
95 assertNull(factory.getCatalog("foo"));
96 assertEquals(0, getCatalogCount());
97
98 }
99
100
101 /***
102 * <p>Test the default {@link Catalog} instance.</p>
103 */
104 public void testDefaultCatalog() {
105
106 Catalog catalog = new CatalogBase();
107 factory.setCatalog(catalog);
108 assertTrue(catalog == factory.getCatalog());
109 assertEquals(0, getCatalogCount());
110
111 }
112
113
114 /***
115 * <p>Test adding a specifically named {@link Catalog} instance.</p>
116 */
117 public void testSpecificCatalog() {
118
119 Catalog catalog = new CatalogBase();
120 factory.setCatalog(catalog);
121 catalog = new CatalogBase();
122 factory.addCatalog("foo", catalog);
123 assertTrue(catalog == factory.getCatalog("foo"));
124 assertEquals(1, getCatalogCount());
125 factory.addCatalog("foo", new CatalogBase());
126 assertEquals(1, getCatalogCount());
127 assertTrue(!(catalog == factory.getCatalog("foo")));
128 CatalogFactory.clear();
129 factory = CatalogFactory.getInstance();
130 assertEquals(0, getCatalogCount());
131
132 }
133
134
135
136
137
138 /***
139 * <p>Return the number of {@link Catalog}s defined in our
140 * {@link CatalogFactory}.</p>
141 */
142 private int getCatalogCount() {
143
144 Iterator names = factory.getNames();
145 assertNotNull(names);
146 int n = 0;
147 while (names.hasNext()) {
148 names.next();
149 n++;
150 }
151 return n;
152
153 }
154
155
156 }