jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cla...@apache.org
Subject svn commit: r1519171 [4/4] - in /jena/Experimental/new-test: ./ src/test/java/com/hp/hpl/jena/datatypes/ src/test/java/com/hp/hpl/jena/datatypes/xsd/ src/test/java/com/hp/hpl/jena/graph/ src/test/java/com/hp/hpl/jena/graph/impl/ src/test/java/com/hp/hp...
Date Sat, 31 Aug 2013 11:01:48 GMT
Added: 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=1519171&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/CollectionGraphSuite.java
(added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/CollectionGraphSuite.java
Sat Aug 31 11:01:47 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.impl;
+
+import java.util.HashSet;
+
+import org.junit.BeforeClass;
+
+import com.hp.hpl.jena.graph.AbstractGraphProducer;
+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;
+
+public class CollectionGraphSuite extends AbstractGraphSuite {
+
+	@BeforeClass
+	public static void beforeClass() {
+		setGraphProducer(new GraphProducer());
+	}
+
+	public static class GraphProducer extends AbstractGraphProducer {
+		@Override
+		public Graph createNewGraph() {
+			return new CollectionGraph(new HashSet<Triple>());
+		}
+	}
+
+}

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/CollectionGraphSuite.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestCollectionGraph.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestCollectionGraph.java?rev=1519171&r1=1519170&r2=1519171&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestCollectionGraph.java
(original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestCollectionGraph.java
Sat Aug 31 11:01:47 2013
@@ -20,6 +20,7 @@ package com.hp.hpl.jena.graph.impl;
 
 import java.util.HashSet;
 
+import com.hp.hpl.jena.graph.AbstractGraphProducer;
 import com.hp.hpl.jena.graph.GraphProducerInterface;
 import com.hp.hpl.jena.graph.AbstractGraphTest;
 import com.hp.hpl.jena.graph.Graph;
@@ -27,17 +28,18 @@ import com.hp.hpl.jena.graph.Triple;
 import com.hp.hpl.jena.graph.impl.CollectionGraph;
 
 public class TestCollectionGraph extends AbstractGraphTest {
-	 
-	public TestCollectionGraph() {
-		super( new GraphProducer() );
-	}
 
-	public static class GraphProducer implements GraphProducerInterface
-	{
 	@Override
-	public Graph newGraph() {
-		return new CollectionGraph( new HashSet<Triple>() );
+	protected GraphProducerInterface getGraphProducer() {
+		// TODO Auto-generated method stub
+		return null;
 	}
+
+	public static class GraphProducer extends AbstractGraphProducer {
+		@Override
+		public Graph createNewGraph() {
+			return new CollectionGraph(new HashSet<Triple>());
+		}
 	}
 
 }

Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestFileGraph.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestFileGraph.java?rev=1519171&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestFileGraph.java
(added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestFileGraph.java
Sat Aug 31 11:01:47 2013
@@ -0,0 +1,187 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestSuite;
+
+import com.hp.hpl.jena.graph.AbstractGraphTest;
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.GraphProducerInterface;
+import com.hp.hpl.jena.graph.GraphUtil;
+import com.hp.hpl.jena.graph.impl.FileGraph;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.util.FileUtils;
+
+/**
+ * Test FileGraph by seeing if we can make some file graphs and then read them
+ * back.
+ */
+
+public class TestFileGraph extends AbstractGraphTest {
+
+	public TestFileGraph(GraphProducerInterface graphProducer) {
+		super(graphProducer);
+		// TODO Auto-generated constructor stub
+	}
+
+	// TODO want a wider variety of cases, now we've discovered how to abstract.
+	public static TestSuite suite() {
+		TestSuite result = new TestSuite(TestFileGraph.class);
+		result.addTest(new Case("x /R y", "xxxA", ".rdf"));
+		result.addTest(new Case("x /R y", "xxxB", ".n3"));
+		result.addTest(new Case("x /R y", "xxxC", ".nt"));
+		result.addTest(new Case("x /R y; p /R q", "xxxD", ".rdf"));
+		result.addTest(new Case("x /R y; p /R q", "xxxE", ".n3"));
+		result.addTest(new Case("x /R y; p /R q", "xxxF", ".nt"));
+		result.addTest(new Case("http://domain/S ftp:ftp/P O", "xxxG", ".rdf"));
+		result.addTest(new Case("http://domain/S ftp:ftp/P O", "xxxH", ".nt"));
+		result.addTest(new Case("http://domain/S ftp:ftp/P O", "xxxI", ".n3"));
+		return result;
+	}
+
+	public void testPlausibleGraphname() {
+		assertTrue(FileGraph.isPlausibleGraphName("agnessi.rdf"));
+		assertTrue(FileGraph.isPlausibleGraphName("parabola.nt"));
+		assertTrue(FileGraph.isPlausibleGraphName("hyperbola.n3"));
+		assertTrue(FileGraph.isPlausibleGraphName("chris.dollin.n3"));
+		assertTrue(FileGraph.isPlausibleGraphName("hedgehog.spine.end.rdf"));
+	}
+
+	public void testisPlausibleUppercaseGraphname() {
+		assertTrue(FileGraph.isPlausibleGraphName("LOUDER.RDF"));
+		assertTrue(FileGraph.isPlausibleGraphName("BRIDGE.NT"));
+		assertTrue(FileGraph.isPlausibleGraphName("NOTN2.N3"));
+		assertTrue(FileGraph.isPlausibleGraphName("chris.dollin.N3"));
+		assertTrue(FileGraph.isPlausibleGraphName("hedgehog.spine.end.RDF"));
+	}
+
+	public void testImPlausibleGraphName() {
+		assertFalse(FileGraph.isPlausibleGraphName("undecorated"));
+		assertFalse(FileGraph.isPlausibleGraphName("danger.exe"));
+		assertFalse(FileGraph.isPlausibleGraphName("pretty.jpg"));
+		assertFalse(FileGraph.isPlausibleGraphName("FileGraph.java"));
+		assertFalse(FileGraph.isPlausibleGraphName("infix.rdf.c"));
+	}
+
+	public void testTransactionCommit() {
+		Graph initial = graphWithTxn("initial hasValue 42; also hasURI hello");
+		Graph extra = graphWithTxn("extra hasValue 17; also hasURI world");
+		File foo = FileUtils.tempFileName("fileGraph", ".nt");
+
+		Graph g = new FileGraph(foo, true, true);
+		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());
+	}
+
+	public void testTransactionAbort() {
+		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);
+	}
+
+	public void testTransactionCommitThenAbort() {
+		Graph initial = graphWithTxn("A pings B; B pings C");
+		Graph extra = graphWithTxn("C pingedBy B; fileGraph rdf:type Graph");
+		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());
+	}
+
+	public void testClosingNotifys() {
+		final List<File> history = new ArrayList<File>();
+		FileGraph.NotifyOnClose n = new FileGraph.NotifyOnClose() {
+			@Override
+			public void notifyClosed(File f) {
+				history.add(f);
+			}
+		};
+		File file = FileUtils.tempFileName("fileGraph", ".nt");
+		Graph g = new FileGraph(n, file, true, true);
+		assertEquals(new ArrayList<File>(), history);
+		g.close();
+		assertEquals(oneElementList(file), history);
+	}
+
+	protected List<Object> oneElementList(Object x) {
+		List<Object> result = new ArrayList<Object>();
+		result.add(x);
+		return result;
+	}
+
+	/**
+	 * Test that the graph encoded as the test-string content can be written out
+	 * to a temporary file generated from the prefix and suffix, and then read
+	 * back correctly. The temporary files are marked as delete-on-exit to try
+	 * and avoid cluttering the user's filespace ...
+	 */
+	private static class Case extends TestFileGraph {
+		String content;
+		String prefix;
+		String suffix;
+
+		Case(String content, String prefix, String suffix) {
+			super("Case: " + content + " in " + prefix + "*" + suffix);
+			this.content = content;
+			this.prefix = prefix;
+			this.suffix = suffix;
+		}
+
+		@Override
+		public void runTest() {
+			File foo = FileUtils.tempFileName(prefix, suffix);
+			Graph original = graphWithTxn(content);
+			Graph g = new FileGraph(foo, true, true);
+			GraphUtil.addInto(g, original);
+			g.close();
+			Graph g2 = new FileGraph(foo, false, true);
+			assertIsomorphic(original, g2);
+			g2.close();
+		}
+	}
+
+}

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestFileGraph.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestFileGraphMaker.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestFileGraphMaker.java?rev=1519171&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestFileGraphMaker.java
(added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestFileGraphMaker.java
Sat Aug 31 11:01:47 2013
@@ -0,0 +1,128 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+import java.util.HashSet;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static com.hp.hpl.jena.graph.GraphTestUtils.*;
+
+import com.hp.hpl.jena.graph.AbstractTestGraphMaker;
+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 com.hp.hpl.jena.util.FileUtils;
+
+/**
+ * Test a FileGraphMaker; use the abstract tests, plus specialised ones for the
+ * name conversion routines.
+ */
+public class TestFileGraphMaker extends AbstractTestGraphMaker {
+
+	@Override
+	public GraphMaker getGraphMaker() {
+		String scratch = FileUtils.getScratchDirectory(
+				"jena-test-FileGraphMaker").getPath();
+		return new FileGraphMaker(scratch, true);
+	}
+
+	@Test
+	public void testToFilename() {
+		assertEquals("plain", FileGraphMaker.toFilename("plain"));
+		assertEquals("with_Sslash", FileGraphMaker.toFilename("with/slash"));
+		assertEquals("with_Ccolon", FileGraphMaker.toFilename("with:colon"));
+		assertEquals("with_Uunderbar",
+				FileGraphMaker.toFilename("with_underbar"));
+		assertEquals("with_Stwo_Sslashes",
+				FileGraphMaker.toFilename("with/two/slashes"));
+		assertEquals("with_Sa_Cmixture_U...",
+				FileGraphMaker.toFilename("with/a:mixture_..."));
+	}
+
+	@Test
+	public void testToGraphname() {
+		assertEquals("plain", FileGraphMaker.toGraphname("plain"));
+		assertEquals("with/slash", FileGraphMaker.toGraphname("with_Sslash"));
+		assertEquals("with:colon", FileGraphMaker.toGraphname("with_Ccolon"));
+		assertEquals("with_underbar",
+				FileGraphMaker.toGraphname("with_Uunderbar"));
+		assertEquals("a/mixture_of:things",
+				FileGraphMaker.toGraphname("a_Smixture_Uof_Cthings"));
+		assertEquals("with/two/slashes",
+				FileGraphMaker.toGraphname("with_Stwo_Sslashes"));
+	}
+
+	@Test
+	public void testDetectsExistingFiles() {
+		File scratch = FileUtils
+				.getScratchDirectory("jena-test-FileGraphMaker-already");
+		Graph content = graphWith("something hasProperty someValue");
+		FileGraphMaker A = new FileGraphMaker(scratch.getPath(), true);
+		FileGraphMaker B = new FileGraphMaker(scratch.getPath(), true);
+		FileGraph gA = (FileGraph) A.createGraph("already", true);
+		GraphUtil.addInto(gA, content);
+		gA.close();
+		FileGraph gB = (FileGraph) B.openGraph("already", false);
+		assertIsomorphic(content, gB);
+		gB.close();
+		gB.delete();
+		gA.delete();
+	}
+
+	@Test
+	public void testDeletesFilesOfClosedMaker() {
+		File scratch = FileUtils
+				.getScratchDirectory("jena-test-FileGraphMaker-forgets");
+		FileGraphMaker A = new FileGraphMaker(scratch.getPath(), true);
+		A.createGraph("empty").close();
+		assertTrue("file 'empty' should exist in '" + scratch + "'", new File(
+				scratch, "empty").exists());
+		A.close();
+		assertFalse("file 'empty' should no longer exist in '" + scratch + "'",
+				new File(scratch, "empty").exists());
+	}
+
+	@Test
+	public void testForgetsClosedGraphs() {
+		File scratch = FileUtils
+				.getScratchDirectory("jena-test-FileGraphMaker-forgets");
+		FileGraphMaker m = new FileGraphMaker(scratch.getPath(), true);
+		m.createGraph("example").close();
+		assertEquals(new HashSet<String>(), m.listGraphs().toSet());
+		m.close();
+	}
+
+	@Test
+	public void testDoesntReusedClosedGraphs() {
+		File scratch = FileUtils
+				.getScratchDirectory("jena-test-FileGraphMaker-noReuse");
+		FileGraphMaker m = new FileGraphMaker(scratch.getPath(), true);
+		Graph m1 = m.createGraph("hello");
+		m1.close();
+		Graph m2 = m.createGraph("hello");
+		assertNotSame(m1, m2);
+		m2.add(triple("this graph isOpen"));
+		m.close();
+	}
+}

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TestFileGraphMaker.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TripleStoreProducerInterface.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TripleStoreProducerInterface.java?rev=1519171&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TripleStoreProducerInterface.java
(added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TripleStoreProducerInterface.java
Sat Aug 31 11:01:47 2013
@@ -0,0 +1,18 @@
+package com.hp.hpl.jena.graph.impl;
+
+import com.hp.hpl.jena.graph.impl.TripleStore;
+
+/**
+ * Creates the graph for testing
+ * 
+ */
+public interface TripleStoreProducerInterface {
+
+	/**
+	 * Returns a TripleStore to take part in the test. Must be overridden in a
+	 * subclass.
+	 * 
+	 * @return The TripleStore implementation to test.
+	 */
+	public abstract TripleStore newTripleStore();
+}

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/TripleStoreProducerInterface.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 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=1519171&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphSuite.java
(added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphSuite.java
Sat Aug 31 11:01:47 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.impl;
+
+/**
+ Tests that check GraphMem and WrappedGraph for correctness against the Graph
+ and reifier test suites.
+ */
+
+import org.junit.BeforeClass;
+import com.hp.hpl.jena.graph.AbstractGraphProducer;
+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;
+
+public class WrappedGraphSuite extends AbstractGraphSuite {
+	@BeforeClass
+	public static void beforeClass() {
+		setGraphProducer(new GraphProducer());
+	}
+
+	public static class GraphProducer extends AbstractGraphProducer {
+		@Override
+		public Graph createNewGraph() {
+			return new WrappedGraph(GraphFactory.createGraphMem());
+		}
+	}
+
+}

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphSuite.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphTest.java?rev=1519171&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphTest.java
(added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphTest.java
Sat Aug 31 11:01:47 2013
@@ -0,0 +1,84 @@
+/*
+ * 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.impl;
+
+/**
+ Tests that check GraphMem and WrappedGraph for correctness against the Graph
+ and reifier test suites.
+ */
+
+import org.junit.Test;
+
+import com.hp.hpl.jena.graph.AbstractGraphSuite;
+import com.hp.hpl.jena.graph.AbstractGraphTest;
+import com.hp.hpl.jena.graph.Factory;
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.GraphProducerInterface;
+import com.hp.hpl.jena.graph.impl.WrappedGraph;
+import com.hp.hpl.jena.mem.GraphMem;
+import com.hp.hpl.jena.sparql.graph.GraphFactory;
+
+public class WrappedGraphTest extends AbstractGraphSuite {
+	public WrappedGraphTest(String name) {
+		super(name);
+	}
+
+	/**
+	 * Answer a test suite that runs the Graph tests on GraphMem and on
+	 * WrappedGraphMem, the latter standing in for testing WrappedGraph.
+	 */
+	public static TestSuite suite() {
+		TestSuite result = new TestSuite(WrappedGraphTest.class);
+		result.addTest(suite(MetaTestGraph.class, GraphMem.class));
+		result.addTest(suite(TestReifier.class, GraphMem.class));
+		result.addTest(suite(MetaTestGraph.class, WrappedGraphMem.class));
+		result.addTest(suite(TestReifier.class, WrappedGraphMem.class));
+		result.addTest(TestGraphListener.suite());
+		result.addTestSuite(TestRegisterGraphListener.class);
+		return result;
+	}
+
+	public static TestSuite suite(Class<? extends Test> classWithTests,
+			Class<? extends Graph> graphClass) {
+		return MetaTestGraph.suite(classWithTests, graphClass);
+	}
+
+	/**
+	 * Trivial [incomplete] test that a Wrapped graph pokes through to the
+	 * underlying graph. Really want something using mock classes. Will think
+	 * about it.
+	 */
+	@Test
+	public void testWrappedSame() {
+		Graph m = Factory.createGraphMem();
+		Graph w = new WrappedGraph(m);
+		graphAdd(m, "a trumps b; c eats d");
+		assertIsomorphic(m, w);
+		graphAdd(w, "i write this; you read that");
+		assertIsomorphic(w, m);
+	}
+
+	public static class GraphProducer implements GraphProducerInterface {
+		@Override
+		public Graph newGraph() {
+			return new WrappedGraph(GraphFactory.createGraphMem());
+		}
+	}
+
+}

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/impl/WrappedGraphTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/test/TestUtils.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/test/TestUtils.java?rev=1519171&r1=1519170&r2=1519171&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/test/TestUtils.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/test/TestUtils.java Sat Aug 31
11:01:47 2013
@@ -26,142 +26,169 @@ import com.hp.hpl.jena.util.CollectionFa
 import com.hp.hpl.jena.util.iterator.*;
 
 /**
-    A basis for Jena test cases which provides assertFalse and assertDiffer.
-    Often the logic of the names is clearer than using a negation.
-*/
-public class TestUtils
-    {
+ * A basis for Jena test cases which provides assertFalse and assertDiffer.
+ * Often the logic of the names is clearer than using a negation.
+ */
+public class TestUtils {
 	// do not instantiate
-    protected TestUtils() {};
-         
-    /**
-        assert that the two objects must be unequal according to .equals().
-        @param title a labelling string for the assertion failure text
-        @param x an object to test; the subject of a .equals()
-        @param y the other object; the argument of the .equals()
-    */
-    public static void assertDiffer( String title, Object x, Object y )
-        { 
-        if (x == null ? y == null : x.equals( y ))
-            fail( (title == null ? "objects should be different, but both were: " : title)
+ x );
-        }
-        
-    /**
-        assert that the two objects must be unequal according to .equals().
-        @param x an object to test; the subject of a .equals()
-        @param y the other object; the argument of the .equals()
-    */
-    public static void assertDiffer( Object x, Object y )
-        { assertDiffer( null, x, y ); }
-    
-    /**
-        assert that the object <code>x</code> must be of the class 
-        <code>expected</code>.
-    */
-    public static void assertInstanceOf( Class<?> expected, Object x )
-        {
-        if (x == null)
-            fail( "expected instance of " + expected + ", but had null" );
-        if (!expected.isInstance( x )) 
-            fail( "expected instance of " + expected + ", but had instance of " + x.getClass()
);
-        }
-        
-    /**
-    	Answer a Set formed from the elements of the List <code>L</code>.
-    */
-    public static <T> Set<T> listToSet( List<T> L )
-        { return CollectionFactory.createHashedSet( L ); }
-
-    /**
-        Answer a List of the substrings of <code>s</code> that are separated

-        by spaces.
-    */
-    public static List<String> listOfStrings( String s )
-        {
-        List<String> result = new ArrayList<String>();
-        StringTokenizer st = new StringTokenizer( s );
-        while (st.hasMoreTokens()) result.add( st.nextToken() );
-        return result;
-        }
-    
-    /**
-        Answer a Set of the substrings of <code>s</code> that are separated 
-        by spaces.
-    */
-    public static Set<String> setOfStrings( String s )
-        {
-        Set<String> result = new HashSet<String>();
-        StringTokenizer st = new StringTokenizer( s );
-        while (st.hasMoreTokens()) result.add( st.nextToken() );
-        return result;
-        }
-
-    /**
-        Answer a list containing the single object <code>x</code>.
-    */
-    public static <T> List<T> listOfOne( T x )
-        {
-        List<T> result = new ArrayList<T>();
-        result.add( x );
-        return result;
-        }
-
-    /**
-        Answer a Set containing the single object <code>x</code>.
-    */
-    public static <T> Set<T> setOfOne( T x )
-        {
-        Set<T> result = new HashSet<T>();
-        result.add( x );
-        return result;
-        }
-    
-    /**
-        Answer a fresh list which is the concatenation of <code>L</code> then
-        <code>R</code>. Neither <code>L</code> nor <code>R</code>
is updated.
-    */
-    public static <T> List<T> append( List<? extends T> L, List<? extends
T> R )
-        { List<T> result = new ArrayList<T>( L );
-        result.addAll( R );
-        return result; }
-    
-    /**
-        Answer an iterator over the space-separated substrings of <code>s</code>.
-    */
-    protected static ExtendedIterator<String> iteratorOfStrings( String s )
-        { return WrappedIterator.create( listOfStrings( s ).iterator() ); }
-    
-    /**
-        Answer the constructor of the class <code>c</code> which takes arguments

-        of the type(s) in <code>args</code>, or <code>null</code>
if there 
-        isn't one.
-    */
-    public static Constructor<?> getConstructor( Class<?> c, Class<?> []
args )
-        {
-        try { return c.getConstructor( args ); }
-        catch (NoSuchMethodException e) { return null; }
-        }
-
-    /**
-         Answer true iff <code>subClass</code> is the same class as 
-         <code>superClass</code>, if its superclass <i>is</i> <code>superClass</code>,
-         or if one of its interfaces hasAsInterface that class.
-    */
-    public static boolean hasAsParent( Class<?> subClass, Class<?> superClass
)
-        {
-        if (subClass == superClass || subClass.getSuperclass() == superClass) return true;
-        Class<?> [] is = subClass.getInterfaces();
-        for (int i = 0; i < is.length; i += 1) if (hasAsParent( is[i], superClass )) return
true;
-        return false;
-        }
-    
-    /**
-         Fail unless <code>subClass</code> has <code>superClass</code>
as a
-         parent, either a superclass or an implemented (directly or not) interface.
-    */
-    public static void assertHasParent( Class<?> subClass, Class<?> superClass
)
-        {
-        if (hasAsParent( subClass, superClass ) == false)
-            fail( "" + subClass + " should have " + superClass + " as a parent" );
-        }
-    }
+	protected TestUtils() {
+	};
+
+	/**
+	 * assert that the two objects must be unequal according to .equals().
+	 * 
+	 * @param title
+	 *            a labelling string for the assertion failure text
+	 * @param x
+	 *            an object to test; the subject of a .equals()
+	 * @param y
+	 *            the other object; the argument of the .equals()
+	 */
+	public static void assertDiffer(String title, Object x, Object y) {
+		if (x == null ? y == null : x.equals(y))
+			fail((title == null ? "objects should be different, but both were: "
+					: title)
+					+ x);
+	}
+
+	/**
+	 * assert that the two objects must be unequal according to .equals().
+	 * 
+	 * @param x
+	 *            an object to test; the subject of a .equals()
+	 * @param y
+	 *            the other object; the argument of the .equals()
+	 */
+	public static void assertDiffer(Object x, Object y) {
+		assertDiffer(null, x, y);
+	}
+
+	/**
+	 * assert that the object <code>x</code> must be of the class
+	 * <code>expected</code>.
+	 */
+	public static void assertInstanceOf(Class<?> expected, Object x) {
+		if (x == null)
+			fail("expected instance of " + expected + ", but had null");
+		if (!expected.isInstance(x))
+			fail("expected instance of " + expected + ", but had instance of "
+					+ x.getClass());
+	}
+
+	/**
+	 * Answer a Set formed from the elements of the List <code>L</code>.
+	 */
+	public static <T> Set<T> listToSet(List<T> L) {
+		return CollectionFactory.createHashedSet(L);
+	}
+
+	/**
+	 * Answer a List of the substrings of <code>s</code> that are separated by
+	 * spaces.
+	 */
+	public static List<String> listOfStrings(String s) {
+		List<String> result = new ArrayList<String>();
+		StringTokenizer st = new StringTokenizer(s);
+		while (st.hasMoreTokens())
+			result.add(st.nextToken());
+		return result;
+	}
+
+	/**
+	 * Answer a Set of the substrings of <code>s</code> that are separated by
+	 * spaces.
+	 */
+	public static Set<String> setOfStrings(String s) {
+		Set<String> result = new HashSet<String>();
+		StringTokenizer st = new StringTokenizer(s);
+		while (st.hasMoreTokens())
+			result.add(st.nextToken());
+		return result;
+	}
+
+	/**
+	 * Answer a list containing the single object <code>x</code>.
+	 */
+	public static <T> List<T> listOfOne(T x) {
+		List<T> result = new ArrayList<T>();
+		result.add(x);
+		return result;
+	}
+
+	/**
+	 * Answer a Set containing the single object <code>x</code>.
+	 */
+	public static <T> Set<T> setOfOne(T x) {
+		Set<T> result = new HashSet<T>();
+		result.add(x);
+		return result;
+	}
+
+	/**
+	 * Answer a fresh list which is the concatenation of <code>L</code> then
+	 * <code>R</code>. Neither <code>L</code> nor <code>R</code>
is updated.
+	 */
+	public static <T> List<T> append(List<? extends T> L, List<? extends
T> R) {
+		List<T> result = new ArrayList<T>(L);
+		result.addAll(R);
+		return result;
+	}
+
+	/**
+	 * Answer an iterator over the space-separated substrings of <code>s</code>.
+	 */
+	protected static ExtendedIterator<String> iteratorOfStrings(String s) {
+		return WrappedIterator.create(listOfStrings(s).iterator());
+	}
+
+	/**
+	 * Answer the constructor of the class <code>c</code> which takes arguments
+	 * of the type(s) in <code>args</code>, or <code>null</code> if
there isn't
+	 * one.
+	 */
+	public static Constructor<?> getConstructor(Class<?> c, Class<?>[] args)
{
+		try {
+			return c.getConstructor(args);
+		} catch (NoSuchMethodException e) {
+			return null;
+		}
+	}
+
+	/**
+	 * Answer true iff <code>subClass</code> is the same class as
+	 * <code>superClass</code>, if its superclass <i>is</i>
+	 * <code>superClass</code>, or if one of its interfaces hasAsInterface that
+	 * class.
+	 */
+	public static boolean hasAsParent(Class<?> subClass, Class<?> superClass) {
+		if (subClass == superClass || subClass.getSuperclass() == superClass)
+			return true;
+		Class<?>[] is = subClass.getInterfaces();
+		for (int i = 0; i < is.length; i += 1)
+			if (hasAsParent(is[i], superClass))
+				return true;
+		return false;
+	}
+
+	/**
+	 * Fail unless <code>subClass</code> has <code>superClass</code>
as a
+	 * parent, either a superclass or an implemented (directly or not)
+	 * interface.
+	 */
+	public static void assertHasParent(Class<?> subClass, Class<?> superClass) {
+		if (hasAsParent(subClass, superClass) == false)
+			fail("" + subClass + " should have " + superClass + " as a parent");
+	}
+
+	/**
+	 * Tests o1.equals( o2 ) && o2.equals(o1) && o1.hashCode() == o2.hashCode()
+	 * 
+	 * @param o1
+	 * @param o2
+	 */
+	public static void assertEquivalent(Object o1, Object o2) {
+		assertEquals(o1, o2);
+		assertEquals(o2, o1);
+		assertEquals(o1.hashCode(), o2.hashCode());
+	}
+}



Mime
View raw message