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);
}
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();
}
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());
}
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());
}
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);
}
}
Aggregations