Search in sources :

Example 1 with WithMockUhUser

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

the class GroupingsRestControllerTest method getDeleteMember.

@Test
@WithMockUhUser
public void getDeleteMember() throws Exception {
    final String grouping = "grouping";
    final String username = "user";
    GroupingsServiceResult gsr = new GroupingsServiceResult("SUCCESS", "delete member from include group");
    GroupingsServiceResult gsr2 = new GroupingsServiceResult("SUCCESS", "delete member from exclude group");
    given(membershipService.deleteGroupMemberByUsername(username, grouping + ":include", username)).willReturn(gsr);
    given(membershipService.deleteGroupMemberByUsername(username, grouping + ":exclude", username)).willReturn(gsr2);
    mockMvc.perform(post("/api/groupings/grouping/user/deleteMemberFromIncludeGroup").with(csrf())).andExpect(status().isOk()).andExpect(jsonPath("resultCode").value("SUCCESS")).andExpect(jsonPath("action").value("delete member from include group"));
    mockMvc.perform(post("/api/groupings/grouping/user/deleteMemberFromExcludeGroup").with(csrf())).andExpect(status().isOk()).andExpect(jsonPath("resultCode").value("SUCCESS")).andExpect(jsonPath("action").value("delete member from exclude group"));
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 2 with WithMockUhUser

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

the class GroupingsRestControllerTest method getOptIn.

@Test
@WithMockUhUser
public void getOptIn() throws Exception {
    final String grouping = "grouping";
    final String username = "user";
    List<GroupingsServiceResult> gsr = new ArrayList<>();
    gsr.add(new GroupingsServiceResult("SUCCESS", "delete member from exclude group"));
    gsr.add(new GroupingsServiceResult("SUCCESS", "add member to include group"));
    gsr.add(new GroupingsServiceResult("SUCCESS", "add self-opted attribute to include group"));
    gsr.add(new GroupingsServiceResult("SUCCESS", "remove self-opted attribute to exclude group"));
    gsr.add(new GroupingsServiceResult("SUCCESS", "update last-modified attribute for exclude group"));
    gsr.add(new GroupingsServiceResult("SUCCESS", "update last-modified attribute for include group"));
    given(membershipService.optIn(username, grouping)).willReturn(gsr);
    mockMvc.perform(post("/api/groupings/grouping/optIn").with(csrf())).andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(6))).andExpect(jsonPath("$[0].resultCode").value("SUCCESS")).andExpect(jsonPath("$[0].action").value("delete member from exclude group")).andExpect(jsonPath("$[1].resultCode").value("SUCCESS")).andExpect(jsonPath("$[1].action").value("add member to include group")).andExpect(jsonPath("$[2].resultCode").value("SUCCESS")).andExpect(jsonPath("$[2].action").value("add self-opted attribute to include group")).andExpect(jsonPath("$[3].resultCode").value("SUCCESS")).andExpect(jsonPath("$[3].action").value("remove self-opted attribute to exclude group")).andExpect(jsonPath("$[4].resultCode").value("SUCCESS")).andExpect(jsonPath("$[4].action").value("update last-modified attribute for exclude group")).andExpect(jsonPath("$[5].resultCode").value("SUCCESS")).andExpect(jsonPath("$[5].action").value("update last-modified attribute for include group"));
}
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 3 with WithMockUhUser

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

the class GroupingsRestControllerTest method getRemoveOwnership.

@Test
@WithMockUhUser
public void getRemoveOwnership() throws Exception {
    final String grouping = "grouping";
    final String username = "user";
    GroupingsServiceResult gsr;
    gsr = new GroupingsServiceResult("SUCCESS", "remove user's ownership privilege for grouping");
    given(memberAttributeService.removeOwnership(grouping, username, username)).willReturn(gsr);
    mockMvc.perform(post("/api/groupings/grouping/user/removeOwnership").with(csrf())).andExpect(status().isOk()).andExpect(jsonPath("resultCode").value("SUCCESS")).andExpect(jsonPath("action").value("remove user's ownership privilege for grouping"));
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 4 with WithMockUhUser

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

the class GroupingsRestControllerTest method getAssignOwnership.

@Test
@WithMockUhUser
public void getAssignOwnership() throws Exception {
    final String grouping = "grouping";
    final String username = "user";
    GroupingsServiceResult gsr;
    gsr = new GroupingsServiceResult("SUCCESS", "give user ownership of grouping");
    given(memberAttributeService.assignOwnership(grouping, username, username)).willReturn(gsr);
    mockMvc.perform(post("/api/groupings/grouping/user/assignOwnership").with(csrf())).andExpect(status().isOk()).andExpect(jsonPath("resultCode").value("SUCCESS")).andExpect(jsonPath("action").value("give user ownership of grouping"));
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 5 with WithMockUhUser

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

the class GroupingsRestControllerTest method rootTest.

@Test
@WithMockUhUser
public void rootTest() throws Exception {
    MvcResult result = mockMvc.perform(get("/api/groupings/")).andExpect(status().isOk()).andReturn();
    assertEquals("University of Hawaii Groupings API", result.getResponse().getContentAsString());
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) 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