use of edu.hawaii.its.api.type.GroupingsServiceResultException 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.GroupingsServiceResultException 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());
}
use of edu.hawaii.its.api.type.GroupingsServiceResultException in project uhgroupings by uhawaii-system-its-ti-iam.
the class MembershipServiceTest method deleteGroupingMemberByUuidTest.
// Debug statement to look at contents of database
// Delete user from include group to remove them
// Use user number not slot in array
// Use assert to check if it worked
@Test
public void deleteGroupingMemberByUuidTest() {
Iterable<Grouping> group = groupingRepository.findAll();
List<GroupingsServiceResult> listGsr;
GroupingsServiceResult gsr;
// Base test
// Remove person from include and composite
listGsr = membershipService.deleteGroupingMemberByUuid(users.get(0).getUsername(), GROUPING_3_PATH, users.get(5).getUuid());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
// If person is in composite and basis, add to exclude group
listGsr = membershipService.deleteGroupingMemberByUuid(users.get(0).getUsername(), GROUPING_3_PATH, users.get(1).getUuid());
for (GroupingsServiceResult gsrFor : listGsr) {
assertTrue(gsrFor.getResultCode().startsWith(SUCCESS));
}
// Not in composite, do nothing but return success
listGsr = membershipService.deleteGroupingMemberByUuid(users.get(0).getUsername(), GROUPING_3_PATH, users.get(2).getUuid());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
// Test if user is not an owner
try {
listGsr = membershipService.deleteGroupingMemberByUuid(users.get(5).getUsername(), GROUPING_3_PATH, users.get(6).getUuid());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
} catch (GroupingsServiceResultException gsre) {
gsr = gsre.getGsr();
}
// Test if user is admin
listGsr = membershipService.deleteGroupingMemberByUuid(ADMIN_USER, GROUPING_3_PATH, users.get(6).getUuid());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
}
use of edu.hawaii.its.api.type.GroupingsServiceResultException in project uhgroupings by uhawaii-system-its-ti-iam.
the class MembershipServiceTest method deleteGroupingMemberbyUsernameTest.
@Test
public void deleteGroupingMemberbyUsernameTest() {
Iterable<Grouping> group = groupingRepository.findAll();
List<GroupingsServiceResult> listGsr;
GroupingsServiceResult gsr;
// Base test
// Remove person from include and composite
listGsr = membershipService.deleteGroupingMemberByUsername(users.get(0).getUsername(), GROUPING_3_PATH, users.get(5).getUsername());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
// If person is in composite and basis, add to exclude group
listGsr = membershipService.deleteGroupingMemberByUsername(users.get(0).getUsername(), GROUPING_3_PATH, users.get(1).getUsername());
for (GroupingsServiceResult gsrFor : listGsr) {
assertTrue(gsrFor.getResultCode().startsWith(SUCCESS));
}
// Not in composite, do nothing but return success
listGsr = membershipService.deleteGroupingMemberByUuid(users.get(0).getUsername(), GROUPING_3_PATH, users.get(2).getUsername());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
// Test if user is not an owner
try {
listGsr = membershipService.deleteGroupingMemberByUuid(users.get(5).getUsername(), GROUPING_3_PATH, users.get(6).getUuid());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
} catch (GroupingsServiceResultException gsre) {
gsr = gsre.getGsr();
}
// Test if user is admin
listGsr = membershipService.deleteGroupingMemberByUuid(ADMIN_USER, GROUPING_3_PATH, users.get(6).getUuid());
assertTrue(listGsr.get(0).getResultCode().startsWith(SUCCESS));
}
use of edu.hawaii.its.api.type.GroupingsServiceResultException in project uhgroupings by uhawaii-system-its-ti-iam.
the class TestMemberAttributeService method assignRemoveOwnershipTest.
@Test
public void assignRemoveOwnershipTest() {
// expect to fail
GroupingsServiceResult assignOwnershipFail;
GroupingsServiceResult removeOwnershipFail;
assertTrue(memberAttributeService.isOwner(GROUPING, username[0]));
assertFalse(memberAttributeService.isOwner(GROUPING, username[1]));
assertFalse(memberAttributeService.isOwner(GROUPING, username[2]));
try {
assignOwnershipFail = memberAttributeService.assignOwnership(GROUPING, username[1], username[1]);
} catch (GroupingsServiceResultException gsre) {
assignOwnershipFail = gsre.getGsr();
}
assertFalse(memberAttributeService.isOwner(GROUPING, username[1]));
assertTrue(assignOwnershipFail.getResultCode().startsWith(FAILURE));
GroupingsServiceResult assignOwnershipSuccess = memberAttributeService.assignOwnership(GROUPING, username[0], username[1]);
assertTrue(memberAttributeService.isOwner(GROUPING, username[1]));
assertTrue(assignOwnershipSuccess.getResultCode().startsWith(SUCCESS));
try {
removeOwnershipFail = memberAttributeService.removeOwnership(GROUPING, username[2], username[1]);
} catch (GroupingsServiceResultException gsre) {
removeOwnershipFail = gsre.getGsr();
}
assertTrue(memberAttributeService.isOwner(GROUPING, username[1]));
assertTrue(removeOwnershipFail.getResultCode().startsWith(FAILURE));
GroupingsServiceResult removeOwnershipSuccess = memberAttributeService.removeOwnership(GROUPING, username[0], username[1]);
assertFalse(memberAttributeService.isOwner(GROUPING, username[1]));
assertTrue(removeOwnershipSuccess.getResultCode().startsWith(SUCCESS));
// have an owner remove itself
assignOwnershipSuccess = memberAttributeService.assignOwnership(GROUPING, username[0], username[1]);
assertTrue(memberAttributeService.isOwner(GROUPING, username[1]));
removeOwnershipSuccess = memberAttributeService.removeOwnership(GROUPING, username[1], username[1]);
assertFalse(memberAttributeService.isOwner(GROUPING, username[1]));
}
Aggregations