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.portalsite;
0018:
0019: import java.lang.reflect.Proxy;
0020: import java.util.HashMap;
0021: import java.util.Iterator;
0022: import java.util.List;
0023: import java.util.Locale;
0024: import java.util.Map;
0025: import java.util.Set;
0026:
0027: import junit.framework.Test;
0028: import junit.framework.TestSuite;
0029:
0030: import org.apache.jetspeed.components.test.AbstractSpringTestCase;
0031: import org.apache.jetspeed.om.folder.Folder;
0032: import org.apache.jetspeed.om.folder.MenuDefinition;
0033: import org.apache.jetspeed.om.page.Link;
0034: import org.apache.jetspeed.om.page.Page;
0035: import org.apache.jetspeed.page.PageManager;
0036: import org.apache.jetspeed.page.document.NodeSet;
0037: import org.apache.jetspeed.page.document.proxy.NodeProxy;
0038: import org.apache.jetspeed.portalsite.impl.MenuImpl;
0039: import org.apache.jetspeed.portalsite.view.SiteView;
0040: import org.apache.jetspeed.profiler.ProfileLocator;
0041: import org.apache.jetspeed.profiler.impl.JetspeedProfileLocator;
0042:
0043: /**
0044: * TestPortalSite
0045: *
0046: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
0047: * @version $Id: TestPortalSite.java 598577 2007-11-27 09:55:10Z woonsan $
0048: */
0049: public class TestPortalSite extends AbstractSpringTestCase {
0050: /**
0051: * pageManager - PageManager component
0052: */
0053: private PageManager pageManager;
0054:
0055: /**
0056: * portalSite - PortalSite component
0057: */
0058: private PortalSite portalSite;
0059:
0060: /**
0061: * default locale
0062: */
0063: private Locale defaultLocale;
0064:
0065: /* (non-Javadoc)
0066: * @see junit.framework.TestCase#setUp()
0067: */
0068: protected void setUp() throws Exception {
0069: super .setUp();
0070: this .pageManager = (PageManager) ctx.getBean("pageManager");
0071: this .portalSite = (PortalSite) ctx.getBean("portalSite");
0072: this .defaultLocale = Locale.getDefault();
0073: Locale.setDefault(Locale.ENGLISH);
0074: }
0075:
0076: /* (non-Javadoc)
0077: * @see junit.framework.TestCase#tearDown()
0078: */
0079: protected void tearDown() throws Exception {
0080: super .tearDown();
0081: Locale.setDefault(this .defaultLocale);
0082: }
0083:
0084: /**
0085: * Start the tests.
0086: *
0087: * @param args the arguments. Not used
0088: */
0089: public static void main(String args[]) {
0090: junit.awtui.TestRunner.main(new String[] { TestPortalSite.class
0091: .getName() });
0092: }
0093:
0094: /**
0095: * Define test suite.
0096: *
0097: * @return the test suite
0098: */
0099: public static Test suite() {
0100: // All methods starting with "test" will be executed in the test suite.
0101: return new TestSuite(TestPortalSite.class);
0102: }
0103:
0104: /**
0105: * Define configuration paths.
0106: *
0107: * @return array of paths.
0108: */
0109: protected String[] getConfigurations() {
0110: return new String[] { "/JETSPEED-INF/spring/test-spring.xml" };
0111: }
0112:
0113: /**
0114: * testPageManagerSetup - Test PageManager test configuration
0115: *
0116: * @throws Exception
0117: */
0118: public void testPageManagerSetup() throws Exception {
0119: assertNotNull(pageManager);
0120: Folder rootFolder = pageManager.getFolder("/");
0121: assertNotNull(rootFolder);
0122: Page rootPage0 = pageManager.getPage("/page0.psml");
0123: assertNotNull(rootPage0);
0124: assertEquals(rootFolder.getPage("page0.psml"), rootPage0);
0125: Link rootLink0 = pageManager.getLink("/link0.link");
0126: assertNotNull(rootLink0);
0127: assertEquals(rootFolder.getLink("link0.link"), rootLink0);
0128: }
0129:
0130: public void testRelativeNavigations() throws Exception {
0131: JetspeedProfileLocator locator = new JetspeedProfileLocator();
0132:
0133: locator.init(null, "/");
0134: locator.add("hostname", true, false, "dash");
0135: locator.add("user", true, false, "joe");
0136: locator.add("page", false, false, "home");
0137: SiteView profileView = new SiteView(pageManager, locator);
0138: assertEquals("/_hostname/dash/_user/joe,/_hostname/dash,/",
0139: profileView.getSearchPathsString());
0140:
0141: locator = new JetspeedProfileLocator();
0142: locator.init(null, "/");
0143: locator.add("hostname", true, false, "dash");
0144: locator.add("user", true, false, "joe");
0145: locator.add("navigation", false, true, "/");
0146: locator.add("hostname", true, false, "dash");
0147: locator.add("role", true, false, "user");
0148: locator.add("page", false, false, "home");
0149: profileView = new SiteView(pageManager, locator);
0150: assertEquals(
0151: "/_hostname/dash/_user/joe,/_hostname/dash/_role/user,/_hostname/dash,/",
0152: profileView.getSearchPathsString());
0153:
0154: locator = new JetspeedProfileLocator();
0155: //locator.init(null, "/__subsite-root");
0156: locator.init(null, "/");
0157: locator.add("navigation", false, true, "subsite-root");
0158: locator.add("hostname", true, false, "localhost");
0159: locator.add("user", true, false, "sublocal");
0160: locator.add("navigation", false, true, "subsite-root");
0161: locator.add("hostname", true, false, "localhost");
0162: locator.add("role", true, false, "somerole");
0163: locator.add("path", false, false, "home");
0164: profileView = new SiteView(pageManager, locator);
0165: assertEquals(
0166: "/__subsite-root/_hostname/localhost/_user/sublocal,/__subsite-root/_hostname/localhost/_role/somerole,/__subsite-root/_hostname/localhost,/__subsite-root",
0167: profileView.getSearchPathsString());
0168: }
0169:
0170: /**
0171: * testSiteView - Test SiteView operation
0172: *
0173: * @throws Exception
0174: */
0175: public void testSiteView() throws Exception {
0176: // test degenerate SiteView
0177: SiteView baseView = new SiteView(pageManager);
0178: assertEquals("/", baseView.getSearchPathsString());
0179: Folder rootFolderProxy = baseView.getRootFolderProxy();
0180: assertNotNull(rootFolderProxy);
0181: assertEquals("/", rootFolderProxy.getName());
0182: assertEquals("root", rootFolderProxy.getTitle());
0183: assertEquals("/", extractFileSystemPathFromId(rootFolderProxy
0184: .getId()));
0185: assertEquals(4, rootFolderProxy.getFolders().size());
0186: Iterator foldersIter = rootFolderProxy.getFolders().iterator();
0187: assertEquals("folder0", ((Folder) foldersIter.next()).getName());
0188: assertEquals("folder1", ((Folder) foldersIter.next()).getName());
0189: assertEquals("folder2", ((Folder) foldersIter.next()).getName());
0190: assertEquals("folder3", ((Folder) foldersIter.next()).getName());
0191: assertEquals(4, rootFolderProxy.getPages().size());
0192: Iterator pagesIter = rootFolderProxy.getPages().iterator();
0193: assertEquals("page2.psml", ((Page) pagesIter.next()).getName());
0194: assertEquals("page1.psml", ((Page) pagesIter.next()).getName());
0195: assertEquals("page0.psml", ((Page) pagesIter.next()).getName());
0196: assertEquals("hidden.psml", ((Page) pagesIter.next()).getName());
0197: assertEquals(2, rootFolderProxy.getLinks().size());
0198: Iterator linksIter = rootFolderProxy.getLinks().iterator();
0199: assertEquals("link1.link", ((Link) linksIter.next()).getName());
0200: assertEquals("link0.link", ((Link) linksIter.next()).getName());
0201: Page rootPage0Proxy = rootFolderProxy.getPage("page0.psml");
0202: assertNotNull(rootPage0Proxy);
0203: assertEquals(rootFolderProxy, rootPage0Proxy.getParent());
0204: assertEquals("page0.psml", rootPage0Proxy.getName());
0205: assertEquals("/page0.psml",
0206: extractFileSystemPathFromId(rootPage0Proxy.getId()));
0207: Page rootHiddenProxy = rootFolderProxy.getPage("hidden.psml");
0208: assertNotNull(rootHiddenProxy);
0209: assertEquals("hidden.psml", rootHiddenProxy.getName());
0210: assertTrue(rootHiddenProxy.isHidden());
0211: Link rootLink0Proxy = rootFolderProxy.getLink("link0.link");
0212: assertNotNull(rootLink0Proxy);
0213: assertEquals(rootFolderProxy, rootLink0Proxy.getParent());
0214: assertEquals("link0.link", rootLink0Proxy.getName());
0215: assertEquals("/link0.link",
0216: extractFileSystemPathFromId(rootLink0Proxy.getId()));
0217: Folder rootFolder0Proxy = rootFolderProxy.getFolder("folder0");
0218: assertNotNull(rootFolder0Proxy);
0219: assertEquals(rootFolderProxy, rootFolder0Proxy.getParent());
0220: assertEquals(1, rootFolder0Proxy.getPages().size());
0221: assertEquals(null, rootFolder0Proxy.getLinks());
0222: assertEquals("folder0", rootFolder0Proxy.getName());
0223: assertEquals("/folder0",
0224: extractFileSystemPathFromId(rootFolder0Proxy.getId()));
0225: Page folder0Page0Proxy = rootFolder0Proxy.getPage("page0.psml");
0226: assertNotNull(folder0Page0Proxy);
0227: assertEquals(rootFolder0Proxy, folder0Page0Proxy.getParent());
0228: assertEquals("page0.psml", folder0Page0Proxy.getName());
0229: assertEquals("/folder0/page0.psml",
0230: extractFileSystemPathFromId(folder0Page0Proxy.getId()));
0231:
0232: // test SiteView access by path
0233: Folder rootFolderProxyByPath = (Folder) baseView.getNodeProxy(
0234: "/", null, false, false);
0235: assertNotNull(rootFolderProxyByPath);
0236: assertEquals(rootFolderProxy, rootFolderProxyByPath);
0237: Folder rootFolder0ProxyByPath = (Folder) baseView.getNodeProxy(
0238: "/folder0/", null, false, false);
0239: assertNotNull(rootFolder0ProxyByPath);
0240: assertEquals(rootFolder0Proxy, rootFolder0ProxyByPath);
0241: Page folder0Page0ProxyByPath = (Page) baseView.getNodeProxy(
0242: "/folder0/page0.psml", null, false, false);
0243: assertNotNull(folder0Page0ProxyByPath);
0244: assertEquals(folder0Page0Proxy, folder0Page0ProxyByPath);
0245: folder0Page0ProxyByPath = (Page) baseView.getNodeProxy(
0246: "page0.psml", rootFolder0Proxy, false, false);
0247: assertNotNull(folder0Page0ProxyByPath);
0248: assertEquals(folder0Page0Proxy, folder0Page0ProxyByPath);
0249: List rootPageProxiesByPath = baseView.getNodeProxies(
0250: "/page?.psml", null, false, false);
0251: assertNotNull(rootPageProxiesByPath);
0252: assertEquals(3, rootPageProxiesByPath.size());
0253: assertTrue(rootPageProxiesByPath.contains(rootPage0Proxy));
0254: List rootFolderProxiesByPath = baseView.getNodeProxies("/*/",
0255: null, false, false);
0256: assertNotNull(rootFolderProxiesByPath);
0257: assertEquals(4, rootFolderProxiesByPath.size());
0258: assertTrue(rootFolderProxiesByPath.contains(rootFolder0Proxy));
0259: List folderPageProxiesByPath = baseView.getNodeProxies(
0260: "*/p*[0-9].psml", rootFolderProxy, false, false);
0261: assertNotNull(folderPageProxiesByPath);
0262: assertEquals(2, folderPageProxiesByPath.size());
0263: assertTrue(folderPageProxiesByPath.contains(folder0Page0Proxy));
0264:
0265: // test aggregating SiteView
0266: SiteView aggregateView = new SiteView(pageManager,
0267: "/_user/user,/_role/role0,/_group/group,/");
0268: assertEquals("/_user/user,/_role/role0,/_group/group,/",
0269: aggregateView.getSearchPathsString());
0270: rootFolderProxy = aggregateView.getRootFolderProxy();
0271: assertNotNull(rootFolderProxy);
0272: assertEquals("/", rootFolderProxy.getName());
0273: assertEquals("user root", rootFolderProxy.getTitle());
0274: assertEquals("/_user/user",
0275: extractFileSystemPathFromId(rootFolderProxy.getId()));
0276: assertEquals(4, rootFolderProxy.getFolders().size());
0277: assertEquals(4, rootFolderProxy.getPages().size());
0278: assertEquals(2, rootFolderProxy.getLinks().size());
0279: rootPage0Proxy = rootFolderProxy.getPage("page0.psml");
0280: assertNotNull(rootPage0Proxy);
0281: assertEquals(rootFolderProxy, rootPage0Proxy.getParent());
0282: assertEquals("page0.psml", rootPage0Proxy.getName());
0283: assertEquals("/page0.psml",
0284: extractFileSystemPathFromId(rootPage0Proxy.getId()));
0285: List rootPage0ProxyMenus = rootPage0Proxy.getMenuDefinitions();
0286: assertNotNull(rootPage0ProxyMenus);
0287: assertEquals(2 + aggregateView.getStandardMenuNames().size(),
0288: rootPage0ProxyMenus.size());
0289: Iterator menusIter = rootPage0ProxyMenus.iterator();
0290: MenuDefinition rootPage0ProxyTopMenu = (MenuDefinition) menusIter
0291: .next();
0292: assertEquals("top", rootPage0ProxyTopMenu.getName());
0293: assertEquals("/", rootPage0ProxyTopMenu.getOptions());
0294: assertEquals(2, rootPage0ProxyTopMenu.getDepth());
0295: assertEquals("dhtml-pull-down", rootPage0ProxyTopMenu.getSkin());
0296: MenuDefinition rootPage0ProxyBreadCrumbMenu = (MenuDefinition) menusIter
0297: .next();
0298: assertEquals("bread-crumbs", rootPage0ProxyBreadCrumbMenu
0299: .getName());
0300: assertEquals("./", rootPage0ProxyBreadCrumbMenu.getOptions());
0301: assertEquals(true, rootPage0ProxyBreadCrumbMenu.isPaths());
0302: for (int i = 0; (i < aggregateView.getStandardMenuNames()
0303: .size()); i++) {
0304: assertTrue(aggregateView.getStandardMenuNames().contains(
0305: ((MenuDefinition) menusIter.next()).getName()));
0306: }
0307: Page rootPage2Proxy = rootFolderProxy.getPage("page2.psml");
0308: assertNotNull(rootPage2Proxy);
0309: assertEquals(rootFolderProxy, rootPage2Proxy.getParent());
0310: assertEquals("page2.psml", rootPage2Proxy.getName());
0311: assertEquals("/_user/user/page2.psml",
0312: extractFileSystemPathFromId(rootPage2Proxy.getId()));
0313: List rootPage2ProxyMenus = rootPage2Proxy.getMenuDefinitions();
0314: assertNotNull(rootPage2ProxyMenus);
0315: assertEquals(2 + aggregateView.getStandardMenuNames().size(),
0316: rootPage2ProxyMenus.size());
0317: menusIter = rootPage2ProxyMenus.iterator();
0318: MenuDefinition rootPage2ProxyTopMenu = (MenuDefinition) menusIter
0319: .next();
0320: assertEquals("top", rootPage2ProxyTopMenu.getName());
0321: assertEquals("/", rootPage2ProxyTopMenu.getOptions());
0322: assertEquals(1, rootPage2ProxyTopMenu.getDepth());
0323: MenuDefinition rootPage2ProxyBreadCrumbMenu = (MenuDefinition) menusIter
0324: .next();
0325: assertEquals("bread-crumbs", rootPage2ProxyBreadCrumbMenu
0326: .getName());
0327: for (int i = 0; (i < aggregateView.getStandardMenuNames()
0328: .size()); i++) {
0329: assertTrue(aggregateView.getStandardMenuNames().contains(
0330: ((MenuDefinition) menusIter.next()).getName()));
0331: }
0332: rootLink0Proxy = rootFolderProxy.getLink("link0.link");
0333: assertNotNull(rootLink0Proxy);
0334: assertEquals(rootFolderProxy, rootLink0Proxy.getParent());
0335: assertEquals("link0.link", rootLink0Proxy.getName());
0336: assertEquals("/_group/group/link0.link",
0337: extractFileSystemPathFromId(rootLink0Proxy.getId()));
0338: rootFolder0Proxy = rootFolderProxy.getFolder("folder0");
0339: assertNotNull(rootFolder0Proxy);
0340: assertEquals(rootFolderProxy, rootFolder0Proxy.getParent());
0341: assertEquals(1, rootFolder0Proxy.getPages().size());
0342: assertEquals(null, rootFolder0Proxy.getLinks());
0343: assertEquals(null, rootFolder0Proxy.getFolders());
0344: assertEquals("folder0", rootFolder0Proxy.getName());
0345: assertEquals("folder0", rootFolder0Proxy.getTitle());
0346: assertEquals("/folder0",
0347: extractFileSystemPathFromId(rootFolder0Proxy.getId()));
0348: folder0Page0Proxy = rootFolder0Proxy.getPage("page0.psml");
0349: assertNotNull(folder0Page0Proxy);
0350: assertEquals(rootFolder0Proxy, folder0Page0Proxy.getParent());
0351: assertEquals("page0.psml", folder0Page0Proxy.getName());
0352: assertEquals("/folder0/page0.psml",
0353: extractFileSystemPathFromId(folder0Page0Proxy.getId()));
0354: Folder rootFolder1Proxy = rootFolderProxy.getFolder("folder1");
0355: assertNotNull(rootFolder1Proxy);
0356: assertEquals(rootFolderProxy, rootFolder1Proxy.getParent());
0357: assertEquals(2, rootFolder1Proxy.getPages().size());
0358: assertEquals(null, rootFolder1Proxy.getLinks());
0359: assertEquals(null, rootFolder1Proxy.getFolders());
0360: assertEquals("folder1", rootFolder1Proxy.getName());
0361: assertEquals("group folder1", rootFolder1Proxy.getTitle());
0362: assertEquals("/_user/user/folder1",
0363: extractFileSystemPathFromId(rootFolder1Proxy.getId()));
0364:
0365: // test degenerate aggregating SiteView
0366: aggregateView = new SiteView(pageManager, "/__subsite-root");
0367: assertEquals("/__subsite-root", aggregateView
0368: .getSearchPathsString());
0369: rootFolderProxy = aggregateView.getRootFolderProxy();
0370: assertNotNull(rootFolderProxy);
0371: assertEquals("/", rootFolderProxy.getName());
0372: assertEquals("subsite root", rootFolderProxy.getTitle());
0373: assertEquals("/__subsite-root",
0374: extractFileSystemPathFromId(rootFolderProxy.getId()));
0375: assertEquals(null, rootFolderProxy.getFolders());
0376: assertEquals(1, rootFolderProxy.getPages().size());
0377: assertEquals(1, rootFolderProxy.getLinks().size());
0378:
0379: // test SiteView construction using profile locators
0380: JetspeedProfileLocator locator = new JetspeedProfileLocator();
0381: locator.init(null, "/");
0382: SiteView profileView = new SiteView(pageManager, locator);
0383: assertEquals("/", profileView.getSearchPathsString());
0384: locator = new JetspeedProfileLocator();
0385: locator.init(null, "/");
0386: locator.add("user", true, false, "user");
0387: locator.add("page", false, false, "default-page");
0388: profileView = new SiteView(pageManager, locator);
0389: assertEquals("/_user/user,/", profileView
0390: .getSearchPathsString());
0391: locator = new JetspeedProfileLocator();
0392: locator.init(null, "/");
0393: locator.add("page", false, false, "default-page");
0394: locator.add("user", true, false, "user");
0395: locator.add("mediatype", true, false, "html");
0396: locator.add("language", true, false, "en");
0397: locator.add("country", true, false, "US");
0398: profileView = new SiteView(pageManager, locator);
0399: assertEquals("/_user/user/_mediatype/html,/_user/user,/",
0400: profileView.getSearchPathsString());
0401: locator = new JetspeedProfileLocator();
0402: locator.init(null, "/");
0403: locator.add("page", false, false, "default-page");
0404: locator.add("role", true, false, "role0");
0405: locator.add("role", true, false, "role1");
0406: profileView = new SiteView(pageManager, locator);
0407: assertEquals("/_role/role0,/_role/role1,/", profileView
0408: .getSearchPathsString());
0409: locator = new JetspeedProfileLocator();
0410: locator.init(null, "/");
0411: locator.add("user", true, false, "user");
0412: locator.add("navigation", false, true, "/");
0413: locator.add("role", true, false, "role0");
0414: locator.add("navigation", false, true, "/");
0415: locator.add("group", true, false, "group");
0416: locator.add("page", false, false, "default-page");
0417: profileView = new SiteView(pageManager, locator);
0418: assertEquals("/_user/user,/_role/role0,/_group/group,/",
0419: profileView.getSearchPathsString());
0420:
0421: locator = new JetspeedProfileLocator();
0422: locator.init(null, "/");
0423: locator.add("hostname", true, false, "dash");
0424: locator.add("user", true, false, "joe");
0425: locator.add("page", false, false, "home");
0426: profileView = new SiteView(pageManager, locator);
0427: assertEquals("/_hostname/dash/_user/joe,/_hostname/dash,/",
0428: profileView.getSearchPathsString());
0429:
0430: locator = new JetspeedProfileLocator();
0431: locator.init(null, "/");
0432: locator.add("navigation", false, true, "subsite-root");
0433: profileView = new SiteView(pageManager, locator);
0434: assertEquals("/__subsite-root", profileView
0435: .getSearchPathsString());
0436: Map locators = new HashMap();
0437: locator = new JetspeedProfileLocator();
0438: locator.init(null, "/");
0439: locator.add("role", true, false, "role0");
0440: locator.add("role", true, false, "role1");
0441: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0442: locator = new JetspeedProfileLocator();
0443: locator.init(null, "/");
0444: locator.add("user", true, false, "user");
0445: locator.add("navigation", false, true, "/");
0446: locator.add("group", true, false, "group");
0447: locators.put("alternate-locator-name", locator);
0448: profileView = new SiteView(pageManager, locators);
0449: assertEquals(
0450: "/_role/role0,/_role/role1,/_user/user,/_group/group,/",
0451: profileView.getSearchPathsString());
0452: rootFolderProxy = profileView.getRootFolderProxy();
0453: assertNotNull(rootFolderProxy);
0454: assertEquals("/", rootFolderProxy.getName());
0455: assertEquals("user root", rootFolderProxy.getTitle());
0456: assertEquals("/_role/role0",
0457: extractFileSystemPathFromId(rootFolderProxy.getId()));
0458: assertEquals(ProfileLocator.PAGE_LOCATOR,
0459: extractLocatorNameFromProxy(rootFolderProxy));
0460: rootPage2Proxy = rootFolderProxy.getPage("page2.psml");
0461: assertNotNull(rootPage2Proxy);
0462: assertEquals("page2.psml", rootPage2Proxy.getName());
0463: assertEquals("/_role/role0/page2.psml",
0464: extractFileSystemPathFromId(rootPage2Proxy.getId()));
0465: assertEquals(ProfileLocator.PAGE_LOCATOR,
0466: extractLocatorNameFromProxy(rootPage2Proxy));
0467: rootFolder1Proxy = rootFolderProxy.getFolder("folder1");
0468: assertNotNull(rootFolder1Proxy);
0469: assertEquals("folder1", rootFolder1Proxy.getName());
0470: assertEquals("group folder1", rootFolder1Proxy.getTitle());
0471: assertEquals("/_user/user/folder1",
0472: extractFileSystemPathFromId(rootFolder1Proxy.getId()));
0473: assertEquals("alternate-locator-name",
0474: extractLocatorNameFromProxy(rootFolder1Proxy));
0475: Page folder1Page1Proxy = rootFolder1Proxy.getPage("page1.psml");
0476: assertNotNull(folder1Page1Proxy);
0477: assertEquals("page1.psml", folder1Page1Proxy.getName());
0478: assertEquals("/_group/group/folder1/page1.psml",
0479: extractFileSystemPathFromId(folder1Page1Proxy.getId()));
0480: assertEquals("alternate-locator-name",
0481: extractLocatorNameFromProxy(folder1Page1Proxy));
0482: }
0483:
0484: /**
0485: * testPortalSiteSetup - Test PortalSite test configuration
0486: *
0487: * @throws Exception
0488: */
0489: public void testPotalSiteSetup() throws Exception {
0490: assertNotNull(portalSite);
0491: PortalSiteSessionContext sessionContext = portalSite
0492: .newSessionContext();
0493: assertNotNull(sessionContext);
0494: JetspeedProfileLocator locator = new JetspeedProfileLocator();
0495: locator.init(null, "/");
0496: locator.add("user", true, false, "user");
0497: locator.add("navigation", false, true, "/");
0498: locator.add("role", true, false, "role0");
0499: locator.add("role", true, false, "role1");
0500: locator.add("navigation", false, true, "/");
0501: locator.add("group", true, false, "group");
0502: Map locators = new HashMap();
0503: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0504: PortalSiteRequestContext requestContext = sessionContext
0505: .newRequestContext(locators);
0506: assertNotNull(requestContext);
0507: Page requestPageProxy = requestContext.getPage();
0508: assertNotNull(requestPageProxy);
0509: assertEquals("page2.psml", requestPageProxy.getName());
0510: assertEquals("/_user/user/page2.psml",
0511: extractFileSystemPathFromId(requestPageProxy.getId()));
0512: Folder requestFolderProxy = requestContext.getFolder();
0513: assertNotNull(requestFolderProxy);
0514: assertEquals("/", requestFolderProxy.getName());
0515: assertEquals("/_user/user",
0516: extractFileSystemPathFromId(requestFolderProxy.getId()));
0517: NodeSet requestSiblingPageProxies = requestContext
0518: .getSiblingPages();
0519: assertNotNull(requestSiblingPageProxies);
0520: assertEquals(3, requestSiblingPageProxies.size());
0521: assertNotNull(requestSiblingPageProxies.get("page0.psml"));
0522: assertEquals("/page0.psml",
0523: extractFileSystemPathFromId(requestSiblingPageProxies
0524: .get("page0.psml").getId()));
0525: assertNotNull(requestSiblingPageProxies.get("page1.psml"));
0526: assertEquals("/page1.psml",
0527: extractFileSystemPathFromId(requestSiblingPageProxies
0528: .get("page1.psml").getId()));
0529: assertNotNull(requestSiblingPageProxies.get("page2.psml"));
0530: assertEquals("/_user/user/page2.psml",
0531: extractFileSystemPathFromId(requestSiblingPageProxies
0532: .get("page2.psml").getId()));
0533: Folder requestParentFolderProxy = requestContext
0534: .getParentFolder();
0535: assertNull(requestParentFolderProxy);
0536: NodeSet requestSiblingFolderProxies = requestContext
0537: .getSiblingFolders();
0538: assertNotNull(requestSiblingFolderProxies);
0539: assertEquals(3, requestSiblingFolderProxies.size());
0540: assertNotNull(requestSiblingFolderProxies.get("folder0"));
0541: assertEquals("/folder0",
0542: extractFileSystemPathFromId(requestSiblingFolderProxies
0543: .get("folder0").getId()));
0544: assertNotNull(requestSiblingFolderProxies.get("folder1"));
0545: assertEquals("/_user/user/folder1",
0546: extractFileSystemPathFromId(requestSiblingFolderProxies
0547: .get("folder1").getId()));
0548: assertNotNull(requestSiblingFolderProxies.get("folder2"));
0549: assertEquals("/folder2",
0550: extractFileSystemPathFromId(requestSiblingFolderProxies
0551: .get("folder2").getId()));
0552: Folder requestRootFolderProxy = requestContext.getRootFolder();
0553: assertNotNull(requestRootFolderProxy);
0554: assertEquals("/", requestRootFolderProxy.getName());
0555: assertEquals("/_user/user",
0556: extractFileSystemPathFromId(requestRootFolderProxy
0557: .getId()));
0558: NodeSet requestRootLinkProxies = requestContext.getRootLinks();
0559: assertNotNull(requestRootLinkProxies);
0560: assertEquals(2, requestRootLinkProxies.size());
0561: assertNotNull(requestRootLinkProxies.get("link0.link"));
0562: assertEquals("/_group/group/link0.link",
0563: extractFileSystemPathFromId(requestRootLinkProxies.get(
0564: "link0.link").getId()));
0565: assertNotNull(requestRootLinkProxies.get("link1.link"));
0566: assertEquals("/link1.link",
0567: extractFileSystemPathFromId(requestRootLinkProxies.get(
0568: "link1.link").getId()));
0569: }
0570:
0571: /**
0572: * testPortalSiteRequests - Test PortalSite request path logic
0573: *
0574: * @throws Exception
0575: */
0576: public void testPotalSiteRequests() throws Exception {
0577: assertNotNull(portalSite);
0578: PortalSiteSessionContext sessionContext = portalSite
0579: .newSessionContext();
0580: assertNotNull(sessionContext);
0581: JetspeedProfileLocator locator = new JetspeedProfileLocator();
0582: locator.init(null, "/");
0583: locator.add("page", false, false, "default-page");
0584: locator.add("user", true, false, "user");
0585: Map locators = new HashMap();
0586: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0587: PortalSiteRequestContext requestContext = sessionContext
0588: .newRequestContext(locators);
0589: assertNotNull(requestContext);
0590: Page requestPageProxy = requestContext.getPage();
0591: assertNotNull(requestPageProxy);
0592: assertEquals("page2.psml", requestPageProxy.getName());
0593: assertEquals("/_user/user/page2.psml",
0594: extractFileSystemPathFromId(requestPageProxy.getId()));
0595:
0596: locator = new JetspeedProfileLocator();
0597: locator.init(null, "/");
0598: locator.add("page", false, false, null);
0599: locator.add("user", true, false, "user");
0600: locators = new HashMap();
0601: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0602: requestContext = sessionContext.newRequestContext(locators);
0603: assertNotNull(requestContext);
0604: requestPageProxy = requestContext.getPage();
0605: assertNotNull(requestPageProxy);
0606: assertEquals("page2.psml", requestPageProxy.getName());
0607: assertEquals("/_user/user/page2.psml",
0608: extractFileSystemPathFromId(requestPageProxy.getId()));
0609:
0610: locator = new JetspeedProfileLocator();
0611: locator.init(null, "/");
0612: locator.add("page", false, false, "page1");
0613: locator.add("user", true, false, "user");
0614: locators = new HashMap();
0615: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0616: requestContext = sessionContext.newRequestContext(locators);
0617: assertNotNull(requestContext);
0618: requestPageProxy = requestContext.getPage();
0619: assertNotNull(requestPageProxy);
0620: assertEquals("page1.psml", requestPageProxy.getName());
0621: assertEquals("/page1.psml",
0622: extractFileSystemPathFromId(requestPageProxy.getId()));
0623:
0624: locator = new JetspeedProfileLocator();
0625: locator.init(null, "/");
0626: locator.add("page", false, false, "folder1/");
0627: locator.add("user", true, false, "user");
0628: locators = new HashMap();
0629: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0630: requestContext = sessionContext.newRequestContext(locators);
0631: assertNotNull(requestContext);
0632: requestPageProxy = requestContext.getPage();
0633: assertNotNull(requestPageProxy);
0634: assertEquals("page0.psml", requestPageProxy.getName());
0635: assertEquals("/_user/user/folder1/page0.psml",
0636: extractFileSystemPathFromId(requestPageProxy.getId()));
0637:
0638: locator = new JetspeedProfileLocator();
0639: locator.init(null, "/");
0640: locator.add("page", false, false, "/folder0/");
0641: locator.add("user", true, false, "user");
0642: locators = new HashMap();
0643: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0644: requestContext = sessionContext.newRequestContext(locators);
0645: assertNotNull(requestContext);
0646: requestPageProxy = requestContext.getPage();
0647: assertNotNull(requestPageProxy);
0648: assertEquals("page0.psml", requestPageProxy.getName());
0649: assertEquals("/folder0/page0.psml",
0650: extractFileSystemPathFromId(requestPageProxy.getId()));
0651:
0652: locator = new JetspeedProfileLocator();
0653: locator.init(null, "/");
0654: locator.add("page", false, false, "/folder3/default-folder0/");
0655: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0656: requestContext = sessionContext.newRequestContext(locators);
0657: assertNotNull(requestContext);
0658: requestPageProxy = requestContext.getPage();
0659: assertNotNull(requestPageProxy);
0660: assertEquals("page1.psml", requestPageProxy.getName());
0661: assertEquals("/folder3/default-folder1/page1.psml",
0662: extractFileSystemPathFromId(requestPageProxy.getId()));
0663: }
0664:
0665: /**
0666: * testPortalSiteMenus - Test PortalSite menu generation
0667: *
0668: * @throws Exception
0669: */
0670: public void testPotalSiteMenus() throws Exception {
0671: assertNotNull(portalSite);
0672: PortalSiteSessionContext sessionContext = portalSite
0673: .newSessionContext();
0674: assertNotNull(sessionContext);
0675:
0676: // first request at /
0677: JetspeedProfileLocator locator = new JetspeedProfileLocator();
0678: locator.init(null, "/");
0679: locator.add("user", true, false, "user");
0680: locator.add("mediatype", true, false, "html");
0681: Map locators = new HashMap();
0682: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0683: locator = new JetspeedProfileLocator();
0684: locator.init(null, "/");
0685: locator.add("role", true, false, "role0");
0686: locators.put("role", locator);
0687: locator = new JetspeedProfileLocator();
0688: locator.init(null, "/");
0689: locator.add("group", true, false, "group");
0690: locators.put("group", locator);
0691: PortalSiteRequestContext requestContext = sessionContext
0692: .newRequestContext(locators);
0693: assertNotNull(requestContext);
0694: Set customMenuNames = requestContext.getCustomMenuNames();
0695: assertNotNull(customMenuNames);
0696: assertEquals(2, customMenuNames.size());
0697: assertTrue(customMenuNames.contains("top"));
0698: assertTrue(customMenuNames.contains("bread-crumbs"));
0699: Menu topMenu = requestContext.getMenu("top");
0700: assertNotNull(topMenu);
0701: assertEquals(MenuElement.MENU_ELEMENT_TYPE, topMenu
0702: .getElementType());
0703: assertNull(topMenu.getParentMenu());
0704: assertEquals("user root", topMenu.getTitle());
0705: assertEquals("user", topMenu.getShortTitle());
0706: assertEquals("dhtml-pull-down", topMenu.getSkin());
0707: assertEquals("top", topMenu.getName());
0708: assertEquals("/", topMenu.getUrl());
0709: assertFalse(topMenu.isEmpty());
0710: List topMenuElements = topMenu.getElements();
0711: assertNotNull(topMenuElements);
0712: assertEquals(7, topMenuElements.size());
0713: Iterator menuElementsIter = topMenuElements.iterator();
0714: while (menuElementsIter.hasNext()) {
0715: MenuElement element = (MenuElement) menuElementsIter.next();
0716: if (element.getElementType().equals(
0717: MenuElement.MENU_ELEMENT_TYPE)
0718: && element.getTitle().equals("folder0")) {
0719: assertTrue(element instanceof Menu);
0720: assertEquals("/folder0", ((Menu) element).getUrl());
0721: assertTrue(((Menu) element).getParentMenu() == topMenu);
0722: assertFalse(((Menu) element).isEmpty());
0723: List elements = ((Menu) element).getElements();
0724: assertNotNull(elements);
0725: assertEquals(1, elements.size());
0726: assertTrue(elements.get(0) instanceof MenuOption);
0727: assertEquals("/folder0/page0.psml",
0728: ((MenuOption) elements.get(0)).getUrl());
0729: assertEquals("dhtml-pull-down", element.getSkin());
0730: } else if (element.getElementType().equals(
0731: MenuElement.MENU_ELEMENT_TYPE)
0732: && element.getTitle().equals("group folder1")) {
0733: assertTrue(element instanceof Menu);
0734: assertEquals("/folder1", ((Menu) element).getUrl());
0735: assertTrue(((Menu) element).getParentMenu() == topMenu);
0736: assertFalse(((Menu) element).isEmpty());
0737: List elements = ((Menu) element).getElements();
0738: assertNotNull(elements);
0739: assertEquals(2, elements.size());
0740: assertTrue(elements.get(0) instanceof MenuOption);
0741: assertEquals("/folder1/page0.psml",
0742: ((MenuOption) elements.get(0)).getTitle());
0743: assertTrue(elements.get(1) instanceof MenuOption);
0744: assertEquals("/folder1/page1.psml",
0745: ((MenuOption) elements.get(1)).getTitle());
0746: } else if (element.getElementType().equals(
0747: MenuElement.OPTION_ELEMENT_TYPE)
0748: && element.getTitle().equals("/page2.psml")) {
0749: assertTrue(element instanceof MenuOption);
0750: assertEquals("/page2.psml", ((MenuOption) element)
0751: .getUrl());
0752: assertEquals(MenuOption.PAGE_OPTION_TYPE,
0753: ((MenuOption) element).getType());
0754: } else if (element.getElementType().equals(
0755: MenuElement.OPTION_ELEMENT_TYPE)
0756: && element.getTitle().equals("/page1.psml")) {
0757: assertTrue(element instanceof MenuOption);
0758: assertEquals("/page1.psml", ((MenuOption) element)
0759: .getUrl());
0760: } else if (element.getElementType().equals(
0761: MenuElement.OPTION_ELEMENT_TYPE)
0762: && element.getTitle().equals("/page0.psml")) {
0763: assertTrue(element instanceof MenuOption);
0764: assertEquals("/page0.psml", ((MenuOption) element)
0765: .getUrl());
0766: } else if (element.getElementType().equals(
0767: MenuElement.OPTION_ELEMENT_TYPE)
0768: && element.getTitle().equals("/link1.link")) {
0769: assertTrue(element instanceof MenuOption);
0770: assertEquals("http://link1", ((MenuOption) element)
0771: .getUrl());
0772: assertEquals("top", ((MenuOption) element).getTarget());
0773: assertEquals(MenuOption.LINK_OPTION_TYPE,
0774: ((MenuOption) element).getType());
0775: } else if (element.getElementType().equals(
0776: MenuElement.OPTION_ELEMENT_TYPE)
0777: && element.getTitle().equals("/link0.link")) {
0778: assertTrue(element instanceof MenuOption);
0779: assertEquals("http://link0", ((MenuOption) element)
0780: .getUrl());
0781: assertNull(((MenuOption) element).getTarget());
0782: assertEquals("dhtml-pull-down", element.getSkin());
0783: } else {
0784: fail("Unexpected menu element type/title: "
0785: + element.getElementType() + "/"
0786: + element.getTitle());
0787: }
0788: }
0789: assertTrue(topMenu.isSelected(requestContext));
0790: MenuElement selected = topMenu
0791: .getSelectedElement(requestContext);
0792: assertNotNull(selected);
0793: assertEquals(MenuElement.OPTION_ELEMENT_TYPE, selected
0794: .getElementType());
0795: assertTrue(selected instanceof MenuOption);
0796: assertEquals("/page2.psml", ((MenuOption) selected).getUrl());
0797: assertEquals("/page2.psml", selected.getTitle());
0798: assertEquals("dhtml-pull-down", selected.getSkin());
0799: assertFalse(((MenuImpl) topMenu).isElementRelative());
0800: Menu breadCrumbsMenu = requestContext.getMenu("bread-crumbs");
0801: assertNotNull(breadCrumbsMenu);
0802: assertEquals("bread-crumbs", breadCrumbsMenu.getName());
0803: assertEquals("/", breadCrumbsMenu.getUrl());
0804: assertFalse(breadCrumbsMenu.isEmpty());
0805: List breadCrumbsElements = breadCrumbsMenu.getElements();
0806: assertNotNull(breadCrumbsElements);
0807: assertEquals(1, breadCrumbsElements.size());
0808: assertTrue(breadCrumbsElements.get(0) instanceof MenuOption);
0809: assertEquals("/", ((MenuOption) breadCrumbsElements.get(0))
0810: .getUrl());
0811: assertEquals(MenuOption.FOLDER_OPTION_TYPE,
0812: ((MenuOption) breadCrumbsElements.get(0)).getType());
0813: assertTrue(((MenuImpl) breadCrumbsMenu).isElementRelative());
0814:
0815: // second request at /folder0
0816: locator = new JetspeedProfileLocator();
0817: locator.init(null, "/folder0");
0818: locator.add("user", true, false, "user");
0819: locator.add("mediatype", true, false, "html");
0820: locators = new HashMap();
0821: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0822: locator = new JetspeedProfileLocator();
0823: locator.init(null, "/folder0");
0824: locator.add("role", true, false, "role0");
0825: locators.put("role", locator);
0826: locator = new JetspeedProfileLocator();
0827: locator.init(null, "/folder0");
0828: locator.add("group", true, false, "group");
0829: locators.put("group", locator);
0830: requestContext = sessionContext.newRequestContext(locators);
0831: assertNotNull(requestContext);
0832: Menu topMenu2 = requestContext.getMenu("top");
0833: assertNotNull(topMenu2);
0834: assertTrue(topMenu == topMenu2);
0835: Menu breadCrumbsMenu2 = requestContext.getMenu("bread-crumbs");
0836: assertNotNull(breadCrumbsMenu2);
0837: assertTrue(breadCrumbsMenu != breadCrumbsMenu2);
0838: assertEquals("bread-crumbs", breadCrumbsMenu2.getName());
0839: assertEquals("/folder0", breadCrumbsMenu2.getUrl());
0840: assertFalse(breadCrumbsMenu2.isEmpty());
0841: breadCrumbsElements = breadCrumbsMenu2.getElements();
0842: assertNotNull(breadCrumbsElements);
0843: assertEquals(2, breadCrumbsElements.size());
0844: assertTrue(breadCrumbsElements.get(0) instanceof MenuOption);
0845: assertEquals("/", ((MenuOption) breadCrumbsElements.get(0))
0846: .getUrl());
0847: assertEquals(MenuOption.FOLDER_OPTION_TYPE,
0848: ((MenuOption) breadCrumbsElements.get(0)).getType());
0849: assertEquals("/folder0", ((MenuOption) breadCrumbsElements
0850: .get(1)).getUrl());
0851: assertEquals(MenuOption.FOLDER_OPTION_TYPE,
0852: ((MenuOption) breadCrumbsElements.get(1)).getType());
0853: assertTrue(((MenuImpl) breadCrumbsMenu2).isElementRelative());
0854: Menu hiddenMenu = requestContext.getMenu("override-hidden");
0855: assertNotNull(hiddenMenu);
0856: assertTrue(hiddenMenu.isEmpty());
0857: Menu navigationsMenu = requestContext.getMenu("navigations");
0858: assertNotNull(navigationsMenu);
0859: assertTrue(navigationsMenu.isEmpty());
0860:
0861: // third request at /page1.psml
0862: locator = new JetspeedProfileLocator();
0863: locator.init(null, "/page1.psml");
0864: locator.add("user", true, false, "user");
0865: locator.add("mediatype", true, false, "html");
0866: locators = new HashMap();
0867: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0868: locator = new JetspeedProfileLocator();
0869: locator.init(null, "/page1.psml");
0870: locator.add("role", true, false, "role0");
0871: locators.put("role", locator);
0872: locator = new JetspeedProfileLocator();
0873: locator.init(null, "/page1.psml");
0874: locator.add("group", true, false, "group");
0875: locators.put("group", locator);
0876: requestContext = sessionContext.newRequestContext(locators);
0877: assertNotNull(requestContext);
0878: assertNull(requestContext.getMenu("no-such-menu"));
0879: Menu topMenu3 = requestContext.getMenu("top");
0880: assertNotNull(topMenu3);
0881: assertTrue(topMenu == topMenu3);
0882: Menu backMenu = requestContext.getMenu("back");
0883: assertNotNull(backMenu);
0884: assertTrue(backMenu.isEmpty());
0885: assertNull(backMenu.getElements());
0886: assertTrue(((MenuImpl) backMenu).isElementRelative());
0887: assertEquals("back", backMenu.getName());
0888: assertEquals("Back to", backMenu.getTitle());
0889: assertEquals("Back to", backMenu.getShortTitle());
0890: assertEquals("\u00bb", backMenu.getTitle(Locale.JAPANESE));
0891: assertEquals("\u00bb", backMenu.getShortTitle(Locale.JAPANESE));
0892: assertEquals("Back to", backMenu.getTitle(new Locale("xx")));
0893: assertEquals("Back to", backMenu
0894: .getShortTitle(new Locale("xx")));
0895: Menu breadcrumbsMenu = requestContext.getMenu("breadcrumbs");
0896: assertNotNull(breadcrumbsMenu);
0897: assertFalse(breadcrumbsMenu.isEmpty());
0898: assertEquals("You are here:", breadcrumbsMenu.getTitle());
0899: assertEquals("\u73fe\u5728\u30d1\u30b9\uff1a", breadcrumbsMenu
0900: .getTitle(Locale.JAPANESE));
0901: navigationsMenu = requestContext.getMenu("navigations");
0902: assertNotNull(navigationsMenu);
0903: assertFalse(navigationsMenu.isEmpty());
0904: List navigationsElements = navigationsMenu.getElements();
0905: assertNotNull(navigationsElements);
0906: assertEquals(6, navigationsElements.size());
0907: menuElementsIter = navigationsElements.iterator();
0908: while (menuElementsIter.hasNext()) {
0909: MenuElement element = (MenuElement) menuElementsIter.next();
0910: if (element.getElementType().equals(
0911: MenuElement.SEPARATOR_ELEMENT_TYPE)
0912: && (element instanceof MenuSeparator)
0913: && ((MenuSeparator) element).getText().equals(
0914: "Folders")) {
0915: } else if (element.getElementType().equals(
0916: MenuElement.OPTION_ELEMENT_TYPE)
0917: && element.getTitle().equals("folder0")) {
0918: assertTrue(element instanceof MenuOption);
0919: assertEquals(MenuOption.FOLDER_OPTION_TYPE,
0920: ((MenuOption) element).getType());
0921: } else if (element.getElementType().equals(
0922: MenuElement.OPTION_ELEMENT_TYPE)
0923: && element.getTitle().equals("group folder1")) {
0924: assertTrue(element instanceof MenuOption);
0925: assertEquals(MenuOption.FOLDER_OPTION_TYPE,
0926: ((MenuOption) element).getType());
0927: } else if (element.getElementType().equals(
0928: MenuElement.SEPARATOR_ELEMENT_TYPE)
0929: && (element instanceof MenuSeparator)
0930: && ((MenuSeparator) element).getText().equals(
0931: "Additional Links")) {
0932: } else if (element.getElementType().equals(
0933: MenuElement.OPTION_ELEMENT_TYPE)
0934: && element.getTitle().equals("/link1.link")) {
0935: assertTrue(element instanceof MenuOption);
0936: assertEquals(MenuOption.LINK_OPTION_TYPE,
0937: ((MenuOption) element).getType());
0938: } else if (element.getElementType().equals(
0939: MenuElement.OPTION_ELEMENT_TYPE)
0940: && element.getTitle().equals("/link0.link")) {
0941: assertTrue(element instanceof MenuOption);
0942: assertEquals(MenuOption.LINK_OPTION_TYPE,
0943: ((MenuOption) element).getType());
0944: assertEquals("left-navigations", element.getSkin());
0945: } else {
0946: fail("Unexpected menu element type/title: "
0947: + element.getElementType() + "/"
0948: + element.getTitle());
0949: }
0950: }
0951: assertEquals("left-navigations", navigationsMenu.getSkin());
0952: assertTrue(((MenuImpl) navigationsMenu).isElementRelative());
0953: Menu pagesMenu = requestContext.getMenu("pages");
0954: assertNotNull(pagesMenu);
0955: assertFalse(pagesMenu.isEmpty());
0956: List pagesElements = pagesMenu.getElements();
0957: assertNotNull(pagesElements);
0958: assertEquals(3, pagesElements.size());
0959: menuElementsIter = pagesElements.iterator();
0960: while (menuElementsIter.hasNext()) {
0961: MenuElement element = (MenuElement) menuElementsIter.next();
0962: if (element.getElementType().equals(
0963: MenuElement.OPTION_ELEMENT_TYPE)
0964: && element.getTitle().equals("/page2.psml")) {
0965: assertTrue(element instanceof MenuOption);
0966: assertEquals("/page2.psml", ((MenuOption) element)
0967: .getUrl());
0968: assertEquals(MenuOption.PAGE_OPTION_TYPE,
0969: ((MenuOption) element).getType());
0970: } else if (element.getElementType().equals(
0971: MenuElement.OPTION_ELEMENT_TYPE)
0972: && element.getTitle().equals("/page1.psml")) {
0973: assertTrue(element instanceof MenuOption);
0974: assertEquals("/page1.psml", ((MenuOption) element)
0975: .getUrl());
0976: } else if (element.getElementType().equals(
0977: MenuElement.OPTION_ELEMENT_TYPE)
0978: && element.getTitle().equals("/page0.psml")) {
0979: assertTrue(element instanceof MenuOption);
0980: assertEquals("/page0.psml", ((MenuOption) element)
0981: .getUrl());
0982: assertEquals("tabs", element.getSkin());
0983: } else {
0984: fail("Unexpected menu element type/title: "
0985: + element.getElementType() + "/"
0986: + element.getTitle());
0987: }
0988: }
0989: assertEquals("tabs", pagesMenu.getSkin());
0990: assertTrue(((MenuImpl) pagesMenu).isElementRelative());
0991:
0992: // new request at /folder1
0993: locator = new JetspeedProfileLocator();
0994: locator.init(null, "/folder1");
0995: locator.add("user", true, false, "user");
0996: locator.add("mediatype", true, false, "html");
0997: locators = new HashMap();
0998: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
0999: locator = new JetspeedProfileLocator();
1000: locator.init(null, "/folder1");
1001: locator.add("group", true, false, "group");
1002: locators.put("group", locator);
1003: requestContext = sessionContext.newRequestContext(locators);
1004: assertNotNull(requestContext);
1005: Menu backMenu2 = requestContext.getMenu("back");
1006: assertNotNull(backMenu2);
1007: assertFalse(backMenu2.isEmpty());
1008: Menu topMenu4 = requestContext.getMenu("top");
1009: assertNotNull(topMenu4);
1010: assertTrue(topMenu != topMenu4);
1011: Menu customMenu = requestContext.getMenu("custom");
1012: assertNotNull(customMenu);
1013: assertFalse(customMenu.isEmpty());
1014: List customElements = customMenu.getElements();
1015: assertNotNull(customElements);
1016: assertEquals(12, customElements.size());
1017: assertEquals("custom", customMenu.getName());
1018: assertEquals("Top Menu", customMenu.getTitle());
1019: assertEquals("Haut", customMenu.getTitle(Locale.FRENCH));
1020: menuElementsIter = customElements.iterator();
1021: for (int i = 0; ((i < 2) && menuElementsIter.hasNext()); i++) {
1022: MenuElement element = (MenuElement) menuElementsIter.next();
1023: if (element.getElementType().equals(
1024: MenuElement.OPTION_ELEMENT_TYPE)
1025: && element.getTitle().equals("/link0.link")) {
1026: assertTrue(element instanceof MenuOption);
1027: assertEquals("http://link0", ((MenuOption) element)
1028: .getUrl());
1029: assertEquals(MenuOption.LINK_OPTION_TYPE,
1030: ((MenuOption) element).getType());
1031: } else if (element.getElementType().equals(
1032: MenuElement.OPTION_ELEMENT_TYPE)
1033: && element.getTitle().equals("/folder1/page1.psml")) {
1034: assertTrue(element instanceof MenuOption);
1035: assertEquals("/folder1/page1.psml",
1036: ((MenuOption) element).getUrl());
1037: assertEquals(MenuOption.PAGE_OPTION_TYPE,
1038: ((MenuOption) element).getType());
1039: } else {
1040: fail("Unexpected menu element type/title: "
1041: + element.getElementType() + "/"
1042: + element.getTitle());
1043: }
1044: }
1045: if (menuElementsIter.hasNext()) {
1046: MenuElement element = (MenuElement) menuElementsIter.next();
1047: if (element.getElementType().equals(
1048: MenuElement.MENU_ELEMENT_TYPE)
1049: && element.getTitle().equals("user root")) {
1050: assertFalse(((Menu) element).isEmpty());
1051: List nestedElements = ((Menu) element).getElements();
1052: assertEquals(6, nestedElements.size());
1053: Iterator nestedElementsIter = nestedElements.iterator();
1054: if (nestedElementsIter.hasNext()) {
1055: MenuElement nestedElement = (MenuElement) nestedElementsIter
1056: .next();
1057: if (nestedElement.getElementType().equals(
1058: MenuElement.SEPARATOR_ELEMENT_TYPE)
1059: && (nestedElement instanceof MenuSeparator)
1060: && ((MenuSeparator) nestedElement)
1061: .getText().equals(
1062: "=== Current Page ===")) {
1063: } else {
1064: fail("Unexpected nested menu element type/title: "
1065: + nestedElement.getElementType()
1066: + "/"
1067: + nestedElement.getTitle());
1068: }
1069: }
1070: if (nestedElementsIter.hasNext()) {
1071: MenuElement nestedElement = (MenuElement) nestedElementsIter
1072: .next();
1073: if (nestedElement.getElementType().equals(
1074: MenuElement.OPTION_ELEMENT_TYPE)
1075: && nestedElement.getTitle().equals(
1076: "/folder1/page1.psml")) {
1077: assertTrue(nestedElement instanceof MenuOption);
1078: assertEquals("/folder1/page1.psml",
1079: ((MenuOption) nestedElement).getUrl());
1080: assertEquals(MenuOption.PAGE_OPTION_TYPE,
1081: ((MenuOption) nestedElement).getType());
1082: } else {
1083: fail("Unexpected nested menu element type/title: "
1084: + nestedElement.getElementType()
1085: + "/"
1086: + nestedElement.getTitle());
1087: }
1088: }
1089: if (nestedElementsIter.hasNext()) {
1090: MenuElement nestedElement = (MenuElement) nestedElementsIter
1091: .next();
1092: if (nestedElement.getElementType().equals(
1093: MenuElement.SEPARATOR_ELEMENT_TYPE)
1094: && (nestedElement instanceof MenuSeparator)
1095: && ((MenuSeparator) nestedElement)
1096: .getText().equals(
1097: "=== Top Pages ===")) {
1098: assertEquals("Top Pages", nestedElement
1099: .getTitle());
1100: } else {
1101: fail("Unexpected nested menu element type/title: "
1102: + nestedElement.getElementType()
1103: + "/"
1104: + nestedElement.getTitle());
1105: }
1106: }
1107: for (int i = 0; ((i < 3) && nestedElementsIter
1108: .hasNext()); i++) {
1109: MenuElement nestedElement = (MenuElement) nestedElementsIter
1110: .next();
1111: if (nestedElement.getElementType().equals(
1112: MenuElement.OPTION_ELEMENT_TYPE)
1113: && nestedElement.getTitle().equals(
1114: "/page2.psml")) {
1115: assertTrue(nestedElement instanceof MenuOption);
1116: assertEquals("/page2.psml",
1117: ((MenuOption) nestedElement).getUrl());
1118: assertEquals(MenuOption.PAGE_OPTION_TYPE,
1119: ((MenuOption) nestedElement).getType());
1120: } else if (nestedElement.getElementType().equals(
1121: MenuElement.OPTION_ELEMENT_TYPE)
1122: && nestedElement.getTitle().equals(
1123: "/page1.psml")) {
1124: assertTrue(nestedElement instanceof MenuOption);
1125: assertEquals("/page1.psml",
1126: ((MenuOption) nestedElement).getUrl());
1127: assertEquals(MenuOption.PAGE_OPTION_TYPE,
1128: ((MenuOption) nestedElement).getType());
1129: } else if (nestedElement.getElementType().equals(
1130: MenuElement.OPTION_ELEMENT_TYPE)
1131: && nestedElement.getTitle().equals(
1132: "/page0.psml")) {
1133: assertTrue(nestedElement instanceof MenuOption);
1134: assertEquals("/page0.psml",
1135: ((MenuOption) nestedElement).getUrl());
1136: assertEquals(MenuOption.PAGE_OPTION_TYPE,
1137: ((MenuOption) nestedElement).getType());
1138: } else {
1139: fail("Unexpected nested menu element type/title: "
1140: + nestedElement.getElementType()
1141: + "/"
1142: + nestedElement.getTitle());
1143: }
1144: }
1145: } else {
1146: fail("Unexpected menu element type/title: "
1147: + element.getElementType() + "/"
1148: + element.getTitle());
1149: }
1150: }
1151: if (menuElementsIter.hasNext()) {
1152: MenuElement element = (MenuElement) menuElementsIter.next();
1153: if (element.getElementType().equals(
1154: MenuElement.SEPARATOR_ELEMENT_TYPE)
1155: && (element instanceof MenuSeparator)
1156: && ((MenuSeparator) element).getText().equals(
1157: "=== More Options ===")) {
1158: } else {
1159: fail("Unexpected menu element type/title: "
1160: + element.getElementType() + "/"
1161: + element.getTitle());
1162: }
1163: }
1164: for (int i = 0; ((i < 4) && menuElementsIter.hasNext()); i++) {
1165: MenuElement element = (MenuElement) menuElementsIter.next();
1166: if (element.getElementType().equals(
1167: MenuElement.OPTION_ELEMENT_TYPE)
1168: && element.getTitle().equals("/link1.link")) {
1169: assertTrue(element instanceof MenuOption);
1170: assertEquals("http://link1", ((MenuOption) element)
1171: .getUrl());
1172: assertEquals(MenuOption.LINK_OPTION_TYPE,
1173: ((MenuOption) element).getType());
1174: } else if (element.getElementType().equals(
1175: MenuElement.OPTION_ELEMENT_TYPE)
1176: && element.getTitle().equals("/page2.psml")) {
1177: assertTrue(element instanceof MenuOption);
1178: assertEquals("/page2.psml", ((MenuOption) element)
1179: .getUrl());
1180: assertEquals(MenuOption.PAGE_OPTION_TYPE,
1181: ((MenuOption) element).getType());
1182: } else if (element.getElementType().equals(
1183: MenuElement.OPTION_ELEMENT_TYPE)
1184: && element.getTitle().equals("/page1.psml")) {
1185: assertTrue(element instanceof MenuOption);
1186: assertEquals("/page1.psml", ((MenuOption) element)
1187: .getUrl());
1188: assertEquals(MenuOption.PAGE_OPTION_TYPE,
1189: ((MenuOption) element).getType());
1190: } else if (element.getElementType().equals(
1191: MenuElement.OPTION_ELEMENT_TYPE)
1192: && element.getTitle().equals("/folder1/page1.psml")) {
1193: assertTrue(element instanceof MenuOption);
1194: assertEquals("/folder1/page1.psml",
1195: ((MenuOption) element).getUrl());
1196: assertEquals(MenuOption.PAGE_OPTION_TYPE,
1197: ((MenuOption) element).getType());
1198: } else {
1199: fail("Unexpected menu element type/title: "
1200: + element.getElementType() + "/"
1201: + element.getTitle());
1202: }
1203: }
1204: if (menuElementsIter.hasNext()) {
1205: MenuElement element = (MenuElement) menuElementsIter.next();
1206: if (element.getElementType().equals(
1207: MenuElement.SEPARATOR_ELEMENT_TYPE)
1208: && (element instanceof MenuSeparator)
1209: && ((MenuSeparator) element).getText().equals(
1210: "=== Standard Menus ===")) {
1211: } else {
1212: fail("Unexpected menu element type/title: "
1213: + element.getElementType() + "/"
1214: + element.getTitle());
1215: }
1216: }
1217: if (menuElementsIter.hasNext()) {
1218: MenuElement element = (MenuElement) menuElementsIter.next();
1219: if (element.getElementType().equals(
1220: MenuElement.OPTION_ELEMENT_TYPE)
1221: && element.getTitle().equals("user root")) {
1222: assertTrue(element instanceof MenuOption);
1223: assertEquals("/", ((MenuOption) element).getUrl());
1224: assertEquals(MenuOption.FOLDER_OPTION_TYPE,
1225: ((MenuOption) element).getType());
1226: } else {
1227: fail("Unexpected menu element type/title: "
1228: + element.getElementType() + "/"
1229: + element.getTitle());
1230: }
1231: }
1232: if (menuElementsIter.hasNext()) {
1233: MenuElement element = (MenuElement) menuElementsIter.next();
1234: if (element.getElementType().equals(
1235: MenuElement.MENU_ELEMENT_TYPE)
1236: && element.getTitle().equals("navigations")) {
1237: assertTrue(element instanceof Menu);
1238: assertEquals("navigations", ((Menu) element).getName());
1239: } else {
1240: fail("Unexpected menu element type/title: "
1241: + element.getElementType() + "/"
1242: + element.getTitle());
1243: }
1244: }
1245: if (menuElementsIter.hasNext()) {
1246: MenuElement element = (MenuElement) menuElementsIter.next();
1247: if (element.getElementType().equals(
1248: MenuElement.MENU_ELEMENT_TYPE)
1249: && element.getTitle().equals("pages")) {
1250: assertTrue(element instanceof Menu);
1251: assertEquals("pages", ((Menu) element).getName());
1252: } else {
1253: fail("Unexpected menu element type/title: "
1254: + element.getElementType() + "/"
1255: + element.getTitle());
1256: }
1257: }
1258: }
1259:
1260: /**
1261: * testPortalSiteHiddenPageMenus - Test PortalSite menu generation for hidden pages
1262: *
1263: * @throws Exception
1264: */
1265: public void testPotalSiteHiddenPageMenus() throws Exception {
1266: assertNotNull(portalSite);
1267: PortalSiteSessionContext sessionContext = portalSite
1268: .newSessionContext();
1269: assertNotNull(sessionContext);
1270:
1271: // first request at /: hidden page suppressed
1272: JetspeedProfileLocator locator = new JetspeedProfileLocator();
1273: locator.init(null, "/");
1274: locator.add("user", true, false, "user");
1275: Map locators = new HashMap();
1276: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
1277: PortalSiteRequestContext requestContext = sessionContext
1278: .newRequestContext(locators);
1279: assertNotNull(requestContext);
1280: Menu topMenu = requestContext.getMenu("top");
1281: assertNotNull(topMenu);
1282: assertFalse(topMenu.isEmpty());
1283: List topMenuElements = topMenu.getElements();
1284: assertNotNull(topMenuElements);
1285: Iterator menuElementsIter = topMenuElements.iterator();
1286: boolean hiddenElement = false;
1287: while (menuElementsIter.hasNext()) {
1288: MenuElement element = (MenuElement) menuElementsIter.next();
1289: if (element.getElementType().equals(
1290: MenuElement.OPTION_ELEMENT_TYPE)
1291: && element.getTitle().equals("/hidden.psml")) {
1292: hiddenElement = true;
1293: }
1294: }
1295: assertFalse(hiddenElement);
1296: Menu pagesMenu = requestContext.getMenu("pages");
1297: assertNotNull(pagesMenu);
1298: assertFalse(pagesMenu.isEmpty());
1299: List pagesElements = pagesMenu.getElements();
1300: assertNotNull(pagesElements);
1301: menuElementsIter = pagesElements.iterator();
1302: hiddenElement = false;
1303: while (menuElementsIter.hasNext()) {
1304: MenuElement element = (MenuElement) menuElementsIter.next();
1305: if (element.getElementType().equals(
1306: MenuElement.OPTION_ELEMENT_TYPE)
1307: && element.getTitle().equals("/hidden.psml")) {
1308: hiddenElement = true;
1309: }
1310: }
1311: assertFalse(hiddenElement);
1312:
1313: // second request at /hidden.psml: hidden page visible
1314: locator = new JetspeedProfileLocator();
1315: locator.init(null, "/hidden.psml");
1316: locator.add("user", true, false, "user");
1317: locators = new HashMap();
1318: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
1319: requestContext = sessionContext.newRequestContext(locators);
1320: assertNotNull(requestContext);
1321: topMenu = requestContext.getMenu("top");
1322: assertNotNull(topMenu);
1323: assertFalse(topMenu.isEmpty());
1324: topMenuElements = topMenu.getElements();
1325: assertNotNull(topMenuElements);
1326: menuElementsIter = topMenuElements.iterator();
1327: hiddenElement = false;
1328: while (menuElementsIter.hasNext()) {
1329: MenuElement element = (MenuElement) menuElementsIter.next();
1330: if (element.getElementType().equals(
1331: MenuElement.OPTION_ELEMENT_TYPE)
1332: && element.getTitle().equals("/hidden.psml")) {
1333: hiddenElement = true;
1334: }
1335: }
1336: assertTrue(hiddenElement);
1337: pagesMenu = requestContext.getMenu("pages");
1338: assertNotNull(pagesMenu);
1339: assertFalse(pagesMenu.isEmpty());
1340: pagesElements = pagesMenu.getElements();
1341: assertNotNull(pagesElements);
1342: menuElementsIter = pagesElements.iterator();
1343: hiddenElement = false;
1344: while (menuElementsIter.hasNext()) {
1345: MenuElement element = (MenuElement) menuElementsIter.next();
1346: if (element.getElementType().equals(
1347: MenuElement.OPTION_ELEMENT_TYPE)
1348: && element.getTitle().equals("/hidden.psml")) {
1349: hiddenElement = true;
1350: }
1351: }
1352: assertTrue(hiddenElement);
1353:
1354: // third request at /: hidden page suppressed
1355: locator = new JetspeedProfileLocator();
1356: locator.init(null, "/");
1357: locator.add("user", true, false, "user");
1358: locators = new HashMap();
1359: locators.put(ProfileLocator.PAGE_LOCATOR, locator);
1360: requestContext = sessionContext.newRequestContext(locators);
1361: assertNotNull(requestContext);
1362: topMenu = requestContext.getMenu("top");
1363: assertNotNull(topMenu);
1364: assertFalse(topMenu.isEmpty());
1365: topMenuElements = topMenu.getElements();
1366: assertNotNull(topMenuElements);
1367: menuElementsIter = topMenuElements.iterator();
1368: hiddenElement = false;
1369: while (menuElementsIter.hasNext()) {
1370: MenuElement element = (MenuElement) menuElementsIter.next();
1371: if (element.getElementType().equals(
1372: MenuElement.OPTION_ELEMENT_TYPE)
1373: && element.getTitle().equals("/hidden.psml")) {
1374: hiddenElement = true;
1375: }
1376: }
1377: assertFalse(hiddenElement);
1378: pagesMenu = requestContext.getMenu("pages");
1379: assertNotNull(pagesMenu);
1380: assertFalse(pagesMenu.isEmpty());
1381: pagesElements = pagesMenu.getElements();
1382: assertNotNull(pagesElements);
1383: menuElementsIter = pagesElements.iterator();
1384: hiddenElement = false;
1385: while (menuElementsIter.hasNext()) {
1386: MenuElement element = (MenuElement) menuElementsIter.next();
1387: if (element.getElementType().equals(
1388: MenuElement.OPTION_ELEMENT_TYPE)
1389: && element.getTitle().equals("/hidden.psml")) {
1390: hiddenElement = true;
1391: }
1392: }
1393: assertFalse(hiddenElement);
1394: }
1395:
1396: /**
1397: * extractFileSystemPathFromId - utility to convert proxy ids to file system paths
1398: *
1399: * @param id proxy node id
1400: * @return files system path
1401: */
1402: private String extractFileSystemPathFromId(String id) {
1403: if ((id != null) && !id.equals(Folder.PATH_SEPARATOR)
1404: && id.endsWith(Folder.PATH_SEPARATOR)) {
1405: return id.substring(0, id.length() - 1);
1406: }
1407: return id;
1408: }
1409:
1410: /**
1411: * extractLocatorNameFromProxy - utility to access profile locator name from proxy
1412: *
1413: * @param proxy site view node proxy
1414: * @return locator name
1415: */
1416: private String extractLocatorNameFromProxy(Object proxy)
1417: throws Exception {
1418: return ((NodeProxy) Proxy.getInvocationHandler(proxy))
1419: .getLocatorName();
1420: }
1421: }
|