Search in sources :

Example 6 with WithMockUhUser

use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.

the class GroupingsRestControllerTest method deleteByUsernameTest.

@Test
@WithMockUhUser
public void deleteByUsernameTest() throws Exception {
    List<GroupingsServiceResult> gsrList = new ArrayList<>();
    gsrList.add(new GroupingsServiceResult("SUCCESS", "delete grouping member by username"));
    // new GroupingsServiceResult("SUCCESS", "delete grouping member by username")
    given(membershipService.deleteGroupingMemberByUsername("user", "grouping", "user")).willReturn(gsrList);
    mockMvc.perform(post("/api/groupings/grouping/user/deleteGroupingMemberByUsername").with(csrf())).andExpect(status().isOk()).andExpect(jsonPath("$[0].resultCode").value("SUCCESS")).andExpect(jsonPath("$[0].action").value("delete grouping member by username"));
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) ArrayList(java.util.ArrayList) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 7 with WithMockUhUser

use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.

the class GroupingsRestControllerTest method getMyGroupings.

@Test
@WithMockUhUser
public void getMyGroupings() throws Exception {
    ObjectMapper om = new ObjectMapper();
    final String username = "user";
    List<Grouping> groupings = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        groupings.add(grouping());
        groupings.get(i).setPath("grouping" + i);
    }
    given(groupingAssignmentService.getGroupingAssignment(username)).willReturn(myGroupings());
    String mvcResult = mockMvc.perform(get("/api/groupings/groupingAssignment")).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    GroupingAssignment mg = om.readValue(mvcResult, GroupingAssignment.class);
    Assert.assertTrue(mg.getGroupingsIn().get(0).getName().equals(groupings.get(0).getName()));
    Assert.assertTrue(mg.getGroupingsIn().get(0).getPath().equals(groupings.get(0).getPath()));
    Assert.assertTrue(mg.getGroupingsIn().get(0).getOwners().getNames().equals(groupings.get(0).getOwners().getNames()));
    Assert.assertTrue(mg.getGroupingsIn().get(0).getOwners().getUsernames().equals(groupings.get(0).getOwners().getUsernames()));
    Assert.assertTrue(mg.getGroupingsIn().get(0).getOwners().getUuids().equals(groupings.get(0).getOwners().getUuids()));
    Assert.assertTrue(mg.getGroupingsOwned().get(0).getName().equals(groupings.get(0).getName()));
    Assert.assertTrue(mg.getGroupingsOwned().get(0).getPath().equals(groupings.get(0).getPath()));
    Assert.assertTrue(mg.getGroupingsOwned().get(0).getOwners().getNames().equals(groupings.get(0).getOwners().getNames()));
    Assert.assertTrue(mg.getGroupingsOwned().get(0).getOwners().getUsernames().equals(groupings.get(0).getOwners().getUsernames()));
    Assert.assertTrue(mg.getGroupingsOwned().get(0).getOwners().getUuids().equals(groupings.get(0).getOwners().getUuids()));
    Assert.assertTrue(mg.getGroupingsToOptInTo().get(0).getName().equals(groupings.get(0).getName()));
    Assert.assertTrue(mg.getGroupingsToOptInTo().get(0).getPath().equals(groupings.get(0).getPath()));
    Assert.assertTrue(mg.getGroupingsToOptInTo().get(0).getOwners().getNames().equals(groupings.get(0).getOwners().getNames()));
    Assert.assertTrue(mg.getGroupingsToOptInTo().get(0).getOwners().getUsernames().equals(groupings.get(0).getOwners().getUsernames()));
    Assert.assertTrue(mg.getGroupingsToOptInTo().get(0).getOwners().getUuids().equals(groupings.get(0).getOwners().getUuids()));
    Assert.assertTrue(mg.getGroupingsToOptOutOf().get(0).getName().equals(groupings.get(0).getName()));
    Assert.assertTrue(mg.getGroupingsToOptOutOf().get(0).getPath().equals(groupings.get(0).getPath()));
    Assert.assertTrue(mg.getGroupingsToOptOutOf().get(0).getOwners().getNames().equals(groupings.get(0).getOwners().getNames()));
    Assert.assertTrue(mg.getGroupingsToOptOutOf().get(0).getOwners().getUsernames().equals(groupings.get(0).getOwners().getUsernames()));
    Assert.assertTrue(mg.getGroupingsToOptOutOf().get(0).getOwners().getUuids().equals(groupings.get(0).getOwners().getUuids()));
    Assert.assertTrue(mg.getGroupingsOptedInTo().get(0).getName().equals(groupings.get(0).getName()));
    Assert.assertTrue(mg.getGroupingsOptedInTo().get(0).getPath().equals(groupings.get(0).getPath()));
    Assert.assertTrue(mg.getGroupingsOptedInTo().get(0).getOwners().getNames().equals(groupings.get(0).getOwners().getNames()));
    Assert.assertTrue(mg.getGroupingsOptedInTo().get(0).getOwners().getUsernames().equals(groupings.get(0).getOwners().getUsernames()));
    Assert.assertTrue(mg.getGroupingsOptedInTo().get(0).getOwners().getUuids().equals(groupings.get(0).getOwners().getUuids()));
    Assert.assertTrue(mg.getGroupingsOptedOutOf().get(0).getName().equals(groupings.get(0).getName()));
    Assert.assertTrue(mg.getGroupingsOptedOutOf().get(0).getPath().equals(groupings.get(0).getPath()));
    Assert.assertTrue(mg.getGroupingsOptedOutOf().get(0).getOwners().getNames().equals(groupings.get(0).getOwners().getNames()));
    Assert.assertTrue(mg.getGroupingsOptedOutOf().get(0).getOwners().getUsernames().equals(groupings.get(0).getOwners().getUsernames()));
    Assert.assertTrue(mg.getGroupingsOptedOutOf().get(0).getOwners().getUuids().equals(groupings.get(0).getOwners().getUuids()));
}
Also used : ArrayList(java.util.ArrayList) Grouping(edu.hawaii.its.api.type.Grouping) GroupingAssignment(edu.hawaii.its.api.type.GroupingAssignment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 8 with WithMockUhUser

use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.

the class TestGroupingsRestController method getEmptyGroupingTest.

@Test
@WithMockUhUser(username = "iamtst01")
public void getEmptyGroupingTest() throws Exception {
    Grouping storeEmpty = mapGrouping(GROUPING_STORE_EMPTY);
    Grouping trueEmpty = mapGrouping(GROUPING_TRUE_EMPTY);
    assertTrue(storeEmpty.getBasis().getMembers().size() == 1);
    assertTrue(storeEmpty.getComposite().getMembers().size() == 0);
    assertTrue(storeEmpty.getExclude().getMembers().size() == 0);
    assertTrue(storeEmpty.getInclude().getMembers().size() == 0);
    assertTrue(storeEmpty.getOwners().getUsernames().contains(tst[0]));
    assertTrue(trueEmpty.getBasis().getMembers().size() == 0);
    assertTrue(trueEmpty.getComposite().getMembers().size() == 0);
    assertTrue(trueEmpty.getExclude().getMembers().size() == 0);
    assertTrue(trueEmpty.getInclude().getMembers().size() == 0);
    assertTrue(trueEmpty.getOwners().getUsernames().contains(tst[0]));
}
Also used : Grouping(edu.hawaii.its.api.type.Grouping) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 9 with WithMockUhUser

use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.

the class TestGroupingsRestController method groupingsAssignmentEmptyTest.

@Test
@WithMockUhUser(username = "iamtst05")
public void groupingsAssignmentEmptyTest() throws Exception {
    GroupingAssignment groupings = mapGroupingAssignment();
    assertEquals(groupings.getGroupingsIn().size(), groupings.getGroupingsToOptOutOf().size());
    for (Grouping grouping : groupings.getGroupingsIn()) {
        mapGSRs("/api/groupings/" + grouping.getPath() + "/optOut");
    }
    groupings = mapGroupingAssignment();
    assertEquals(0, groupings.getGroupingsIn().size());
    assertEquals(0, groupings.getGroupingsToOptOutOf().size());
}
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) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 10 with WithMockUhUser

use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.

the class TestGroupingsRestController method myGroupingsTest4.

@Test
@WithMockUhUser(username = "iamtst06")
public void myGroupingsTest4() throws Exception {
    boolean optedOut = false;
    GroupingAssignment tst5Groupings = mapGroupingAssignment();
    assertEquals(tst5Groupings.getGroupingsOptedOutOf().size(), 0);
    mapGSRs("/api/groupings/" + GROUPING + "/optOut");
    tst5Groupings = mapGroupingAssignment();
    for (Grouping grouping : tst5Groupings.getGroupingsOptedOutOf()) {
        if (grouping.getPath().contains(this.GROUPING)) {
            optedOut = true;
        }
    }
    assertTrue(optedOut);
    membershipService.deleteGroupMemberByUsername(tst[0], GROUPING_EXCLUDE, tst[5]);
}
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) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Aggregations

WithMockUhUser (edu.hawaii.its.groupings.controller.WithMockUhUser)69 Test (org.junit.Test)69 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)69 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)34 ResponseEntity (org.springframework.http.ResponseEntity)31 GroupingsServiceResult (edu.hawaii.its.api.type.GroupingsServiceResult)15 ArrayList (java.util.ArrayList)10 Grouping (edu.hawaii.its.api.type.Grouping)9 GroupingAssignment (edu.hawaii.its.api.type.GroupingAssignment)7 Principal (java.security.Principal)3 SimplePrincipal (org.jasig.cas.client.authentication.SimplePrincipal)3 AdminListsHolder (edu.hawaii.its.api.type.AdminListsHolder)2 Realm (edu.hawaii.its.groupings.configuration.Realm)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpRequestService (edu.hawaii.its.api.service.HttpRequestService)1 Group (edu.hawaii.its.api.type.Group)1 GroupingsHTTPException (edu.hawaii.its.api.type.GroupingsHTTPException)1 ApiServerHandshakeException (edu.hawaii.its.groupings.exceptions.ApiServerHandshakeException)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1