commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [2/3] incubator-commonsrdf git commit: test getGraph(), getGraphNames()
Date Thu, 03 Nov 2016 14:14:57 GMT
test getGraph(), getGraphNames()


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

Branch: refs/heads/master
Commit: 9f20482fb42da24fb80e911fd2a86bd3bd0b50e8
Parents: c483e62
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Thu Nov 3 14:13:27 2016 +0000
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Thu Nov 3 14:13:27 2016 +0000

----------------------------------------------------------------------
 .../commons/rdf/api/AbstractDatasetTest.java    | 75 ++++++++++++++++++--
 1 file changed, 70 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9f20482f/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
index 6940dae..a8e321c 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
@@ -17,11 +17,7 @@
  */
 package org.apache.commons.rdf.api;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -29,7 +25,9 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 import org.junit.Assume;
@@ -464,7 +462,74 @@ public abstract class AbstractDatasetTest {
         g2.add(b2, b2, hasChild, b1);
         return g2;
     }
+    
+    /**
+     * Ensure {@link Dataset#getGraphNames()} contains our two graphs.
+     * 
+     * @throws Exception
+     *             If test fails
+     */
+    @Test
+    public void getGraphNames() throws Exception {
+        Set<BlankNodeOrIRI> names = dataset.getGraphNames().collect(Collectors.toSet());
       
+        assertTrue("Can't find graph name " + graph1, names.contains(graph1));
+        assertTrue("Can't find graph name " + graph2, names.contains(graph2));
+
+        // Some implementations like Virtuoso might have additional internal graphs,
+        // so we can't assume this:
+        //assertEquals(2, names.size());
+    }
+    
+    @Test
+    public void getGraph() throws Exception {
+        Graph defaultGraph = dataset.getGraph();
+        // TODO: Can we assume the default graph was empty before our new triples?
+        assertEquals(2, defaultGraph.size());
+        assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1));
+        // NOTE: graph2 is a BlankNode
+        assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, graph2));
+    }
+
+
+    @Test
+    public void getGraphNull() throws Exception {
+        // Default graph should be present
+        Graph defaultGraph = dataset.getGraph(null).get();
+        // TODO: Can we assume the default graph was empty before our new triples?
+        assertEquals(2, defaultGraph.size());
+        assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1));
+        // NOTE: graph2 is a BlankNode
+        assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, graph2));
+    }
+    
+
+    @Test
+    public void getGraph1() throws Exception {
+        // graph1 should be present
+        Graph g1 = dataset.getGraph(graph1).get();
+        assertEquals(4, g1.size());
+        
+        assertTrue(g1.contains(alice, name, aliceName));
+        assertTrue(g1.contains(alice, knows, bob));
+        assertTrue(g1.contains(alice, member, bnode1));
+        assertTrue(g1.contains(bnode1, name, secretClubName));
+    }
+
+    @Test
+    public void getGraph2() throws Exception {
+        // graph2 should be present, even if is named by a BlankNode
+        Graph g2 = dataset.getGraph(graph2).get();
+        assertEquals(4, g2.size());
+        Triple bobNameTriple = bobNameQuad.asTriple();
+        assertTrue(g2.contains(bobNameTriple));
+        assertTrue(g2.contains(bob, member, bnode1));
+        assertTrue(g2.contains(bob, member, bnode2));
+        assertFalse(g2.contains(bnode1, name, secretClubName));
+        assertTrue(g2.contains(bnode2, name, companyName));
+    }
+    
 
+    
     /**
      * An attempt to use the Java 8 streams to look up a more complicated query.
      * <p>


Mime
View raw message