use of io.gravitee.am.repository.management.api.RoleRepository in project gravitee-access-management by gravitee-io.
the class RoleServiceTest method shouldUpdate_defaultRolePermissions.
@Test
public void shouldUpdate_defaultRolePermissions() {
UpdateRole updateRole = new UpdateRole();
updateRole.setName(DefaultRole.DOMAIN_USER.name());
updateRole.setPermissions(Permission.flatten(Collections.singletonMap(Permission.DOMAIN, Collections.singleton(Acl.READ))));
Role role = new Role();
role.setName(DefaultRole.DOMAIN_USER.name());
// should be able to update a default role.
role.setDefaultRole(true);
role.setReferenceType(ReferenceType.ORGANIZATION);
role.setReferenceId(ORGANIZATION_ID);
when(roleRepository.findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role")).thenReturn(Maybe.just(role));
when(roleRepository.findAll(ReferenceType.ORGANIZATION, ORGANIZATION_ID)).thenReturn(Flowable.empty());
when(roleRepository.update(argThat(r -> r.getPermissionAcls().equals(Permission.unflatten(updateRole.getPermissions()))))).thenReturn(Single.just(role));
when(eventService.create(any())).thenReturn(Single.just(new Event()));
TestObserver testObserver = roleService.update(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role", updateRole, null).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
verify(roleRepository, times(1)).findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role");
verify(roleRepository, times(1)).findAll(ReferenceType.ORGANIZATION, ORGANIZATION_ID);
verify(roleRepository, times(1)).update(any(Role.class));
}
Aggregations