use of io.gravitee.rest.api.model.GroupEntity in project gravitee-management-rest-api by gravitee-io.
the class GroupsResourceTest method shouldCreate.
@Test
public void shouldCreate() {
reset(groupService);
NewGroupEntity newGroupEntity = new NewGroupEntity();
newGroupEntity.setName("my-group-name");
GroupEntity createdGroup = new GroupEntity();
createdGroup.setId("my-group-id");
doReturn(createdGroup).when(groupService).create(any());
final Response response = envTarget().request().post(Entity.json(newGroupEntity));
assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
assertEquals(envTarget().path("my-group-id").getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
}
use of io.gravitee.rest.api.model.GroupEntity in project gravitee-management-rest-api by gravitee-io.
the class GroupService_FindByEventTest method shouldGetGroupsByEvents.
@Test
public void shouldGetGroupsByEvents() throws Exception {
Group grp1 = new Group();
grp1.setId("grp1");
grp1.setName("grp1");
grp1.setEventRules(Collections.singletonList(new GroupEventRule(GroupEvent.API_CREATE)));
Group grp2 = new Group();
grp2.setId("grp2");
grp2.setName("grp2");
grp2.setEventRules(Collections.singletonList(new GroupEventRule(GroupEvent.API_CREATE)));
HashSet<Group> findAll = new HashSet<>();
findAll.add(grp1);
findAll.add(grp2);
when(groupRepository.findAllByEnvironment(Mockito.any())).thenReturn(findAll);
when(membershipService.getRoles(any(), any(), any(), any())).thenReturn(Collections.emptySet());
Set<GroupEntity> groupEntities = groupService.findByEvent(API_CREATE);
assertNotNull(groupEntities);
assertFalse(groupEntities.isEmpty());
assertEquals(2, groupEntities.size());
List<String> groupIds = groupEntities.stream().map(GroupEntity::getId).collect(Collectors.toList());
assertTrue(groupIds.containsAll(Arrays.asList("grp1", "grp2")));
}
use of io.gravitee.rest.api.model.GroupEntity in project gravitee-management-rest-api by gravitee-io.
the class GroupService_FindByEventTest method shouldNotGetGroupsByEvents.
@Test
public void shouldNotGetGroupsByEvents() throws Exception {
Group grp1 = new Group();
grp1.setId("grp1");
grp1.setEventRules(Collections.singletonList(new GroupEventRule(GroupEvent.APPLICATION_CREATE)));
Group grp2 = new Group();
grp2.setId("grp2");
grp2.setEventRules(Collections.singletonList(new GroupEventRule(GroupEvent.APPLICATION_CREATE)));
HashSet<Group> findAll = new HashSet<>();
findAll.add(grp1);
findAll.add(grp2);
when(groupRepository.findAllByEnvironment(any())).thenReturn(findAll);
Set<GroupEntity> groupEntities = groupService.findByEvent(API_CREATE);
assertNotNull(groupEntities);
assertTrue(groupEntities.isEmpty());
}
use of io.gravitee.rest.api.model.GroupEntity in project gravitee-management-rest-api by gravitee-io.
the class MembershipService_FindUserMembershipTest method shouldGetApiWithApiAndGroups.
@Test
public void shouldGetApiWithApiAndGroups() throws Exception {
RoleEntity roleEntity = new RoleEntity();
roleEntity.setId("role");
roleEntity.setName("PO");
roleEntity.setScope(RoleScope.API);
when(mockRoleService.findByScope(any())).thenReturn(Collections.singletonList(roleEntity));
Membership mApi = mock(Membership.class);
when(mApi.getReferenceId()).thenReturn("api-id1");
when(mApi.getRoleId()).thenReturn("role");
Membership mGroup = mock(Membership.class);
when(mGroup.getReferenceId()).thenReturn("api-id2");
when(mApi.getRoleId()).thenReturn("role");
when(mockMembershipRepository.findByMemberIdAndMemberTypeAndReferenceType(eq(USER_ID), eq(MembershipMemberType.USER), eq(MembershipReferenceType.API))).thenReturn(Collections.singleton(mApi));
when(mockMembershipRepository.findByMemberIdAndMemberTypeAndReferenceType(eq("GROUP"), eq(MembershipMemberType.GROUP), eq(MembershipReferenceType.API))).thenReturn(Collections.singleton(mGroup));
GroupEntity group1 = mock(GroupEntity.class);
doReturn("GROUP").when(group1).getId();
doReturn(new HashSet<>(asList(group1))).when(mockGroupService).findByUser(USER_ID);
List<UserMembership> references = membershipService.findUserMembership(io.gravitee.rest.api.model.MembershipReferenceType.API, USER_ID);
assertFalse(references.isEmpty());
assertEquals(2, references.size());
assertNotEquals(references.get(0).getReference(), references.get(1).getReference());
assertTrue(references.get(0).getReference().equals("api-id1") || references.get(0).getReference().equals("api-id2"));
assertTrue(references.get(1).getReference().equals("api-id1") || references.get(1).getReference().equals("api-id2"));
assertEquals("API", references.get(0).getType());
}
use of io.gravitee.rest.api.model.GroupEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_FindPrimaryOwnerTest method setPoUserInNoPOGroup.
private void setPoUserInNoPOGroup() {
GroupEntity aNonPoGroup = new GroupEntity();
aNonPoGroup.setId("aNonPoGroup");
aNonPoGroup.setApiPrimaryOwner(null);
GroupEntity anotherNonPoGroup = new GroupEntity();
anotherNonPoGroup.setId("anotherNonPoGroup");
anotherNonPoGroup.setApiPrimaryOwner(null);
when(groupService.findByUser(PO_USER_ID)).thenReturn(new HashSet<>(Arrays.asList(aNonPoGroup, anotherNonPoGroup)));
}
Aggregations