use of gov.ca.cwds.rest.exception.IssueDetails in project cals-api by ca-cwds.
the class RFA1aApplicantResourceTest method postDuplicateApplicantFirstNameValidationTest.
@Test
public void postDuplicateApplicantFirstNameValidationTest() throws Exception {
try {
RFA1aFormDTO form = formAHelper.createRFA1aForm();
ApplicantDTO firstApplicant = applicantHelper.postApplicant(form.getId(), getApplicantDTO());
ApplicantDTO secondApplicant = getApplicantDTO();
secondApplicant.setFirstName("differentName");
secondApplicant = applicantHelper.postApplicant(form.getId(), secondApplicant);
secondApplicant.setFirstName(firstApplicant.getFirstName());
putApplicant(form, secondApplicant);
fail();
} catch (ClientErrorException e) {
assertEquals(422, e.getResponse().getStatus());
String entity = e.getResponse().readEntity(String.class);
Map<String, Object> parameters = new HashMap<>();
BaseExceptionResponse exceptionResponse = e.getResponse().readEntity(BaseExceptionResponse.class);
Set<IssueDetails> issueDetails = exceptionResponse.getIssueDetails();
IssueDetails detail = issueDetails.iterator().next();
parameters.put("incident_id", detail.getIncidentId());
assertResponseByFixtureTemplate(entity, "fixtures/rfa/validation/applicant-duplicate-name-violation-response.json", parameters);
}
}
use of gov.ca.cwds.rest.exception.IssueDetails 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.IssueDetails 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.IssueDetails 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.IssueDetails 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();
}
Aggregations