Search in sources :

Example 1 with ApiMembership

use of io.gravitee.rest.api.management.rest.model.ApiMembership in project gravitee-management-rest-api by gravitee-io.

the class ApiMembersResourceTest method shouldCreateMember.

@Test
public void shouldCreateMember() {
    ApiMembership apiMembership = new ApiMembership();
    apiMembership.setId(MEMBER_1);
    apiMembership.setRole("my-api-membership-role");
    final Response response = envTarget(API).path("members").request().post(Entity.json(apiMembership));
    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(API, memberShipRefCaptor.getValue().getId());
    assertEquals("my-api-membership-role", memberShipRoleCaptor.getValue().getName());
    assertEquals(MEMBER_1, memberShipUserCaptor.getValue().getMemberId());
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.rest.api.service.MembershipService) ApiMembership(io.gravitee.rest.api.management.rest.model.ApiMembership) Test(org.junit.Test)

Aggregations

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