commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wik...@apache.org
Subject [20/50] [abbrv] incubator-commonsrdf git commit: Don't rely on BlankNode.ntriplesString() making sense.
Date Fri, 27 Mar 2015 18:15:18 GMT
Don't rely on BlankNode.ntriplesString() making sense.

As pointed out in #42, the ntriplesString() does not need to match
the internal identifier. 

The tests now also assume that RDFNodes in a Triple are equal to those
passed into the RDFTermFactory.createTriple() - as those
terms were also made with the same RDFTermFactory and the Triple
is not (yet) inserted into a graph.

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

Branch: refs/heads/master
Commit: 28008951c9e7ade548f30a5fb1363d3dc80054e3
Parents: 4d348f9
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Jan 26 10:13:02 2015 +0000
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Jan 26 10:13:02 2015 +0000

----------------------------------------------------------------------
 .../api/AbstractRDFTermFactoryTest.java         | 73 ++++++++++----------
 1 file changed, 38 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/28008951/api/src/test/java/com/github/commonsrdf/api/AbstractRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/com/github/commonsrdf/api/AbstractRDFTermFactoryTest.java b/api/src/test/java/com/github/commonsrdf/api/AbstractRDFTermFactoryTest.java
index 56ec164..a4215c9 100644
--- a/api/src/test/java/com/github/commonsrdf/api/AbstractRDFTermFactoryTest.java
+++ b/api/src/test/java/com/github/commonsrdf/api/AbstractRDFTermFactoryTest.java
@@ -46,19 +46,11 @@ public abstract class AbstractRDFTermFactoryTest {
 			Assume.assumeNoException(ex);
 			return;
 		}
-		String ntriplesString = bnode.ntriplesString();
-		assertTrue("ntriples must start with _:",
-				ntriplesString.startsWith("_:"));
-		assertTrue("Internal identifier can't be empty", bnode
-				.internalIdentifier().length() > 0);
-		assertEquals("ntriples does not correspond with internal identifier",
-				bnode.internalIdentifier(),
-				ntriplesString.substring(2, ntriplesString.length()));
 
 		BlankNode bnode2 = factory.createBlankNode();
 		assertNotEquals(
 				"Second blank node has not got a unique internal identifier",
-				bnode.internalIdentifier(), bnode2.internalIdentifier());
+				bnode.internalIdentifier(), bnode2.internalIdentifier());		
 	}
 
 	@Test
@@ -71,9 +63,30 @@ public abstract class AbstractRDFTermFactoryTest {
 			return;
 		}
 		assertEquals("example1", bnode.internalIdentifier());
-		assertEquals("_:example1", bnode.ntriplesString());
+		// .. but we can't assume the internal identifier leaks into
+		// ntriplesString
+		//assertEquals("_:example1", bnode.ntriplesString());
 	}
 
+	@Test
+	public void createBlankNodeIdentifierTwice() throws Exception {
+		BlankNode bnode1, bnode2, bnode3;
+		try {
+			bnode1 = factory.createBlankNode("example1");
+			bnode2 = factory.createBlankNode("example1");
+			bnode3 = factory.createBlankNode("differ");
+		} catch (UnsupportedOperationException ex) {
+			Assume.assumeNoException(ex);
+			return;
+		}
+		assertEquals(bnode1.internalIdentifier(), bnode2.internalIdentifier());
+		// We don't know what the ntriplesString is, but it MUST be the same
+		assertEquals(bnode1.ntriplesString(), bnode2.ntriplesString());
+		// and here it MUST differ
+		assertNotEquals(bnode1.ntriplesString(), bnode3.ntriplesString());
+	}
+
+	
 	public abstract RDFTermFactory createFactory();
 
 	@Test
@@ -266,15 +279,11 @@ public abstract class AbstractRDFTermFactoryTest {
 			return;
 		}
 
-		// NOTE: We do not require object equivalence after insertion,
-		// but the ntriples should match
-		assertEquals(subject.ntriplesString(), triple.getSubject()
-				.ntriplesString());
-		assertEquals(predicate.ntriplesString(), triple.getPredicate()
-				.ntriplesString());
-		assertEquals(object.ntriplesString(), triple.getObject()
-				.ntriplesString());
-
+		// bnode equivalence should be OK as we used the same
+		// factory and have not yet inserted Triple into a Graph
+		assertEquals(subject, triple.getSubject());		
+		assertEquals(predicate, triple.getPredicate());
+		assertEquals(object, triple.getObject());
 	}
 
 	@Test
@@ -293,14 +302,11 @@ public abstract class AbstractRDFTermFactoryTest {
 			return;
 		}
 
-		// NOTE: We do not require object equivalence after insertion,
-		// but the ntriples should match
-		assertEquals(subject.ntriplesString(), triple.getSubject()
-				.ntriplesString());
-		assertEquals(predicate.ntriplesString(), triple.getPredicate()
-				.ntriplesString());
-		assertEquals(object.ntriplesString(), triple.getObject()
-				.ntriplesString());
+		// bnode equivalence should be OK as we used the same
+		// factory and have not yet inserted Triple into a Graph
+		assertEquals(subject, triple.getSubject());		
+		assertEquals(predicate, triple.getPredicate());
+		assertEquals(object, triple.getObject());
 	}
 
 	@Test
@@ -319,14 +325,11 @@ public abstract class AbstractRDFTermFactoryTest {
 			return;
 		}
 
-		// NOTE: We do not require object equivalence after insertion,
-		// but the ntriples should match
-		assertEquals(subject.ntriplesString(), triple.getSubject()
-				.ntriplesString());
-		assertEquals(predicate.ntriplesString(), triple.getPredicate()
-				.ntriplesString());
-		assertEquals(object.ntriplesString(), triple.getObject()
-				.ntriplesString());
+		// bnode equivalence should be OK as we used the same
+		// factory and have not yet inserted Triple into a Graph
+		assertEquals(subject, triple.getSubject());		
+		assertEquals(predicate, triple.getPredicate());
+		assertEquals(object, triple.getObject());
 	}
 
 	@Before


Mime
View raw message