Source Code Cross Referenced for TestCastorXmlPageManager.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » page » 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 » Portal » jetspeed 2.1.3 » org.apache.jetspeed.page 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Licensed to the Apache Software Foundation (ASF) under one or more
0003:         * contributor license agreements.  See the NOTICE file distributed with
0004:         * this work for additional information regarding copyright ownership.
0005:         * The ASF licenses this file to You under the Apache License, Version 2.0
0006:         * (the "License"); you may not use this file except in compliance with
0007:         * the License.  You may obtain a copy of the License at
0008:         * 
0009:         *      http://www.apache.org/licenses/LICENSE-2.0
0010:         * 
0011:         * Unless required by applicable law or agreed to in writing, software
0012:         * distributed under the License is distributed on an "AS IS" BASIS,
0013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         * See the License for the specific language governing permissions and
0015:         * limitations under the License.
0016:         */
0017:        package org.apache.jetspeed.page;
0018:
0019:        // Java imports
0020:        import java.util.ArrayList;
0021:        import java.util.Collection;
0022:        import java.util.Iterator;
0023:        import java.util.List;
0024:        import java.util.Locale;
0025:        import java.util.Map;
0026:
0027:        import junit.framework.Test;
0028:        import junit.framework.TestCase;
0029:        import junit.framework.TestSuite;
0030:
0031:        import org.apache.commons.collections.CollectionUtils;
0032:        import org.apache.jetspeed.JetspeedActions;
0033:        import org.apache.jetspeed.om.common.GenericMetadata;
0034:        import org.apache.jetspeed.om.common.SecurityConstraint;
0035:        import org.apache.jetspeed.om.common.SecurityConstraints;
0036:        import org.apache.jetspeed.om.folder.Folder;
0037:        import org.apache.jetspeed.om.folder.FolderNotFoundException;
0038:        import org.apache.jetspeed.om.folder.MenuDefinition;
0039:        import org.apache.jetspeed.om.folder.MenuExcludeDefinition;
0040:        import org.apache.jetspeed.om.folder.MenuIncludeDefinition;
0041:        import org.apache.jetspeed.om.folder.MenuOptionsDefinition;
0042:        import org.apache.jetspeed.om.folder.MenuSeparatorDefinition;
0043:        import org.apache.jetspeed.om.page.Document;
0044:        import org.apache.jetspeed.om.page.Fragment;
0045:        import org.apache.jetspeed.om.page.Link;
0046:        import org.apache.jetspeed.om.page.Page;
0047:        import org.apache.jetspeed.om.preference.FragmentPreference;
0048:        import org.apache.jetspeed.page.document.DocumentNotFoundException;
0049:        import org.apache.jetspeed.page.psml.CastorXmlPageManager;
0050:
0051:        /**
0052:         * TestCastorXmlPageManager
0053:         * 
0054:         * @author <a href="raphael@apache.org">Rapha\u00ebl Luta</a>
0055:         * @author <a href="rwatler@apache.org">Randy Watler</a>
0056:         * @version $Id: TestCastorXmlPageManager.java 553584 2007-07-05 18:09:45Z taylor $
0057:         */
0058:        public class TestCastorXmlPageManager extends TestCase implements 
0059:                PageManagerTestShared {
0060:            private String testPage002 = "/test002.psml";
0061:            private String testPage003 = "/test003.psml";
0062:            private String testPage004 = "/folder2/test004.psml";
0063:            private String testFolder2 = "/folder2";
0064:            private String testFolder3 = "/folder3";
0065:            private String testLink002 = "/test002.link";
0066:            private String testLink003 = "/test003.link";
0067:
0068:            protected CastorXmlPageManager pageManager;
0069:
0070:            /*
0071:             * (non-Javadoc)
0072:             * 
0073:             * @see junit.framework.TestCase#setUp()
0074:             */
0075:            protected void setUp() throws Exception {
0076:                super .setUp();
0077:                pageManager = Shared.makeCastorXMLPageManager("pages", false,
0078:                        false);
0079:            }
0080:
0081:            /**
0082:             * <p>
0083:             * tearDown
0084:             * </p>
0085:             * 
0086:             * @see junit.framework.TestCase#tearDown()
0087:             * @throws java.lang.Exception
0088:             */
0089:            protected void tearDown() throws Exception {
0090:                super .tearDown();
0091:            }
0092:
0093:            /**
0094:             * Defines the testcase name for JUnit.
0095:             * 
0096:             * @param name
0097:             *            the testcase's name.
0098:             */
0099:            public TestCastorXmlPageManager(String name) {
0100:                super (name);
0101:            }
0102:
0103:            /**
0104:             * Start the tests.
0105:             * 
0106:             * @param args
0107:             *            the arguments. Not used
0108:             */
0109:            public static void main(String args[]) {
0110:                junit.awtui.TestRunner
0111:                        .main(new String[] { TestCastorXmlPageManager.class
0112:                                .getName() });
0113:            }
0114:
0115:            /**
0116:             * Creates the test suite.
0117:             * 
0118:             * @return a test suite (<code>TestSuite</code>) that includes all
0119:             *         methods starting with "test"
0120:             */
0121:            public static Test suite() {
0122:                // All methods starting with "test" will be executed in the test suite.
0123:                return new TestSuite(TestCastorXmlPageManager.class);
0124:            }
0125:
0126:            public void testNewPage() {
0127:                Page testpage = pageManager.newPage(this .testPage003);
0128:                assertNotNull(testpage);
0129:                assertNotNull(testpage.getId());
0130:                assertNotNull(testpage.getPath());
0131:                assertEquals(testpage.getId(), testpage.getPath());
0132:                assertNotNull(testpage.getRootFragment());
0133:                assertNotNull(testpage.getRootFragment().getId());
0134:            }
0135:
0136:            public void testNewFragment() {
0137:                Fragment f = pageManager.newFragment();
0138:                assertNotNull(f);
0139:                assertNotNull(f.getId());
0140:                assertTrue(f.getType().equals(Fragment.LAYOUT));
0141:            }
0142:
0143:            public void testNewFolder() {
0144:                Folder testfolder = pageManager.newFolder(this .testFolder3);
0145:                assertNotNull(testfolder);
0146:                assertNotNull(testfolder.getId());
0147:                assertNotNull(testfolder.getPath());
0148:                assertEquals(testfolder.getId(), testfolder.getPath());
0149:            }
0150:
0151:            public void testNewLink() {
0152:                Link testlink = pageManager.newLink(this .testLink003);
0153:                assertNotNull(testlink);
0154:                assertNotNull(testlink.getId());
0155:                assertNotNull(testlink.getPath());
0156:                assertEquals(testlink.getId(), testlink.getPath());
0157:            }
0158:
0159:            public void testGetPage() throws Exception {
0160:                Page testpage = pageManager.getPage("/test001.psml");
0161:                assertNotNull(testpage);
0162:                assertTrue(testpage.getId().equals("/test001.psml"));
0163:                assertTrue(testpage.getTitle().equals("Test Page"));
0164:                assertTrue(testpage.getSkin().equals("test-skin"));
0165:                assertTrue(testpage.getEffectiveDefaultDecorator(
0166:                        Fragment.LAYOUT).equals("test-layout"));
0167:                assertTrue(testpage.getDefaultDecorator(Fragment.LAYOUT)
0168:                        .equals("test-layout"));
0169:                assertTrue(testpage.getDefaultDecorator(Fragment.PORTLET)
0170:                        .equals("test-portlet"));
0171:                assertTrue(testpage.getVersion().equals("2.77"));
0172:
0173:                GenericMetadata md = testpage.getMetadata();
0174:                Collection descriptions = md.getFields("description");
0175:                Collection subjects = md.getFields("subject");
0176:                assertEquals(2, descriptions.size());
0177:                assertEquals(1, subjects.size());
0178:
0179:                Fragment root = testpage.getRootFragment();
0180:                assertNotNull(root);
0181:                assertTrue(root.getId().equals("f001"));
0182:                assertTrue(root.getName().equals("TwoColumns"));
0183:                assertTrue(root.getType().equals(Fragment.LAYOUT));
0184:                assertNull(root.getDecorator());
0185:
0186:                List children = root.getFragments();
0187:                assertNotNull(children);
0188:                assertTrue(children.size() == 3);
0189:
0190:                Fragment f = (Fragment) children.get(0);
0191:                assertTrue(f.getId().equals("pe001"));
0192:                assertTrue(f.getName().equals("HelloPortlet"));
0193:                assertTrue(f.getType().equals(Fragment.PORTLET));
0194:
0195:                Map properties = f.getProperties();
0196:                assertNotNull(properties);
0197:                assertTrue(properties.size() == 7);
0198:                assertEquals("0", f.getProperty(Fragment.ROW_PROPERTY_NAME));
0199:                assertEquals(0, f.getIntProperty(Fragment.COLUMN_PROPERTY_NAME));
0200:                assertEquals(0, f.getLayoutRow());
0201:                assertEquals(0, f.getLayoutColumn());
0202:                assertNotNull(f.getProperty(Fragment.X_PROPERTY_NAME));
0203:                assertTrue(f.getProperty(Fragment.X_PROPERTY_NAME).startsWith(
0204:                        "11.1"));
0205:                assertTrue((f.getLayoutX() > 11.0F) && (f.getLayoutX() < 12.0F));
0206:                assertTrue((f.getFloatProperty(Fragment.X_PROPERTY_NAME) > 11.0F)
0207:                        && (f.getFloatProperty(Fragment.X_PROPERTY_NAME) < 12.0F));
0208:                assertTrue((f.getLayoutY() > 22.0F) && (f.getLayoutY() < 23.0F));
0209:                assertTrue((f.getLayoutZ() > 33.0F) && (f.getLayoutZ() < 34.0F));
0210:                assertTrue((f.getLayoutWidth() > 44.0F)
0211:                        && (f.getLayoutWidth() < 45.0F));
0212:                assertTrue((f.getLayoutHeight() > 55.0F)
0213:                        && (f.getLayoutWidth() < 56.0F));
0214:
0215:                List preferences = f.getPreferences();
0216:                assertNotNull(preferences);
0217:                assertTrue(preferences.size() == 2);
0218:                assertEquals("pref0", ((FragmentPreference) preferences.get(0))
0219:                        .getName());
0220:                assertTrue(((FragmentPreference) preferences.get(0))
0221:                        .isReadOnly());
0222:                assertNotNull(((FragmentPreference) preferences.get(0))
0223:                        .getValueList());
0224:                assertEquals(2, ((FragmentPreference) preferences.get(0))
0225:                        .getValueList().size());
0226:                assertEquals("pref0-value0",
0227:                        (String) ((FragmentPreference) preferences.get(0))
0228:                                .getValueList().get(0));
0229:                assertEquals("pref0-value1",
0230:                        (String) ((FragmentPreference) preferences.get(0))
0231:                                .getValueList().get(1));
0232:                assertEquals("pref1", ((FragmentPreference) preferences.get(1))
0233:                        .getName());
0234:                assertFalse(((FragmentPreference) preferences.get(1))
0235:                        .isReadOnly());
0236:                assertNotNull(((FragmentPreference) preferences.get(1))
0237:                        .getValueList());
0238:                assertEquals(1, ((FragmentPreference) preferences.get(1))
0239:                        .getValueList().size());
0240:                assertEquals("pref1-value",
0241:                        (String) ((FragmentPreference) preferences.get(1))
0242:                                .getValueList().get(0));
0243:
0244:                f = (Fragment) children.get(1);
0245:                assertTrue(f.getId().equals("pe002"));
0246:                assertTrue(f.getName().equals("JMXPortlet"));
0247:                assertTrue(f.getType().equals(Fragment.PORTLET));
0248:
0249:                properties = f.getProperties();
0250:                assertNotNull(properties);
0251:                assertTrue(properties.size() == 2);
0252:                assertEquals("0", f.getProperty(Fragment.ROW_PROPERTY_NAME));
0253:                assertEquals(1, f.getIntProperty(Fragment.COLUMN_PROPERTY_NAME));
0254:
0255:                f = testpage.getFragmentById("f002");
0256:                assertNotNull(f);
0257:                assertTrue(f.getId().equals("f002"));
0258:                assertTrue(f.getName().equals("Card"));
0259:                assertTrue(f.getType().equals(Fragment.LAYOUT));
0260:                assertTrue(f.getDecorator().equals("Tab"));
0261:                assertNotNull(f.getFragments());
0262:                assertTrue(f.getFragments().size() == 2);
0263:
0264:                List fragments = testpage.getFragmentsByName("JMXPortlet");
0265:                assertNotNull(fragments);
0266:                assertEquals(1, fragments.size());
0267:                assertTrue(((Fragment) fragments.get(0)).getId()
0268:                        .equals("pe002"));
0269:                assertTrue(((Fragment) fragments.get(0)).getName().equals(
0270:                        "JMXPortlet"));
0271:                assertTrue(((Fragment) fragments.get(0)).getType().equals(
0272:                        Fragment.PORTLET));
0273:            }
0274:
0275:            public void testCreatePage() throws Exception {
0276:                Page page = pageManager.newPage(this .testPage002);
0277:                System.out.println("Retrieved test_id in create "
0278:                        + this .testPage002);
0279:                page.setSkin("myskin");
0280:                page.setTitle("Created Page");
0281:                GenericMetadata metadata = page.getMetadata();
0282:                metadata.addField(Locale.FRENCH, "title",
0283:                        "Created Page de PSML");
0284:                metadata.addField(Locale.JAPANESE, "title",
0285:                        "Created \u3078\u3088\u3046\u3053\u305d");
0286:
0287:                Fragment root = page.getRootFragment();
0288:                root.setName("TestLayout");
0289:                Fragment f = pageManager.newFragment();
0290:                f.setType(Fragment.PORTLET);
0291:                f.setName("TestPortlet");
0292:                Map properties = f.getProperties();
0293:                properties.put(Fragment.ROW_PROPERTY_NAME, "0");
0294:                properties.put(Fragment.COLUMN_PROPERTY_NAME, "0");
0295:                root.getFragments().add(f);
0296:
0297:                SecurityConstraints constraints = page.newSecurityConstraints();
0298:                constraints.setOwner("new-user");
0299:                List constraintsList = new ArrayList(1);
0300:                SecurityConstraint constraint = page.newSecurityConstraint();
0301:                constraint.setUsers(Shared.makeListFromCSV("user10,user11"));
0302:                constraint.setRoles(Shared.makeListFromCSV("*"));
0303:                constraint.setPermissions(Shared
0304:                        .makeListFromCSV(JetspeedActions.EDIT + ","
0305:                                + JetspeedActions.VIEW));
0306:                constraintsList.add(constraint);
0307:                constraints.setSecurityConstraints(constraintsList);
0308:                List constraintsRefsList = new ArrayList(1);
0309:                constraintsRefsList.add("public-view");
0310:                constraints.setSecurityConstraintsRefs(constraintsRefsList);
0311:                page.setSecurityConstraints(constraints);
0312:
0313:                try {
0314:                    pageManager.updatePage(page);
0315:                } catch (Exception e) {
0316:                    String errmsg = "Exception in page update: " + e.toString();
0317:                    e.printStackTrace();
0318:                    System.err.println(errmsg);
0319:                    assertNotNull(errmsg, null);
0320:                }
0321:
0322:                page = pageManager.getPage(this .testPage002);
0323:                assertNotNull(page);
0324:                assertTrue(page.getId().equals(this .testPage002));
0325:                assertEquals("Created Page", page.getTitle());
0326:                assertEquals("Created Page de PSML", page
0327:                        .getTitle(Locale.FRENCH));
0328:                assertEquals("Created \u3078\u3088\u3046\u3053\u305d", page
0329:                        .getTitle(Locale.JAPANESE));
0330:                assertNotNull(page.getRootFragment());
0331:                assertTrue(page.getRootFragment().getName()
0332:                        .equals("TestLayout"));
0333:                assertTrue(page.getRootFragment().getFragments().size() == 1);
0334:
0335:                f = (Fragment) page.getRootFragment().getFragments().get(0);
0336:                assertNotNull(f.getProperties());
0337:                assertEquals(0, f.getIntProperty(Fragment.ROW_PROPERTY_NAME));
0338:            }
0339:
0340:            public void testCreateFolder() throws Exception {
0341:                Folder folder = pageManager.newFolder(this .testFolder2);
0342:                System.out.println("Retrieved test_id in create "
0343:                        + this .testFolder2);
0344:                folder.setTitle("Created Folder");
0345:                folder.setSkin("test-skin");
0346:                folder.setDefaultDecorator("test-layout", Fragment.LAYOUT);
0347:                folder.setDefaultDecorator("test-portlet", Fragment.PORTLET);
0348:
0349:                try {
0350:                    pageManager.updateFolder(folder);
0351:                } catch (Exception e) {
0352:                    String errmsg = "Exception in folder update: "
0353:                            + e.toString();
0354:                    e.printStackTrace();
0355:                    System.err.println(errmsg);
0356:                    assertNotNull(errmsg, null);
0357:                }
0358:
0359:                folder = pageManager.getFolder(this .testFolder2);
0360:                assertNotNull(folder);
0361:                assertTrue(folder.getId().equals(this .testFolder2));
0362:                assertTrue(folder.getTitle().equals("Created Folder"));
0363:                assertTrue(folder.getSkin().equals("test-skin"));
0364:                assertTrue(folder.getEffectiveDefaultDecorator(Fragment.LAYOUT)
0365:                        .equals("test-layout"));
0366:                assertTrue(folder.getDefaultDecorator(Fragment.LAYOUT).equals(
0367:                        "test-layout"));
0368:                assertTrue(folder.getDefaultDecorator(Fragment.PORTLET).equals(
0369:                        "test-portlet"));
0370:            }
0371:
0372:            public void testCreateLink() throws Exception {
0373:                Link link = pageManager.newLink(this .testLink002);
0374:                System.out.println("Retrieved test_id in create "
0375:                        + this .testLink002);
0376:                link.setTitle("Created Link");
0377:                link.setSkin("test-skin");
0378:                link.setUrl("http://www.created.link.com/");
0379:
0380:                try {
0381:                    pageManager.updateLink(link);
0382:                } catch (Exception e) {
0383:                    String errmsg = "Exception in link update: " + e.toString();
0384:                    e.printStackTrace();
0385:                    System.err.println(errmsg);
0386:                    assertNotNull(errmsg, null);
0387:                }
0388:
0389:                link = pageManager.getLink(this .testLink002);
0390:                assertNotNull(link);
0391:                assertTrue(link.getId().equals(this .testLink002));
0392:                assertTrue(link.getTitle().equals("Created Link"));
0393:                assertTrue(link.getSkin().equals("test-skin"));
0394:            }
0395:
0396:            public void testUpdatePage() throws Exception {
0397:                Page page = pageManager.getPage(this .testPage002);
0398:                page.setTitle("Updated Title");
0399:                Fragment root = page.getRootFragment();
0400:                assertNotNull(root);
0401:                assertNotNull(root.getFragments());
0402:                assertEquals(1, root.getFragments().size());
0403:                String testId = ((Fragment) root.getFragments().get(0)).getId();
0404:                assertNotNull(page.removeFragmentById(testId));
0405:
0406:                try {
0407:                    pageManager.updatePage(page);
0408:                } catch (Exception e) {
0409:                    String errmsg = "Exception in page update: " + e.toString();
0410:                    e.printStackTrace();
0411:                    System.err.println(errmsg);
0412:                    assertNotNull(errmsg, null);
0413:                }
0414:
0415:                page = pageManager.getPage(this .testPage002);
0416:                assertTrue(page.getTitle().equals("Updated Title"));
0417:                root = page.getRootFragment();
0418:                assertNotNull(root);
0419:                assertNotNull(root.getFragments());
0420:                assertTrue(root.getFragments().isEmpty());
0421:            }
0422:
0423:            public void testUpdateFolder() throws Exception {
0424:                Folder folder = pageManager.getFolder(this .testFolder2);
0425:                folder.setTitle("Updated Title");
0426:
0427:                try {
0428:                    pageManager.updateFolder(folder);
0429:                } catch (Exception e) {
0430:                    String errmsg = "Exception in folder update: "
0431:                            + e.toString();
0432:                    e.printStackTrace();
0433:                    System.err.println(errmsg);
0434:                    assertNotNull(errmsg, null);
0435:                }
0436:
0437:                folder = pageManager.getFolder(this .testFolder2);
0438:                assertTrue(folder.getTitle().equals("Updated Title"));
0439:
0440:                Page page = pageManager.newPage(this .testPage004);
0441:                page.setTitle("Folder Page");
0442:
0443:                try {
0444:                    pageManager.updatePage(page);
0445:                } catch (Exception e) {
0446:                    String errmsg = "Exception in page update: " + e.toString();
0447:                    e.printStackTrace();
0448:                    System.err.println(errmsg);
0449:                    assertNotNull(errmsg, null);
0450:                }
0451:
0452:                assertEquals(1, folder.getPages().size());
0453:                assertEquals(1, pageManager.getPages(folder).size());
0454:                assertNotNull(folder.getPages().get(this .testPage004));
0455:
0456:                folder.setTitle("Updated Deep Title");
0457:                page.setTitle("Updated Deep Title");
0458:
0459:                try {
0460:                    pageManager.updateFolder(folder, true);
0461:                } catch (Exception e) {
0462:                    String errmsg = "Exception in deep folder update: "
0463:                            + e.toString();
0464:                    e.printStackTrace();
0465:                    System.err.println(errmsg);
0466:                    assertNotNull(errmsg, null);
0467:                }
0468:
0469:                folder = pageManager.getFolder(this .testFolder2);
0470:                assertTrue(folder.getTitle().equals("Updated Deep Title"));
0471:                page = pageManager.getPage(this .testPage004);
0472:                assertTrue(page.getTitle().equals("Updated Deep Title"));
0473:            }
0474:
0475:            public void testUpdateLink() throws Exception {
0476:                Link link = pageManager.getLink(this .testLink002);
0477:                link.setTitle("Updated Title");
0478:
0479:                try {
0480:                    pageManager.updateLink(link);
0481:                } catch (Exception e) {
0482:                    String errmsg = "Exception in link update: " + e.toString();
0483:                    e.printStackTrace();
0484:                    System.err.println(errmsg);
0485:                    assertNotNull(errmsg, null);
0486:                }
0487:
0488:                link = pageManager.getLink(this .testLink002);
0489:                assertTrue(link.getTitle().equals("Updated Title"));
0490:            }
0491:
0492:            public void testGetFolders() throws Exception {
0493:
0494:                Folder subsites = pageManager.getFolder("/subsites");
0495:                assertNotNull(subsites);
0496:
0497:                Iterator ssi = subsites.getFolders().iterator();
0498:                assertTrue(ssi.hasNext());
0499:                int count = 0;
0500:                while (ssi.hasNext()) {
0501:                    Folder folder = (Folder) ssi.next();
0502:                    System.out.println("folder = " + folder.getName());
0503:                    count++;
0504:                }
0505:                assertEquals(4, count);
0506:            }
0507:
0508:            public void testFolders() throws Exception {
0509:
0510:                Folder folder1 = pageManager.getFolder("/folder1");
0511:                assertNotNull(folder1);
0512:                assertTrue(folder1.getSkin().equals("test-skin"));
0513:                assertTrue(folder1
0514:                        .getEffectiveDefaultDecorator(Fragment.LAYOUT).equals(
0515:                                "test-layout"));
0516:                assertTrue(folder1.getDefaultDecorator(Fragment.LAYOUT).equals(
0517:                        "test-layout"));
0518:                assertTrue(folder1.getDefaultDecorator(Fragment.PORTLET)
0519:                        .equals("test-portlet"));
0520:
0521:                assertEquals(2, folder1.getFolders().size());
0522:                assertEquals(2, pageManager.getFolders(folder1).size());
0523:                Iterator childItr = folder1.getFolders().iterator();
0524:                // Test that the folders are naturally orderd
0525:                Folder folder2 = (Folder) childItr.next();
0526:                assertEquals("/folder1/folder2", folder2.getPath());
0527:                assertEquals("folder2", folder2.getName());
0528:                Folder folder3 = (Folder) childItr.next();
0529:                assertEquals("/folder1/folder3", folder3.getPath());
0530:                assertEquals("test001.psml", folder3.getDefaultPage());
0531:                assertEquals(1, folder2.getPages().size());
0532:                assertEquals(2, folder3.getPages().size());
0533:                assertEquals(2, pageManager.getPages(folder3).size());
0534:
0535:                // test folder decoration inheritance
0536:                Page page = (Page) folder3.getPages().get("test001.psml");
0537:                assertTrue(page.getEffectiveDefaultDecorator(Fragment.LAYOUT)
0538:                        .equals("test-layout"));
0539:                assertTrue(page.getEffectiveDefaultDecorator(Fragment.PORTLET)
0540:                        .equals("test-portlet"));
0541:
0542:                // Check link order
0543:                assertEquals(6, folder3.getAll().size());
0544:                assertEquals(6, pageManager.getAll(folder3).size());
0545:                Iterator linkItr = folder3.getAll().iterator();
0546:                assertEquals("Jetspeed2Wiki.link", ((Link) linkItr.next())
0547:                        .getName());
0548:                assertEquals("Jetspeed2.link", ((Link) linkItr.next())
0549:                        .getName());
0550:                assertEquals("apache_portals.link", ((Link) linkItr.next())
0551:                        .getName());
0552:                assertEquals("apache.link", ((Link) linkItr.next()).getName());
0553:                assertEquals("test001.psml", ((Page) linkItr.next()).getName());
0554:                assertEquals("default-page.psml", ((Page) linkItr.next())
0555:                        .getName());
0556:
0557:                //Test FolderSet with both absolute and relative names
0558:                assertNotNull(folder1.getFolders().get("/folder1/folder2"));
0559:                assertNotNull(folder1.getFolders().get("folder2"));
0560:                assertEquals(folder1.getFolders().get("/folder1/folder2"),
0561:                        folder1.getFolders().get("folder2"));
0562:
0563:                //Test PageSet with both absolute and relative names
0564:                assertNotNull(folder3.getPages().get(
0565:                        "/folder1/folder3/test001.psml"));
0566:                assertNotNull(folder3.getPages().get("test001.psml"));
0567:                assertEquals("test001.psml", folder3.getPages().get(
0568:                        "/folder1/folder3/test001.psml").getName());
0569:
0570:                assertTrue(folder3.isHidden());
0571:                assertTrue(folder3.getPage("default-page.psml").isHidden());
0572:                assertTrue(folder3.getLinks().get("Jetspeed2.link").isHidden());
0573:                assertFalse(folder3.getLinks().get("apache.link").isHidden());
0574:
0575:                assertNotNull(folder3.getAll().get("Jetspeed2.link"));
0576:                assertNull(folder3.getAll().exclusiveSubset("Jetspeed2\\.link")
0577:                        .get("Jetspeed2.link"));
0578:                assertNull(folder3.getAll().inclusiveSubset("apache\\.link")
0579:                        .get("Jetspeed2.link"));
0580:                assertNotNull(folder3.getAll().inclusiveSubset("apache\\.link")
0581:                        .get("apache.link"));
0582:            }
0583:
0584:            public void testFolderMetaData() throws Exception {
0585:                Folder folder1French = pageManager.getFolder("/folder1");
0586:
0587:                assertEquals("Titre francais pour la chemise 1", folder1French
0588:                        .getTitle(Locale.FRENCH));
0589:                assertEquals("Titre francais pour la chemise 1", folder1French
0590:                        .getTitle(Locale.FRANCE));
0591:
0592:                Folder folder1English = pageManager.getFolder("/folder1");
0593:
0594:                assertEquals("English Title for Folder 1", folder1English
0595:                        .getTitle(Locale.ENGLISH));
0596:
0597:                // check that default works
0598:                Folder folder1German = pageManager.getFolder("/folder1");
0599:
0600:                assertEquals("Default Title for Folder 1", folder1German
0601:                        .getTitle(Locale.GERMAN));
0602:
0603:                // Test folder with no metadata assigned
0604:                Folder rootFolder = pageManager.getFolder("/");
0605:                assertEquals(rootFolder.getTitle(), rootFolder
0606:                        .getTitle(Locale.FRENCH));
0607:            }
0608:
0609:            public void testDefaultTitles() throws Exception {
0610:                Page defaultPage = pageManager
0611:                        .getPage("/folder1/folder2/default-page.psml");
0612:                assertNotNull(defaultPage);
0613:                assertEquals("Default Page", defaultPage.getTitle());
0614:
0615:                Folder rootFolder = pageManager.getFolder("/");
0616:                assertEquals("Top", rootFolder.getTitle());
0617:            }
0618:
0619:            public void testPageMetaData() throws Exception {
0620:                Page page = pageManager.getPage("/default-page.psml");
0621:                assertNotNull(page);
0622:                String frenchTitle = page.getTitle(Locale.FRENCH);
0623:                assertNotNull(frenchTitle);
0624:                assertEquals("Ma Premiere Page de PSML", frenchTitle);
0625:                String japaneseTitle = page.getTitle(Locale.JAPANESE);
0626:                assertNotNull(japaneseTitle);
0627:                assertEquals("Jetspeed 2 \u3078\u3088\u3046\u3053\u305d",
0628:                        japaneseTitle);
0629:                String defaultTitle = page.getTitle(Locale.GERMAN);
0630:                assertNotNull(defaultTitle);
0631:                assertEquals("My First PSML Page", defaultTitle);
0632:            }
0633:
0634:            public void testLinks() throws Exception {
0635:                Link link = pageManager.getLink("/apache_portals.link");
0636:                assertNotNull(link);
0637:                assertEquals("http://portals.apache.org", link.getUrl());
0638:                assertEquals("Apache Portals Website", link.getTitle());
0639:                assertEquals("Apache Software Foundation [french]", link
0640:                        .getTitle(Locale.FRENCH));
0641:                assertEquals("test-skin", link.getSkin());
0642:
0643:                Folder folder = pageManager.getFolder("/");
0644:                assertNotNull(folder);
0645:                assertNotNull(folder.getLinks());
0646:                assertEquals(2, folder.getLinks().size());
0647:                assertEquals(2, pageManager.getLinks(folder).size());
0648:                assertEquals("http://portals.apache.org", ((Document) folder
0649:                        .getLinks().get("/apache_portals.link")).getUrl());
0650:            }
0651:
0652:            public void testMenuDefinitions() throws Exception {
0653:                // test folder resident menu definitions
0654:                Folder folder = pageManager.getFolder("/");
0655:                assertNotNull(folder);
0656:                List menus = folder.getMenuDefinitions();
0657:                assertNotNull(menus);
0658:                assertEquals(5, menus.size());
0659:
0660:                MenuDefinition simpleMenu = (MenuDefinition) menus.get(0);
0661:                assertNotNull(simpleMenu);
0662:                assertEquals("simple", simpleMenu.getName());
0663:                assertNotNull(simpleMenu.getMenuElements());
0664:                assertEquals(1, simpleMenu.getMenuElements().size());
0665:                assertTrue(simpleMenu.getMenuElements().get(0) instanceof  MenuOptionsDefinition);
0666:                assertEquals("/test001.psml,/folder1/folder2",
0667:                        ((MenuOptionsDefinition) simpleMenu.getMenuElements()
0668:                                .get(0)).getOptions());
0669:
0670:                MenuDefinition top2LevelsMenu = (MenuDefinition) menus.get(1);
0671:                assertNotNull(top2LevelsMenu);
0672:                assertEquals("top-2-levels", top2LevelsMenu.getName());
0673:                assertNull(top2LevelsMenu.getMenuElements());
0674:                assertEquals("/", top2LevelsMenu.getOptions());
0675:                assertEquals(2, top2LevelsMenu.getDepth());
0676:                assertEquals("dhtml-pull-down", top2LevelsMenu.getSkin());
0677:
0678:                MenuDefinition topRolePagesMenu = (MenuDefinition) menus.get(2);
0679:                assertNotNull(topRolePagesMenu);
0680:                assertEquals("top-role-pages", topRolePagesMenu.getName());
0681:                assertTrue(topRolePagesMenu.isRegexp());
0682:                assertEquals("roles", topRolePagesMenu.getProfile());
0683:                assertEquals("*.psml,*.link", topRolePagesMenu.getOrder());
0684:
0685:                MenuDefinition breadCrumbsMenu = (MenuDefinition) menus.get(3);
0686:                assertNotNull(breadCrumbsMenu);
0687:                assertEquals("bread-crumbs", breadCrumbsMenu.getName());
0688:                assertTrue(breadCrumbsMenu.isPaths());
0689:
0690:                MenuDefinition topCustomMenu = (MenuDefinition) menus.get(4);
0691:                assertNotNull(topCustomMenu);
0692:                assertEquals("top-custom", topCustomMenu.getName());
0693:                assertEquals("Top Menu", topCustomMenu.getTitle());
0694:                assertEquals("Top", topCustomMenu.getShortTitle());
0695:                assertEquals("Haut", topCustomMenu.getTitle(Locale.FRENCH));
0696:                assertEquals("H", topCustomMenu.getShortTitle(Locale.FRENCH));
0697:                assertNotNull(topCustomMenu.getMenuElements());
0698:                assertEquals(5, topCustomMenu.getMenuElements().size());
0699:                assertTrue(topCustomMenu.getMenuElements().get(0) instanceof  MenuOptionsDefinition);
0700:                assertTrue(((MenuOptionsDefinition) topCustomMenu
0701:                        .getMenuElements().get(0)).isRegexp());
0702:                assertEquals("groups", ((MenuOptionsDefinition) topCustomMenu
0703:                        .getMenuElements().get(0)).getProfile());
0704:                assertTrue(topCustomMenu.getMenuElements().get(1) instanceof  MenuDefinition);
0705:                assertTrue(topCustomMenu.getMenuElements().get(2) instanceof  MenuExcludeDefinition);
0706:                assertEquals("top-role-pages",
0707:                        ((MenuExcludeDefinition) topCustomMenu
0708:                                .getMenuElements().get(2)).getName());
0709:                assertTrue(topCustomMenu.getMenuElements().get(3) instanceof  MenuSeparatorDefinition);
0710:                assertEquals("More Top Pages",
0711:                        ((MenuSeparatorDefinition) topCustomMenu
0712:                                .getMenuElements().get(3)).getText());
0713:                assertTrue(topCustomMenu.getMenuElements().get(4) instanceof  MenuIncludeDefinition);
0714:                assertEquals("simple", ((MenuIncludeDefinition) topCustomMenu
0715:                        .getMenuElements().get(4)).getName());
0716:                assertTrue(((MenuIncludeDefinition) topCustomMenu
0717:                        .getMenuElements().get(4)).isNest());
0718:
0719:                MenuDefinition topCustomNestedMenu = (MenuDefinition) topCustomMenu
0720:                        .getMenuElements().get(1);
0721:                assertEquals("/", topCustomNestedMenu.getOptions());
0722:                assertEquals("page", topCustomNestedMenu.getProfile());
0723:                assertEquals(5, topCustomNestedMenu.getMenuElements().size());
0724:                assertTrue(topCustomNestedMenu.getMenuElements().get(0) instanceof  MenuSeparatorDefinition);
0725:                assertEquals("Top Pages",
0726:                        ((MenuSeparatorDefinition) topCustomNestedMenu
0727:                                .getMenuElements().get(0)).getText());
0728:                assertEquals("Ye Olde Top Pages",
0729:                        ((MenuSeparatorDefinition) topCustomNestedMenu
0730:                                .getMenuElements().get(0))
0731:                                .getText(Locale.ENGLISH));
0732:                assertEquals("Select from Top Pages menu...",
0733:                        ((MenuSeparatorDefinition) topCustomNestedMenu
0734:                                .getMenuElements().get(0)).getTitle());
0735:                assertEquals("Haut",
0736:                        ((MenuSeparatorDefinition) topCustomNestedMenu
0737:                                .getMenuElements().get(0))
0738:                                .getTitle(Locale.FRENCH));
0739:                assertTrue(topCustomNestedMenu.getMenuElements().get(1) instanceof  MenuOptionsDefinition);
0740:                assertTrue(topCustomNestedMenu.getMenuElements().get(2) instanceof  MenuSeparatorDefinition);
0741:                assertEquals("bold",
0742:                        ((MenuSeparatorDefinition) topCustomNestedMenu
0743:                                .getMenuElements().get(2)).getSkin());
0744:                assertEquals("Custom Pages",
0745:                        ((MenuSeparatorDefinition) topCustomNestedMenu
0746:                                .getMenuElements().get(2)).getTitle());
0747:                assertTrue(topCustomNestedMenu.getMenuElements().get(3) instanceof  MenuOptionsDefinition);
0748:                assertEquals(1, ((MenuOptionsDefinition) topCustomNestedMenu
0749:                        .getMenuElements().get(3)).getDepth());
0750:                assertEquals("*.psml",
0751:                        ((MenuOptionsDefinition) topCustomNestedMenu
0752:                                .getMenuElements().get(3)).getOrder());
0753:                assertTrue(topCustomNestedMenu.getMenuElements().get(4) instanceof  MenuOptionsDefinition);
0754:                assertTrue(((MenuOptionsDefinition) topCustomNestedMenu
0755:                        .getMenuElements().get(4)).isPaths());
0756:                assertEquals("*", ((MenuOptionsDefinition) topCustomNestedMenu
0757:                        .getMenuElements().get(4)).getProfile());
0758:                assertEquals("links",
0759:                        ((MenuOptionsDefinition) topCustomNestedMenu
0760:                                .getMenuElements().get(4)).getSkin());
0761:                assertEquals("@", ((MenuOptionsDefinition) topCustomNestedMenu
0762:                        .getMenuElements().get(4)).getOptions());
0763:
0764:                // test page resident menu definitions
0765:                Page page = pageManager.getPage("/test001.psml");
0766:                assertNotNull(page);
0767:                menus = page.getMenuDefinitions();
0768:                assertNotNull(menus);
0769:                assertEquals(1, menus.size());
0770:
0771:                simpleMenu = (MenuDefinition) menus.get(0);
0772:                assertNotNull(simpleMenu);
0773:                assertEquals("simple", simpleMenu.getName());
0774:                assertNotNull(simpleMenu.getMenuElements());
0775:                assertEquals(2, simpleMenu.getMenuElements().size());
0776:
0777:                // test writing page menu definitions
0778:                page = pageManager.getPage(this .testPage002);
0779:                page.setMenuDefinitions(new ArrayList());
0780:                MenuDefinition newMenu = page.newMenuDefinition();
0781:                newMenu.setName("updated-menu");
0782:                newMenu.setSkin("tabs");
0783:                newMenu.setMenuElements(new ArrayList());
0784:                MenuSeparatorDefinition newSeparator = page
0785:                        .newMenuSeparatorDefinition();
0786:                newSeparator.setText("-- Updated Menu --");
0787:                newMenu.getMenuElements().add(newSeparator);
0788:                MenuOptionsDefinition newOptions0 = page
0789:                        .newMenuOptionsDefinition();
0790:                newOptions0.setOptions("/*.psml");
0791:                newOptions0.setRegexp(true);
0792:                newMenu.getMenuElements().add(newOptions0);
0793:                MenuOptionsDefinition newOptions1 = page
0794:                        .newMenuOptionsDefinition();
0795:                newOptions1.setOptions("/folder0");
0796:                newMenu.getMenuElements().add(newOptions1);
0797:                MenuDefinition newNestedMenu = page.newMenuDefinition();
0798:                newNestedMenu.setOptions("/*/");
0799:                newNestedMenu.setRegexp(true);
0800:                newMenu.getMenuElements().add(newNestedMenu);
0801:                MenuExcludeDefinition newExcludeMenu = page
0802:                        .newMenuExcludeDefinition();
0803:                newExcludeMenu.setName("exclude-menu");
0804:                newMenu.getMenuElements().add(newExcludeMenu);
0805:                MenuIncludeDefinition newIncludeMenu = page
0806:                        .newMenuIncludeDefinition();
0807:                newIncludeMenu.setName("include-menu");
0808:                newIncludeMenu.setNest(true);
0809:                newMenu.getMenuElements().add(newIncludeMenu);
0810:                page.getMenuDefinitions().add(newMenu);
0811:                try {
0812:                    pageManager.updatePage(page);
0813:                } catch (Exception e) {
0814:                    String errmsg = "Exception in page update: " + e.toString();
0815:                    e.printStackTrace();
0816:                    System.err.println(errmsg);
0817:                    assertNotNull(errmsg, null);
0818:                }
0819:                page = pageManager.getPage(this .testPage002);
0820:                assertNotNull(page.getMenuDefinitions());
0821:                assertEquals(1, page.getMenuDefinitions().size());
0822:                assertNotNull(((MenuDefinition) page.getMenuDefinitions()
0823:                        .get(0)).getMenuElements());
0824:                assertEquals(6, ((MenuDefinition) page.getMenuDefinitions()
0825:                        .get(0)).getMenuElements().size());
0826:                assertTrue(((MenuDefinition) page.getMenuDefinitions().get(0))
0827:                        .getMenuElements().get(0) instanceof  MenuSeparatorDefinition);
0828:                assertTrue(((MenuDefinition) page.getMenuDefinitions().get(0))
0829:                        .getMenuElements().get(1) instanceof  MenuOptionsDefinition);
0830:                assertTrue(((MenuDefinition) page.getMenuDefinitions().get(0))
0831:                        .getMenuElements().get(2) instanceof  MenuOptionsDefinition);
0832:                assertTrue(((MenuDefinition) page.getMenuDefinitions().get(0))
0833:                        .getMenuElements().get(3) instanceof  MenuDefinition);
0834:                assertTrue(((MenuDefinition) page.getMenuDefinitions().get(0))
0835:                        .getMenuElements().get(4) instanceof  MenuExcludeDefinition);
0836:                assertTrue(((MenuDefinition) page.getMenuDefinitions().get(0))
0837:                        .getMenuElements().get(5) instanceof  MenuIncludeDefinition);
0838:
0839:                // test writing folder menu definitions
0840:                folder = pageManager.getFolder(this .testFolder2);
0841:                folder.setMenuDefinitions(new ArrayList());
0842:                newMenu = folder.newMenuDefinition();
0843:                newMenu.setName("updated-menu");
0844:                newMenu.setSkin("bread-crumbs");
0845:                newMenu.setOptions("./");
0846:                newMenu.setPaths(true);
0847:                folder.getMenuDefinitions().add(newMenu);
0848:                try {
0849:                    pageManager.updateFolder(folder);
0850:                } catch (Exception e) {
0851:                    String errmsg = "Exception in folder update: "
0852:                            + e.toString();
0853:                    e.printStackTrace();
0854:                    System.err.println(errmsg);
0855:                    assertNotNull(errmsg, null);
0856:                }
0857:                folder = pageManager.getFolder(this .testFolder2);
0858:                assertNotNull(folder.getMenuDefinitions());
0859:                assertEquals(1, folder.getMenuDefinitions().size());
0860:                assertEquals("updated-menu", ((MenuDefinition) folder
0861:                        .getMenuDefinitions().get(0)).getName());
0862:                assertEquals("bread-crumbs", ((MenuDefinition) folder
0863:                        .getMenuDefinitions().get(0)).getSkin());
0864:                assertEquals("./", ((MenuDefinition) folder
0865:                        .getMenuDefinitions().get(0)).getOptions());
0866:            }
0867:
0868:            public void testRemovePage() throws Exception {
0869:                Page page = pageManager.getPage(this .testPage002);
0870:
0871:                try {
0872:                    pageManager.removePage(page);
0873:                } catch (Exception e) {
0874:                    String errmsg = "Exception in page remove: " + e.toString();
0875:                    e.printStackTrace();
0876:                    System.err.println(errmsg);
0877:                    assertNotNull(errmsg, null);
0878:                }
0879:
0880:                boolean exceptionFound = false;
0881:                try {
0882:                    page = pageManager.getPage(this .testPage002);
0883:                } catch (DocumentNotFoundException dnfe) {
0884:                    exceptionFound = true;
0885:                }
0886:                assertTrue(exceptionFound);
0887:            }
0888:
0889:            public void testRemoveFolder() throws Exception {
0890:                Folder folder = pageManager.getFolder(this .testFolder2);
0891:
0892:                try {
0893:                    pageManager.removeFolder(folder);
0894:                } catch (Exception e) {
0895:                    String errmsg = "Exception in folder remove: "
0896:                            + e.toString();
0897:                    e.printStackTrace();
0898:                    System.err.println(errmsg);
0899:                    assertNotNull(errmsg, null);
0900:                }
0901:
0902:                boolean exceptionFound = false;
0903:                try {
0904:                    folder = pageManager.getFolder(this .testFolder2);
0905:                } catch (FolderNotFoundException fnfe) {
0906:                    exceptionFound = true;
0907:                }
0908:                assertTrue(exceptionFound);
0909:            }
0910:
0911:            public void testRemoveLink() throws Exception {
0912:                Link link = pageManager.getLink(this .testLink002);
0913:
0914:                try {
0915:                    pageManager.removeLink(link);
0916:                } catch (Exception e) {
0917:                    String errmsg = "Exception in link remove: " + e.toString();
0918:                    e.printStackTrace();
0919:                    System.err.println(errmsg);
0920:                    assertNotNull(errmsg, null);
0921:                }
0922:
0923:                boolean exceptionFound = false;
0924:                try {
0925:                    link = pageManager.getLink(this .testLink002);
0926:                } catch (DocumentNotFoundException dnfe) {
0927:                    exceptionFound = true;
0928:                }
0929:                assertTrue(exceptionFound);
0930:            }
0931:
0932:            public void testClonePage() throws Exception {
0933:                Page testpage = pageManager.getPage("/clonetest.psml");
0934:                assertNotNull(testpage);
0935:                Page clone = pageManager.copyPage(testpage, "/cloned.psml");
0936:                assertNotNull(clone);
0937:
0938:                assertTrue(clone.getId().equals("/cloned.psml"));
0939:                assertTrue(clone.getName().equals("cloned.psml"));
0940:                assertTrue(clone.getTitle().equals("Test Page"));
0941:                assertTrue(clone.getSkin().equals("test-skin"));
0942:                assertTrue(clone.getEffectiveDefaultDecorator(Fragment.LAYOUT)
0943:                        .equals("test-layout"));
0944:                assertTrue(clone.getDefaultDecorator(Fragment.LAYOUT).equals(
0945:                        "test-layout"));
0946:                assertTrue(clone.getDefaultDecorator(Fragment.PORTLET).equals(
0947:                        "test-portlet"));
0948:
0949:                // TODO: Test Meta data
0950:                Fragment root = testpage.getRootFragment();
0951:                Fragment cloneRoot = clone.getRootFragment();
0952:
0953:                assertNotNull(cloneRoot);
0954:                assertNotNull(cloneRoot.getId());
0955:                assertFalse(cloneRoot.getId().equals(root.getId()));
0956:                assertTrue(cloneRoot.getName().equals("TwoColumns"));
0957:                assertTrue(cloneRoot.getType().equals(Fragment.LAYOUT));
0958:                assertNull(cloneRoot.getDecorator());
0959:
0960:                List children = root.getFragments();
0961:                List cloneChildren = cloneRoot.getFragments();
0962:                assertNotNull(cloneChildren);
0963:                assertTrue(cloneChildren.size() == 3);
0964:
0965:                Fragment f = (Fragment) children.get(0);
0966:                Fragment cf = (Fragment) cloneChildren.get(0);
0967:                assertNotNull(cf.getId());
0968:                assertFalse(cf.getId().equals(f.getId()));
0969:                assertTrue(cf.getName().equals("HelloPortlet"));
0970:                assertTrue(cf.getType().equals(Fragment.PORTLET));
0971:
0972:                Map properties = f.getProperties();
0973:                Map cloneProperties = cf.getProperties();
0974:
0975:                assertNotNull(cloneProperties);
0976:                assertTrue(cloneProperties.size() == 2);
0977:                assertEquals("0", cf.getProperty(Fragment.ROW_PROPERTY_NAME));
0978:                assertEquals(0, cf
0979:                        .getIntProperty(Fragment.COLUMN_PROPERTY_NAME));
0980:
0981:                cf = (Fragment) cloneChildren.get(1);
0982:                f = (Fragment) children.get(1);
0983:                assertNotNull(cf.getId());
0984:                assertFalse(cf.getId().equals(f.getId()));
0985:                assertTrue(cf.getName().equals("JMXPortlet"));
0986:                assertTrue(cf.getType().equals(Fragment.PORTLET));
0987:
0988:                properties = cf.getProperties();
0989:                assertNotNull(properties);
0990:                assertTrue(properties.size() == 2);
0991:                assertEquals("0", cf.getProperty(Fragment.ROW_PROPERTY_NAME));
0992:                assertEquals(1, cf
0993:                        .getIntProperty(Fragment.COLUMN_PROPERTY_NAME));
0994:
0995:                f = testpage.getFragmentById("f002");
0996:                cf = (Fragment) cloneChildren.get(2);
0997:                String id = cf.getId();
0998:                cf = clone.getFragmentById(id);
0999:
1000:                assertNotNull(cf);
1001:                assertNotNull(cf.getId());
1002:                assertFalse(cf.getId().equals(f.getId()));
1003:                assertTrue(cf.getName().equals("Card"));
1004:                assertTrue(cf.getType().equals(Fragment.LAYOUT));
1005:                assertTrue(cf.getDecorator().equals("Tab"));
1006:                assertNotNull(cf.getFragments());
1007:                assertTrue(cf.getFragments().size() == 2);
1008:
1009:                // security testing
1010:                SecurityConstraints constraints = clone
1011:                        .getSecurityConstraints();
1012:                assertNotNull(constraints);
1013:                assertTrue(constraints.getOwner().equals("new-user"));
1014:                List secs = constraints.getSecurityConstraints();
1015:                assertNotNull(secs);
1016:                assertTrue(secs.size() == 1);
1017:                SecurityConstraint constraint = (SecurityConstraint) secs
1018:                        .get(0);
1019:                assertNotNull(constraint);
1020:                assertTrue(constraint.getUsers() != null);
1021:                assertTrue(constraint.getUsers().size() == 2);
1022:                assertTrue(Shared.makeCSVFromList(constraint.getUsers())
1023:                        .equals("user10,user11"));
1024:                assertTrue(constraint.getRoles() != null);
1025:                assertTrue(constraint.getRoles().size() == 1);
1026:                assertTrue(Shared.makeCSVFromList(constraint.getRoles())
1027:                        .equals("*"));
1028:                assertTrue(constraint.getPermissions() != null);
1029:                assertTrue(constraint.getPermissions().size() == 2);
1030:                assertTrue(Shared.makeCSVFromList(constraint.getPermissions())
1031:                        .equals("edit,view"));
1032:                List refs = constraints.getSecurityConstraintsRefs();
1033:                assertNotNull(refs);
1034:                assertTrue(refs.size() == 1);
1035:                String ref = (String) refs.get(0);
1036:                assertNotNull(ref);
1037:                assertTrue(ref.equals("public-view"));
1038:
1039:                // TODO: menu testing
1040:            }
1041:
1042:            public Collection collectIds(Folder f) throws Exception {
1043:                Collection result = new ArrayList();
1044:
1045:                for (Iterator iter = f.getAll().iterator(); iter.hasNext();) {
1046:                    Object obj = iter.next();
1047:
1048:                    if (obj instanceof  Page) {
1049:                        Page this Page = (Page) obj;
1050:                        if (this Page.getRootFragment() != null) {
1051:                            result
1052:                                    .addAll(collectIds(this Page
1053:                                            .getRootFragment()));
1054:                        }
1055:                    } else if (obj instanceof  Folder) {
1056:                        Folder this Folder = (Folder) obj;
1057:                        result.addAll(collectIds((Folder) obj));
1058:                    }
1059:                }
1060:
1061:                return result;
1062:            }
1063:
1064:            public Collection collectIds(Fragment f) {
1065:                Collection result = new ArrayList();
1066:
1067:                result.add(f.getId());
1068:                if (f.getFragments().size() > 0) {
1069:                    for (Iterator iter = f.getFragments().iterator(); iter
1070:                            .hasNext();) {
1071:                        Fragment child = (Fragment) iter.next();
1072:                        result.addAll(collectIds(child));
1073:                    }
1074:                }
1075:                return result;
1076:            }
1077:
1078:            private int countFragments(Fragment f) {
1079:                int result = 1;
1080:                for (Iterator iter = f.getFragments().iterator(); iter
1081:                        .hasNext();) {
1082:                    result += countFragments((Fragment) iter.next());
1083:                }
1084:
1085:                return result;
1086:            }
1087:
1088:            private void compareFolders(Folder folder1, Folder folder2)
1089:                    throws Exception {
1090:                for (Iterator iter = folder1.getAll().iterator(); iter
1091:                        .hasNext();) {
1092:                    Object obj = iter.next();
1093:
1094:                    if (obj instanceof  Page) {
1095:                        Page this Page = (Page) obj;
1096:                        Page otherPage = folder2.getPage(this Page.getName());
1097:                        assertEquals(this Page.getRootFragment() != null,
1098:                                otherPage.getRootFragment() != null);
1099:                        if (this Page.getRootFragment() != null) {
1100:                            Fragment this RootFragment = this Page
1101:                                    .getRootFragment();
1102:                            Fragment otherRootFragment = otherPage
1103:                                    .getRootFragment();
1104:                            assertEquals(
1105:                                    this RootFragment.getFragments().size(),
1106:                                    otherRootFragment.getFragments().size());
1107:                            assertEquals(countFragments(this RootFragment),
1108:                                    countFragments(otherRootFragment));
1109:                        }
1110:                    } else if (obj instanceof  Folder) {
1111:                        Folder this Folder = (Folder) obj;
1112:                        compareFolders(this Folder, folder2.getFolder(this Folder
1113:                                .getName()));
1114:                    }
1115:
1116:                }
1117:            }
1118:
1119:            public void testIdGeneration() throws Exception {
1120:                Folder webappIds = pageManager.getFolder("/webapp-ids");
1121:                Folder webappNoIds = pageManager.getFolder("/webapp-no-ids");
1122:
1123:                compareFolders(webappIds, webappNoIds);
1124:
1125:                Collection allIds = collectIds(webappNoIds);
1126:                for (Iterator iter = allIds.iterator(); iter.hasNext();) {
1127:                    String id = (String) iter.next();
1128:                    assertNotNull(id);
1129:                    assertEquals(true, id.length() > 0);
1130:                    if (CollectionUtils.cardinality(id, allIds) > 1) {
1131:                        System.out.println("Fragment with id " + id
1132:                                + " has duplicates");
1133:                    }
1134:                    assertEquals(1, CollectionUtils.cardinality(id, allIds)); // uniqueness test			
1135:                }
1136:            }
1137:
1138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.