use of com.ibm.websphere.jaxrs20.multipart.IMultipartBody in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method getFhirConfigFileBody.
private IMultipartBody getFhirConfigFileBody() throws Exception {
// Create the metadata part of the request
ObjectMapper om = new ObjectMapper();
String json = om.writeValueAsString(getFhirServerConfig());
ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
IAttachment rootPart = mockAttachment(jsonIs);
// Assemble them together into a reasonable facsimile of the real request
IMultipartBody body = mock(IMultipartBody.class);
when(body.getAttachment(CohortEngineRestHandler.FHIR_DATA_SERVER_CONFIG_PART)).thenReturn(rootPart);
return body;
}
use of com.ibm.websphere.jaxrs20.multipart.IMultipartBody in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testLoadValueSets.
@PrepareForTest({ Response.class, ValueSetUtil.class })
@Test
public void testLoadValueSets() throws Exception {
prepMocks();
mockResponseClasses();
PowerMockito.mockStatic(ValueSetUtil.class);
PowerMockito.whenNew(DefaultFhirClientBuilder.class).withArguments(Mockito.any()).thenReturn(mockDefaultFhirClientBuilder);
PowerMockito.when(ValueSetUtil.importArtifact(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.eq(false))).thenReturn("ID");
File tempFile = new File(VALUE_SET_INPUT);
IAttachment spreadsheetPart = PowerMockito.mock(IAttachment.class);
DataHandler dataHandler = PowerMockito.mock(DataHandler.class);
when(spreadsheetPart.getDataHandler()).thenReturn(dataHandler);
when(dataHandler.getInputStream()).thenReturn(new ByteArrayInputStream(Files.readAllBytes(Paths.get(tempFile.getAbsolutePath()))));
IMultipartBody body = getFhirConfigFileBody();
when(body.getAttachment(CohortEngineRestHandler.VALUE_SET_PART)).thenReturn(spreadsheetPart);
Response loadResponse = restHandler.createValueSet(VERSION, body, false);
assertNotNull(loadResponse);
PowerMockito.verifyStatic(Response.class);
Response.status(Status.CREATED);
}
use of com.ibm.websphere.jaxrs20.multipart.IMultipartBody in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testEvaluatePatientListMeasure_null_measure_part.
@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluatePatientListMeasure_null_measure_part() {
prepMocks();
PowerMockito.mockStatic(ServiceBaseUtility.class);
PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_PATIENT_LIST_MEASURE.getName())).thenReturn(null);
mockResponseClasses();
IMultipartBody body = mock(IMultipartBody.class);
when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(mock(IAttachment.class));
when(body.getAttachment(CohortEngineRestHandler.MEASURE_PART)).thenReturn(null);
restHandler.evaluatePatientListMeasure(mockRequestContext, VERSION, body);
PowerMockito.verifyStatic(Response.class);
Response.status(400);
}
use of com.ibm.websphere.jaxrs20.multipart.IMultipartBody in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testCohortBadVersion.
@PrepareForTest({ Response.class, FHIRRestUtils.class })
@Test
public void testCohortBadVersion() throws Exception {
prepMocks();
mockResponseClasses();
// Assemble them together into a reasonable facsimile of the real request
IMultipartBody body = getFhirConfigFileBody();
Response loadResponse = restHandler.evaluateCohort(mockRequestContext, "bad-version", body);
assertNotNull(loadResponse);
PowerMockito.verifyStatic(Response.class);
Response.status(400);
PowerMockito.verifyStatic(ServiceBaseUtility.class);
ServiceBaseUtility.apiSetup(Mockito.anyString(), Mockito.any(), Mockito.anyString());
// verifyStatic must be called before each verification
PowerMockito.verifyStatic(ServiceBaseUtility.class);
ServiceBaseUtility.apiCleanup(Mockito.any(), Mockito.eq(MethodNames.EVALUATE_COHORT.getName()));
}
use of com.ibm.websphere.jaxrs20.multipart.IMultipartBody in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandlerTest method testEvaluateMeasureSuccess.
/**
* Test the successful building of a response.
*/
@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluateMeasureSuccess() throws Exception {
prepMocks();
PowerMockito.mockStatic(ServiceBaseUtility.class);
PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_MEASURE.getName())).thenReturn(null);
mockResponseClasses();
Library library = TestHelper.getTemplateLibrary();
Measure measure = TestHelper.getTemplateMeasure(library);
Patient patient = getPatient("patientId", AdministrativeGender.MALE, 40);
mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
mockFhirResourceRetrieval(patient);
FhirServerConfig clientConfig = getFhirServerConfig();
Map<String, Parameter> parameterOverrides = new HashMap<>();
parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
MeasureContext measureContext = new MeasureContext(measure.getId(), parameterOverrides);
MeasureEvaluation evaluationRequest = new MeasureEvaluation();
evaluationRequest.setDataServerConfig(clientConfig);
evaluationRequest.setPatientId(patient.getId());
evaluationRequest.setMeasureContext(measureContext);
// evaluationRequest.setEvidenceOptions(evidenceOptions);
evaluationRequest.setExpandValueSets(true);
evaluationRequest.setSearchPageSize(500);
FhirContext fhirContext = FhirContext.forR4();
IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
// Create the metadata part of the request
ObjectMapper om = new ObjectMapper();
String json = om.writeValueAsString(evaluationRequest);
ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
IAttachment rootPart = mockAttachment(jsonIs);
// Create the ZIP part of the request
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TestHelper.createMeasureArtifact(baos, parser, measure, library);
ByteArrayInputStream zipIs = new ByteArrayInputStream(baos.toByteArray());
IAttachment measurePart = mockAttachment(zipIs);
// Assemble them together into a reasonable facsimile of the real request
IMultipartBody body = mock(IMultipartBody.class);
when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(rootPart);
when(body.getAttachment(CohortEngineRestHandler.MEASURE_PART)).thenReturn(measurePart);
Response loadResponse = restHandler.evaluateMeasure(mockRequestContext, VERSION, body);
assertEquals(mockResponse, loadResponse);
PowerMockito.verifyStatic(Response.class);
Response.status(Response.Status.OK);
}
Aggregations