use of io.gravitee.rest.api.management.rest.model.RoleMembership in project gravitee-management-rest-api by gravitee-io.
the class RoleUsersResourceTest method shouldAddRoleToUser.
@Test
public void shouldAddRoleToUser() {
reset(membershipService);
RoleMembership roleMembership = new RoleMembership();
roleMembership.setId(USER_NAME);
final Response response = envTarget(SCOPE).path("roles").path(ROLE).path("users").request().post(Entity.json(roleMembership));
assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
assertNull(response.getHeaders().getFirst(HttpHeaders.LOCATION));
ArgumentCaptor<MembershipService.MembershipReference> memberShipRefCaptor = ArgumentCaptor.forClass(MembershipService.MembershipReference.class);
ArgumentCaptor<MembershipService.MembershipRole> memberShipRoleCaptor = ArgumentCaptor.forClass(MembershipService.MembershipRole.class);
ArgumentCaptor<MembershipService.MembershipMember> memberShipUserCaptor = ArgumentCaptor.forClass(MembershipService.MembershipMember.class);
Mockito.verify(membershipService).addRoleToMemberOnReference(memberShipRefCaptor.capture(), memberShipUserCaptor.capture(), memberShipRoleCaptor.capture());
assertEquals(GraviteeContext.getCurrentOrganization(), memberShipRefCaptor.getValue().getId());
assertEquals(MembershipReferenceType.ORGANIZATION, memberShipRefCaptor.getValue().getType());
assertEquals(ROLE, memberShipRoleCaptor.getValue().getName());
assertEquals(RoleScope.ORGANIZATION, memberShipRoleCaptor.getValue().getScope());
assertEquals(USER_NAME, memberShipUserCaptor.getValue().getMemberId());
}
Aggregations