Search in sources :

Example 6 with MemberEntity

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

the class ApplicationMembersResourceTest method shouldCreateMember.

@Test
public void shouldCreateMember() {
    MemberInput memberInput = new MemberInput().role("USER").user(MEMBER_1);
    MemberEntity returnedMemberEntity = mock(MemberEntity.class);
    doReturn(MEMBER_1).when(returnedMemberEntity).getId();
    doReturn(returnedMemberEntity).when(membershipService).addRoleToMemberOnReference(any(), any(), any());
    final Response response = target(APPLICATION).path("members").request().post(Entity.json(memberInput));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
    assertEquals(target(APPLICATION).path("members").path(MEMBER_1).getUri().toString(), 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("USER", memberShipRoleCaptor.getValue().getName());
    assertEquals(MEMBER_1, memberShipUserCaptor.getValue().getMemberId());
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.rest.api.service.MembershipService) MemberEntity(io.gravitee.rest.api.model.MemberEntity) Test(org.junit.Test)

Example 7 with MemberEntity

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

the class ApplicationMembersResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    MemberEntity memberEntity1 = new MemberEntity();
    memberEntity1.setId(MEMBER_1);
    MemberEntity memberEntity2 = new MemberEntity();
    memberEntity2.setId(MEMBER_2);
    doReturn(new Member().id(MEMBER_2)).when(memberMapper).convert(eq(memberEntity2), any());
    doReturn(new Member().id(MEMBER_1)).when(memberMapper).convert(eq(memberEntity1), any());
    doReturn(Sets.newSet(memberEntity1, memberEntity2)).when(membershipService).getMembersByReference(MembershipReferenceType.APPLICATION, APPLICATION);
    doReturn(memberEntity1).when(membershipService).getUserMember(MembershipReferenceType.APPLICATION, APPLICATION, MEMBER_1);
    doReturn(null).when(membershipService).getUserMember(MembershipReferenceType.APPLICATION, APPLICATION, MEMBER_2);
    doThrow(ApplicationNotFoundException.class).when(applicationService).findById(UNKNOWN_APPLICATION);
    doThrow(UserNotFoundException.class).when(userService).findById(UNKNOWN_MEMBER);
}
Also used : MemberEntity(io.gravitee.rest.api.model.MemberEntity) Before(org.junit.Before)

Example 8 with MemberEntity

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

the class MembershipService_GetMembersTest method shouldGetMembersWithMembership.

@Test
public void shouldGetMembersWithMembership() throws Exception {
    Membership membership = new Membership();
    membership.setReferenceId(API_ID);
    membership.setCreatedAt(new Date());
    membership.setUpdatedAt(membership.getCreatedAt());
    membership.setReferenceType(MembershipReferenceType.API);
    membership.setRoleId("API_PRIMARY_OWNER");
    membership.setMemberId("user-id");
    membership.setMemberType(MembershipMemberType.USER);
    UserEntity userEntity = new UserEntity();
    userEntity.setId(membership.getMemberId());
    userEntity.setFirstname("John");
    userEntity.setLastname("Doe");
    RoleEntity po = mock(RoleEntity.class);
    po.setName(SystemRole.PRIMARY_OWNER.name());
    List<String> memberIds = Collections.singletonList(membership.getMemberId());
    Set<UserEntity> userEntities = Collections.singleton(userEntity);
    when(membershipRepository.findByReferencesAndRoleId(MembershipReferenceType.API, Collections.singletonList(API_ID), "API_PRIMARY_OWNER")).thenReturn(Collections.singleton(membership));
    when(userService.findByIds(memberIds, false)).thenReturn(userEntities);
    when(roleService.findById("API_PRIMARY_OWNER")).thenReturn(po);
    Set<MemberEntity> members = membershipService.getMembersByReferenceAndRole(io.gravitee.rest.api.model.MembershipReferenceType.API, API_ID, "API_PRIMARY_OWNER");
    Assert.assertNotNull(members);
    Assert.assertFalse("members must not be empty", members.isEmpty());
    verify(membershipRepository, times(1)).findByReferencesAndRoleId(MembershipReferenceType.API, Collections.singletonList(API_ID), "API_PRIMARY_OWNER");
    verify(userService, times(1)).findByIds(memberIds, false);
}
Also used : RoleEntity(io.gravitee.rest.api.model.RoleEntity) Membership(io.gravitee.repository.management.model.Membership) MemberEntity(io.gravitee.rest.api.model.MemberEntity) Date(java.util.Date) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Aggregations

MemberEntity (io.gravitee.rest.api.model.MemberEntity)8 Test (org.junit.Test)4 RoleEntity (io.gravitee.rest.api.model.RoleEntity)3 UserEntity (io.gravitee.rest.api.model.UserEntity)3 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)3 MembershipService (io.gravitee.rest.api.service.MembershipService)3 Date (java.util.Date)3 Membership (io.gravitee.repository.management.model.Membership)2 SinglePrimaryOwnerException (io.gravitee.rest.api.service.exceptions.SinglePrimaryOwnerException)2 Member (io.gravitee.rest.api.portal.rest.model.Member)1 User (io.gravitee.rest.api.portal.rest.model.User)1 Instant (java.time.Instant)1 Response (javax.ws.rs.core.Response)1 Before (org.junit.Before)1