assertNotNull(portalSite);
PortalSiteSessionContext sessionContext = portalSite.newSessionContext();
assertNotNull(sessionContext);
// first request at /
JetspeedProfileLocator locator = new JetspeedProfileLocator();
locator.init(null, "/");
locator.add("user", true, false, "user");
locator.add("mediatype", true, false, "html");
Map locators = new HashMap();
locators.put(ProfileLocator.PAGE_LOCATOR, locator);
locator = new JetspeedProfileLocator();
locator.init(null, "/");
locator.add("role", true, false, "role0");
locators.put("role", locator);
locator = new JetspeedProfileLocator();
locator.init(null, "/");
locator.add("group", true, false, "group");
locators.put("group", locator);
PortalSiteRequestContext requestContext = sessionContext.newRequestContext(locators, "user");
assertNotNull(requestContext);
Set customMenuNames = requestContext.getCustomMenuNames();
assertNotNull(customMenuNames);
assertEquals(7, customMenuNames.size());
assertTrue(customMenuNames.contains("top"));
assertTrue(customMenuNames.contains("bread-crumbs"));
assertTrue(customMenuNames.contains("template-test"));
assertTrue(customMenuNames.contains("current-page-test"));
assertTrue(customMenuNames.contains("current-path-test"));
assertTrue(customMenuNames.contains("site-navigations"));
assertTrue(customMenuNames.contains("rooted-navigations"));
Menu topMenu = requestContext.getMenu("top");
assertNotNull(topMenu);
assertEquals(MenuElement.MENU_ELEMENT_TYPE, topMenu.getElementType());
assertNull(topMenu.getParentMenu());
assertEquals("user root", topMenu.getTitle());
assertEquals("user", topMenu.getShortTitle());
assertEquals("dhtml-pull-down", topMenu.getSkin());
assertEquals("top", topMenu.getName());
assertEquals("/", topMenu.getUrl());
assertFalse(topMenu.isEmpty());
List topMenuElements = topMenu.getElements();
assertNotNull(topMenuElements);
assertEquals(8, topMenuElements.size());
Iterator menuElementsIter = topMenuElements.iterator();
while (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("folder0"))
{
assertTrue(element instanceof Menu);
assertEquals("/folder0", ((Menu)element).getUrl());
assertTrue(((Menu)element).getParentMenu() == topMenu);
assertTrue(element.getNode() instanceof Folder);
assertEquals("/folder0", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Folder);
assertEquals("/folder0", element.getManagedNode().getPath());
assertFalse(((Menu)element).isEmpty());
List elements = ((Menu)element).getElements();
assertNotNull(elements);
assertEquals(1, elements.size());
assertTrue(elements.get(0) instanceof MenuOption);
assertEquals("/folder0/page0.psml", ((MenuOption)elements.get(0)).getUrl());
assertEquals("dhtml-pull-down", element.getSkin());
}
else if (element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("group folder1"))
{
assertTrue(element instanceof Menu);
assertEquals("/folder1", ((Menu)element).getUrl());
assertTrue(((Menu)element).getParentMenu() == topMenu);
assertTrue(element.getNode() instanceof Folder);
assertEquals("/folder1", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Folder);
assertEquals("/_user/user/folder1", element.getManagedNode().getPath());
assertFalse(((Menu)element).isEmpty());
List elements = ((Menu)element).getElements();
assertNotNull(elements);
assertEquals(3, elements.size());
assertTrue(elements.get(0) instanceof MenuOption);
assertEquals("folder1/folder", ((MenuOption)elements.get(0)).getTitle());
assertTrue(elements.get(1) instanceof MenuOption);
assertEquals("/folder1/page0.psml", ((MenuOption)elements.get(1)).getTitle());
assertTrue(elements.get(2) instanceof MenuOption);
assertEquals("/folder1/page1.psml", ((MenuOption)elements.get(2)).getTitle());
}
else if (element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("Folder4"))
{
assertTrue(element instanceof Menu);
assertEquals("/folder4", ((Menu)element).getUrl());
assertTrue(((Menu)element).getParentMenu() == topMenu);
assertTrue(element.getNode() instanceof Folder);
assertEquals("/folder4", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Folder);
assertEquals("/folder4", element.getManagedNode().getPath());
assertFalse(((Menu)element).isEmpty());
List elements = ((Menu)element).getElements();
assertNotNull(elements);
assertEquals(1, elements.size());
assertTrue(elements.get(0) instanceof MenuOption);
assertEquals("Folder", ((MenuOption)elements.get(0)).getTitle());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page2.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/page2.psml", ((MenuOption)element).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)element).getType());
assertTrue(element.getNode() instanceof Page);
assertEquals("/page2.psml", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Page);
assertEquals("/_user/user/_mediatype/html/page2.psml", element.getManagedNode().getPath());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page1.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/page1.psml", ((MenuOption)element).getUrl());
assertTrue(element.getNode() instanceof Page);
assertEquals("/page1.psml", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Page);
assertEquals("/page1.psml", element.getManagedNode().getPath());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page0.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/page0.psml", ((MenuOption)element).getUrl());
assertTrue(element.getNode() instanceof Page);
assertEquals("/page0.psml", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Page);
assertEquals("/page0.psml", element.getManagedNode().getPath());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/link1.link"))
{
assertTrue(element instanceof MenuOption);
assertEquals("http://link1", ((MenuOption)element).getUrl());
assertEquals("top", ((MenuOption)element).getTarget());
assertEquals(MenuOption.LINK_OPTION_TYPE, ((MenuOption)element).getType());
assertTrue(element.getNode() instanceof Link);
assertEquals("/link1.link", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Link);
assertEquals("/link1.link", element.getManagedNode().getPath());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/link0.link"))
{
assertTrue(element instanceof MenuOption);
assertEquals("http://link0", ((MenuOption)element).getUrl());
assertNull(((MenuOption)element).getTarget());
assertEquals("dhtml-pull-down", element.getSkin());
assertTrue(element.getNode() instanceof Link);
assertEquals("/link0.link", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Link);
assertEquals("/_group/group/link0.link", element.getManagedNode().getPath());
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
assertTrue(topMenu.isSelected(requestContext));
MenuElement selected = topMenu.getSelectedElement(requestContext);
assertNotNull(selected);
assertEquals(MenuElement.OPTION_ELEMENT_TYPE, selected.getElementType());
assertTrue(selected instanceof MenuOption);
assertEquals("/page2.psml", ((MenuOption)selected).getUrl());
assertEquals("/page2.psml", selected.getTitle());
assertEquals("dhtml-pull-down", selected.getSkin());
assertFalse(((MenuImpl)topMenu).isElementRelative());
Menu breadCrumbsMenu = requestContext.getMenu("bread-crumbs");
assertNotNull(breadCrumbsMenu);
assertEquals("bread-crumbs", breadCrumbsMenu.getName());
assertEquals("/", breadCrumbsMenu.getUrl());
assertFalse(breadCrumbsMenu.isEmpty());
List breadCrumbsElements = breadCrumbsMenu.getElements();
assertNotNull(breadCrumbsElements);
assertEquals(1, breadCrumbsElements.size());
assertTrue(breadCrumbsElements.get(0) instanceof MenuOption);
assertEquals("/", ((MenuOption)breadCrumbsElements.get(0)).getUrl());
assertEquals(MenuOption.FOLDER_OPTION_TYPE, ((MenuOption)breadCrumbsElements.get(0)).getType());
assertTrue(((MenuImpl)breadCrumbsMenu).isElementRelative());
Menu templateTestMenu = requestContext.getMenu("template-test");
assertNotNull(templateTestMenu);
assertEquals("template-test", templateTestMenu.getName());
assertFalse(templateTestMenu.isEmpty());
List templateTestElements = templateTestMenu.getElements();
assertNotNull(templateTestElements);
assertEquals(1, templateTestElements.size());
assertTrue(templateTestElements.get(0) instanceof MenuOption);
assertEquals("/page1.psml", ((MenuOption)templateTestElements.get(0)).getUrl());
Menu currentPageTestMenu = requestContext.getMenu("current-page-test");
assertEquals("current-page-test", currentPageTestMenu.getName());
assertFalse(currentPageTestMenu.isEmpty());
List currentPageTestElements = currentPageTestMenu.getElements();
assertNotNull(currentPageTestElements);
assertEquals(1, currentPageTestElements.size());
assertTrue(currentPageTestElements.get(0) instanceof MenuOption);
assertEquals("/page2.psml", ((MenuOption)currentPageTestElements.get(0)).getUrl());
assertTrue(currentPageTestMenu.isSelected(requestContext));
assertTrue(((MenuOption)currentPageTestElements.get(0)).isSelected(requestContext));
Menu currentPathTestMenu = requestContext.getMenu("current-path-test");
assertEquals("current-path-test", currentPathTestMenu.getName());
assertTrue(currentPathTestMenu.isEmpty());
List currentPathTestElements = currentPathTestMenu.getElements();
assertNull(currentPathTestElements);
Menu siteNavigationsMenu = requestContext.getMenu("site-navigations");
assertEquals("site-navigations", siteNavigationsMenu.getName());
assertFalse(siteNavigationsMenu.isEmpty());
List siteNavigationsElements = siteNavigationsMenu.getElements();
assertNotNull(siteNavigationsElements);
assertEquals(6, siteNavigationsElements.size());
menuElementsIter = siteNavigationsElements.iterator();
while (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("folder0"))
{
assertTrue(element instanceof Menu);
assertEquals("/folder0", ((Menu)element).getUrl());
assertTrue(((Menu)element).getParentMenu() == siteNavigationsMenu);
assertTrue(element.getNode() instanceof Folder);
assertEquals("/folder0", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Folder);
assertEquals("/folder0", element.getManagedNode().getPath());
assertFalse(((Menu)element).isEmpty());
List elements = ((Menu)element).getElements();
assertNotNull(elements);
assertEquals(1, elements.size());
assertTrue(elements.get(0) instanceof MenuOption);
assertEquals("/folder0/page0.psml", ((MenuOption)elements.get(0)).getUrl());
}
else if (element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("group folder1"))
{
assertTrue(element instanceof Menu);
assertEquals("/folder1", ((Menu)element).getUrl());
assertTrue(((Menu)element).getParentMenu() == siteNavigationsMenu);
assertTrue(element.getNode() instanceof Folder);
assertEquals("/folder1", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Folder);
assertEquals("/_user/user/folder1", element.getManagedNode().getPath());
assertFalse(((Menu)element).isEmpty());
List elements = ((Menu)element).getElements();
assertNotNull(elements);
assertEquals(3, elements.size());
assertTrue(elements.get(0) instanceof Menu);
assertEquals("folder1/folder", ((Menu)elements.get(0)).getTitle());
assertTrue(elements.get(1) instanceof MenuOption);
assertEquals("/folder1/page0.psml", ((MenuOption)elements.get(1)).getTitle());
assertTrue(elements.get(2) instanceof MenuOption);
assertEquals("/folder1/page1.psml", ((MenuOption)elements.get(2)).getTitle());
}
else if (element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("Folder4"))
{
assertTrue(element instanceof Menu);
assertEquals("/folder4", ((Menu)element).getUrl());
assertTrue(((Menu)element).getParentMenu() == siteNavigationsMenu);
assertTrue(element.getNode() instanceof Folder);
assertEquals("/folder4", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Folder);
assertEquals("/folder4", element.getManagedNode().getPath());
Menu menuElement = (Menu)element;
assertFalse(menuElement.isEmpty());
List elements = menuElement.getElements();
assertNotNull(elements);
assertEquals(1, elements.size());
assertTrue(elements.get(0) instanceof Menu);
Menu subFolderMenuElement = (Menu)elements.get(0);
assertEquals("Folder", subFolderMenuElement.getTitle());
elements = subFolderMenuElement.getElements();
assertNotNull(elements);
assertEquals(1, elements.size());
assertTrue(elements.get(0) instanceof MenuOption);
MenuOption subFolderMenuOptionElement = (MenuOption)elements.get(0);
assertEquals("/folder4/folder/page0.psml", subFolderMenuOptionElement.getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, subFolderMenuOptionElement.getType());
assertTrue(subFolderMenuOptionElement.getNode() instanceof Page);
assertEquals("/folder4/folder/page0.psml", subFolderMenuOptionElement.getNode().getPath());
assertTrue(subFolderMenuOptionElement.getManagedNode() instanceof Page);
assertEquals("/folder4/folder/page0.psml", subFolderMenuOptionElement.getManagedNode().getPath());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page2.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/page2.psml", ((MenuOption)element).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)element).getType());
assertTrue(element.getNode() instanceof Page);
assertEquals("/page2.psml", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Page);
assertEquals("/_user/user/_mediatype/html/page2.psml", element.getManagedNode().getPath());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page1.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/page1.psml", ((MenuOption)element).getUrl());
assertTrue(element.getNode() instanceof Page);
assertEquals("/page1.psml", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Page);
assertEquals("/page1.psml", element.getManagedNode().getPath());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page0.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/page0.psml", ((MenuOption)element).getUrl());
assertTrue(element.getNode() instanceof Page);
assertEquals("/page0.psml", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Page);
assertEquals("/page0.psml", element.getManagedNode().getPath());
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
Menu rootedMenu = requestContext.getMenu("rooted-navigations");
assertNotNull(rootedMenu);
assertFalse(rootedMenu.isEmpty());
List rootedElements = rootedMenu.getElements();
assertNotNull(rootedElements);
assertEquals(8, rootedElements.size());
menuElementsIter = rootedElements.iterator();
while (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if ((element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("folder0")) ||
(element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("group folder1")) ||
(element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("Folder4")) ||
(element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page2.psml")) ||
(element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page1.psml")) ||
(element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page0.psml")) ||
(element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/link0.link")) ||
(element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/link1.link")))
{
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
// second request at /folder0
locator = new JetspeedProfileLocator();
locator.init(null, "/folder0");
locator.add("user", true, false, "user");
locator.add("mediatype", true, false, "html");
locators = new HashMap();
locators.put(ProfileLocator.PAGE_LOCATOR, locator);
locator = new JetspeedProfileLocator();
locator.init(null, "/folder0");
locator.add("role", true, false, "role0");
locators.put("role", locator);
locator = new JetspeedProfileLocator();
locator.init(null, "/folder0");
locator.add("group", true, false, "group");
locators.put("group", locator);
requestContext = sessionContext.newRequestContext(locators, "user");
assertNotNull(requestContext);
Menu topMenu2 = requestContext.getMenu("top");
assertNotNull(topMenu2);
assertTrue(topMenu == topMenu2);
Menu breadCrumbsMenu2 = requestContext.getMenu("bread-crumbs");
assertNotNull(breadCrumbsMenu2);
assertTrue(breadCrumbsMenu != breadCrumbsMenu2);
assertEquals("bread-crumbs", breadCrumbsMenu2.getName());
assertEquals("/folder0", breadCrumbsMenu2.getUrl());
assertFalse(breadCrumbsMenu2.isEmpty());
breadCrumbsElements = breadCrumbsMenu2.getElements();
assertNotNull(breadCrumbsElements);
assertEquals(2, breadCrumbsElements.size());
assertTrue(breadCrumbsElements.get(0) instanceof MenuOption);
assertEquals("/", ((MenuOption)breadCrumbsElements.get(0)).getUrl());
assertEquals(MenuOption.FOLDER_OPTION_TYPE, ((MenuOption)breadCrumbsElements.get(0)).getType());
assertEquals("/folder0", ((MenuOption)breadCrumbsElements.get(1)).getUrl());
assertEquals(MenuOption.FOLDER_OPTION_TYPE, ((MenuOption)breadCrumbsElements.get(1)).getType());
assertTrue(((MenuImpl)breadCrumbsMenu2).isElementRelative());
Menu hiddenMenu = requestContext.getMenu("override-hidden");
assertNotNull(hiddenMenu);
assertTrue(hiddenMenu.isEmpty());
Menu navigationsMenu = requestContext.getMenu("navigations");
assertNotNull(navigationsMenu);
assertTrue(navigationsMenu.isEmpty());
currentPageTestMenu = requestContext.getMenu("current-page-test");
assertEquals("current-page-test", currentPageTestMenu.getName());
assertFalse(currentPageTestMenu.isEmpty());
currentPageTestElements = currentPageTestMenu.getElements();
assertNotNull(currentPageTestElements);
assertEquals(1, currentPageTestElements.size());
assertTrue(currentPageTestElements.get(0) instanceof MenuOption);
assertEquals("/folder0/page0.psml", ((MenuOption)currentPageTestElements.get(0)).getUrl());
assertTrue(currentPageTestMenu.isSelected(requestContext));
assertTrue(((MenuOption)currentPageTestElements.get(0)).isSelected(requestContext));
currentPathTestMenu = requestContext.getMenu("current-path-test");
assertEquals("current-path-test", currentPathTestMenu.getName());
assertFalse(currentPathTestMenu.isEmpty());
currentPathTestElements = currentPathTestMenu.getElements();
assertNotNull(currentPathTestElements);
assertEquals(1, currentPathTestElements.size());
assertTrue(currentPathTestElements.get(0) instanceof MenuOption);
assertEquals("/folder0/page0.psml", ((MenuOption)currentPathTestElements.get(0)).getUrl());
assertTrue(currentPathTestMenu.isSelected(requestContext));
assertTrue(((MenuOption)currentPathTestElements.get(0)).isSelected(requestContext));
siteNavigationsMenu = requestContext.getMenu("site-navigations");
assertEquals("site-navigations", siteNavigationsMenu.getName());
// third request at /page1.psml
locator = new JetspeedProfileLocator();
locator.init(null, "/page1.psml");
locator.add("user", true, false, "user");
locator.add("mediatype", true, false, "html");
locators = new HashMap();
locators.put(ProfileLocator.PAGE_LOCATOR, locator);
locator = new JetspeedProfileLocator();
locator.init(null, "/page1.psml");
locator.add("role", true, false, "role0");
locators.put("role", locator);
locator = new JetspeedProfileLocator();
locator.init(null, "/page1.psml");
locator.add("group", true, false, "group");
locators.put("group", locator);
requestContext = sessionContext.newRequestContext(locators, "user");
assertNotNull(requestContext);
assertNull(requestContext.getMenu("no-such-menu"));
Menu topMenu3 = requestContext.getMenu("top");
assertNotNull(topMenu3);
assertTrue(topMenu == topMenu3);
Menu backMenu = requestContext.getMenu("back");
assertNotNull(backMenu);
assertTrue(backMenu.isEmpty());
assertNull(backMenu.getElements());
assertTrue(((MenuImpl)backMenu).isElementRelative());
assertEquals("back", backMenu.getName());
assertEquals("Back to", backMenu.getTitle());
assertEquals("Back to", backMenu.getShortTitle());
assertEquals("\u00bb", backMenu.getTitle(Locale.JAPANESE));
assertEquals("\u00bb", backMenu.getShortTitle(Locale.JAPANESE));
assertEquals("Back to", backMenu.getTitle(new Locale("xx")));
assertEquals("Back to", backMenu.getShortTitle(new Locale("xx")));
Menu breadcrumbsMenu = requestContext.getMenu("breadcrumbs");
assertNotNull(breadcrumbsMenu);
assertFalse(breadcrumbsMenu.isEmpty());
assertEquals("You are here:", breadcrumbsMenu.getTitle());
assertEquals("\u73fe\u5728\u30d1\u30b9\uff1a", breadcrumbsMenu.getTitle(Locale.JAPANESE));
navigationsMenu = requestContext.getMenu("navigations");
assertNotNull(navigationsMenu);
assertFalse(navigationsMenu.isEmpty());
List navigationsElements = navigationsMenu.getElements();
assertNotNull(navigationsElements);
assertEquals(7, navigationsElements.size());
menuElementsIter = navigationsElements.iterator();
while (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.SEPARATOR_ELEMENT_TYPE) &&
(element instanceof MenuSeparator) &&
((MenuSeparator)element).getText().equals("Folders"))
{
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("folder0"))
{
assertTrue(element instanceof MenuOption);
assertEquals(MenuOption.FOLDER_OPTION_TYPE, ((MenuOption)element).getType());
assertTrue(element.getNode() instanceof Folder);
assertEquals("/folder0", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Folder);
assertEquals("/folder0", element.getManagedNode().getPath());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("group folder1"))
{
assertTrue(element instanceof MenuOption);
assertEquals(MenuOption.FOLDER_OPTION_TYPE, ((MenuOption)element).getType());
assertTrue(element.getNode() instanceof Folder);
assertEquals("/folder1", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Folder);
assertEquals("/_user/user/folder1", element.getManagedNode().getPath());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("Folder4"))
{
assertTrue(element instanceof MenuOption);
assertEquals(MenuOption.FOLDER_OPTION_TYPE, ((MenuOption)element).getType());
assertTrue(element.getNode() instanceof Folder);
assertEquals("/folder4", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Folder);
assertEquals("/folder4", element.getManagedNode().getPath());
}
else if (element.getElementType().equals(MenuElement.SEPARATOR_ELEMENT_TYPE) &&
(element instanceof MenuSeparator) &&
((MenuSeparator)element).getText().equals("Additional Links"))
{
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/link1.link"))
{
assertTrue(element instanceof MenuOption);
assertEquals(MenuOption.LINK_OPTION_TYPE, ((MenuOption)element).getType());
assertTrue(element.getNode() instanceof Link);
assertEquals("/link1.link", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Link);
assertEquals("/link1.link", element.getManagedNode().getPath());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/link0.link"))
{
assertTrue(element instanceof MenuOption);
assertEquals(MenuOption.LINK_OPTION_TYPE, ((MenuOption)element).getType());
assertEquals("left-navigations", element.getSkin());
assertTrue(element.getNode() instanceof Link);
assertEquals("/link0.link", element.getNode().getPath());
assertTrue(element.getManagedNode() instanceof Link);
assertEquals("/_group/group/link0.link", element.getManagedNode().getPath());
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
assertEquals("left-navigations", navigationsMenu.getSkin());
assertTrue(((MenuImpl)navigationsMenu).isElementRelative());
Menu pagesMenu = requestContext.getMenu("pages");
assertNotNull(pagesMenu);
assertFalse(pagesMenu.isEmpty());
List pagesElements = pagesMenu.getElements();
assertNotNull(pagesElements);
assertEquals(3, pagesElements.size());
menuElementsIter = pagesElements.iterator();
while (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page2.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/page2.psml", ((MenuOption)element).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)element).getType());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page1.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/page1.psml", ((MenuOption)element).getUrl());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page0.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/page0.psml", ((MenuOption)element).getUrl());
assertEquals("tabs", element.getSkin());
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
assertEquals("tabs", pagesMenu.getSkin());
assertTrue(((MenuImpl)pagesMenu).isElementRelative());
// fourth request at /page0.psml
locator = new JetspeedProfileLocator();
locator.init(null, "/page0.psml");
locator.add("user", true, false, "user");
locator.add("mediatype", true, false, "html");
locators = new HashMap();
locators.put(ProfileLocator.PAGE_LOCATOR, locator);
locator = new JetspeedProfileLocator();
locator.init(null, "/page0.psml");
locator.add("role", true, false, "role0");
locators.put("role", locator);
locator = new JetspeedProfileLocator();
locator.init(null, "/page0.psml");
locator.add("group", true, false, "group");
locators.put("group", locator);
requestContext = sessionContext.newRequestContext(locators, "user");
assertNotNull(requestContext);
Menu templateTestMenu2 = requestContext.getMenu("template-test");
assertNotNull(templateTestMenu2);
assertEquals("template-test", templateTestMenu2.getName());
assertFalse(templateTestMenu2.isEmpty());
List templateTestElements2 = templateTestMenu2.getElements();
assertNotNull(templateTestElements2);
assertEquals(1, templateTestElements2.size());
assertTrue(templateTestElements2.get(0) instanceof MenuOption);
assertEquals("/page2.psml", ((MenuOption)templateTestElements2.get(0)).getUrl());
// new request at /folder1
locator = new JetspeedProfileLocator();
locator.init(null, "/folder1");
locator.add("user", true, false, "user");
locator.add("mediatype", true, false, "html");
locators = new HashMap();
locators.put(ProfileLocator.PAGE_LOCATOR, locator);
locator = new JetspeedProfileLocator();
locator.init(null, "/folder1");
locator.add("group", true, false, "group");
locators.put("group", locator);
requestContext = sessionContext.newRequestContext(locators, "user");
assertNotNull(requestContext);
Menu backMenu2 = requestContext.getMenu("back");
assertNotNull(backMenu2);
assertFalse(backMenu2.isEmpty());
Menu topMenu4 = requestContext.getMenu("top");
assertNotNull(topMenu4);
assertTrue(topMenu != topMenu4);
Menu customMenu = requestContext.getMenu("custom");
assertNotNull(customMenu);
assertFalse(customMenu.isEmpty());
List customElements = customMenu.getElements();
assertNotNull(customElements);
assertEquals(12, customElements.size());
assertEquals("custom", customMenu.getName());
assertEquals("Top Menu", customMenu.getTitle());
assertEquals("Haut", customMenu.getTitle(Locale.FRENCH));
menuElementsIter = customElements.iterator();
for (int i = 0; ((i < 2) && menuElementsIter.hasNext()); i++)
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/link0.link"))
{
assertTrue(element instanceof MenuOption);
assertEquals("http://link0", ((MenuOption)element).getUrl());
assertEquals(MenuOption.LINK_OPTION_TYPE, ((MenuOption)element).getType());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/folder1/page1.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/folder1/page1.psml", ((MenuOption)element).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)element).getType());
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
if (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("user root"))
{
assertFalse(((Menu)element).isEmpty());
List nestedElements = ((Menu)element).getElements();
assertEquals(6, nestedElements.size());
Iterator nestedElementsIter = nestedElements.iterator();
if (nestedElementsIter.hasNext())
{
MenuElement nestedElement = (MenuElement)nestedElementsIter.next();
if (nestedElement.getElementType().equals(MenuElement.SEPARATOR_ELEMENT_TYPE) &&
(nestedElement instanceof MenuSeparator) &&
((MenuSeparator)nestedElement).getText().equals("=== Current Page ==="))
{
}
else
{
fail("Unexpected nested menu element type/title: "+nestedElement.getElementType()+"/"+nestedElement.getTitle());
}
}
if (nestedElementsIter.hasNext())
{
MenuElement nestedElement = (MenuElement)nestedElementsIter.next();
if (nestedElement.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) &&
nestedElement.getTitle().equals("/folder1/page1.psml"))
{
assertTrue(nestedElement instanceof MenuOption);
assertEquals("/folder1/page1.psml", ((MenuOption)nestedElement).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)nestedElement).getType());
}
else
{
fail("Unexpected nested menu element type/title: "+nestedElement.getElementType()+"/"+nestedElement.getTitle());
}
}
if (nestedElementsIter.hasNext())
{
MenuElement nestedElement = (MenuElement)nestedElementsIter.next();
if (nestedElement.getElementType().equals(MenuElement.SEPARATOR_ELEMENT_TYPE) &&
(nestedElement instanceof MenuSeparator) &&
((MenuSeparator)nestedElement).getText().equals("=== Top Pages ==="))
{
assertEquals("Top Pages", nestedElement.getTitle());
}
else
{
fail("Unexpected nested menu element type/title: "+nestedElement.getElementType()+"/"+nestedElement.getTitle());
}
}
for (int i = 0; ((i < 3) && nestedElementsIter.hasNext()); i++)
{
MenuElement nestedElement = (MenuElement)nestedElementsIter.next();
if (nestedElement.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) &&
nestedElement.getTitle().equals("/page2.psml"))
{
assertTrue(nestedElement instanceof MenuOption);
assertEquals("/page2.psml", ((MenuOption)nestedElement).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)nestedElement).getType());
}
else if (nestedElement.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) &&
nestedElement.getTitle().equals("/page1.psml"))
{
assertTrue(nestedElement instanceof MenuOption);
assertEquals("/page1.psml", ((MenuOption)nestedElement).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)nestedElement).getType());
}
else if (nestedElement.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) &&
nestedElement.getTitle().equals("/page0.psml"))
{
assertTrue(nestedElement instanceof MenuOption);
assertEquals("/page0.psml", ((MenuOption)nestedElement).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)nestedElement).getType());
}
else
{
fail("Unexpected nested menu element type/title: "+nestedElement.getElementType()+"/"+nestedElement.getTitle());
}
}
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
if (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.SEPARATOR_ELEMENT_TYPE) &&
(element instanceof MenuSeparator) &&
((MenuSeparator)element).getText().equals("=== More Options ==="))
{
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
for (int i = 0; ((i < 4) && menuElementsIter.hasNext()); i++)
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/link1.link"))
{
assertTrue(element instanceof MenuOption);
assertEquals("http://link1", ((MenuOption)element).getUrl());
assertEquals(MenuOption.LINK_OPTION_TYPE, ((MenuOption)element).getType());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page2.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/page2.psml", ((MenuOption)element).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)element).getType());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/page1.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/page1.psml", ((MenuOption)element).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)element).getType());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/folder1/page1.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/folder1/page1.psml", ((MenuOption)element).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)element).getType());
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
if (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.SEPARATOR_ELEMENT_TYPE) &&
(element instanceof MenuSeparator) &&
((MenuSeparator)element).getText().equals("=== Standard Menus ==="))
{
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
if (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("user root"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/", ((MenuOption)element).getUrl());
assertEquals(MenuOption.FOLDER_OPTION_TYPE, ((MenuOption)element).getType());
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
if (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("navigations"))
{
assertTrue(element instanceof Menu);
assertEquals("navigations", ((Menu)element).getName());
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
if (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("pages"))
{
assertTrue(element instanceof Menu);
assertEquals("pages", ((Menu)element).getName());
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
rootedMenu = requestContext.getMenu("rooted-navigations");
assertNotNull(rootedMenu);
assertFalse(rootedMenu.isEmpty());
rootedElements = rootedMenu.getElements();
assertNotNull(rootedElements);
assertEquals(3, rootedElements.size());
menuElementsIter = rootedElements.iterator();
while (menuElementsIter.hasNext())
{
MenuElement element = (MenuElement)menuElementsIter.next();
if (element.getElementType().equals(MenuElement.MENU_ELEMENT_TYPE) && element.getTitle().equals("folder1/folder"))
{
assertTrue(element instanceof Menu);
assertEquals("/folder1/folder", ((Menu)element).getUrl());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/folder1/page0.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/folder1/page0.psml", ((MenuOption)element).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)element).getType());
}
else if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE) && element.getTitle().equals("/folder1/page1.psml"))
{
assertTrue(element instanceof MenuOption);
assertEquals("/folder1/page1.psml", ((MenuOption)element).getUrl());
assertEquals(MenuOption.PAGE_OPTION_TYPE, ((MenuOption)element).getType());
}
else
{
fail("Unexpected menu element type/title: "+element.getElementType()+"/"+element.getTitle());
}
}
// new request at /folder1/folder/page0.psml
locator = new JetspeedProfileLocator();
locator.init(null, "/folder1/folder/page0.psml");
locator.add("user", true, false, "user");
locator.add("mediatype", true, false, "html");
locators = new HashMap();
locators.put(ProfileLocator.PAGE_LOCATOR, locator);
locator = new JetspeedProfileLocator();
locator.init(null, "/folder1");
locator.add("group", true, false, "group");
locators.put("group", locator);
requestContext = sessionContext.newRequestContext(locators, "user");
assertNotNull(requestContext);
rootedMenu = requestContext.getMenu("rooted-navigations");
assertNotNull(rootedMenu);