use of gov.ca.cwds.rest.exception.BaseExceptionResponse in project cals-api by ca-cwds.
the class ExceptionHandlingResponseTest method technicalValidationTest.
@Test
public void technicalValidationTest() throws Exception {
String fixture = "{\"application_county\": {\"id\": -1, \"value\": \"Unknown\"}}";
Response response = clientTestRule.target(API.RFA_1A_FORMS).request(MediaType.APPLICATION_JSON).post(Entity.entity(clientTestRule.getMapper().readValue(fixture, RFA1aFormDTO.class), MediaType.APPLICATION_JSON_TYPE));
assertEquals(422, response.getStatus());
String entity = response.readEntity(String.class);
Map<String, Object> parameters = new HashMap<>();
BaseExceptionResponse exceptionResponse = clientTestRule.getMapper().readValue(entity, BaseExceptionResponse.class);
Set<IssueDetails> issueDetails = exceptionResponse.getIssueDetails();
IssueDetails detail = issueDetails.iterator().next();
parameters.put("incident_id", detail.getIncidentId());
assertResponseByFixtureTemplate(entity, "fixtures/exception/technical-validation-exception.json", parameters);
}
use of gov.ca.cwds.rest.exception.BaseExceptionResponse in project cals-api by ca-cwds.
the class ExceptionHandlingResponseTest method businessValidationTest.
@Test
public void businessValidationTest() throws Exception {
RFA1aFormDTO form = formAHelper.createRFA1aForm();
applicantHelper.postApplicant(form.getId(), getApplicantDTO());
WebTarget target = clientTestRule.target(API.RFA_1A_FORMS + "/" + form.getId() + "/" + API.RFA_1A_APPLICANTS);
Response response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(getApplicantDTO(), MediaType.APPLICATION_JSON_TYPE));
assertEquals(422, response.getStatus());
String entity = response.readEntity(String.class);
Map<String, Object> parameters = new HashMap<>();
BaseExceptionResponse exceptionResponse = clientTestRule.getMapper().readValue(entity, BaseExceptionResponse.class);
Set<IssueDetails> issueDetails = exceptionResponse.getIssueDetails();
IssueDetails detail = issueDetails.iterator().next();
parameters.put("incident_id", detail.getIncidentId());
assertResponseByFixtureTemplate(entity, "fixtures/exception/business-validation-exception.json", parameters);
}
use of gov.ca.cwds.rest.exception.BaseExceptionResponse in project cals-api by ca-cwds.
the class ExceptionHandlingResponseTest method unExpectedExceptionTest.
@Test
public void unExpectedExceptionTest() throws Exception {
if (TestModeUtils.isIntegrationTestsMode()) {
return;
}
WebTarget target = clientTestRule.target(Constants.API.FACILITIES + "/" + FACILITY_ID);
Response response = target.request(MediaType.APPLICATION_JSON).get();
assertEquals(500, response.getStatus());
BaseExceptionResponse unexpectedErrorResponse = response.readEntity(BaseExceptionResponse.class);
IssueDetails details = unexpectedErrorResponse.getIssueDetails().iterator().next();
assertNotNull(details.getStackTrace());
assertEquals(UNEXPECTED_EXCEPTION, details.getType());
assertNotNull(details.getIncidentId());
assertEquals(IssueDetails.BASE_MESSAGE, details.getUserMessage());
}
use of gov.ca.cwds.rest.exception.BaseExceptionResponse in project api-core by ca-cwds.
the class BusinessValidationExceptionMapper method toResponse.
@Override
public Response toResponse(BusinessValidationException exception) {
Set<IssueDetails> detailsList = exception.getValidationDetailsList();
for (IssueDetails details : detailsList) {
if (details.getType() == null) {
details.setType(IssueType.BUSINESS_VALIDATION);
}
}
BaseExceptionResponse manualValidationResponse = new BaseExceptionResponse();
manualValidationResponse.setIssueDetails(detailsList);
return Response.status(422).type(MediaType.APPLICATION_JSON).entity(manualValidationResponse).build();
}
use of gov.ca.cwds.rest.exception.BaseExceptionResponse in project api-core by ca-cwds.
the class ValidationExceptionMapperImpl method toResponse.
@Override
public Response toResponse(ConstraintViolationException exception) {
Set<IssueDetails> validationDetailsList = IssueDetailsCreator.create(exception, loggingContext.getUniqueId());
BaseExceptionResponse constraintViolationsResponse = new BaseExceptionResponse();
constraintViolationsResponse.setIssueDetails(validationDetailsList);
return Response.status(422).type(MediaType.APPLICATION_JSON_TYPE).entity(constraintViolationsResponse).build();
}
Aggregations