Search in sources :

Example 66 with WithMockUhUser

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

the class GroupingsRestControllerTest method numberOfGroupingsTest.

@Test
@WithMockUhUser
public void numberOfGroupingsTest() throws Exception {
    String uri = REST_CONTROLLER_BASE + "owners/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)

Example 67 with WithMockUhUser

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

the class UserBuilderTest method testAdminUser.

@Test
@WithMockUhUser
public void testAdminUser() {
    Map<String, String> map = new HashMap<>();
    Principal principal = new SimplePrincipal(userContextService.getCurrentUhUuid());
    map.put("uid", userContextService.getCurrentUser().getUid());
    map.put("uhUuid", userContextService.getCurrentUhUuid());
    given(groupingsRestController.hasOwnerPrivs(principal)).willReturn(new ResponseEntity<>("true", HttpStatus.OK));
    given(groupingsRestController.hasAdminPrivs(principal)).willReturn(new ResponseEntity<>("true", HttpStatus.OK));
    User user = userBuilder.make(map);
    // Check results.
    assertEquals(4, user.getAuthorities().size());
    assertTrue(user.hasRole(Role.ANONYMOUS));
    assertTrue(user.hasRole(Role.UH));
    assertTrue(user.hasRole(Role.ADMIN));
    assertTrue(user.hasRole(Role.OWNER));
}
Also used : WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser) HashMap(java.util.HashMap) SimplePrincipal(org.jasig.cas.client.authentication.SimplePrincipal) Principal(java.security.Principal) SimplePrincipal(org.jasig.cas.client.authentication.SimplePrincipal) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 68 with WithMockUhUser

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

the class GroupingsRestControllerTest method addMembersToIncludeGroupTest.

@Test
@WithMockUhUser
public void addMembersToIncludeGroupTest() throws Exception {
    String uri = REST_CONTROLLER_BASE + GROUPING + "/" + USERNAME + "/addMembersToIncludeGroup";
    given(httpRequestService.makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.PUT))).willReturn(new ResponseEntity(HttpStatus.OK));
    assertNotNull(mockMvc.perform(post(uri).with(csrf())).andExpect(status().isOk()).andReturn());
    verify(httpRequestService, times(1)).makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.PUT));
}
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 69 with WithMockUhUser

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

the class GroupingsRestControllerTest method hasOwnerPrivsTest.

@Test
@WithMockUhUser
public void hasOwnerPrivsTest() throws Exception {
    String uri = REST_CONTROLLER_BASE + "owners";
    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