Search in sources :

Example 16 with BaseExceptionResponse

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

the class ExceptionHandlingResponseTest method corruptedJSONValidationTest.

@Test
public void corruptedJSONValidationTest() throws Exception {
    String fixture = "{\"wrong\": -1}";
    Response response = clientTestRule.target(API.RFA_1A_FORMS).request(MediaType.APPLICATION_JSON).post(Entity.entity(clientTestRule.getMapper().readValue(fixture, Wrong.class), MediaType.APPLICATION_JSON_TYPE));
    assertEquals(400, response.getStatus());
    String entity = response.readEntity(String.class);
    BaseExceptionResponse baseExceptionResponse = clientTestRule.getMapper().readValue(entity, BaseExceptionResponse.class);
    VelocityHelper velocityHelper = new VelocityHelper();
    IssueDetails details = baseExceptionResponse.getIssueDetails().iterator().next();
    velocityHelper.setParameter("incident_id", details.getIncidentId());
    velocityHelper.setParameter("user_message", BASE_MESSAGE);
    assertResponseByFixture(entity, velocityHelper.process("fixtures/exception/json-error-response.json"));
}
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) VelocityHelper(gov.ca.cwds.cals.web.rest.utils.VelocityHelper) BaseRFAIntegrationTest(gov.ca.cwds.cals.web.rest.rfa.BaseRFAIntegrationTest) Test(org.junit.Test)

Example 17 with BaseExceptionResponse

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

the class ExceptionHandlingResponseTest method expectedExceptionTest.

@Test
public void expectedExceptionTest() throws Exception {
    WebTarget target = clientTestRule.target(FACILITIES + "/" + FACILITY_ID + "/" + Constants.API.COMPLAINTS + "/" + WRONG_FACILITY_ID);
    Invocation.Builder invocation = target.request(MediaType.APPLICATION_JSON);
    Response response = invocation.get();
    assertEquals(404, response.getStatus());
    String entity = response.readEntity(String.class);
    BaseExceptionResponse baseExceptionResponse = clientTestRule.getMapper().readValue(entity, BaseExceptionResponse.class);
    VelocityHelper velocityHelper = new VelocityHelper();
    IssueDetails details = baseExceptionResponse.getIssueDetails().iterator().next();
    velocityHelper.setParameter("incident_id", details.getIncidentId());
    velocityHelper.setParameter("user_message", BASE_MESSAGE);
    velocityHelper.setParameter("technical_message", Constants.ExpectedExceptionMessages.COMPLAINT_NOT_FOUND_BY_ID);
    assertResponseByFixture(entity, velocityHelper.process("fixtures/exception/expected-exception.json"));
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) Response(javax.ws.rs.core.Response) BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) Invocation(javax.ws.rs.client.Invocation) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) WebTarget(javax.ws.rs.client.WebTarget) VelocityHelper(gov.ca.cwds.cals.web.rest.utils.VelocityHelper) BaseRFAIntegrationTest(gov.ca.cwds.cals.web.rest.rfa.BaseRFAIntegrationTest) Test(org.junit.Test)

Example 18 with BaseExceptionResponse

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

the class RFA1aApplicantResourceTest method testDuplicatePhoneNumbers.

@Test
public void testDuplicatePhoneNumbers() throws Exception {
    RFA1aFormDTO form = formAHelper.createRFA1aForm();
    ApplicantDTO applicant = getApplicantDTO();
    applicant.getPhones().clear();
    applicant.getPhones().add(createPhoneNoExtension());
    applicant.getPhones().add(createPhoneNoExtension());
    try {
        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-duplicate-phone-numbers-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 19 with BaseExceptionResponse

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

the class RFA1aApplicantResourceTest method testEmptyFirstNameValidation.

@Test
public void testEmptyFirstNameValidation() throws Exception {
    RFA1aFormDTO form = formAHelper.createRFA1aForm();
    ApplicantDTO applicant = getApplicantDTO();
    applicant.setFirstName(" ");
    applicant.setLastName("setLastName");
    try {
        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-empty-first-name-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 20 with BaseExceptionResponse

use of gov.ca.cwds.rest.exception.BaseExceptionResponse 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)

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