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));
}
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();
}
}
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);
}
Aggregations