@Test public void shouldGetAllRolesMapByRightType() throws Exception { List<Role> allRoles = new ArrayList<>(); Role role1 = new Role(); role1.setId(1L); Role role2 = new Role(); role2.setId(2L); Role role3 = new Role(); role3.setId(3L); Role role4 = new Role(); role4.setId(4L); allRoles.add(role1); allRoles.add(role2); allRoles.add(role3); allRoles.add(role4); when(roleRightsRepository.getAllRoles()).thenReturn(allRoles); when(roleRightsRepository.getRightTypeForRoleId(1L)).thenReturn(RightType.REQUISITION); when(roleRightsRepository.getRightTypeForRoleId(2L)).thenReturn(RightType.ADMIN); when(roleRightsRepository.getRightTypeForRoleId(3L)).thenReturn(RightType.ALLOCATION); when(roleRightsRepository.getRightTypeForRoleId(4L)).thenReturn(RightType.ALLOCATION); Map<String, List<Role>> allRolesMap = roleRightsService.getAllRolesMap(); assertThat(allRolesMap.size(), is(3)); assertThat(allRolesMap.get(RightType.ADMIN.name()).size(), is(1)); assertThat(allRolesMap.get(RightType.REQUISITION.name()).size(), is(1)); assertThat(allRolesMap.get(RightType.ALLOCATION.name()).size(), is(2)); }
@Test public void shouldGetRoleById() throws Exception { Role role = new Role(); Long roleId = 1L; when(roleRightsRepository.getRole(roleId)).thenReturn(role); assertThat(roleRightsService.getRole(roleId), is(role)); verify(roleRightsRepository).getRole(roleId); }
@Test public void shouldGetRightsForUserAndWarehouse() { Set<Right> expectedRights = new HashSet<>(); Long userId = 1l; Long warehouseId = 2l; when(roleRightsRepository.getRightsForUserAndWarehouse(userId, warehouseId)) .thenReturn(expectedRights); Set<Right> rights = roleRightsService.getRightsForUserAndWarehouse(userId, warehouseId); assertThat(rights, is(expectedRights)); verify(roleRightsRepository).getRightsForUserAndWarehouse(userId, warehouseId); }
@Test public void shouldGetRightsForAUserOnHomeFacilityAndProgram() throws Exception { Long userId = 1L; Facility facility = new Facility(2L); Program program = new Program(3L); List<Right> expected = asList(CREATE_REQUISITION); when(facilityService.getHomeFacility(userId)).thenReturn(facility); when(roleRightsRepository.getRightsForUserOnHomeFacilityAndProgram(userId, program)) .thenReturn(expected); Set<Right> result = roleRightsService.getRightsForUserAndFacilityProgram(userId, facility, program); assertThat(result.containsAll(expected), is(true)); verify(roleRightsRepository).getRightsForUserOnHomeFacilityAndProgram(userId, program); }
@Test public void shouldGetRightsForAUserOnSupervisedFacilityAndProgram() throws Exception { Long userId = 1L; Facility facility = new Facility(2L); Program program = new Program(3L); List<Right> expected = asList(CREATE_REQUISITION); SupervisoryNode supervisoryNode = new SupervisoryNode(4L); List<SupervisoryNode> supervisoryNodes = asList(supervisoryNode); when(supervisoryNodeService.getFor(facility, program)).thenReturn(supervisoryNode); when(supervisoryNodeService.getAllParentSupervisoryNodesInHierarchy(supervisoryNode)) .thenReturn(supervisoryNodes); when(roleRightsRepository.getRightsForUserOnSupervisoryNodeAndProgram( userId, supervisoryNodes, program)) .thenReturn(expected); Set<Right> result = roleRightsService.getRightsForUserAndFacilityProgram(userId, facility, program); verify(roleRightsRepository) .getRightsForUserOnSupervisoryNodeAndProgram(userId, supervisoryNodes, program); assertThat(result.containsAll(expected), is(true)); }