Search in sources :

Example 6 with ModelResponse

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);
}
Also used : EvaluationResponse(org.openscoring.common.EvaluationResponse) BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) BatchModelResponse(org.openscoring.common.BatchModelResponse) ModelResponse(org.openscoring.common.ModelResponse) SimpleResponse(org.openscoring.common.SimpleResponse) Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) URI(java.net.URI)

Example 7 with ModelResponse

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);
}
Also used : EvaluationResponse(org.openscoring.common.EvaluationResponse) BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) BatchModelResponse(org.openscoring.common.BatchModelResponse) ModelResponse(org.openscoring.common.ModelResponse) SimpleResponse(org.openscoring.common.SimpleResponse) Response(javax.ws.rs.core.Response)

Example 8 with ModelResponse

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);
}
Also used : EvaluationResponse(org.openscoring.common.EvaluationResponse) BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) BatchModelResponse(org.openscoring.common.BatchModelResponse) ModelResponse(org.openscoring.common.ModelResponse) SimpleResponse(org.openscoring.common.SimpleResponse) Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream)

Example 9 with ModelResponse

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);
}
Also used : BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) BatchEvaluationRequest(org.openscoring.common.BatchEvaluationRequest) EvaluationRequest(org.openscoring.common.EvaluationRequest) BatchModelResponse(org.openscoring.common.BatchModelResponse) BatchModelResponse(org.openscoring.common.BatchModelResponse) ModelResponse(org.openscoring.common.ModelResponse) BatchEvaluationRequest(org.openscoring.common.BatchEvaluationRequest) EvaluationResponse(org.openscoring.common.EvaluationResponse) BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

ModelResponse (org.openscoring.common.ModelResponse)9 BatchModelResponse (org.openscoring.common.BatchModelResponse)7 Response (javax.ws.rs.core.Response)4 BatchEvaluationResponse (org.openscoring.common.BatchEvaluationResponse)4 EvaluationResponse (org.openscoring.common.EvaluationResponse)4 SimpleResponse (org.openscoring.common.SimpleResponse)3 InputStream (java.io.InputStream)2 URI (java.net.URI)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 PushbackInputStream (java.io.PushbackInputStream)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 BadRequestException (javax.ws.rs.BadRequestException)1 GET (javax.ws.rs.GET)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 NotFoundException (javax.ws.rs.NotFoundException)1 Produces (javax.ws.rs.Produces)1