Search in sources :

Example 1 with VelocityHelper

use of gov.ca.cwds.cals.web.rest.utils.VelocityHelper 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 2 with VelocityHelper

use of gov.ca.cwds.cals.web.rest.utils.VelocityHelper 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 3 with VelocityHelper

use of gov.ca.cwds.cals.web.rest.utils.VelocityHelper in project cals-api by ca-cwds.

the class RFA1aApplicantResourceTest method checkValidationResponse.

private void checkValidationResponse(ClientErrorException e, Map<String, Object> parameters) throws IOException, JSONException {
    assertEquals(422, e.getResponse().getStatus());
    String entity = e.getResponse().readEntity(String.class);
    VelocityHelper velocityHelper = new VelocityHelper();
    velocityHelper.setParameters(parameters);
    assertResponseByFixture(entity, velocityHelper.process("fixtures/rfa/validation/validation-error-response.json"));
}
Also used : VelocityHelper(gov.ca.cwds.cals.web.rest.utils.VelocityHelper)

Example 4 with VelocityHelper

use of gov.ca.cwds.cals.web.rest.utils.VelocityHelper 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 5 with VelocityHelper

use of gov.ca.cwds.cals.web.rest.utils.VelocityHelper in project cals-api by ca-cwds.

the class DBUnitAssertHelper method processTemplate.

private void processTemplate() {
    VelocityHelper velocityHelper = new VelocityHelper();
    velocityHelper.setParameters(templateParams);
    try {
        expectedDataSet = getReplacementDataSet(velocityHelper.process(templatePath));
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : VelocityHelper(gov.ca.cwds.cals.web.rest.utils.VelocityHelper) URISyntaxException(java.net.URISyntaxException) DatabaseUnitException(org.dbunit.DatabaseUnitException) DataSetException(org.dbunit.dataset.DataSetException)

Aggregations

VelocityHelper (gov.ca.cwds.cals.web.rest.utils.VelocityHelper)5 BaseExceptionResponse (gov.ca.cwds.rest.exception.BaseExceptionResponse)3 IssueDetails (gov.ca.cwds.rest.exception.IssueDetails)3 BaseRFAIntegrationTest (gov.ca.cwds.cals.web.rest.rfa.BaseRFAIntegrationTest)2 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 URISyntaxException (java.net.URISyntaxException)1 Invocation (javax.ws.rs.client.Invocation)1 WebTarget (javax.ws.rs.client.WebTarget)1 DatabaseUnitException (org.dbunit.DatabaseUnitException)1 DataSetException (org.dbunit.dataset.DataSetException)1