commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject commons-rdf git commit: COMMONSRDF-55: More tests
Date Wed, 01 Feb 2017 15:06:27 GMT
Repository: commons-rdf
Updated Branches:
  refs/heads/COMMONSRDF-55 bb264738a -> 98da22af4


COMMONSRDF-55: More tests


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/98da22af
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/98da22af
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/98da22af

Branch: refs/heads/COMMONSRDF-55
Commit: 98da22af438a1c0eaadf3cac7cd5e80f285fea4b
Parents: bb26473
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Wed Feb 1 15:06:16 2017 +0000
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Wed Feb 1 15:06:16 2017 +0000

----------------------------------------------------------------------
 .../commons/rdf/jena/impl/AbstractQuadLike.java |  9 +++--
 .../rdf/jena/DefaultGraphInQuadTest.java        | 41 +++++++++++++++++++-
 2 files changed, 46 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/98da22af/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
index 3100ae6..6127ee6 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
@@ -22,15 +22,12 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.UUID;
 
-import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.IRI;
 import org.apache.commons.rdf.api.QuadLike;
 import org.apache.commons.rdf.api.RDFTerm;
 import org.apache.commons.rdf.jena.JenaQuad;
 import org.apache.commons.rdf.jena.JenaQuadLike;
 import org.apache.commons.rdf.jena.JenaRDF;
 import org.apache.commons.rdf.jena.JenaTriple;
-import org.apache.jena.graph.Factory;
 import org.apache.jena.graph.Triple;
 import org.apache.jena.sparql.core.Quad;
 
@@ -57,6 +54,12 @@ abstract class AbstractQuadLike<S extends RDFTerm, P extends RDFTerm,
O extends
 
     /**
      * COMMONSRDF-55 - special handling of urn:x-arq:DefaultGraph and friends
+     * <p>
+     * This can recognize <urn:x-arq:DefaultGraph> and
+     * <urn:x-arq:DefaultGraphNode> from any IRI instance, so they can be
+     * replaced with Optional.empty(). Note that this code does not hardcode the
+     * internal Jena IRIs but uses Jena's constants {@link Quad#defaultGraphIRI}
+     * and {@link Quad#defaultGraphNodeGenerated}.
      */
     private static class DefaultGraphChecker {
         // Fixed UUID for comparison of defaultGraphNodeGenerated

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/98da22af/jena/src/test/java/org/apache/commons/rdf/jena/DefaultGraphInQuadTest.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/DefaultGraphInQuadTest.java b/jena/src/test/java/org/apache/commons/rdf/jena/DefaultGraphInQuadTest.java
index 739d7a4..477f460 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/DefaultGraphInQuadTest.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/DefaultGraphInQuadTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.simple.SimpleRDF;
 import org.apache.jena.graph.Node;
 import org.apache.jena.graph.NodeFactory;
 import org.apache.jena.sparql.core.Quad;
@@ -53,6 +54,42 @@ public class DefaultGraphInQuadTest {
         assertEquals(Quad.defaultGraphIRI,  q.asJenaQuad().getGraph());
         assertFalse(q.getGraphName().isPresent());
     }
+
+    @Test
+    public void createFromForeignDefaultGraph() throws Exception {
+        // What if <urn:x-arq:DefaultGraph> appear in a non-Jena IRI?
+        IRI foreignDefaultGraph = new SimpleRDF().createIRI(Quad.defaultGraphIRI.getURI());
+        JenaQuad q = rdf.createQuad(foreignDefaultGraph, example, example, example);
+        assertTrue(q.asJenaQuad().isDefaultGraph());
+        assertEquals(Quad.defaultGraphIRI,  q.asJenaQuad().getGraph());
+        assertFalse(q.getGraphName().isPresent());
+    }
+    
+
+    @Test
+    public void createFromDefaultGraphNodeGeneratedIRINode() throws Exception {
+        // What if <urn:x-arq:DefaultGraphNode> appear as an IRI instance?
+        IRI foreignDefaultGraph = rdf.createIRI(Quad.defaultGraphNodeGenerated.getURI());
+        JenaQuad q = rdf.createQuad(foreignDefaultGraph, example, example, example);
+        assertTrue(q.asJenaQuad().isDefaultGraph());
+        assertFalse(q.getGraphName().isPresent());
+        // Unfortunately  Quad.defaultGraphNodeGenerated is not preserved
+        // within JenaQuad
+        //assertEquals(Quad.defaultGraphNodeGenerated, q.asJenaQuad().getGraph());
+    }
+
+    @Test
+    public void createFromDefaultGraphNodeGeneratedIRIString() throws Exception {
+        // What if <urn:x-arq:DefaultGraphNode> appear in a non-Jena IRI?
+        IRI foreignDefaultGraph = (IRI) rdf.asRDFTerm((Quad.defaultGraphNodeGenerated));
+        JenaQuad q = rdf.createQuad(foreignDefaultGraph, example, example, example);
+        assertTrue(q.asJenaQuad().isDefaultGraph());
+        assertFalse(q.getGraphName().isPresent());
+        // Unfortunately  Quad.defaultGraphNodeGenerated is not preserved
+        // within JenaQuad
+        assertEquals(Quad.defaultGraphNodeGenerated, q.asJenaQuad().getGraph());
+    }
+
     
     @Test
     public void defaultGraphIRI() throws Exception {
@@ -64,11 +101,13 @@ public class DefaultGraphInQuadTest {
 
     @Test
     public void defaultGraphNodeGenerated() throws Exception {        
-        // defaultGraphNodeGenerated might appear in parser output
+        // <urn:x-arq:DefaultGraphNode> might appear in parser output
         Quad jenaQuad = Quad.create(Quad.defaultGraphNodeGenerated, exampleJena, exampleJena,
exampleJena);
         JenaQuad q = rdf.asQuad(jenaQuad);        
         assertFalse(q.getGraphName().isPresent());
         assertTrue(q.asJenaQuad().isDefaultGraph());
+        // Preserves <urn:x-arq:DefaultGraphNode>
+        assertEquals(Quad.defaultGraphNodeGenerated, q.asJenaQuad().getGraph());
     }
 
     @Test


Mime
View raw message