Search in sources :

Example 6 with ServiceErrorList

use of com.ibm.cohort.engine.api.service.model.ServiceErrorList in project quality-measure-and-cohort-service by Alvearie.

the class CohortServiceExceptionMapperTest method testToResponseFhirClientConnectionExceptionUnknownHost.

@Test
public void testToResponseFhirClientConnectionExceptionUnknownHost() throws Exception {
    Response response = exMapper.toResponse(new FhirClientConnectionException("Something bad got input").initCause(new java.net.UnknownHostException("bad host")));
    ServiceErrorList actual = (ServiceErrorList) response.getEntity();
    ServiceErrorList expected = new ServiceErrorList();
    expected.setStatusCode(500);
    expected.getErrors().add(newServiceError(500, "Something bad got input", "Reason: FhirClientConnectionException"));
    expected.getErrors().add(newServiceError(404, "bad host", null));
    expected.setErrorSource(ErrorSource.COHORT_SERVICE);
    testErrorListEquality(expected, actual);
}
Also used : Response(javax.ws.rs.core.Response) FhirClientConnectionException(ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException) ServiceErrorList(com.ibm.cohort.engine.api.service.model.ServiceErrorList) Test(org.junit.Test)

Example 7 with ServiceErrorList

use of com.ibm.cohort.engine.api.service.model.ServiceErrorList in project quality-measure-and-cohort-service by Alvearie.

the class CohortServiceExceptionMapperTest method testToResponseResourceNotFoundExceptionNotOperationOutcome.

@Test
public void testToResponseResourceNotFoundExceptionNotOperationOutcome() throws Exception {
    ResourceNotFoundException ex = new ResourceNotFoundException("Bad URL");
    ex.setResponseBody("Bad Body");
    Response response = new CohortServiceExceptionMapper().toResponse(ex);
    ServiceErrorList actual = (ServiceErrorList) response.getEntity();
    ServiceErrorList expected = new ServiceErrorList();
    expected.setStatusCode(400);
    expected.getErrors().add(newServiceError(404, "FHIR Resource Not Found: Bad URL", "Bad Body"));
    expected.setErrorSource(ErrorSource.FHIR_SERVER);
    testErrorListEquality(expected, actual);
}
Also used : Response(javax.ws.rs.core.Response) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) ServiceErrorList(com.ibm.cohort.engine.api.service.model.ServiceErrorList) Test(org.junit.Test)

Example 8 with ServiceErrorList

use of com.ibm.cohort.engine.api.service.model.ServiceErrorList in project quality-measure-and-cohort-service by Alvearie.

the class CohortServiceExceptionMapperTest method testToResponseIllegalArgumentException.

@Test
public void testToResponseIllegalArgumentException() throws Exception {
    Response response = exMapper.toResponse(new IllegalArgumentException("Something bad got input", new IllegalArgumentException("Nested exception")));
    ServiceErrorList actual = (ServiceErrorList) response.getEntity();
    ServiceErrorList expected = new ServiceErrorList();
    expected.setStatusCode(400);
    expected.getErrors().add(newServiceError(400, "Something bad got input", ""));
    expected.getErrors().add(newServiceError(400, "Nested exception", null));
    expected.setErrorSource(ErrorSource.COHORT_SERVICE);
    testErrorListEquality(expected, actual);
}
Also used : Response(javax.ws.rs.core.Response) ServiceErrorList(com.ibm.cohort.engine.api.service.model.ServiceErrorList) Test(org.junit.Test)

Example 9 with ServiceErrorList

use of com.ibm.cohort.engine.api.service.model.ServiceErrorList in project quality-measure-and-cohort-service by Alvearie.

the class CohortServiceExceptionMapperTest method testToResponseResourceNotFoundExceptionHAPIFormat.

@Test
public void testToResponseResourceNotFoundExceptionHAPIFormat() throws Exception {
    OperationOutcome outcome = new OperationOutcome();
    outcome.getText().setStatusAsString("generated");
    outcome.getIssueFirstRep().setSeverity(IssueSeverity.ERROR).setCode(OperationOutcome.IssueType.PROCESSING).setDiagnostics("Resource Patient/something is not found");
    ResourceNotFoundException ex = new ResourceNotFoundException("Error", outcome);
    ex.setResponseBody(parser.encodeResourceToString(outcome));
    Response response = new CohortServiceExceptionMapper().toResponse(ex);
    ServiceErrorList actual = (ServiceErrorList) response.getEntity();
    ServiceErrorList expected = new ServiceErrorList();
    expected.setStatusCode(400);
    expected.getErrors().add(newServiceError(404, "FHIR Resource Not Found: Error", "{\"resourceType\":\"OperationOutcome\",\"text\":{\"status\":\"generated\"},\"issue\":[{\"severity\":\"error\",\"code\":\"processing\",\"diagnostics\":\"Resource Patient/something is not found\"}]}"));
    expected.setErrorSource(ErrorSource.FHIR_SERVER);
    testErrorListEquality(expected, actual);
}
Also used : Response(javax.ws.rs.core.Response) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) ServiceErrorList(com.ibm.cohort.engine.api.service.model.ServiceErrorList) Test(org.junit.Test)

Example 10 with ServiceErrorList

use of com.ibm.cohort.engine.api.service.model.ServiceErrorList in project quality-measure-and-cohort-service by Alvearie.

the class CohortServiceExceptionMapperTest method testToResponseCqlException.

@Test
public void testToResponseCqlException() throws Exception {
    Response response = exMapper.toResponse(new CqlException("Unexpected exception caught during execution", new IllegalArgumentException("Failed to resolve ValueSet")));
    ServiceErrorList actual = (ServiceErrorList) response.getEntity();
    ServiceErrorList expected = new ServiceErrorList();
    expected.setStatusCode(400);
    expected.getErrors().add(newServiceError(400, "Unexpected exception caught during execution", ""));
    expected.getErrors().add(newServiceError(400, "Failed to resolve ValueSet", null));
    expected.setErrorSource(ErrorSource.COHORT_SERVICE);
    testErrorListEquality(expected, actual);
}
Also used : Response(javax.ws.rs.core.Response) ServiceErrorList(com.ibm.cohort.engine.api.service.model.ServiceErrorList) CqlException(org.opencds.cqf.cql.engine.exception.CqlException) Test(org.junit.Test)

Aggregations

ServiceErrorList (com.ibm.cohort.engine.api.service.model.ServiceErrorList)17 Response (javax.ws.rs.core.Response)15 Test (org.junit.Test)15 FhirClientConnectionException (ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException)7 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)4 AuthenticationException (ca.uhn.fhir.rest.server.exceptions.AuthenticationException)2 ConnectException (java.net.ConnectException)2 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)2 CqlException (org.opencds.cqf.cql.engine.exception.CqlException)2 BaseServerResponseException (ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException)1 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 MismatchedInputException (com.fasterxml.jackson.databind.exc.MismatchedInputException)1 ErrorSource (com.ibm.cohort.engine.api.service.model.ServiceErrorList.ErrorSource)1 ServiceError (com.ibm.watson.service.base.model.ServiceError)1 IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)1 IMultipartBody (com.ibm.websphere.jaxrs20.multipart.IMultipartBody)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 Status (javax.ws.rs.core.Response.Status)1