Search in sources :

Example 1 with GroupingsHTTPException

use of edu.hawaii.its.api.type.GroupingsHTTPException in project uhgroupings by uhawaii-system-its-ti-iam.

the class TestGroupingsRestController method addDeleteAdminTest.

@Test
@WithMockUhUser(username = "iamtst01")
public void addDeleteAdminTest() throws Exception {
    GroupingsServiceResult addAdminResults;
    GroupingsServiceResult deleteAdminResults;
    try {
        // addAdminResults = gc.addAdmin(tst[0], tst[0]).getBody();
        addAdminResults = mapGSR("/api/groupings/" + tst[0] + "/addAdmin");
    } catch (GroupingsHTTPException ghe) {
        addAdminResults = new GroupingsServiceResult();
        addAdminResults.setResultCode(FAILURE);
    }
    try {
        // deleteAdminResults = gc.deleteAdmin(tst[0], tst[0]).getBody();
        deleteAdminResults = mapGSR("/api/groupings/" + tst[0] + "/deleteAdmin");
    } catch (GroupingsHTTPException ghe) {
        deleteAdminResults = new GroupingsServiceResult();
        deleteAdminResults.setResultCode(FAILURE);
    }
    assertTrue(addAdminResults.getResultCode().startsWith(FAILURE));
    assertTrue(deleteAdminResults.getResultCode().startsWith(FAILURE));
}
Also used : GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) GroupingsHTTPException(edu.hawaii.its.api.type.GroupingsHTTPException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 2 with GroupingsHTTPException

use of edu.hawaii.its.api.type.GroupingsHTTPException in project uhgroupings by uhawaii-system-its-ti-iam.

the class TestGroupingsRestController method mapGSR.

private GroupingsServiceResult mapGSR(String uri) throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    MvcResult result = mockMvc.perform(post(uri).with(csrf())).andReturn();
    if (result.getResponse().getStatus() == 200) {
        return objectMapper.readValue(result.getResponse().getContentAsByteArray(), GroupingsServiceResult.class);
    } else {
        throw new GroupingsHTTPException();
    }
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GroupingsHTTPException(edu.hawaii.its.api.type.GroupingsHTTPException)

Example 3 with GroupingsHTTPException

use of edu.hawaii.its.api.type.GroupingsHTTPException in project uhgroupings by uhawaii-system-its-ti-iam.

the class ErrorControllerAdvice method exceptionResponse.

private ResponseEntity<GroupingsHTTPException> exceptionResponse(String message, Throwable cause, int status) {
    String username = null;
    User user = userContextService.getCurrentUser();
    if (user != null) {
        username = user.getUsername();
    }
    GroupingsHTTPException httpException = new GroupingsHTTPException(message, cause, status);
    logger.error("username: " + username + "; Exception: ", httpException.getCause());
    return ResponseEntity.status(status).body(httpException);
}
Also used : User(edu.hawaii.its.groupings.access.User) GroupingsHTTPException(edu.hawaii.its.api.type.GroupingsHTTPException)

Aggregations

GroupingsHTTPException (edu.hawaii.its.api.type.GroupingsHTTPException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GroupingsServiceResult (edu.hawaii.its.api.type.GroupingsServiceResult)1 User (edu.hawaii.its.groupings.access.User)1 WithMockUhUser (edu.hawaii.its.groupings.controller.WithMockUhUser)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1