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: import java.util.ArrayList;
0020: import java.util.Iterator;
0021: import java.util.List;
0022: import java.util.Locale;
0023: import org.apache.jetspeed.components.util.DatasourceEnabledSpringTestCase;
0024: import org.apache.jetspeed.om.common.GenericMetadata;
0025: import org.apache.jetspeed.om.common.SecurityConstraint;
0026: import org.apache.jetspeed.om.common.SecurityConstraints;
0027: import org.apache.jetspeed.om.folder.Folder;
0028: import org.apache.jetspeed.om.folder.FolderNotFoundException;
0029: import org.apache.jetspeed.om.folder.MenuDefinition;
0030: import org.apache.jetspeed.om.folder.MenuExcludeDefinition;
0031: import org.apache.jetspeed.om.folder.MenuIncludeDefinition;
0032: import org.apache.jetspeed.om.folder.MenuOptionsDefinition;
0033: import org.apache.jetspeed.om.folder.MenuSeparatorDefinition;
0034: import org.apache.jetspeed.om.page.Fragment;
0035: import org.apache.jetspeed.om.page.Link;
0036: import org.apache.jetspeed.om.page.Page;
0037: import org.apache.jetspeed.om.page.PageSecurity;
0038: import org.apache.jetspeed.om.page.SecurityConstraintsDef;
0039: import org.apache.jetspeed.om.preference.FragmentPreference;
0040: import org.apache.jetspeed.page.document.DocumentNotFoundException;
0041: import org.apache.jetspeed.page.document.FailedToUpdateDocumentException;
0042: import org.apache.jetspeed.page.document.Node;
0043:
0044: import org.springframework.context.support.ClassPathXmlApplicationContext;
0045:
0046: import junit.framework.Test;
0047: import junit.framework.TestSuite;
0048:
0049: /**
0050: * TestPageXmlPersistence
0051: *
0052: * @author <a href="taylor@apache.org">David Sean Taylor</a>
0053: * @version $Id: $
0054: *
0055: */
0056: public class TestDatabasePageManager extends
0057: DatasourceEnabledSpringTestCase implements
0058: PageManagerTestShared, PageManagerEventListener {
0059: private String deepFolderPath = "/__subsite-rootx/_user/userx/_role/rolex/_group/groupx/_mediatype/xhtml/_language/en/_country/us/_custom/customx";
0060: private String deepPagePath = deepFolderPath + "/default-page.psml";
0061:
0062: private static ClassPathXmlApplicationContext context;
0063: private static boolean lastTestRun;
0064:
0065: private static PageManager pageManager;
0066:
0067: private static int newNodeCount;
0068: private static int updatedNodeCount;
0069: private static int removedNodeCount;
0070:
0071: public static void main(String args[]) {
0072: junit.awtui.TestRunner
0073: .main(new String[] { TestDatabasePageManager.class
0074: .getName() });
0075: }
0076:
0077: protected void setUp() throws Exception {
0078: // reuse context between test cases below
0079: // that is normally configured if null in
0080: // super class setUp() implementation
0081: if (context == null) {
0082: // new context
0083: super .setUp();
0084: context = ctx;
0085: lastTestRun = false;
0086:
0087: // lookup page manager in context and reset to initial state
0088: pageManager = (PageManager) context.getBean("pageManager");
0089: try {
0090: Folder removeRootFolder = pageManager.getFolder("/");
0091: pageManager.removeFolder(removeRootFolder);
0092: pageManager.reset();
0093: } catch (FolderNotFoundException e) {
0094: }
0095:
0096: // setup page manager listener
0097: pageManager.addListener(this );
0098: } else {
0099: // recycle context
0100: ctx = context;
0101: super .setUp();
0102: }
0103: }
0104:
0105: protected void tearDown() throws Exception {
0106: // save context for reuse
0107: if (!lastTestRun) {
0108: ctx = null;
0109: }
0110: super .tearDown();
0111: }
0112:
0113: public static Test suite() {
0114: // All methods starting with "test" will be executed in the test suite.
0115: return new TestSuite(TestDatabasePageManager.class);
0116: }
0117:
0118: protected String[] getConfigurations() {
0119: return new String[] { "database-page-manager.xml",
0120: "transaction.xml" };
0121: }
0122:
0123: /* (non-Javadoc)
0124: * @see org.apache.jetspeed.page.PageManagerEventListener#newNode(org.apache.jetspeed.page.document.Node)
0125: */
0126: public void newNode(Node node) {
0127: newNodeCount++;
0128: }
0129:
0130: /* (non-Javadoc)
0131: * @see org.apache.jetspeed.page.PageManagerEventListener#newNode(org.apache.jetspeed.page.document.Node)
0132: */
0133: public void updatedNode(Node node) {
0134: updatedNodeCount++;
0135: }
0136:
0137: /* (non-Javadoc)
0138: * @see org.apache.jetspeed.page.PageManagerEventListener#newNode(org.apache.jetspeed.page.document.Node)
0139: */
0140: public void removedNode(Node node) {
0141: removedNodeCount++;
0142: }
0143:
0144: public void testCreates() throws Exception {
0145: // reset page manager cache
0146: pageManager.reset();
0147:
0148: // test document and folder creation
0149: Folder folder = pageManager.newFolder("/");
0150: assertEquals("Top", folder.getTitle());
0151: folder.setTitle("Root Folder");
0152: folder.setDefaultDecorator("jetspeed", Fragment.LAYOUT);
0153: folder.setDefaultDecorator("gray-gradient", Fragment.PORTLET);
0154: folder.setSkin("skin-1");
0155: folder.setDefaultPage("default-page.psml");
0156: folder.setShortTitle("Root");
0157: GenericMetadata metadata = folder.getMetadata();
0158: metadata.addField(Locale.FRENCH, "title", "[fr] Root Folder");
0159: SecurityConstraints folderConstraints = pageManager
0160: .newSecurityConstraints();
0161: folderConstraints.setOwner("admin");
0162: List inlineFolderConstraints = new ArrayList(2);
0163: SecurityConstraint folderConstraint = pageManager
0164: .newFolderSecurityConstraint();
0165: folderConstraint.setUsers(Shared.makeListFromCSV("user,admin"));
0166: folderConstraint.setRoles(Shared.makeListFromCSV("manager"));
0167: folderConstraint.setGroups(Shared.makeListFromCSV("*"));
0168: folderConstraint.setPermissions(Shared
0169: .makeListFromCSV("view,edit"));
0170: inlineFolderConstraints.add(folderConstraint);
0171: folderConstraint = folder.newSecurityConstraint();
0172: folderConstraint.setPermissions(Shared.makeListFromCSV("edit"));
0173: inlineFolderConstraints.add(folderConstraint);
0174: folderConstraints
0175: .setSecurityConstraints(inlineFolderConstraints);
0176: List folderConstraintsRefs = new ArrayList(2);
0177: folderConstraintsRefs.add("public-view");
0178: folderConstraintsRefs.add("public-edit");
0179: folderConstraints
0180: .setSecurityConstraintsRefs(folderConstraintsRefs);
0181: folder.setSecurityConstraints(folderConstraints);
0182: List documentOrder = new ArrayList(2);
0183: documentOrder.add("some-other-page.psml");
0184: documentOrder.add("default-page.psml");
0185: folder.setDocumentOrder(documentOrder);
0186: MenuDefinition newMenu = folder.newMenuDefinition();
0187: newMenu.setName("folder-menu");
0188: newMenu.setTitle("The Test Folder Menu");
0189: newMenu.setShortTitle("Folder Menu");
0190: newMenu.setProfile("group-fallback");
0191: metadata = newMenu.getMetadata();
0192: metadata.addField(Locale.FRENCH, "short-title",
0193: "[fr] Folder Menu");
0194: metadata.addField(Locale.FRENCH, "title",
0195: "[fr] The Test Folder Menu");
0196: MenuSeparatorDefinition newSeparator = folder
0197: .newMenuSeparatorDefinition();
0198: newSeparator.setText("-- Folder Menu --");
0199: newSeparator.setTitle("Rollover: Folder Menu");
0200: newSeparator.setSkin("header");
0201: metadata = newSeparator.getMetadata();
0202: metadata.addField(Locale.FRENCH, "text",
0203: "-- [fr] Folder Menu --");
0204: metadata.addField(Locale.FRENCH, "title",
0205: "[fr] Rollover: Folder Menu");
0206: newMenu.getMenuElements().add(newSeparator);
0207: MenuOptionsDefinition newOptions0 = folder
0208: .newMenuOptionsDefinition();
0209: newOptions0.setOptions("/*.psml");
0210: newOptions0.setRegexp(true);
0211: newOptions0.setSkin("flash");
0212: newMenu.getMenuElements().add(newOptions0);
0213: MenuOptionsDefinition newOptions1 = folder
0214: .newMenuOptionsDefinition();
0215: newOptions1.setOptions("/folder0");
0216: newOptions1.setProfile("role-fallback");
0217: newOptions1.setOrder("/folder*");
0218: newOptions1.setDepth(1);
0219: newOptions1.setPaths(true);
0220: newMenu.getMenuElements().add(newOptions1);
0221: MenuDefinition newNestedMenu = folder.newMenuDefinition();
0222: newNestedMenu.setOptions("/*/");
0223: newNestedMenu.setRegexp(true);
0224: newNestedMenu.setDepth(2);
0225: newNestedMenu.setOrder("/x*/,/y*/,/z*/");
0226: newNestedMenu.setSkin("bold");
0227: newMenu.getMenuElements().add(newNestedMenu);
0228: MenuExcludeDefinition newExcludeMenu = folder
0229: .newMenuExcludeDefinition();
0230: newExcludeMenu.setName("exclude-menu");
0231: newMenu.getMenuElements().add(newExcludeMenu);
0232: MenuIncludeDefinition newIncludeMenu = folder
0233: .newMenuIncludeDefinition();
0234: newIncludeMenu.setName("include-menu");
0235: newIncludeMenu.setNest(true);
0236: newMenu.getMenuElements().add(newIncludeMenu);
0237: folder.getMenuDefinitions().add(newMenu);
0238: newMenu = folder.newMenuDefinition();
0239: newMenu.setName("folder-breadcrumb-menu");
0240: newMenu.setSkin("bread-crumbs");
0241: newMenu.setOptions("./");
0242: newMenu.setPaths(true);
0243: folder.getMenuDefinitions().add(newMenu);
0244: pageManager.updateFolder(folder);
0245:
0246: assertNull(folder.getParent());
0247:
0248: Page page = pageManager.newPage("/default-page.psml");
0249: assertEquals("Default Page", page.getTitle());
0250: page.setTitle("Default Page");
0251: page.setVersion("6.89");
0252: page.setDefaultDecorator("tigris", Fragment.LAYOUT);
0253: page.setDefaultDecorator("blue-gradient", Fragment.PORTLET);
0254: page.setSkin("skin-1");
0255: page.setShortTitle("Default");
0256: metadata = page.getMetadata();
0257: metadata.addField(Locale.FRENCH, "title", "[fr] Default Page");
0258: metadata
0259: .addField(Locale.JAPANESE, "title", "[ja] Default Page");
0260: SecurityConstraints pageConstraints = page
0261: .newSecurityConstraints();
0262: pageConstraints.setOwner("user");
0263: List inlinePageConstraints = new ArrayList(1);
0264: SecurityConstraint pageConstraint = page
0265: .newSecurityConstraint();
0266: pageConstraint.setUsers(Shared.makeListFromCSV("jetspeed"));
0267: pageConstraint.setPermissions(Shared.makeListFromCSV("edit"));
0268: inlinePageConstraints.add(pageConstraint);
0269: pageConstraints.setSecurityConstraints(inlinePageConstraints);
0270: List pageConstraintsRefs = new ArrayList(1);
0271: pageConstraintsRefs.add("manager-edit");
0272: pageConstraints.setSecurityConstraintsRefs(pageConstraintsRefs);
0273: page.setSecurityConstraints(pageConstraints);
0274: List pageMenus = new ArrayList();
0275: newMenu = page.newMenuDefinition();
0276: newMenu.setName("page-menu-1");
0277: newMenu.setTitle("The Test Page Menu");
0278: metadata = newMenu.getMetadata();
0279: metadata.addField(Locale.FRENCH, "title",
0280: "[fr] The Test Page Menu");
0281: newSeparator = page.newMenuSeparatorDefinition();
0282: newSeparator.setText("-- Page Menu --");
0283: List menuElements = new ArrayList();
0284: menuElements.add(newSeparator);
0285: newOptions0 = page.newMenuOptionsDefinition();
0286: newOptions0.setOptions("/*.psml");
0287: menuElements.add(newOptions0);
0288: newNestedMenu = page.newMenuDefinition();
0289: newNestedMenu.setOptions("/*/");
0290: menuElements.add(newNestedMenu);
0291: newExcludeMenu = page.newMenuExcludeDefinition();
0292: newExcludeMenu.setName("exclude-menu");
0293: menuElements.add(newExcludeMenu);
0294: newIncludeMenu = page.newMenuIncludeDefinition();
0295: newIncludeMenu.setName("include-menu");
0296: menuElements.add(newIncludeMenu);
0297: newMenu.setMenuElements(menuElements);
0298: pageMenus.add(newMenu);
0299: newMenu = page.newMenuDefinition();
0300: newMenu.setName("page-menu-2");
0301: newMenu.setOptions("./");
0302: pageMenus.add(newMenu);
0303: page.setMenuDefinitions(pageMenus);
0304:
0305: Fragment root = page.getRootFragment();
0306: root.setDecorator("blue-gradient");
0307: root.setName("jetspeed-layouts::VelocityTwoColumns");
0308: root.setShortTitle("Root");
0309: root.setTitle("Root Fragment");
0310: root.setState("Normal");
0311: root.setLayoutSizes("50%,50%");
0312: root.getProperties().put("custom-prop1", "custom-prop-value1");
0313: root.getProperties().put("custom-prop2", "custom-prop-value2");
0314:
0315: Fragment portlet = pageManager.newPortletFragment();
0316: portlet.setName("security::LoginPortlet");
0317: portlet.setShortTitle("Portlet");
0318: portlet.setTitle("Portlet Fragment");
0319: portlet.setState("Normal");
0320: portlet.setLayoutRow(88);
0321: portlet.setLayoutColumn(99);
0322: portlet.setLayoutX(12.34F);
0323: portlet.setLayoutY(23.45F);
0324: portlet.setLayoutZ(34.56F);
0325: portlet.setLayoutWidth(45.67F);
0326: portlet.setLayoutHeight(56.78F);
0327: List preferences = new ArrayList(2);
0328: FragmentPreference preference = pageManager
0329: .newFragmentPreference();
0330: preference.setName("pref0");
0331: preference.setReadOnly(true);
0332: List preferenceValues = new ArrayList(2);
0333: preferenceValues.add("pref0-value0");
0334: preferenceValues.add("pref0-value1");
0335: preference.setValueList(preferenceValues);
0336: preferences.add(preference);
0337: preference = pageManager.newFragmentPreference();
0338: preference.setName("pref1");
0339: preferenceValues = new ArrayList(1);
0340: preferenceValues.add("pref1-value");
0341: preference.setValueList(preferenceValues);
0342: preferences.add(preference);
0343: portlet.setPreferences(preferences);
0344: root.getFragments().add(portlet);
0345: portlet = pageManager.newPortletFragment();
0346: portlet.setName("some-app::SomePortlet");
0347: portlet.setShortTitle("Some Portlet");
0348: portlet.setTitle("Some Portlet Fragment");
0349: portlet.setState("Normal");
0350: portlet.setLayoutRow(22);
0351: portlet.setLayoutColumn(11);
0352: portlet.setLayoutX(11.11F);
0353: portlet.setLayoutY(22.22F);
0354: portlet.setLayoutZ(33.33F);
0355: portlet.setLayoutWidth(44.44F);
0356: portlet.setLayoutHeight(55.55F);
0357: SecurityConstraints fragmentConstraints = portlet
0358: .newSecurityConstraints();
0359: fragmentConstraints.setOwner("user");
0360: portlet.setSecurityConstraints(fragmentConstraints);
0361: root.getFragments().add(portlet);
0362:
0363: pageManager.updatePage(page);
0364:
0365: assertNotNull(page.getParent());
0366: assertEquals(page.getParent().getId(), folder.getId());
0367: assertNotNull(folder.getPages());
0368: assertEquals(1, folder.getPages().size());
0369: assertNotNull(pageManager.getPages(folder));
0370: assertEquals(1, pageManager.getPages(folder).size());
0371:
0372: page = pageManager.newPage("/another-page.psml");
0373: assertEquals("Another Page", page.getTitle());
0374: page.setTitle("Another Page");
0375: pageManager.updatePage(page);
0376: assertNotNull(page.getParent());
0377: assertEquals(page.getParent().getId(), folder.getId());
0378: page = pageManager.newPage("/some-other-page.psml");
0379: assertEquals("Some Other Page", page.getTitle());
0380: page.setTitle("Some Other Page");
0381: pageManager.updatePage(page);
0382: assertNotNull(page.getParent());
0383: assertEquals(page.getParent().getId(), folder.getId());
0384: assertEquals(3, folder.getPages().size());
0385: assertEquals(3, pageManager.getPages(folder).size());
0386:
0387: Link link = pageManager.newLink("/default.link");
0388: assertEquals("Default", link.getTitle());
0389: link.setTitle("Default Link");
0390: link.setVersion("1.23");
0391: link.setShortTitle("Default");
0392: link.setTarget("top");
0393: link.setUrl("http://www.default.org/");
0394: metadata = link.getMetadata();
0395: metadata.addField(Locale.FRENCH, "title", "[fr] Default Link");
0396: metadata.addField(Locale.GERMAN, "title", "[de] Default Link");
0397: SecurityConstraints linkConstraints = link
0398: .newSecurityConstraints();
0399: linkConstraints.setOwner("user");
0400: List inlineLinkConstraints = new ArrayList(1);
0401: SecurityConstraint linkConstraint = link
0402: .newSecurityConstraint();
0403: linkConstraint.setUsers(Shared.makeListFromCSV("jetspeed"));
0404: linkConstraint.setPermissions(Shared.makeListFromCSV("edit"));
0405: inlineLinkConstraints.add(linkConstraint);
0406: linkConstraints.setSecurityConstraints(inlineLinkConstraints);
0407: List linkConstraintsRefs = new ArrayList(1);
0408: linkConstraintsRefs.add("manager-edit");
0409: linkConstraints.setSecurityConstraintsRefs(linkConstraintsRefs);
0410: link.setSecurityConstraints(linkConstraints);
0411:
0412: pageManager.updateLink(link);
0413:
0414: assertNotNull(link.getParent());
0415: assertEquals(link.getParent().getId(), folder.getId());
0416: assertNotNull(folder.getLinks());
0417: assertEquals(1, folder.getLinks().size());
0418: assertNotNull(pageManager.getLinks(folder));
0419: assertEquals(1, pageManager.getLinks(folder).size());
0420:
0421: PageSecurity pageSecurity = pageManager.newPageSecurity();
0422: List constraintsDefs = new ArrayList(2);
0423: SecurityConstraintsDef constraintsDef = pageManager
0424: .newSecurityConstraintsDef();
0425: constraintsDef.setName("public-view");
0426: List defConstraints = new ArrayList(1);
0427: SecurityConstraint defConstraint = pageSecurity
0428: .newSecurityConstraint();
0429: defConstraint.setUsers(Shared.makeListFromCSV("*"));
0430: defConstraint.setPermissions(Shared.makeListFromCSV("view"));
0431: defConstraints.add(defConstraint);
0432: constraintsDef.setSecurityConstraints(defConstraints);
0433: constraintsDefs.add(constraintsDef);
0434: constraintsDef = pageSecurity.newSecurityConstraintsDef();
0435: constraintsDef.setName("admin-all");
0436: defConstraints = new ArrayList(2);
0437: defConstraint = pageSecurity.newSecurityConstraint();
0438: defConstraint.setRoles(Shared.makeListFromCSV("admin"));
0439: defConstraint.setPermissions(Shared
0440: .makeListFromCSV("view,edit"));
0441: defConstraints.add(defConstraint);
0442: defConstraint = pageSecurity.newSecurityConstraint();
0443: defConstraint.setRoles(Shared.makeListFromCSV("nobody"));
0444: defConstraints.add(defConstraint);
0445: constraintsDef.setSecurityConstraints(defConstraints);
0446: constraintsDefs.add(constraintsDef);
0447: pageSecurity.setSecurityConstraintsDefs(constraintsDefs);
0448: List globalConstraintsRefs = new ArrayList(2);
0449: globalConstraintsRefs.add("admin-all");
0450: globalConstraintsRefs.add("public-view");
0451: pageSecurity
0452: .setGlobalSecurityConstraintsRefs(globalConstraintsRefs);
0453:
0454: pageManager.updatePageSecurity(pageSecurity);
0455:
0456: assertNotNull(pageSecurity.getParent());
0457: assertEquals(pageSecurity.getParent().getId(), folder.getId());
0458: assertNotNull(folder.getPageSecurity());
0459:
0460: // test duplicate creates
0461: try {
0462: Folder dupFolder = pageManager.newFolder("/");
0463: pageManager.updateFolder(dupFolder);
0464: assertTrue("Duplicate Folder / CREATED", false);
0465: } catch (FolderNotUpdatedException e) {
0466: }
0467: try {
0468: Page dupPage = pageManager.newPage("/default-page.psml");
0469: pageManager.updatePage(dupPage);
0470: assertTrue("Duplicate Page / CREATED", false);
0471: } catch (PageNotUpdatedException e) {
0472: }
0473: try {
0474: Link dupLink = pageManager.newLink("/default.link");
0475: pageManager.updateLink(dupLink);
0476: assertTrue("Duplicate Link / CREATED", false);
0477: } catch (FailedToUpdateDocumentException e) {
0478: }
0479: try {
0480: PageSecurity dupPageSecurity = pageManager
0481: .newPageSecurity();
0482: pageManager.updatePageSecurity(dupPageSecurity);
0483: assertTrue("Duplicate PageSecurity / CREATED", false);
0484: } catch (FailedToUpdateDocumentException e) {
0485: }
0486:
0487: // test folder/page creation with attributes on deep path
0488: Folder deepFolder = null;
0489: int pathIndex = deepFolderPath.indexOf('/', 1);
0490: while ((pathIndex != -1)
0491: && (pathIndex <= deepFolderPath.length())) {
0492: deepFolder = pageManager.newFolder(deepFolderPath
0493: .substring(0, pathIndex));
0494: pageManager.updateFolder(deepFolder);
0495: assertNotNull(deepFolder.getParent());
0496: assertNotNull(((Folder) deepFolder.getParent())
0497: .getFolders());
0498: assertEquals(1, ((Folder) deepFolder.getParent())
0499: .getFolders().size());
0500: assertNotNull(pageManager.getFolders((Folder) deepFolder
0501: .getParent()));
0502: assertEquals(1, pageManager.getFolders(
0503: (Folder) deepFolder.getParent()).size());
0504: if (pathIndex < deepFolderPath.length()) {
0505: pathIndex = deepFolderPath.indexOf('/', pathIndex + 1);
0506: if (pathIndex == -1) {
0507: pathIndex = deepFolderPath.length();
0508: }
0509: } else {
0510: pathIndex = -1;
0511: }
0512: }
0513: Page deepPage = pageManager.newPage(deepPagePath);
0514: pageManager.updatePage(deepPage);
0515: assertNotNull(deepPage.getParent());
0516: assertEquals(deepPage.getParent().getId(), deepFolder.getId());
0517:
0518: // test folder nodesets
0519: assertNotNull(folder.getFolders());
0520: assertEquals(1, folder.getFolders().size());
0521: assertNotNull(pageManager.getFolders(folder));
0522: assertEquals(1, pageManager.getFolders(folder).size());
0523: assertNotNull(folder.getAll());
0524: assertEquals(6, folder.getAll().size());
0525: assertNotNull(pageManager.getAll(folder));
0526: assertEquals(6, pageManager.getAll(folder).size());
0527: Iterator all = folder.getAll().iterator();
0528: assertEquals("some-other-page.psml", ((Node) all.next())
0529: .getName());
0530: assertEquals("default-page.psml", ((Node) all.next()).getName());
0531: assertEquals("__subsite-rootx", ((Node) all.next()).getName());
0532: assertEquals("another-page.psml", ((Node) all.next()).getName());
0533: assertEquals("default.link", ((Node) all.next()).getName());
0534: assertEquals("page.security", ((Node) all.next()).getName());
0535: assertNotNull(folder.getAll().subset(Page.DOCUMENT_TYPE));
0536: assertEquals(3, folder.getAll().subset(Page.DOCUMENT_TYPE)
0537: .size());
0538: assertNotNull(folder.getAll().inclusiveSubset(".*other.*"));
0539: assertEquals(2, folder.getAll().inclusiveSubset(".*other.*")
0540: .size());
0541: assertNotNull(folder.getAll().inclusiveSubset("nomatch"));
0542: assertEquals(0, folder.getAll().inclusiveSubset("nomatch")
0543: .size());
0544: assertNotNull(folder.getAll().exclusiveSubset(".*-page.psml"));
0545: assertEquals(3, folder.getAll().exclusiveSubset(".*-page.psml")
0546: .size());
0547: }
0548:
0549: public void testGets() throws Exception {
0550: // reset page manager cache
0551: pageManager.reset();
0552:
0553: // read documents and folders from persisted store
0554: try {
0555: PageSecurity check = pageManager.getPageSecurity();
0556: assertEquals("/page.security", check.getPath());
0557: assertEquals("page.security", check.getName());
0558: assertEquals("/page.security", check.getUrl());
0559: assertNotNull(check.getSecurityConstraintsDefs());
0560: assertEquals(2, check.getSecurityConstraintsDefs().size());
0561: assertEquals("admin-all", ((SecurityConstraintsDef) check
0562: .getSecurityConstraintsDefs().get(0)).getName());
0563: assertNotNull(((SecurityConstraintsDef) check
0564: .getSecurityConstraintsDefs().get(0))
0565: .getSecurityConstraints());
0566: assertEquals(2, ((SecurityConstraintsDef) check
0567: .getSecurityConstraintsDefs().get(0))
0568: .getSecurityConstraints().size());
0569: assertEquals(
0570: "view,edit",
0571: Shared
0572: .makeCSVFromList(((SecurityConstraint) ((SecurityConstraintsDef) check
0573: .getSecurityConstraintsDefs()
0574: .get(0)).getSecurityConstraints()
0575: .get(0)).getPermissions()));
0576: assertEquals("public-view", ((SecurityConstraintsDef) check
0577: .getSecurityConstraintsDefs().get(1)).getName());
0578: assertNotNull(((SecurityConstraintsDef) check
0579: .getSecurityConstraintsDefs().get(1))
0580: .getSecurityConstraints());
0581: assertEquals(1, ((SecurityConstraintsDef) check
0582: .getSecurityConstraintsDefs().get(1))
0583: .getSecurityConstraints().size());
0584: assertEquals(
0585: "*",
0586: Shared
0587: .makeCSVFromList(((SecurityConstraint) ((SecurityConstraintsDef) check
0588: .getSecurityConstraintsDefs()
0589: .get(1)).getSecurityConstraints()
0590: .get(0)).getUsers()));
0591: assertEquals(
0592: "view",
0593: Shared
0594: .makeCSVFromList(((SecurityConstraint) ((SecurityConstraintsDef) check
0595: .getSecurityConstraintsDefs()
0596: .get(1)).getSecurityConstraints()
0597: .get(0)).getPermissions()));
0598: assertNotNull(check.getGlobalSecurityConstraintsRefs());
0599: assertEquals(2, check.getGlobalSecurityConstraintsRefs()
0600: .size());
0601: assertEquals("admin-all", (String) check
0602: .getGlobalSecurityConstraintsRefs().get(0));
0603: assertEquals("public-view", (String) check
0604: .getGlobalSecurityConstraintsRefs().get(1));
0605: assertNotNull(check.getParent());
0606: } catch (DocumentNotFoundException e) {
0607: assertTrue("PageSecurity NOT FOUND", false);
0608: }
0609: try {
0610: Link check = pageManager.getLink("/default.link");
0611: assertEquals("/default.link", check.getPath());
0612: assertEquals("default.link", check.getName());
0613: assertEquals("Default Link", check.getTitle());
0614: assertEquals("1.23", check.getVersion());
0615: assertEquals("Default", check.getShortTitle());
0616: assertEquals("top", check.getTarget());
0617: assertEquals("http://www.default.org/", check.getUrl());
0618: assertNotNull(check.getMetadata());
0619: assertEquals("[fr] Default Link", check
0620: .getTitle(Locale.FRENCH));
0621: assertEquals("[de] Default Link", check
0622: .getTitle(Locale.GERMAN));
0623: assertNotNull(check.getSecurityConstraints());
0624: assertEquals("user", check.getSecurityConstraints()
0625: .getOwner());
0626: assertNotNull(check.getSecurityConstraints()
0627: .getSecurityConstraintsRefs());
0628: assertEquals(1, check.getSecurityConstraints()
0629: .getSecurityConstraintsRefs().size());
0630: assertEquals("manager-edit", (String) check
0631: .getSecurityConstraints()
0632: .getSecurityConstraintsRefs().get(0));
0633: assertNotNull(check.getSecurityConstraints()
0634: .getSecurityConstraints());
0635: assertEquals(1, check.getSecurityConstraints()
0636: .getSecurityConstraints().size());
0637: assertEquals("jetspeed", Shared
0638: .makeCSVFromList(((SecurityConstraint) check
0639: .getSecurityConstraints()
0640: .getSecurityConstraints().get(0))
0641: .getUsers()));
0642: assertNotNull(check.getParent());
0643: } catch (PageNotFoundException e) {
0644: assertTrue("Link /default.link NOT FOUND", false);
0645: }
0646: try {
0647: Page check = pageManager.getPage("/default-page.psml");
0648: assertEquals("/default-page.psml", check.getPath());
0649: assertEquals("default-page.psml", check.getName());
0650: assertEquals("/default-page.psml", check.getUrl());
0651: assertEquals("Default Page", check.getTitle());
0652: assertEquals("6.89", check.getVersion());
0653: assertEquals("tigris", check
0654: .getEffectiveDefaultDecorator(Fragment.LAYOUT));
0655: assertEquals("tigris", check
0656: .getDefaultDecorator(Fragment.LAYOUT));
0657: assertEquals("blue-gradient", check
0658: .getDefaultDecorator(Fragment.PORTLET));
0659: assertEquals("skin-1", check.getSkin());
0660: assertEquals("Default", check.getShortTitle());
0661: assertNotNull(check.getMetadata());
0662: assertEquals("[fr] Default Page", check
0663: .getTitle(Locale.FRENCH));
0664: assertEquals("[ja] Default Page", check
0665: .getTitle(Locale.JAPANESE));
0666: assertNotNull(check.getSecurityConstraints());
0667: assertEquals("user", check.getSecurityConstraints()
0668: .getOwner());
0669: assertNotNull(check.getSecurityConstraints()
0670: .getSecurityConstraintsRefs());
0671: assertEquals(1, check.getSecurityConstraints()
0672: .getSecurityConstraintsRefs().size());
0673: assertEquals("manager-edit", (String) check
0674: .getSecurityConstraints()
0675: .getSecurityConstraintsRefs().get(0));
0676: assertNotNull(check.getSecurityConstraints()
0677: .getSecurityConstraints());
0678: assertEquals(1, check.getSecurityConstraints()
0679: .getSecurityConstraints().size());
0680: assertEquals("jetspeed", Shared
0681: .makeCSVFromList(((SecurityConstraint) check
0682: .getSecurityConstraints()
0683: .getSecurityConstraints().get(0))
0684: .getUsers()));
0685: assertNotNull(check.getMenuDefinitions());
0686: assertEquals(2, check.getMenuDefinitions().size());
0687: MenuDefinition checkMenu = (MenuDefinition) check
0688: .getMenuDefinitions().get(0);
0689: assertEquals("page-menu-1", checkMenu.getName());
0690: assertEquals("The Test Page Menu", checkMenu.getTitle());
0691: assertEquals("[fr] The Test Page Menu", checkMenu
0692: .getTitle(Locale.FRENCH));
0693: assertNotNull(checkMenu.getMenuElements());
0694: assertEquals(5, checkMenu.getMenuElements().size());
0695: assertTrue(checkMenu.getMenuElements().get(0) instanceof MenuSeparatorDefinition);
0696: assertEquals("-- Page Menu --",
0697: ((MenuSeparatorDefinition) checkMenu
0698: .getMenuElements().get(0)).getText());
0699: assertTrue(checkMenu.getMenuElements().get(1) instanceof MenuOptionsDefinition);
0700: assertEquals("/*.psml", ((MenuOptionsDefinition) checkMenu
0701: .getMenuElements().get(1)).getOptions());
0702: assertTrue(checkMenu.getMenuElements().get(2) instanceof MenuDefinition);
0703: assertEquals("/*/", ((MenuDefinition) checkMenu
0704: .getMenuElements().get(2)).getOptions());
0705: assertNotNull(((MenuDefinition) checkMenu.getMenuElements()
0706: .get(2)).getMenuElements());
0707: assertTrue(((MenuDefinition) checkMenu.getMenuElements()
0708: .get(2)).getMenuElements().isEmpty());
0709: assertTrue(checkMenu.getMenuElements().get(3) instanceof MenuExcludeDefinition);
0710: assertEquals("exclude-menu",
0711: ((MenuExcludeDefinition) checkMenu
0712: .getMenuElements().get(3)).getName());
0713: assertTrue(checkMenu.getMenuElements().get(4) instanceof MenuIncludeDefinition);
0714: assertEquals("include-menu",
0715: ((MenuIncludeDefinition) checkMenu
0716: .getMenuElements().get(4)).getName());
0717: checkMenu = (MenuDefinition) check.getMenuDefinitions()
0718: .get(1);
0719: assertEquals("page-menu-2", checkMenu.getName());
0720: assertNotNull(checkMenu.getMenuElements());
0721: assertTrue(checkMenu.getMenuElements().isEmpty());
0722: assertNotNull(check.getRootFragment());
0723: assertEquals("blue-gradient", check.getRootFragment()
0724: .getDecorator());
0725: assertEquals("jetspeed-layouts::VelocityTwoColumns", check
0726: .getRootFragment().getName());
0727: assertEquals("Root", check.getRootFragment()
0728: .getShortTitle());
0729: assertEquals("Root Fragment", check.getRootFragment()
0730: .getTitle());
0731: assertEquals("Normal", check.getRootFragment().getState());
0732: assertEquals("50%,50%", check.getRootFragment()
0733: .getLayoutSizes());
0734: assertNotNull(check.getRootFragment().getProperties());
0735: assertEquals("custom-prop-value1", check.getRootFragment()
0736: .getProperty("custom-prop1"));
0737: assertNotNull(check.getRootFragment().getFragments());
0738: assertEquals(2, check.getRootFragment().getFragments()
0739: .size());
0740: Fragment check0 = (Fragment) check.getRootFragment()
0741: .getFragments().get(0);
0742: assertEquals("security::LoginPortlet", check0.getName());
0743: assertEquals("Portlet", check0.getShortTitle());
0744: assertEquals("Portlet Fragment", check0.getTitle());
0745: assertEquals("Normal", check0.getState());
0746: assertEquals(88, check0.getLayoutRow());
0747: assertEquals(88, check0
0748: .getIntProperty(Fragment.ROW_PROPERTY_NAME));
0749: assertEquals(99, check0.getLayoutColumn());
0750: assertNotNull(check0.getProperty(Fragment.X_PROPERTY_NAME));
0751: assertTrue(check0.getProperty(Fragment.X_PROPERTY_NAME)
0752: .startsWith("12.3"));
0753: assertTrue((check0.getLayoutX() > 12.0F)
0754: && (check0.getLayoutX() < 13.0F));
0755: assertTrue((check0
0756: .getFloatProperty(Fragment.X_PROPERTY_NAME) > 12.0F)
0757: && (check0
0758: .getFloatProperty(Fragment.X_PROPERTY_NAME) < 13.0F));
0759: assertTrue((check0.getLayoutY() > 23.0F)
0760: && (check0.getLayoutY() < 24.0F));
0761: assertTrue((check0.getLayoutZ() > 34.0F)
0762: && (check0.getLayoutZ() < 35.0F));
0763: assertTrue((check0.getLayoutWidth() > 45.0F)
0764: && (check0.getLayoutWidth() < 46.0F));
0765: assertTrue((check0.getLayoutHeight() > 56.0F)
0766: && (check0.getLayoutWidth() < 57.0F));
0767: assertNotNull(check0.getPreferences());
0768: assertEquals(2, check0.getPreferences().size());
0769: assertEquals("pref0", ((FragmentPreference) check0
0770: .getPreferences().get(0)).getName());
0771: assertTrue(((FragmentPreference) check0.getPreferences()
0772: .get(0)).isReadOnly());
0773: assertNotNull(((FragmentPreference) check0.getPreferences()
0774: .get(0)).getValueList());
0775: assertEquals(2, ((FragmentPreference) check0
0776: .getPreferences().get(0)).getValueList().size());
0777: assertEquals("pref0-value0",
0778: (String) ((FragmentPreference) check0
0779: .getPreferences().get(0)).getValueList()
0780: .get(0));
0781: assertEquals("pref0-value1",
0782: (String) ((FragmentPreference) check0
0783: .getPreferences().get(0)).getValueList()
0784: .get(1));
0785: assertEquals("pref1", ((FragmentPreference) check0
0786: .getPreferences().get(1)).getName());
0787: assertFalse(((FragmentPreference) check0.getPreferences()
0788: .get(1)).isReadOnly());
0789: assertNotNull(((FragmentPreference) check0.getPreferences()
0790: .get(1)).getValueList());
0791: assertEquals(1, ((FragmentPreference) check0
0792: .getPreferences().get(1)).getValueList().size());
0793: assertEquals("pref1-value",
0794: (String) ((FragmentPreference) check0
0795: .getPreferences().get(1)).getValueList()
0796: .get(0));
0797: Fragment check1 = (Fragment) check.getRootFragment()
0798: .getFragments().get(1);
0799: assertEquals("some-app::SomePortlet", check1.getName());
0800: assertEquals("Some Portlet", check1.getShortTitle());
0801: assertEquals("Some Portlet Fragment", check1.getTitle());
0802: assertEquals("Normal", check1.getState());
0803: assertEquals(22, check1.getLayoutRow());
0804: assertEquals(11, check1.getLayoutColumn());
0805: assertTrue((check1.getLayoutX() > 11.0F)
0806: && (check1.getLayoutX() < 12.0F));
0807: assertTrue((check1.getLayoutY() > 22.0F)
0808: && (check1.getLayoutY() < 23.0F));
0809: assertTrue((check1.getLayoutZ() > 33.0F)
0810: && (check1.getLayoutZ() < 34.0F));
0811: assertTrue((check1.getLayoutWidth() > 44.0F)
0812: && (check1.getLayoutWidth() < 45.0F));
0813: assertTrue((check1.getLayoutHeight() > 55.0F)
0814: && (check1.getLayoutWidth() < 56.0F));
0815: assertNotNull(check1.getSecurityConstraints());
0816: assertEquals("user", check1.getSecurityConstraints()
0817: .getOwner());
0818: assertNotNull(check.getFragmentById(check0.getId()));
0819: assertNotNull(check
0820: .getFragmentsByName("some-app::SomePortlet"));
0821: assertEquals(1, check.getFragmentsByName(
0822: "some-app::SomePortlet").size());
0823: assertNotNull(check.getParent());
0824: } catch (PageNotFoundException e) {
0825: assertTrue("Page /default-page.psml NOT FOUND", false);
0826: }
0827: try {
0828: Folder check = pageManager.getFolder("/");
0829: assertEquals("/", check.getPath());
0830: assertEquals("/", check.getName());
0831: assertEquals("/", check.getUrl());
0832: assertEquals("Root Folder", check.getTitle());
0833: assertEquals("jetspeed", check
0834: .getEffectiveDefaultDecorator(Fragment.LAYOUT));
0835: assertEquals("jetspeed", check
0836: .getDefaultDecorator(Fragment.LAYOUT));
0837: assertEquals("gray-gradient", check
0838: .getDefaultDecorator(Fragment.PORTLET));
0839: assertEquals("skin-1", check.getSkin());
0840: assertEquals("default-page.psml", check.getDefaultPage());
0841: assertEquals("Root", check.getShortTitle());
0842: assertNotNull(check.getMetadata());
0843: assertEquals("[fr] Root Folder", check
0844: .getTitle(Locale.FRENCH));
0845: assertNotNull(check.getSecurityConstraints());
0846: assertEquals("admin", check.getSecurityConstraints()
0847: .getOwner());
0848: assertNotNull(check.getSecurityConstraints()
0849: .getSecurityConstraintsRefs());
0850: assertEquals(2, check.getSecurityConstraints()
0851: .getSecurityConstraintsRefs().size());
0852: assertEquals("public-edit", (String) check
0853: .getSecurityConstraints()
0854: .getSecurityConstraintsRefs().get(1));
0855: assertNotNull(check.getSecurityConstraints()
0856: .getSecurityConstraints());
0857: assertEquals(2, check.getSecurityConstraints()
0858: .getSecurityConstraints().size());
0859: assertEquals("user,admin", Shared
0860: .makeCSVFromList(((SecurityConstraint) check
0861: .getSecurityConstraints()
0862: .getSecurityConstraints().get(0))
0863: .getUsers()));
0864: assertEquals("manager", Shared
0865: .makeCSVFromList(((SecurityConstraint) check
0866: .getSecurityConstraints()
0867: .getSecurityConstraints().get(0))
0868: .getRoles()));
0869: assertEquals("*", Shared
0870: .makeCSVFromList(((SecurityConstraint) check
0871: .getSecurityConstraints()
0872: .getSecurityConstraints().get(0))
0873: .getGroups()));
0874: assertEquals("edit", Shared
0875: .makeCSVFromList(((SecurityConstraint) check
0876: .getSecurityConstraints()
0877: .getSecurityConstraints().get(1))
0878: .getPermissions()));
0879: assertNotNull(check.getDocumentOrder());
0880: assertEquals(2, check.getDocumentOrder().size());
0881: assertEquals("some-other-page.psml", (String) check
0882: .getDocumentOrder().get(0));
0883: assertEquals("default-page.psml", (String) check
0884: .getDocumentOrder().get(1));
0885: assertNull(check.getParent());
0886: assertNotNull(check.getPageSecurity());
0887: assertNotNull(check.getPages());
0888: assertEquals(3, check.getPages().size());
0889: assertNotNull(check.getLinks());
0890: assertEquals(1, check.getLinks().size());
0891: assertNotNull(check.getFolders());
0892: assertEquals(1, check.getFolders().size());
0893: assertNotNull(check.getAll());
0894: assertEquals(6, check.getAll().size());
0895: Iterator all = check.getAll().iterator();
0896: assertEquals("some-other-page.psml", ((Node) all.next())
0897: .getName());
0898: assertEquals("default-page.psml", ((Node) all.next())
0899: .getName());
0900: assertEquals("__subsite-rootx", ((Node) all.next())
0901: .getName());
0902: assertEquals("another-page.psml", ((Node) all.next())
0903: .getName());
0904: assertEquals("default.link", ((Node) all.next()).getName());
0905: assertEquals("page.security", ((Node) all.next()).getName());
0906: assertNotNull(check.getMenuDefinitions());
0907: assertEquals(2, check.getMenuDefinitions().size());
0908: MenuDefinition checkMenu = (MenuDefinition) check
0909: .getMenuDefinitions().get(0);
0910: assertEquals("folder-breadcrumb-menu", checkMenu.getName());
0911: assertEquals("bread-crumbs", checkMenu.getSkin());
0912: assertEquals("./", checkMenu.getOptions());
0913: assertTrue(checkMenu.isPaths());
0914: assertNotNull(checkMenu.getMenuElements());
0915: assertTrue(checkMenu.getMenuElements().isEmpty());
0916: checkMenu = (MenuDefinition) check.getMenuDefinitions()
0917: .get(1);
0918: assertEquals("folder-menu", checkMenu.getName());
0919: assertEquals("The Test Folder Menu", checkMenu.getTitle());
0920: assertEquals("Folder Menu", checkMenu.getShortTitle());
0921: assertEquals("group-fallback", checkMenu.getProfile());
0922: assertEquals("[fr] Folder Menu", checkMenu
0923: .getShortTitle(Locale.FRENCH));
0924: assertEquals("[fr] The Test Folder Menu", checkMenu
0925: .getTitle(Locale.FRENCH));
0926: assertNotNull(checkMenu.getMenuElements());
0927: assertEquals(6, checkMenu.getMenuElements().size());
0928: assertTrue(checkMenu.getMenuElements().get(0) instanceof MenuSeparatorDefinition);
0929: assertEquals("-- Folder Menu --",
0930: ((MenuSeparatorDefinition) checkMenu
0931: .getMenuElements().get(0)).getText());
0932: assertEquals("Rollover: Folder Menu",
0933: ((MenuSeparatorDefinition) checkMenu
0934: .getMenuElements().get(0)).getTitle());
0935: assertEquals("header", ((MenuSeparatorDefinition) checkMenu
0936: .getMenuElements().get(0)).getSkin());
0937: assertEquals("-- [fr] Folder Menu --",
0938: ((MenuSeparatorDefinition) checkMenu
0939: .getMenuElements().get(0))
0940: .getText(Locale.FRENCH));
0941: assertEquals("[fr] Rollover: Folder Menu",
0942: ((MenuSeparatorDefinition) checkMenu
0943: .getMenuElements().get(0))
0944: .getTitle(Locale.FRENCH));
0945: assertTrue(checkMenu.getMenuElements().get(1) instanceof MenuOptionsDefinition);
0946: assertEquals("/*.psml", ((MenuOptionsDefinition) checkMenu
0947: .getMenuElements().get(1)).getOptions());
0948: assertTrue(((MenuOptionsDefinition) checkMenu
0949: .getMenuElements().get(1)).isRegexp());
0950: assertEquals("flash", ((MenuOptionsDefinition) checkMenu
0951: .getMenuElements().get(1)).getSkin());
0952: assertTrue(checkMenu.getMenuElements().get(2) instanceof MenuOptionsDefinition);
0953: assertEquals("/folder0", ((MenuOptionsDefinition) checkMenu
0954: .getMenuElements().get(2)).getOptions());
0955: assertEquals("role-fallback",
0956: ((MenuOptionsDefinition) checkMenu
0957: .getMenuElements().get(2)).getProfile());
0958: assertEquals("/folder*", ((MenuOptionsDefinition) checkMenu
0959: .getMenuElements().get(2)).getOrder());
0960: assertEquals(1, ((MenuOptionsDefinition) checkMenu
0961: .getMenuElements().get(2)).getDepth());
0962: assertTrue(((MenuOptionsDefinition) checkMenu
0963: .getMenuElements().get(2)).isPaths());
0964: assertTrue(checkMenu.getMenuElements().get(3) instanceof MenuDefinition);
0965: assertEquals("/*/", ((MenuDefinition) checkMenu
0966: .getMenuElements().get(3)).getOptions());
0967: assertTrue(((MenuDefinition) checkMenu.getMenuElements()
0968: .get(3)).isRegexp());
0969: assertEquals(2, ((MenuDefinition) checkMenu
0970: .getMenuElements().get(3)).getDepth());
0971: assertEquals("/x*/,/y*/,/z*/", ((MenuDefinition) checkMenu
0972: .getMenuElements().get(3)).getOrder());
0973: assertEquals("bold", ((MenuDefinition) checkMenu
0974: .getMenuElements().get(3)).getSkin());
0975: assertNotNull(((MenuDefinition) checkMenu.getMenuElements()
0976: .get(3)).getMenuElements());
0977: assertTrue(((MenuDefinition) checkMenu.getMenuElements()
0978: .get(3)).getMenuElements().isEmpty());
0979: assertTrue(checkMenu.getMenuElements().get(4) instanceof MenuExcludeDefinition);
0980: assertEquals("exclude-menu",
0981: ((MenuExcludeDefinition) checkMenu
0982: .getMenuElements().get(4)).getName());
0983: assertTrue(checkMenu.getMenuElements().get(5) instanceof MenuIncludeDefinition);
0984: assertEquals("include-menu",
0985: ((MenuIncludeDefinition) checkMenu
0986: .getMenuElements().get(5)).getName());
0987: assertTrue(((MenuIncludeDefinition) checkMenu
0988: .getMenuElements().get(5)).isNest());
0989: } catch (FolderNotFoundException e) {
0990: assertTrue("Folder / NOT FOUND", false);
0991: }
0992: try {
0993: Page check = pageManager.getPage("/another-page.psml");
0994: assertEquals("/another-page.psml", check.getPath());
0995: assertEquals("another-page.psml", check.getName());
0996: assertEquals("Another Page", check.getTitle());
0997: assertEquals("jetspeed", check
0998: .getEffectiveDefaultDecorator(Fragment.LAYOUT));
0999: assertEquals("gray-gradient", check
1000: .getEffectiveDefaultDecorator(Fragment.PORTLET));
1001: assertNull(check.getDefaultDecorator(Fragment.LAYOUT));
1002: assertNull(check.getDefaultDecorator(Fragment.PORTLET));
1003: } catch (PageNotFoundException e) {
1004: assertTrue("Page /default-page.psml NOT FOUND", false);
1005: }
1006:
1007: try {
1008: Page check = pageManager.getPage(deepPagePath);
1009: assertEquals(deepPagePath, check.getPath());
1010: assertNotNull(check.getParent());
1011: } catch (PageNotFoundException e) {
1012: assertTrue("Page " + deepPagePath + " NOT FOUND", false);
1013: }
1014: try {
1015: Folder check = pageManager.getFolder(deepFolderPath);
1016: assertEquals(deepFolderPath, check.getPath());
1017: assertNotNull(check.getParent());
1018: } catch (FolderNotFoundException e) {
1019: assertTrue("Folder " + deepFolderPath + " NOT FOUND", false);
1020: }
1021: }
1022:
1023: public void testUpdates() throws Exception {
1024: // reset page manager cache
1025: pageManager.reset();
1026:
1027: // update documents and folders in persisted store
1028: PageSecurity pageSecurity = pageManager.getPageSecurity();
1029: assertEquals("/page.security", pageSecurity.getPath());
1030: pageSecurity.getGlobalSecurityConstraintsRefs().add("UPDATED");
1031: pageManager.updatePageSecurity(pageSecurity);
1032:
1033: Page page = pageManager.getPage("/default-page.psml");
1034: assertEquals("/default-page.psml", page.getPath());
1035: page.setTitle("UPDATED");
1036: page.getRootFragment().getProperties().remove("custom-prop1");
1037: page.getRootFragment().getProperties()
1038: .put("UPDATED", "UPDATED");
1039: assertNotNull(page.getRootFragment().getFragments());
1040: assertEquals(2, page.getRootFragment().getFragments().size());
1041: String removeId = ((Fragment) page.getRootFragment()
1042: .getFragments().get(1)).getId();
1043: assertNotNull(page.removeFragmentById(removeId));
1044: SecurityConstraint pageConstraint = page
1045: .newSecurityConstraint();
1046: pageConstraint.setUsers(Shared.makeListFromCSV("UPDATED"));
1047: page.getSecurityConstraints().getSecurityConstraints().add(0,
1048: pageConstraint);
1049: pageManager.updatePage(page);
1050:
1051: Link link = pageManager.getLink("/default.link");
1052: assertEquals("/default.link", link.getPath());
1053: link.setTitle("UPDATED");
1054: link.getSecurityConstraints().setOwner("UPDATED");
1055: pageManager.updateLink(link);
1056:
1057: Folder folder = pageManager.getFolder("/");
1058: assertEquals("/", folder.getPath());
1059: folder.setTitle("UPDATED");
1060: folder.getDocumentOrder().remove("some-other-page.psml");
1061: folder.getDocumentOrder().add("UPDATED");
1062: folder.getDocumentOrder().add("some-other-page.psml");
1063: MenuDefinition updateMenu = (MenuDefinition) folder
1064: .getMenuDefinitions().get(1);
1065: updateMenu.setName("UPDATED");
1066: updateMenu.setTitle("UPDATED");
1067: updateMenu.getMetadata().addField(Locale.JAPANESE,
1068: "short-title", "[ja] UPDATED");
1069: ((MenuOptionsDefinition) updateMenu.getMenuElements().get(2))
1070: .setProfile("UPDATED");
1071: pageManager.updateFolder(folder);
1072: assertNotNull(folder.getAll());
1073: assertEquals(6, folder.getAll().size());
1074: Iterator all = folder.getAll().iterator();
1075: assertEquals("default-page.psml", ((Node) all.next()).getName());
1076: assertEquals("some-other-page.psml", ((Node) all.next())
1077: .getName());
1078:
1079: folder.setTitle("FOLDER-UPDATED-DEEP");
1080: page.setTitle("FOLDER-UPDATED-DEEP");
1081: link.setTitle("FOLDER-UPDATED-DEEP");
1082: Folder deepFolder = pageManager.getFolder(deepFolderPath);
1083: deepFolder.setTitle("FOLDER-UPDATED-DEEP");
1084: Page deepPage = pageManager.getPage(deepPagePath);
1085: deepPage.setTitle("FOLDER-UPDATED-DEEP");
1086: pageManager.updateFolder(folder, true);
1087: }
1088:
1089: public void testRemoves() throws Exception {
1090: // reset page manager cache
1091: pageManager.reset();
1092:
1093: // remove root folder
1094: try {
1095: Folder remove = pageManager.getFolder("/");
1096: assertEquals("/", remove.getPath());
1097: pageManager.removeFolder(remove);
1098: } catch (FolderNotFoundException e) {
1099: assertTrue("Folder / NOT FOUND", false);
1100: }
1101:
1102: // reset page manager cache
1103: pageManager.reset();
1104:
1105: // verify root folder deep removal
1106: try {
1107: pageManager.getFolder("/");
1108: assertTrue("Folder / FOUND", false);
1109: } catch (FolderNotFoundException e) {
1110: }
1111: try {
1112: pageManager.getPageSecurity();
1113: assertTrue("PageSecurity FOUND", false);
1114: } catch (DocumentNotFoundException e) {
1115: }
1116: try {
1117: pageManager.getLink("/default.link");
1118: assertTrue("Link /default.link FOUND", false);
1119: } catch (DocumentNotFoundException e) {
1120: }
1121: try {
1122: pageManager.getPage("/default-page.psml");
1123: assertTrue("Page /default-page.psml FOUND", false);
1124: } catch (PageNotFoundException e) {
1125: }
1126: try {
1127: pageManager.getFolder("/");
1128: assertTrue("Folder / FOUND", false);
1129: } catch (FolderNotFoundException e) {
1130: }
1131: try {
1132: pageManager.getFolder(deepFolderPath);
1133: assertTrue("Folder " + deepFolderPath + " FOUND", false);
1134: } catch (FolderNotFoundException e) {
1135: }
1136: try {
1137: pageManager.getPage(deepPagePath);
1138: assertTrue("Page " + deepPagePath + " FOUND", false);
1139: } catch (PageNotFoundException e) {
1140: }
1141: }
1142:
1143: public void testEvents() throws Exception {
1144: // verify listener functionality and operation counts
1145: assertEquals(22, newNodeCount);
1146: assertEquals(26, updatedNodeCount);
1147: assertEquals(22, removedNodeCount);
1148:
1149: // last test has been run
1150: lastTestRun = true;
1151: }
1152: }
|