Search in sources :

Example 1 with GroupEventRule

use of io.gravitee.repository.management.model.GroupEventRule 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 2 with GroupEventRule

use of io.gravitee.repository.management.model.GroupEventRule 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)

Aggregations

Group (io.gravitee.repository.management.model.Group)2 GroupEventRule (io.gravitee.repository.management.model.GroupEventRule)2 GroupEntity (io.gravitee.rest.api.model.GroupEntity)2 Test (org.junit.Test)2