use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.
the class DatabaseSetup method setUpMemberships.
private void setUpMemberships() {
Person grouperAll = new Person();
grouperAll.setUsername("GrouperAll");
personRepository.save(grouperAll);
Iterable<Group> groups = groupRepository.findAll();
for (Group group : groups) {
group.addMember(grouperAll);
groupRepository.save(group);
for (Person person : group.getMembers()) {
Membership membership = new Membership(person, group);
membershipRepository.save(membership);
}
}
Iterable<Grouping> groupings = groupingRepository.findAll();
for (Grouping grouping : groupings) {
Membership allExclude = membershipRepository.findByPersonAndGroup(grouperAll, grouping.getExclude());
Membership allInclude = membershipRepository.findByPersonAndGroup(grouperAll, grouping.getInclude());
Membership allComposite = membershipRepository.findByPersonAndGroup(grouperAll, grouping.getComposite());
if (grouping.isOptOutOn()) {
allComposite.setOptOutEnabled(true);
allExclude.setOptInEnabled(true);
allExclude.setOptOutEnabled(true);
}
if (grouping.isOptInOn()) {
allComposite.setOptInEnabled(true);
allInclude.setOptInEnabled(true);
allInclude.setOptOutEnabled(true);
}
membershipRepository.save(allComposite);
membershipRepository.save(allExclude);
membershipRepository.save(allInclude);
}
}
use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupAttributeServiceTest method changeListservStatusTest.
@Test
public void changeListservStatusTest() {
// expect actions by "Random" to fail
GroupingsServiceResult turnOnWhenOnRandom;
GroupingsServiceResult turnOnWhenOffRandom;
GroupingsServiceResult turnOffWhenOnRandom;
GroupingsServiceResult turnOffWhenOffRandom;
Grouping grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertFalse(grouping.isListservOn());
try {
turnOnWhenOffRandom = groupingsService.changeListservStatus(GROUPING_4_PATH, users.get(1).getUsername(), true);
} catch (GroupingsServiceResultException gsre) {
turnOnWhenOffRandom = gsre.getGsr();
}
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertFalse(grouping.isListservOn());
GroupingsServiceResult turnOnWhenOffOwner = groupingsService.changeListservStatus(GROUPING_4_PATH, users.get(0).getUsername(), true);
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertTrue(grouping.isListservOn());
try {
turnOnWhenOnRandom = groupingsService.changeListservStatus(GROUPING_4_PATH, users.get(1).getUsername(), true);
} catch (GroupingsServiceResultException gsre) {
turnOnWhenOnRandom = gsre.getGsr();
}
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertTrue(grouping.isListservOn());
GroupingsServiceResult turnOnWhenOnOwner = groupingsService.changeListservStatus(GROUPING_4_PATH, users.get(0).getUsername(), true);
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertTrue(grouping.isListservOn());
GroupingsServiceResult turnOnWhenOnAdmin = groupingsService.changeListservStatus(GROUPING_4_PATH, ADMIN_USER, true);
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertTrue(grouping.isListservOn());
try {
turnOffWhenOnRandom = groupingsService.changeListservStatus(GROUPING_4_PATH, users.get(1).getUsername(), false);
} catch (GroupingsServiceResultException gsre) {
turnOffWhenOnRandom = gsre.getGsr();
}
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertTrue(grouping.isListservOn());
GroupingsServiceResult turnOffWhenOnOwner = groupingsService.changeListservStatus(GROUPING_4_PATH, users.get(0).getUsername(), false);
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertFalse(grouping.isListservOn());
GroupingsServiceResult turnOnWhenOffAdmin = groupingsService.changeListservStatus(GROUPING_4_PATH, ADMIN_USER, true);
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertTrue(grouping.isListservOn());
GroupingsServiceResult turnOffWhenOnAdmin = groupingsService.changeListservStatus(GROUPING_4_PATH, ADMIN_USER, false);
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertFalse(grouping.isListservOn());
try {
turnOffWhenOffRandom = groupingsService.changeListservStatus(GROUPING_4_PATH, users.get(1).getUsername(), false);
} catch (GroupingsServiceResultException gsre) {
turnOffWhenOffRandom = gsre.getGsr();
}
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertFalse(grouping.isListservOn());
GroupingsServiceResult turnOffWhenOffOwner = groupingsService.changeListservStatus(GROUPING_4_PATH, users.get(0).getUsername(), false);
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertFalse(grouping.isListservOn());
GroupingsServiceResult turnOffWhenOffAdmin = groupingsService.changeListservStatus(GROUPING_4_PATH, ADMIN_USER, false);
grouping = groupingRepository.findByPath(GROUPING_4_PATH);
assertFalse(grouping.isListservOn());
assertTrue(turnOnWhenOnRandom.getResultCode().startsWith(FAILURE));
assertTrue(turnOnWhenOnOwner.getResultCode().startsWith(SUCCESS));
assertTrue(turnOnWhenOnAdmin.getResultCode().startsWith(SUCCESS));
assertTrue(turnOffWhenOnRandom.getResultCode().startsWith(FAILURE));
assertTrue(turnOffWhenOnOwner.getResultCode().startsWith(SUCCESS));
assertTrue(turnOffWhenOnAdmin.getResultCode().startsWith(SUCCESS));
assertTrue(turnOnWhenOffRandom.getResultCode().startsWith(FAILURE));
assertTrue(turnOnWhenOffOwner.getResultCode().startsWith(SUCCESS));
assertTrue(turnOnWhenOffAdmin.getResultCode().startsWith(SUCCESS));
assertTrue(turnOffWhenOffRandom.getResultCode().startsWith(FAILURE));
assertTrue(turnOffWhenOffOwner.getResultCode().startsWith(SUCCESS));
assertTrue(turnOffWhenOffAdmin.getResultCode().startsWith(SUCCESS));
}
use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingAssignmentServiceTest method groupingsOptedOutOfTest.
@Test
public void groupingsOptedOutOfTest() {
String user1 = users.get(1).getUsername();
Iterable<Group> groups = groupRepository.findByMembersUsername(user1);
List<String> groupPaths = new ArrayList<>();
for (Group group : groups) {
groupPaths.add(group.getPath());
}
List<Grouping> groupingsOptedOutOf = groupingAssignmentService.groupingsOptedOutOf(user1, groupPaths);
// starts with no groupings out of
assertEquals(0, groupingsOptedOutOf.size());
// opt out of a grouping
membershipService.optOut(user1, GROUPING_1_PATH);
groups = groupRepository.findByMembersUsername(user1);
groupPaths = new ArrayList<>();
for (Group group : groups) {
groupPaths.add(group.getPath());
}
groupingsOptedOutOf = groupingAssignmentService.groupingsOptedOutOf(user1, groupPaths);
assertEquals(1, groupingsOptedOutOf.size());
// opt out of another grouping
membershipService.optOut(user1, GROUPING_3_PATH);
groups = groupRepository.findByMembersUsername(user1);
groupPaths = new ArrayList<>();
for (Group group : groups) {
groupPaths.add(group.getPath());
}
groupingsOptedOutOf = groupingAssignmentService.groupingsOptedOutOf(user1, groupPaths);
assertEquals(2, groupingsOptedOutOf.size());
// opt into a grouping
membershipService.optIn(user1, GROUPING_3_PATH);
groups = groupRepository.findByMembersUsername(user1);
groupPaths = new ArrayList<>();
for (Group group : groups) {
groupPaths.add(group.getPath());
}
groupingsOptedOutOf = groupingAssignmentService.groupingsOptedOutOf(user1, groupPaths);
assertEquals(1, groupingsOptedOutOf.size());
// opt into another grouping
membershipService.optIn(user1, GROUPING_1_PATH);
groups = groupRepository.findByMembersUsername(user1);
groupPaths = new ArrayList<>();
for (Group group : groups) {
groupPaths.add(group.getPath());
}
groupingsOptedOutOf = groupingAssignmentService.groupingsOptedOutOf(user1, groupPaths);
assertEquals(0, groupingsOptedOutOf.size());
}
use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingAssignmentServiceTest method groupingsOwnedTest.
@Test
public void groupingsOwnedTest() {
Iterable<Group> groupsIn = groupRepository.findByMembersUsername(users.get(0).getUsername());
List<String> groupPaths = new ArrayList<>();
for (Group group : groupsIn) {
groupPaths.add(group.getPath());
}
List<Grouping> groupingsOwned = groupingAssignmentService.groupingsOwned(groupPaths);
for (int i = 0; i < groupingsOwned.size(); i++) {
assertTrue(groupingsOwned.get(i).getPath().equals(PATH_ROOT + i));
}
}
use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.
the class MemberAttributeServiceTest method assignOwnershipTest.
@Test
public void assignOwnershipTest() {
// expect this to fail
GroupingsServiceResult randomUserAdds;
Person randomUser = personRepository.findByUsername(users.get(1).getUsername());
Grouping grouping = groupingRepository.findByPath(GROUPING_0_PATH);
assertFalse(grouping.getOwners().getMembers().contains(randomUser));
assertFalse(grouping.getOwners().isMember(randomUser));
try {
randomUserAdds = memberAttributeService.assignOwnership(GROUPING_0_PATH, randomUser.getUsername(), randomUser.getUsername());
} catch (GroupingsServiceResultException gsre) {
randomUserAdds = gsre.getGsr();
}
grouping = groupingRepository.findByPath(GROUPING_0_PATH);
assertFalse(grouping.getOwners().getMembers().contains(randomUser));
assertFalse(grouping.getOwners().isMember(randomUser));
assertNotEquals(randomUserAdds.getResultCode(), SUCCESS);
GroupingsServiceResult ownerAdds = memberAttributeService.assignOwnership(GROUPING_0_PATH, users.get(0).getUsername(), randomUser.getUsername());
grouping = groupingRepository.findByPath(GROUPING_0_PATH);
assertTrue(grouping.getOwners().getMembers().contains(randomUser));
assertTrue(grouping.getOwners().isMember(randomUser));
assertEquals(ownerAdds.getResultCode(), SUCCESS);
GroupingsServiceResult adminAdds = memberAttributeService.assignOwnership(GROUPING_0_PATH, ADMIN_USER, randomUser.getUsername());
grouping = groupingRepository.findByPath(GROUPING_0_PATH);
assertTrue(grouping.getOwners().getMembers().contains(randomUser));
assertTrue(grouping.getOwners().isMember(randomUser));
assertEquals(SUCCESS, adminAdds.getResultCode());
}
Aggregations