Search in sources :

Example 21 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class PropertiesByDatasetResourceTest method testRDFXML_Dataset.

@Test
public void testRDFXML_Dataset() throws Exception {
    String dataset = String.format("http://localhost:%d%s/2?%s=%d", port, OpenTox.URI.dataset.getURI(), AbstractResource.max_hits, 1);
    RDFPropertyIterator iterator = new RDFPropertyIterator(new Reference(dataset), "test");
    iterator.setBaseReference(new Reference(String.format("http://localhost:%d", port)));
    int count = 0;
    while (iterator.hasNext()) {
        Property p = iterator.next();
        System.out.println(p);
        Assert.assertEquals("CAS", p.getName());
        Assert.assertEquals(3, p.getId());
        count++;
    }
    iterator.close();
    Assert.assertEquals(1, count);
}
Also used : RDFPropertyIterator(ambit2.rest.rdf.RDFPropertyIterator) Reference(org.restlet.data.Reference) Property(ambit2.base.data.Property) Test(org.junit.Test) ResourceTest(ambit2.rest.test.ResourceTest)

Example 22 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class PropertyResourceTest method testCreateEntry.

/**
 * <pre>
 * <rdf:RDF
 *     xmlns:j.0="http://purl.org/net/nknouf/ns/bibtex#"
 *     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 *     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
 *     xmlns:ot="http://www.opentox.org/api/1.1#"
 *     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
 *     xmlns:owl="http://www.w3.org/2002/07/owl#"
 *     xmlns:dc="http://purl.org/dc/elements/1.1/" >
 *   <rdf:Description rdf:about="http://www.opentox.org/api/1.1#units">
 *     <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
 *   </rdf:Description>
 *   <rdf:Description rdf:about="http://purl.org/net/nknouf/ns/bibtex#Entry">
 *     <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
 *   </rdf:Description>
 *   <rdf:Description rdf:about="http://www.opentox.org/api/1.1#hasSource">
 *     <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
 *   </rdf:Description>
 *   <rdf:Description rdf:nodeID="A0">
 *     <rdfs:seeAlso>bbb</rdfs:seeAlso>
 *     <dc:title>aaa</dc:title>
 *     <rdf:type rdf:resource="http://purl.org/net/nknouf/ns/bibtex#Entry"/>
 *   </rdf:Description>
 *   <rdf:Description rdf:about="http://www.opentox.org/api/1.1#Feature">
 *     <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
 *   </rdf:Description>
 *   <rdf:Description rdf:nodeID="A1">
 *     <dc:type>http://www.w3.org/2001/XMLSchema#string</dc:type>
 *     <ot:hasSource rdf:nodeID="A0"/>
 *     <owl:sameAs>CasRN</owl:sameAs>
 *     <ot:units></ot:units>
 *     <dc:title>cas</dc:title>
 *     <rdf:type rdf:resource="http://www.opentox.org/api/1.1#Feature"/>
 *   </rdf:Description>
 * </rdf:RDF>
 * </pre>
 *
 * @throws Exception
 */
@Test
public void testCreateEntry() throws Exception {
    OntModel model = OT.createModel();
    Property p = new Property("cas", new LiteratureEntry("aaa", "bbb"));
    p.setNominal(true);
    PropertyRDFReporter.addToModel(model, p, new PropertyURIReporter(new Reference(String.format("http://localhost:%d%s", port, PropertyResource.featuredef))), new ReferenceURIReporter());
    StringWriter writer = new StringWriter();
    model.write(writer, "RDF/XML");
    System.out.println(writer.toString());
    Response response = testPost(String.format("http://localhost:%d%s", port, PropertyResource.featuredef), MediaType.APPLICATION_RDF_XML, writer.toString());
    Assert.assertEquals(Status.SUCCESS_OK, response.getStatus());
    // Assert.assertEquals("http://localhost:8181/feature/4",
    // response.getLocationRef().toString());
    IDatabaseConnection c = getConnection();
    ITable table = c.createQueryTable("EXPECTED", String.format("SELECT * FROM properties join catalog_references using(idreference) where name='cas' and comments='%s' and title='aaa' and url='bbb' and isLocal=1", Property.opentox_CAS));
    Assert.assertEquals(1, table.getRowCount());
    c.close();
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) ReferenceURIReporter(ambit2.rest.reference.ReferenceURIReporter) LiteratureEntry(ambit2.base.data.LiteratureEntry) Reference(org.restlet.data.Reference) OntModel(com.hp.hpl.jena.ontology.OntModel) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Property(ambit2.base.data.Property) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter) Test(org.junit.Test) ResourceTest(ambit2.rest.test.ResourceTest)

Example 23 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class PropertyResourceTest method testUpdateExistingEntry.

@Test
public void testUpdateExistingEntry() throws Exception {
    // now we can only update by PUT, not POST
    Property p = new Property("Property 1", new LiteratureEntry("Dummy", "NA"));
    p.setLabel("Test");
    p.setNominal(true);
    OntModel model = OT.createModel();
    PropertyRDFReporter.addToModel(model, p, new PropertyURIReporter(new Reference(String.format("http://localhost:%d%s", port, PropertyResource.featuredef))), new ReferenceURIReporter());
    StringWriter writer = new StringWriter();
    model.write(writer, "RDF/XML");
    Response response = testPut(String.format("http://localhost:%d%s/1", port, PropertyResource.featuredef), MediaType.TEXT_URI_LIST, new StringRepresentation(writer.toString(), MediaType.APPLICATION_RDF_XML));
    Assert.assertEquals(Status.SUCCESS_OK, response.getStatus());
    IDatabaseConnection c = getConnection();
    ITable table = c.createQueryTable("EXPECTED", String.format("SELECT isLocal FROM properties join catalog_references using(idreference) where name='Property 1' and comments='%s' and title='Dummy' and url='NA'", "http://www.opentox.org/api/1.1#Test"));
    Assert.assertEquals(1, table.getRowCount());
    Assert.assertEquals(true, table.getValue(0, "isLocal"));
    c.close();
    Assert.assertEquals("http://localhost:8181/feature/1", response.getLocationRef().toString());
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) ReferenceURIReporter(ambit2.rest.reference.ReferenceURIReporter) StringRepresentation(org.restlet.representation.StringRepresentation) LiteratureEntry(ambit2.base.data.LiteratureEntry) Reference(org.restlet.data.Reference) OntModel(com.hp.hpl.jena.ontology.OntModel) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Property(ambit2.base.data.Property) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter) Test(org.junit.Test) ResourceTest(ambit2.rest.test.ResourceTest)

Example 24 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class PropertyResourceTest method testUpdateExistingEntry1.

// this fails because of mysql foreign key constraints
public void testUpdateExistingEntry1() throws Exception {
    Property p = new Property("Property 1", new LiteratureEntry("Dummy 1", "NA"));
    p.setLabel("Test");
    p.setId(1);
    OntModel model = OT.createModel();
    PropertyRDFReporter.addToModel(model, p, new PropertyURIReporter(new Reference(String.format("http://localhost:%d%s", port))), new ReferenceURIReporter());
    StringWriter writer = new StringWriter();
    model.write(writer, "RDF/XML");
    Response response = testPost(String.format("http://localhost:%d%s/2", port, PropertyResource.featuredef), MediaType.APPLICATION_RDF_XML, writer.toString());
    Assert.assertEquals(Status.SUCCESS_OK, response.getStatus());
    IDatabaseConnection c = getConnection();
    ITable table = c.createQueryTable("EXPECTED", String.format("SELECT * FROM properties join catalog_references using(idreference) where name='Property 1' and comments='%s' and title='Dummy' and url='NA'", "http://www.opentox.org/api/1.1#Test"));
    Assert.assertEquals(1, table.getRowCount());
    c.close();
    Assert.assertEquals("http://localhost:8181/feature/2", response.getLocationRef().toString());
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) ReferenceURIReporter(ambit2.rest.reference.ReferenceURIReporter) LiteratureEntry(ambit2.base.data.LiteratureEntry) Reference(org.restlet.data.Reference) OntModel(com.hp.hpl.jena.ontology.OntModel) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Property(ambit2.base.data.Property) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter)

Example 25 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class PropertyResourceTest method testRDFXMLForeignURI.

@Test
public void testRDFXMLForeignURI() throws Exception {
    try {
        RDFPropertyIterator iterator = new RDFPropertyIterator(new Reference("http://google.com"), "test");
        iterator.setBaseReference(new Reference(String.format("http://localhost:%d", port)));
        while (iterator.hasNext()) {
            Property p = iterator.next();
            Assert.assertTrue(false);
        }
        iterator.close();
        Assert.assertTrue(false);
    } catch (Exception x) {
        Assert.assertTrue(true);
    }
}
Also used : RDFPropertyIterator(ambit2.rest.rdf.RDFPropertyIterator) Reference(org.restlet.data.Reference) Property(ambit2.base.data.Property) Test(org.junit.Test) ResourceTest(ambit2.rest.test.ResourceTest)

Aggregations

Property (ambit2.base.data.Property)247 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)113 Test (org.junit.Test)69 IStructureRecord (ambit2.base.interfaces.IStructureRecord)56 ResourceException (org.restlet.resource.ResourceException)46 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)44 ITable (org.dbunit.dataset.ITable)44 Reference (org.restlet.data.Reference)37 LiteratureEntry (ambit2.base.data.LiteratureEntry)36 IOException (java.io.IOException)30 ArrayList (java.util.ArrayList)30 SQLException (java.sql.SQLException)28 InputStream (java.io.InputStream)27 StructureRecord (ambit2.base.data.StructureRecord)26 Form (org.restlet.data.Form)25 DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)24 ResourceTest (ambit2.rest.test.ResourceTest)22 PropertyAnnotation (ambit2.base.data.PropertyAnnotation)19 SourceDataset (ambit2.base.data.SourceDataset)16 Template (ambit2.base.data.Template)16