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