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);
assertNotNull(requestContext);
Set customMenuNames = requestContext.getCustomMenuNames();
assertNotNull(customMenuNames);
assertEquals(2, customMenuNames.size());
assertTrue(customMenuNames.contains("top"));
assertTrue(customMenuNames.contains("bread-crumbs"));
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(7, 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);
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);
assertFalse(((Menu)element).isEmpty());
List elements = ((Menu)element).getElements();
assertNotNull(elements);
assertEquals(2, elements.size());
assertTrue(elements.get(0) instanceof MenuOption);
assertEquals("/folder1/page0.psml", ((MenuOption)elements.get(0)).getTitle());
assertTrue(elements.get(1) instanceof MenuOption);
assertEquals("/folder1/page1.psml", ((MenuOption)elements.get(1)).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());
}
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());
}
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());
}
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());
}
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());
// 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);
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());
// 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);
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(6, 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());
}
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());
}
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());
}
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());
}
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());
// 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);
assertNotNull(requestContext);
Menu backMenu2 = requestContext.getMenu("back");
assertNotNull(backMenu2);