Source Code Cross Referenced for TestSite.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » engine » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » rife 1.6.1 » com.uwyn.rife.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: TestSite.java 3634 2007-01-08 21:42:24Z gbevin $
007:         */
008:        package com.uwyn.rife.engine;
009:
010:        import com.uwyn.rife.engine.exceptions.DuplicateElementIdException;
011:        import com.uwyn.rife.engine.exceptions.EngineException;
012:        import com.uwyn.rife.engine.exceptions.UrlExistsException;
013:        import com.uwyn.rife.tools.ExceptionUtils;
014:        import junit.framework.TestCase;
015:
016:        public class TestSite extends TestCase {
017:            public TestSite(String name) {
018:                super (name);
019:            }
020:
021:            public void testInstantiation() {
022:                Site site = null;
023:
024:                site = new Site();
025:
026:                assertNotNull(site);
027:            }
028:
029:            public void testNoInitialUrls() {
030:                Site site = new Site();
031:
032:                assertEquals(site.getUrls().size(), 0);
033:            }
034:
035:            public void testAddElement() throws EngineException {
036:                Site site = new Site();
037:                ElementInfo element_info1 = null;
038:                ElementInfo element_info2 = null;
039:                try {
040:                    element_info1 = new ElementInfo("element/test1.xml",
041:                            "text/html", TestElement1.class.getName(),
042:                            ElementType.JAVA_CLASS);
043:                    site
044:                            .addElementInfo(".ELEMENT1", element_info1,
045:                                    "/element1");
046:                    assertEquals(site.getUrls().size(), 1);
047:                    element_info2 = new ElementInfo("element/test2.xml",
048:                            "text/html", TestElement1.class.getName(),
049:                            ElementType.JAVA_CLASS);
050:                    site
051:                            .addElementInfo(".ELEMENT2", element_info2,
052:                                    "/element2");
053:                    assertEquals(site.getUrls().size(), 2);
054:                } catch (EngineException e) {
055:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
056:                }
057:
058:                assertTrue(site.containsUrl("/element1"));
059:                assertTrue(site.containsUrl("/element2"));
060:                assertSame(site.resolveUrl("/element1", null), element_info1);
061:                assertSame(site.resolveUrl("/element2", null), element_info2);
062:                assertNull(site.resolveUrl("/element1", "/pathinfo"));
063:                assertNull(site.resolveUrl("/element2", "/pathinfo"));
064:                assertSame(site.resolveId(".ELEMENT1"), element_info1);
065:                assertSame(site.resolveId(".ELEMENT2"), element_info2);
066:                assertEquals(element_info1.getUrl(), "/element1");
067:                assertEquals(element_info2.getUrl(), "/element2");
068:            }
069:
070:            public void testTrailingSlash() throws EngineException {
071:                Site site = new Site();
072:                ElementInfo element_info1 = null;
073:                ElementInfo element_info2 = null;
074:                ElementInfo element_info3a = null;
075:                ElementInfo element_info3b = null;
076:                ElementInfo element_info4 = null;
077:                ElementInfo element_info5 = null;
078:                try {
079:                    element_info1 = new ElementInfo("element/test1.xml",
080:                            "text/html", TestElement1.class.getName(),
081:                            ElementType.JAVA_CLASS);
082:                    site
083:                            .addElementInfo(".ELEMENT1", element_info1,
084:                                    "/element1");
085:                    element_info2 = new ElementInfo("element/test2.xml",
086:                            "text/html", TestElement1.class.getName(),
087:                            ElementType.JAVA_CLASS);
088:                    site.addElementInfo(".ELEMENT2", element_info2,
089:                            "/element2/");
090:                    element_info3a = new ElementInfo("element/test3a.xml",
091:                            "text/html", TestElement1.class.getName(),
092:                            ElementType.JAVA_CLASS);
093:                    site.addElementInfo(".ELEMENT3a", element_info3a,
094:                            "/element3");
095:                    element_info3b = new ElementInfo("element/test3b.xml",
096:                            "text/html", TestElement1.class.getName(),
097:                            ElementType.JAVA_CLASS);
098:                    site.addElementInfo(".ELEMENT3b", element_info3b,
099:                            "/element3/");
100:                    element_info4 = new ElementInfo("element/test4.xml",
101:                            "text/html", TestElement1.class.getName(),
102:                            ElementType.JAVA_CLASS);
103:                    site.addElementInfo(".ELEMENT4", element_info4,
104:                            "/element4.html");
105:                    element_info5 = new ElementInfo("element/test5.xml",
106:                            "text/html", TestElement1.class.getName(),
107:                            ElementType.JAVA_CLASS);
108:                    site.addElementInfo(".ELEMENT5", element_info5,
109:                            "/element5.html/itis");
110:                } catch (EngineException e) {
111:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
112:                }
113:
114:                assertTrue(site.containsUrl("/element1"));
115:                assertFalse(site.containsUrl("/element2"));
116:                assertTrue(site.containsUrl("/element3"));
117:                assertTrue(site.containsUrl("/element1/"));
118:                assertTrue(site.containsUrl("/element2/"));
119:                assertTrue(site.containsUrl("/element3/"));
120:                assertTrue(site.containsUrl("/element4.html"));
121:                assertFalse(site.containsUrl("/element4.html/"));
122:                assertTrue(site.containsUrl("/element5.html/itis"));
123:                assertTrue(site.containsUrl("/element5.html/itis/"));
124:                assertSame(site.resolveUrl("/element1", null), element_info1);
125:                assertSame(site.resolveUrl("/element1/", null), element_info1);
126:                assertNull(site.resolveUrl("/element2", null));
127:                assertSame(site.resolveUrl("/element2/", null), element_info2);
128:                assertSame(site.resolveUrl("/element3", null), element_info3a);
129:                assertSame(site.resolveUrl("/element3/", null), element_info3b);
130:                assertSame(site.resolveUrl("/element4.html", null),
131:                        element_info4);
132:                assertNull(site.resolveUrl("/element4.html/", null));
133:                assertSame(site.resolveUrl("/element5.html/itis", null),
134:                        element_info5);
135:                assertSame(site.resolveUrl("/element5.html/itis/", null),
136:                        element_info5);
137:                assertEquals(element_info1.getUrl(), "/element1");
138:                assertEquals(element_info2.getUrl(), "/element2/");
139:                assertEquals(element_info3a.getUrl(), "/element3");
140:                assertEquals(element_info3b.getUrl(), "/element3/");
141:                assertEquals(element_info4.getUrl(), "/element4.html");
142:                assertEquals(element_info5.getUrl(), "/element5.html/itis");
143:            }
144:
145:            public void testAddDuplicateUrl() throws EngineException {
146:                Site site = new Site();
147:
148:                ElementInfo element_info1 = null;
149:                ElementInfo element_info2 = null;
150:                try {
151:                    element_info1 = new ElementInfo("element/test1.xml",
152:                            "text/html", TestElement1.class.getName(),
153:                            ElementType.JAVA_CLASS);
154:                    element_info2 = new ElementInfo("element/test2.xml",
155:                            "text/html", TestElement1.class.getName(),
156:                            ElementType.JAVA_CLASS);
157:                    site
158:                            .addElementInfo(".ELEMENT1", element_info1,
159:                                    "/element1");
160:                    site
161:                            .addElementInfo(".ELEMENT2", element_info2,
162:                                    "/element1");
163:                    fail();
164:                } catch (UrlExistsException e) {
165:                    assertEquals(e.getUrl(), "/element1");
166:                } catch (EngineException e) {
167:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
168:                }
169:            }
170:
171:            public void testAddDuplicateUrlPathinfo() throws EngineException {
172:                Site site = new Site();
173:
174:                ElementInfo element_info1 = null;
175:                ElementInfo element_info2 = null;
176:                element_info1 = new ElementInfo("element/test1.xml",
177:                        "text/html", TestElement1.class.getName(),
178:                        ElementType.JAVA_CLASS);
179:                element_info1.setPathInfoUsed(true);
180:                element_info2 = new ElementInfo("element/test2.xml",
181:                        "text/html", TestElement1.class.getName(),
182:                        ElementType.JAVA_CLASS);
183:                element_info2.setPathInfoUsed(true);
184:                site.addElementInfo(".ELEMENT1", element_info1, "/element1");
185:                site.addElementInfo(".ELEMENT2", element_info2, "/element1");
186:                assertSame(element_info1, site.resolveUrl("/element1", null));
187:                assertSame(element_info1, site.resolveUrl("/element1",
188:                        "/pathinfo"));
189:            }
190:
191:            public void testAddDuplicateId() throws EngineException {
192:                Site site = new Site();
193:
194:                ElementInfo element_info1 = null;
195:                ElementInfo element_info2 = null;
196:                try {
197:                    element_info1 = new ElementInfo("element/test1.xml",
198:                            "text/html", TestElement1.class.getName(),
199:                            ElementType.JAVA_CLASS);
200:                    element_info2 = new ElementInfo("element/test2.xml",
201:                            "text/html", TestElement1.class.getName(),
202:                            ElementType.JAVA_CLASS);
203:                    site
204:                            .addElementInfo(".ELEMENT1", element_info1,
205:                                    "/element1");
206:                    site
207:                            .addElementInfo(".ELEMENT1", element_info2,
208:                                    "/element2");
209:                    fail();
210:                } catch (DuplicateElementIdException e) {
211:                    assertEquals(e.getId(), ".ELEMENT1");
212:                } catch (EngineException e) {
213:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
214:                }
215:            }
216:
217:            public void testMapElementToSeveralUrls() throws EngineException {
218:                Site site = new Site();
219:                ElementInfo element_info = null;
220:                try {
221:                    element_info = new ElementInfo("element/test1.xml",
222:                            "text/html", TestElement1.class.getName(),
223:                            ElementType.JAVA_CLASS);
224:                    site.addElementInfo(".ELEMENT1", element_info, "/element");
225:                    assertEquals(site.getUrls().size(), 1);
226:                } catch (EngineException e) {
227:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
228:                }
229:
230:                try {
231:                    site.addElementInfo(".ELEMENT2", element_info, "/element2");
232:                    fail();
233:                } catch (EngineException e) {
234:                    assertEquals(site.getUrls().size(), 1);
235:                }
236:            }
237:
238:            public void testResolveElementIds() throws EngineException {
239:                Site site = new Site();
240:                ElementInfo element_info1 = new ElementInfo(
241:                        "element/test1.xml", "text/html", TestElement1.class
242:                                .getName(), ElementType.JAVA_CLASS);
243:                ElementInfo element_info2 = new ElementInfo(
244:                        "element/test1.xml", "text/html", TestElement1.class
245:                                .getName(), ElementType.JAVA_CLASS);
246:                ElementInfo element_info3 = new ElementInfo(
247:                        "element/test1.xml", "text/html", TestElement1.class
248:                                .getName(), ElementType.JAVA_CLASS);
249:                ElementInfo element_info4 = new ElementInfo(
250:                        "element/test1.xml", "text/html", TestElement1.class
251:                                .getName(), ElementType.JAVA_CLASS);
252:                ElementInfo element_info5 = new ElementInfo(
253:                        "element/test1.xml", "text/html", TestElement1.class
254:                                .getName(), ElementType.JAVA_CLASS);
255:                ElementInfo element_info6 = new ElementInfo(
256:                        "element/test1.xml", "text/html", TestElement1.class
257:                                .getName(), ElementType.JAVA_CLASS);
258:                site.addElementInfo(".ELEMENT1", element_info1, "/element1");
259:                site.addElementInfo(".ELEMENT2", element_info2, "/element2");
260:                site.addElementInfo(".ELEMENTS.ELEMENT", element_info3,
261:                        "/element3");
262:                site.addElementInfo(".ELEMENTS.ANOTHER", element_info4,
263:                        "/element4");
264:                site.addElementInfo(".MORE_ELEMENTS.ELEMENT", element_info5,
265:                        "/element5");
266:                site.addElementInfo(".MORE_ELEMENTS.ANOTHER", element_info6,
267:                        "/element6");
268:
269:                try {
270:                    site.resolveId("ELEMENT1");
271:                    fail();
272:                } catch (IllegalArgumentException e) {
273:                    assertTrue(true);
274:                }
275:
276:                assertSame(element_info1, site.resolveId(".ELEMENT1"));
277:                assertSame(element_info2, site.resolveId(".ELEMENT2"));
278:                assertSame(element_info3, site.resolveId(".ELEMENTS.ELEMENT"));
279:                assertSame(element_info4, site.resolveId(".ELEMENTS.ANOTHER"));
280:                assertSame(element_info5, site
281:                        .resolveId(".MORE_ELEMENTS.ELEMENT"));
282:                assertSame(element_info6, site
283:                        .resolveId(".MORE_ELEMENTS.ANOTHER"));
284:
285:                assertSame(element_info1, site.resolveId("ELEMENT1",
286:                        element_info1));
287:                assertSame(element_info1, site.resolveId("ELEMENT1",
288:                        element_info2));
289:                assertNull(site.resolveId("ELEMENT1", element_info3));
290:                assertNull(site.resolveId("ELEMENT1", element_info4));
291:                assertNull(site.resolveId("ELEMENT1", element_info5));
292:                assertNull(site.resolveId("ELEMENT1", element_info6));
293:
294:                assertSame(element_info2, site.resolveId("ELEMENT2",
295:                        element_info1));
296:                assertSame(element_info2, site.resolveId("ELEMENT2",
297:                        element_info2));
298:                assertNull(site.resolveId("ELEMENT2", element_info3));
299:                assertNull(site.resolveId("ELEMENT2", element_info4));
300:                assertNull(site.resolveId("ELEMENT2", element_info5));
301:                assertNull(site.resolveId("ELEMENT2", element_info6));
302:
303:                assertSame(element_info3, site.resolveId("ELEMENTS.ELEMENT",
304:                        element_info1));
305:                assertSame(element_info3, site.resolveId("ELEMENTS.ELEMENT",
306:                        element_info2));
307:                assertNull(site.resolveId("ELEMENTS.ELEMENT", element_info3));
308:                assertNull(site.resolveId("ELEMENTS.ELEMENT", element_info4));
309:                assertNull(site.resolveId("ELEMENTS.ELEMENT", element_info5));
310:                assertNull(site.resolveId("ELEMENTS.ELEMENT", element_info6));
311:
312:                assertSame(element_info4, site.resolveId("ELEMENTS.ANOTHER",
313:                        element_info1));
314:                assertSame(element_info4, site.resolveId("ELEMENTS.ANOTHER",
315:                        element_info2));
316:                assertNull(site.resolveId("ELEMENTS.ANOTHER", element_info3));
317:                assertNull(site.resolveId("ELEMENTS.ANOTHER", element_info4));
318:                assertNull(site.resolveId("ELEMENTS.ANOTHER", element_info5));
319:                assertNull(site.resolveId("ELEMENTS.ANOTHER", element_info6));
320:
321:                assertSame(element_info5, site.resolveId(
322:                        "MORE_ELEMENTS.ELEMENT", element_info1));
323:                assertSame(element_info5, site.resolveId(
324:                        "MORE_ELEMENTS.ELEMENT", element_info2));
325:                assertNull(site.resolveId("MORE_ELEMENTS.ELEMENT",
326:                        element_info3));
327:                assertNull(site.resolveId("MORE_ELEMENTS.ELEMENT",
328:                        element_info4));
329:                assertNull(site.resolveId("MORE_ELEMENTS.ELEMENT",
330:                        element_info5));
331:                assertNull(site.resolveId("MORE_ELEMENTS.ELEMENT",
332:                        element_info6));
333:
334:                assertSame(element_info6, site.resolveId(
335:                        "MORE_ELEMENTS.ANOTHER", element_info1));
336:                assertSame(element_info6, site.resolveId(
337:                        "MORE_ELEMENTS.ANOTHER", element_info2));
338:                assertNull(site.resolveId("MORE_ELEMENTS.ANOTHER",
339:                        element_info3));
340:                assertNull(site.resolveId("MORE_ELEMENTS.ANOTHER",
341:                        element_info4));
342:                assertNull(site.resolveId("MORE_ELEMENTS.ANOTHER",
343:                        element_info5));
344:                assertNull(site.resolveId("MORE_ELEMENTS.ANOTHER",
345:                        element_info6));
346:
347:                assertNull(site.resolveId("ELEMENT", element_info1));
348:                assertNull(site.resolveId("ELEMENT", element_info2));
349:                assertSame(element_info3, site.resolveId("ELEMENT",
350:                        element_info3));
351:                assertSame(element_info3, site.resolveId("ELEMENT",
352:                        element_info4));
353:                assertSame(element_info5, site.resolveId("ELEMENT",
354:                        element_info5));
355:                assertSame(element_info5, site.resolveId("ELEMENT",
356:                        element_info6));
357:
358:                assertNull(site.resolveId("ANOTHER", element_info1));
359:                assertNull(site.resolveId("ANOTHER", element_info2));
360:                assertSame(element_info4, site.resolveId("ANOTHER",
361:                        element_info3));
362:                assertSame(element_info4, site.resolveId("ANOTHER",
363:                        element_info4));
364:                assertSame(element_info6, site.resolveId("ANOTHER",
365:                        element_info5));
366:                assertSame(element_info6, site.resolveId("ANOTHER",
367:                        element_info6));
368:
369:                assertSame(element_info2, site.resolveId(".ELEMENT1^ELEMENT2"));
370:                assertSame(element_info1, site.resolveId(".ELEMENT2^ELEMENT1"));
371:                assertSame(element_info4, site
372:                        .resolveId(".ELEMENTS.ELEMENT^ANOTHER"));
373:                assertSame(element_info3, site
374:                        .resolveId(".ELEMENTS.ANOTHER^ELEMENT"));
375:                assertSame(element_info6, site
376:                        .resolveId(".MORE_ELEMENTS.ELEMENT^ANOTHER"));
377:                assertSame(element_info5, site
378:                        .resolveId(".MORE_ELEMENTS.ANOTHER^ELEMENT"));
379:                assertSame(element_info5, site
380:                        .resolveId(".ELEMENTS.ELEMENT^^MORE_ELEMENTS.ELEMENT"));
381:                assertSame(element_info6, site
382:                        .resolveId(".ELEMENTS.ANOTHER^^MORE_ELEMENTS.ANOTHER"));
383:                assertSame(element_info3, site
384:                        .resolveId(".MORE_ELEMENTS.ELEMENT^^ELEMENTS.ELEMENT"));
385:                assertSame(element_info4, site
386:                        .resolveId(".MORE_ELEMENTS.ANOTHER^^ELEMENTS.ANOTHER"));
387:
388:                assertSame(element_info1, site.resolveId("^ELEMENT1",
389:                        element_info1));
390:                assertSame(element_info1, site.resolveId("^ELEMENT1",
391:                        element_info2));
392:                assertSame(element_info1, site.resolveId("^ELEMENT1",
393:                        element_info3));
394:                assertSame(element_info1, site.resolveId("^ELEMENT1",
395:                        element_info4));
396:                assertSame(element_info1, site.resolveId("^ELEMENT1",
397:                        element_info5));
398:                assertSame(element_info1, site.resolveId("^ELEMENT1",
399:                        element_info6));
400:
401:                assertSame(element_info2, site.resolveId("^ELEMENT2",
402:                        element_info1));
403:                assertSame(element_info2, site.resolveId("^ELEMENT2",
404:                        element_info2));
405:                assertSame(element_info2, site.resolveId("^ELEMENT2",
406:                        element_info3));
407:                assertSame(element_info2, site.resolveId("^ELEMENT2",
408:                        element_info4));
409:                assertSame(element_info2, site.resolveId("^ELEMENT2",
410:                        element_info5));
411:                assertSame(element_info2, site.resolveId("^ELEMENT2",
412:                        element_info6));
413:            }
414:        }
415:
416:        class TestElement1 extends Element {
417:            public void processElement() throws EngineException {
418:                print("the content");
419:            }
420:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.