Search in sources :

Example 11 with BaseExceptionResponse

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);
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) Response(javax.ws.rs.core.Response) BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) HashMap(java.util.HashMap) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) BaseRFAIntegrationTest(gov.ca.cwds.cals.web.rest.rfa.BaseRFAIntegrationTest) Test(org.junit.Test)

Example 12 with BaseExceptionResponse

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);
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) Response(javax.ws.rs.core.Response) BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) HashMap(java.util.HashMap) RFA1aFormDTO(gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) WebTarget(javax.ws.rs.client.WebTarget) BaseRFAIntegrationTest(gov.ca.cwds.cals.web.rest.rfa.BaseRFAIntegrationTest) Test(org.junit.Test)

Example 13 with BaseExceptionResponse

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());
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) Response(javax.ws.rs.core.Response) BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) WebTarget(javax.ws.rs.client.WebTarget) BaseRFAIntegrationTest(gov.ca.cwds.cals.web.rest.rfa.BaseRFAIntegrationTest) Test(org.junit.Test)

Example 14 with BaseExceptionResponse

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();
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails)

Example 15 with BaseExceptionResponse

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();
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails)

Aggregations

BaseExceptionResponse (gov.ca.cwds.rest.exception.BaseExceptionResponse)23 IssueDetails (gov.ca.cwds.rest.exception.IssueDetails)22 Test (org.junit.Test)16 HashMap (java.util.HashMap)12 RFA1aFormDTO (gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO)11 ApplicantDTO (gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO)10 Map (java.util.Map)10 Set (java.util.Set)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 Response (javax.ws.rs.core.Response)6 BaseRFAIntegrationTest (gov.ca.cwds.cals.web.rest.rfa.BaseRFAIntegrationTest)5 HashSet (java.util.HashSet)4 VelocityHelper (gov.ca.cwds.cals.web.rest.utils.VelocityHelper)3 WebTarget (javax.ws.rs.client.WebTarget)3 ErrorMessage (io.dropwizard.jersey.errors.ErrorMessage)1 ConstraintViolation (javax.validation.ConstraintViolation)1 Invocation (javax.ws.rs.client.Invocation)1