Search in sources :

Example 6 with Grouping

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);
    }
}
Also used : Group(edu.hawaii.its.api.type.Group) Membership(edu.hawaii.its.api.type.Membership) Grouping(edu.hawaii.its.api.type.Grouping) Person(edu.hawaii.its.api.type.Person)

Example 7 with Grouping

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));
}
Also used : GroupingsServiceResultException(edu.hawaii.its.api.type.GroupingsServiceResultException) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Grouping(edu.hawaii.its.api.type.Grouping) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with Grouping

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());
}
Also used : WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) Group(edu.hawaii.its.api.type.Group) ArrayList(java.util.ArrayList) Grouping(edu.hawaii.its.api.type.Grouping) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with Grouping

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));
    }
}
Also used : WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) Group(edu.hawaii.its.api.type.Group) ArrayList(java.util.ArrayList) Grouping(edu.hawaii.its.api.type.Grouping) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with Grouping

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());
}
Also used : GroupingsServiceResultException(edu.hawaii.its.api.type.GroupingsServiceResultException) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Grouping(edu.hawaii.its.api.type.Grouping) Person(edu.hawaii.its.api.type.Person) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Grouping (edu.hawaii.its.api.type.Grouping)45 Test (org.junit.Test)28 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)28 ArrayList (java.util.ArrayList)14 Group (edu.hawaii.its.api.type.Group)13 GroupingAssignment (edu.hawaii.its.api.type.GroupingAssignment)11 WsGroup (edu.internet2.middleware.grouperClient.ws.beans.WsGroup)11 WithMockUhUser (edu.hawaii.its.groupings.controller.WithMockUhUser)9 Person (edu.hawaii.its.api.type.Person)8 GroupingsServiceResult (edu.hawaii.its.api.type.GroupingsServiceResult)6 GroupingsServiceResultException (edu.hawaii.its.api.type.GroupingsServiceResultException)6 WsAttributeAssign (edu.internet2.middleware.grouperClient.ws.beans.WsAttributeAssign)5 WsResultMeta (edu.internet2.middleware.grouperClient.ws.beans.WsResultMeta)5 WsAssignAttributesResults (edu.internet2.middleware.grouperClient.ws.beans.WsAssignAttributesResults)3 WsGetAttributeAssignmentsResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetAttributeAssignmentsResults)3 AdminListsHolder (edu.hawaii.its.api.type.AdminListsHolder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Membership (edu.hawaii.its.api.type.Membership)1 StemScope (edu.internet2.middleware.grouperClient.ws.StemScope)1 WsAddMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults)1