Search in sources :

Example 6 with GroupEntity

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));
}
Also used : Response(javax.ws.rs.core.Response) NewGroupEntity(io.gravitee.rest.api.model.NewGroupEntity) GroupEntity(io.gravitee.rest.api.model.GroupEntity) NewGroupEntity(io.gravitee.rest.api.model.NewGroupEntity) Test(org.junit.Test)

Example 7 with GroupEntity

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")));
}
Also used : Group(io.gravitee.repository.management.model.Group) GroupEntity(io.gravitee.rest.api.model.GroupEntity) GroupEventRule(io.gravitee.repository.management.model.GroupEventRule) Test(org.junit.Test)

Example 8 with GroupEntity

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());
}
Also used : Group(io.gravitee.repository.management.model.Group) GroupEntity(io.gravitee.rest.api.model.GroupEntity) GroupEventRule(io.gravitee.repository.management.model.GroupEventRule) Test(org.junit.Test)

Example 9 with GroupEntity

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());
}
Also used : RoleEntity(io.gravitee.rest.api.model.RoleEntity) GroupEntity(io.gravitee.rest.api.model.GroupEntity) Membership(io.gravitee.repository.management.model.Membership) UserMembership(io.gravitee.rest.api.model.UserMembership) UserMembership(io.gravitee.rest.api.model.UserMembership) Test(org.junit.Test)

Example 10 with GroupEntity

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)));
}
Also used : GroupEntity(io.gravitee.rest.api.model.GroupEntity)

Aggregations

GroupEntity (io.gravitee.rest.api.model.GroupEntity)14 Test (org.junit.Test)5 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)3 Group (io.gravitee.repository.management.model.Group)2 GroupEventRule (io.gravitee.repository.management.model.GroupEventRule)2 Membership (io.gravitee.repository.management.model.Membership)2 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)2 UpdateGroupEntity (io.gravitee.rest.api.model.UpdateGroupEntity)2 UserMembership (io.gravitee.rest.api.model.UserMembership)2 Permission (io.gravitee.rest.api.management.rest.security.Permission)1 NewGroupEntity (io.gravitee.rest.api.model.NewGroupEntity)1 PrimaryOwnerEntity (io.gravitee.rest.api.model.PrimaryOwnerEntity)1 RoleEntity (io.gravitee.rest.api.model.RoleEntity)1 UserEntity (io.gravitee.rest.api.model.UserEntity)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)1 GroupInvitationForbiddenException (io.gravitee.rest.api.service.exceptions.GroupInvitationForbiddenException)1 GroupMembersLimitationExceededException (io.gravitee.rest.api.service.exceptions.GroupMembersLimitationExceededException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Principal (java.security.Principal)1