use of io.gravitee.am.service.model.UpdateRole in project gravitee-access-management by gravitee-io.
the class RoleServiceTest method shouldUpdate_roleNotFound.
@Test
public void shouldUpdate_roleNotFound() {
UpdateRole updateRole = Mockito.mock(UpdateRole.class);
when(roleRepository.findById(ReferenceType.DOMAIN, DOMAIN, "my-role")).thenReturn(Maybe.empty());
TestObserver testObserver = new TestObserver();
roleService.update(DOMAIN, "my-role", updateRole).subscribe(testObserver);
testObserver.assertError(RoleNotFoundException.class);
testObserver.assertNotComplete();
verify(roleRepository, never()).findAll(ReferenceType.DOMAIN, DOMAIN);
verify(roleRepository, never()).create(any(Role.class));
}
use of io.gravitee.am.service.model.UpdateRole in project gravitee-access-management by gravitee-io.
the class RoleServiceTest method shouldNotUpdate_systemRole.
@Test
public void shouldNotUpdate_systemRole() {
UpdateRole updateRole = new UpdateRole();
Role role = new Role();
role.setSystem(true);
role.setReferenceType(ReferenceType.ORGANIZATION);
role.setReferenceId(ORGANIZATION_ID);
when(roleRepository.findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role")).thenReturn(Maybe.just(role));
TestObserver testObserver = roleService.update(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role", updateRole, null).test();
testObserver.awaitTerminalEvent();
testObserver.assertNotComplete();
testObserver.assertError(SystemRoleUpdateException.class);
verify(roleRepository, times(1)).findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role");
verify(roleRepository, never()).findAll(ReferenceType.ORGANIZATION, ORGANIZATION_ID);
verify(roleRepository, never()).update(any(Role.class));
}
use of io.gravitee.am.service.model.UpdateRole in project gravitee-access-management by gravitee-io.
the class RoleServiceTest method shouldUpdate_technicalException.
@Test
public void shouldUpdate_technicalException() {
UpdateRole updateRole = Mockito.mock(UpdateRole.class);
when(roleRepository.findById(ReferenceType.DOMAIN, DOMAIN, "my-role")).thenReturn(Maybe.error(TechnicalException::new));
TestObserver testObserver = new TestObserver();
roleService.update(DOMAIN, "my-role", updateRole).subscribe(testObserver);
testObserver.assertError(TechnicalManagementException.class);
testObserver.assertNotComplete();
verify(roleRepository, never()).findAll(ReferenceType.DOMAIN, DOMAIN);
verify(roleRepository, never()).update(any(Role.class));
}
use of io.gravitee.am.service.model.UpdateRole in project gravitee-access-management by gravitee-io.
the class RoleResource method update.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a role", notes = "User must have the DOMAIN_ROLE[UPDATE] permission on the specified domain " + "or DOMAIN_ROLE[UPDATE] permission on the specified environment " + "or DOMAIN_ROLE[UPDATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Role successfully updated", response = RoleEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
public void update(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @PathParam("role") String role, @ApiParam(name = "role", required = true) @Valid @NotNull UpdateRole updateRole, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_ROLE, Acl.UPDATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(irrelevant -> roleService.update(domain, role, convert(updateRole), authenticatedUser)).map(this::convert)).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.service.model.UpdateRole in project gravitee-access-management by gravitee-io.
the class RoleServiceTest method shouldUpdate.
@Test
public void shouldUpdate() {
UpdateRole updateRole = Mockito.mock(UpdateRole.class);
Role role = new Role();
role.setReferenceType(ReferenceType.DOMAIN);
role.setReferenceId("domain#1");
when(roleRepository.findById(ReferenceType.DOMAIN, DOMAIN, "my-role")).thenReturn(Maybe.just(role));
when(roleRepository.findAll(ReferenceType.DOMAIN, DOMAIN)).thenReturn(Flowable.empty());
when(roleRepository.update(any(Role.class))).thenReturn(Single.just(role));
when(eventService.create(any())).thenReturn(Single.just(new Event()));
TestObserver testObserver = roleService.update(DOMAIN, "my-role", updateRole).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
verify(roleRepository, times(1)).findById(ReferenceType.DOMAIN, DOMAIN, "my-role");
verify(roleRepository, times(1)).findAll(ReferenceType.DOMAIN, DOMAIN);
verify(roleRepository, times(1)).update(any(Role.class));
}
Aggregations