use of org.openscoring.common.ModelResponse in project openscoring by openscoring.
the class ModelResourceTest method deployForm.
private ModelResponse deployForm(String id) throws IOException {
Response response;
try (InputStream is = openPMML(id)) {
FormDataMultiPart formData = new FormDataMultiPart();
formData.field("id", id);
formData.bodyPart(new FormDataBodyPart("pmml", is, MediaType.APPLICATION_XML_TYPE));
Entity<FormDataMultiPart> entity = Entity.entity(formData, MediaType.MULTIPART_FORM_DATA);
response = target("model").request(MediaType.APPLICATION_JSON).post(entity);
formData.close();
}
assertEquals(201, response.getStatus());
assertNotNull(response.getHeaderString(Headers.SERVICE));
URI location = response.getLocation();
assertEquals("/model/" + id, location.getPath());
return response.readEntity(ModelResponse.class);
}
use of org.openscoring.common.ModelResponse in project openscoring by openscoring.
the class ModelResourceTest method query.
private ModelResponse query(String id) {
Response response = target("model/" + id).request(MediaType.APPLICATION_JSON).get();
assertEquals(200, response.getStatus());
return response.readEntity(ModelResponse.class);
}
use of org.openscoring.common.ModelResponse in project openscoring by openscoring.
the class ModelResourceTest method deploy.
private ModelResponse deploy(String id) throws IOException {
Response response;
try (InputStream is = openPMML(id)) {
Entity<InputStream> entity = Entity.entity(is, MediaType.APPLICATION_XML);
response = target("model/" + id).request(MediaType.APPLICATION_JSON).put(entity);
}
assertEquals(201, response.getStatus());
assertNotNull(response.getHeaderString(Headers.SERVICE));
return response.readEntity(ModelResponse.class);
}
use of org.openscoring.common.ModelResponse in project openscoring by openscoring.
the class ModelResourceTest method decisionTreeIris.
@Test
public void decisionTreeIris() throws Exception {
String id = "DecisionTreeIris";
assertEquals("Iris", extractSuffix(id));
BatchModelResponse batchModelResponse = queryBatch();
List<ModelResponse> modelResponses = batchModelResponse.getResponses();
assertNull(modelResponses);
deploy(id);
batchModelResponse = queryBatch();
modelResponses = batchModelResponse.getResponses();
assertEquals(1, modelResponses.size());
download(id);
List<EvaluationRequest> evaluationRequests = loadRecords(id);
EvaluationRequest evaluationRequest = evaluationRequests.get(0);
EvaluationResponse evaluationResponse = evaluate(id, evaluationRequest);
assertEquals(evaluationRequest.getId(), evaluationResponse.getId());
EvaluationRequest invalidEvaluationRequest = invalidate(evaluationRequests.get(50));
evaluationRequests = Arrays.asList(evaluationRequests.get(0), invalidEvaluationRequest, evaluationRequests.get(100));
BatchEvaluationRequest batchEvaluationRequest = new BatchEvaluationRequest();
batchEvaluationRequest.setRequests(evaluationRequests);
BatchEvaluationResponse batchEvaluationResponse = evaluateBatch(id, batchEvaluationRequest);
assertEquals(batchEvaluationRequest.getId(), batchEvaluationResponse.getId());
List<EvaluationResponse> evaluationResponses = batchEvaluationResponse.getResponses();
assertEquals(evaluationRequests.size(), evaluationResponses.size());
EvaluationResponse invalidEvaluationResponse = evaluationResponses.get(1);
assertEquals(invalidEvaluationRequest.getId(), invalidEvaluationResponse.getId());
assertNotNull(invalidEvaluationResponse.getMessage());
undeploy(id);
}
Aggregations