Repository: incubator-commonsrdf Updated Branches: refs/heads/jena-jsonld-rdf4j-integration 97e3acd94 -> 2b51794e8
AllToAllTest Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/1828c2ab Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/1828c2ab Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/1828c2ab Branch: refs/heads/jena-jsonld-rdf4j-integration Commit: 1828c2abf584958bf25de48d0827c825fd3bb21a Parents: 97e3acd Author: Stian Soiland-Reyes <st...@apache.org> Authored: Fri Sep 9 17:36:32 2016 +0100 Committer: Stian Soiland-Reyes <st...@apache.org> Committed: Fri Sep 9 17:36:41 2016 +0100 ---------------------------------------------------------------------- .../rdf/integrationtests/AllToAllTest.java | 99 ++++++++++++++++++++ .../rdf/integrationtests/JenaRDF4JTest.java | 78 --------------- 2 files changed, 99 insertions(+), 78 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/1828c2ab/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java ---------------------------------------------------------------------- diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java new file mode 100644 index 0000000..a8cd1cd --- /dev/null +++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java @@ -0,0 +1,99 @@ +package org.apache.commons.rdf.integrationtests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.apache.commons.rdf.api.BlankNode; +import org.apache.commons.rdf.api.Graph; +import org.apache.commons.rdf.api.IRI; +import org.apache.commons.rdf.api.Literal; +import org.apache.commons.rdf.api.RDFTermFactory; +import org.apache.commons.rdf.api.Triple; +import org.apache.commons.rdf.jena.JenaRDFTermFactory; +import org.apache.commons.rdf.jsonldjava.JsonLdRDFTermFactory; +import org.apache.commons.rdf.rdf4j.RDF4JTermFactory; +import org.apache.commons.rdf.simple.SimpleRDFTermFactory; +import org.junit.Test; + +public class AllToAllTest { + + private RDFTermFactory simpleFactory = new SimpleRDFTermFactory(); + private RDFTermFactory jenaFactory = new JenaRDFTermFactory(); + private RDFTermFactory rdf4jFactory = new RDF4JTermFactory(); + private RDFTermFactory jsonldFactory = new JsonLdRDFTermFactory(); + + @Test + public void jenaToRdf4j() throws Exception { + nodesIntoOther(jenaFactory, rdf4jFactory); + } + @Test + public void jenaToJsonLd() throws Exception { + nodesIntoOther(jenaFactory, jsonldFactory); + } + @Test + public void jenaToSimple() throws Exception { + nodesIntoOther(jenaFactory, simpleFactory); + } + + @Test + public void rdf4jToJena() throws Exception { + nodesIntoOther(rdf4jFactory, jenaFactory); + } + @Test + public void rdf4jToJsonLd() throws Exception { + nodesIntoOther(rdf4jFactory, jsonldFactory); + } + @Test + public void rdf4jToSimple() throws Exception { + nodesIntoOther(rdf4jFactory, simpleFactory); + } + + @Test + public void simpletoJena() throws Exception { + nodesIntoOther(simpleFactory, jenaFactory); + } + @Test + public void simpleToJsonLd() throws Exception { + nodesIntoOther(simpleFactory, jsonldFactory); + } + @Test + public void simpleToRdf4j() throws Exception { + nodesIntoOther(simpleFactory, rdf4jFactory); + } + + public void nodesIntoOther(RDFTermFactory fromFactory, RDFTermFactory toFactory) throws Exception { + Graph g = fromFactory.createGraph(); + BlankNode s = toFactory.createBlankNode(); + IRI p = toFactory.createIRI("http://example.com/p"); + Literal o = toFactory.createLiteral("Hello"); + + g.add(s, p, o); + + // blankNode should still work with g.contains() + assertTrue(g.contains(s, p, o)); + Triple t1 = g.stream().findAny().get(); + + // Can't make assumptions about mappegetPredicated BlankNode equality + // assertEquals(s, t.getSubject()); + assertEquals(p, t1.getPredicate()); + assertEquals(o, t1.getObject()); + + IRI s2 = toFactory.createIRI("http://example.com/s2"); + g.add(s2, p, s); + assertTrue(g.contains(s2, p, s)); + + // This should be mapped to the same BlankNode + // (even if it has a different identifier), e.g. + // we should be able to do: + + Triple t2 = g.stream(s2, p, null).findAny().get(); + + BlankNode bnode = (BlankNode) t2.getObject(); + // And that (possibly adapted) BlankNode object should + // match the subject of t1 statement + assertEquals(bnode, t1.getSubject()); + // And can be used as a key: + Triple t3 = g.stream(bnode, p, null).findAny().get(); + assertEquals(t1, t3); + } +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/1828c2ab/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JenaRDF4JTest.java ---------------------------------------------------------------------- diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JenaRDF4JTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JenaRDF4JTest.java deleted file mode 100644 index 50b5c68..0000000 --- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JenaRDF4JTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.apache.commons.rdf.integrationtests; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.apache.commons.rdf.api.BlankNode; -import org.apache.commons.rdf.api.Graph; -import org.apache.commons.rdf.api.IRI; -import org.apache.commons.rdf.api.Literal; -import org.apache.commons.rdf.api.RDFTermFactory; -import org.apache.commons.rdf.api.Triple; -import org.apache.commons.rdf.jena.RDFTermFactoryJena; -import org.apache.commons.rdf.rdf4j.RDF4JTermFactory; -import org.apache.commons.rdf.simple.SimpleRDFTermFactory; -import org.junit.Test; - -public class JenaRDF4JTest { - - private RDFTermFactory simpleFactory = new SimpleRDFTermFactory(); - private RDFTermFactory jenaFactory = new RDFTermFactoryJena(); - private RDFTermFactory rdf4jFactory = new RDF4JTermFactory(); - - @Test - public void jenaToRdf4j() throws Exception { - nodesIntoOther(jenaFactory, rdf4jFactory); - } - - @Test - public void rdf4jToJena() throws Exception { - nodesIntoOther(rdf4jFactory, jenaFactory); - } - - @Test - public void simpletoJena() throws Exception { - nodesIntoOther(simpleFactory, jenaFactory); - } - - @Test - public void simpleToRdf4j() throws Exception { - nodesIntoOther(simpleFactory, rdf4jFactory); - } - - public void nodesIntoOther(RDFTermFactory fromFactory, RDFTermFactory toFactory) throws Exception { - Graph g = fromFactory.createGraph(); - BlankNode s = toFactory.createBlankNode(); - IRI p = toFactory.createIRI("http://example.com/p"); - Literal o = toFactory.createLiteral("Hello"); - - g.add(s, p, o); - - // blankNode should still work with g.contains() - assertTrue(g.contains(s, p, o)); - Triple t1 = g.stream().findAny().get(); - - // Can't make assumptions about mappegetPredicated BlankNode equality - // assertEquals(s, t.getSubject()); - assertEquals(p, t1.getPredicate()); - assertEquals(o, t1.getObject()); - - IRI s2 = toFactory.createIRI("http://example.com/s2"); - g.add(s2, p, s); - assertTrue(g.contains(s2, p, s)); - - // This should be mapped to the same BlankNode - // (even if it has a different identifier), e.g. - // we should be able to do: - - Triple t2 = g.stream(s2, p, null).findAny().get(); - - BlankNode bnode = (BlankNode) t2.getObject(); - // And that (possibly adapted) BlankNode object should - // match the subject of t1 statement - assertEquals(bnode, t1.getSubject()); - // And can be used as a key: - Triple t3 = g.stream(bnode, p, null).findAny().get(); - assertEquals(t1, t3); - } -}