Search in sources :

Example 31 with GroupingsServiceResult

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

the class MemberAttributeServiceTest method removeOwnershipTest.

@Test
public void removeOwnershipTest() {
    GroupingsServiceResult randomUserRemoves;
    try {
        // non-owner/non-admin tries to remove ownership
        randomUserRemoves = memberAttributeService.removeOwnership(GROUPING_0_PATH, users.get(1).getUsername(), users.get(1).getUsername());
    } catch (GroupingsServiceResultException gsre) {
        randomUserRemoves = gsre.getGsr();
    }
    assertTrue(randomUserRemoves.getResultCode().startsWith(FAILURE));
    // add owner for owner to remove
    membershipService.addGroupMemberByUsername(users.get(0).getUsername(), GROUPING_0_OWNERS_PATH, users.get(1).getUsername());
    // owner tries to remove other ownership
    GroupingsServiceResult ownerRemoves = memberAttributeService.removeOwnership(GROUPING_0_PATH, users.get(0).getUsername(), users.get(1).getUsername());
    assertEquals(SUCCESS, ownerRemoves.getResultCode());
    // try to remove ownership from user that is not an owner
    GroupingsServiceResult ownerRemovesNonOwner = memberAttributeService.removeOwnership(GROUPING_0_PATH, users.get(0).getUsername(), users.get(1).getUsername());
    assertEquals(SUCCESS, ownerRemovesNonOwner.getResultCode());
    // add owner for admin to remove
    membershipService.addGroupMemberByUsername(users.get(0).getUsername(), GROUPING_0_OWNERS_PATH, users.get(1).getUsername());
    // admin tries to remove ownership
    GroupingsServiceResult adminRemoves = memberAttributeService.removeOwnership(GROUPING_0_PATH, ADMIN_USER, users.get(1).getUsername());
    assertEquals(adminRemoves.getResultCode(), SUCCESS);
}
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 32 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult 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 33 with GroupingsServiceResult

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

the class MembershipServiceTest method removeSelfOptedTest.

@Test
public void removeSelfOptedTest() {
    Group group = groupRepository.findByPath(GROUPING_4_EXCLUDE_PATH);
    GroupingsServiceResult gsr;
    try {
        // member is not in group
        gsr = membershipService.removeSelfOpted(GROUPING_4_EXCLUDE_PATH, users.get(5).getUsername());
    } catch (GroupingsServiceResultException gsre) {
        gsr = gsre.getGsr();
    }
    assertTrue(gsr.getResultCode().startsWith(FAILURE));
    // member is not self-opted
    gsr = membershipService.removeSelfOpted(GROUPING_4_EXCLUDE_PATH, users.get(4).getUsername());
    assertTrue(gsr.getResultCode().startsWith(SUCCESS));
    // make member self-opted
    Membership membership = membershipRepository.findByPersonAndGroup(users.get(4), group);
    membership.setSelfOpted(true);
    membershipRepository.save(membership);
    // member is self-opted
    gsr = membershipService.removeSelfOpted(GROUPING_4_EXCLUDE_PATH, users.get(4).getUsername());
    assertTrue(gsr.getResultCode().startsWith(SUCCESS));
}
Also used : Group(edu.hawaii.its.api.type.Group) GroupingsServiceResultException(edu.hawaii.its.api.type.GroupingsServiceResultException) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Membership(edu.hawaii.its.api.type.Membership) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 34 with GroupingsServiceResult

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

the class MembershipServiceTest method addGroupingMemberbyUuidTest.

@Test
public void addGroupingMemberbyUuidTest() {
    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.addGroupingMemberByUuid(users.get(0).getUsername(), GROUPING_3_PATH, users.get(3).getUuid());
    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).getUuid());
    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).getUuid());
        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 GroupingsServiceResult

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

the class MembershipServiceTest method addAdminTest.

@Test
public void addAdminTest() {
    GroupingsServiceResult gsr;
    try {
        // user is not super user
        gsr = membershipService.addAdmin(users.get(9).getUsername(), users.get(9).getUsername());
    } catch (GroupingsServiceResultException gsre) {
        gsr = gsre.getGsr();
    }
    assertTrue(gsr.getResultCode().startsWith(FAILURE));
    // user is super user
    gsr = membershipService.addAdmin(ADMIN_USER, users.get(9).getUsername());
    assertEquals(SUCCESS, gsr.getResultCode());
    // users.get(9) is already and admin
    gsr = membershipService.addAdmin(ADMIN_USER, users.get(9).getUsername());
    assertTrue(gsr.getResultCode().startsWith(SUCCESS));
}
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)

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