Search in sources :

Example 1 with RoleMembership

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());
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.rest.api.service.MembershipService) RoleMembership(io.gravitee.rest.api.management.rest.model.RoleMembership) Test(org.junit.Test)

Aggregations

RoleMembership (io.gravitee.rest.api.management.rest.model.RoleMembership)1 MembershipService (io.gravitee.rest.api.service.MembershipService)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1