use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingAssignmentServiceTest method getGroupingTest.
@Test
public void getGroupingTest() {
Grouping groupingRandom = groupingAssignmentService.getGrouping(GROUPING_0_PATH, users.get(1).getUsername());
Grouping groupingOwner = groupingAssignmentService.getGrouping(GROUPING_0_PATH, users.get(0).getUsername());
Grouping groupingAdmin = groupingAssignmentService.getGrouping(GROUPING_0_PATH, ADMIN_USER);
assertEquals(0, groupingRandom.getComposite().getMembers().size());
assertEquals(0, groupingRandom.getInclude().getMembers().size());
assertEquals(0, groupingRandom.getExclude().getMembers().size());
assertEquals(0, groupingRandom.getBasis().getMembers().size());
assertEquals(0, groupingRandom.getOwners().getMembers().size());
assertTrue(groupingOwner.getComposite().getNames().contains(users.get(0).getName()));
assertTrue(groupingOwner.getComposite().getUsernames().contains(users.get(0).getUsername()));
assertTrue(groupingOwner.getComposite().getUuids().contains(users.get(0).getUuid()));
assertTrue(groupingOwner.getInclude().getNames().contains(users.get(5).getName()));
assertTrue(groupingOwner.getExclude().getNames().contains(users.get(2).getName()));
assertTrue(groupingOwner.getBasis().getNames().contains(users.get(4).getName()));
assertTrue(groupingOwner.getOwners().getNames().contains(users.get(0).getName()));
assertTrue(groupingAdmin.getComposite().getNames().contains(users.get(0).getName()));
assertTrue(groupingAdmin.getComposite().getUsernames().contains(users.get(0).getUsername()));
assertTrue(groupingAdmin.getComposite().getUuids().contains(users.get(0).getUuid()));
assertTrue(groupingAdmin.getInclude().getNames().contains(users.get(5).getName()));
assertTrue(groupingAdmin.getExclude().getNames().contains(users.get(2).getName()));
assertTrue(groupingAdmin.getBasis().getNames().contains(users.get(4).getName()));
assertTrue(groupingAdmin.getOwners().getNames().contains(users.get(0).getName()));
}
use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingAssignmentServiceTest method groupingsInTest.
@Test
public void groupingsInTest() {
Iterable<Group> groupsIn = groupRepository.findByMembersUsername(users.get(6).getUsername());
List<String> groupPaths = new ArrayList<>();
List<String> supposedGroupings = new ArrayList<>();
for (Group group : groupsIn) {
groupPaths.add(group.getPath());
}
supposedGroupings.addAll(groupPaths.stream().filter(groupPath -> groupPath.matches("[a-zA-Z0-9:]*grouping[0-9]*")).collect(Collectors.toList()));
List<Grouping> groupingsIn = groupingAssignmentService.groupingsIn(groupPaths);
List<String> groupingPaths = groupingsIn.stream().map(Grouping::getPath).collect(Collectors.toList());
for (String path : supposedGroupings) {
assertTrue(groupingPaths.contains(path));
}
for (Grouping grouping : groupingsIn) {
assertTrue(supposedGroupings.contains(grouping.getPath()));
}
}
use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingAssignmentServiceTest method groupingsOptedIntoTest.
@Test
public void groupingsOptedIntoTest() {
String user5 = users.get(5).getUsername();
Iterable<Group> groups = groupRepository.findByMembersUsername(user5);
List<String> groupPaths = new ArrayList<>();
for (Group group : groups) {
groupPaths.add(group.getPath());
}
List<Grouping> groupingsOptedInto = groupingAssignmentService.groupingsOptedInto(user5, groupPaths);
// starts with no groupings opted into
assertEquals(0, groupingsOptedInto.size());
// opt into a grouping
membershipService.optIn(user5, GROUPING_1_PATH);
groupingsOptedInto = groupingAssignmentService.groupingsOptedInto(user5, groupPaths);
assertEquals(1, groupingsOptedInto.size());
// opt into another grouping
membershipService.optIn(user5, GROUPING_3_PATH);
groupingsOptedInto = groupingAssignmentService.groupingsOptedInto(user5, groupPaths);
assertEquals(2, groupingsOptedInto.size());
// opt out of a grouping
membershipService.optOut(user5, GROUPING_3_PATH);
groupingsOptedInto = groupingAssignmentService.groupingsOptedInto(user5, groupPaths);
assertEquals(1, groupingsOptedInto.size());
// opt out of another grouping
membershipService.optOut(user5, GROUPING_1_PATH);
groupingsOptedInto = groupingAssignmentService.groupingsOptedInto(user5, groupPaths);
assertEquals(0, groupingsOptedInto.size());
}
use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.
the class MembershipServiceTest method addGroupingMemberbyUsernameTest.
@Test
public void addGroupingMemberbyUsernameTest() {
Iterable<Grouping> group = groupingRepository.findAll();
List<GroupingsServiceResult> listGsr;
GroupingsServiceResult gsr;
// Base test
// Remove person who's not in composite from exclude and return SUCCESS
listGsr = membershipService.addGroupingMemberByUsername(users.get(0).getUsername(), GROUPING_3_PATH, users.get(2).getUsername());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
// todo Case where !inComposite && !inBasis is impossible w/ current db
// In composite
listGsr = membershipService.addGroupingMemberByUuid(users.get(0).getUsername(), GROUPING_3_PATH, users.get(5).getUsername());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
// Test if user is not an owner
try {
listGsr = membershipService.addGroupingMemberByUuid(users.get(5).getUsername(), GROUPING_3_PATH, users.get(3).getUsername());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
} catch (GroupingsServiceResultException gsre) {
gsr = gsre.getGsr();
}
// Test if user is admin
listGsr = membershipService.addGroupingMemberByUuid(ADMIN_USER, GROUPING_3_PATH, users.get(3).getUuid());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
}
use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.
the class MembershipServiceTest method addMemberByUuidTest.
@Test
public void addMemberByUuidTest() {
Grouping grouping = groupingRepository.findByPath(GROUPING_1_PATH);
assertFalse(grouping.getComposite().getMembers().contains(users.get(3)));
membershipService.addGroupMemberByUuid(users.get(0).getUsername(), GROUPING_1_INCLUDE_PATH, users.get(3).getUuid());
grouping = groupingRepository.findByPath(GROUPING_1_PATH);
assertTrue(grouping.getComposite().getMembers().contains(users.get(3)));
}
Aggregations