@Test public void shouldNotAddMenuSectionIfUserDoesNotHaveAccessToAnySubMenu() { setUpToTestAccessControlledSubMenuLinks(false); when(userService.getRoles(USERNAME)).thenReturn(Arrays.asList("someOtherRole")); when(bundle.getHeaders().get(DOC_URL)).thenReturn("http: ModuleMenu menu = menuBuilder.buildMenu(USERNAME); assertNotNull(menu); List<ModuleMenuSection> menuSections = menu.getSections(); assertFalse(menuSections.isEmpty()); assertThat(menuSections.size(), Is.is(1)); assertThat(menuSections.get(0).getName(), Is.is("server.modules")); }
public ModuleMenu buildMenu(String username) { ModuleMenu moduleMenu = new ModuleMenu(); List<String> userRoles = userService.getRoles(username); for (ModuleRegistrationData moduleRegistrationData : getModulesWithSubMenu(userRoles)) { ModuleMenuSection menuSection = getModuleMenuSection(username, userRoles, moduleRegistrationData); if (!menuSection.getLinks().isEmpty()) { moduleMenu.addMenuSection(menuSection); } } moduleMenu.addMenuSection(serverModulesMenuSection(userRoles)); if (checkUserPermission(userRoles, REST_API_PERMISSION)) { ModuleMenuSection restSection = restDocumentationMenu(); if (CollectionUtils.isNotEmpty(restSection.getLinks())) { moduleMenu.addMenuSection(restSection); } } return moduleMenu; }
MenuBuilder { public ModuleMenu buildMenu(String username) { ModuleMenu moduleMenu = new ModuleMenu(); List<String> userRoles = userService.getRoles(username); for (ModuleRegistrationData moduleRegistrationData : getModulesWithSubMenu(userRoles)) { ModuleMenuSection menuSection = getModuleMenuSection(username, userRoles, moduleRegistrationData); if (!menuSection.getLinks().isEmpty()) { moduleMenu.addMenuSection(menuSection); } } moduleMenu.addMenuSection(serverModulesMenuSection(userRoles)); if (checkUserPermission(userRoles, REST_API_PERMISSION)) { ModuleMenuSection restSection = restDocumentationMenu(); if (CollectionUtils.isNotEmpty(restSection.getLinks())) { moduleMenu.addMenuSection(restSection); } } return moduleMenu; } }
MenuBuilder { public ModuleMenu buildMenu(String username) { ModuleMenu moduleMenu = new ModuleMenu(); List<String> userRoles = userService.getRoles(username); for (ModuleRegistrationData moduleRegistrationData : getModulesWithSubMenu(userRoles)) { ModuleMenuSection menuSection = getModuleMenuSection(username, userRoles, moduleRegistrationData); if (!menuSection.getLinks().isEmpty()) { moduleMenu.addMenuSection(menuSection); } } moduleMenu.addMenuSection(serverModulesMenuSection(userRoles)); if (checkUserPermission(userRoles, REST_API_PERMISSION)) { ModuleMenuSection restSection = restDocumentationMenu(); if (CollectionUtils.isNotEmpty(restSection.getLinks())) { moduleMenu.addMenuSection(restSection); } } return moduleMenu; }  }
MenuBuilder { public ModuleMenu buildMenu(String username) { ModuleMenu moduleMenu = new ModuleMenu(); List<String> userRoles = userService.getRoles(username); for (ModuleRegistrationData moduleRegistrationData : getModulesWithSubMenu(userRoles)) { ModuleMenuSection menuSection = getModuleMenuSection(username, userRoles, moduleRegistrationData); if (!menuSection.getLinks().isEmpty()) { moduleMenu.addMenuSection(menuSection); } } moduleMenu.addMenuSection(serverModulesMenuSection(userRoles)); if (checkUserPermission(userRoles, REST_API_PERMISSION)) { ModuleMenuSection restSection = restDocumentationMenu(); if (CollectionUtils.isNotEmpty(restSection.getLinks())) { moduleMenu.addMenuSection(restSection); } } return moduleMenu; }  ModuleMenu buildMenu(String username); }
MenuBuilder { public ModuleMenu buildMenu(String username) { ModuleMenu moduleMenu = new ModuleMenu(); List<String> userRoles = userService.getRoles(username); for (ModuleRegistrationData moduleRegistrationData : getModulesWithSubMenu(userRoles)) { ModuleMenuSection menuSection = getModuleMenuSection(username, userRoles, moduleRegistrationData); if (!menuSection.getLinks().isEmpty()) { moduleMenu.addMenuSection(menuSection); } } moduleMenu.addMenuSection(serverModulesMenuSection(userRoles)); if (checkUserPermission(userRoles, REST_API_PERMISSION)) { ModuleMenuSection restSection = restDocumentationMenu(); if (CollectionUtils.isNotEmpty(restSection.getLinks())) { moduleMenu.addMenuSection(restSection); } } return moduleMenu; }  ModuleMenu buildMenu(String username);  }