Search in sources :

Example 6 with GroupingsServiceResultException

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

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

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

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

use of edu.hawaii.its.api.type.GroupingsServiceResultException 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)

Aggregations

GroupingsServiceResultException (edu.hawaii.its.api.type.GroupingsServiceResultException)16 GroupingsServiceResult (edu.hawaii.its.api.type.GroupingsServiceResult)15 Test (org.junit.Test)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 Grouping (edu.hawaii.its.api.type.Grouping)6 Group (edu.hawaii.its.api.type.Group)1 Membership (edu.hawaii.its.api.type.Membership)1 Person (edu.hawaii.its.api.type.Person)1