You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by cl...@apache.org on 2013/10/09 19:16:18 UTC
svn commit: r1530718 [3/10] - in /jena/Experimental/new-test: ./
src/test/java/com/hp/hpl/jena/graph/
src/test/java/com/hp/hpl/jena/graph/compose/
src/test/java/com/hp/hpl/jena/graph/impl/
src/test/java/com/hp/hpl/jena/mem/ src/test/java/com/hp/hpl/jen...
Copied: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/RecordingGraphListener.java (from r1523135, jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/RecordingListener.java)
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/RecordingGraphListener.java?p2=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/RecordingGraphListener.java&p1=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/RecordingListener.java&r1=1523135&r2=1530718&rev=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/RecordingListener.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/RecordingGraphListener.java Wed Oct 9 17:16:15 2013
@@ -18,23 +18,21 @@
package com.hp.hpl.jena.graph;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
-import org.junit.Assert;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphListener;
import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.testing_framework.AbstractRecordingListener;
import com.hp.hpl.jena.testing_framework.GraphHelper;
/**
* This testing listener records the event names and data, and provides a method
* for comparing the actual with the expected history.
*/
-public class RecordingListener implements GraphListener {
- public List<Object> history = new ArrayList<Object>();
+public class RecordingGraphListener extends AbstractRecordingListener implements
+ GraphListener {
@Override
public void notifyAddTriple(Graph g, Triple t) {
@@ -91,58 +89,4 @@ public class RecordingListener implement
record("someEvent", source, event);
}
- protected void record(String tag, Object x, Object y) {
- history.add(tag);
- history.add(x);
- history.add(y);
- }
-
- protected void record(String tag, Object info) {
- history.add(tag);
- history.add(info);
- }
-
- public void clear() {
- history.clear();
- }
-
- public boolean has(List<Object> things) {
- return Arrays.deepEquals(history.toArray(), things.toArray());
- }
-
- public boolean hasStart(List<Object> L) {
- return L.size() <= history.size()
- && L.equals(history.subList(0, L.size()));
- }
-
- public boolean hasEnd(List<Object> L) {
- return L.size() <= history.size()
- && L.equals(history.subList(history.size() - L.size(),
- history.size()));
- }
-
- public boolean has(Object[] things) {
- return Arrays.deepEquals(history.toArray(), things);
- }
-
- public void assertHas(List<Object> things) {
- if (has(things) == false)
- Assert.fail("expected " + things + " but got " + history);
- }
-
- public void assertHas(Object[] things) {
- assertHas(Arrays.asList(things));
- }
-
- public void assertHasStart(Object[] start) {
- List<Object> L = Arrays.asList(start);
- if (hasStart(L) == false)
- Assert.fail("expected " + L + " at the beginning of " + history);
- }
-
- public void assertHasEnd(Object[] end) {
- List<Object> L = Arrays.asList(end);
- if (hasEnd(L) == false)
- Assert.fail("expected " + L + " at the end of " + history);
- }
}
Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/ReifierTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/ReifierTest.java?rev=1530718&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/ReifierTest.java (added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/ReifierTest.java Wed Oct 9 17:16:15 2013
@@ -0,0 +1,313 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.hp.hpl.jena.graph;
+
+import static org.junit.Assert.*;
+import static com.hp.hpl.jena.testing_framework.GraphHelper.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.hp.hpl.jena.rdf.model.impl.ReifierStd;
+import com.hp.hpl.jena.shared.AlreadyReifiedException;
+import com.hp.hpl.jena.shared.CannotReifyException;
+import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
+import org.xenei.junit.contract.IProducer;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+public class ReifierTest {
+
+ private Graph g;
+
+ protected IProducer<? extends Graph> graphProducer = new AbstractGraphProducer<Graph>() {
+ @Override
+ protected Graph createNewGraph() {
+ return memGraph();
+ }
+ };
+
+ /**
+ * Answer the empty graph if cond is false, otherwise the graph with the
+ * given facts.
+ */
+ protected final Graph graphWithUnless(boolean cond, String facts) {
+ return graphWith(graphProducer.newInstance(), cond ? "" : facts);
+ }
+
+ protected final Graph graphWithIf(boolean cond, String facts) {
+ return graphWithUnless(!cond, facts);
+ }
+
+ @Before
+ public final void beforeReifierTest() {
+ g = graphProducer.newInstance();
+ }
+
+ @After
+ public final void afterReifierTest() {
+ graphProducer.cleanUp();
+ }
+
+ /**
+ * Check that the standard reifier will note, but not hide, reification
+ * quads.
+ */
+ @Test
+ public void testStandard() {
+ assertFalse(ReifierStd.hasTriple(g, triple("s p o")));
+ graphAddTxn(g, "x rdf:subject s");
+ assertEquals(1, g.size());
+ graphAddTxn(g, "x rdf:predicate p");
+ assertEquals(2, g.size());
+ graphAddTxn(g, "x rdf:object o");
+ assertEquals(3, g.size());
+ graphAddTxn(g, "x rdf:type rdf:Statement");
+ assertEquals(4, g.size());
+ assertTrue(ReifierStd.hasTriple(g, triple("s p o")));
+ }
+
+ /**
+ * Test that the Standard reifier will expose implicit quads arising from
+ * reifyAs().
+ */
+ @Test
+ public void testStandardExplode() {
+ txnBegin(g);
+ ReifierStd.reifyAs(g, node("a"), triple("p Q r"));
+ txnCommit(g);
+ Graph r = graphProducer.newInstance();
+ graphAddTxn(r,
+ "a rdf:type rdf:Statement; a rdf:subject p; a rdf:predicate Q; a rdf:object r");
+ assertEquals(4, g.size());
+ assertIsomorphic(r, g);
+ }
+
+ /**
+ * Ensure that over-specifying a reification means that we don't get a
+ * triple back. Goodness knows why this test wasn't in right from the
+ * beginning.
+ */
+ @Test
+ public void testOverspecificationSuppressesReification() {
+ graphAddTxn(g,
+ "x rdf:subject A; x rdf:predicate P; x rdf:object O; x rdf:type rdf:Statement");
+ assertEquals(triple("A P O"), ReifierStd.getTriple(g, node("x")));
+ graphAddTxn(g, "x rdf:subject BOOM");
+ assertNull(ReifierStd.getTriple(g, node("x")));
+ }
+
+ @Test
+ public void testReificationSubjectClash() {
+ testReificationClash("x rdf:subject SS");
+ }
+
+ @Test
+ public void testReificationPredicateClash() {
+ testReificationClash("x rdf:predicate PP");
+ }
+
+ @Test
+ public void testReificationObjectClash() {
+ testReificationClash("x rdf:object OO");
+ }
+
+ protected void testReificationClash(String clashingStatement) {
+ Triple SPO = triple("S P O");
+ txnBegin(g);
+ ReifierStd.reifyAs(g, node("x"), SPO);
+ txnCommit(g);
+ assertTrue(ReifierStd.hasTriple(g, SPO));
+ graphAddTxn(g, clashingStatement);
+ assertNull(ReifierStd.getTriple(g, node("x")));
+ // System.err.println( ">> tRC: clashing = " + clashingStatement );
+ assertFalse(ReifierStd.hasTriple(g, SPO));
+ }
+
+ /**
+ * Test that reifying a triple explicitly has some effect on the graph only
+ * for Standard reifiers.
+ */
+ @Test
+ public void testManifestQuads() {
+ txnBegin(g);
+ ReifierStd.reifyAs(g, node("A"), triple("S P O"));
+ txnCommit(g);
+ String reified = "A rdf:type rdf:Statement; A rdf:subject S; A rdf:predicate P; A rdf:object O";
+ assertIsomorphic(graphWith(graphProducer.newInstance(), reified), g);
+ }
+
+ @Test
+ public void testHiddenVsReification() {
+ txnBegin(g);
+ ReifierStd.reifyAs(g, node("A"), triple("S P O"));
+ txnCommit(g);
+ assertTrue(ReifierStd.findEither(g, Triple.ANY, false).hasNext());
+ }
+
+ @Test
+ public void testRetrieveTriplesByNode() {
+ Node n = NodeFactory.createAnon(), m = NodeFactory.createAnon();
+ txnBegin(g);
+ ReifierStd.reifyAs(g, n, triple("x R y"));
+ txnCommit(g);
+ assertEquals("gets correct triple", triple("x R y"),
+ ReifierStd.getTriple(g, n));
+ txnBegin(g);
+ ReifierStd.reifyAs(g, m, triple("p S q"));
+ txnCommit(g);
+ assertDiffer("the anon nodes must be distinct", n, m);
+ assertEquals("gets correct triple", triple("p S q"),
+ ReifierStd.getTriple(g, m));
+
+ assertTrue("node is known bound", ReifierStd.hasTriple(g, m));
+ assertTrue("node is known bound", ReifierStd.hasTriple(g, n));
+ assertFalse("node is known unbound",
+ ReifierStd.hasTriple(g, NodeFactory.createURI("any:thing")));
+ }
+
+ @Test
+ public void testRetrieveTriplesByTriple() {
+ Triple T = triple("x R y"), T2 = triple("y R x");
+ Node N = node("someNode");
+ txnBegin(g);
+ ReifierStd.reifyAs(g, N, T);
+ txnCommit(g);
+ assertTrue("R must have T", ReifierStd.hasTriple(g, T));
+ assertFalse("R must not have T2", ReifierStd.hasTriple(g, T2));
+ }
+
+ @Test
+ public void testReifyAs() {
+ Node x = NodeFactory.createURI("some:uri");
+ txnBegin(g);
+ Node y = ReifierStd.reifyAs(g, x, triple("x R y"));
+ txnCommit(g);
+ assertEquals("node used", x, y);
+ assertEquals("retrieves correctly", triple("x R y"),
+ ReifierStd.getTriple(g, x));
+ }
+
+ @Test
+ public void testAllNodes() {
+ txnBegin(g);
+ ReifierStd.reifyAs(g, node("x"), triple("cows eat grass"));
+ ReifierStd.reifyAs(g, node("y"), triple("pigs can fly"));
+ ReifierStd.reifyAs(g, node("z"), triple("dogs may bark"));
+ txnCommit(g);
+ assertEquals("", nodeSet("z y x"),
+ iteratorToSet(ReifierStd.allNodes(g)));
+ }
+
+ @Test
+ public void testRemoveByNode() {
+ Node X = node("x"), Y = node("y");
+ txnBegin(g);
+ ReifierStd.reifyAs(g, X, triple("x R a"));
+ ReifierStd.reifyAs(g, Y, triple("y R a"));
+ ReifierStd.remove(g, X, triple("x R a"));
+ txnCommit(g);
+ assertFalse("triple X has gone", ReifierStd.hasTriple(g, X));
+ assertEquals("triple Y still there", triple("y R a"),
+ ReifierStd.getTriple(g, Y));
+ }
+
+ @Test
+ public void testException() {
+ Node X = node("x");
+ txnBegin(g);
+ ReifierStd.reifyAs(g, X, triple("x R y"));
+ ReifierStd.reifyAs(g, X, triple("x R y"));
+ try {
+ ReifierStd.reifyAs(g, X, triple("x R z"));
+ fail("did not detect already reified node");
+ } catch (AlreadyReifiedException e) {
+ } finally {
+ txnRollback(g);
+ }
+ }
+
+ @Test
+ public void testKevinCaseA() {
+ Node X = node("x"), a = node("a"), b = node("b"), c = node("c");
+ txnBegin(g);
+ g.add(Triple.create(X, RDF.Nodes.type, RDF.Nodes.Statement));
+ ReifierStd.reifyAs(g, X, Triple.create(a, b, c));
+ txnCommit(g);
+ }
+
+ @Test
+ public void testKevinCaseB() {
+ Node X = node("x"), Y = node("y");
+ Node a = node("a"), b = node("b"), c = node("c");
+ txnBegin(g);
+ g.add(Triple.create(X, RDF.Nodes.subject, Y));
+ try {
+ ReifierStd.reifyAs(g, X, Triple.create(a, b, c));
+ fail("X already has subject Y: cannot make it a");
+ } catch (CannotReifyException e) {
+ // expected
+ } finally {
+ txnRollback(g);
+ }
+ }
+
+ @Test
+ public void testFindExposed_EmptyFind() {
+ assertEquals(tripleSet(""), ReifierStd.findExposed(g, Triple.ANY)
+ .toSet());
+ }
+
+ @Test
+ public void testReifierFind_Subject() {
+ testReifierFind("x rdf:subject S");
+ }
+
+ @Test
+ public void testReifierFind_Object() {
+ testReifierFind("x rdf:object O");
+ }
+
+ @Test
+ public void testReifierFind_Predicate() {
+ testReifierFind("x rdf:predicate P");
+ }
+
+ @Test
+ public void testReifierFind_Complete() {
+ testReifierFind("x rdf:predicate P; x rdf:subject S; x rdf:object O; x rdf:type rdf:Statement");
+ }
+
+ @Test
+ public void testReifierFind_Filter() {
+ graphAddTxn(g, "s rdf:subject S");
+ assertEquals(tripleSet(""),
+ ReifierStd.findExposed(g, triple("s otherPredicate S")).toSet());
+ }
+
+ protected void testReifierFind(String triples) {
+ testReifierFind(triples, "?? ?? ??");
+ }
+
+ protected void testReifierFind(String triples, String pattern) {
+ graphAddTxn(g, triples);
+ assertEquals(tripleSet(triples),
+ ReifierStd.findExposed(g, triple(pattern)).toSet());
+ }
+}
Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/ReifierTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestGraphUtil.java (from r1520788, jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestGraphUtils.java)
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestGraphUtil.java?p2=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestGraphUtil.java&p1=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestGraphUtils.java&r1=1520788&r2=1530718&rev=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestGraphUtils.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestGraphUtil.java Wed Oct 9 17:16:15 2013
@@ -18,14 +18,32 @@
package com.hp.hpl.jena.graph;
+import static com.hp.hpl.jena.testing_framework.GraphHelper.*;
import static org.junit.Assert.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
import org.junit.Test;
import com.hp.hpl.jena.graph.impl.GraphBase;
+import com.hp.hpl.jena.util.CollectionFactory;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
-public class TestGraphUtils {
+public class TestGraphUtil {
+
+ private static final Triple[] tripleArray = tripleArray("S P O; A R B; X Q Y");
+ private static final List<Triple> tripleList = Arrays
+ .asList(tripleArray("i lt j; p equals q"));
+ private static final Triple[] setTriples = tripleArray("scissors cut paper; paper wraps stone; stone breaks scissors");
+
+ private static final Set<Triple> tripleSet = CollectionFactory
+ .createHashedSet(Arrays.asList(setTriples));
private static class Bool {
boolean value;
@@ -52,4 +70,302 @@ public class TestGraphUtils {
GraphUtil.findAll(mock);
assertTrue("find(ANY, ANY, ANY) called", foundAll.value);
}
+
+ /**
+ * Test that nodes can be found in all triple positions. However, testing
+ * for literals in subject positions is suppressed at present to avoid
+ * problems with InfGraphs which try to prevent such constructs leaking out
+ * to the RDF layer.
+ */
+ @Test
+ public void testContainsNode() {
+ Graph g = graphWith("a P b; _c p1 _D; a P2 12");
+ assertTrue(containsNode(g, node("a")));
+ assertTrue(containsNode(g, node("P")));
+ assertTrue(containsNode(g, node("b")));
+ assertTrue(containsNode(g, node("_c")));
+ assertTrue(containsNode(g, node("p1")));
+ assertTrue(containsNode(g, node("_D")));
+ // assertTrue( qh.containsNode( node( "10" ) ) );
+ // assertTrue(containsNode(g, node("11")));
+ assertTrue(containsNode(g, node("12")));
+ /* */
+ assertFalse(containsNode(g, node("x")));
+ assertFalse(containsNode(g, node("_y")));
+ assertFalse(containsNode(g, node("99")));
+ }
+
+ private boolean containsNode(Graph g, Node node) {
+ return GraphUtil.containsNode(g, node);
+ }
+
+ @Test
+ public void testListSubjects() {
+ Set<Node> emptySubjects = listSubjects(graphWith(""));
+ Graph g = graphWith("x P y; y Q z");
+ assertEquals(nodeSet("x y"), remove(listSubjects(g), emptySubjects));
+ txnBegin(g);
+ g.delete(triple("x P y"));
+ txnCommit(g);
+ assertEquals(nodeSet("y"), remove(listSubjects(g), emptySubjects));
+ }
+
+ protected Set<Node> listSubjects(Graph g) {
+ return GraphUtil.listSubjects(g, Node.ANY, Node.ANY).toSet();
+ }
+
+ @Test
+ public void testListPredicates() {
+ Set<Node> emptyPredicates = listPredicates(graphWith(""));
+ Graph g = graphWith("x P y; y Q z");
+ assertEquals(nodeSet("P Q"), remove(listPredicates(g), emptyPredicates));
+ txnBegin(g);
+ g.delete(triple("x P y"));
+ txnCommit(g);
+ assertEquals(nodeSet("Q"), remove(listPredicates(g), emptyPredicates));
+ }
+
+ protected Set<Node> listPredicates(Graph g) {
+ return GraphUtil.listPredicates(g, Node.ANY, Node.ANY).toSet();
+ }
+
+ @Test
+ public void testListObjects() {
+ Set<Node> emptyObjects = listObjects(graphWith(""));
+ Graph g = graphWith("x P y; y Q z");
+ assertEquals(nodeSet("y z"), remove(listObjects(g), emptyObjects));
+ txnBegin(g);
+ g.delete(triple("x P y"));
+ txnCommit(g);
+ assertEquals(nodeSet("z"), remove(listObjects(g), emptyObjects));
+ }
+
+ protected Set<Node> listObjects(Graph g) {
+ return GraphUtil.listObjects(g, Node.ANY, Node.ANY).toSet();
+ }
+
+ @Test
+ public void testSubjectsFor() {
+ // First get the answer from the empty graph (not empty for an inf
+ // graph)
+ Graph b = graphWith("");
+ Set<Node> B = GraphUtil.listSubjects(b, Node.ANY, Node.ANY).toSet();
+
+ Graph g = graphWith("a P b; a Q c; a P d; b P x; c Q y");
+
+ testSubjects(g, B, Node.ANY, Node.ANY, node("a"), node("b"), node("c"));
+ testSubjects(g, B, node("P"), Node.ANY, node("a"), node("b"));
+ testSubjects(g, B, node("Q"), node("c"), node("a"));
+ testSubjects(g, B, node("Q"), node("y"), node("c"));
+ testSubjects(g, B, node("Q"), node("a"));
+ testSubjects(g, B, node("Q"), node("z"));
+ }
+
+ protected void testSubjects(Graph g, Collection<Node> exclude, Node p,
+ Node o, Node... expected) {
+ List<Node> R = GraphUtil.listSubjects(g, p, o).toList();
+ R.removeAll(exclude);
+ assertSameUnordered(R, exclude, expected);
+ }
+
+ @Test
+ public void testObjectsFor() {
+ // First get the answer from the empty graph (not empty for an inf
+ // graph)
+ Graph b = graphWith("");
+ Set<Node> B = GraphUtil.listObjects(b, Node.ANY, Node.ANY).toSet();
+
+ Graph g = graphWith("b P a; c Q a; d P a; x P b; y Q c");
+ testObjects(g, B, Node.ANY, Node.ANY, node("a"), node("b"), node("c"));
+ testObjects(g, B, Node.ANY, node("P"), node("a"), node("b"));
+ testObjects(g, B, node("c"), node("Q"), node("a"));
+ testObjects(g, B, node("y"), node("Q"), node("c"));
+ testObjects(g, B, node("a"), node("Q"));
+ testObjects(g, B, node("z"), node("Q"));
+ }
+
+ protected void testObjects(Graph g, Collection<Node> exclude, Node s,
+ Node p, Node... expected) {
+ List<Node> X = GraphUtil.listObjects(g, s, p).toList();
+ assertSameUnordered(X, exclude, expected);
+ }
+
+ @Test
+ public void testPredicatesFor() {
+ // First get the answer from the empty graph (not empty for an inf
+ // graph)
+ Graph b = graphWith("");
+ Set<Node> B = GraphUtil.listPredicates(b, Node.ANY, Node.ANY).toSet();
+
+ Graph g = graphWith("a P b; z P b; c Q d; e R f; g P b; h Q i");
+ testPredicates(g, B, Node.ANY, Node.ANY, node("P"), node("Q"),
+ node("R"));
+ testPredicates(g, B, Node.ANY, node("b"), node("P"));
+ testPredicates(g, B, node("g"), Node.ANY, node("P"));
+ testPredicates(g, B, node("c"), node("d"), node("Q"));
+ testPredicates(g, B, node("e"), node("f"), node("R"));
+ testPredicates(g, B, node("e"), node("a"));
+ testPredicates(g, B, node("z"), node("y"));
+ }
+
+ protected void testPredicates(Graph g, Collection<Node> exclude, Node s,
+ Node o, Node... expected) {
+ List<Node> X = GraphUtil.listPredicates(g, s, o).toList();
+ assertSameUnordered(X, exclude, expected);
+ }
+
+ @Test
+ public void testListObjectsNoRemove() {
+ Graph g = graphWith("a P b; b Q c; c R a");
+ Iterator<Node> it = GraphUtil.listObjects(g, Node.ANY, Node.ANY);
+ it.next();
+ try {
+ it.remove();
+ fail("listObjects for " + g.getClass()
+ + " should not support .remove()");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testListPredicatesNoRemove() {
+ Graph g = graphWith("a P b; b Q c; c R a");
+ Iterator<Node> it = GraphUtil.listPredicates(g, Node.ANY, Node.ANY);
+ it.next();
+ try {
+ it.remove();
+ fail("listPredicates for " + g.getClass()
+ + " should not support .remove()");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ protected void add(Graph toUpdate, Graph toAdd) {
+ txnBegin(toUpdate);
+ GraphUtil.addInto(toUpdate, toAdd);
+ txnCommit(toUpdate);
+ }
+
+ protected Graph remove(Graph toUpdate, Graph toRemove) {
+ txnBegin(toUpdate);
+ GraphUtil.deleteFrom(toUpdate, toRemove);
+ txnCommit(toUpdate);
+ return toUpdate;
+ }
+
+ protected Graph copy(Graph g) {
+ Graph result = memGraph();
+ txnBegin(result);
+ GraphUtil.addInto(result, g);
+ txnCommit(result);
+ return result;
+ }
+
+ @Test
+ public void testBulkUpdate() {
+ Graph g = memGraph();
+ Graph items = graphWith("pigs might fly; dead can dance");
+ int initialSize = g.size();
+ /* */
+ txnBegin(g);
+ GraphUtil.add(g, tripleArray);
+ txnCommit(g);
+ testContains(g, tripleArray);
+ testOmits(g, tripleList);
+ /* */
+ txnBegin(g);
+ GraphUtil.add(g, tripleList);
+ txnCommit(g);
+ testContains(g, tripleList);
+ testContains(g, tripleArray);
+ /* */
+ txnBegin(g);
+ GraphUtil.add(g, tripleSet.iterator());
+ txnCommit(g);
+ testContains(g, tripleSet.iterator());
+ testContains(g, tripleList);
+ testContains(g, tripleArray);
+ /* */
+ txnBegin(g);
+ GraphUtil.addInto(g, items);
+ txnCommit(g);
+ testContains(g, items);
+ testContains(g, tripleSet.iterator());
+ testContains(g, tripleArray);
+ testContains(g, tripleList);
+ /* */
+ txnBegin(g);
+ GraphUtil.delete(g, tripleArray);
+ txnCommit(g);
+ testOmits(g, tripleArray);
+ testContains(g, tripleList);
+ testContains(g, tripleSet.iterator());
+ testContains(g, items);
+ /* */
+ txnBegin(g);
+ GraphUtil.delete(g, tripleSet.iterator());
+ txnCommit(g);
+ testOmits(g, tripleSet.iterator());
+ testOmits(g, tripleArray);
+ testContains(g, tripleList);
+ testContains(g, items);
+ /* */
+ txnBegin(g);
+ GraphUtil.deleteFrom(g, items);
+ txnCommit(g);
+ testOmits(g, tripleSet.iterator());
+ testOmits(g, tripleArray);
+ testContains(g, tripleList);
+ testOmits(g, items);
+ /* */
+ txnBegin(g);
+ GraphUtil.delete(g, tripleList);
+ txnCommit(g);
+ assertEquals("graph has original size", initialSize, g.size());
+ }
+
+ /**
+ * Answer a set with all the elements of <code>A</code> except those in
+ * <code>B</code>.
+ */
+ private <T> Set<T> remove(Set<T> A, Set<T> B) {
+ Set<T> result = new HashSet<T>(A);
+ result.removeAll(B);
+ return result;
+ }
+
+ // Same - except for order
+ private void assertSameUnordered(List<Node> x1, Collection<Node> exclude,
+ Node[] expected) {
+ List<Node> x = new ArrayList<Node>();
+ x.addAll(x1);
+ x.removeAll(exclude);
+
+ assertEquals(expected.length, x.size());
+ Set<Node> X = new HashSet<Node>();
+ X.addAll(x);
+
+ Set<Node> R = new HashSet<Node>();
+ R.addAll(Arrays.asList(expected));
+
+ assertEquals(R, X);
+
+ }
+
+ @Test
+ public void testListSubjectsNoRemove() {
+ Graph g = graphWith("a P b; b Q c; c R a");
+ Iterator<Node> it = GraphUtil.listSubjects(g, Node.ANY, Node.ANY);
+ it.next();
+ try {
+ it.remove();
+ fail("listSubjects for " + g.getClass()
+ + " should not support .remove()");
+ } catch (UnsupportedOperationException expected) {
+ // expected result
+ }
+ }
+
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestNode.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestNode.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestNode.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestNode.java Wed Oct 9 17:16:15 2013
@@ -525,14 +525,14 @@ public class TestNode {
public void testNodeHelp() {
assertTrue("GraphTestUtils.node() making URIs",
GraphHelper.node("hello").isURI());
- assertTrue("GraphTestUtils.node() making literals", GraphHelper
- .node("123").isLiteral());
- assertTrue("GraphTestUtils.node() making literals", GraphHelper
- .node("'hello'").isLiteral());
+ assertTrue("GraphTestUtils.node() making literals",
+ GraphHelper.node("123").isLiteral());
+ assertTrue("GraphTestUtils.node() making literals",
+ GraphHelper.node("'hello'").isLiteral());
assertTrue("GraphTestUtils.node() making hyphens",
GraphHelper.node("_x").isBlank());
- assertTrue("GraphTestUtils.node() making variables", GraphHelper
- .node("?x").isVariable());
+ assertTrue("GraphTestUtils.node() making variables",
+ GraphHelper.node("?x").isVariable());
}
@Test
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestNodeToTriplesMap.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestNodeToTriplesMap.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestNodeToTriplesMap.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TestNodeToTriplesMap.java Wed Oct 9 17:16:15 2013
@@ -139,8 +139,7 @@ public class TestNodeToTriplesMap {
it.remove();
}
assertEquals(
- GraphHelper
- .tripleSet("x nice a; x nice c; y nice d; y nice f"),
+ GraphHelper.tripleSet("x nice a; x nice c; y nice d; y nice f"),
ntS.iterateAll().toSet());
}
Copied: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TransactionHandlerContractTest.java (from r1523135, jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/AbstractTransactionHandlerTest.java)
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TransactionHandlerContractTest.java?p2=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TransactionHandlerContractTest.java&p1=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/AbstractTransactionHandlerTest.java&r1=1523135&r2=1530718&rev=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/AbstractTransactionHandlerTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/TransactionHandlerContractTest.java Wed Oct 9 17:16:15 2013
@@ -18,24 +18,21 @@
package com.hp.hpl.jena.graph;
-import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.junit.Test;
+import org.xenei.junit.contract.Contract;
+
import static org.junit.Assert.*;
-import com.hp.hpl.jena.graph.Graph;
-import com.hp.hpl.jena.graph.GraphUtil;
import com.hp.hpl.jena.graph.TransactionHandler;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.shared.Command;
import com.hp.hpl.jena.shared.JenaException;
-import com.hp.hpl.jena.testing_framework.AbstractGraphProducerUser;
+import org.xenei.junit.contract.IProducer;
import com.hp.hpl.jena.util.CollectionFactory;
-import com.hp.hpl.jena.util.FileUtils;
-
import static com.hp.hpl.jena.testing_framework.GraphHelper.*;
/**
@@ -43,21 +40,11 @@ import static com.hp.hpl.jena.testing_fr
* to be a Graph. The abstract method getGraph must be overridden in subclasses
* to deliver a Graph of interest.
*/
+@Contract(TransactionHandler.class)
+public abstract class TransactionHandlerContractTest {
-public abstract class AbstractTransactionHandlerTest extends
- AbstractGraphProducerUser {
- protected Graph graphWithTxn(String s) {
- Graph g = getGraphProducer().newGraph();
- txnBegin(g);
- try {
- graphAdd(g, s);
- txnCommit(g);
- } catch (Exception e) {
- txnRollback(g);
- fail(e.getMessage());
- }
- return g;
- }
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ protected abstract IProducer<TransactionHandler> getTransactionHandlerProducer();
/**
* Test that Graphs have transaction support methods, and that if they fail
@@ -72,9 +59,7 @@ public abstract class AbstractTransactio
}
};
- Graph g = getGraphProducer().newGraph();
-
- TransactionHandler th = g.getTransactionHandler();
+ TransactionHandler th = getTransactionHandlerProducer().newInstance();
if (th.transactionsSupported()) {
th.begin();
@@ -110,8 +95,8 @@ public abstract class AbstractTransactio
@Test
public void testExecuteInTransactionCatchesThrowable() {
- Graph g = getGraphProducer().newGraph();
- TransactionHandler th = g.getTransactionHandler();
+ TransactionHandler th = getTransactionHandlerProducer().newInstance();
+
if (th.transactionsSupported()) {
Command cmd = new Command() {
@Override
@@ -137,63 +122,4 @@ public abstract class AbstractTransactio
static final Set<Triple> tripleSet = CollectionFactory
.createHashedSet(Arrays.asList(setTriples));
- @Test
- public void testTransactionCommit() {
- Graph g = getGraphProducer().newGraph();
- if (g.getTransactionHandler().transactionsSupported()) {
- Graph initial = graphWithTxn("initial hasValue 42; also hasURI hello");
- Graph extra = graphWithTxn("extra hasValue 17; also hasURI world");
-
- GraphUtil.addInto(g, initial);
- g.getTransactionHandler().begin();
- GraphUtil.addInto(g, extra);
- g.getTransactionHandler().commit();
- Graph union = graphWithTxn("");
- GraphUtil.addInto(union, initial);
- GraphUtil.addInto(union, extra);
- assertIsomorphic(union, g);
- // Model inFile = ModelFactory.createDefaultModel();
- // inFile.read( "file:///" + foo, "N-TRIPLES" );
- // assertIsomorphic( union, inFile.getGraph() );
- }
- }
-
- @Test
- public void testTransactionAbort() {
- Graph g = getGraphProducer().newGraph();
- if (g.getTransactionHandler().transactionsSupported()) {
- Graph initial = graphWithTxn("initial hasValue 42; also hasURI hello");
- Graph extra = graphWithTxn("extra hasValue 17; also hasURI world");
- File foo = FileUtils.tempFileName("fileGraph", ".n3");
- // Graph g = new FileGraph( foo, true, true );
- GraphUtil.addInto(g, initial);
- g.getTransactionHandler().begin();
- GraphUtil.addInto(g, extra);
- g.getTransactionHandler().abort();
- assertIsomorphic(initial, g);
- }
- }
-
- @Test
- public void testTransactionCommitThenAbort() {
- Graph g = getGraphProducer().newGraph();
- if (g.getTransactionHandler().transactionsSupported()) {
- Graph initial = graphWithTxn("A pings B; B pings C");
- Graph extra = graphWithTxn("C pingedBy B; fileGraph rdf:type Graph");
- // Graph g = getGraphProducer().newGraph();
- // File foo = FileUtils.tempFileName( "fileGraph", ".nt" );
- // Graph g = new FileGraph( foo, true, true );
- g.getTransactionHandler().begin();
- GraphUtil.addInto(g, initial);
- g.getTransactionHandler().commit();
- g.getTransactionHandler().begin();
- GraphUtil.addInto(g, extra);
- g.getTransactionHandler().abort();
- assertIsomorphic(initial, g);
- // Model inFile = ModelFactory.createDefaultModel();
- // inFile.read( "file:///" + foo, "N-TRIPLES" );
- // assertIsomorphic( initial, inFile.getGraph() );
- }
- }
-
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/AbstractDyadicTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/AbstractDyadicTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/AbstractDyadicTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/AbstractDyadicTest.java Wed Oct 9 17:16:15 2013
@@ -23,15 +23,24 @@ import static org.junit.Assert.*;
import java.util.StringTokenizer;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
-import com.hp.hpl.jena.graph.AbstractGraphTest;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.TripleMatch;
+import org.xenei.junit.contract.IProducer;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.util.iterator.NiceIterator;
-public abstract class AbstractDyadicTest extends AbstractGraphTest {
+@RunWith(ContractSuite.class)
+@ContractImpl(Dyadic.class)
+public abstract class AbstractDyadicTest {
+
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public abstract IProducer<? extends Dyadic> getGraphProducer();
static private NiceIterator<String> things(final String x) {
return new NiceIterator<String>() {
@@ -69,8 +78,8 @@ public abstract class AbstractDyadicTest
@Test
public void testDyadicOperands() {
- Graph g = getGraphProducer().newGraph(), h = getGraphProducer()
- .newGraph();
+ Graph g = getGraphProducer().newInstance(), h = getGraphProducer()
+ .newInstance();
Dyadic d = new Dyadic(g, h) {
@Override
protected ExtendedIterator<Triple> _graphBaseFind(TripleMatch m) {
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DeltaSuite.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DeltaSuite.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DeltaSuite.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DeltaSuite.java Wed Oct 9 17:16:15 2013
@@ -22,7 +22,6 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import com.hp.hpl.jena.graph.AbstractGraphSuite;
-import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
@@ -31,9 +30,9 @@ public class DeltaSuite extends Abstract
@BeforeClass
public static void beforeClass() {
- setGraphProducer(new AbstractGraphProducer() {
+ setGraphProducer(new AbstractGraphProducer<Delta>() {
@Override
- protected Graph createNewGraph() {
+ protected Delta createNewGraph() {
return new Delta(GraphFactory.createGraphMem());
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DeltaTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DeltaTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DeltaTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DeltaTest.java Wed Oct 9 17:16:15 2013
@@ -21,39 +21,47 @@ package com.hp.hpl.jena.graph.compose;
import static com.hp.hpl.jena.testing_framework.GraphHelper.*;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
-import com.hp.hpl.jena.testing_framework.GraphProducerInterface;
+import org.xenei.junit.contract.IProducer;
+@SuppressWarnings("deprecation")
+@RunWith(ContractSuite.class)
+@ContractImpl(Delta.class)
public class DeltaTest extends AbstractDyadicTest {
- private GraphProducerInterface graphProducer = new AbstractGraphProducer() {
+
+ private IProducer<Delta> graphProducer = new AbstractGraphProducer<Delta>() {
@Override
- protected Graph createNewGraph() {
+ protected Delta createNewGraph() {
return new Delta(GraphFactory.createGraphMem());
}
};
@Override
- public GraphProducerInterface getGraphProducer() {
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<Delta> getGraphProducer() {
return graphProducer;
}
@Test
public void testDelta() {
- Graph x = graphWithTxn("x R y");
+ Graph x = graphWith(getGraphProducer().newInstance(), "x R y");
assertContains("x", "x R y", x);
x.delete(triple("x R y"));
assertOmits("x", x, "x R y");
/* */
Graph base = graphWith("x R y; p S q; I like cheese; pins pop balloons");
- Graph save = graphWith("x R y; p S q; I like cheese; pins pop balloons");
Delta delta = new Delta(base);
assertContainsAll("Delta", delta,
"x R y; p S q; I like cheese; pins pop balloons");
- assertContainsAll("Delta", base,
+ assertContainsAll("Base", base,
"x R y; p S q; I like cheese; pins pop balloons");
/* */
delta.add(triple("pigs fly winglessly"));
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DifferenceSuite.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DifferenceSuite.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DifferenceSuite.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DifferenceSuite.java Wed Oct 9 17:16:15 2013
@@ -22,18 +22,18 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import com.hp.hpl.jena.graph.AbstractGraphSuite;
-import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
@RunWith(Suite.class)
public class DifferenceSuite extends AbstractGraphSuite {
+ @SuppressWarnings("deprecation")
@BeforeClass
public static void beforeClass() {
- setGraphProducer(new AbstractGraphProducer() {
+ setGraphProducer(new AbstractGraphProducer<Difference>() {
@Override
- protected Graph createNewGraph() {
+ protected Difference createNewGraph() {
return new Difference(GraphFactory.createGraphMem(),
GraphFactory.createGraphMem());
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DifferenceTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DifferenceTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DifferenceTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DifferenceTest.java Wed Oct 9 17:16:15 2013
@@ -22,26 +22,25 @@ import static com.hp.hpl.jena.testing_fr
import static org.junit.Assert.*;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.compose.Difference;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
-import com.hp.hpl.jena.testing_framework.GraphProducerInterface;
+import org.xenei.junit.contract.IProducer;
@SuppressWarnings("deprecation")
+@RunWith(ContractSuite.class)
+@ContractImpl(Difference.class)
public class DifferenceTest extends AbstractDyadicTest {
- private GraphProducerInterface graphProducer = new AbstractGraphProducer() {
+
+ private IProducer<Difference> graphProducer = new AbstractGraphProducer<Difference>() {
@Override
- protected Graph createNewGraph() {
- // Graph g1 = graphWith(GraphFactory.createGraphMem(),
- // "x R y; p R q");
- // Graph g2 = graphWith(GraphFactory.createGraphMem(),
- // "r A s; x R y");
- // Graph g1 = graphWith(GraphFactory.createGraphMem(),
- // "x R y; p R q");
- // Graph g2 = graphWith(GraphFactory.createGraphMem(),
- // "r A s; x R y");
+ protected Difference createNewGraph() {
return new Difference(GraphFactory.createGraphMem(),
GraphFactory.createGraphMem());
}
@@ -49,7 +48,8 @@ public class DifferenceTest extends Abst
};
@Override
- public GraphProducerInterface getGraphProducer() {
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<Difference> getGraphProducer() {
return graphProducer;
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DisjointUnionSuite.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DisjointUnionSuite.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DisjointUnionSuite.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DisjointUnionSuite.java Wed Oct 9 17:16:15 2013
@@ -22,7 +22,6 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import com.hp.hpl.jena.graph.AbstractGraphSuite;
-import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
@@ -31,9 +30,9 @@ public class DisjointUnionSuite extends
@BeforeClass
public static void beforeClass() {
- setGraphProducer(new AbstractGraphProducer() {
+ setGraphProducer(new AbstractGraphProducer<DisjointUnion>() {
@Override
- protected Graph createNewGraph() {
+ protected DisjointUnion createNewGraph() {
return new DisjointUnion(GraphFactory.createGraphMem(),
GraphFactory.createGraphMem());
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DisjointUnionTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DisjointUnionTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DisjointUnionTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/DisjointUnionTest.java Wed Oct 9 17:16:15 2013
@@ -22,27 +22,36 @@ import static com.hp.hpl.jena.testing_fr
import static org.junit.Assert.*;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.compose.DisjointUnion;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
-import com.hp.hpl.jena.testing_framework.GraphProducerInterface;
+import org.xenei.junit.contract.IProducer;
/**
* TestDisjointUnion - test that DisjointUnion works, as well as we can.
*/
+@RunWith(ContractSuite.class)
+@ContractImpl(DisjointUnion.class)
public class DisjointUnionTest extends AbstractDyadicTest {
- private GraphProducerInterface graphProducer = new AbstractGraphProducer() {
+
+ private IProducer<DisjointUnion> graphProducer = new AbstractGraphProducer<DisjointUnion>() {
@Override
- protected Graph createNewGraph() {
+ protected DisjointUnion createNewGraph() {
return new DisjointUnion(GraphFactory.createGraphMem(),
GraphFactory.createGraphMem());
}
+
};
@Override
- public GraphProducerInterface getGraphProducer() {
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<DisjointUnion> getGraphProducer() {
return graphProducer;
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/IntersectionSuite.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/IntersectionSuite.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/IntersectionSuite.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/IntersectionSuite.java Wed Oct 9 17:16:15 2013
@@ -22,19 +22,19 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import com.hp.hpl.jena.graph.AbstractGraphSuite;
-import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
@RunWith(Suite.class)
public class IntersectionSuite extends AbstractGraphSuite {
+ @SuppressWarnings("deprecation")
@BeforeClass
public static void beforeClass() {
- setGraphProducer(new AbstractGraphProducer() {
+ setGraphProducer(new AbstractGraphProducer<Intersection>() {
@SuppressWarnings("deprecation")
@Override
- protected Graph createNewGraph() {
+ protected Intersection createNewGraph() {
return new Intersection(GraphFactory.createGraphMem(),
GraphFactory.createGraphMem());
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/IntersectionTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/IntersectionTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/IntersectionTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/IntersectionTest.java Wed Oct 9 17:16:15 2013
@@ -22,19 +22,26 @@ import static com.hp.hpl.jena.testing_fr
import static org.junit.Assert.*;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphUtil;
import com.hp.hpl.jena.graph.compose.Intersection;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
-import com.hp.hpl.jena.testing_framework.GraphProducerInterface;
+import org.xenei.junit.contract.IProducer;
@SuppressWarnings("deprecation")
+@RunWith(ContractSuite.class)
+@ContractImpl(Intersection.class)
public class IntersectionTest extends AbstractDyadicTest {
- private GraphProducerInterface graphProducer = new AbstractGraphProducer() {
+
+ private IProducer<? extends Intersection> graphProducer = new AbstractGraphProducer<Intersection>() {
@Override
- protected Graph createNewGraph() {
+ protected Intersection createNewGraph() {
return new Intersection(GraphFactory.createGraphMem(),
GraphFactory.createGraphMem());
}
@@ -42,8 +49,9 @@ public class IntersectionTest extends Ab
};
@Override
- public GraphProducerInterface getGraphProducer() {
- return graphProducer;
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<Intersection> getGraphProducer() {
+ return (IProducer<Intersection>) graphProducer;
}
@Test
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionReifierTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionReifierTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionReifierTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionReifierTest.java Wed Oct 9 17:16:15 2013
@@ -24,43 +24,38 @@ import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
-
-import com.hp.hpl.jena.graph.AbstractReifierTest;
import com.hp.hpl.jena.graph.Factory;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphUtil;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.NodeFactory;
+import com.hp.hpl.jena.graph.ReifierTest;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.compose.MultiUnion;
import com.hp.hpl.jena.rdf.model.impl.ReifierStd;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
-import com.hp.hpl.jena.testing_framework.GraphProducerInterface;
import com.hp.hpl.jena.testing_framework.NodeCreateUtils;
import com.hp.hpl.jena.vocabulary.RDF;
/**
* Test the reifier for multi-unions.
*/
-public class MultiUnionReifierTest extends AbstractReifierTest {
- private GraphProducerInterface graphProducer = new AbstractGraphProducer() {
- @Override
- protected Graph createNewGraph() {
- Graph gBase = GraphFactory.createDefaultGraph();
- Graph g1 = GraphFactory.createDefaultGraph();
- Graph g2 = GraphFactory.createDefaultGraph();
- MultiUnion poly = new MultiUnion(new Graph[] { gBase, g1, g2 });
- poly.setBaseGraph(gBase);
- return poly;
-
- }
- };
+public class MultiUnionReifierTest extends ReifierTest {
- @Override
- public GraphProducerInterface getGraphProducer() {
- return graphProducer;
+ public MultiUnionReifierTest() {
+ graphProducer = new AbstractGraphProducer<MultiUnion>() {
+ @Override
+ protected MultiUnion createNewGraph() {
+ Graph gBase = GraphFactory.createDefaultGraph();
+ Graph g1 = GraphFactory.createDefaultGraph();
+ Graph g2 = GraphFactory.createDefaultGraph();
+ MultiUnion poly = new MultiUnion(new Graph[] { gBase, g1, g2 });
+ poly.setBaseGraph(gBase);
+ return poly;
+ }
+ };
}
@Test
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionSuite.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionSuite.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionSuite.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionSuite.java Wed Oct 9 17:16:15 2013
@@ -31,16 +31,15 @@ public class MultiUnionSuite extends Abs
@BeforeClass
public static void beforeClass() {
- setGraphProducer(new AbstractGraphProducer() {
+ setGraphProducer(new AbstractGraphProducer<MultiUnion>() {
@Override
- protected Graph createNewGraph() {
+ protected MultiUnion createNewGraph() {
Graph gBase = GraphFactory.createDefaultGraph();
Graph g1 = GraphFactory.createDefaultGraph();
Graph g2 = GraphFactory.createDefaultGraph();
MultiUnion poly = new MultiUnion(new Graph[] { gBase, g1, g2 });
poly.setBaseGraph(gBase);
return poly;
-
}
});
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/MultiUnionTest.java Wed Oct 9 17:16:15 2013
@@ -30,8 +30,11 @@ import java.util.Iterator;
import java.util.List;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
-import com.hp.hpl.jena.graph.AbstractGraphTest;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
import com.hp.hpl.jena.graph.compose.MultiUnion;
@@ -41,7 +44,7 @@ import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
-import com.hp.hpl.jena.testing_framework.GraphProducerInterface;
+import org.xenei.junit.contract.IProducer;
import com.hp.hpl.jena.testing_framework.TestUtils;
/**
@@ -49,20 +52,22 @@ import com.hp.hpl.jena.testing_framework
* Unit tests for multi-union graph.
* </p>
*/
-public class MultiUnionTest extends AbstractGraphTest {
+@RunWith(ContractSuite.class)
+@ContractImpl(MultiUnion.class)
+public class MultiUnionTest {
+
+ public IProducer<MultiUnion> producer = new AbstractGraphProducer<MultiUnion>() {
+ @Override
+ protected MultiUnion createNewGraph() {
+ return new MultiUnion(new Graph[] { GraphFactory.createGraphMem(),
+ GraphFactory.createGraphMem() });
- @Override
- public GraphProducerInterface getGraphProducer() {
- return new AbstractGraphProducer() {
- @Override
- protected Graph createNewGraph() {
- return new MultiUnion(new Graph[] {
- GraphFactory.createGraphMem(),
- GraphFactory.createGraphMem() });
-
- }
+ }
+ };
- };
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<? extends MultiUnion> getGraphProducer() {
+ return producer;
}
// External signature methods
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/PolyadicPrefixMappingTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/PolyadicPrefixMappingTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/PolyadicPrefixMappingTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/PolyadicPrefixMappingTest.java Wed Oct 9 17:16:15 2013
@@ -25,60 +25,106 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
-import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mockito;
+import org.xenei.junit.contract.Contract.Inject;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
+
import com.hp.hpl.jena.graph.Graph;
-import com.hp.hpl.jena.shared.AbstractPrefixMappingTest;
import com.hp.hpl.jena.shared.PrefixMapping;
import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
+import org.xenei.junit.contract.IProducer;
-public class PolyadicPrefixMappingTest extends AbstractPrefixMappingTest {
- private Polyadic poly;
- private Graph gBase;
- private PrefixMapping gBaseMapping;
- private Graph g1;
- private PrefixMapping g1Mapping;
- private Graph g2;
- private PrefixMapping g2Mapping;
- private PolyadicPrefixMappingImpl prefixMapping;
-
- @Before
- public void setup() {
- gBase = mock(Graph.class);
- gBaseMapping = mock(PrefixMapping.class);
- when(gBase.getPrefixMapping()).thenReturn(gBaseMapping);
- g1 = Mockito.mock(Graph.class);
- g1Mapping = mock(PrefixMapping.class);
- when(g1.getPrefixMapping()).thenReturn(g1Mapping);
- g2 = Mockito.mock(Graph.class);
- g2Mapping = mock(PrefixMapping.class);
- when(g2.getPrefixMapping()).thenReturn(g2Mapping);
- poly = mock(Polyadic.class);
- when(poly.getBaseGraph()).thenReturn(gBase);
- when(poly.getSubGraphs()).thenReturn(
- Arrays.asList(new Graph[] { g1, g2 }));
- prefixMapping = new PolyadicPrefixMappingImpl(poly);
- when(poly.getPrefixMapping()).thenReturn(prefixMapping);
-
- }
+@RunWith(ContractSuite.class)
+@ContractImpl(PolyadicPrefixMappingImpl.class)
+public class PolyadicPrefixMappingTest {
+
+ private PolyadicPrefixMappingProducer producer = new PolyadicPrefixMappingProducer();
+
+ private class PolyadicPrefixMappingProducer implements
+ IProducer<PolyadicPrefixMappingImpl> {
+ Map<PolyadicPrefixMappingImpl, Map<String, PrefixMapping>> pmMap = new HashMap<PolyadicPrefixMappingImpl, Map<String, PrefixMapping>>();
+
+ @Override
+ public PolyadicPrefixMappingImpl newInstance() {
+ Map<String, PrefixMapping> polyMap = new HashMap<String, PrefixMapping>();
+ Graph gBase = mock(Graph.class);
+ PrefixMappingImpl gBasePfx = new PrefixMappingImpl();
+ polyMap.put("gBasePfx", gBasePfx);
+ when(gBase.getPrefixMapping()).thenReturn(gBasePfx);
+ Graph g1 = Mockito.mock(Graph.class);
+ PrefixMappingImpl g1Pfx = new PrefixMappingImpl();
+ polyMap.put("g1Pfx", g1Pfx);
+ when(g1.getPrefixMapping()).thenReturn(g1Pfx);
+ Graph g2 = Mockito.mock(Graph.class);
+ PrefixMappingImpl g2Pfx = new PrefixMappingImpl();
+ polyMap.put("g2Pfx", g2Pfx);
+ when(g2.getPrefixMapping()).thenReturn(g2Pfx);
+ Polyadic poly = mock(Polyadic.class);
+ when(poly.getBaseGraph()).thenReturn(gBase);
+ when(poly.getSubGraphs()).thenReturn(
+ Arrays.asList(new Graph[] { g1, g2 }));
+ PolyadicPrefixMappingImpl retval = new PolyadicPrefixMappingImpl(
+ poly);
+ pmMap.put(retval, polyMap);
+ return retval;
+ }
+
+ @Override
+ public void cleanUp() {
+ pmMap = new HashMap<PolyadicPrefixMappingImpl, Map<String, PrefixMapping>>();
+ }
+
+ public PrefixMapping getPM(PolyadicPrefixMappingImpl poly, String val) {
+ Map<String, PrefixMapping> polyMap = pmMap.get(poly);
+ return polyMap == null ? null : polyMap.get(val);
+ }
+
+ };
+
+ @Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public PolyadicPrefixMappingProducer getMappingProducer() {
+ return producer;
+ }
+
+ // @Before
+ // public final void setupPolyadicPrefixMappingTest() {
+ // gBase = mock(Graph.class);
+ // gBaseMapping = mock(PrefixMapping.class);
+ // when(gBase.getPrefixMapping()).thenReturn(gBaseMapping);
+ // g1 = Mockito.mock(Graph.class);
+ // g1Mapping = mock(PrefixMapping.class);
+ // when(g1.getPrefixMapping()).thenReturn(g1Mapping);
+ // g2 = Mockito.mock(Graph.class);
+ // g2Mapping = mock(PrefixMapping.class);
+ // when(g2.getPrefixMapping()).thenReturn(g2Mapping);
+ // poly = mock(Polyadic.class);
+ // when(poly.getBaseGraph()).thenReturn(gBase);
+ // when(poly.getSubGraphs()).thenReturn(
+ // Arrays.asList(new Graph[] { g1, g2 }));
+ // prefixMapping = new PolyadicPrefixMappingImpl(poly);
+ // when(poly.getPrefixMapping()).thenReturn(prefixMapping);
+ //
+ // }
// PolyadicPrefixMappingImpl
- @Override
- protected PrefixMapping getMapping() {
- PrefixMappingImpl pfx = new PrefixMappingImpl();
- Graph gBase = mock(Graph.class);
- when(gBase.getPrefixMapping()).thenReturn(new PrefixMappingImpl());
- Graph g1 = Mockito.mock(Graph.class);
- when(g1.getPrefixMapping()).thenReturn(new PrefixMappingImpl());
- Graph g2 = Mockito.mock(Graph.class);
- when(g2.getPrefixMapping()).thenReturn(new PrefixMappingImpl());
- poly = mock(Polyadic.class);
- when(poly.getBaseGraph()).thenReturn(gBase);
- when(poly.getSubGraphs()).thenReturn(
- Arrays.asList(new Graph[] { g1, g2 }));
- return new PolyadicPrefixMappingImpl(poly);
- }
+ // @Override
+ // protected PrefixMapping getMapping() {
+ // PrefixMappingImpl pfx = new PrefixMappingImpl();
+ // Graph gBase = mock(Graph.class);
+ // when(gBase.getPrefixMapping()).thenReturn(new PrefixMappingImpl());
+ // Graph g1 = Mockito.mock(Graph.class);
+ // when(g1.getPrefixMapping()).thenReturn(new PrefixMappingImpl());
+ // Graph g2 = Mockito.mock(Graph.class);
+ // when(g2.getPrefixMapping()).thenReturn(new PrefixMappingImpl());
+ // poly = mock(Polyadic.class);
+ // when(poly.getBaseGraph()).thenReturn(gBase);
+ // when(poly.getSubGraphs()).thenReturn(
+ // Arrays.asList(new Graph[] { g1, g2 }));
+ // return new PolyadicPrefixMappingImpl(poly);
+ // }
protected static final String alpha = "something:alpha#";
protected static final String beta = "something:beta#";
@@ -90,37 +136,62 @@ public class PolyadicPrefixMappingTest e
*/
@Test
public void testOnlyBaseMutated() {
- prefixMapping.setNsPrefix("a", alpha);
- verify(g1Mapping, times(0)).setNsPrefix(anyString(), anyString());
- verify(g2Mapping, times(0)).setNsPrefix(anyString(), anyString());
- verify(gBaseMapping, times(1)).setNsPrefix(anyString(), anyString());
- verify(gBaseMapping, times(1)).setNsPrefix("a", alpha);
+ PolyadicPrefixMappingImpl pm = getMappingProducer().newInstance();
+ pm.setNsPrefix("a", alpha);
+
+ PrefixMapping gpm = getMappingProducer().getPM(pm, "g1Pfx");
+ assertNotNull(gpm);
+ assertTrue(gpm.getNsPrefixMap().isEmpty());
+
+ gpm = getMappingProducer().getPM(pm, "g2Pfx");
+ assertNotNull(gpm);
+ assertTrue(gpm.getNsPrefixMap().isEmpty());
+
+ gpm = getMappingProducer().getPM(pm, "gBasePfx");
+ assertNotNull(gpm);
+ assertEquals(alpha, gpm.getNsPrefixMap().get("a"));
}
@Test
public void testUpdatesVisible() {
- when(g1Mapping.getNsPrefixURI("a")).thenReturn(alpha);
- when(g2Mapping.getNsPrefixURI("b")).thenReturn(beta);
+ PolyadicPrefixMappingImpl prefixMapping = getMappingProducer()
+ .newInstance();
+ PrefixMapping gpm = getMappingProducer().getPM(prefixMapping, "g1Pfx");
+ gpm.setNsPrefix("a", alpha);
+
+ gpm = getMappingProducer().getPM(prefixMapping, "g2Pfx");
+ gpm.setNsPrefix("b", beta);
+
assertEquals(alpha, prefixMapping.getNsPrefixURI("a"));
assertEquals(beta, prefixMapping.getNsPrefixURI("b"));
- verify(gBaseMapping, times(1)).getNsPrefixURI("a");
- verify(gBaseMapping, times(1)).getNsPrefixURI("b");
+
}
@Test
public void testUpdatesOverridden() {
- when(g1Mapping.getNsPrefixURI("x")).thenReturn(alpha);
- when(gBaseMapping.getNsPrefixURI("x")).thenReturn(beta);
- assertEquals(beta, poly.getPrefixMapping().getNsPrefixURI("x"));
+ PolyadicPrefixMappingImpl prefixMapping = getMappingProducer()
+ .newInstance();
+ PrefixMapping gpm = getMappingProducer().getPM(prefixMapping, "g1Pfx");
+ gpm.setNsPrefix("x", alpha);
+
+ gpm = getMappingProducer().getPM(prefixMapping, "gBasePfx");
+ gpm.setNsPrefix("x", beta);
+
+ assertEquals(beta, prefixMapping.getNsPrefixURI("x"));
}
@Test
public void testQNameComponents() {
- when(g1Mapping.qnameFor(alpha + "hoop")).thenReturn("x:hoop");
- when(g2Mapping.qnameFor(beta + "lens")).thenReturn("y:lens");
+ PolyadicPrefixMappingImpl prefixMapping = getMappingProducer()
+ .newInstance();
+ PrefixMapping gpm = getMappingProducer().getPM(prefixMapping, "g1Pfx");
+ gpm.setNsPrefix("x", alpha);
- assertEquals("x:hoop", poly.getPrefixMapping().qnameFor(alpha + "hoop"));
- assertEquals("y:lens", poly.getPrefixMapping().qnameFor(beta + "lens"));
+ gpm = getMappingProducer().getPM(prefixMapping, "g2Pfx");
+ gpm.setNsPrefix("y", beta);
+
+ assertEquals("x:hoop", prefixMapping.qnameFor(alpha + "hoop"));
+ assertEquals("y:lens", prefixMapping.qnameFor(beta + "lens"));
}
/**
@@ -131,56 +202,55 @@ public class PolyadicPrefixMappingTest e
public void testSubgraphsDontPolluteDefaultPrefix() {
String imported = "http://imported#", local = "http://local#";
- Map<String, String> g1Map = new HashMap<String, String>();
- g1Map.put("", imported);
-
- Map<String, String> g2Map = new HashMap<String, String>();
- g2Map.put("", local);
+ PolyadicPrefixMappingImpl prefixMapping = getMappingProducer()
+ .newInstance();
+ PrefixMapping gpm = getMappingProducer().getPM(prefixMapping, "g1Pfx");
+ gpm.setNsPrefix("", imported);
- when(g1Mapping.getNsPrefixMap()).thenReturn(g1Map);
- when(gBaseMapping.getNsPrefixMap()).thenReturn(g2Map);
+ gpm = getMappingProducer().getPM(prefixMapping, "g2Pfx");
+ gpm.setNsPrefix("", local);
- assertEquals(null, poly.getPrefixMapping().getNsURIPrefix(imported));
+ assertEquals(null, prefixMapping.getNsURIPrefix(imported));
}
@Test
public void testPolyDoesntSeeImportedDefaultPrefix() {
String imported = "http://imported#";
- Map<String, String> g1Map = new HashMap<String, String>();
- g1Map.put("", imported);
- when(g1Mapping.getNsPrefixMap()).thenReturn(g1Map);
- assertEquals(null, poly.getPrefixMapping().getNsPrefixURI(""));
+ PolyadicPrefixMappingImpl prefixMapping = getMappingProducer()
+ .newInstance();
+ PrefixMapping gpm = getMappingProducer().getPM(prefixMapping, "g1Pfx");
+ gpm.setNsPrefix("", imported);
+
+ assertEquals(null, prefixMapping.getNsPrefixURI(""));
}
@Test
public void testPolyMapOverridesFromTheLeft() {
- Map<String, String> g1Map = new HashMap<String, String>();
- g1Map.put("a", "eh:/U1");
-
- Map<String, String> g2Map = new HashMap<String, String>();
- g2Map.put("a", "eh:/U2");
+ PolyadicPrefixMappingImpl prefixMapping = getMappingProducer()
+ .newInstance();
+ PrefixMapping gpm = getMappingProducer().getPM(prefixMapping, "g1Pfx");
+ gpm.setNsPrefix("a", "eh:/U1");
- when(g1Mapping.getNsPrefixMap()).thenReturn(g1Map);
- when(g2Mapping.getNsPrefixMap()).thenReturn(g2Map);
+ gpm = getMappingProducer().getPM(prefixMapping, "g2Pfx");
+ gpm.setNsPrefix("a", "eh:/U2");
- String a = poly.getPrefixMapping().getNsPrefixMap().get("a");
+ String a = prefixMapping.getNsPrefixMap().get("a");
assertEquals("eh:/U1", a);
}
@Test
public void testPolyMapHandlesBase() {
- Map<String, String> g1Map = new HashMap<String, String>();
- g1Map.put("", "eh:/U1");
-
- Map<String, String> g2Map = new HashMap<String, String>();
- g2Map.put("", "eh:/U2");
+ PolyadicPrefixMappingImpl prefixMapping = getMappingProducer()
+ .newInstance();
+ PrefixMapping gpm = getMappingProducer().getPM(prefixMapping, "g1Pfx");
+ gpm.setNsPrefix("", "eh:/U1");
- when(g1Mapping.getNsPrefixMap()).thenReturn(g1Map);
- when(g2Mapping.getNsPrefixMap()).thenReturn(g2Map);
+ gpm = getMappingProducer().getPM(prefixMapping, "g2Pfx");
+ gpm.setNsPrefix("", "eh:/U2");
- String a = poly.getPrefixMapping().getNsPrefixMap().get("");
- assertEquals(poly.getPrefixMapping().getNsPrefixURI(""), a);
+ String a = prefixMapping.getNsPrefixMap().get("");
+ assertEquals(prefixMapping.getNsPrefixURI(""), a);
}
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/UnionTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/UnionTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/UnionTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/compose/UnionTest.java Wed Oct 9 17:16:15 2013
@@ -22,6 +22,10 @@ import static com.hp.hpl.jena.testing_fr
import static org.junit.Assert.*;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
@@ -32,13 +36,16 @@ import com.hp.hpl.jena.graph.compose.Uni
import com.hp.hpl.jena.graph.impl.GraphBase;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
-import com.hp.hpl.jena.testing_framework.GraphProducerInterface;
+import org.xenei.junit.contract.IProducer;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+@RunWith(ContractSuite.class)
+@ContractImpl(Union.class)
public class UnionTest extends AbstractDyadicTest {
- private GraphProducerInterface graphProducer = new AbstractGraphProducer() {
+
+ private IProducer<Union> graphProducer = new AbstractGraphProducer<Union>() {
@Override
- protected Graph createNewGraph() {
+ protected Union createNewGraph() {
Graph g1 = GraphFactory.createGraphMem();
Graph g2 = GraphFactory.createGraphMem();
return new Union(g1, g2);
@@ -47,7 +54,8 @@ public class UnionTest extends AbstractD
};
@Override
- public GraphProducerInterface getGraphProducer() {
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<Union> getGraphProducer() {
return graphProducer;
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/CollectionGraphSuite.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/CollectionGraphSuite.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/CollectionGraphSuite.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/CollectionGraphSuite.java Wed Oct 9 17:16:15 2013
@@ -23,9 +23,7 @@ import java.util.HashSet;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
-
import com.hp.hpl.jena.graph.AbstractGraphSuite;
-import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.impl.CollectionGraph;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
@@ -38,9 +36,10 @@ public class CollectionGraphSuite extend
setGraphProducer(new GraphProducer());
}
- public static class GraphProducer extends AbstractGraphProducer {
+ public static class GraphProducer extends
+ AbstractGraphProducer<CollectionGraph> {
@Override
- public Graph createNewGraph() {
+ public CollectionGraph createNewGraph() {
return new CollectionGraph(new HashSet<Triple>());
}
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/CollectionGraphTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/CollectionGraphTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/CollectionGraphTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/CollectionGraphTest.java Wed Oct 9 17:16:15 2013
@@ -20,27 +20,32 @@ package com.hp.hpl.jena.graph.impl;
import java.util.HashSet;
-import com.hp.hpl.jena.graph.AbstractGraphTest;
-import com.hp.hpl.jena.graph.Graph;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
+import org.xenei.junit.contract.Contract.Inject;
+
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.impl.CollectionGraph;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
-import com.hp.hpl.jena.testing_framework.GraphProducerInterface;
-
-public class CollectionGraphTest extends AbstractGraphTest {
+import org.xenei.junit.contract.IProducer;
- private GraphProducerInterface graphProducer = new GraphProducer();
+@RunWith(ContractSuite.class)
+@ContractImpl(CollectionGraph.class)
+public class CollectionGraphTest {
- @Override
- public GraphProducerInterface getGraphProducer() {
- return graphProducer;
- }
+ protected IProducer<CollectionGraph> graphProducer = new AbstractGraphProducer<CollectionGraph>() {
- public static class GraphProducer extends AbstractGraphProducer {
@Override
- public Graph createNewGraph() {
+ protected CollectionGraph createNewGraph() {
return new CollectionGraph(new HashSet<Triple>());
}
+
+ };
+
+ @Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<CollectionGraph> getGraphProducer() {
+ return graphProducer;
}
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphMakerTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphMakerTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphMakerTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphMakerTest.java Wed Oct 9 17:16:15 2013
@@ -19,32 +19,60 @@
package com.hp.hpl.jena.graph.impl;
import java.io.File;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
import static org.junit.Assert.*;
import static com.hp.hpl.jena.testing_framework.GraphHelper.*;
-import com.hp.hpl.jena.graph.AbstractGraphMakerTest;
import com.hp.hpl.jena.graph.Graph;
-import com.hp.hpl.jena.graph.GraphMaker;
import com.hp.hpl.jena.graph.GraphUtil;
import com.hp.hpl.jena.graph.impl.FileGraph;
import com.hp.hpl.jena.graph.impl.FileGraphMaker;
+import org.xenei.junit.contract.IProducer;
import com.hp.hpl.jena.util.FileUtils;
/**
* Test a FileGraphMaker; use the abstract tests, plus specialised ones for the
* name conversion routines.
*/
-public class FileGraphMakerTest extends AbstractGraphMakerTest {
-
- @Override
- public GraphMaker getGraphMaker() {
- String scratch = FileUtils.getScratchDirectory(
- "jena-test-FileGraphMaker").getPath();
- return new FileGraphMaker(scratch, true);
+@RunWith(ContractSuite.class)
+@ContractImpl(FileGraphMaker.class)
+public class FileGraphMakerTest {
+
+ private IProducer<FileGraphMaker> producer = new IProducer<FileGraphMaker>() {
+
+ List<FileGraphMaker> constructed = new ArrayList<FileGraphMaker>();
+
+ @Override
+ public FileGraphMaker newInstance() {
+ String scratch = FileUtils.getScratchDirectory(
+ "jena-test-FileGraphMaker").getPath();
+ FileGraphMaker retval = new FileGraphMaker(scratch, true);
+ constructed.add(retval);
+ return retval;
+ }
+
+ @Override
+ public void cleanUp() {
+ for (FileGraphMaker fgm : constructed) {
+ fgm.close();
+ }
+ constructed = new ArrayList<FileGraphMaker>();
+
+ }
+ };
+
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<FileGraphMaker> getGraphMakerProducer() {
+ return producer;
}
@Test
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphSuite.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphSuite.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphSuite.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphSuite.java Wed Oct 9 17:16:15 2013
@@ -25,12 +25,12 @@ import java.util.List;
import static org.junit.Assert.*;
+import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Suite;
import org.junit.runners.Parameterized.Parameters;
-
import static com.hp.hpl.jena.testing_framework.GraphHelper.*;
import com.hp.hpl.jena.graph.Graph;
@@ -39,8 +39,6 @@ import com.hp.hpl.jena.graph.impl.FileGr
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
-import com.hp.hpl.jena.testing_framework.AbstractGraphProducerUser;
-import com.hp.hpl.jena.testing_framework.GraphProducerInterface;
import com.hp.hpl.jena.util.FileUtils;
/**
@@ -53,7 +51,7 @@ import com.hp.hpl.jena.util.FileUtils;
FileGraphSuite.FileNameTransactionTests.class })
public class FileGraphSuite {
- public static class GraphProducer extends AbstractGraphProducer {
+ public static class GraphProducer extends AbstractGraphProducer<FileGraph> {
private String suffix = ".nt";
private String prefix = "tfg";
private boolean strict = true;
@@ -76,15 +74,13 @@ public class FileGraphSuite {
}
@Override
- protected Graph createNewGraph() {
+ protected FileGraph createNewGraph() {
File foo = FileUtils.tempFileName(prefix, suffix);
- foo.deleteOnExit();
return new FileGraph(foo, true, strict);
}
final public FileGraph newGraph(FileGraph.NotifyOnClose notifyOnClose) {
File foo = FileUtils.tempFileName(prefix, suffix);
- foo.deleteOnExit();
FileGraph retval = new FileGraph(notifyOnClose, foo, true, strict);
graphList.add(retval);
return retval;
@@ -99,12 +95,12 @@ public class FileGraphSuite {
* and avoid cluttering the user's filespace ...
*/
@RunWith(Parameterized.class)
- public static class TestNames extends AbstractGraphProducerUser {
+ public static class TestNames {
private GraphProducer graphProducer = new GraphProducer();
- @Override
- public GraphProducerInterface getGraphProducer() {
- return graphProducer;
+ @After
+ public final void afterTestNames() {
+ graphProducer.cleanUp();
}
// TODO want a wider variety of cases, now we've discovered how to
@@ -132,8 +128,8 @@ public class FileGraphSuite {
@Test
public void test() {
- Graph original = graphWith(graphProducer.newGraph(), content);
- FileGraph g = (FileGraph) graphProducer.newGraph();
+ Graph original = graphWith(graphProducer.newInstance(), content);
+ FileGraph g = graphProducer.newInstance();
GraphUtil.addInto(g, original);
g.close();
Graph g2 = new FileGraph(g.name, false, true);
@@ -143,13 +139,7 @@ public class FileGraphSuite {
}
- public static class FileNameTests extends AbstractGraphProducerUser {
- private GraphProducer graphProducer = new GraphProducer();
-
- @Override
- public GraphProducerInterface getGraphProducer() {
- return graphProducer;
- }
+ public static class FileNameTests {
@Test
public void testPlausibleGraphname() {
@@ -179,29 +169,28 @@ public class FileGraphSuite {
}
}
- public static class FileNameTransactionTests extends
- AbstractGraphProducerUser {
+ public static class FileNameTransactionTests {
private GraphProducer graphProducer = new GraphProducer();
- @Override
- public GraphProducerInterface getGraphProducer() {
- return graphProducer;
+ @After
+ public final void afterTestNames() {
+ graphProducer.cleanUp();
}
@Test
public void testTransactionCommit() {
- Graph initial = graphWith(graphProducer.newGraph(),
+ Graph initial = graphWith(graphProducer.newInstance(),
"initial hasValue 42; also hasURI hello");
- Graph extra = graphWith(graphProducer.newGraph(),
+ Graph extra = graphWith(graphProducer.newInstance(),
"extra hasValue 17; also hasURI world");
- FileGraph g = (FileGraph) graphProducer.newGraph();
+ FileGraph g = graphProducer.newInstance();
GraphUtil.addInto(g, initial);
g.getTransactionHandler().begin();
GraphUtil.addInto(g, extra);
g.getTransactionHandler().commit();
- Graph union = graphWith(graphProducer.newGraph(), "");
+ Graph union = graphWith(graphProducer.newInstance(), "");
GraphUtil.addInto(union, initial);
GraphUtil.addInto(union, extra);
assertIsomorphic(union, g);
@@ -212,12 +201,12 @@ public class FileGraphSuite {
@Test
public void testTransactionCommitThenAbort() {
- Graph initial = graphWith(graphProducer.newGraph(),
+ Graph initial = graphWith(graphProducer.newInstance(),
"A pings B; B pings C");
- Graph extra = graphWith(graphProducer.newGraph(),
+ Graph extra = graphWith(graphProducer.newInstance(),
"C pingedBy B; fileGraph rdf:type Graph");
File foo = FileUtils.tempFileName("fileGraph", ".nt");
- FileGraph g = (FileGraph) graphProducer.newGraph();
+ FileGraph g = graphProducer.newInstance();
g.getTransactionHandler().begin();
GraphUtil.addInto(g, initial);
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/FileGraphTest.java Wed Oct 9 17:16:15 2013
@@ -18,20 +18,25 @@
package com.hp.hpl.jena.graph.impl;
-import com.hp.hpl.jena.graph.AbstractGraphTest;
-import com.hp.hpl.jena.testing_framework.GraphProducerInterface;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
+import org.xenei.junit.contract.Contract.Inject;
+
+import org.xenei.junit.contract.IProducer;
/**
* Test FileGraph by seeing if we can make some file graphs and then read them
* back.
*/
+@RunWith(ContractSuite.class)
+@ContractImpl(FileGraph.class)
+public class FileGraphTest {
-public class FileGraphTest extends AbstractGraphTest {
-
- GraphProducerInterface graphProducer = new FileGraphSuite.GraphProducer();
+ protected IProducer<FileGraph> graphProducer = new FileGraphSuite.GraphProducer();
- @Override
- public GraphProducerInterface getGraphProducer() {
+ @Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<FileGraph> getGraphProducer() {
return graphProducer;
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/SimpleEventManagerTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/SimpleEventManagerTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/SimpleEventManagerTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/SimpleEventManagerTest.java Wed Oct 9 17:16:15 2013
@@ -18,28 +18,40 @@
package com.hp.hpl.jena.graph.impl;
+import org.junit.runner.RunWith;
import org.mockito.Mockito;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
-import com.hp.hpl.jena.graph.AbstractEventManagerTest;
import com.hp.hpl.jena.graph.Graph;
-import com.hp.hpl.jena.graph.GraphEventManager;
-import com.hp.hpl.jena.testing_framework.GraphEventManagerProducerInterface;
+import org.xenei.junit.contract.IProducer;
/**
* Test the SimpleGraphFactory by extending AbstractTestGraphFactory and
* supplying new SimplGraphFactorys via getGraph.
*/
-public class SimpleEventManagerTest extends AbstractEventManagerTest {
-
- @Override
- protected GraphEventManagerProducerInterface getEventManagerProducer() {
- return new GraphEventManagerProducerInterface() {
-
- @Override
- public GraphEventManager newEventManager() {
- return new SimpleEventManager(Mockito.mock(Graph.class));
- }
- };
+@RunWith(ContractSuite.class)
+@ContractImpl(SimpleEventManager.class)
+public class SimpleEventManagerTest {
+
+ private IProducer<SimpleEventManager> producer = new IProducer<SimpleEventManager>() {
+
+ @Override
+ public SimpleEventManager newInstance() {
+ return new SimpleEventManager(Mockito.mock(Graph.class));
+ }
+
+ @Override
+ public void cleanUp() {
+ // TODO Auto-generated method stub
+
+ }
+ };
+
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<SimpleEventManager> getEventManagerProducer() {
+ return producer;
}
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/SimpleGraphMakerTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/SimpleGraphMakerTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/SimpleGraphMakerTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/SimpleGraphMakerTest.java Wed Oct 9 17:16:15 2013
@@ -18,17 +18,36 @@
package com.hp.hpl.jena.graph.impl;
-import com.hp.hpl.jena.graph.AbstractGraphMakerTest;
-import com.hp.hpl.jena.graph.GraphMaker;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
+
+import org.xenei.junit.contract.IProducer;
/**
* Test the SimpleGraphFactory by extending AbstractTestGraphFactory and
* supplying new SimplGraphFactorys via getGraph.
*/
-public class SimpleGraphMakerTest extends AbstractGraphMakerTest {
+@RunWith(ContractSuite.class)
+@ContractImpl(SimpleGraphMaker.class)
+public class SimpleGraphMakerTest {
+
+ private IProducer<SimpleGraphMaker> producer = new IProducer<SimpleGraphMaker>() {
+
+ @Override
+ public SimpleGraphMaker newInstance() {
+ return new SimpleGraphMaker();
+ }
+
+ @Override
+ public void cleanUp() {
+ }
+
+ };
- @Override
- public GraphMaker getGraphMaker() {
- return new SimpleGraphMaker();
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<SimpleGraphMaker> getGraphMaker() {
+ return producer;
}
}
Copied: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TripleStoreContractTest.java (from r1523135, jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/AbstractTripleStoreTest.java)
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TripleStoreContractTest.java?p2=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TripleStoreContractTest.java&p1=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/AbstractTripleStoreTest.java&r1=1523135&r2=1530718&rev=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/AbstractTripleStoreTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TripleStoreContractTest.java Wed Oct 9 17:16:15 2013
@@ -18,29 +18,40 @@
package com.hp.hpl.jena.graph.impl;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.xenei.junit.contract.Contract;
+
import static org.junit.Assert.*;
import static com.hp.hpl.jena.testing_framework.GraphHelper.*;
import com.hp.hpl.jena.graph.impl.TripleStore;
+import org.xenei.junit.contract.IProducer;
/**
* AbstractTestTripleStore - post-hoc tests for TripleStores.
*/
-public abstract class AbstractTripleStoreTest {
+@Contract(TripleStore.class)
+public abstract class TripleStoreContractTest {
/**
* Subclasses must over-ride to return a new empty TripleStore.
*/
- public abstract TripleStore getTripleStore();
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public abstract IProducer<TripleStore> getTripleStoreProducer();
protected TripleStore store;
@Before
- public void setUp() {
- store = getTripleStore();
+ public final void beforeAbstractTripleStoreTest() {
+ store = getTripleStoreProducer().newInstance();
+ }
+
+ @After
+ public final void afterAbstractTripleStoreTest() {
+ getTripleStoreProducer().cleanUp();
}
@Test
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphSuite.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphSuite.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphSuite.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphSuite.java Wed Oct 9 17:16:15 2013
@@ -27,7 +27,6 @@ import org.junit.runners.Suite;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import com.hp.hpl.jena.graph.AbstractGraphSuite;
-import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.impl.WrappedGraph;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
@@ -39,9 +38,10 @@ public class WrappedGraphSuite extends A
setGraphProducer(new GraphProducer());
}
- public static class GraphProducer extends AbstractGraphProducer {
+ public static class GraphProducer extends
+ AbstractGraphProducer<WrappedGraph> {
@Override
- public Graph createNewGraph() {
+ public WrappedGraph createNewGraph() {
return new WrappedGraph(GraphFactory.createGraphMem());
}
}