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());
}
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);
}
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);
}
Aggregations