Source Code Cross Referenced for PageActionTest.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) 


0001:        /* 
0002:         * Copyright (C) 2006 Methodhead Software LLC.  All rights reserved.
0003:         * 
0004:         * This file is part of TransferCM.
0005:         * 
0006:         * TransferCM is free software; you can redistribute it and/or modify it under the
0007:         * terms of the GNU General Public License as published by the Free Software
0008:         * Foundation; either version 2 of the License, or (at your option) any later
0009:         * version.
0010:         * 
0011:         * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
0012:         * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
0013:         * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
0014:         * details.
0015:         * 
0016:         * You should have received a copy of the GNU General Public License along with
0017:         * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
0018:         * Fifth Floor, Boston, MA  02110-1301  USA
0019:         */
0020:
0021:        package com.methodhead.shim;
0022:
0023:        import java.io.*;
0024:        import java.util.*;
0025:        import java.sql.*;
0026:        import junit.framework.*;
0027:        import org.apache.log4j.*;
0028:        import com.methodhead.persistable.*;
0029:        import com.methodhead.aikp.*;
0030:        import com.methodhead.test.*;
0031:        import com.methodhead.auth.*;
0032:        import com.methodhead.tree.*;
0033:        import com.methodhead.sitecontext.*;
0034:        import com.methodhead.*;
0035:        import com.methodhead.util.*;
0036:        import servletunit.struts.*;
0037:        import org.apache.cactus.*;
0038:        import org.apache.struts.util.*;
0039:        import org.apache.struts.action.*;
0040:        import javax.swing.tree.*;
0041:
0042:        public class PageActionTest extends CactusStrutsTestCase {
0043:
0044:            static {
0045:                TestUtils.initLogger();
0046:                TestUtils.initDb();
0047:            }
0048:
0049:            private SiteMap siteMap = null;
0050:            private Link link = null;
0051:            private Link sublink = null;
0052:            private Page page = null;
0053:            private SiteMapTree tree = null;
0054:            private DefaultMutableTreeNode node = null;
0055:            private DefaultMutableTreeNode subnode = null;
0056:            private FoldingTreeNode foldingNode = null;
0057:            private DynaActionForm form = null;
0058:            private List list = null;
0059:            private LabelValueBean bean = null;
0060:            private Panel panel = null;
0061:            private TextModule textModule = null;
0062:            private Module module = null;
0063:
0064:            private Page page1_ = null;
0065:            private Page page2_ = null;
0066:            private Page page3_ = null;
0067:            private Page page4_ = null;
0068:            private Page page5_ = null;
0069:
0070:            private Link link1_ = null;
0071:            private Link link2_ = null;
0072:            private Link link3_ = null;
0073:            private Link link4_ = null;
0074:            private Link link5_ = null;
0075:
0076:            private void createData() {
0077:                Panel panel = null;
0078:
0079:                panel = new Panel();
0080:                panel.setName("body");
0081:                panel.setModuleClass("com.methodhead.shim.MockModule");
0082:
0083:                page1_ = new Page();
0084:                page1_.set("title", "Page1");
0085:                page1_.set("alttitle", "altPage1");
0086:                page1_.set("aliasname", "page1");
0087:                page1_.setBoolean("hidden", false);
0088:                page1_.setString("template", "template.jsp");
0089:                page1_.set("metadescription", "metadescription");
0090:                page1_.set("metakeywords", "metakeywords");
0091:                page1_.addPanel(panel);
0092:                page1_.setSiteContext(SiteContext.getDefaultContext());
0093:                page1_.saveNew();
0094:
0095:                page2_ = new Page();
0096:                page2_.set("title", "Page2");
0097:                page2_.set("aliasname", "page2");
0098:                page2_.setBoolean("hidden", true);
0099:                page2_.setString("template", "template.jsp");
0100:                page2_.addPanel(panel);
0101:                page2_.setSiteContext(SiteContext.getDefaultContext());
0102:                page2_.saveNew();
0103:
0104:                page3_ = new Page();
0105:                page3_.set("title", "Page3");
0106:                page3_.set("aliasname", "page3");
0107:                page3_.setBoolean("hidden", false);
0108:                page3_.setString("template", "template.jsp");
0109:                page3_.addPanel(panel);
0110:                page3_.setSiteContext(SiteContext.getDefaultContext());
0111:                page3_.saveNew();
0112:
0113:                page4_ = new Page();
0114:                page4_.set("title", "Page4");
0115:                page4_.set("aliasname", "page4");
0116:                page4_.setBoolean("hidden", false);
0117:                page4_.setString("template", "template.jsp");
0118:                page4_.addPanel(panel);
0119:                page4_.setSiteContext(SiteContext.getDefaultContext());
0120:                page4_.saveNew();
0121:
0122:                page5_ = new Page();
0123:                page5_.set("title", "Page5");
0124:                page5_.set("aliasname", "page5");
0125:                page5_.setBoolean("hidden", false);
0126:                page5_.setString("template", "template.jsp");
0127:                page5_.addPanel(panel);
0128:                page5_.setSiteContext(SiteContext.getDefaultContext());
0129:                page5_.saveNew();
0130:            }
0131:
0132:            private void createSiteMap() {
0133:
0134:                link1_ = new Link();
0135:                link1_.setPageId(1);
0136:                link1_.setTitle("Page1");
0137:                link1_.setAlias("page1");
0138:
0139:                link2_ = new Link();
0140:                link2_.setPageId(2);
0141:                link2_.setTitle("Page2");
0142:                link2_.setAlias("page2");
0143:
0144:                link3_ = new Link();
0145:                link3_.setPageId(3);
0146:                link3_.setTitle("Page3");
0147:                link3_.setAlias("page3");
0148:
0149:                link4_ = new Link();
0150:                link4_.setPageId(4);
0151:                link4_.setTitle("Page4");
0152:                link4_.setAlias("page4");
0153:
0154:                link5_ = new Link();
0155:                link5_.setPageId(5);
0156:                link5_.setTitle("Page5");
0157:                link5_.setAlias("page5");
0158:
0159:                link1_.add(link2_);
0160:                link2_.add(link3_);
0161:                link1_.add(link4_);
0162:                link1_.add(link5_);
0163:
0164:                SiteMap siteMap = ShimUtils.getSiteMap(request);
0165:                siteMap.setRoot(link1_);
0166:                siteMap.save();
0167:
0168:                SiteMapTree tree = (SiteMapTree) getSession().getAttribute(
0169:                        ShimGlobals.SITEMAPTREE_KEY);
0170:                tree.build(siteMap);
0171:            }
0172:
0173:            public PageActionTest(String name) {
0174:                super (name);
0175:            }
0176:
0177:            public void setUp() throws Exception {
0178:
0179:                TestData.createWebappFiles(ServletUtils
0180:                        .getRealFile(request, ""));
0181:
0182:                //setLogLevel( Level.DEBUG );
0183:                try {
0184:                    ConnectionSingleton.runBatchUpdate(new FileReader(
0185:                            "webapp/WEB-INF/db/transfer-reset.sql"));
0186:
0187:                    super .setUp();
0188:
0189:                    //
0190:                    // login an admin
0191:                    //
0192:                    TestData.createUsers();
0193:                    AuthUtil.setUser(getRequest(), TestData.user1);
0194:
0195:                    //
0196:                    // use the default site context
0197:                    //
0198:                    getSession().setAttribute(SiteContext.SITECONTEXT_KEY,
0199:                            SiteContext.getDefaultContext());
0200:
0201:                    getSession().removeAttribute(ShimGlobals.SITEMAPTREE_KEY);
0202:                    getSession().getServletContext().removeAttribute(
0203:                            ShimGlobals.SITEMAPMAP_KEY);
0204:
0205:                    //
0206:                    // set up the tree
0207:                    //
0208:                    tree = new SiteMapTree();
0209:                    tree.build(ShimUtils.getSiteMap(request));
0210:                    getSession().setAttribute(ShimGlobals.SITEMAPTREE_KEY,
0211:                            new SiteMapTree());
0212:                } catch (Exception e) {
0213:                    fail(e.getMessage());
0214:                }
0215:            }
0216:
0217:            public void tearDown() throws Exception {
0218:
0219:                super .tearDown();
0220:            }
0221:
0222:            public void testDoNewPageForm() throws Exception {
0223:                PageForm form = null;
0224:                List l = null;
0225:                LabelValueBean option = null;
0226:
0227:                //
0228:                // without site map destination
0229:                //
0230:                setRequestPathInfo("/newPageForm");
0231:                actionPerform();
0232:
0233:                verifyForward("form");
0234:
0235:                form = (PageForm) getActionForm();
0236:                l = (List) form.get("templates");
0237:
0238:                assertEquals("", form.get("destid"));
0239:                assertEquals("", form.get("position"));
0240:
0241:                assertEquals(5, l.size());
0242:
0243:                option = (LabelValueBean) l.get(0);
0244:
0245:                assertEquals("", option.getValue());
0246:                assertEquals("Select...", option.getLabel());
0247:
0248:                option = (LabelValueBean) l.get(1);
0249:
0250:                assertEquals("template.jsp", option.getValue());
0251:                assertEquals("Template", option.getLabel());
0252:            }
0253:
0254:            public void testDoNewPageFormWithSiteMapDest() throws Exception {
0255:                PageForm form = null;
0256:                List l = null;
0257:                LabelValueBean option = null;
0258:
0259:                //
0260:                // with site map destination
0261:                //
0262:                setRequestPathInfo("/newPageForm");
0263:                addRequestParameter("destid", "666");
0264:                addRequestParameter("position", "under");
0265:                actionPerform();
0266:
0267:                verifyForward("form");
0268:
0269:                form = (PageForm) getActionForm();
0270:                l = (List) form.get("templates");
0271:
0272:                assertEquals("666", form.get("destid"));
0273:                assertEquals("under", form.get("position"));
0274:
0275:                assertEquals(5, l.size());
0276:
0277:                option = (LabelValueBean) l.get(0);
0278:
0279:                assertEquals("", option.getValue());
0280:                assertEquals("Select...", option.getLabel());
0281:
0282:                option = (LabelValueBean) l.get(1);
0283:
0284:                assertEquals("template.jsp", option.getValue());
0285:                assertEquals("Template", option.getLabel());
0286:            }
0287:
0288:            public void testDoConfigurePageForm() throws Exception {
0289:                createData();
0290:
0291:                addRequestParameter("id", "" + page1_.getInt("id"));
0292:                setRequestPathInfo("/configurePageForm");
0293:                actionPerform();
0294:
0295:                verifyForward("form");
0296:
0297:                //
0298:                // form initialization tested in testDoNewPageForm()
0299:                //
0300:                form = (PageForm) getActionForm();
0301:                assertEquals(page1_.getString("title"), form.get("title"));
0302:                assertEquals(page1_.getString("aliasname"), form.get("alias"));
0303:                assertEquals(page1_.getString("template"), form.get("template"));
0304:                assertEquals("altPage1", form.get("alttitle"));
0305:                assertEquals("metadescription", form.get("metadescription"));
0306:                assertEquals("metakeywords", form.get("metakeywords"));
0307:            }
0308:
0309:            public void testDoConfigurePageFormHiddenPage() throws Exception {
0310:                createData();
0311:
0312:                //
0313:                // a page with hidden set to true
0314:                //
0315:                addRequestParameter("id", "" + page2_.getInt("id"));
0316:                setRequestPathInfo("/configurePageForm");
0317:                actionPerform();
0318:
0319:                verifyForward("form");
0320:
0321:                //
0322:                // form initialization tested in testDoNewPageForm()
0323:                //
0324:                form = (PageForm) getActionForm();
0325:                assertEquals("yes", form.get("hidden"));
0326:            }
0327:
0328:            public void testDoConfigurePageNewCancel() {
0329:                try {
0330:                    //
0331:                    // cancelling
0332:                    //
0333:                    setRequestPathInfo("/configurePage");
0334:                    addRequestParameter("cancel", "Cancel");
0335:                    actionPerform();
0336:
0337:                    verifyForwardPath("/home.do");
0338:                } catch (Exception e) {
0339:                    e.printStackTrace();
0340:                    fail();
0341:                }
0342:            }
0343:
0344:            public void testDoConfigurePageNew() {
0345:                try {
0346:                    //
0347:                    // no dest with an empty site map
0348:                    //
0349:                    clearRequestParameters();
0350:                    setRequestPathInfo("/configurePage");
0351:                    addRequestParameter("title", "Page1");
0352:                    addRequestParameter("alias", "page1");
0353:                    addRequestParameter("hidden", "");
0354:                    addRequestParameter("template", "template.jsp");
0355:                    addRequestParameter("alttitle", "alttitle");
0356:                    addRequestParameter("metadescription", "metadescription");
0357:                    addRequestParameter("metakeywords", "metakeywords");
0358:                    actionPerform();
0359:
0360:                    verifyForwardPath("/editPage.do?id=1");
0361:
0362:                    page = new Page();
0363:                    page.setSiteContext(SiteContext.getDefaultContext());
0364:                    page.load(new IntKey(1));
0365:
0366:                    assertEquals("Page1", page.getString("title"));
0367:                    assertEquals("page1", page.getString("aliasname"));
0368:                    assertEquals(false, page.getBoolean("hidden"));
0369:                    assertEquals("template.jsp", page.getString("template"));
0370:                    assertEquals("alttitle", page.getString("alttitle"));
0371:                    assertEquals("metadescription", page
0372:                            .getString("metadescription"));
0373:                    assertEquals("metakeywords", page.getString("metakeywords"));
0374:
0375:                    assertNotNull(page.getPanels());
0376:                    assertEquals(1, page.getPanels().size());
0377:
0378:                    panel = (Panel) page.getPanels().get("body");
0379:
0380:                    assertEquals("body", panel.getName());
0381:                    assertEquals(ShimGlobals.DEFAULT_MODULE, panel
0382:                            .getModuleClass());
0383:
0384:                    textModule = new TextModule();
0385:                    textModule.load("page_id=1 AND panel='body'");
0386:                    assertEquals("Insert your text here...", textModule
0387:                            .getString("value"));
0388:
0389:                    siteMap = ShimUtils.getSiteMap(request);
0390:                    link = (Link) siteMap.getRoot();
0391:                    assertNotNull(link);
0392:                    assertEquals("Page1", link.getTitle());
0393:                    assertEquals("page1", link.getAlias());
0394:                    assertEquals(false, link.getHidden());
0395:                    assertEquals(1, link.getPageId());
0396:                    assertEquals(0, link.getChildCount());
0397:
0398:                    siteMap = new SiteMap();
0399:                    siteMap.setSiteContext(SiteContext.getDefaultContext());
0400:                    siteMap.load();
0401:                    link = (Link) siteMap.getRoot();
0402:                    assertNotNull(link);
0403:                    assertEquals("Page1", link.getTitle());
0404:                    assertEquals("page1", link.getAlias());
0405:                    assertEquals(false, link.getHidden());
0406:                    assertEquals(1, link.getPageId());
0407:                    assertEquals(0, link.getChildCount());
0408:
0409:                    tree = (SiteMapTree) session
0410:                            .getAttribute(ShimGlobals.SITEMAPTREE_KEY);
0411:
0412:                    assertNotNull(tree);
0413:
0414:                    foldingNode = (FoldingTreeNode) tree.getRoot();
0415:
0416:                    assertNotNull(tree);
0417:                    assertEquals("Page1", foldingNode.getLabel());
0418:                    assertEquals(new Integer(1), foldingNode.getUserObject());
0419:                    assertEquals("editPage.do?id=1", foldingNode.getUrl());
0420:                    assertEquals("PAGE", foldingNode.getIconHint());
0421:                    assertEquals(0, foldingNode.getChildCount());
0422:                } catch (Exception e) {
0423:                    e.printStackTrace();
0424:                    fail();
0425:                }
0426:            }
0427:
0428:            public void testDoConfigurePage_NewAutoAlias() {
0429:                try {
0430:
0431:                    //
0432:                    // new page with out alias; alias should be automatically be generated
0433:                    //
0434:                    setRequestPathInfo("/configurePage");
0435:                    addRequestParameter("id", "");
0436:                    addRequestParameter("title", "Page1");
0437:                    addRequestParameter("alias", "");
0438:                    addRequestParameter("template", "template.jsp");
0439:                    actionPerform();
0440:
0441:                    verifyForwardPath("/editPage.do?id=1");
0442:
0443:                    page = new Page();
0444:                    page.setSiteContext(SiteContext.getDefaultContext());
0445:                    page.load(new IntKey(1));
0446:
0447:                    assertEquals("Page1", page.getString("title"));
0448:                    assertEquals("page1", page.getString("aliasname"));
0449:                    assertEquals("template.jsp", page.getString("template"));
0450:                } catch (Exception e) {
0451:                    e.printStackTrace();
0452:                    fail();
0453:                }
0454:            }
0455:
0456:            public void testDoConfigurePage_NewByCopy() {
0457:                try {
0458:                    createData();
0459:                    createSiteMap();
0460:
0461:                    MockModule.setCopied(false);
0462:
0463:                    setRequestPathInfo("/configurePage");
0464:                    addRequestParameter("id", "");
0465:                    addRequestParameter("title", "Page6");
0466:                    addRequestParameter("alias", "");
0467:                    addRequestParameter("template", "");
0468:                    addRequestParameter("copyfrom", "1");
0469:                    actionPerform();
0470:
0471:                    verifyForwardPath("/editPage.do?id=6");
0472:
0473:                    page = new Page();
0474:                    page.setSiteContext(SiteContext.getDefaultContext());
0475:                    page.load(new IntKey(6));
0476:
0477:                    assertEquals("Page6", page.getString("title"));
0478:                    assertEquals("", page.getString("alttitle"));
0479:                    assertEquals("page6", page.getString("aliasname"));
0480:                    assertEquals("template.jsp", page.getString("template"));
0481:                    assertEquals("metadescription", page
0482:                            .getString("metadescription"));
0483:                    assertEquals("metakeywords", page.getString("metakeywords"));
0484:
0485:                    panel = (Panel) page.getPanels().get("body");
0486:                    assertEquals("body", panel.getName());
0487:                    assertEquals("com.methodhead.shim.MockModule", panel
0488:                            .getModuleClass());
0489:                    assertEquals(true, MockModule.isCopied());
0490:                } catch (Exception e) {
0491:                    e.printStackTrace();
0492:                    fail();
0493:                }
0494:            }
0495:
0496:            public void testDoConfigurePageNewAutoAliasExisting() {
0497:                try {
0498:                    createData();
0499:
0500:                    //
0501:                    // alias should be automatically generated and incremented
0502:                    //
0503:                    setRequestPathInfo("/configurePage");
0504:                    addRequestParameter("title", "Page1");
0505:                    addRequestParameter("alias", "");
0506:                    addRequestParameter("template", "template.jsp");
0507:                    actionPerform();
0508:
0509:                    verifyForwardPath("/editPage.do?id=6");
0510:
0511:                    page = new Page();
0512:                    page.setSiteContext(SiteContext.getDefaultContext());
0513:                    page.load(new IntKey(6));
0514:
0515:                    assertEquals("Page1", page.getString("title"));
0516:                    assertEquals("page12", page.getString("aliasname"));
0517:                    assertEquals("template.jsp", page.getString("template"));
0518:                } catch (Exception e) {
0519:                    e.printStackTrace();
0520:                    fail();
0521:                }
0522:            }
0523:
0524:            public void testDoConfigurePageNewUnderRoot() {
0525:                try {
0526:                    Page page = null;
0527:                    Panel panel = null;
0528:                    TextModule textModule = null;
0529:                    DynaActionForm form = null;
0530:                    SiteMap siteMap = null;
0531:                    Link link = null;
0532:                    SiteMapTree tree = null;
0533:                    FoldingTreeNode node = null;
0534:
0535:                    createData();
0536:                    createSiteMap();
0537:                    setRequestPathInfo("/configurePage");
0538:                    addRequestParameter("title", "Page6");
0539:                    addRequestParameter("alias", "page6");
0540:                    addRequestParameter("template", "template.jsp");
0541:                    actionPerform();
0542:
0543:                    verifyForwardPath("/editPage.do?id=6");
0544:
0545:                    //
0546:                    // just check the site map
0547:                    //
0548:                    siteMap = ShimUtils.getSiteMap(request);
0549:
0550:                    link = (Link) siteMap.getRoot();
0551:                    assertNotNull(link);
0552:                    assertEquals("Page1", link.getTitle());
0553:                    assertEquals("page1", link.getAlias());
0554:                    assertEquals(false, link.getHidden());
0555:                    assertEquals(1, link.getPageId());
0556:                    assertEquals(4, link.getChildCount());
0557:
0558:                    link = (Link) link.getChildAt(3);
0559:                    assertNotNull(link);
0560:                    assertEquals("Page6", link.getTitle());
0561:                    assertEquals("page6", link.getAlias());
0562:                    assertEquals(false, link.getHidden());
0563:                    assertEquals(6, link.getPageId());
0564:                    assertEquals(0, link.getChildCount());
0565:
0566:                    siteMap = new SiteMap();
0567:                    siteMap.setSiteContext(SiteContext.getDefaultContext());
0568:                    siteMap.load();
0569:                    link = (Link) siteMap.getRoot();
0570:
0571:                    assertNotNull(link);
0572:                    assertEquals("Page1", link.getTitle());
0573:                    assertEquals("page1", link.getAlias());
0574:                    assertEquals(false, link.getHidden());
0575:                    assertEquals(1, link.getPageId());
0576:                    assertEquals(4, link.getChildCount());
0577:
0578:                    link = (Link) link.getChildAt(3);
0579:
0580:                    assertNotNull(link);
0581:                    assertEquals("Page6", link.getTitle());
0582:                    assertEquals("page6", link.getAlias());
0583:                    assertEquals(false, link.getHidden());
0584:                    assertEquals(6, link.getPageId());
0585:                    assertEquals(0, link.getChildCount());
0586:
0587:                    tree = (SiteMapTree) session
0588:                            .getAttribute(ShimGlobals.SITEMAPTREE_KEY);
0589:
0590:                    assertNotNull(tree);
0591:
0592:                    node = (FoldingTreeNode) tree.getRoot();
0593:
0594:                    assertNotNull(node);
0595:                    assertEquals("Page1", node.getLabel());
0596:                    assertEquals(new Integer(1), node.getUserObject());
0597:                    assertEquals("editPage.do?id=1", node.getUrl());
0598:                    assertEquals("PAGE", node.getIconHint());
0599:                    assertEquals(4, node.getChildCount());
0600:
0601:                    node = (FoldingTreeNode) node.getChildAt(3);
0602:
0603:                    assertNotNull(node);
0604:                    assertEquals("Page6", node.getLabel());
0605:                    assertEquals(new Integer(6), node.getUserObject());
0606:                    assertEquals("editPage.do?id=6", node.getUrl());
0607:                    assertEquals("PAGE", node.getIconHint());
0608:                    assertEquals(0, node.getChildCount());
0609:                } catch (Exception e) {
0610:                    e.printStackTrace();
0611:                    fail();
0612:                }
0613:            }
0614:
0615:            public void testDoConfigurePageNewWithDestUnder() {
0616:                try {
0617:                    SiteMap siteMap = null;
0618:                    Link link = null;
0619:                    SiteMapTree tree = null;
0620:                    FoldingTreeNode node = null;
0621:
0622:                    //
0623:                    // no dest with the root set
0624:                    //
0625:                    createData();
0626:                    createSiteMap();
0627:
0628:                    setRequestPathInfo("/configurePage");
0629:                    addRequestParameter("title", "Page6");
0630:                    addRequestParameter("alias", "page6");
0631:                    addRequestParameter("template", "template.jsp");
0632:                    addRequestParameter("destid", "2");
0633:                    addRequestParameter("position", "under");
0634:                    actionPerform();
0635:
0636:                    verifyForwardPath("/editPage.do?id=6");
0637:
0638:                    //
0639:                    // just check the site map
0640:                    //
0641:                    siteMap = ShimUtils.getSiteMap(request);
0642:
0643:                    link = (Link) siteMap.find(2);
0644:                    assertNotNull(link);
0645:                    assertEquals(2, link.getChildCount());
0646:
0647:                    link = (Link) link.getChildAt(1);
0648:                    assertNotNull(link);
0649:                    assertEquals("Page6", link.getTitle());
0650:                    assertEquals("page6", link.getAlias());
0651:                    assertEquals(false, link.getHidden());
0652:                    assertEquals(6, link.getPageId());
0653:                    assertEquals(0, link.getChildCount());
0654:
0655:                    siteMap = new SiteMap();
0656:                    siteMap.setSiteContext(SiteContext.getDefaultContext());
0657:                    siteMap.load();
0658:                    link = (Link) siteMap.find(2);
0659:
0660:                    assertNotNull(link);
0661:                    assertEquals(2, link.getChildCount());
0662:
0663:                    link = (Link) link.getChildAt(1);
0664:
0665:                    assertNotNull(link);
0666:                    assertEquals("Page6", link.getTitle());
0667:                    assertEquals("page6", link.getAlias());
0668:                    assertEquals(false, link.getHidden());
0669:                    assertEquals(6, link.getPageId());
0670:                    assertEquals(0, link.getChildCount());
0671:
0672:                    tree = (SiteMapTree) session
0673:                            .getAttribute(ShimGlobals.SITEMAPTREE_KEY);
0674:
0675:                    assertNotNull(tree);
0676:
0677:                    node = (FoldingTreeNode) tree.find(2);
0678:
0679:                    assertNotNull(node);
0680:                    assertEquals(2, node.getChildCount());
0681:
0682:                    node = (FoldingTreeNode) node.getChildAt(1);
0683:
0684:                    assertNotNull(node);
0685:                    assertEquals("Page6", node.getLabel());
0686:                    assertEquals(new Integer(6), node.getUserObject());
0687:                    assertEquals("editPage.do?id=6", node.getUrl());
0688:                    assertEquals("PAGE", node.getIconHint());
0689:                    assertEquals(0, node.getChildCount());
0690:                } catch (Exception e) {
0691:                    e.printStackTrace();
0692:                    fail();
0693:                }
0694:            }
0695:
0696:            public void testDoConfigurePageNewWithDestBefore() {
0697:                try {
0698:                    //
0699:                    // no dest with the root set
0700:                    //
0701:                    createData();
0702:                    createSiteMap();
0703:
0704:                    setRequestPathInfo("/configurePage");
0705:                    addRequestParameter("title", "Page6");
0706:                    addRequestParameter("alias", "page6");
0707:                    addRequestParameter("template", "template.jsp");
0708:                    addRequestParameter("destid", "2");
0709:                    addRequestParameter("position", "before");
0710:                    actionPerform();
0711:
0712:                    verifyForwardPath("/editPage.do?id=6");
0713:
0714:                    //
0715:                    // just check the site map
0716:                    //
0717:                    siteMap = ShimUtils.getSiteMap(request);
0718:
0719:                    link = (Link) siteMap.find(1);
0720:                    assertNotNull(link);
0721:                    assertEquals(4, link.getChildCount());
0722:
0723:                    link = (Link) link.getChildAt(0);
0724:                    assertNotNull(link);
0725:                    assertEquals("Page6", link.getTitle());
0726:                    assertEquals("page6", link.getAlias());
0727:                    assertEquals(false, link.getHidden());
0728:                    assertEquals(6, link.getPageId());
0729:                    assertEquals(0, link.getChildCount());
0730:
0731:                    siteMap = new SiteMap();
0732:                    siteMap.setSiteContext(SiteContext.getDefaultContext());
0733:                    siteMap.load();
0734:                    link = (Link) siteMap.find(1);
0735:
0736:                    assertNotNull(link);
0737:                    assertEquals(4, link.getChildCount());
0738:
0739:                    link = (Link) link.getChildAt(0);
0740:
0741:                    assertNotNull(link);
0742:                    assertEquals("Page6", link.getTitle());
0743:                    assertEquals("page6", link.getAlias());
0744:                    assertEquals(false, link.getHidden());
0745:                    assertEquals(6, link.getPageId());
0746:                    assertEquals(0, link.getChildCount());
0747:
0748:                    tree = (SiteMapTree) session
0749:                            .getAttribute(ShimGlobals.SITEMAPTREE_KEY);
0750:
0751:                    assertNotNull(tree);
0752:
0753:                    foldingNode = (FoldingTreeNode) tree.find(1);
0754:
0755:                    assertNotNull(foldingNode);
0756:                    assertEquals(4, foldingNode.getChildCount());
0757:
0758:                    foldingNode = (FoldingTreeNode) foldingNode.getChildAt(0);
0759:
0760:                    assertNotNull(foldingNode);
0761:                    assertEquals("Page6", foldingNode.getLabel());
0762:                    assertEquals(new Integer(6), foldingNode.getUserObject());
0763:                    assertEquals("editPage.do?id=6", foldingNode.getUrl());
0764:                    assertEquals("PAGE", foldingNode.getIconHint());
0765:                    assertEquals(0, foldingNode.getChildCount());
0766:                } catch (Exception e) {
0767:                    e.printStackTrace();
0768:                    fail();
0769:                }
0770:            }
0771:
0772:            public void testDoConfigurePageNewWithDestAfter() {
0773:                try {
0774:                    SiteMap siteMap = null;
0775:                    Link link = null;
0776:                    SiteMapTree tree = null;
0777:                    FoldingTreeNode node = null;
0778:
0779:                    //
0780:                    // no dest with the root set
0781:                    //
0782:                    createData();
0783:                    createSiteMap();
0784:
0785:                    setRequestPathInfo("/configurePage");
0786:                    addRequestParameter("title", "Page6");
0787:                    addRequestParameter("template", "template.jsp");
0788:                    addRequestParameter("destid", "2");
0789:                    addRequestParameter("position", "after");
0790:                    actionPerform();
0791:
0792:                    verifyForwardPath("/editPage.do?id=6");
0793:
0794:                    //
0795:                    // just check the site map
0796:                    //
0797:                    siteMap = ShimUtils.getSiteMap(request);
0798:
0799:                    link = (Link) siteMap.find(1);
0800:                    assertNotNull(link);
0801:                    assertEquals(4, link.getChildCount());
0802:
0803:                    link = (Link) link.getChildAt(1);
0804:                    assertNotNull(link);
0805:                    assertEquals("Page6", link.getTitle());
0806:                    assertEquals("page6", link.getAlias());
0807:                    assertEquals(false, link.getHidden());
0808:                    assertEquals(6, link.getPageId());
0809:                    assertEquals(0, link.getChildCount());
0810:
0811:                    siteMap = new SiteMap();
0812:                    siteMap.setSiteContext(SiteContext.getDefaultContext());
0813:                    siteMap.load();
0814:                    link = (Link) siteMap.find(1);
0815:
0816:                    assertNotNull(link);
0817:                    assertEquals(4, link.getChildCount());
0818:
0819:                    link = (Link) link.getChildAt(1);
0820:
0821:                    assertNotNull(link);
0822:                    assertEquals("Page6", link.getTitle());
0823:                    assertEquals("page6", link.getAlias());
0824:                    assertEquals(false, link.getHidden());
0825:                    assertEquals(6, link.getPageId());
0826:                    assertEquals(0, link.getChildCount());
0827:
0828:                    tree = (SiteMapTree) session
0829:                            .getAttribute(ShimGlobals.SITEMAPTREE_KEY);
0830:
0831:                    assertNotNull(tree);
0832:
0833:                    node = (FoldingTreeNode) tree.find(1);
0834:
0835:                    assertNotNull(node);
0836:                    assertEquals(4, node.getChildCount());
0837:
0838:                    node = (FoldingTreeNode) node.getChildAt(1);
0839:
0840:                    assertNotNull(node);
0841:                    assertEquals("Page6", node.getLabel());
0842:                    assertEquals("page6", link.getAlias());
0843:                    assertEquals(false, link.getHidden());
0844:                    assertEquals(new Integer(6), node.getUserObject());
0845:                    assertEquals("editPage.do?id=6", node.getUrl());
0846:                    assertEquals("PAGE", node.getIconHint());
0847:                    assertEquals(0, node.getChildCount());
0848:                } catch (Exception e) {
0849:                    e.printStackTrace();
0850:                    fail();
0851:                }
0852:            }
0853:
0854:            public void testDoConfigurePageCancel() {
0855:                try {
0856:                    setRequestPathInfo("/configurePage");
0857:                    addRequestParameter("cancel", "Cancel");
0858:                    addRequestParameter("id", "1");
0859:                    actionPerform();
0860:
0861:                    verifyForwardPath("/editPage.do?id=1");
0862:                } catch (Exception e) {
0863:                    e.printStackTrace();
0864:                    fail();
0865:                }
0866:            }
0867:
0868:            public void testDoConfigurePage() {
0869:                try {
0870:                    Page page = null;
0871:                    Panel panel = null;
0872:                    TextModule textModule = null;
0873:                    DynaActionForm form = null;
0874:                    SiteMap siteMap = null;
0875:                    Link link = null;
0876:                    SiteMapTree tree = null;
0877:                    FoldingTreeNode node = null;
0878:
0879:                    createData();
0880:                    createSiteMap();
0881:                    setRequestPathInfo("/configurePage");
0882:                    addRequestParameter("id", "" + page1_.getInt("id"));
0883:                    addRequestParameter("title", "Page1 Updated");
0884:                    addRequestParameter("alias", "page1updated");
0885:                    addRequestParameter("hidden", "yes");
0886:                    addRequestParameter("template", "Template2.jsp");
0887:                    addRequestParameter("alttitle", "alttitle");
0888:                    addRequestParameter("metadescription", "metadescription");
0889:                    addRequestParameter("metakeywords", "metakeywords");
0890:                    actionPerform();
0891:
0892:                    verifyForwardPath("/editPage.do?id=1");
0893:
0894:                    page = new Page();
0895:                    page.setSiteContext(SiteContext.getDefaultContext());
0896:                    page.load(page1_.getKey());
0897:
0898:                    assertEquals("Page1 Updated", page.getString("title"));
0899:                    assertEquals("page1updated", page.getString("aliasname"));
0900:                    assertEquals(true, page.getBoolean("hidden"));
0901:                    assertEquals("Template2.jsp", page.getString("template"));
0902:
0903:                    assertNotNull(page.getPanels());
0904:                    assertEquals(2, page.getPanels().size());
0905:
0906:                    panel = (Panel) page.getPanels().get("body");
0907:
0908:                    assertEquals("body", panel.getName());
0909:                    assertEquals("com.methodhead.shim.MockModule", panel
0910:                            .getModuleClass());
0911:
0912:                    siteMap = ShimUtils.getSiteMap(request);
0913:                    link = (Link) siteMap.find(1);
0914:                    assertNotNull(link);
0915:                    assertEquals("Page1 Updated", link.getTitle());
0916:                    assertEquals("page1updated", link.getAlias());
0917:                    assertEquals(true, link.getHidden());
0918:
0919:                    siteMap = new SiteMap();
0920:                    siteMap.setSiteContext(SiteContext.getDefaultContext());
0921:                    siteMap.load();
0922:                    assertNotNull(link);
0923:                    assertEquals("Page1 Updated", link.getTitle());
0924:                    assertEquals("page1updated", link.getAlias());
0925:                    assertEquals(true, link.getHidden());
0926:
0927:                    tree = (SiteMapTree) session
0928:                            .getAttribute(ShimGlobals.SITEMAPTREE_KEY);
0929:
0930:                    assertNotNull(tree);
0931:
0932:                    node = (FoldingTreeNode) tree.find(1);
0933:
0934:                    assertNotNull(node);
0935:                    assertEquals("Page1 Updated", node.getLabel());
0936:                } catch (Exception e) {
0937:                    e.printStackTrace();
0938:                    fail();
0939:                }
0940:            }
0941:
0942:            public void testDoEditPage() {
0943:                try {
0944:                    createData();
0945:                    MockModule.setConfigurable(true);
0946:                    MockModule.setEditable(false);
0947:                    setRequestPathInfo("/editPage");
0948:                    addRequestParameter("id", "" + page1_.getInt("id"));
0949:                    actionPerform();
0950:
0951:                    verifyForward(null);
0952:                } catch (Exception e) {
0953:                    e.printStackTrace();
0954:                    fail();
0955:                }
0956:            }
0957:
0958:            public void endDoEditPage(WebResponse response) {
0959:                assertEquals(
0960:                        "\n<a href=\"configurePanelForm.do?pageid=1&panel=body\"><img title=\"Select Module\" border=0 align=\"middle\" src=\"approot/images/panel_module.gif\"></a> <a href=\"configureModule.do?pageid=1&panel=body\"><img title=\"Configure\" border=0 align=\"middle\" src=\"approot/images/panel_configure.gif\"></a>\nHello from MockModule.display().\n\n\n",
0961:                        response.getText());
0962:            }
0963:
0964:            public void testDoEditPageByAlias() {
0965:                try {
0966:                    createData();
0967:                    MockModule.setConfigurable(true);
0968:                    MockModule.setEditable(false);
0969:                    setRequestPathInfo("/editPage");
0970:                    addRequestParameter("alias", "page1");
0971:                    actionPerform();
0972:
0973:                    verifyForward(null);
0974:                } catch (Exception e) {
0975:                    e.printStackTrace();
0976:                    fail();
0977:                }
0978:            }
0979:
0980:            public void endDoEditPageByAlias(WebResponse response) {
0981:                assertEquals(
0982:                        "\n<a href=\"configurePanelForm.do?pageid=1&panel=body\"><img title=\"Select Module\" border=0 align=\"middle\" src=\"approot/images/panel_module.gif\"></a> <a href=\"configureModule.do?pageid=1&panel=body\"><img title=\"Configure\" border=0 align=\"middle\" src=\"approot/images/panel_configure.gif\"></a>\nHello from MockModule.display().\n\n\n",
0983:                        response.getText());
0984:            }
0985:
0986:            public void testDoEditPageByAliasPageNotFound() {
0987:                createData();
0988:
0989:                MockModule.setConfigurable(true);
0990:                MockModule.setEditable(false);
0991:
0992:                setRequestPathInfo("/editPage");
0993:                addRequestParameter("alias", "invalidalias");
0994:                actionPerform();
0995:
0996:                verifyForward("pageNotFound");
0997:            }
0998:
0999:            public void testDoEditPageByAliasPageNotFoundWithPage()
1000:                    throws Exception {
1001:                TestData.createPageNotFoundPage();
1002:                TestData.createWebappFiles(ServletUtils
1003:                        .getRealFile(request, ""));
1004:
1005:                setRequestPathInfo("/editPage");
1006:                addRequestParameter("alias", "invalidalias");
1007:                actionPerform();
1008:            }
1009:
1010:            public void endDoEditPageByAliasPageNotFoundWithPage(
1011:                    WebResponse webResponse) {
1012:                assertEquals("This is a template.\n", webResponse.getText());
1013:            }
1014:
1015:            public void testDoConfigureModule() {
1016:                try {
1017:                    Page page = null;
1018:                    Panel panel = null;
1019:
1020:                    panel = new Panel();
1021:                    panel.setName("body");
1022:                    panel.setModuleClass("com.methodhead.shim.MockModule");
1023:                    page = new Page();
1024:                    page.setString("template", "template.jsp");
1025:                    page.addPanel(panel);
1026:                    page.setSiteContext(SiteContext.getDefaultContext());
1027:                    page.saveNew();
1028:                    setRequestPathInfo("/configureModule");
1029:                    addRequestParameter("pageid", "" + page.getInt("id"));
1030:                    addRequestParameter("panel", "body");
1031:                    actionPerform();
1032:
1033:                    verifyForward("accessDenied"); // this is what MockModule returns
1034:                } catch (Exception e) {
1035:                    e.printStackTrace();
1036:                    fail();
1037:                }
1038:            }
1039:
1040:            public void testDoEditPanel() {
1041:                try {
1042:                    Page page = null;
1043:                    Panel panel = null;
1044:
1045:                    panel = new Panel();
1046:                    panel.setName("body");
1047:                    panel.setModuleClass("com.methodhead.shim.MockModule");
1048:                    page = new Page();
1049:                    page.setString("title", "Page1");
1050:                    page.setString("template", "template.jsp");
1051:                    page.addPanel(panel);
1052:                    page.setSiteContext(SiteContext.getDefaultContext());
1053:                    page.saveNew();
1054:                    setRequestPathInfo("/editPanel");
1055:                    addRequestParameter("pageid", "" + page.getInt("id"));
1056:                    addRequestParameter("panel", "body");
1057:                    actionPerform();
1058:
1059:                    verifyForward("editor");
1060:
1061:                    DynaActionForm form = (DynaActionForm) getActionForm();
1062:
1063:                    assertEquals("Page1", form.get("title"));
1064:                } catch (Exception e) {
1065:                    e.printStackTrace();
1066:                    fail();
1067:                }
1068:            }
1069:
1070:            public void testDoEditPanelToolbar() {
1071:                try {
1072:                    Page page = null;
1073:                    Panel panel = null;
1074:
1075:                    panel = new Panel();
1076:                    panel.setName("body");
1077:                    panel.setModuleClass("com.methodhead.shim.MockModule");
1078:                    page = new Page();
1079:                    page.setString("template", "template.jsp");
1080:                    page.addPanel(panel);
1081:                    page.setSiteContext(SiteContext.getDefaultContext());
1082:                    page.saveNew();
1083:                    setRequestPathInfo("/editPanel");
1084:                    addRequestParameter("pageid", "" + page.getInt("id"));
1085:                    addRequestParameter("panel", "body");
1086:                    addRequestParameter("toolbar", "yes");
1087:                    actionPerform();
1088:
1089:                    verifyForward("toolbar");
1090:                } catch (Exception e) {
1091:                    e.printStackTrace();
1092:                    fail();
1093:                }
1094:            }
1095:
1096:            public void testDoEditPanelEditWin() {
1097:                try {
1098:                    Page page = null;
1099:                    Panel panel = null;
1100:
1101:                    panel = new Panel();
1102:                    panel.setName("body");
1103:                    panel.setModuleClass("com.methodhead.shim.MockModule");
1104:                    page = new Page();
1105:                    page.setString("template", "template.jsp");
1106:                    page.addPanel(panel);
1107:                    page.setSiteContext(SiteContext.getDefaultContext());
1108:                    page.saveNew();
1109:                    setRequestPathInfo("/editPanel");
1110:                    addRequestParameter("pageid", "" + page.getInt("id"));
1111:                    addRequestParameter("panel", "body");
1112:                    addRequestParameter("editWin", "yes");
1113:                    actionPerform();
1114:
1115:                    assertEquals(ShimGlobals.MODE_RICHEDIT, request
1116:                            .getAttribute(ShimGlobals.MODE_KEY));
1117:                    verifyForward(null);
1118:                } catch (Exception e) {
1119:                    e.printStackTrace();
1120:                    fail();
1121:                }
1122:            }
1123:
1124:            public void testDoSavePanel() {
1125:                try {
1126:                    Page page = null;
1127:                    Panel panel = null;
1128:
1129:                    panel = new Panel();
1130:                    panel.setName("body");
1131:                    panel.setModuleClass("com.methodhead.shim.MockModule");
1132:                    page = new Page();
1133:                    page.setString("template", "template.jsp");
1134:                    page.addPanel(panel);
1135:                    page.setSiteContext(SiteContext.getDefaultContext());
1136:                    page.saveNew();
1137:                    setRequestPathInfo("/savePanel");
1138:                    addRequestParameter("pageid", "" + page.getInt("id"));
1139:                    addRequestParameter("panel", "body");
1140:                    addRequestParameter("text", "Test text.");
1141:                    actionPerform();
1142:
1143:                    assertEquals("Test text.", MockModule.getText());
1144:                    verifyForwardPath("/editPage.do?id=" + page.getInt("id"));
1145:                } catch (Exception e) {
1146:                    e.printStackTrace();
1147:                    fail();
1148:                }
1149:            }
1150:
1151:            public void testApplyTemplate() {
1152:                try {
1153:                    Page page = null;
1154:                    Panel panel = null;
1155:                    Panel panelConfig = null;
1156:                    Template template = null;
1157:                    TextModule textModule = null;
1158:
1159:                    //
1160:                    // apply a template to a page with no panels
1161:                    //
1162:                    page = new Page();
1163:                    page.setSiteContext(SiteContext.getDefaultContext());
1164:                    page.saveNew();
1165:                    template = new Template();
1166:                    template.setSiteContext(SiteContext.getDefaultContext());
1167:                    template.load(request, "Template2.jsp");
1168:
1169:                    PageAction.applyTemplate(page, template);
1170:                    page.save();
1171:
1172:                    assertEquals(2, page.getPanels().keySet().size());
1173:
1174:                    panel = (Panel) page.getPanels().get("body");
1175:
1176:                    assertEquals("com.methodhead.shim.TextModule", panel
1177:                            .getModuleClass());
1178:
1179:                    module = panel.getModule();
1180:
1181:                    assertNotNull(module);
1182:                    assertEquals(TextModule.class, module.getClass());
1183:
1184:                    textModule = new TextModule();
1185:                    textModule.init(page, "body");
1186:                    textModule.load();
1187:
1188:                    assertEquals("Insert your text here...", textModule
1189:                            .getString("value"));
1190:
1191:                    textModule.init(page, "body");
1192:                    textModule.load();
1193:
1194:                    assertEquals("Insert your text here...", textModule
1195:                            .getString("value"));
1196:
1197:                    //
1198:                    // update the body text so we can verify that it didn't get changed on
1199:                    // the next applyTemplate()
1200:                    //
1201:                    textModule.setString("value", "Updated text.");
1202:                    textModule.save();
1203:
1204:                    //
1205:                    // apply a template without the footer panel
1206:                    //
1207:                    page.loadFull(page.getKey());
1208:                    template = new Template();
1209:                    template.setSiteContext(SiteContext.getDefaultContext());
1210:                    template.load(request, "template.jsp");
1211:
1212:                    PageAction.applyTemplate(page, template);
1213:
1214:                    assertEquals(1, page.getPanels().keySet().size());
1215:
1216:                    panel = (Panel) page.getPanels().get("body");
1217:
1218:                    assertEquals("com.methodhead.shim.TextModule", panel
1219:                            .getModuleClass());
1220:
1221:                    textModule = new TextModule();
1222:                    textModule.init(page, "body");
1223:                    textModule.load();
1224:
1225:                    assertEquals("Updated text.", textModule.getString("value"));
1226:
1227:                    try {
1228:                        textModule = new TextModule();
1229:                        textModule.load("page_id=" + page.getInt("id")
1230:                                + " AND panel='footer'");
1231:                        fail("Text module still in the database.");
1232:                    } catch (Exception e) {
1233:                        // success
1234:                    }
1235:                } catch (Exception e) {
1236:                    e.printStackTrace();
1237:                    fail();
1238:                }
1239:            }
1240:
1241:            public void testDoDeletePageForm() {
1242:                try {
1243:                    DynaActionForm form = null;
1244:
1245:                    createData();
1246:                    createSiteMap();
1247:                    setRequestPathInfo("/deletePageForm");
1248:                    addRequestParameter("id", "" + page1_.getInt("id"));
1249:                    actionPerform();
1250:
1251:                    verifyForward("form");
1252:
1253:                    form = (DynaActionForm) getActionForm();
1254:
1255:                    assertEquals("Page1", form.get("title"));
1256:                    assertEquals("1", form.get("id"));
1257:                    assertEquals("promote", form.get("delOption"));
1258:                } catch (Exception e) {
1259:                    e.printStackTrace();
1260:                    fail();
1261:                }
1262:            }
1263:
1264:            public void testDoDeletePageWithChildren() {
1265:                try {
1266:                    createData();
1267:                    createSiteMap();
1268:
1269:                    //
1270:                    // page with child pages
1271:                    //
1272:                    setRequestPathInfo("/deletePage");
1273:                    addRequestParameter("id", "" + page2_.getInt("id"));
1274:                    actionPerform();
1275:
1276:                    verifyForwardPath("/deletePageForm.do?id="
1277:                            + page2_.getInt("id"));
1278:                } catch (Exception e) {
1279:                    e.printStackTrace();
1280:                    fail();
1281:                }
1282:            }
1283:
1284:            public void testDoDeletePageCancel() {
1285:                try {
1286:                    createData();
1287:                    createSiteMap();
1288:
1289:                    //
1290:                    // cancel
1291:                    //
1292:                    setRequestPathInfo("/deletePage");
1293:                    addRequestParameter("cancel", "Cancel");
1294:                    addRequestParameter("id", "" + page1_.getInt("id"));
1295:                    actionPerform();
1296:
1297:                    verifyForwardPath("/editPage.do?id=" + page1_.getInt("id"));
1298:                } catch (Exception e) {
1299:                    e.printStackTrace();
1300:                    fail();
1301:                }
1302:            }
1303:
1304:            public void testDoDeletePageLeaf() {
1305:                try {
1306:                    SiteMap siteMap = null;
1307:                    Link link = null;
1308:                    Page page = null;
1309:                    SiteMapTree tree = null;
1310:
1311:                    createData();
1312:                    createSiteMap();
1313:                    MockModule.setDestroyed(false);
1314:                    setRequestPathInfo("/deletePage");
1315:                    addRequestParameter("confirm", "Confirm");
1316:                    addRequestParameter("id", "" + page4_.getInt("id"));
1317:                    actionPerform();
1318:
1319:                    verifyForwardPath("/editPage.do?id=" + page1_.getInt("id"));
1320:
1321:                    try {
1322:                        page = new Page();
1323:                        page.setSiteContext(SiteContext.getDefaultContext());
1324:                        page.load(page4_.getKey());
1325:                        fail("Page still in database.");
1326:                    } catch (Exception e) {
1327:                        // success
1328:                    }
1329:
1330:                    assertTrue(MockModule.isDestroyed());
1331:
1332:                    siteMap = new SiteMap();
1333:                    siteMap.setSiteContext(SiteContext.getDefaultContext());
1334:                    siteMap.load();
1335:
1336:                    assertNull(siteMap.find(page4_.getInt("id")));
1337:
1338:                    tree = (SiteMapTree) session
1339:                            .getAttribute(ShimGlobals.SITEMAPTREE_KEY);
1340:
1341:                    assertNull(tree.find(page4_.getInt("id")));
1342:                } catch (Exception e) {
1343:                    e.printStackTrace();
1344:                    fail();
1345:                }
1346:            }
1347:
1348:            public void testDoDeletePagePromoteChildren() {
1349:                try {
1350:                    SiteMap siteMap = null;
1351:                    Link link = null;
1352:                    Page page = null;
1353:                    SiteMapTree tree = null;
1354:                    DefaultMutableTreeNode node = null;
1355:
1356:                    createData();
1357:                    createSiteMap();
1358:                    MockModule.setDestroyed(false);
1359:                    setRequestPathInfo("/deletePage");
1360:                    addRequestParameter("confirm", "Confirm");
1361:                    addRequestParameter("delOption", "promote");
1362:                    addRequestParameter("id", "" + page2_.getInt("id"));
1363:                    actionPerform();
1364:
1365:                    verifyForwardPath("/editPage.do?id=" + page1_.getInt("id"));
1366:
1367:                    try {
1368:                        page = new Page();
1369:                        page.setSiteContext(SiteContext.getDefaultContext());
1370:                        page.load(page2_.getKey());
1371:                        fail("Page still in database.");
1372:                    } catch (Exception e) {
1373:                        // success
1374:                    }
1375:
1376:                    assertTrue(MockModule.isDestroyed());
1377:
1378:                    siteMap = new SiteMap();
1379:                    siteMap.setSiteContext(SiteContext.getDefaultContext());
1380:                    siteMap.load();
1381:
1382:                    assertNull(siteMap.find(page2_.getInt("id")));
1383:
1384:                    link = (Link) siteMap.getRoot();
1385:
1386:                    assertEquals(3, link.getChildCount());
1387:
1388:                    link = (Link) link.getChildAt(2);
1389:
1390:                    assertEquals(3, link.getPageId());
1391:
1392:                    tree = (SiteMapTree) session
1393:                            .getAttribute(ShimGlobals.SITEMAPTREE_KEY);
1394:
1395:                    assertNull(tree.find(page2_.getInt("id")));
1396:
1397:                    node = (DefaultMutableTreeNode) tree.getRoot();
1398:
1399:                    assertEquals(3, node.getChildCount());
1400:
1401:                    node = (DefaultMutableTreeNode) node.getChildAt(2);
1402:
1403:                    assertEquals(3, link.getPageId());
1404:                } catch (Exception e) {
1405:                    e.printStackTrace();
1406:                    fail();
1407:                }
1408:            }
1409:
1410:            public void testDoDeletePageDeleteChildren() {
1411:                try {
1412:                    SiteMap siteMap = null;
1413:                    Link link = null;
1414:                    Page page = null;
1415:
1416:                    createData();
1417:                    createSiteMap();
1418:                    MockModule.setDestroyed(false);
1419:                    setRequestPathInfo("/deletePage");
1420:                    addRequestParameter("confirm", "Confirm");
1421:                    addRequestParameter("delOption", "delete");
1422:                    addRequestParameter("id", "" + page2_.getInt("id"));
1423:                    actionPerform();
1424:
1425:                    verifyForwardPath("/editPage.do?id=" + page1_.getInt("id"));
1426:
1427:                    try {
1428:                        page = new Page();
1429:                        page.setSiteContext(SiteContext.getDefaultContext());
1430:                        page.load(page2_.getKey());
1431:                        fail("Page still in database.");
1432:                    } catch (Exception e) {
1433:                        // success
1434:                    }
1435:
1436:                    assertTrue(MockModule.isDestroyed());
1437:
1438:                    siteMap = new SiteMap();
1439:                    siteMap.setSiteContext(SiteContext.getDefaultContext());
1440:                    siteMap.load();
1441:
1442:                    assertNull(siteMap.find(page3_.getInt("id")));
1443:
1444:                    link = (Link) siteMap.getRoot();
1445:
1446:                    assertEquals(2, link.getChildCount());
1447:
1448:                    link = (Link) link.getChildAt(0);
1449:
1450:                    assertEquals(4, link.getPageId());
1451:                } catch (Exception e) {
1452:                    e.printStackTrace();
1453:                    fail();
1454:                }
1455:            }
1456:
1457:            public void testDoMovePageForm() {
1458:                try {
1459:                    createData();
1460:                    createSiteMap();
1461:                    setRequestPathInfo("/movePageForm");
1462:                    addRequestParameter("id", "" + page2_.getInt("id"));
1463:                    actionPerform();
1464:
1465:                    verifyForward("form");
1466:
1467:                    form = (DynaActionForm) getActionForm();
1468:
1469:                    assertEquals("" + page2_.getInt("id"), form.get("id"));
1470:                    assertEquals("before", form.get("position"));
1471:
1472:                    list = (List) form.get("pages");
1473:
1474:                    assertEquals(6, list.size());
1475:
1476:                    bean = (LabelValueBean) list.get(0);
1477:
1478:                    assertEquals("", bean.getValue());
1479:                    assertEquals("Select...", bean.getLabel());
1480:
1481:                    bean = (LabelValueBean) list.get(1);
1482:
1483:                    assertEquals("1", bean.getValue());
1484:                    assertEquals("Page1", bean.getLabel());
1485:
1486:                    bean = (LabelValueBean) list.get(2);
1487:
1488:                    assertEquals("2", bean.getValue());
1489:                    assertEquals("Page2", bean.getLabel());
1490:
1491:                    bean = (LabelValueBean) list.get(3);
1492:
1493:                    assertEquals("3", bean.getValue());
1494:                    assertEquals("Page3", bean.getLabel());
1495:
1496:                    bean = (LabelValueBean) list.get(4);
1497:
1498:                    assertEquals("4", bean.getValue());
1499:                    assertEquals("Page4", bean.getLabel());
1500:
1501:                    bean = (LabelValueBean) list.get(5);
1502:
1503:                    assertEquals("5", bean.getValue());
1504:                    assertEquals("Page5", bean.getLabel());
1505:                } catch (Exception e) {
1506:                    e.printStackTrace();
1507:                    fail();
1508:                }
1509:            }
1510:
1511:            public void testDoMovePageValidationMissingDest() throws Exception {
1512:                createData();
1513:                createSiteMap();
1514:                setRequestPathInfo("/movePage");
1515:                addRequestParameter("id", "" + page2_.getInt("id"));
1516:                addRequestParameter("position", "under");
1517:                actionPerform();
1518:
1519:                verifyInputForward();
1520:                verifyActionErrors(new String[] { "shim.movePageForm.missingDest" });
1521:            }
1522:
1523:            public void testDoMovePageValidationCannotMoveRoot()
1524:                    throws Exception {
1525:                createData();
1526:                createSiteMap();
1527:                setRequestPathInfo("/movePage");
1528:                addRequestParameter("id", "" + page1_.getInt("id"));
1529:                addRequestParameter("position", "under");
1530:                addRequestParameter("destid", "" + page2_.getInt("id"));
1531:                actionPerform();
1532:
1533:                verifyInputForward();
1534:                verifyActionErrors(new String[] { "shim.movePageForm.cannotMoveRoot" });
1535:            }
1536:
1537:            public void testDoMovePageValidationCannotMoveNearSelf()
1538:                    throws Exception {
1539:                createData();
1540:                createSiteMap();
1541:                setRequestPathInfo("/movePage");
1542:                addRequestParameter("id", "" + page2_.getInt("id"));
1543:                addRequestParameter("position", "under");
1544:                addRequestParameter("destid", "" + page2_.getInt("id"));
1545:                actionPerform();
1546:
1547:                verifyInputForward();
1548:                verifyActionErrors(new String[] { "shim.movePageForm.cannotMoveNearSelf" });
1549:            }
1550:
1551:            public void testDoMovePageValidationCannotMoveUnderSelf()
1552:                    throws Exception {
1553:                createData();
1554:                createSiteMap();
1555:                setRequestPathInfo("/movePage");
1556:                addRequestParameter("id", "" + page2_.getInt("id"));
1557:                addRequestParameter("position", "under");
1558:                addRequestParameter("destid", "" + page3_.getInt("id"));
1559:                actionPerform();
1560:
1561:                verifyInputForward();
1562:                verifyActionErrors(new String[] { "shim.movePageForm.cannotMoveUnderSelf" });
1563:            }
1564:
1565:            public void testDoMovePageValidationCannotMoveAfterRoot()
1566:                    throws Exception {
1567:                createData();
1568:                createSiteMap();
1569:                setRequestPathInfo("/movePage");
1570:                addRequestParameter("id", "" + page2_.getInt("id"));
1571:                addRequestParameter("position", "after");
1572:                addRequestParameter("destid", "" + page1_.getInt("id"));
1573:                actionPerform();
1574:
1575:                verifyInputForward();
1576:                verifyActionErrors(new String[] { "shim.movePageForm.cannotMoveAfterRoot" });
1577:            }
1578:
1579:            public void testDoMovePageValidationCannotMoveBeforeRoot()
1580:                    throws Exception {
1581:                createData();
1582:                createSiteMap();
1583:                setRequestPathInfo("/movePage");
1584:                addRequestParameter("id", "" + page2_.getInt("id"));
1585:                addRequestParameter("position", "before");
1586:                addRequestParameter("destid", "" + page1_.getInt("id"));
1587:                actionPerform();
1588:
1589:                verifyInputForward();
1590:                verifyActionErrors(new String[] { "shim.movePageForm.cannotMoveBeforeRoot" });
1591:            }
1592:
1593:            public void testDoMovePageCancel() {
1594:                try {
1595:                    createData();
1596:                    createSiteMap();
1597:                    setRequestPathInfo("/movePage");
1598:                    addRequestParameter("id", "" + page2_.getInt("id"));
1599:                    addRequestParameter("position", "under");
1600:                    addRequestParameter("cancel", "Cancel");
1601:                    actionPerform();
1602:
1603:                    verifyForwardPath("/editPage.do?id=" + page2_.getInt("id"));
1604:                } catch (Exception e) {
1605:                    e.printStackTrace();
1606:                    fail();
1607:                }
1608:            }
1609:
1610:            public void testDoMovePage() {
1611:                try {
1612:                    createData();
1613:                    createSiteMap();
1614:                    setRequestPathInfo("/movePage");
1615:                    addRequestParameter("id", "" + page2_.getInt("id"));
1616:                    addRequestParameter("destid", "" + page4_.getInt("id"));
1617:                    addRequestParameter("position", "under");
1618:                    actionPerform();
1619:
1620:                    verifyForwardPath("/editPage.do?id=" + page4_.getInt("id"));
1621:
1622:                    siteMap = new SiteMap();
1623:                    siteMap.setSiteContext(SiteContext.getDefaultContext());
1624:                    siteMap.load();
1625:                    link = (Link) siteMap.getRoot();
1626:
1627:                    assertNotNull(link);
1628:                    assertEquals(2, link.getChildCount());
1629:
1630:                    link = (Link) link.getChildAt(0);
1631:
1632:                    assertEquals(page4_.getInt("id"), link.getPageId());
1633:
1634:                    link = (Link) link.getChildAt(0);
1635:
1636:                    assertEquals(page2_.getInt("id"), link.getPageId());
1637:                    assertEquals(1, link.getChildCount());
1638:
1639:                    tree = ShimUtils.getSiteMapTree(request);
1640:                    node = tree.getRoot();
1641:
1642:                    assertNotNull(node);
1643:                    assertEquals(2, node.getChildCount());
1644:
1645:                    node = (DefaultMutableTreeNode) node.getChildAt(0);
1646:
1647:                    assertEquals(page4_.get("id"), node.getUserObject());
1648:
1649:                    node = (DefaultMutableTreeNode) node.getChildAt(0);
1650:
1651:                    assertEquals(page2_.get("id"), node.getUserObject());
1652:                    assertEquals(1, node.getChildCount());
1653:
1654:                    createSiteMap();
1655:                    clearRequestParameters();
1656:                    setRequestPathInfo("/movePage");
1657:                    addRequestParameter("id", "" + page2_.getInt("id"));
1658:                    addRequestParameter("destid", "" + page4_.getInt("id"));
1659:                    addRequestParameter("position", "after");
1660:                    actionPerform();
1661:
1662:                    verifyForwardPath("/editPage.do?id=" + page1_.getInt("id"));
1663:
1664:                    siteMap = new SiteMap();
1665:                    siteMap.setSiteContext(SiteContext.getDefaultContext());
1666:                    siteMap.load();
1667:                    link = (Link) siteMap.getRoot();
1668:
1669:                    assertNotNull(link);
1670:                    assertEquals(3, link.getChildCount());
1671:
1672:                    sublink = (Link) link.getChildAt(0);
1673:
1674:                    assertEquals(page4_.getInt("id"), sublink.getPageId());
1675:
1676:                    sublink = (Link) link.getChildAt(1);
1677:
1678:                    assertEquals(page2_.getInt("id"), sublink.getPageId());
1679:                    assertEquals(1, sublink.getChildCount());
1680:
1681:                    tree = ShimUtils.getSiteMapTree(request);
1682:                    node = tree.getRoot();
1683:
1684:                    assertNotNull(node);
1685:                    assertEquals(3, node.getChildCount());
1686:
1687:                    subnode = (DefaultMutableTreeNode) node.getChildAt(0);
1688:
1689:                    assertEquals(page4_.get("id"), subnode.getUserObject());
1690:
1691:                    subnode = (DefaultMutableTreeNode) node.getChildAt(1);
1692:
1693:                    assertEquals(page2_.get("id"), subnode.getUserObject());
1694:                    assertEquals(1, subnode.getChildCount());
1695:                } catch (Exception e) {
1696:                    e.printStackTrace();
1697:                    fail();
1698:                }
1699:            }
1700:
1701:            public void testDoConfigurePanelForm() {
1702:                try {
1703:                    createData();
1704:                    createSiteMap();
1705:                    setRequestPathInfo("/configurePanelForm");
1706:                    addRequestParameter("pageid", "" + page1_.getInt("id"));
1707:                    addRequestParameter("panel", "body");
1708:                    actionPerform();
1709:
1710:                    verifyForward("form");
1711:
1712:                    form = (DynaActionForm) getActionForm();
1713:                    list = (List) form.get("modules");
1714:
1715:                    assertNotNull(list);
1716:                    assertTrue(list.size() > 0);
1717:                    assertEquals("com.methodhead.shim.MockModule", form
1718:                            .get("module"));
1719:                } catch (Exception e) {
1720:                    e.printStackTrace();
1721:                    fail();
1722:                }
1723:            }
1724:
1725:            public void testDoConfigurePanel() throws Exception {
1726:                //
1727:                // cancel
1728:                //
1729:                createData();
1730:                createSiteMap();
1731:                MockModule.setDestroyed(false);
1732:                setRequestPathInfo("/configurePanel");
1733:                addRequestParameter("pageid", "" + page1_.getInt("id"));
1734:                addRequestParameter("panel", "body");
1735:                addRequestParameter("module", "com.methodhead.shim.TextModule");
1736:                addRequestParameter("cancel", "Cancel");
1737:                actionPerform();
1738:
1739:                verifyForwardPath("/editPage.do?id=" + page1_.getInt("id"));
1740:            }
1741:
1742:            public void testDoConfigurePanelSameModule() throws Exception {
1743:                //
1744:                // same module
1745:                //
1746:                createData();
1747:                createSiteMap();
1748:                MockModule.setDestroyed(false);
1749:                setRequestPathInfo("/configurePanel");
1750:                addRequestParameter("pageid", "" + page1_.getInt("id"));
1751:                addRequestParameter("panel", "body");
1752:                addRequestParameter("module", "com.methodhead.shim.MockModule");
1753:                addRequestParameter("cancel", "");
1754:                addRequestParameter("submit", "Submit");
1755:                actionPerform();
1756:
1757:                verifyForwardPath("/editPage.do?id=" + page1_.getInt("id"));
1758:
1759:                assertTrue(!MockModule.isDestroyed());
1760:            }
1761:
1762:            public void testDoConfigurePanelDifferentModule() throws Exception {
1763:                //
1764:                // different module
1765:                //
1766:                createData();
1767:                createSiteMap();
1768:                MockModule.setDestroyed(false);
1769:                setRequestPathInfo("/configurePanel");
1770:                addRequestParameter("pageid", "" + page1_.getInt("id"));
1771:                addRequestParameter("panel", "body");
1772:                addRequestParameter("module", "com.methodhead.shim.TextModule");
1773:                addRequestParameter("cancel", "");
1774:                addRequestParameter("submit", "Submit");
1775:                actionPerform();
1776:
1777:                verifyForwardPath("/editPage.do?id=" + page1_.getInt("id"));
1778:
1779:                assertTrue(MockModule.isDestroyed());
1780:
1781:                page = new Page();
1782:                page.setSiteContext(SiteContext.getDefaultContext());
1783:                page.load(page1_.getKey());
1784:                panel = (Panel) page.getPanels().get("body");
1785:
1786:                assertEquals("com.methodhead.shim.TextModule", panel
1787:                        .getModuleClass());
1788:
1789:                textModule = new TextModule();
1790:                textModule.init(page, "body");
1791:                textModule.load();
1792:
1793:                assertEquals("Insert your text here...", textModule
1794:                        .getString("value"));
1795:            }
1796:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.