protected RoleList defaultRoleList() {
      // Having an empty role list is not valid, they should always have one role
      Role role = new Role();
      role.setName("derpRole");
      role.setId("9");
      role.setDescription("Derp description");

      RoleList roleList = new RoleList();
      roleList.getRole().add(role);
      return roleList;
    }
Exemplo n.º 2
0
  @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));
  }
Exemplo n.º 3
0
 @Test
 public void shouldUpdateRole() {
   role.setRights(new HashSet<>(asList(CREATE_REQUISITION)));
   roleRightsService.updateRole(role);
   verify(roleRightsRepository).updateRole(role);
 }
Exemplo n.º 4
0
 @Test
 public void shouldSaveRole() throws Exception {
   role.setRights(new HashSet<>(asList(CREATE_REQUISITION, VIEW_REQUISITION)));
   roleRightsService.saveRole(role);
   verify(roleRightsRepository).createRole(role);
 }