Search in sources :

Example 1 with ApplicationMembership

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

the class ApplicationMembersResourceTest method shouldCreateMember.

@Test
public void shouldCreateMember() {
    Mockito.reset(membershipService);
    ApplicationMembership applicationMembership = new ApplicationMembership();
    applicationMembership.setId(MEMBER_1);
    applicationMembership.setRole("my-application-membership-role");
    final Response response = envTarget(APPLICATION).path("members").request().post(Entity.json(applicationMembership));
    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(APPLICATION, memberShipRefCaptor.getValue().getId());
    assertEquals("my-application-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) ApplicationMembership(io.gravitee.rest.api.management.rest.model.ApplicationMembership) Test(org.junit.Test)

Aggregations

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