Repository: jena Updated Branches: refs/heads/JENA-380 be0e6f278 -> e2f4d02d1
JENA-380 Migrate TestReasoners, create its test suite and adjust ReasonerTester for JUnit4 Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/e2f4d02d Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/e2f4d02d Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/e2f4d02d Branch: refs/heads/JENA-380 Commit: e2f4d02d1b78a6aacec69ee3e4d5ecf1a71c25d7 Parents: be0e6f2 Author: Bruno P. Kinoshita <[email protected]> Authored: Tue Apr 21 17:55:31 2015 +1200 Committer: Bruno P. Kinoshita <[email protected]> Committed: Tue Apr 21 17:55:31 2015 +1200 ---------------------------------------------------------------------- .../hpl/jena/reasoner/test/ReasonerTester.java | 26 +++--- .../hp/hpl/jena/reasoner/test/TS_Reasoners.java | 28 +++++++ .../hpl/jena/reasoner/test/TestReasoners.java | 88 ++++++++++---------- 3 files changed, 83 insertions(+), 59 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/e2f4d02d/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/ReasonerTester.java ---------------------------------------------------------------------- diff --git a/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/ReasonerTester.java b/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/ReasonerTester.java index 86a89e4..0e3b7b8 100644 --- a/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/ReasonerTester.java +++ b/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/ReasonerTester.java @@ -18,14 +18,14 @@ package com.hp.hpl.jena.reasoner.test; +import static org.junit.Assert.assertTrue; + import java.io.BufferedReader ; import java.io.FileReader ; import java.io.IOException ; import java.io.Reader ; import java.util.* ; -import junit.framework.TestCase ; -import org.junit.Assert ; import org.slf4j.Logger ; import org.slf4j.LoggerFactory ; @@ -188,16 +188,15 @@ public class ReasonerTester { /** * Run all the tests in the manifest * @param reasonerF the factory for the reasoner to be tested - * @param testcase the JUnit test case which is requesting this test * @param configuration optional configuration information * @return true if all the tests pass * @throws IOException if one of the test files can't be found * @throws JenaException if the test can't be found or fails internally */ - public boolean runTests(ReasonerFactory reasonerF, TestCase testcase, Resource configuration) throws IOException { + public boolean runTests(ReasonerFactory reasonerF, Resource configuration) throws IOException { for ( String test : listTests() ) { - if ( !runTest( test, reasonerF, testcase, configuration ) ) + if ( !runTest( test, reasonerF, configuration ) ) { return false; } @@ -208,15 +207,14 @@ public class ReasonerTester { /** * Run all the tests in the manifest * @param reasoner the reasoner to be tested - * @param testcase the JUnit test case which is requesting this test * @return true if all the tests pass * @throws IOException if one of the test files can't be found * @throws JenaException if the test can't be found or fails internally */ - public boolean runTests(Reasoner reasoner, TestCase testcase) throws IOException { + public boolean runTests(Reasoner reasoner) throws IOException { for ( String test : listTests() ) { - if ( !runTest( test, reasoner, testcase ) ) + if ( !runTest( test, reasoner ) ) { return false; } @@ -241,27 +239,25 @@ public class ReasonerTester { * Run a single designated test. * @param uri the uri of the test, as defined in the manifest file * @param reasonerF the factory for the reasoner to be tested - * @param testcase the JUnit test case which is requesting this test * @param configuration optional configuration information * @return true if the test passes * @throws IOException if one of the test files can't be found * @throws JenaException if the test can't be found or fails internally */ - public boolean runTest(String uri, ReasonerFactory reasonerF, TestCase testcase, Resource configuration) throws IOException { + public boolean runTest(String uri, ReasonerFactory reasonerF, Resource configuration) throws IOException { Reasoner reasoner = reasonerF.create(configuration); - return runTest(uri, reasoner, testcase); + return runTest(uri, reasoner); } /** * Run a single designated test. * @param uri the uri of the test, as defined in the manifest file * @param reasoner the reasoner to be tested - * @param testcase the JUnit test case which is requesting this test * @return true if the test passes * @throws IOException if one of the test files can't be found * @throws JenaException if the test can't be found or fails internally */ - public boolean runTest(String uri, Reasoner reasoner, TestCase testcase) throws IOException { + public boolean runTest(String uri, Reasoner reasoner) throws IOException { // Find the specification for the named test Resource test = testManifest.getResource(uri); if (!test.hasProperty(RDF.type, testClass)) { @@ -319,9 +315,7 @@ public class ReasonerTester { } */ // ... end of debugging hack - if (testcase != null) { - Assert.assertTrue(description, correct); - } + assertTrue(description, correct); return correct; } http://git-wip-us.apache.org/repos/asf/jena/blob/e2f4d02d/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/TS_Reasoners.java ---------------------------------------------------------------------- diff --git a/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/TS_Reasoners.java b/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/TS_Reasoners.java new file mode 100644 index 0000000..492c024 --- /dev/null +++ b/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/TS_Reasoners.java @@ -0,0 +1,28 @@ +/* + * 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.reasoner.test; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses(TestReasoners.class) +public class TS_Reasoners { + +} http://git-wip-us.apache.org/repos/asf/jena/blob/e2f4d02d/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/TestReasoners.java ---------------------------------------------------------------------- diff --git a/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/TestReasoners.java b/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/TestReasoners.java index 4c84dfa..64862d1 100644 --- a/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/TestReasoners.java +++ b/jena-core/src/test/java/com/hp/hpl/jena/reasoner/test/TestReasoners.java @@ -18,6 +18,9 @@ package com.hp.hpl.jena.reasoner.test; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import com.hp.hpl.jena.reasoner.transitiveReasoner.*; import com.hp.hpl.jena.reasoner.rulesys.RDFSRuleReasonerFactory; import com.hp.hpl.jena.reasoner.*; @@ -28,45 +31,32 @@ import com.hp.hpl.jena.util.FileManager; import com.hp.hpl.jena.util.PrintUtil; import com.hp.hpl.jena.vocabulary.*; -import junit.framework.TestCase; -import junit.framework.TestSuite; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Set; +import org.junit.Test; + /** * Outline unit tests for initial experimental reasoners */ -public class TestReasoners extends TestCase { - - /** - * Boilerplate for junit - */ - public TestReasoners( String name ) { - super( name ); - } +public class TestReasoners { /** - * Boilerplate for junit. - * This is its own test suite - */ - public static TestSuite suite() { - return new TestSuite(TestReasoners.class); - } - - /** * Test the basic functioning of a Transitive closure cache */ + @Test public void testTransitiveReasoner() throws IOException { ReasonerTester tester = new ReasonerTester("transitive/manifest.rdf"); ReasonerFactory rf = TransitiveReasonerFactory.theInstance(); - assertTrue("transitive reasoner tests", tester.runTests(rf, this, null)); + assertTrue("transitive reasoner tests", tester.runTests(rf, null)); } /** * Test rebind operation for the transitive reasoner */ + @Test public void testTransitiveRebind() { Graph data = Factory.createGraphMem(); Node C1 = NodeFactory.createURI("C1"); @@ -79,7 +69,7 @@ public class TestReasoners extends TestCase { assertTrue(reasoner.supportsProperty(RDFS.subClassOf)); assertTrue(! reasoner.supportsProperty(RDFS.domain)); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(C1, null, null), new Object[] { new Triple(C1, RDFS.subClassOf.asNode(), C1), @@ -97,13 +87,13 @@ public class TestReasoners extends TestCase { Node c = NodeFactory.createURI("c"); infgraph.add(new Triple(a, RDFS.subClassOf.asNode(), b)); infgraph.add(new Triple(b, RDFS.subClassOf.asNode(), c)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(b, RDFS.subClassOf.asNode(), null), new Object[] { new Triple(b, RDFS.subClassOf.asNode(), c), new Triple(b, RDFS.subClassOf.asNode(), b) } ); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(a, RDFS.subClassOf.asNode(), null), new Object[] { new Triple(a, RDFS.subClassOf.asNode(), a), @@ -115,13 +105,13 @@ public class TestReasoners extends TestCase { Node r = NodeFactory.createURI("r"); infgraph.add(new Triple(p, RDFS.subPropertyOf.asNode(), q)); infgraph.add(new Triple(q, RDFS.subPropertyOf.asNode(), r)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(q, RDFS.subPropertyOf.asNode(), null), new Object[] { new Triple(q, RDFS.subPropertyOf.asNode(), q), new Triple(q, RDFS.subPropertyOf.asNode(), r) } ); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(p, RDFS.subPropertyOf.asNode(), null), new Object[] { new Triple(p, RDFS.subPropertyOf.asNode(), p), @@ -133,6 +123,7 @@ public class TestReasoners extends TestCase { /** * Test delete operation for Transtive reasoner. */ + @Test public void testTransitiveRemove() { Graph data = Factory.createGraphMem(); Node a = NodeFactory.createURI("a"); @@ -148,7 +139,7 @@ public class TestReasoners extends TestCase { data.add( new Triple(d, RDFS.subClassOf.asNode(), e) ); Reasoner reasoner = TransitiveReasonerFactory.theInstance().create(null); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, infgraph.find(a, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(a, RDFS.subClassOf.asNode(), null), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b), @@ -157,14 +148,14 @@ public class TestReasoners extends TestCase { new Triple(a, closedP, d), new Triple(a, closedP, e) }); - TestUtil.assertIteratorValues(this, infgraph.find(b, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(b, RDFS.subClassOf.asNode(), null), new Object[] { new Triple(b, closedP, b), new Triple(b, closedP, d), new Triple(b, closedP, e) }); infgraph.delete(new Triple(b, closedP, d)); - TestUtil.assertIteratorValues(this, infgraph.find(a, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(a, RDFS.subClassOf.asNode(), null), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b), @@ -173,21 +164,21 @@ public class TestReasoners extends TestCase { new Triple(a, closedP, d), new Triple(a, closedP, e) }); - TestUtil.assertIteratorValues(this, infgraph.find(b, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(b, RDFS.subClassOf.asNode(), null), new Object[] { new Triple(b, closedP, b), }); infgraph.delete(new Triple(a, closedP, c)); - TestUtil.assertIteratorValues(this, infgraph.find(a, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(a, RDFS.subClassOf.asNode(), null), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b) }); - TestUtil.assertIteratorValues(this, infgraph.find(b, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(b, RDFS.subClassOf.asNode(), null), new Object[] { new Triple(b, closedP, b) }); - TestUtil.assertIteratorValues(this, data.find(null, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", data.find(null, RDFS.subClassOf.asNode(), null), new Object[] { new Triple(a, closedP, b), new Triple(c, closedP, d), @@ -198,6 +189,7 @@ public class TestReasoners extends TestCase { /** * Test metalevel add/remove subproperty operations for transitive reasoner. */ + @Test public void testTransitiveMetaLevel() { doTestMetaLevel(TransitiveReasonerFactory.theInstance()); } @@ -205,6 +197,7 @@ public class TestReasoners extends TestCase { /** * Test metalevel add/remove subproperty operations for rdsf reasoner. */ + @Test public void testRDFSMetaLevel() { doTestMetaLevel(RDFSRuleReasonerFactory.theInstance()); } @@ -226,22 +219,22 @@ public class TestReasoners extends TestCase { data.add( new Triple(c1, p, c2)); Reasoner reasoner = rf.create(null); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(c1, sC, null), new Object[] { }); infgraph.add(new Triple(p, q, sC)); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(c1, sC, null), new Object[] { }); infgraph.add(new Triple(q, sP, sP)); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(c1, sC, null), new Object[] { new Triple(c1, sC, c1), new Triple(c1, sC, c2), new Triple(c1, sC, c3) }); infgraph.delete(new Triple(p, q, sC)); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(c1, sC, null), new Object[] { }); } @@ -249,6 +242,7 @@ public class TestReasoners extends TestCase { /** * Check a complex graph's transitive reduction. */ + @Test public void testTransitiveReduction() { Model test = FileManager.get().loadModel("testing/reasoners/bugs/subpropertyModel.n3"); Property dp = test.getProperty(TransitiveReasoner.directSubPropertyOf.getURI()); @@ -292,6 +286,7 @@ public class TestReasoners extends TestCase { * solved just be not reusing reasoners. * @todo this test might be better moved to OntModel tests somewhere */ + @Test public void testTransitiveSpecReuse() { OntModel om1 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF); Resource c1 = om1.createResource(PrintUtil.egNS + "Class1"); @@ -314,6 +309,7 @@ public class TestReasoners extends TestCase { * model might lead to interference. This in fact used to happen with the transitive * reasoner. This is a test to check that the transitive reasoner state reuse has been fixed at source. */ + @Test public void testTransitiveBindReuse() { Reasoner r = ReasonerRegistry.getTransitiveReasoner(); InfModel om1 = ModelFactory.createInfModel(r, ModelFactory.createDefaultModel()); @@ -334,6 +330,7 @@ public class TestReasoners extends TestCase { /** * Test rebind operation for the RDFS reasoner */ + @Test public void testRDFSRebind() { Graph data = Factory.createGraphMem(); Node C1 = NodeFactory.createURI("C1"); @@ -344,7 +341,7 @@ public class TestReasoners extends TestCase { data.add( new Triple(C2, RDFS.subClassOf.asNode(), C3) ); Reasoner reasoner = RDFSRuleReasonerFactory.theInstance().create(null); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(C1, RDFS.subClassOf.asNode(), null), new Object[] { new Triple(C1, RDFS.subClassOf.asNode(), C1), @@ -355,7 +352,7 @@ public class TestReasoners extends TestCase { data2.add( new Triple(C1, RDFS.subClassOf.asNode(), C2) ); data2.add( new Triple(C2, RDFS.subClassOf.asNode(), C4) ); infgraph.rebind(data2); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(C1, RDFS.subClassOf.asNode(), null), new Object[] { new Triple(C1, RDFS.subClassOf.asNode(), C1), @@ -369,6 +366,7 @@ public class TestReasoners extends TestCase { * This is an example to test that rebing is invoked correctly rather * than an RDFS-specific test. */ + @Test public void testRDFSRemove() { InfModel m = ModelFactory.createRDFSModel(ModelFactory.createDefaultModel()); String NS = PrintUtil.egNS; @@ -380,20 +378,21 @@ public class TestReasoners extends TestCase { p.addProperty(RDFS.domain, D); i.addProperty(p, c); i.addProperty(p, d); - TestUtil.assertIteratorValues(this, i.listProperties(), new Object[] { + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", i.listProperties(), new Object[] { m.createStatement(i, p, c), m.createStatement(i, p, d), m.createStatement(i, RDF.type, D), m.createStatement(i, RDF.type, RDFS.Resource), }); i.removeAll(p); - TestUtil.assertIteratorValues(this, i.listProperties(), new Object[] { + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", i.listProperties(), new Object[] { }); } /** * Cycle bug in transitive reasoner */ + @Test public void testTransitiveCycleBug() { Model m = FileManager.get().loadModel( "file:testing/reasoners/bugs/unbroken.n3" ); OntModel om = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM_TRANS_INF, m ); @@ -406,6 +405,7 @@ public class TestReasoners extends TestCase { /** * Test the ModelFactory interface */ + @Test public void testModelFactoryRDFS() { Model data = ModelFactory.createDefaultModel(); Property p = data.createProperty("urn:x-hp:ex/p"); @@ -416,7 +416,7 @@ public class TestReasoners extends TestCase { .add(a, p, b); Model result = ModelFactory.createRDFSModel(data); StmtIterator i = result.listStatements( b, RDF.type, (RDFNode)null ); - TestUtil.assertIteratorValues(this, i, new Object[] { + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", i, new Object[] { data.createStatement(b, RDF.type, RDFS.Resource ), data.createStatement(b, RDF.type, C ) }); @@ -426,6 +426,7 @@ public class TestReasoners extends TestCase { /** * Run test on findWithPremies for Transitive reasoner. */ + @Test public void testTransitiveFindWithPremises() { doTestFindWithPremises(TransitiveReasonerFactory.theInstance()); } @@ -433,6 +434,7 @@ public class TestReasoners extends TestCase { /** * Run test on findWithPremies for RDFS reasoner. */ + @Test public void testRDFSFindWithPremises() { doTestFindWithPremises(RDFSRuleReasonerFactory.theInstance()); } @@ -452,16 +454,16 @@ public class TestReasoners extends TestCase { premise.add( new Triple(c1, sC, c2)); Reasoner reasoner = rf.create(null); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(c1, sC, null), new Object[] { }); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null, premise), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(c1, sC, null, premise), new Object[] { new Triple(c1, sC, c2), new Triple(c1, sC, c3), new Triple(c1, sC, c1) }); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues(TestReasoners.class, "TestReasoners", infgraph.find(c1, sC, null), new Object[] { });
