1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.services.registry;
18
19 import java.util.Iterator;
20
21
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24
25
26 import org.apache.jetspeed.test.JetspeedTestCase;
27 import org.apache.jetspeed.om.registry.*;
28
29 import org.apache.turbine.util.TurbineConfig;
30 import org.apache.turbine.util.StringUtils;
31
32 import org.apache.jetspeed.services.Registry;
33 import org.apache.jetspeed.om.registry.base.CategoryIterator;
34
35 /***
36 * TestRegistryCategories
37 *
38 * @author <a href="taylor@apache.org">David Sean Taylor</a>
39 * @version $Id: TestRegistryCategories.java,v 1.1 2004/04/07 22:02:42 jford Exp $
40 */
41
42 public class TestRegistryCategories extends JetspeedTestCase {
43
44 /***
45 * Defines the testcase name for JUnit.
46 *
47 * @param name the testcase's name.
48 */
49 public TestRegistryCategories( String name ) {
50 super( name );
51 }
52
53 /***
54 * Start the tests.
55 *
56 * @param args the arguments. Not used
57 */
58 public static void main(String args[]) {
59 junit.awtui.TestRunner.main( new String[] { TestRegistryCategories.class.getName() } );
60 }
61
62 public void setup() {
63 System.out.println("Setup: Testing categories of Registry");
64 }
65 /***
66 * Creates the test suite.
67 *
68 * @return a test suite (<code>TestSuite</code>) that includes all methods
69 * starting with "test"
70 */
71 public static Test suite() {
72
73 return new TestSuite( TestRegistryCategories.class );
74 }
75
76 /***
77 * Tests categories
78 * @throws Exception
79 */
80 public void testCategories() throws Exception
81 {
82 try
83 {
84 PortletRegistry registry = (PortletRegistry)Registry.get(Registry.PORTLET);
85
86 PortletEntry pe = (PortletEntry)registry.getEntry("RSS");
87 assertNotNull(pe);
88
89 Iterator iterator = registry.findPortletsByCategory("rss");
90 int count = 0;
91 init();
92 PortletEntry rss;
93 while (iterator.hasNext())
94 {
95 rss = (PortletEntry)iterator.next();
96 print(iterator, rss);
97 count++;
98 }
99 System.out.println("[RSS] count = " + count);
100 System.out.println("------------------");
101 assertEquals( "RSS Count", 10, count);
102
103
104 registry.removeEntry(pe);
105 iterator = registry.findPortletsByCategory("rss");
106 assertTrue(iterator.hasNext());
107
108
109
110
111
112 registry.addEntry(pe);
113 iterator = registry.findPortletsByCategory("rss");
114 assertTrue(iterator.hasNext());
115 rss = (PortletEntry)iterator.next();
116 Iterator cats = rss.listCategories();
117 assertNotNull(cats);
118 assertTrue(cats.hasNext());
119 Category cat = (Category)cats.next();
120 assertTrue(cat.getName().startsWith("rss") || cat.getName().startsWith("news"));
121
122
123 iterator = registry.listByCategory();
124 count = 0;
125 init();
126 while (iterator.hasNext())
127 {
128 PortletEntry entry = (PortletEntry)iterator.next();
129
130 count++;
131 }
132 System.out.println("[Everything] count = " + count);
133 System.out.println("------------------");
134
135 iterator = registry.findPortletsByCategory("General");
136 count = 0;
137 init();
138 while (iterator.hasNext())
139 {
140 PortletEntry entry = (PortletEntry)iterator.next();
141
142 count++;
143 }
144 System.out.println("[General] count = " + count);
145 System.out.println("------------------");
146
147 iterator = registry.findPortletsByGroupCategory("base", "news.xml.rss");
148 count = 0;
149 init();
150 while (iterator.hasNext())
151 {
152 PortletEntry entry = (PortletEntry)iterator.next();
153
154 count++;
155 }
156 System.out.println("[base][xml.rss] count = " + count);
157 System.out.println("------------------");
158
159 iterator = registry.findPortletsByCategory("");
160 count = 0;
161 init();
162 while (iterator.hasNext())
163 {
164 PortletEntry entry = (PortletEntry)iterator.next();
165
166 count++;
167 }
168 System.out.println("[] count = " + count);
169 System.out.println("------------------");
170
171 iterator = registry.findPortletsByGroupCategory("", "");
172 count = 0;
173 init();
174 while (iterator.hasNext())
175 {
176 PortletEntry entry = (PortletEntry)iterator.next();
177
178 count++;
179 }
180 System.out.println("[][] count = " + count);
181 System.out.println("------------------");
182
183 iterator = registry.findPortletsByGroupCategory("Jetspeed", "");
184 count = 0;
185 init();
186 while (iterator.hasNext())
187 {
188 PortletEntry entry = (PortletEntry)iterator.next();
189
190 count++;
191 }
192 System.out.println("[Jetspeed][] count = " + count);
193 System.out.println("------------------");
194
195 iterator = registry.findPortletsByCategory("news");
196 count = 0;
197 init();
198 while (iterator.hasNext())
199 {
200 PortletEntry entry = (PortletEntry)iterator.next();
201
202 count++;
203 }
204 System.out.println("[news] count = " + count);
205 System.out.println("------------------");
206
207
208
209
210 }
211 catch (Exception e)
212 {
213 String errmsg = "Error in category test: " + e.toString();
214
215 assertNotNull(errmsg, null);
216 }
217 }
218
219 private String lastGroup = "";
220 private String lastCategory = "";
221
222 private void init()
223 {
224 lastGroup = "";
225 lastCategory = "";
226 }
227
228 private void print(Iterator iterator, PortletEntry entry)
229 {
230 String group = ((CategoryIterator)iterator).getGroup();
231 String category = ((CategoryIterator)iterator).getCategory();
232 if (!lastGroup.equals(group))
233 {
234 System.out.println("Group: [" + group + "]");
235 lastGroup = group;
236 }
237 if (!lastCategory.equals(category))
238 {
239 System.out.println("....Cat: [" + category + "]");
240 lastCategory = category;
241 }
242 System.out.println("........" + entry.getName());
243 }
244
245 /***
246 * Tests IdentityElement unmarshaling entryset base stuff
247 * @throws Exception
248 */
249
250
251
252
253
254
255 private static TurbineConfig config = null;
256
257
258
259
260
261 static
262 {
263 try
264 {
265 config = new TurbineConfig( "webapp", "/WEB-INF/conf/TurbineResources.properties");
266 config.init();
267 }
268 catch (Exception e)
269 {
270 fail(StringUtils.stackTrace(e));
271 }
272 }
273 }