commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [6/9] commons-rdf git commit: COMMONSRDF-55: recognize default graph Node for generalizedQuad
Date Wed, 08 Feb 2017 14:42:15 GMT
COMMONSRDF-55: recognize default graph Node for generalizedQuad

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

Branch: refs/heads/master
Commit: c90bafec0df0b156493c61a1f41e71007fc1ad5e
Parents: d0ae2d8
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Wed Feb 8 14:32:49 2017 +0000
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Wed Feb 8 14:32:49 2017 +0000

----------------------------------------------------------------------
 .../rdf/jena/GeneralizedRDFQuadTest.java        | 68 +++++++++++++-------
 1 file changed, 45 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/c90bafec/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFQuadTest.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFQuadTest.java b/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFQuadTest.java
index e5b26a4..1e183d3 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFQuadTest.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFQuadTest.java
@@ -17,9 +17,12 @@
  */
 package org.apache.commons.rdf.jena;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import org.apache.commons.rdf.api.BlankNode;
+import org.apache.jena.sparql.core.Quad;
 import org.junit.Test;
 
 public class GeneralizedRDFQuadTest {
@@ -33,11 +36,12 @@ public class GeneralizedRDFQuadTest {
         JenaIRI ex2 = jena.createIRI("http://example.com/ex2");
         JenaIRI ex3 = jena.createIRI("http://example.com/ex3");
         
-        JenaGeneralizedQuadLike t = jena.createGeneralizedQuad(ex1, b1, ex2, ex3);
-        assertEquals(ex1, t.getSubject());
-        assertEquals(ex2, t.getObject());
-        assertEquals(b1, t.getPredicate()); // it's a bnode!
-        assertTrue(t.asJenaQuad().getPredicate().isBlank());
+        JenaGeneralizedQuadLike q = jena.createGeneralizedQuad(ex1, b1, ex2, ex3);
+        assertEquals(ex1, q.getSubject());
+        assertEquals(ex2, q.getObject());
+        assertEquals(b1, q.getPredicate()); // it's a bnode!
+        assertEquals(ex3, q.getGraphName().get());
+        assertTrue(q.asJenaQuad().getPredicate().isBlank());
     }
 
     @Test
@@ -47,11 +51,12 @@ public class GeneralizedRDFQuadTest {
         JenaIRI ex3 = jena.createIRI("http://example.com/ex3");
         JenaLiteral lit = jena.createLiteral("Hello");
         
-        JenaGeneralizedQuadLike t = jena.createGeneralizedQuad(ex1, lit, ex2, ex3);
-        assertEquals(ex1, t.getSubject());
-        assertEquals(ex2, t.getObject());
-        assertEquals(lit, t.getPredicate()); // it's a literal!
-        assertTrue(t.asJenaQuad().getPredicate().isLiteral());
+        JenaGeneralizedQuadLike q = jena.createGeneralizedQuad(ex1, lit, ex2, ex3);
+        assertEquals(ex1, q.getSubject());
+        assertEquals(ex2, q.getObject());
+        assertEquals(lit, q.getPredicate()); // it's a literal!
+        assertEquals(ex3, q.getGraphName().get());
+        assertTrue(q.asJenaQuad().getPredicate().isLiteral());
     }
 
 
@@ -62,14 +67,32 @@ public class GeneralizedRDFQuadTest {
         JenaIRI ex3 = jena.createIRI("http://example.com/ex3");
         JenaLiteral lit = jena.createLiteral("Hello");
         
-        JenaGeneralizedQuadLike t = jena.createGeneralizedQuad(lit, ex1, ex2, ex3);
-        assertEquals(lit, t.getSubject()); // it's a literal!
-        assertEquals(ex1, t.getPredicate());
-        assertEquals(ex2, t.getObject());
-        assertTrue(t.asJenaQuad().getSubject().isLiteral());
+        JenaGeneralizedQuadLike q = jena.createGeneralizedQuad(lit, ex1, ex2, ex3);
+        assertEquals(lit, q.getSubject()); // it's a literal!
+        assertEquals(ex1, q.getPredicate());
+        assertEquals(ex2, q.getObject());
+        assertEquals(ex3, q.getGraphName().get());
+        assertTrue(q.asJenaQuad().getSubject().isLiteral());
     }
     
+    @Test
+    public void literalSubjectDefaultGraphGen() throws Exception {
+        JenaIRI ex1 = jena.createIRI("http://example.com/ex1");
+        JenaIRI ex2 = jena.createIRI("http://example.com/ex2");
+        // No need to cast to JenaIRI
+        JenaRDFTerm defG = jena.asRDFTerm(Quad.defaultGraphNodeGenerated); 
+        JenaLiteral lit = jena.createLiteral("Hello");
+        
+        JenaGeneralizedQuadLike q = jena.createGeneralizedQuad(lit, ex1, ex2, defG);
+        assertEquals(lit, q.getSubject()); // it's a literal!
+        assertEquals(ex1, q.getPredicate());
+        assertEquals(ex2, q.getObject());
+        assertTrue(q.asJenaQuad().getSubject().isLiteral());
+        assertFalse(q.getGraphName().isPresent());
+        assertTrue(q.asJenaQuad().isDefaultGraph());
+    }
 
+    
     @Test
     public void literalGraph() throws Exception {
         JenaIRI ex1 = jena.createIRI("http://example.com/ex1");
@@ -77,13 +100,12 @@ public class GeneralizedRDFQuadTest {
         JenaIRI ex3 = jena.createIRI("http://example.com/ex3");
         JenaLiteral lit = jena.createLiteral("Hello");
         
-        JenaGeneralizedQuadLike t = jena.createGeneralizedQuad(ex1, ex2, ex3, lit);
-        assertEquals(ex1, t.getSubject()); 
-        assertEquals(ex2, t.getPredicate());
-        assertEquals(ex3, t.getObject());
-        assertTrue(t.getGraphName().isPresent());
-        assertEquals(lit, t.getGraphName().get());
-        assertTrue(t.asJenaQuad().getGraph().isLiteral());
+        JenaGeneralizedQuadLike q = jena.createGeneralizedQuad(ex1, ex2, ex3, lit);
+        assertEquals(ex1, q.getSubject()); 
+        assertEquals(ex2, q.getPredicate());
+        assertEquals(ex3, q.getObject());
+        assertEquals(lit, q.getGraphName().get()); // it's a literal!
+        assertTrue(q.asJenaQuad().getGraph().isLiteral());
     }
     
     


Mime
View raw message