Search in sources :

Example 11 with Grouping

use of edu.hawaii.its.api.type.Grouping 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));
}
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 12 with Grouping

use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.

the class MembershipServiceTest method addMemberByUsernameTest.

@Test
public void addMemberByUsernameTest() {
    Grouping grouping = groupingRepository.findByPath(GROUPING_1_PATH);
    assertFalse(grouping.getComposite().getMembers().contains(users.get(3)));
    membershipService.addGroupMemberByUsername(users.get(0).getUsername(), GROUPING_1_INCLUDE_PATH, users.get(3).getUsername());
    grouping = groupingRepository.findByPath(GROUPING_1_PATH);
    assertTrue(grouping.getComposite().getMembers().contains(users.get(3)));
// todo Cases (inBasis && inInclude) and (!inComposite && !inBasis) not reachable w/ current DB
}
Also used : Grouping(edu.hawaii.its.api.type.Grouping) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with Grouping

use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.

the class MembershipServiceTest method addMembersByUsername.

@Test
public void addMembersByUsername() {
    // add all usernames
    List<String> usernames = new ArrayList<>();
    for (Person user : users) {
        usernames.add(user.getUsername());
    }
    Grouping grouping = groupingRepository.findByPath(GROUPING_3_PATH);
    // check how many members are in the basis
    int numberOfBasisMembers = grouping.getBasis().getMembers().size();
    // try to put all users into exclude group
    membershipService.addGroupMembersByUsername(users.get(0).getUsername(), GROUPING_3_EXCLUDE_PATH, usernames);
    grouping = groupingRepository.findByPath(GROUPING_3_PATH);
    // there should be no real members in composite, but it should still have the 'grouperAll' member
    assertEquals(1, grouping.getComposite().getMembers().size());
    // only the users in the basis should have been added to the exclude group
    assertEquals(numberOfBasisMembers, grouping.getExclude().getMembers().size());
    // try to put all users into the include group
    membershipService.addGroupMembersByUsername(users.get(0).getUsername(), GROUPING_3_INCLUDE_PATH, usernames);
    grouping = groupingRepository.findByPath(GROUPING_3_PATH);
    // all members should be in the group ( - 1 for 'grouperAll' in composite);
    assertEquals(usernames.size(), grouping.getComposite().getMembers().size() - 1);
    // members in basis should not have been added to the include group ( + 2 for 'grouperAll' in both groups)
    assertEquals(usernames.size() - numberOfBasisMembers + 2, grouping.getInclude().getMembers().size());
}
Also used : ArrayList(java.util.ArrayList) 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)

Example 14 with Grouping

use of edu.hawaii.its.api.type.Grouping 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));
}
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 15 with Grouping

use of edu.hawaii.its.api.type.Grouping in project uhgroupings by uhawaii-system-its-ti-iam.

the class TestGroupingAssignmentService method groupingsOwnedTest.

@Test
public void groupingsOwnedTest() {
    GroupingAssignment groupingAssignment = groupingAssignmentService.getGroupingAssignment(username[0]);
    boolean ownsGrouping = false;
    for (Grouping grouping : groupingAssignment.getGroupingsOwned()) {
        if (grouping.getPath().contains(GROUPING)) {
            ownsGrouping = true;
            break;
        }
    }
    assertTrue(ownsGrouping);
    ownsGrouping = false;
    groupingAssignment = groupingAssignmentService.getGroupingAssignment(username[4]);
    for (Grouping grouping : groupingAssignment.getGroupingsOwned()) {
        if (grouping.getPath().contains(GROUPING)) {
            ownsGrouping = true;
            break;
        }
    }
    assertFalse(ownsGrouping);
}
Also used : Grouping(edu.hawaii.its.api.type.Grouping) GroupingAssignment(edu.hawaii.its.api.type.GroupingAssignment) 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