Search in sources :

Example 11 with GroupingsServiceResult

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

Example 12 with GroupingsServiceResult

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

the class TestMembershipService method deleteMemberAsTest.

@Test
public void deleteMemberAsTest() {
    // username[2] is in composite and include, not basis or exclude
    assertTrue(memberAttributeService.isMember(GROUPING, username[2]));
    assertTrue(memberAttributeService.isMember(GROUPING_INCLUDE, username[2]));
    assertFalse(memberAttributeService.isMember(GROUPING_BASIS, username[2]));
    assertFalse(memberAttributeService.isMember(GROUPING_EXCLUDE, username[2]));
    // username[3] is in basis and exclude, not composite or include
    assertTrue(memberAttributeService.isMember(GROUPING_BASIS, username[3]));
    assertTrue(memberAttributeService.isMember(GROUPING_EXCLUDE, username[3]));
    assertFalse(memberAttributeService.isMember(GROUPING, username[3]));
    assertFalse(memberAttributeService.isMember(GROUPING_INCLUDE, username[3]));
    // delete username[3] from exclude
    GroupingsServiceResult deleteMember1 = membershipService.deleteGroupMemberByUsername(username[0], GROUPING_EXCLUDE, username[3]);
    // deletion was successful
    assertEquals(deleteMember1.getResultCode(), SUCCESS);
    // username[3] is no longer in the exclude
    assertFalse(memberAttributeService.isMember(GROUPING_EXCLUDE, username[3]));
    // delete username[2] from include
    GroupingsServiceResult deleteMember2 = membershipService.deleteGroupMemberByUsername(username[0], GROUPING_INCLUDE, username[2]);
    // deletion was successful
    assertEquals(deleteMember2.getResultCode(), SUCCESS);
    // username[2] is no longer in composite or include
    assertFalse(memberAttributeService.isMember(GROUPING, username[2]));
    assertFalse(memberAttributeService.isMember(GROUPING_INCLUDE, username[2]));
    // test when not in group
    deleteMember1 = membershipService.deleteGroupMemberByUsername(username[0], GROUPING_EXCLUDE, username[3]);
    deleteMember2 = membershipService.deleteGroupMemberByUsername(username[0], GROUPING_INCLUDE, username[2]);
    // results are successful because the end result is the same
    assertTrue(deleteMember1.getResultCode().startsWith(SUCCESS));
    assertTrue(deleteMember2.getResultCode().startsWith(SUCCESS));
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with GroupingsServiceResult

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

the class TestMembershipService method updateLastModifiedTest.

@Test
public void updateLastModifiedTest() {
    // Test is accurate to the minute, and if checks to see if the current
    // time gets added to the lastModified attribute of a group if the
    // minute happens to change in between getting the time and setting
    // the time, the test will fail.
    final String group = GROUPING_INCLUDE;
    GroupingsServiceResult gsr = membershipService.updateLastModified(group);
    String dateStr = gsr.getAction().split(" to time ")[1];
    WsGetAttributeAssignmentsResults assignments = groupAttributeService.attributeAssignmentsResults(ASSIGN_TYPE_GROUP, group, YYYYMMDDTHHMM);
    String assignedValue = assignments.getWsAttributeAssigns()[0].getWsAttributeAssignValues()[0].getValueSystem();
    assertEquals(dateStr, assignedValue);
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) WsGetAttributeAssignmentsResults(edu.internet2.middleware.grouperClient.ws.beans.WsGetAttributeAssignmentsResults) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with GroupingsServiceResult

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

the class HelperServiceImpl method makeGroupingsServiceResult.

// makes a groupingsServiceResult with the resultCode and the action string
@Override
public GroupingsServiceResult makeGroupingsServiceResult(String resultCode, String action) {
    GroupingsServiceResult groupingsServiceResult = new GroupingsServiceResult();
    groupingsServiceResult.setAction(action);
    groupingsServiceResult.setResultCode(resultCode);
    if (groupingsServiceResult.getResultCode().startsWith(FAILURE)) {
        throw new GroupingsServiceResultException(groupingsServiceResult);
    }
    return groupingsServiceResult;
}
Also used : GroupingsServiceResultException(edu.hawaii.its.api.type.GroupingsServiceResultException) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult)

Example 15 with GroupingsServiceResult

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

the class MemberAttributeServiceImpl method removeOwnership.

// remove ownership of a grouping from a current owner
// todo change ownerUsername to "actor"?
@Override
public GroupingsServiceResult removeOwnership(String groupingPath, String ownerUsername, String ownerToRemove) {
    logger.info("removeOwnership; grouping: " + groupingPath + "; username: " + ownerUsername + "; ownerToRemove: " + ownerToRemove + ";");
    GroupingsServiceResult ownershipResults;
    String action = "remove ownership of " + groupingPath + " from " + ownerToRemove;
    if (isOwner(groupingPath, ownerUsername) || isAdmin(ownerUsername)) {
        WsSubjectLookup lookup = grouperFS.makeWsSubjectLookup(ownerUsername);
        WsDeleteMemberResults memberResults = grouperFS.makeWsDeleteMemberResults(groupingPath + OWNERS, lookup, ownerToRemove);
        ownershipResults = hs.makeGroupingsServiceResult(memberResults, action);
        return ownershipResults;
    }
    ownershipResults = hs.makeGroupingsServiceResult(FAILURE + ", " + ownerUsername + " does not own " + groupingPath, action);
    return ownershipResults;
}
Also used : WsSubjectLookup(edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) WsDeleteMemberResults(edu.internet2.middleware.grouperClient.ws.beans.WsDeleteMemberResults)

Aggregations

GroupingsServiceResult (edu.hawaii.its.api.type.GroupingsServiceResult)43 Test (org.junit.Test)32 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)32 GroupingsServiceResultException (edu.hawaii.its.api.type.GroupingsServiceResultException)15 WithMockUhUser (edu.hawaii.its.groupings.controller.WithMockUhUser)15 ArrayList (java.util.ArrayList)15 Grouping (edu.hawaii.its.api.type.Grouping)6 WsSubjectLookup (edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup)4 Person (edu.hawaii.its.api.type.Person)3 WsAddMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults)3 WsDeleteMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsDeleteMemberResults)2 WsGetAttributeAssignmentsResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetAttributeAssignmentsResults)2 Group (edu.hawaii.its.api.type.Group)1 GroupingsHTTPException (edu.hawaii.its.api.type.GroupingsHTTPException)1 Membership (edu.hawaii.its.api.type.Membership)1 WsResultMeta (edu.internet2.middleware.grouperClient.ws.beans.WsResultMeta)1 WsStemLookup (edu.internet2.middleware.grouperClient.ws.beans.WsStemLookup)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1