commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [3/5] incubator-commonsrdf git commit: Also test adding Triple instances
Date Mon, 12 Sep 2016 22:29:13 GMT
Also test adding Triple instances

Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/112505df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/112505df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/112505df

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 112505dfe488889b1ad16dca1120bd6c59ae8075
Parents: b8ff697
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Sep 12 18:59:33 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Sep 12 18:59:33 2016 +0100

----------------------------------------------------------------------
 .../rdf/integrationtests/AllToAllTest.java      | 64 +++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/112505df/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
index b9ea397..0d65f05 100644
--- 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
@@ -26,40 +26,49 @@ public class AllToAllTest {
 	@Test
 	public void jenaToRdf4j() throws Exception {
 		addTermsFromOtherFactory(jenaFactory, rdf4jFactory);
+		addTriplesFromOtherFactory(jenaFactory, rdf4jFactory);
 	}
 	@Test
 	public void jenaToJsonLd() throws Exception {
 		addTermsFromOtherFactory(jenaFactory, jsonldFactory);
+		addTriplesFromOtherFactory( jenaFactory, jsonldFactory );
 	}
 	@Test
 	public void jenaToSimple() throws Exception {
 		addTermsFromOtherFactory(jenaFactory, simpleFactory);
+		addTriplesFromOtherFactory( jenaFactory, simpleFactory );
 	}
 	
 	@Test
 	public void rdf4jToJena() throws Exception {
 		addTermsFromOtherFactory(rdf4jFactory, jenaFactory);
+		addTriplesFromOtherFactory( rdf4jFactory, jenaFactory );
 	}
 	@Test
 	public void rdf4jToJsonLd() throws Exception {
 		addTermsFromOtherFactory(rdf4jFactory, jsonldFactory);
+		addTriplesFromOtherFactory( rdf4jFactory, jenaFactory );
 	}	
 	@Test
 	public void rdf4jToSimple() throws Exception {
 		addTermsFromOtherFactory(rdf4jFactory, simpleFactory);
+		addTriplesFromOtherFactory(rdf4jFactory, simpleFactory  );
 	}
 	
 	@Test
 	public void simpletoJena() throws Exception {
 		addTermsFromOtherFactory(simpleFactory, jenaFactory);
+		addTriplesFromOtherFactory( simpleFactory, jenaFactory);
 	}
 	@Test
 	public void simpleToJsonLd() throws Exception {
 		addTermsFromOtherFactory(simpleFactory, jsonldFactory);
+		addTriplesFromOtherFactory( simpleFactory, jsonldFactory );
 	}
 	@Test
 	public void simpleToRdf4j() throws Exception {
 		addTermsFromOtherFactory(simpleFactory, rdf4jFactory);
+		addTriplesFromOtherFactory( simpleFactory, rdf4jFactory );
 	}
 	
 	/**
@@ -67,8 +76,8 @@ public class AllToAllTest {
 	 * {@link RDFTermFactory}, then inserts/queries with
 	 * triples using {@link RDFTerm}s created with the second factory.
 	 * 
+	 * @param nodeFactory Factory to create {@link RDFTerm} instances
 	 * @param graphFactory Factory to create {@link Graph}
-	 * @param nodeFactory
 	 * @throws Exception
 	 */
 	public void addTermsFromOtherFactory(RDFTermFactory nodeFactory, RDFTermFactory graphFactory)
throws Exception {
@@ -108,4 +117,57 @@ public class AllToAllTest {
 		Triple t3 = g.stream(bnode, p, null).findAny().get();
 		assertEquals(t1, t3);		
 	}
+	
+
+	/**
+	 * This is a variation of {@link #addTermsFromOtherFactory(RDFTermFactory, RDFTermFactory)},

+	 * but here {@link Triple} is created in the "foreign" nodeFactory before adding to the
graph.
+	 * 
+	 * @param nodeFactory Factory to create {@link RDFTerm} and {@link Triple}s
+	 * @param graphFactory Factory to create {@link Graph}
+	 * @throws Exception
+	 */
+	public void addTriplesFromOtherFactory(RDFTermFactory nodeFactory, RDFTermFactory graphFactory)
throws Exception {
+		Graph g = graphFactory.createGraph();
+		BlankNode s = nodeFactory.createBlankNode();
+		IRI p = nodeFactory.createIRI("http://example.com/p");
+		Literal o = nodeFactory.createLiteral("Hello");
+		
+		Triple srcT1 = nodeFactory.createTriple(s, p, o);
+		// This should work even with BlankNode as they are from the same factory
+		assertEquals(s, srcT1.getSubject());
+		assertEquals(p, srcT1.getPredicate());
+		assertEquals(o, srcT1.getObject());
+		g.add(srcT1);
+		
+		// what about the blankNode within?
+		assertTrue(g.contains(srcT1));
+		Triple t1 = g.stream().findAny().get();
+
+		// Can't make assumptions about BlankNode equality - it might
+		// have been mapped to a different BlankNode.uniqueReference()
+		//assertEquals(srcT1, t1);
+		//assertEquals(s, t1.getSubject());
+		assertEquals(p, t1.getPredicate());
+		assertEquals(o, t1.getObject());
+
+		IRI s2 = nodeFactory.createIRI("http://example.com/s2");
+		Triple srcT2 = nodeFactory.createTriple(s2, p, s);
+		g.add(srcT2);
+		assertTrue(g.contains(srcT2));
+
+		// 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);		
+	}	
 }


Mime
View raw message