Search in sources :

Example 1 with ModuleRegistrations

use of org.motechproject.osgi.web.util.ModuleRegistrations in project motech by motech.

the class MenuBuilderTest method setUpMenu.

private void setUpMenu() {
    HashMap<String, String> i18n = new HashMap<>();
    List<String> angularModules = new ArrayList<>();
    ModuleRegistrationData adminRegData = new ModuleRegistrationData("admin", "/admin", angularModules, i18n);
    adminRegData.setRoleForAccess("adminPerm");
    adminRegData.addSubMenu("#/log", "Log");
    adminRegData.addSubMenu("#/settings", "Settings");
    adminRegData.addSubMenu("#/manage", "manage.modules");
    adminRegData.setNeedsAttention(true);
    adminRegData.addAngularModule("admin");
    adminRegData.setBundle(bundle);
    ModuleRegistrationData wsRegData = new ModuleRegistrationData("web-security", "/ws", angularModules, i18n);
    wsRegData.addSubMenu("#/roles", "Roles");
    wsRegData.addSubMenu("#/users", "Users");
    wsRegData.addAngularModule("webSecurity");
    wsRegData.setBundle(bundle);
    ModuleRegistrationData emailRegData = new ModuleRegistrationData("email", "/email", angularModules, i18n);
    List<String> rolesForAccess = new ArrayList<>();
    rolesForAccess.add("emailPerm");
    rolesForAccess.add("otherPerm");
    rolesForAccess.add("completlyOtherPerm");
    emailRegData.setRoleForAccess(rolesForAccess);
    emailRegData.addAngularModule("email");
    emailRegData.setDefaultURL("/email/send");
    emailRegData.setBundle(bundle);
    ModuleRegistrationData schedulerRegData = new ModuleRegistrationData("scheduler", "/scheduler", angularModules, i18n);
    schedulerRegData.setRoleForAccess("schedulerPerm");
    schedulerRegData.setDefaultURL("/scheduler");
    schedulerRegData.setBundle(bundle);
    ModuleRegistrationData metricsRegData = new ModuleRegistrationData("metrics", "/metrics", angularModules, i18n);
    metricsRegData.setDefaultURL("/metrics");
    metricsRegData.setBundle(bundle);
    ModuleRegistrationData outboxRegData = new ModuleRegistrationData("outbox", "outbox", null, i18n);
    outboxRegData.setBundle(bundle);
    ModuleRegistrations modules = new ModuleRegistrations();
    modules.setModulesWithoutSubmenu(Arrays.asList(emailRegData, schedulerRegData, metricsRegData));
    modules.setModulesWithSubMenu(Arrays.asList(adminRegData, wsRegData));
    modules.setModulesWithoutUI(Arrays.asList(outboxRegData));
    when(uiFrameworkService.getRegisteredModules()).thenReturn(modules);
}
Also used : ModuleRegistrations(org.motechproject.osgi.web.util.ModuleRegistrations) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModuleRegistrationData(org.motechproject.osgi.web.ModuleRegistrationData)

Example 2 with ModuleRegistrations

use of org.motechproject.osgi.web.util.ModuleRegistrations in project motech by motech.

the class UIFrameworkServiceImplTest method testRegisterUnregisterModule.

@Test
public void testRegisterUnregisterModule() {
    // register
    service.registerModule(moduleRegistration);
    ModuleRegistrations result = service.getRegisteredModules();
    assertTrue(result.getModulesWithSubMenu().isEmpty());
    assertTrue(result.getModulesWithoutSubmenu().contains(moduleRegistration));
    // unregister
    service.unregisterModule(moduleRegistration.getModuleName());
    result = service.getRegisteredModules();
    assertTrue(result.getModulesWithSubMenu().isEmpty());
    assertTrue(result.getModulesWithSubMenu().isEmpty());
}
Also used : ModuleRegistrations(org.motechproject.osgi.web.util.ModuleRegistrations) Test(org.junit.Test)

Example 3 with ModuleRegistrations

use of org.motechproject.osgi.web.util.ModuleRegistrations in project motech by motech.

the class MenuBuilderTest method setUpToTestAccessControlledSubMenuLinks.

private void setUpToTestAccessControlledSubMenuLinks(boolean addSubMenuWithoutAccessControl) {
    ModuleRegistrationData fooRegData = new ModuleRegistrationData("foo", "foo");
    Map<String, SubmenuInfo> subMenuMap = new HashMap<>();
    SubmenuInfo subMenuWithAccessForUserFoo = new SubmenuInfo("#/foo");
    subMenuWithAccessForUserFoo.setRoleForAccess("foo");
    SubmenuInfo subMenuWithAccessForUserBar = new SubmenuInfo("#/bar");
    subMenuWithAccessForUserBar.setRoleForAccess("bar");
    SubmenuInfo subMenuWithoutAccessControl = new SubmenuInfo("#/random");
    subMenuMap.put("Foo", subMenuWithAccessForUserFoo);
    subMenuMap.put("Bar", subMenuWithAccessForUserBar);
    if (addSubMenuWithoutAccessControl) {
        subMenuMap.put("Random", subMenuWithoutAccessControl);
    }
    fooRegData.setSubMenu(subMenuMap);
    fooRegData.setBundle(bundle);
    ModuleRegistrations modules = new ModuleRegistrations();
    modules.setModulesWithSubMenu(Arrays.asList(fooRegData));
    when(uiFrameworkService.getRegisteredModules()).thenReturn(modules);
    RoleDto fooRole = new RoleDto("fooRole", Arrays.asList("foo"));
    RoleDto someOtherRole = new RoleDto("someOtherRole", Arrays.asList("someOtherPermission"));
    when(roleService.getRole("fooRole")).thenReturn(fooRole);
    when(roleService.getRole("someOtherRole")).thenReturn(someOtherRole);
}
Also used : RoleDto(org.motechproject.security.model.RoleDto) ModuleRegistrations(org.motechproject.osgi.web.util.ModuleRegistrations) HashMap(java.util.HashMap) ModuleRegistrationData(org.motechproject.osgi.web.ModuleRegistrationData) SubmenuInfo(org.motechproject.osgi.web.SubmenuInfo)

Aggregations

ModuleRegistrations (org.motechproject.osgi.web.util.ModuleRegistrations)3 HashMap (java.util.HashMap)2 ModuleRegistrationData (org.motechproject.osgi.web.ModuleRegistrationData)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 SubmenuInfo (org.motechproject.osgi.web.SubmenuInfo)1 RoleDto (org.motechproject.security.model.RoleDto)1