Search in sources :

Example 26 with IssueDetails

use of gov.ca.cwds.rest.exception.IssueDetails in project cals-api by ca-cwds.

the class RFA1aApplicantResourceTest method postDuplicateApplicantMiddleNameValidationTest.

@Test
public void postDuplicateApplicantMiddleNameValidationTest() throws Exception {
    try {
        RFA1aFormDTO form = formAHelper.createRFA1aForm();
        ApplicantDTO firstApplicant = applicantHelper.postApplicant(form.getId(), getApplicantDTO());
        ApplicantDTO secondApplicant = getApplicantDTO();
        secondApplicant.setMiddleName("differentName");
        secondApplicant = applicantHelper.postApplicant(form.getId(), secondApplicant);
        secondApplicant.setMiddleName(firstApplicant.getMiddleName());
        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 27 with IssueDetails

use of gov.ca.cwds.rest.exception.IssueDetails in project cals-api by ca-cwds.

the class RFA1aApplicantResourceTest method postDuplicateApplicantLastNameValidationTest.

@Test
public void postDuplicateApplicantLastNameValidationTest() throws Exception {
    try {
        RFA1aFormDTO form = formAHelper.createRFA1aForm();
        ApplicantDTO firstApplicant = applicantHelper.postApplicant(form.getId(), getApplicantDTO());
        ApplicantDTO secondApplicant = getApplicantDTO();
        secondApplicant.setLastName("differentName");
        secondApplicant = applicantHelper.postApplicant(form.getId(), secondApplicant);
        secondApplicant.setLastName(firstApplicant.getLastName());
        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 28 with IssueDetails

use of gov.ca.cwds.rest.exception.IssueDetails in project cals-api by ca-cwds.

the class RFA1aApplicantResourceTest method moreThenOnePreferredNumberInApplicantValidationTest.

@Test
public void moreThenOnePreferredNumberInApplicantValidationTest() throws Exception {
    RFA1aFormDTO form = formAHelper.createRFA1aForm();
    ApplicantDTO applicant = getApplicantDTO();
    applicant.getPhones().forEach(p -> p.setPreferred(true));
    try {
        applicant = applicantHelper.postApplicant(form.getId(), applicant);
        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-more-then-one-preferred-number-response.json", parameters);
    }
    // Update test
    applicant.getPhones().forEach(p -> p.setPreferred(false));
    applicant = applicantHelper.postApplicant(form.getId(), applicant);
    try {
        applicant.getPhones().forEach(p -> p.setPreferred(true));
        putApplicant(form, applicant);
        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-more-then-one-preferred-number-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 29 with IssueDetails

use of gov.ca.cwds.rest.exception.IssueDetails in project cals-api by ca-cwds.

the class BaseInternalEntityApiHelper method checkExpectedExceptionResponse.

private void checkExpectedExceptionResponse(Response response) throws IOException, JSONException {
    BaseExceptionResponse expectedExceptionResponse = response.readEntity(BaseExceptionResponse.class);
    VelocityHelper velocityHelper = new VelocityHelper();
    IssueDetails details = expectedExceptionResponse.getIssueDetails().iterator().next();
    velocityHelper.setParameter("incident_id", details.getIncidentId());
    velocityHelper.setParameter("user_message", BASE_MESSAGE);
    velocityHelper.setParameter("technical_message", Constants.ExpectedExceptionMessages.RFA_1A_APPLICATION_NOT_FOUND_BY_ID);
    assertResponseByFixture(clientTestRule.getMapper().writeValueAsString(expectedExceptionResponse), velocityHelper.process("fixtures/rfa/rfa-1a-application-not-found.json"));
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) VelocityHelper(gov.ca.cwds.cals.web.rest.utils.VelocityHelper)

Example 30 with IssueDetails

use of gov.ca.cwds.rest.exception.IssueDetails in project cals-api by ca-cwds.

the class RFA1aFormService method performSubmissionValidation.

private void performSubmissionValidation(RFA1aFormDTO formDTO) throws DroolsException {
    Validator validator = environment.getValidator();
    Optional.ofNullable(validator.validate(formDTO)).ifPresent(violations -> {
        if (!violations.isEmpty()) {
            throw new ConstraintViolationException(violations);
        }
    });
    Set<IssueDetails> detailsList = droolsService.performBusinessRules(createConfiguration(), formDTO);
    if (!detailsList.isEmpty()) {
        throw new BusinessValidationException(detailsList);
    }
}
Also used : BusinessValidationException(gov.ca.cwds.rest.exception.BusinessValidationException) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) ConstraintViolationException(javax.validation.ConstraintViolationException) Validator(javax.validation.Validator)

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