jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject [33/44] jena git commit: Beginning tests of dataset collectors
Date Sat, 06 Jan 2018 15:17:57 GMT
Beginning tests of dataset collectors


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

Branch: refs/heads/master
Commit: f665fa184c41173096e9590bd2775aa13b895140
Parents: 1579273
Author: ajs6f <ajs6f@apache.org>
Authored: Fri Dec 29 12:54:56 2017 -0500
Committer: ajs6f <ajs6f@apache.org>
Committed: Fri Jan 5 09:32:55 2018 -0500

----------------------------------------------------------------------
 .../jena/query/util/TestDatasetCollector.java   | 33 ++++++++++++++++++--
 .../util/TestIntersectionDatasetCollector.java  | 12 +++++++
 .../query/util/TestUnionDatasetCollector.java   | 32 +++++++++++++++++++
 3 files changed, 74 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/f665fa18/jena-arq/src/test/java/org/apache/jena/query/util/TestDatasetCollector.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/query/util/TestDatasetCollector.java b/jena-arq/src/test/java/org/apache/jena/query/util/TestDatasetCollector.java
index c86ace0..83093e9 100644
--- a/jena-arq/src/test/java/org/apache/jena/query/util/TestDatasetCollector.java
+++ b/jena-arq/src/test/java/org/apache/jena/query/util/TestDatasetCollector.java
@@ -1,7 +1,34 @@
 package org.apache.jena.query.util;
 
-public class TestDatasetCollector {
-    
-    
+import java.util.stream.Stream;
 
+import org.apache.jena.query.Dataset;
+import org.apache.jena.query.DatasetFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+public abstract class TestDatasetCollector extends Assert {
+
+    public abstract DatasetCollector testInstance();
+
+    @Test
+    public void collectionOfEmptyStreamShouldBeEmpty() {
+        final Dataset collected = Stream.<Dataset>empty().collect(testInstance());
+        assertTrue(collected.isEmpty());
+    }
+
+    @Test
+    public void collectionOfStreamOfEmptyDatasetsShouldBeEmpty() {
+        Stream<Dataset> stream = Stream.<Dataset>builder()
+                .add(DatasetFactory.create())
+                .add(DatasetFactory.create())
+                .add(DatasetFactory.create()).build();
+        final Dataset collected = stream.collect(testInstance());
+        assertTrue(collected.isEmpty());
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void noNullDatasetsAllowed() {
+        Stream.<Dataset>builder().add(null).build().collect(testInstance());
+    }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/f665fa18/jena-arq/src/test/java/org/apache/jena/query/util/TestIntersectionDatasetCollector.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/query/util/TestIntersectionDatasetCollector.java
b/jena-arq/src/test/java/org/apache/jena/query/util/TestIntersectionDatasetCollector.java
new file mode 100644
index 0000000..a8b1285
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/query/util/TestIntersectionDatasetCollector.java
@@ -0,0 +1,12 @@
+package org.apache.jena.query.util;
+
+public class TestIntersectionDatasetCollector extends TestDatasetCollector{
+
+    @Override
+    public DatasetCollector testInstance() {
+        return DatasetLib.collectors().intersect();
+    }
+
+    
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/f665fa18/jena-arq/src/test/java/org/apache/jena/query/util/TestUnionDatasetCollector.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/query/util/TestUnionDatasetCollector.java
b/jena-arq/src/test/java/org/apache/jena/query/util/TestUnionDatasetCollector.java
new file mode 100644
index 0000000..65b94d0
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/query/util/TestUnionDatasetCollector.java
@@ -0,0 +1,32 @@
+package org.apache.jena.query.util;
+
+import static org.apache.jena.rdf.model.ModelFactory.createModelForGraph;
+import static org.apache.jena.sparql.sse.SSE.parseGraph;
+
+import java.util.stream.Stream;
+
+import org.apache.jena.graph.Graph;
+import org.apache.jena.query.Dataset;
+import org.apache.jena.query.DatasetFactory;
+import org.apache.jena.rdf.model.Model;
+import org.junit.Test;
+
+public class TestUnionDatasetCollector extends TestDatasetCollector {
+
+    @Override
+    public DatasetCollector testInstance() {
+        return DatasetLib.collectors().union();
+    }
+
+    @Test
+    public void collectingOneDatasetGivesOneDataset() {
+        Graph graph = parseGraph("(graph (triple <s1> <p1> <o1> ))");
+        Model model = createModelForGraph(graph);
+        Dataset dataset = DatasetFactory.create(model);
+        Dataset collection = Stream.<Dataset>builder().add(dataset).build().collect(testInstance());
+        assertTrue(dataset.getDefaultModel().isIsomorphicWith(collection.getDefaultModel()));
+        dataset.listNames().forEachRemaining(graphName -> assertTrue(
+                dataset.getNamedModel(graphName).isIsomorphicWith(collection.getNamedModel(graphName))));
+    }
+
+}


Mime
View raw message