Search in sources :

Example 31 with Grouping

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

Example 32 with Grouping

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()));
    }
}
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 33 with Grouping

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());
}
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 34 with Grouping

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));
}
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 35 with Grouping

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