Search in sources :

Example 6 with ModuleMenu

use of org.motechproject.server.web.dto.ModuleMenu in project motech by motech.

the class MenuBuilderTest method shouldBuildMenuWithAllLinks.

@Test
public void shouldBuildMenuWithAllLinks() {
    setUpRest();
    when(userService.getRoles(USERNAME)).thenReturn(Arrays.asList("emailRole", "adminRole", "schedulerRole", "mcRole", "mdsRole", "viewRestRole"));
    when(dictionary.get(DOC_URL)).thenReturn("http://grameenfoundation.org/");
    ModuleMenu menu = menuBuilder.buildMenu(USERNAME);
    assertNotNull(menu);
    List<ModuleMenuSection> menuSections = menu.getSections();
    assertNotNull(menuSections);
    assertEquals(4, menuSections.size());
    ModuleMenuSection adminSection = menu.getSections().get(0);
    verifyAdminSection(adminSection);
    ModuleMenuSection wsSection = menu.getSections().get(1);
    verifyWsSection(wsSection);
    ModuleMenuSection modulesSection = menu.getSections().get(2);
    verifyModulesSection(modulesSection, true, true);
    ModuleMenuSection restSection = menu.getSections().get(3);
    verifyRestSection(restSection, true, true);
}
Also used : ModuleMenuSection(org.motechproject.server.web.dto.ModuleMenuSection) ModuleMenu(org.motechproject.server.web.dto.ModuleMenu) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with ModuleMenu

use of org.motechproject.server.web.dto.ModuleMenu in project motech by motech.

the class MenuBuilderTest method shouldNotAddLinksForSubMenusForWhichUserDoesNotHaveRequisiteRole.

@Test
public void shouldNotAddLinksForSubMenusForWhichUserDoesNotHaveRequisiteRole() {
    setUpToTestAccessControlledSubMenuLinks(true);
    when(userService.getRoles(USERNAME)).thenReturn(Arrays.asList("fooRole"));
    when(bundle.getHeaders().get(DOC_URL)).thenReturn("http://grameenfoundation.org/");
    ModuleMenu menu = menuBuilder.buildMenu(USERNAME);
    assertNotNull(menu);
    List<ModuleMenuSection> menuSections = menu.getSections();
    assertNotNull(menuSections);
    ModuleMenuLink onlyFooHasAccessToLink = new ModuleMenuLink("Foo", "foo", "#/foo", false, null);
    ModuleMenuLink onlyBarHasAccessToLink = new ModuleMenuLink("Bar", "foo", "#/bar", false, null);
    ModuleMenuLink linkIsNotAccessControlled = new ModuleMenuLink("Random", "foo", "#/random", false, null);
    ModuleMenuSection fooMenuSection = menuSections.get(0);
    assertNotNull(fooMenuSection);
    assertTrue(fooMenuSection.hasLinkFor(onlyFooHasAccessToLink.getUrl()));
    assertTrue(fooMenuSection.hasLinkFor(linkIsNotAccessControlled.getUrl()));
    assertFalse(fooMenuSection.hasLinkFor(onlyBarHasAccessToLink.getUrl()));
}
Also used : ModuleMenuLink(org.motechproject.server.web.dto.ModuleMenuLink) ModuleMenuSection(org.motechproject.server.web.dto.ModuleMenuSection) ModuleMenu(org.motechproject.server.web.dto.ModuleMenu) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ModuleMenu (org.motechproject.server.web.dto.ModuleMenu)7 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ModuleMenuSection (org.motechproject.server.web.dto.ModuleMenuSection)5 ModuleRegistrationData (org.motechproject.osgi.web.ModuleRegistrationData)1 ModuleMenuLink (org.motechproject.server.web.dto.ModuleMenuLink)1