Source Code Cross Referenced for NavModuleTest.java in  » Content-Management-System » TransferCM » com » methodhead » shim » 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 » Content Management System » TransferCM » com.methodhead.shim 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright (C) 2006 Methodhead Software LLC.  All rights reserved.
003:         * 
004:         * This file is part of TransferCM.
005:         * 
006:         * TransferCM is free software; you can redistribute it and/or modify it under the
007:         * terms of the GNU General Public License as published by the Free Software
008:         * Foundation; either version 2 of the License, or (at your option) any later
009:         * version.
010:         * 
011:         * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012:         * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013:         * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
014:         * details.
015:         * 
016:         * You should have received a copy of the GNU General Public License along with
017:         * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018:         * Fifth Floor, Boston, MA  02110-1301  USA
019:         */
020:
021:        package com.methodhead.shim;
022:
023:        import java.util.*;
024:        import java.sql.*;
025:        import java.io.*;
026:        import junit.framework.*;
027:        import org.apache.log4j.*;
028:        import org.apache.struts.action.*;
029:        import com.methodhead.persistable.*;
030:        import com.methodhead.test.*;
031:        import com.methodhead.sitecontext.*;
032:        import com.methodhead.util.*;
033:        import com.methodhead.*;
034:        import org.apache.cactus.*;
035:
036:        public class NavModuleTest extends JspTestCase {
037:
038:            private NavModule navModule = null;
039:            private Panel panel = null;
040:            private List list = null;
041:            private DynaActionForm dynaActionForm = null;
042:            private ActionForward forward = null;
043:            private Link link = null;
044:
045:            private SiteMap siteMap1_ = null;
046:
047:            private SiteContext siteContext1_ = null;
048:
049:            private Page page1_ = null;
050:            private Page page2_ = null;
051:            private Page page3_ = null;
052:            private Page page4_ = null;
053:            private Page page5_ = null;
054:            private Page page6_ = null;
055:
056:            private Link link1_ = null;
057:            private Link link2_ = null;
058:            private Link link3_ = null;
059:            private Link link4_ = null;
060:            private Link link5_ = null;
061:
062:            static {
063:                TestUtils.initLogger();
064:                TestUtils.initDb();
065:            }
066:
067:            public NavModuleTest(String name) {
068:                super (name);
069:            }
070:
071:            public void setUp() {
072:                //setLogLevel( Level.DEBUG );
073:                try {
074:                    TestData.createWebappFiles(ServletUtils.getRealFile(
075:                            request, ""));
076:
077:                    ConnectionSingleton.runBatchUpdate(new FileReader(
078:                            "webapp/WEB-INF/db/transfer-reset.sql"));
079:
080:                    panel = new Panel();
081:                    panel.setModuleClass("com.methodhead.shim.NavModule");
082:                    panel.setName("body");
083:
084:                    siteContext1_ = new SiteContext();
085:                    siteContext1_.saveNew();
086:
087:                    page1_ = new Page();
088:                    page1_.setSiteContext(SiteContext.getDefaultContext());
089:                    page1_.setString("template", "template.jsp");
090:                    page1_.setString("title", "Page1");
091:                    page1_.setString("aliasname", "page1");
092:                    page1_.addPanel(panel);
093:                    page1_.saveNew();
094:
095:                    page2_ = new Page();
096:                    page2_.setSiteContext(SiteContext.getDefaultContext());
097:                    page2_.setString("template", "template.jsp");
098:                    page2_.setString("title", "Page2");
099:                    page2_.setString("aliasname", "page2");
100:                    page2_.addPanel(panel);
101:                    page2_.saveNew();
102:
103:                    page3_ = new Page();
104:                    page3_.setSiteContext(SiteContext.getDefaultContext());
105:                    page3_.setString("template", "template.jsp");
106:                    page3_.setString("title", "Page3");
107:                    page3_.setString("aliasname", "page3");
108:                    page3_.addPanel(panel);
109:                    page3_.saveNew();
110:
111:                    page4_ = new Page();
112:                    page4_.setSiteContext(SiteContext.getDefaultContext());
113:                    page4_.setString("template", "template.jsp");
114:                    page4_.setString("title", "Page4");
115:                    page4_.setString("aliasname", "page4");
116:                    page4_.addPanel(panel);
117:                    page4_.saveNew();
118:
119:                    page5_ = new Page();
120:                    page5_.setSiteContext(SiteContext.getDefaultContext());
121:                    page5_.setString("template", "template.jsp");
122:                    page5_.setString("title", "Page5");
123:                    page5_.setString("aliasname", "page5");
124:                    page5_.addPanel(panel);
125:                    page5_.saveNew();
126:
127:                    page6_ = new Page();
128:                    page6_.setSiteContext(SiteContext.getDefaultContext());
129:                    page6_.setString("template", "Template2.jsp");
130:                    page6_.setString("title", "Page6");
131:                    page6_.setString("aliasname", "page6");
132:                    page6_.addPanel(panel);
133:                    page6_.saveNew();
134:
135:                    // Link1
136:                    //   Link2
137:                    //     Link3
138:                    //   Link4
139:                    //   Link5
140:                    link1_ = new Link();
141:                    link1_.setTitle("Page1");
142:                    link1_.setAlias("page1");
143:                    link1_.setPageId(page1_.getInt("id"));
144:
145:                    link2_ = new Link();
146:                    link2_.setTitle("Page2");
147:                    link2_.setAlias("page2");
148:                    link2_.setPageId(page2_.getInt("id"));
149:
150:                    link3_ = new Link();
151:                    link3_.setTitle("Page3");
152:                    link3_.setAlias("page3");
153:                    link3_.setPageId(page3_.getInt("id"));
154:
155:                    link4_ = new Link();
156:                    link4_.setTitle("Page4");
157:                    link4_.setAlias("page4");
158:                    link4_.setPageId(page4_.getInt("id"));
159:
160:                    link5_ = new Link();
161:                    link5_.setTitle("Page5");
162:                    link5_.setAlias("page5");
163:                    link5_.setPageId(page5_.getInt("id"));
164:
165:                    link1_.add(link2_);
166:                    link2_.add(link3_);
167:                    link1_.add(link4_);
168:                    link1_.add(link5_);
169:
170:                    siteMap1_ = new SiteMap();
171:                    siteMap1_.setSiteContext(SiteContext.getDefaultContext());
172:                    siteMap1_.setRoot(link1_);
173:
174:                    ShimUtils.setSiteMap(request, siteMap1_);
175:                    SiteContext.setContext(request, SiteContext
176:                            .getDefaultContext());
177:                    request.setAttribute(ShimGlobals.PAGE_KEY, page1_);
178:                } catch (Exception e) {
179:                    fail(e.getMessage());
180:                }
181:            }
182:
183:            public void tearDown() {
184:            }
185:
186:            public void testInit() {
187:                try {
188:                    navModule = new NavModule();
189:                    navModule.init(page1_, "body");
190:
191:                    assertEquals(SiteContext.getDefaultContext().getInt("id"),
192:                            navModule.getInt("sitecontext_id"));
193:                    assertEquals("template.jsp", navModule
194:                            .getString("template"));
195:                    assertEquals("body", navModule.getString("panel"));
196:                } catch (Exception e) {
197:                    e.printStackTrace();
198:                    fail();
199:                }
200:            }
201:
202:            public void testLoad() {
203:                try {
204:                    navModule = new NavModule();
205:                    navModule.init(page1_, "body");
206:
207:                    try {
208:                        navModule.load();
209:                        fail("Exception not thrown.");
210:                    } catch (Exception e) {
211:                        // success
212:                    }
213:
214:                    navModule.saveNew();
215:                    navModule
216:                            .load("sitecontext_id=0 AND template='template.jsp' AND panel='body'");
217:
218:                    // shouldn't throw exception
219:                } catch (Exception e) {
220:                    e.printStackTrace();
221:                    fail();
222:                }
223:            }
224:
225:            public void testSave() {
226:                try {
227:                    navModule = new NavModule();
228:                    navModule.init(page1_, "body");
229:                    navModule.create();
230:
231:                    navModule = new NavModule();
232:                    navModule.init(page1_, "body");
233:                    navModule.load();
234:                    navModule.setString("separator", " - ");
235:                    navModule.setInt("startlev", 2);
236:                    navModule.setInt("contextlev", 2);
237:                    navModule.setInt("depthlev", 2);
238:                    navModule.setInt("toplev", 2);
239:                    navModule.setString("header", "header");
240:                    navModule.setString("link", "link");
241:                    navModule.setString("curlink", "curlink");
242:                    navModule.setString("footer", "footer");
243:                    navModule.save();
244:
245:                    navModule = new NavModule();
246:                    navModule.init(page1_, "body");
247:                    navModule.load();
248:
249:                    assertEquals(" - ", navModule
250:                            .getString("separator"));
251:                    assertEquals(2, navModule.getInt("startlev"));
252:                    assertEquals(2, navModule.getInt("contextlev"));
253:                    assertEquals(2, navModule.getInt("depthlev"));
254:                    assertEquals(2, navModule.getInt("toplev"));
255:                    assertEquals("header", navModule.getString("header"));
256:                    assertEquals("link", navModule.getString("link"));
257:                    assertEquals("curlink", navModule.getString("curlink"));
258:                    assertEquals("footer", navModule.getString("footer"));
259:                } catch (Exception e) {
260:                    e.printStackTrace();
261:                    fail();
262:                }
263:            }
264:
265:            public void testCreate() {
266:                try {
267:                    navModule = new NavModule();
268:                    navModule.init(page1_, "body");
269:                    navModule.create();
270:                    navModule = new NavModule();
271:                    navModule.load("sitecontext_id="
272:                            + SiteContext.getDefaultContext().getInt("id")
273:                            + " AND panel='body'");
274:                    list = navModule
275:                            .loadAll(
276:                                    NavModule.dynaClass_,
277:                                    "sitecontext_id="
278:                                            + SiteContext.getDefaultContext()
279:                                                    .getInt("id")
280:                                            + " AND template='template.jsp' AND panel='body'",
281:                                    null);
282:
283:                    assertEquals(1, list.size());
284:
285:                    navModule = (NavModule) list.get(0);
286:
287:                    assertEquals("template.jsp", navModule
288:                            .getString("template"));
289:                    assertEquals(NavModule.TYPE_TEXTSEPARATED, navModule
290:                            .getString("type"));
291:                    assertEquals(" | ", navModule
292:                            .getString("separator"));
293:                    assertEquals("", navModule.getString("jsp"));
294:
295:                    //
296:                    // create for another page with the same template and verify the same
297:                    // navigation settings are used
298:                    //
299:                    navModule = new NavModule();
300:                    navModule.init(page2_, "body");
301:                    navModule.create();
302:                    list = navModule
303:                            .loadAll(
304:                                    NavModule.dynaClass_,
305:                                    "sitecontext_id="
306:                                            + SiteContext.getDefaultContext()
307:                                                    .getInt("id")
308:                                            + " AND template='template.jsp' AND panel='body'",
309:                                    null);
310:
311:                    assertEquals(1, list.size());
312:
313:                    navModule = (NavModule) list.get(0);
314:
315:                    assertEquals("template.jsp", navModule
316:                            .getString("template"));
317:                    assertEquals(NavModule.TYPE_TEXTSEPARATED, navModule
318:                            .getString("type"));
319:                    assertEquals(" | ", navModule
320:                            .getString("separator"));
321:                    assertEquals("", navModule.getString("jsp"));
322:
323:                    //
324:                    // create for another page with a different template that has a panel of
325:                    // the same name and verify that nav settings are set up
326:                    //
327:                    navModule = new NavModule();
328:                    navModule.init(page6_, "body");
329:                    navModule.create();
330:                    list = navModule
331:                            .loadAll(
332:                                    NavModule.dynaClass_,
333:                                    "sitecontext_id="
334:                                            + SiteContext.getDefaultContext()
335:                                                    .getInt("id")
336:                                            + " AND template='Template2.jsp' AND panel='body'",
337:                                    null);
338:
339:                    assertEquals(1, list.size());
340:
341:                    navModule = (NavModule) list.get(0);
342:
343:                    assertEquals("Template2.jsp", navModule
344:                            .getString("template"));
345:                    assertEquals(NavModule.TYPE_TEXTSEPARATED, navModule
346:                            .getString("type"));
347:                    assertEquals(" | ", navModule
348:                            .getString("separator"));
349:                    assertEquals("", navModule.getString("jsp"));
350:                } catch (Exception e) {
351:                    e.printStackTrace();
352:                    fail();
353:                }
354:            }
355:
356:            public void testDisplayTextSeparated() {
357:                try {
358:                    navModule = new NavModule();
359:                    navModule.init(page1_, "body");
360:                    navModule.create();
361:
362:                    navModule = new NavModule();
363:                    navModule.init(page1_, "body");
364:                    navModule.display(request, response, out);
365:                } catch (Exception e) {
366:                    e.printStackTrace();
367:                    fail();
368:                }
369:            }
370:
371:            public void endDisplayTextSeparated(WebResponse response) {
372:                assertEquals(
373:                        "<a href=\"page1.shtml\">Page1</a>&nbsp;|&nbsp;<a href=\"page2.shtml\">Page2</a>&nbsp;|&nbsp;<a href=\"page4.shtml\">Page4</a>&nbsp;|&nbsp;<a href=\"page5.shtml\">Page5</a>",
374:                        response.getText());
375:            }
376:
377:            public void testDisplayTextSeparatedHiddenLink() {
378:                try {
379:                    navModule = new NavModule();
380:                    navModule.init(page1_, "body");
381:                    navModule.create();
382:
383:                    //
384:                    // hide link4 for this test
385:                    //
386:                    link4_.setHidden(true);
387:
388:                    navModule = new NavModule();
389:                    navModule.init(page1_, "body");
390:                    navModule.display(request, response, out);
391:
392:                    //
393:                    // hide the root link
394:                    //
395:                    link1_.setHidden(true);
396:
397:                    navModule = new NavModule();
398:                    navModule.init(page1_, "body");
399:                    navModule.display(request, response, out);
400:                } catch (Exception e) {
401:                    e.printStackTrace();
402:                    fail();
403:                }
404:            }
405:
406:            public void endDisplayTextSeparatedHiddenLink(WebResponse response) {
407:                assertEquals(
408:                        "<a href=\"page1.shtml\">Page1</a>&nbsp;|&nbsp;<a href=\"page2.shtml\">Page2</a>&nbsp;|&nbsp;<a href=\"page5.shtml\">Page5</a>"
409:                                + "<a href=\"page2.shtml\">Page2</a>&nbsp;|&nbsp;<a href=\"page5.shtml\">Page5</a>",
410:                        response.getText());
411:            }
412:
413:            public void testDisplayTextSeparatedHiddenLink2() {
414:                try {
415:                    navModule = new NavModule();
416:                    navModule.init(page1_, "body");
417:                    navModule.create();
418:
419:                    //
420:                    // hide link2 for this test
421:                    //
422:                    link2_.setHidden(true);
423:
424:                    navModule = new NavModule();
425:                    navModule.init(page1_, "body");
426:                    navModule.display(request, response, out);
427:                } catch (Exception e) {
428:                    e.printStackTrace();
429:                    fail();
430:                }
431:            }
432:
433:            public void endDisplayTextSeparatedHiddenLink2(WebResponse response) {
434:                assertEquals(
435:                        "<a href=\"page1.shtml\">Page1</a>&nbsp;|&nbsp;<a href=\"page4.shtml\">Page4</a>&nbsp;|&nbsp;<a href=\"page5.shtml\">Page5</a>",
436:                        response.getText());
437:            }
438:
439:            public void testDisplayTextSeparatedWithHeader() {
440:                try {
441:                    request.setAttribute(ShimGlobals.PAGE_KEY, page2_);
442:
443:                    navModule = new NavModule();
444:                    navModule.init(page1_, "body");
445:                    navModule.create();
446:                    navModule.setString("header", ">>");
447:                    navModule.setString("footer", "<<");
448:                    navModule.setString("link", "{title}/{url}");
449:                    navModule.setString("curlink", "({title}/{url})");
450:                    navModule.setBoolean("hideroot", true);
451:                    navModule.save();
452:
453:                    navModule = new NavModule();
454:                    navModule.init(page1_, "body");
455:                    navModule.display(request, response, out);
456:                } catch (Exception e) {
457:                    e.printStackTrace();
458:                    fail();
459:                }
460:            }
461:
462:            public void endDisplayTextSeparatedWithHeader(WebResponse response) {
463:                assertEquals(
464:                        ">>(Page2/page2.shtml)&nbsp;|&nbsp;Page4/page4.shtml&nbsp;|&nbsp;Page5/page5.shtml<<",
465:                        response.getText());
466:            }
467:
468:            public void testDisplayTextSeparatedSubLevel() {
469:                try {
470:                    request.setAttribute(ShimGlobals.PAGE_KEY, page2_);
471:
472:                    navModule = new NavModule();
473:                    navModule.init(page1_, "body");
474:                    navModule.create();
475:                    navModule.setString("header", ">>");
476:                    navModule.setString("footer", "<<");
477:                    navModule.setString("link", "{title}/{url}");
478:                    navModule.setString("curlink", "({title}/{url})");
479:                    navModule.setBoolean("hideroot", false);
480:                    navModule.save();
481:
482:                    //
483:                    // page 2 should be highlighted since page 3 is current and under it
484:                    //
485:                    request.setAttribute(ShimGlobals.PAGE_KEY, page3_);
486:
487:                    navModule = new NavModule();
488:                    navModule.init(page1_, "body");
489:                    navModule.display(request, response, out);
490:                } catch (Exception e) {
491:                    e.printStackTrace();
492:                    fail();
493:                }
494:            }
495:
496:            public void endDisplayTextSeparatedSubLevel(WebResponse response) {
497:                assertEquals(
498:                        ">>Page1/page1.shtml&nbsp;|&nbsp;(Page2/page2.shtml)&nbsp;|&nbsp;Page4/page4.shtml&nbsp;|&nbsp;Page5/page5.shtml<<",
499:                        response.getText());
500:            }
501:
502:            public void testDisplayTextSeparatedEditMode() {
503:                try {
504:                    session.setAttribute(ShimGlobals.MODE_KEY,
505:                            ShimGlobals.MODE_EDIT);
506:                    request.setAttribute(ShimGlobals.PAGE_KEY, page2_);
507:
508:                    navModule = new NavModule();
509:                    navModule.init(page1_, "body");
510:                    navModule.create();
511:                    navModule.setString("header", ">>");
512:                    navModule.setString("footer", "<<");
513:                    navModule.setString("link", "{title}/{url}");
514:                    navModule.setString("curlink", "({title}/{url})");
515:                    navModule.setBoolean("hideroot", true);
516:                    navModule.save();
517:
518:                    navModule = new NavModule();
519:                    navModule.init(page1_, "body");
520:                    navModule.display(request, response, out);
521:                } catch (Exception e) {
522:                    e.printStackTrace();
523:                    fail();
524:                }
525:            }
526:
527:            public void endDisplayTextSeparatedEditMode(WebResponse response) {
528:                assertEquals(
529:                        ">>(Page2/page2.shtml)&nbsp;|&nbsp;Page4/page4.shtml&nbsp;|&nbsp;Page5/page5.shtml<<",
530:                        response.getText());
531:            }
532:
533:            public void testDisplayFolding() {
534:                try {
535:                    navModule = new NavModule();
536:                    navModule.init(page1_, "body");
537:                    navModule.create();
538:
539:                    navModule = new NavModule();
540:                    navModule.init(page1_, "body");
541:                    navModule.load();
542:                    navModule.setString("type", NavModule.TYPE_FOLDING);
543:                    navModule.setString("header", "<ul>\n");
544:                    navModule
545:                            .setString("link",
546:                                    "<li class=\"lev{level}\"><a href=\"{url}\">{title}</a></li>\n");
547:                    navModule
548:                            .setString("curlink",
549:                                    "<li class=\"lev{level}cur\"><a href=\"{url}\">{title}</a></li>\n");
550:                    navModule.setString("footer", "</ul>\n");
551:                    navModule.save();
552:
553:                    navModule = new NavModule();
554:                    navModule.init(page1_, "body");
555:                    navModule.display(request, response, out);
556:                } catch (Exception e) {
557:                    e.printStackTrace();
558:                    fail();
559:                }
560:            }
561:
562:            public void endDisplayFolding(WebResponse response) {
563:                String html = "<ul>\n"
564:                        + "<li class=\"lev1cur\"><a href=\"page1.shtml\">Page1</a></li>\n"
565:                        + "<li class=\"lev2\"><a href=\"page2.shtml\">Page2</a></li>\n"
566:                        + "<li class=\"lev2\"><a href=\"page4.shtml\">Page4</a></li>\n"
567:                        + "<li class=\"lev2\"><a href=\"page5.shtml\">Page5</a></li>\n"
568:                        + "</ul>\n\n";
569:
570:                assertEquals(html, response.getText());
571:            }
572:
573:            public void testDisplayFoldingWithPath() {
574:                try {
575:                    //
576:                    // force the path on the site context (very flimsy)
577:                    //
578:                    page1_.getSiteContext().setString("path", "path");
579:
580:                    navModule = new NavModule();
581:                    navModule.init(page1_, "body");
582:                    navModule.create();
583:
584:                    navModule = new NavModule();
585:                    navModule.init(page1_, "body");
586:                    navModule.load();
587:                    navModule.setString("type", NavModule.TYPE_FOLDING);
588:                    navModule.setString("header", "<ul>\n");
589:                    navModule
590:                            .setString("link",
591:                                    "<li class=\"lev{level}\"><a href=\"{url}\">{title}</a></li>\n");
592:                    navModule
593:                            .setString("curlink",
594:                                    "<li class=\"lev{level}cur\"><a href=\"{url}\">{title}</a></li>\n");
595:                    navModule.setString("footer", "</ul>\n");
596:                    navModule.save();
597:
598:                    navModule = new NavModule();
599:                    navModule.init(page1_, "body");
600:                    navModule.display(request, response, out);
601:                } catch (Exception e) {
602:                    e.printStackTrace();
603:                    fail();
604:                }
605:            }
606:
607:            public void endDisplayFoldingWithPath(WebResponse response) {
608:                String html = "<ul>\n"
609:                        + "<li class=\"lev1cur\"><a href=\"page1.shtml\">Page1</a></li>\n"
610:                        + "<li class=\"lev2\"><a href=\"page2.shtml\">Page2</a></li>\n"
611:                        + "<li class=\"lev2\"><a href=\"page4.shtml\">Page4</a></li>\n"
612:                        + "<li class=\"lev2\"><a href=\"page5.shtml\">Page5</a></li>\n"
613:                        + "</ul>\n\n";
614:
615:                assertEquals(html, response.getText());
616:            }
617:
618:            public void testDisplayFoldingEditMode() {
619:                try {
620:                    //
621:                    // force the path on the site context (very flimsy)
622:                    //
623:                    session.setAttribute(ShimGlobals.MODE_KEY,
624:                            ShimGlobals.MODE_EDIT);
625:                    page1_.getSiteContext().setString("path", "path");
626:
627:                    navModule = new NavModule();
628:                    navModule.init(page1_, "body");
629:                    navModule.create();
630:
631:                    navModule = new NavModule();
632:                    navModule.init(page1_, "body");
633:                    navModule.load();
634:                    navModule.setString("type", NavModule.TYPE_FOLDING);
635:                    navModule.setString("header", "<ul>\n");
636:                    navModule
637:                            .setString("link",
638:                                    "<li class=\"lev{level}\"><a href=\"{url}\">{title}</a></li>\n");
639:                    navModule
640:                            .setString("curlink",
641:                                    "<li class=\"lev{level}cur\"><a href=\"{url}\">{title}</a></li>\n");
642:                    navModule.setString("footer", "</ul>\n");
643:                    navModule.save();
644:
645:                    navModule = new NavModule();
646:                    navModule.init(page1_, "body");
647:                    navModule.display(request, response, out);
648:                } catch (Exception e) {
649:                    e.printStackTrace();
650:                    fail();
651:                }
652:            }
653:
654:            public void endDisplayFoldingEditMode(WebResponse response) {
655:                String html = "<ul>\n"
656:                        + "<li class=\"lev1cur\"><a href=\"page1.shtml\">Page1</a></li>\n"
657:                        + "<li class=\"lev2\"><a href=\"page2.shtml\">Page2</a></li>\n"
658:                        + "<li class=\"lev2\"><a href=\"page4.shtml\">Page4</a></li>\n"
659:                        + "<li class=\"lev2\"><a href=\"page5.shtml\">Page5</a></li>\n"
660:                        + "</ul>\n\n";
661:
662:                assertEquals(html, response.getText());
663:            }
664:
665:            public void testDisplayJsp() {
666:                try {
667:                    navModule = new NavModule();
668:                    navModule.init(page1_, "body");
669:                    navModule.create();
670:                    navModule.setString("type", NavModule.TYPE_JSP);
671:                    navModule.setString("jsp", "jsp/nav.jsp");
672:                    navModule.save();
673:
674:                    navModule = new NavModule();
675:                    navModule.init(page1_, "body");
676:                    navModule.display(request, response, out);
677:
678:                    link = (Link) request
679:                            .getAttribute(ShimGlobals.CURRENTLINK_KEY);
680:
681:                    assertNotNull(link);
682:                    assertEquals("Page1", link.getTitle());
683:                } catch (Exception e) {
684:                    e.printStackTrace();
685:                    fail();
686:                }
687:            }
688:
689:            public void endDisplayJsp(WebResponse response) {
690:                assertEquals("Hello from nav.jsp!\n", response.getText());
691:            }
692:
693:            public void testDisplayJspException() {
694:                try {
695:                    navModule = new NavModule();
696:                    navModule.init(page1_, "body");
697:                    navModule.create();
698:                    navModule.setString("type", NavModule.TYPE_JSP);
699:                    navModule.setString("jsp", "jsp/invalid.jsp");
700:                    navModule.save();
701:
702:                    navModule = new NavModule();
703:                    navModule.init(page1_, "body");
704:                    navModule.display(request, response, out);
705:
706:                    link = (Link) request
707:                            .getAttribute(ShimGlobals.CURRENTLINK_KEY);
708:
709:                    assertNotNull(link);
710:                    assertEquals("Page1", link.getTitle());
711:                } catch (Exception e) {
712:                    e.printStackTrace();
713:                    fail();
714:                }
715:            }
716:
717:            public void endDisplayJspException(WebResponse response) {
718:                assertTrue(response.getText().startsWith(
719:                        "org.apache.jasper.JasperException"));
720:            }
721:
722:            public void testConfigure() {
723:                try {
724:                    dynaActionForm = new MockDynaActionForm();
725:                    dynaActionForm.set("pageid", "666");
726:                    dynaActionForm.set("panel", "body");
727:
728:                    navModule = new NavModule();
729:                    forward = navModule.configure(new ActionMapping(),
730:                            dynaActionForm, request, response);
731:
732:                    assertEquals(
733:                            "/configureNavModuleForm.do?pageid=666&panel=body",
734:                            forward.getPath());
735:                } catch (Exception e) {
736:                    e.printStackTrace();
737:                    fail();
738:                }
739:            }
740:
741:            public void testCopyTo() {
742:                try {
743:                    //
744:                    // copy to a new page
745:                    //
746:                    navModule = new NavModule();
747:                    navModule.init(page1_, "body");
748:                    navModule.create();
749:                    navModule.setString("type", NavModule.DEFAULT_TYPE);
750:                    navModule.setString("separator", "|");
751:                    navModule.save();
752:
753:                    navModule = new NavModule();
754:                    navModule.init(page1_, "body");
755:                    navModule.copyTo(page2_);
756:
757:                    navModule = new NavModule();
758:                    navModule.init(page2_, "body");
759:                    navModule.load();
760:
761:                    assertEquals(NavModule.DEFAULT_TYPE, navModule
762:                            .getString("type"));
763:                    assertEquals("|", navModule.getString("separator"));
764:
765:                    //
766:                    // copy to an existing page
767:                    //
768:                    navModule.setString("separator", "*");
769:                    navModule.save();
770:
771:                    navModule = new NavModule();
772:                    navModule.init(page2_, "body");
773:                    navModule.copyTo(page1_);
774:
775:                    navModule = new NavModule();
776:                    navModule.init(page1_, "body");
777:                    navModule.load();
778:
779:                    assertEquals("*", navModule.getString("separator"));
780:                } catch (Exception e) {
781:                    e.printStackTrace();
782:                    fail();
783:                }
784:            }
785:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.