commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [04/50] incubator-commonsrdf git commit: Create our own BlankNode for testing
Date Mon, 20 Jun 2016 08:57:58 GMT
Create our own BlankNode for testing

The test was improved to make the g1 and g2 with its own BlankNode instances - each graph
then having _:b1 and _:b2 - but with different uniqueReference().

This would also test that multiple graph.add(s,p,o) works with foreign BlankNode instances,
but without taking a stance on COMMONSRDF-15 - we don't care how it does the mapping (if any)
- and don't even require that they have the same uniqueReference() after adding.

Iterating g1 and g2 to add to g3 should not assume those BlankNodes are the same based on
their triplesString() - but differ by their uniqueReference()


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

Branch: refs/heads/parser-with-quads
Commit: a06f6219a4458f5dda70cda3097b975b005db308
Parents: 6fa2b48
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Apr 11 15:58:20 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Apr 11 15:58:20 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/api/AbstractGraphTest.java      | 50 ++++++++++++++++++--
 1 file changed, 45 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a06f6219/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index a6c4397..326e2ff 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@ -28,6 +28,8 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.junit.Assume;
@@ -362,15 +364,19 @@ public abstract class AbstractGraphTest {
         source.getTriples().unordered().sequential().forEach(t -> target.add(t));
     }
 
+    /**
+     * Make a new graph with two BlankNodes - each with a different uniqueReference
+     */
     private Graph createGraph1() {
         RDFTermFactory factory1 = createFactory();
 
         IRI name = factory1.createIRI("http://xmlns.com/foaf/0.1/name");
         Graph g1 = factory1.createGraph();
-        BlankNode b1 = factory1.createBlankNode();
+        BlankNode b1 = createOwnBlankNode("b1");
         g1.add(b1, name, factory1.createLiteral("Alice"));
-
-        BlankNode b2 = factory1.createBlankNode();
+        
+        
+        BlankNode b2 = createOwnBlankNode("b2");
         g1.add(b2, name, factory1.createLiteral("Bob"));
 
         IRI hasChild = factory1.createIRI("http://example.com/hasChild");
@@ -379,16 +385,50 @@ public abstract class AbstractGraphTest {
         return g1;
     }
 
+    /** 
+     * Create a different implementation of BlankNode to be tested with
+     * graph.add(a,b,c);
+     * (the implementation may or may not then choose to translate such to 
+     * its own instances)
+     * 
+     * @param name
+     * @return
+     */
+	private BlankNode createOwnBlankNode(String name) {
+		return new BlankNode() {			
+			@Override
+			public String ntriplesString() {
+				return "_: " + name;
+			}
+			@Override
+			public String uniqueReference() {
+				return "urn:uuid:" + UUID.randomUUID().toString();
+			}
+			@Override
+			public int hashCode() {
+				return uniqueReference().hashCode();
+			}
+			@Override
+			public boolean equals(Object obj) {
+				if (!( obj instanceof BlankNode)) {
+					return false;
+				}
+				BlankNode other = (BlankNode)obj;
+				return uniqueReference().equals(other.uniqueReference());
+			}
+		};
+	}
+
     private Graph createGraph2() {
         RDFTermFactory factory2 = createFactory();
         IRI name = factory2.createIRI("http://xmlns.com/foaf/0.1/name");
 
         Graph g2 = factory2.createGraph();
 
-        BlankNode b1 = factory2.createBlankNode();
+        BlankNode b1 = createOwnBlankNode("b1");
         g2.add(b1, name, factory2.createLiteral("Charlie"));
 
-        BlankNode b2 = factory2.createBlankNode();
+        BlankNode b2 = createOwnBlankNode("b2");
         g2.add(b2, name, factory2.createLiteral("Dave"));
 
         IRI hasChild = factory2.createIRI("http://example.com/hasChild");


Mime
View raw message