Search in sources :

Example 1 with ClientResourceWrapper

use of net.idea.restnet.c.task.ClientResourceWrapper in project ambit-mirror by ideaconsult.

the class StaXRDFTest method simpleTestRDFXML.

@Test
public void simpleTestRDFXML() throws Exception {
    // testGet(getTestURI(),MediaType.APPLICATION_RDF_XML);
    ClientResourceWrapper r = new ClientResourceWrapper(getTestURI());
    Representation rep = r.get(MediaType.APPLICATION_RDF_XML);
    Assert.assertEquals(Status.SUCCESS_OK, r.getStatus());
    Assert.assertTrue(rep.isAvailable());
    System.out.println(rep.getText());
    rep.release();
    r.release();
}
Also used : ClientResourceWrapper(net.idea.restnet.c.task.ClientResourceWrapper) Representation(org.restlet.representation.Representation) Test(org.junit.Test) ResourceTest(ambit2.rest.test.ResourceTest)

Example 2 with ClientResourceWrapper

use of net.idea.restnet.c.task.ClientResourceWrapper in project ambit-mirror by ideaconsult.

the class AlgorithmResourceTest method testLocalRegression.

@Test
public void testLocalRegression() throws Exception {
    Form features = new Form();
    for (int i = 1; i < 3; i++) features.add(OpenTox.params.feature_uris.toString(), String.format("http://localhost:%d/feature/%d", port, i));
    Form headers = new Form();
    Reference dataset = new Reference(String.format("http://localhost:%d/dataset/1", port));
    dataset.setQuery(features.getQueryString());
    headers.add(OpenTox.params.dataset_uri.toString(), dataset.toString());
    headers.add(OpenTox.params.target.toString(), String.format("http://localhost:%d/feature/2", port));
    testAsyncTask(String.format("http://localhost:%d/algorithm/LR", port), // Reference.encode(String.format("http://localhost:%d/dataset/1",port))),
    headers, Status.SUCCESS_OK, String.format("http://localhost:%d/model/%s", port, "3"));
    headers = new Form();
    headers.add(OpenTox.params.dataset_uri.toString(), dataset.toString());
    testAsyncTask(String.format("http://localhost:%d/model/3", port), // Reference.encode(String.format("http://localhost:%d/dataset/1",port))),
    headers, Status.SUCCESS_OK, "http://localhost:8181/dataset/1?feature_uris%5B%5D=http%3A%2F%2Flocalhost%3A8181%2Ffeature%2F1&feature_uris%5B%5D=http%3A%2F%2Flocalhost%3A8181%2Ffeature%2F2&feature_uris=http%3A%2F%2Flocalhost%3A8181%2Fmodel%2F3%2Fpredicted");
    IDatabaseConnection c = getConnection();
    ITable table = c.createQueryTable("EXPECTED", "SELECT * from properties where name='Property 2'");
    Assert.assertEquals(2, table.getRowCount());
    ClientResourceWrapper client = new ClientResourceWrapper(new Reference(String.format("http://localhost:%d/model/3", port)));
    Representation r = client.get(MediaType.TEXT_PLAIN);
    logger.info(r.getText());
    r.release();
    client.release();
    Assert.fail("second run, try if predictions already exists");
    testAsyncTask(String.format("http://localhost:%d/model/3", port), headers, Status.SUCCESS_OK, "http://localhost:8181/dataset/1?feature_uris%5B%5D=http%3A%2F%2Flocalhost%3A8181%2Ffeature%2F1&feature_uris%5B%5D=http%3A%2F%2Flocalhost%3A8181%2Ffeature%2F2&feature_uris=http%3A%2F%2Flocalhost%3A8181%2Fmodel%2F3%2Fpredicted");
    table = c.createQueryTable("EXPECTED", "SELECT name,idstructure,idchemical FROM values_all join structure using(idstructure) where name='Property 2'");
    Assert.assertEquals(7, table.getRowCount());
}
Also used : ClientResourceWrapper(net.idea.restnet.c.task.ClientResourceWrapper) Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) ITable(org.dbunit.dataset.ITable) Representation(org.restlet.representation.Representation) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test) ResourceTest(ambit2.rest.test.ResourceTest)

Example 3 with ClientResourceWrapper

use of net.idea.restnet.c.task.ClientResourceWrapper in project ambit-mirror by ideaconsult.

the class ResourceTest method testGetJavaObject.

public void testGetJavaObject(String uri, MediaType media, Status expectedStatus) throws Exception {
    ClientResourceWrapper resource = new ClientResourceWrapper(uri);
    resource.setMethod(Method.GET);
    resource.get(media);
    Assert.assertEquals(expectedStatus, resource.getStatus());
    if (resource.getStatus().isSuccess()) {
        verifyResponseJavaObject(uri, media, resource.getResponseEntity());
    }
}
Also used : ClientResourceWrapper(net.idea.restnet.c.task.ClientResourceWrapper)

Example 4 with ClientResourceWrapper

use of net.idea.restnet.c.task.ClientResourceWrapper in project ambit-mirror by ideaconsult.

the class ResourceTest method testGetRepresentation.

public void testGetRepresentation(String uri, MediaType media) throws Exception {
    ClientResourceWrapper client = new ClientResourceWrapper(uri);
    Assert.assertTrue(verifyRepresentation(uri, media, client.get(media)));
}
Also used : ClientResourceWrapper(net.idea.restnet.c.task.ClientResourceWrapper)

Example 5 with ClientResourceWrapper

use of net.idea.restnet.c.task.ClientResourceWrapper in project ambit-mirror by ideaconsult.

the class OTModel method report.

public String report(String ontologyURI) throws Exception {
    String a = String.format("<%s>", getUri());
    String query = String.format(OTModel.getSparql("sparql/ModelReport.sparql").toString(), "", a, a);
    OTOntologyService<String> ontology = new OTOntologyService<String>(ontologyURI);
    StringBuilder b = new StringBuilder().append(ontology.report(query));
    ClientResourceWrapper client = new ClientResourceWrapper(getUri());
    Representation r = null;
    try {
        r = client.get(MediaType.TEXT_PLAIN);
        b.append(r.getText().replace("\n", "<br>"));
    } catch (Exception x) {
    } finally {
        try {
            r.release();
        } catch (Exception x) {
        }
        try {
            client.release();
        } catch (Exception x) {
        }
    }
    return b.toString();
}
Also used : ClientResourceWrapper(net.idea.restnet.c.task.ClientResourceWrapper) Representation(org.restlet.representation.Representation) ResourceException(org.restlet.resource.ResourceException)

Aggregations

ClientResourceWrapper (net.idea.restnet.c.task.ClientResourceWrapper)18 Representation (org.restlet.representation.Representation)16 ResourceException (org.restlet.resource.ResourceException)13 Reference (org.restlet.data.Reference)6 Form (org.restlet.data.Form)5 StringRepresentation (org.restlet.representation.StringRepresentation)4 IOException (java.io.IOException)3 ResourceTest (ambit2.rest.test.ResourceTest)2 Test (org.junit.Test)2 IStructureDiagramHighlights (ambit2.core.data.IStructureDiagramHighlights)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 StringWriter (java.io.StringWriter)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)1 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)1 ITable (org.dbunit.dataset.ITable)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1 IteratingSDFReader (org.openscience.cdk.io.iterator.IteratingSDFReader)1 FileRepresentation (org.restlet.representation.FileRepresentation)1