Search in sources :

Example 11 with IssueDetails

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);
    }
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) Set(java.util.Set) RFA1aFormDTO(gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) ClientErrorException(javax.ws.rs.ClientErrorException) ApplicantDTO(gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 12 with IssueDetails

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);
}
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 13 with IssueDetails

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);
}
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 14 with IssueDetails

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());
}
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 15 with IssueDetails

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

Aggregations

IssueDetails (gov.ca.cwds.rest.exception.IssueDetails)30 BaseExceptionResponse (gov.ca.cwds.rest.exception.BaseExceptionResponse)22 Test (org.junit.Test)19 RFA1aFormDTO (gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO)15 ApplicantDTO (gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO)14 HashMap (java.util.HashMap)12 Set (java.util.Set)11 Map (java.util.Map)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 Response (javax.ws.rs.core.Response)10 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)4 REQUIRED_APPLICANT_DATE_OF_BIRTH (gov.ca.cwds.cals.Constants.Validation.Business.Code.REQUIRED_APPLICANT_DATE_OF_BIRTH)4 REQUIRED_APPLICANT_DRIVER_LICENSE_NUMBER (gov.ca.cwds.cals.Constants.Validation.Business.Code.REQUIRED_APPLICANT_DRIVER_LICENSE_NUMBER)4 REQUIRED_APPLICANT_DRIVER_LICENSE_STATE (gov.ca.cwds.cals.Constants.Validation.Business.Code.REQUIRED_APPLICANT_DRIVER_LICENSE_STATE)4 REQUIRED_APPLICANT_OTHER_NAMES_FIRST_NAME (gov.ca.cwds.cals.Constants.Validation.Business.Code.REQUIRED_APPLICANT_OTHER_NAMES_FIRST_NAME)4 REQUIRED_APPLICANT_OTHER_NAMES_LAST_NAME (gov.ca.cwds.cals.Constants.Validation.Business.Code.REQUIRED_APPLICANT_OTHER_NAMES_LAST_NAME)4 REQUIRED_APPLICANT_PHONE_NUMBER (gov.ca.cwds.cals.Constants.Validation.Business.Code.REQUIRED_APPLICANT_PHONE_NUMBER)4 REQUIRED_BODY_OF_WATER_EXIST_FIELD (gov.ca.cwds.cals.Constants.Validation.Business.Code.REQUIRED_BODY_OF_WATER_EXIST_FIELD)4 REQUIRED_HOME_LANGUAGES (gov.ca.cwds.cals.Constants.Validation.Business.Code.REQUIRED_HOME_LANGUAGES)4 REQUIRED_MINOR_CHILD_ADOPTED (gov.ca.cwds.cals.Constants.Validation.Business.Code.REQUIRED_MINOR_CHILD_ADOPTED)4