Search in sources :

Example 11 with WithMockUhUser

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

the class TestGroupingsRestController method getGroupingTest.

@Test
@WithMockUhUser(username = "iamtst01")
public void getGroupingTest() throws Exception {
    Grouping grouping = mapGrouping(GROUPING);
    Group basis = grouping.getBasis();
    Group composite = grouping.getComposite();
    Group exclude = grouping.getExclude();
    Group include = grouping.getInclude();
    // basis
    assertTrue(basis.getUsernames().contains(tst[3]));
    assertTrue(basis.getUsernames().contains(tst[4]));
    assertTrue(basis.getUsernames().contains(tst[5]));
    assertTrue(basis.getNames().contains(tstName[3]));
    assertTrue(basis.getNames().contains(tstName[4]));
    assertTrue(basis.getNames().contains(tstName[5]));
    // composite
    assertTrue(composite.getUsernames().contains(tst[0]));
    assertTrue(composite.getUsernames().contains(tst[1]));
    assertTrue(composite.getUsernames().contains(tst[2]));
    assertTrue(composite.getUsernames().contains(tst[4]));
    assertTrue(composite.getUsernames().contains(tst[5]));
    assertTrue(composite.getNames().contains(tstName[0]));
    assertTrue(composite.getNames().contains(tstName[1]));
    assertTrue(composite.getNames().contains(tstName[2]));
    assertTrue(composite.getNames().contains(tstName[4]));
    assertTrue(composite.getNames().contains(tstName[5]));
    // exclude
    assertTrue(exclude.getUsernames().contains(tst[3]));
    assertTrue(exclude.getNames().contains(tstName[3]));
    // include
    assertTrue(include.getUsernames().contains(tst[0]));
    assertTrue(include.getUsernames().contains(tst[1]));
    assertTrue(include.getUsernames().contains(tst[2]));
    assertTrue(include.getNames().contains(tstName[0]));
    assertTrue(include.getNames().contains(tstName[1]));
    assertTrue(include.getNames().contains(tstName[2]));
    assertFalse(grouping.getOwners().getNames().contains(tstName[5]));
    mapGSR("/api/groupings/" + grouping.getPath() + "/" + tst[5] + "/assignOwnership");
    grouping = mapGrouping(GROUPING);
    assertTrue(grouping.getOwners().getNames().contains(tstName[5]));
    mapGSR("/api/groupings/" + grouping.getPath() + "/" + tst[5] + "/removeOwnership");
    grouping = mapGrouping(GROUPING);
    assertFalse(grouping.getOwners().getNames().contains(tstName[5]));
}
Also used : Group(edu.hawaii.its.api.type.Group) 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 12 with WithMockUhUser

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

the class GroupingsRestControllerTest method hasAdminPrivsTest.

@Test
@WithMockUhUser(username = "admin")
public void hasAdminPrivsTest() throws Exception {
    String uri = REST_CONTROLLER_BASE + "admins";
    given(httpRequestService.makeApiRequest(eq(ADMIN_USERNAME), anyString(), eq(HttpMethod.GET))).willReturn(new ResponseEntity(HttpStatus.OK));
    assertNotNull(mockMvc.perform(get(uri).with(csrf())).andExpect(status().isOk()).andReturn());
    verify(httpRequestService, times(1)).makeApiRequest(eq(ADMIN_USERNAME), anyString(), eq(HttpMethod.GET));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 13 with WithMockUhUser

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

the class GroupingsRestControllerTest method removeFromGroupsTest.

@Test
@WithMockUhUser(username = "admin")
public void removeFromGroupsTest() throws Exception {
    String uri = REST_CONTROLLER_BASE + GROUPING3 + "/user/removeFromGroups";
    given(httpRequestService.makeApiRequest(eq(ADMIN_USERNAME), anyString(), eq(HttpMethod.DELETE))).willReturn(new ResponseEntity(HttpStatus.OK));
    assertNotNull(mockMvc.perform(post(uri).with(csrf())).andExpect(status().isOk()).andReturn());
    verify(httpRequestService, times(1)).makeApiRequest(eq(ADMIN_USERNAME), anyString(), eq(HttpMethod.DELETE));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 14 with WithMockUhUser

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

the class GroupingsRestControllerTest method removeAdminTest.

@Test
@WithMockUhUser(username = "admin")
public void removeAdminTest() throws Exception {
    String uri = REST_CONTROLLER_BASE + "newAdmin/removeAdmin";
    given(httpRequestService.makeApiRequest(eq(ADMIN_USERNAME), anyString(), eq(HttpMethod.DELETE))).willReturn(new ResponseEntity(HttpStatus.OK));
    assertNotNull(mockMvc.perform(post(uri).with(csrf())).andExpect(status().isOk()).andReturn());
    verify(httpRequestService, times(1)).makeApiRequest(eq(ADMIN_USERNAME), anyString(), eq(HttpMethod.DELETE));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 15 with WithMockUhUser

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

the class GroupingsRestControllerTest method groupingTest.

@Test
@WithMockUhUser
public void groupingTest() throws Exception {
    String uri = REST_CONTROLLER_BASE + "groupings/" + GROUPING;
    given(httpRequestService.makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.GET))).willReturn(new ResponseEntity(HttpStatus.OK));
    assertNotNull(mockMvc.perform(get(uri).with(csrf())).andExpect(status().isOk()).andReturn());
    verify(httpRequestService, times(1)).makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.GET));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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