jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject [14/44] jena git commit: More tests
Date Sat, 06 Jan 2018 15:17:38 GMT
More tests


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

Branch: refs/heads/master
Commit: f53bdaca052526a9e8b111d3eac36f27f75e967c
Parents: 388583c
Author: ajs6f <ajs6f@apache.org>
Authored: Fri Dec 15 15:55:05 2017 -0500
Committer: ajs6f <ajs6f@apache.org>
Committed: Fri Jan 5 09:26:07 2018 -0500

----------------------------------------------------------------------
 .../jena/sparql/util/ViewDatasetGraph.java      |   7 +-
 .../util/TestIntersectionDatasetGraph.java      |  17 +++
 .../jena/sparql/util/TestUnionDatasetGraph.java |  37 +++++++
 .../jena/sparql/util/TestViewDatasetGraph.java  | 109 +++++++++++++++++++
 4 files changed, 167 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/f53bdaca/jena-arq/src/main/java/org/apache/jena/sparql/util/ViewDatasetGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/ViewDatasetGraph.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/ViewDatasetGraph.java
index 24e0769..c1c6542 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/ViewDatasetGraph.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/ViewDatasetGraph.java
@@ -1,5 +1,6 @@
 package org.apache.jena.sparql.util;
 
+import static java.util.Objects.requireNonNull;
 import static org.apache.jena.atlas.iterator.Iter.count;
 import static org.apache.jena.atlas.iterator.Iter.map;
 import static org.apache.jena.ext.com.google.common.collect.Iterators.concat;
@@ -26,8 +27,8 @@ public abstract class ViewDatasetGraph extends Pair.OfSameType<DatasetGraph>
imp
     private final Lock lock;
 
     public ViewDatasetGraph(DatasetGraph left, DatasetGraph right, Context c) {
-        super(left, right);
-        this.context = c;
+        super(requireNonNull(left), requireNonNull(right));
+        this.context = requireNonNull(c);
         this.lock = new PairLock(left.getLock(), right.getLock());
     }
 
@@ -56,7 +57,7 @@ public abstract class ViewDatasetGraph extends Pair.OfSameType<DatasetGraph>
imp
 
     @Override
     public void abort() {
-        throwNoMutationAllowed();
+        end();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/f53bdaca/jena-arq/src/test/java/org/apache/jena/sparql/util/TestIntersectionDatasetGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestIntersectionDatasetGraph.java
b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestIntersectionDatasetGraph.java
new file mode 100644
index 0000000..59eaf0e
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestIntersectionDatasetGraph.java
@@ -0,0 +1,17 @@
+package org.apache.jena.sparql.util;
+
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.junit.Test;
+
+public class TestIntersectionDatasetGraph extends TestViewDatasetGraph<IntersectionDatasetGraph>
{
+
+    @Override
+    public IntersectionDatasetGraph testInstance(DatasetGraph left, DatasetGraph right, Context
c) {
+        return new IntersectionDatasetGraph(right, right, c);
+    }
+
+    @Test
+    public void testIntersection() {
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/f53bdaca/jena-arq/src/test/java/org/apache/jena/sparql/util/TestUnionDatasetGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestUnionDatasetGraph.java
b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestUnionDatasetGraph.java
new file mode 100644
index 0000000..a131846
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestUnionDatasetGraph.java
@@ -0,0 +1,37 @@
+package org.apache.jena.sparql.util;
+
+import static org.apache.jena.sparql.sse.SSE.parseGraph;
+
+import org.apache.jena.graph.*;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.DatasetGraphFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestUnionDatasetGraph extends TestViewDatasetGraph<UnionDatasetGraph>
{
+
+    @Override
+    public UnionDatasetGraph testInstance(DatasetGraph left, DatasetGraph right, Context
c) {
+        return new UnionDatasetGraph(left, right, c);
+    }
+
+    @Test
+    public void testUnion() {
+
+        final Graph g1 = parseGraph("(graph (triple <s1> <p1> <o1> ))");
+        final DatasetGraph dsg1 = DatasetGraphFactory.create(g1);
+        final Node graphName1 = NodeFactory.createBlankNode();
+        dsg1.addGraph(graphName1, g1);
+        final Graph g2 = parseGraph("(graph (triple <s2> <p2> <o2> ))");
+        final DatasetGraph dsg2 = DatasetGraphFactory.create(g2);
+        final Node graphName2 = NodeFactory.createBlankNode();
+        dsg2.addGraph(graphName2, g2);
+        DatasetGraph dsg = testInstance(dsg1, dsg2, Context.emptyContext);
+
+        assertEquals(2, dsg.size());
+        assertTrue(g1.isIsomorphicWith(dsg.getGraph(graphName1)));
+        assertTrue(g2.isIsomorphicWith(dsg.getGraph(graphName2)));
+        g1.find().mapWith(dsg.getDefaultGraph()::contains).forEachRemaining(Assert::assertTrue);
+        g2.find().mapWith(dsg.getDefaultGraph()::contains).forEachRemaining(Assert::assertTrue);
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/f53bdaca/jena-arq/src/test/java/org/apache/jena/sparql/util/TestViewDatasetGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/util/TestViewDatasetGraph.java
b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestViewDatasetGraph.java
new file mode 100644
index 0000000..b6415db
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/util/TestViewDatasetGraph.java
@@ -0,0 +1,109 @@
+package org.apache.jena.sparql.util;
+
+import org.apache.jena.atlas.junit.BaseTest;
+import org.apache.jena.query.ReadWrite;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.DatasetGraphZero;
+import org.junit.Test;
+
+public abstract class TestViewDatasetGraph<T extends ViewDatasetGraph> extends BaseTest
{
+
+    public abstract T testInstance(DatasetGraph left, DatasetGraph right, Context c);
+
+    private T emptyDsg() {
+        return testInstance(new DatasetGraphZero(), new DatasetGraphZero(), Context.emptyContext);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void nullDatasetGraphsNotAllowed() {
+        testInstance(null, null, Context.emptyContext);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void nullContextNotAllowed() {
+        testInstance(new DatasetGraphZero(), new DatasetGraphZero(), null);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void noAddingQuads() {
+        emptyDsg().add(null);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void noAddingQuads2() {
+        emptyDsg().add(null, null, null, null);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void noDeletingQuads() {
+        emptyDsg().delete(null);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void noDeletingQuads2() {
+        emptyDsg().delete(null, null, null, null);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void noDeletingAnyQuads() {
+        emptyDsg().deleteAny(null, null, null, null);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void noAddingGraphs() {
+        emptyDsg().addGraph(null, null);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void noDeletingGraphs() {
+        emptyDsg().removeGraph(null);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void noClearing() {
+        emptyDsg().clear();
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void noWriting() {
+        emptyDsg().begin(ReadWrite.WRITE);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void noCommitting() {
+        final DatasetGraph dsg = emptyDsg();
+        assertFalse(dsg.isInTransaction());
+        dsg.begin(ReadWrite.READ);
+        assertTrue(dsg.isInTransaction());
+        dsg.commit();
+    }
+
+    @Test
+    public void canUseEndToFinishTransaction() {
+        try {
+            DatasetGraph dsg = emptyDsg();
+            assertFalse(dsg.isInTransaction());
+            dsg.begin(ReadWrite.READ);
+            assertTrue(dsg.isInTransaction());
+            dsg.end();
+            assertFalse(dsg.isInTransaction());
+        } catch (UnsupportedOperationException e) {
+            fail();
+        }
+    }
+
+    @Test
+    public void canUseAbortToFinishTransaction() {
+        try {
+            DatasetGraph dsg = emptyDsg();
+            assertFalse(dsg.isInTransaction());
+            dsg.begin(ReadWrite.READ);
+            assertTrue(dsg.isInTransaction());
+            dsg.abort();
+            assertFalse(dsg.isInTransaction());
+        } catch (UnsupportedOperationException e) {
+            fail();
+        }
+    }
+
+}


Mime
View raw message