From a4bd71904ac8a5c902294422170643f65c972c35 Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Sun, 30 Aug 2026 16:55:45 +0100 Subject: [PATCH 01/12] GH-3236: Convert jena-core ontology testing to JUnit6 --- .../jena/ontology/impl/OntTestBase.java | 74 +- .../jena/ontology/impl/OntTestUtil.java | 129 +++ .../impl/{TS3_ont.java => TS6_ont.java} | 18 +- .../jena/ontology/impl/TestAllDifferent.java | 44 +- .../ontology/impl/TestClassExpression.java | 866 +++++++++--------- .../ontology/impl/TestCreateInOntModel.java | 61 +- .../jena/ontology/impl/TestFrameView.java | 138 ++- .../jena/ontology/impl/TestIndividual.java | 65 +- .../impl/TestListSyntaxCategories.java | 62 +- .../jena/ontology/impl/TestOntClass.java | 119 ++- .../ontology/impl/TestOntDocumentManager.java | 220 +++-- .../jena/ontology/impl/TestOntGraph.java | 12 +- .../jena/ontology/impl/TestOntModel.java | 339 +++---- .../jena/ontology/impl/TestOntModelSpec.java | 14 +- .../jena/ontology/impl/TestOntReasoning.java | 85 +- .../jena/ontology/impl/TestOntResource.java | 413 ++++----- .../jena/ontology/impl/TestOntTools.java | 51 +- .../jena/ontology/impl/TestOntology.java | 80 +- .../jena/ontology/impl/TestProperty.java | 358 ++++---- ..._ModelMakers.java => TS6_ModelMakers.java} | 19 +- .../jena/ontology/makers/TestGraphMaker.java | 83 +- .../ontology/makers/TestModelMakerImpl.java | 46 +- .../jena/reasoner/test/TestUtil_JU6.java | 128 +++ .../apache/jena/test/JenaCoreTestAll_JU4.java | 4 +- .../apache/jena/test/JenaCoreTestAll_JU6.java | 5 + 25 files changed, 1929 insertions(+), 1504 deletions(-) create mode 100644 jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestUtil.java rename jena-core/src/test/java/org/apache/jena/ontology/impl/{TS3_ont.java => TS6_ont.java} (80%) rename jena-core/src/test/java/org/apache/jena/ontology/makers/{TS3_ModelMakers.java => TS6_ModelMakers.java} (74%) create mode 100644 jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil_JU6.java diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestBase.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestBase.java index 694fe1d40b1..98c7f5b3ad2 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestBase.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestBase.java @@ -19,29 +19,35 @@ * SPDX-License-Identifier: Apache-2.0 */ -// Package -/////////////// package org.apache.jena.ontology.impl; +import static org.junit.jupiter.api.Assertions.*; -// Imports -/////////////// import java.util.*; +import java.util.stream.Stream; + +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; -import junit.framework.*; import org.apache.jena.ontology.*; import org.apache.jena.rdf.model.*; -import org.apache.jena.reasoner.test.TestUtil; - +import org.apache.jena.test.JenaTestLib; /** *

- * Generic test case for ontology unit testing + * Generic test case for ontology unit testing. + *

+ *

+ * JUnit6 counterpart of {@link OntTestBase}. The JUnit3 original was a + * {@code TestSuite} that built one {@code TestCase} per entry of + * {@link #getTests}; here the same array becomes one {@link DynamicTest} per + * entry, so the test count is unchanged. {@code OntTestCase} keeps the + * constructor and {@code ontTest} contract of the original, so sub-classes + * carry over unaltered. *

*/ @SuppressWarnings("removal") public abstract class OntTestBase - extends TestSuite { // Constants ////////////////////////////////// @@ -49,30 +55,24 @@ public abstract class OntTestBase public static final String BASE = "http://jena.hpl.hp.com/testing/ontology"; public static final String NS = BASE + "#"; - - // Static variables - ////////////////////////////////// - - // Instance variables - ////////////////////////////////// - - - // Constructors - ////////////////////////////////// - - public OntTestBase( String name ) { - super( name ); - TestCase[] tc = getTests(); - - for ( TestCase aTc : tc ) - { - addTest( aTc ); - } - } + static { JenaTestLib.setup(); } // External signature methods ////////////////////////////////// + /** + * One dynamic test per entry of {@link #getTests}. Each entry runs the three + * language profiles internally, exactly as {@code OntTestCase.runTest()} did + * under JUnit3, so one entry remains one test. + */ + @TestFactory + public Stream ontTests() { + OntTestCase[] tc = getTests(); + if (tc == null) + return Stream.empty(); + return Arrays.stream( tc ) + .map( t -> DynamicTest.dynamicTest( t.getName(), () -> { t.setUp(); t.runTest(); } ) ); + } // Internal implementation methods ////////////////////////////////// @@ -82,31 +82,34 @@ protected OntTestCase[] getTests() { return null; } - //============================================================================== // Inner class definitions //============================================================================== protected abstract class OntTestCase - extends TestCase { protected boolean m_inOWL; protected boolean m_inOWLLite; protected boolean m_inRDFS; protected String m_langElement; + protected String m_name; protected boolean m_owlLang = true; protected boolean m_owlLiteLang = false; protected boolean m_rdfsLang = false; public OntTestCase( String langElement , boolean inOWL , boolean inOWLLite , boolean inRDFS ) { - super( "Ontology API test " + langElement ); + m_name = "Ontology API test " + langElement; m_langElement = langElement; m_inOWL = inOWL; m_inOWLLite = inOWLLite; m_inRDFS = inRDFS; } - @Override + /** The name this case ran under in the JUnit3 suite. */ + public String getName() { + return m_name; + } + public void runTest() throws Exception { @@ -136,7 +139,7 @@ protected void runTest( OntModel m, boolean inModel ) profileEx = true; } - assertEquals( "language element " + m_langElement + " was " + (inModel ? "" : "not") + " expected in model " + m.getProfile().getLabel(), inModel, !profileEx ); + assertEquals( inModel, !profileEx, "language element " + m_langElement + " was " + (inModel ? "" : "not") + " expected in model " + m.getProfile().getLabel() ); } /** Does the work in the test sub-class */ @@ -144,10 +147,9 @@ protected void runTest( OntModel m, boolean inModel ) /** Test that an iterator delivers the expected values */ protected void iteratorTest( Iterator i, Object[] expected ) { - TestUtil.assertIteratorValues( this, i, expected ); + OntTestUtil.assertIteratorValues( i, expected ); } - @Override public void setUp() { // ensure the ont doc manager is in a consistent state OntDocumentManager.getInstance().reset( true ); diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestUtil.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestUtil.java new file mode 100644 index 00000000000..999de2ae119 --- /dev/null +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestUtil.java @@ -0,0 +1,129 @@ +/* + * 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 + * + * https://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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.apache.jena.ontology.impl; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Iterator; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.Statement; + +/** + * Collection of utilities to assist with unit testing. + *

+ * The {@code assertIterator*} methods are derived from + * {@link org.apache.jena.reasoner.test.TestUtil} so that this package can be + * migrated to JUnit6 independently. The {@code junit.framework.TestCase} + * argument of the originals has been dropped: it served only to label failure + * messages and to name the logger, both of which JUnit6 reports for itself. + */ +class OntTestUtil { + + private static final Logger LOG = LoggerFactory.getLogger( OntTestUtil.class ); + + /** + * Helper method to test an iterator against a list of objects - order independent + * @param it The iterator to test + * @param vals The expected values of the iterator + */ + static void assertIteratorValues(Iterator it, Object[] vals) { + assertIteratorValues( it, vals, 0 ); + } + + /** + * Helper method to test an iterator against a list of objects - order independent, and + * can optionally check the count of anonymous resources. This allows us to test a + * iterator of resource values which includes both URI nodes and bNodes. + * @param it The iterator to test + * @param vals The expected values of the iterator + * @param countAnon If non zero, count the number of anonymous resources returned by it, + * and don't check these resources against the expected vals. + */ + static void assertIteratorValues(Iterator it, Object[] vals, int countAnon ) { + boolean[] found = new boolean[vals.length]; + int anonFound = 0; + + for (int i = 0; i < vals.length; i++) found[i] = false; + + while (it.hasNext()) { + Object n = it.next(); + boolean gotit = false; + + // do bNodes separately + if (countAnon > 0 && isAnonValue( n )) { + anonFound++; + continue; + } + + for (int i = 0; i < vals.length; i++) { + if (n.equals(vals[i])) { + gotit = true; + found[i] = true; + } + } + if (!gotit) { + LOG.debug( "found unexpected iterator value: " + n); + } + assertTrue( gotit, "found unexpected iterator value: " + n); + } + + // check that no expected values were unfound + for (int i = 0; i < vals.length; i++) { + if (!found[i]) { + LOG.debug( "failed to find expected iterator value: " + vals[i]); + } + assertTrue( found[i], "failed to find expected iterator value: " + vals[i]); + } + + // check we got the right no. of anons + assertEquals( countAnon, anonFound, "iterator test did not find the right number of anon. nodes" ); + } + + /** + * Check the length of an iterator. + */ + static void assertIteratorLength(Iterator it, int expectedLength) { + int length = 0; + while (it.hasNext()) { + it.next(); + length++; + } + assertEquals(expectedLength, length); + } + + /** + * For the purposes of counting, a value is anonymous if (a) it is an anonymous resource, + * or (b) it is a statement with a bNode subject or (c) it is a statement with a bNode + * object. This is because we cannot check bNode identity against fixed expected data values. + * @param n A value + * @return True if n is anonymous + */ + static boolean isAnonValue( Object n ) { + return ((n instanceof Resource) && ((Resource) n).isAnon()) || + ((n instanceof Statement) && ((Statement) n).getSubject().isAnon()) || + ((n instanceof Statement) && isAnonValue( ((Statement) n).getObject() )); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TS3_ont.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TS6_ont.java similarity index 80% rename from jena-core/src/test/java/org/apache/jena/ontology/impl/TS3_ont.java rename to jena-core/src/test/java/org/apache/jena/ontology/impl/TS6_ont.java index 37b50723159..bc7cbc8f9f9 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TS3_ont.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TS6_ont.java @@ -21,12 +21,14 @@ package org.apache.jena.ontology.impl; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.junit.platform.suite.api.BeforeSuite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; +import org.apache.jena.test.JenaTestLib; -@RunWith(Suite.class) -@Suite.SuiteClasses({ +@Suite +@SelectClasses({ TestOntGraph.class, TestOntResource.class, TestClassExpression.class, @@ -44,4 +46,10 @@ TestFrameView.class, TestOntTools.class, }) -public class TS3_ont {} + +public class TS6_ont { + @BeforeSuite + public static void beforeSuite() { + JenaTestLib.setup(); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestAllDifferent.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestAllDifferent.java index 5b14e9d472d..16280673a57 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestAllDifferent.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestAllDifferent.java @@ -25,19 +25,24 @@ // Imports /////////////// -import junit.framework.*; import org.apache.jena.ontology.*; import org.apache.jena.rdf.model.RDFNode; +import static org.junit.jupiter.api.Assertions.*; + +import org.apache.jena.test.JenaTestLib; + /** *

* Unit tests for the AllDifferent declaration. *

*/ @SuppressWarnings("removal") -public class TestAllDifferent - extends OntTestBase +public class TestAllDifferent extends OntTestBase { + + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// @@ -50,15 +55,6 @@ public class TestAllDifferent // Constructors ////////////////////////////////// - static public TestSuite suite() { - return new TestAllDifferent( "TestAllDifferent" ); - } - - public TestAllDifferent( String name ) { - super( name ); - } - - // External signature methods ////////////////////////////////// @@ -74,26 +70,26 @@ public void ontTest( OntModel m ) { OntResource c = m.getResource( NS + "c" ).as( OntResource.class ); a.addDistinctMember( b ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); - assertEquals( "List size should be 1", 1, a.getDistinctMembers().size() ); - assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); + assertEquals( 1, a.getCardinality( prof.DISTINCT_MEMBERS() ), "Cardinality should be 1" ); + assertEquals( 1, a.getDistinctMembers().size(), "List size should be 1" ); + assertTrue( a.hasDistinctMember( b ), "a should have b as distinct" ); a.addDistinctMember( c ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); - assertEquals( "List size should be 2", 2, a.getDistinctMembers().size() ); + assertEquals( 1, a.getCardinality( prof.DISTINCT_MEMBERS() ), "Cardinality should be 1" ); + assertEquals( 2, a.getDistinctMembers().size(), "List size should be 2" ); iteratorTest( a.listDistinctMembers(), new Object[] {b, c} ); - assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); - assertTrue( "a should have c as distinct", a.hasDistinctMember( c ) ); + assertTrue( a.hasDistinctMember( b ), "a should have b as distinct" ); + assertTrue( a.hasDistinctMember( c ), "a should have c as distinct" ); a.setDistinctMembers( m.createList( new RDFNode[] {b} ) ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); - assertEquals( "List size should be 1", 1, a.getDistinctMembers().size() ); - assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); - assertTrue( "a should not have c as distinct", !a.hasDistinctMember( c ) ); + assertEquals( 1, a.getCardinality( prof.DISTINCT_MEMBERS() ), "Cardinality should be 1" ); + assertEquals( 1, a.getDistinctMembers().size(), "List size should be 1" ); + assertTrue( a.hasDistinctMember( b ), "a should have b as distinct" ); + assertTrue( !a.hasDistinctMember( c ), "a should not have c as distinct" ); a.removeDistinctMember( b ); - assertTrue( "a should have not b as distinct", !a.hasDistinctMember( b ) ); + assertTrue( !a.hasDistinctMember( b ), "a should have not b as distinct" ); } }, }; diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestClassExpression.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestClassExpression.java index f750bc761a3..df61e020894 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestClassExpression.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestClassExpression.java @@ -23,17 +23,17 @@ /////////////// package org.apache.jena.ontology.impl; - - // Imports /////////////// -import junit.framework.*; import org.apache.jena.ontology.*; import org.apache.jena.rdf.model.*; import org.apache.jena.util.iterator.ClosableIterator; import org.apache.jena.util.iterator.NullIterator; import org.apache.jena.vocabulary.*; +import static org.junit.jupiter.api.Assertions.*; + +import org.apache.jena.test.JenaTestLib; /** *

@@ -41,9 +41,11 @@ *

*/ @SuppressWarnings("removal") -public class TestClassExpression - extends OntTestBase +public class TestClassExpression extends OntTestBase { + + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// @@ -56,15 +58,6 @@ public class TestClassExpression // Constructors ////////////////////////////////// - static public TestSuite suite() { - return new TestClassExpression( "TestClassExpression" ); - } - - public TestClassExpression( String name ) { - super( name ); - } - - // External signature methods ////////////////////////////////// @@ -80,22 +73,22 @@ public void ontTest( OntModel m ) { OntClass C = m.createClass( NS + "C" ); A.addSuperClass( B ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.SUB_CLASS_OF() ) ); - assertEquals( "A should have super-class B", B, A.getSuperClass() ); + assertEquals( 1, A.getCardinality( prof.SUB_CLASS_OF() ), "Cardinality should be 1" ); + assertEquals( B, A.getSuperClass(), "A should have super-class B" ); A.addSuperClass( C ); - assertEquals( "Cardinality should be 2", 2, A.getCardinality( prof.SUB_CLASS_OF() ) ); + assertEquals( 2, A.getCardinality( prof.SUB_CLASS_OF() ), "Cardinality should be 2" ); iteratorTest( A.listSuperClasses(), new Object[] {C, B} ); A.setSuperClass( C ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.SUB_CLASS_OF() ) ); - assertEquals( "A shuold have super-class C", C, A.getSuperClass() ); - assertTrue( "A shuold not have super-class B", !A.hasSuperClass( B, false ) ); + assertEquals( 1, A.getCardinality( prof.SUB_CLASS_OF() ), "Cardinality should be 1" ); + assertEquals( C, A.getSuperClass(), "A shuold have super-class C" ); + assertTrue( !A.hasSuperClass( B, false ), "A shuold not have super-class B" ); A.removeSuperClass( B ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.SUB_CLASS_OF() ) ); + assertEquals( 1, A.getCardinality( prof.SUB_CLASS_OF() ), "Cardinality should be 1" ); A.removeSuperClass( C ); - assertEquals( "Cardinality should be 0", 0, A.getCardinality( prof.SUB_CLASS_OF() ) ); + assertEquals( 0, A.getCardinality( prof.SUB_CLASS_OF() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntClass.sub-class", true, true, true ) { @@ -107,22 +100,22 @@ public void ontTest( OntModel m ) { OntClass C = m.createClass( NS + "C" ); A.addSubClass( B ); - assertEquals( "Cardinality should be 1", 1, B.getCardinality( prof.SUB_CLASS_OF() ) ); - assertEquals( "A should have sub-class B", B, A.getSubClass() ); + assertEquals( 1, B.getCardinality( prof.SUB_CLASS_OF() ), "Cardinality should be 1" ); + assertEquals( B, A.getSubClass(), "A should have sub-class B" ); A.addSubClass( C ); - assertEquals( "Cardinality should be 2", 2, B.getCardinality( prof.SUB_CLASS_OF() ) + C.getCardinality( prof.SUB_CLASS_OF() ) ); + assertEquals( 2, B.getCardinality( prof.SUB_CLASS_OF() ) + C.getCardinality( prof.SUB_CLASS_OF() ), "Cardinality should be 2" ); iteratorTest( A.listSubClasses(), new Object[] {C, B} ); A.setSubClass( C ); - assertEquals( "Cardinality should be 1", 1, B.getCardinality( prof.SUB_CLASS_OF() ) + C.getCardinality( prof.SUB_CLASS_OF() ) ); - assertEquals( "A shuold have sub-class C", C, A.getSubClass() ); - assertTrue( "A shuold not have sub-class B", !A.hasSubClass( B, false ) ); + assertEquals( 1, B.getCardinality( prof.SUB_CLASS_OF() ) + C.getCardinality( prof.SUB_CLASS_OF() ), "Cardinality should be 1" ); + assertEquals( C, A.getSubClass(), "A shuold have sub-class C" ); + assertTrue( !A.hasSubClass( B, false ), "A shuold not have sub-class B" ); A.removeSubClass( B ); - assertTrue( "A should have sub-class C", A.hasSubClass( C, false ) ); + assertTrue( A.hasSubClass( C, false ), "A should have sub-class C" ); A.removeSubClass( C ); - assertTrue( "A should not have sub-class C", !A.hasSubClass( C, false ) ); + assertTrue( !A.hasSubClass( C, false ), "A should not have sub-class C" ); } }, new OntTestCase( "OntClass.equivalentClass", true, true, false ) { @@ -134,22 +127,22 @@ public void ontTest( OntModel m ) { OntClass C = m.createClass( NS + "C" ); A.addEquivalentClass( B ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.EQUIVALENT_CLASS() ) ); - assertEquals( "A have equivalentClass B", B, A.getEquivalentClass() ); + assertEquals( 1, A.getCardinality( prof.EQUIVALENT_CLASS() ), "Cardinality should be 1" ); + assertEquals( B, A.getEquivalentClass(), "A have equivalentClass B" ); A.addEquivalentClass( C ); - assertEquals( "Cardinality should be 2", 2, A.getCardinality( prof.EQUIVALENT_CLASS() ) ); + assertEquals( 2, A.getCardinality( prof.EQUIVALENT_CLASS() ), "Cardinality should be 2" ); iteratorTest( A.listEquivalentClasses(), new Object[] {C, B} ); A.setEquivalentClass( C ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.EQUIVALENT_CLASS() ) ); - assertEquals( "A should have equivalentClass C", C, A.getEquivalentClass() ); - assertTrue( "A should not have equivalentClass B", !A.hasEquivalentClass( B ) ); + assertEquals( 1, A.getCardinality( prof.EQUIVALENT_CLASS() ), "Cardinality should be 1" ); + assertEquals( C, A.getEquivalentClass(), "A should have equivalentClass C" ); + assertTrue( !A.hasEquivalentClass( B ), "A should not have equivalentClass B" ); A.removeEquivalentClass( B ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.EQUIVALENT_CLASS() ) ); + assertEquals( 1, A.getCardinality( prof.EQUIVALENT_CLASS() ), "Cardinality should be 1" ); A.removeEquivalentClass( C ); - assertEquals( "Cardinality should be 0", 0, A.getCardinality( prof.EQUIVALENT_CLASS() ) ); + assertEquals( 0, A.getCardinality( prof.EQUIVALENT_CLASS() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntClass.disjointWith", true, false, false ) { @@ -161,22 +154,22 @@ public void ontTest( OntModel m ) { OntClass C = m.createClass( NS + "C" ); A.addDisjointWith( B ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.DISJOINT_WITH() ) ); - assertEquals( "A have be disjoint with B", B, A.getDisjointWith() ); + assertEquals( 1, A.getCardinality( prof.DISJOINT_WITH() ), "Cardinality should be 1" ); + assertEquals( B, A.getDisjointWith(), "A have be disjoint with B" ); A.addDisjointWith( C ); - assertEquals( "Cardinality should be 2", 2, A.getCardinality( prof.DISJOINT_WITH() ) ); + assertEquals( 2, A.getCardinality( prof.DISJOINT_WITH() ), "Cardinality should be 2" ); iteratorTest( A.listDisjointWith(), new Object[] {C,B} ); A.setDisjointWith( C ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.DISJOINT_WITH() ) ); - assertEquals( "A should be disjoint with C", C, A.getDisjointWith() ); - assertTrue( "A should not be disjoint with B", !A.isDisjointWith( B ) ); + assertEquals( 1, A.getCardinality( prof.DISJOINT_WITH() ), "Cardinality should be 1" ); + assertEquals( C, A.getDisjointWith(), "A should be disjoint with C" ); + assertTrue( !A.isDisjointWith( B ), "A should not be disjoint with B" ); A.removeDisjointWith( B ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.DISJOINT_WITH() ) ); + assertEquals( 1, A.getCardinality( prof.DISJOINT_WITH() ), "Cardinality should be 1" ); A.removeDisjointWith( C ); - assertEquals( "Cardinality should be 0", 0, A.getCardinality( prof.DISJOINT_WITH() ) ); + assertEquals( 0, A.getCardinality( prof.DISJOINT_WITH() ), "Cardinality should be 0" ); } }, new OntTestCase( "EnumeratedClass.oneOf", true, false, false ) { @@ -188,25 +181,25 @@ public void ontTest( OntModel m ) { OntResource b = m.getResource( NS + "b" ).as( OntResource.class ); A.addOneOf( a ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); - assertEquals( "Size should be 1", 1, A.getOneOf().size() ); - assertTrue( "A should have a as enumerated member", A.getOneOf().contains( a ) ); + assertEquals( 1, A.getCardinality( prof.ONE_OF() ), "Cardinality should be 1" ); + assertEquals( 1, A.getOneOf().size(), "Size should be 1" ); + assertTrue( A.getOneOf().contains( a ), "A should have a as enumerated member" ); A.addOneOf( b ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); - assertEquals( "Size should be 2", 2, A.getOneOf().size() ); + assertEquals( 1, A.getCardinality( prof.ONE_OF() ), "Cardinality should be 1" ); + assertEquals( 2, A.getOneOf().size(), "Size should be 2" ); iteratorTest( A.listOneOf(), new Object[] {a,b} ); A.setOneOf( m.createList( new RDFNode[] {b} ) ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); - assertEquals( "Size should be 1", 1, A.getOneOf().size() ); - assertTrue( "A should have b in the enum", A.hasOneOf( b ) ); - assertTrue( "A should not have a in the enum", !A.hasOneOf( a ) ); + assertEquals( 1, A.getCardinality( prof.ONE_OF() ), "Cardinality should be 1" ); + assertEquals( 1, A.getOneOf().size(), "Size should be 1" ); + assertTrue( A.hasOneOf( b ), "A should have b in the enum" ); + assertTrue( !A.hasOneOf( a ), "A should not have a in the enum" ); A.removeOneOf( a ); - assertTrue( "Should have b as an enum value", A.hasOneOf( b ) ); + assertTrue( A.hasOneOf( b ), "Should have b as an enum value" ); A.removeOneOf( b ); - assertTrue( "Should not have b as an enum value", !A.hasOneOf( b ) ); + assertTrue( !A.hasOneOf( b ), "Should not have b as an enum value" ); } }, new OntTestCase( "IntersectionClass.intersectionOf", true, true, false ) { @@ -218,29 +211,29 @@ public void ontTest( OntModel m ) { OntClass C = m.createClass( NS + "C" ); A.addOperand( B ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); - assertEquals( "Size should be 1", 1, A.getOperands().size() ); - assertTrue( "A should have a as intersection member", A.getOperands().contains( B ) ); + assertEquals( 1, A.getCardinality( prof.INTERSECTION_OF() ), "Cardinality should be 1" ); + assertEquals( 1, A.getOperands().size(), "Size should be 1" ); + assertTrue( A.getOperands().contains( B ), "A should have a as intersection member" ); A.addOperand( C ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); - assertEquals( "Size should be 2", 2, A.getOperands().size() ); + assertEquals( 1, A.getCardinality( prof.INTERSECTION_OF() ), "Cardinality should be 1" ); + assertEquals( 2, A.getOperands().size(), "Size should be 2" ); iteratorTest( A.listOperands(), new Object[] {B,C} ); ClosableIterator i = A.listOperands(); - assertTrue( "Argument should be an OntClass", i.next() instanceof OntClass ); + assertTrue( i.next() instanceof OntClass, "Argument should be an OntClass" ); i.close(); A.setOperands( m.createList( new RDFNode[] {C} ) ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); - assertEquals( "Size should be 1", 1, A.getOperands().size() ); - assertTrue( "A should have C in the intersection", A.hasOperand( C ) ); - assertTrue( "A should not have B in the intersection", !A.hasOperand( B ) ); + assertEquals( 1, A.getCardinality( prof.INTERSECTION_OF() ), "Cardinality should be 1" ); + assertEquals( 1, A.getOperands().size(), "Size should be 1" ); + assertTrue( A.hasOperand( C ), "A should have C in the intersection" ); + assertTrue( !A.hasOperand( B ), "A should not have B in the intersection" ); A.removeOperand( B ); - assertTrue( "Should have C as an operand", A.hasOperand( C ) ); + assertTrue( A.hasOperand( C ), "Should have C as an operand" ); A.removeOperand( C ); - assertTrue( "Should not have C as an operand", !A.hasOperand( C ) ); + assertTrue( !A.hasOperand( C ), "Should not have C as an operand" ); } }, new OntTestCase( "UnionClass.unionOf", true, false, false ) { @@ -252,29 +245,29 @@ public void ontTest( OntModel m ) { OntClass C = m.createClass( NS + "C" ); A.addOperand( B ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.UNION_OF() ) ); - assertEquals( "Size should be 1", 1, A.getOperands().size() ); - assertTrue( "A should have a as union member", A.getOperands().contains( B ) ); + assertEquals( 1, A.getCardinality( prof.UNION_OF() ), "Cardinality should be 1" ); + assertEquals( 1, A.getOperands().size(), "Size should be 1" ); + assertTrue( A.getOperands().contains( B ), "A should have a as union member" ); A.addOperand( C ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.UNION_OF() ) ); - assertEquals( "Size should be 2", 2, A.getOperands().size() ); + assertEquals( 1, A.getCardinality( prof.UNION_OF() ), "Cardinality should be 1" ); + assertEquals( 2, A.getOperands().size(), "Size should be 2" ); iteratorTest( A.listOperands(), new Object[] {B,C} ); ClosableIterator i = A.listOperands(); - assertTrue( "Argument should be an OntClass", i.next() instanceof OntClass ); + assertTrue( i.next() instanceof OntClass, "Argument should be an OntClass" ); i.close(); A.setOperands( m.createList( new RDFNode[] {C} ) ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.UNION_OF() ) ); - assertEquals( "Size should be 1", 1, A.getOperands().size() ); - assertTrue( "A should have C in the union", A.hasOperand( C ) ); - assertTrue( "A should not have B in the union", !A.hasOperand( B ) ); + assertEquals( 1, A.getCardinality( prof.UNION_OF() ), "Cardinality should be 1" ); + assertEquals( 1, A.getOperands().size(), "Size should be 1" ); + assertTrue( A.hasOperand( C ), "A should have C in the union" ); + assertTrue( !A.hasOperand( B ), "A should not have B in the union" ); A.removeOperand( B ); - assertTrue( "Should have C as an operand", A.hasOperand( C ) ); + assertTrue( A.hasOperand( C ), "Should have C as an operand" ); A.removeOperand( C ); - assertTrue( "Should not have C as an operand", !A.hasOperand( C ) ); + assertTrue( !A.hasOperand( C ), "Should not have C as an operand" ); } }, new OntTestCase( "ComplementClass.complementOf", true, false, false ) { @@ -287,30 +280,30 @@ public void ontTest( OntModel m ) { boolean ex = false; try { A.addOperand( B ); } catch (UnsupportedOperationException e) {ex = true;} - assertTrue( "Should fail to add to a complement", ex ); + assertTrue( ex, "Should fail to add to a complement" ); ex = false; try { A.addOperands( new NullIterator() ); } catch (UnsupportedOperationException e) {ex = true;} - assertTrue( "Should fail to add to a complement", ex ); + assertTrue( ex, "Should fail to add to a complement" ); ex = false; try { A.setOperands( m.createList( new RDFNode[] {C} ) ); } catch (UnsupportedOperationException e) {ex = true;} - assertTrue( "Should fail to set a list to a complement", ex ); + assertTrue( ex, "Should fail to set a list to a complement" ); A.setOperand( B ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.COMPLEMENT_OF() ) ); - assertEquals( "Complement should be B", B, A.getOperand() ); + assertEquals( 1, A.getCardinality( prof.COMPLEMENT_OF() ), "Cardinality should be 1" ); + assertEquals( B, A.getOperand(), "Complement should be B" ); iteratorTest( A.listOperands(), new Object[] {B} ); A.setOperand( C ); - assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.COMPLEMENT_OF() ) ); - assertTrue( "A should have C in the complement", A.hasOperand( C ) ); - assertTrue( "A should not have B in the complement", !A.hasOperand( B ) ); + assertEquals( 1, A.getCardinality( prof.COMPLEMENT_OF() ), "Cardinality should be 1" ); + assertTrue( A.hasOperand( C ), "A should have C in the complement" ); + assertTrue( !A.hasOperand( B ), "A should not have B in the complement" ); A.removeOperand( B ); - assertTrue( "Should have C as an operand", A.hasOperand( C ) ); + assertTrue( A.hasOperand( C ), "Should have C as an operand" ); A.removeOperand( C ); - assertTrue( "Should not have C as an operand", !A.hasOperand( C ) ); + assertTrue( !A.hasOperand( C ), "Should not have C as an operand" ); } }, new OntTestCase( "Restriction.onProperty", true, true, false ) { @@ -323,22 +316,22 @@ public void ontTest( OntModel m ) { Restriction A = m.createAllValuesFromRestriction( NS + "A", p, B ); - assertEquals( "Restriction should be on property p", p, A.getOnProperty() ); - assertTrue( "Restriction should be on property p", A.onProperty( p ) ); - assertTrue( "Restriction should not be on property q", !A.onProperty( q ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ON_PROPERTY() )); + assertEquals( p, A.getOnProperty(), "Restriction should be on property p" ); + assertTrue( A.onProperty( p ), "Restriction should be on property p" ); + assertTrue( !A.onProperty( q ), "Restriction should not be on property q" ); + assertEquals( 1, A.getCardinality( prof.ON_PROPERTY() ), "cardinality should be 1 "); A.setOnProperty( q ); - assertEquals( "Restriction should be on property q", q, A.getOnProperty() ); - assertTrue( "Restriction should not be on property p", !A.onProperty( p ) ); - assertTrue( "Restriction should not on property q", A.onProperty( q ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ON_PROPERTY() )); + assertEquals( q, A.getOnProperty(), "Restriction should be on property q" ); + assertTrue( !A.onProperty( p ), "Restriction should not be on property p" ); + assertTrue( A.onProperty( q ), "Restriction should not on property q" ); + assertEquals( 1, A.getCardinality( prof.ON_PROPERTY() ), "cardinality should be 1 "); A.removeOnProperty( p ); - assertTrue( "Should have q as on property", A.onProperty( q ) ); + assertTrue( A.onProperty( q ), "Should have q as on property" ); A.removeOnProperty( q ); - assertTrue( "Should not have q as on property", !A.onProperty( q ) ); + assertTrue( !A.onProperty( q ), "Should not have q as on property" ); } }, new OntTestCase( "AllValuesFromRestriction.allValuesFrom", true, true, false ) { @@ -351,22 +344,22 @@ public void ontTest( OntModel m ) { AllValuesFromRestriction A = m.createAllValuesFromRestriction( NS + "A", p, B ); - assertEquals( "Restriction should be all values from B", B, A.getAllValuesFrom() ); - assertTrue( "Restriction should be all values from B", A.hasAllValuesFrom( B ) ); - assertTrue( "Restriction should not be all values from C", !A.hasAllValuesFrom( C ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ALL_VALUES_FROM() )); + assertEquals( B, A.getAllValuesFrom(), "Restriction should be all values from B" ); + assertTrue( A.hasAllValuesFrom( B ), "Restriction should be all values from B" ); + assertTrue( !A.hasAllValuesFrom( C ), "Restriction should not be all values from C" ); + assertEquals( 1, A.getCardinality( prof.ALL_VALUES_FROM() ), "cardinality should be 1 "); A.setAllValuesFrom( C ); - assertEquals( "Restriction should be all values from C", C, A.getAllValuesFrom() ); - assertTrue( "Restriction should not be all values from B", !A.hasAllValuesFrom( B ) ); - assertTrue( "Restriction should be all values from C", A.hasAllValuesFrom( C ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ALL_VALUES_FROM() )); + assertEquals( C, A.getAllValuesFrom(), "Restriction should be all values from C" ); + assertTrue( !A.hasAllValuesFrom( B ), "Restriction should not be all values from B" ); + assertTrue( A.hasAllValuesFrom( C ), "Restriction should be all values from C" ); + assertEquals( 1, A.getCardinality( prof.ALL_VALUES_FROM() ), "cardinality should be 1 "); A.removeAllValuesFrom( C ); - assertTrue( "Restriction should not be some values from C", !A.hasAllValuesFrom( C ) ); - assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.ALL_VALUES_FROM() )); + assertTrue( !A.hasAllValuesFrom( C ), "Restriction should not be some values from C" ); + assertEquals( 0, A.getCardinality( prof.ALL_VALUES_FROM() ), "cardinality should be 0 "); } }, new OntTestCase( "AllValuesFromRestriction.allValuesFrom.datatype", true, true, false ) { @@ -377,22 +370,22 @@ public void ontTest( OntModel m ) { AllValuesFromRestriction A = m.createAllValuesFromRestriction( NS + "A", p, XSD.gDay ); - assertEquals( "Restriction should be all values from gDay", XSD.gDay, A.getAllValuesFrom() ); - assertTrue( "Restriction should be all values from gDay", A.hasAllValuesFrom( XSD.gDay ) ); - assertTrue( "Restriction should not be all values from decimal", !A.hasAllValuesFrom( XSD.decimal ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ALL_VALUES_FROM() )); + assertEquals( XSD.gDay, A.getAllValuesFrom(), "Restriction should be all values from gDay" ); + assertTrue( A.hasAllValuesFrom( XSD.gDay ), "Restriction should be all values from gDay" ); + assertTrue( !A.hasAllValuesFrom( XSD.decimal ), "Restriction should not be all values from decimal" ); + assertEquals( 1, A.getCardinality( prof.ALL_VALUES_FROM() ), "cardinality should be 1 "); A.setAllValuesFrom( XSD.gMonth ); - assertEquals( "Restriction should be all values from gMonth", XSD.gMonth, A.getAllValuesFrom() ); - assertTrue( "Restriction should not be all values from gDay", !A.hasAllValuesFrom( XSD.gDay ) ); - assertTrue( "Restriction should be all values from gMonth", A.hasAllValuesFrom( XSD.gMonth ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ALL_VALUES_FROM() )); + assertEquals( XSD.gMonth, A.getAllValuesFrom(), "Restriction should be all values from gMonth" ); + assertTrue( !A.hasAllValuesFrom( XSD.gDay ), "Restriction should not be all values from gDay" ); + assertTrue( A.hasAllValuesFrom( XSD.gMonth ), "Restriction should be all values from gMonth" ); + assertEquals( 1, A.getCardinality( prof.ALL_VALUES_FROM() ), "cardinality should be 1 "); A.removeAllValuesFrom( XSD.gMonth ); - assertTrue( "Restriction should not be some values from gMonth", !A.hasAllValuesFrom( XSD.gMonth ) ); - assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.ALL_VALUES_FROM() )); + assertTrue( !A.hasAllValuesFrom( XSD.gMonth ), "Restriction should not be some values from gMonth" ); + assertEquals( 0, A.getCardinality( prof.ALL_VALUES_FROM() ), "cardinality should be 0 "); } }, new OntTestCase( "AllValuesFromRestriction.allValuesFrom.literal", true, true, false ) { @@ -403,10 +396,10 @@ public void ontTest( OntModel m ) { AllValuesFromRestriction A = m.createAllValuesFromRestriction( NS + "A", p, RDFS.Literal ); - assertEquals( "Restriction should be all values from literal", RDFS.Literal, A.getAllValuesFrom() ); - assertTrue( "Restriction should be all values from literal", A.hasAllValuesFrom( RDFS.Literal ) ); - assertTrue( "Restriction should not be all values from decimal", !A.hasAllValuesFrom( XSD.decimal ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ALL_VALUES_FROM() )); + assertEquals( RDFS.Literal, A.getAllValuesFrom(), "Restriction should be all values from literal" ); + assertTrue( A.hasAllValuesFrom( RDFS.Literal ), "Restriction should be all values from literal" ); + assertTrue( !A.hasAllValuesFrom( XSD.decimal ), "Restriction should not be all values from decimal" ); + assertEquals( 1, A.getCardinality( prof.ALL_VALUES_FROM() ), "cardinality should be 1 "); } }, new OntTestCase( "AllValuesFromRestriction.allValuesFrom.datarange", true, false, false ) { @@ -420,16 +413,16 @@ public void ontTest( OntModel m ) { AllValuesFromRestriction A = m.createAllValuesFromRestriction( NS + "A", p, dr ); - assertEquals( "Restriction should be all values from dr", dr, A.getAllValuesFrom() ); - assertTrue( "value should be a datarange", A.getAllValuesFrom() instanceof DataRange ); - assertTrue( "Restriction should be all values from dr", A.hasAllValuesFrom( dr ) ); - assertTrue( "Restriction should not be all values from decimal", !A.hasAllValuesFrom( XSD.decimal ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.ALL_VALUES_FROM() )); + assertEquals( dr, A.getAllValuesFrom(), "Restriction should be all values from dr" ); + assertTrue( A.getAllValuesFrom() instanceof DataRange, "value should be a datarange" ); + assertTrue( A.hasAllValuesFrom( dr ), "Restriction should be all values from dr" ); + assertTrue( !A.hasAllValuesFrom( XSD.decimal ), "Restriction should not be all values from decimal" ); + assertEquals( 1, A.getCardinality( prof.ALL_VALUES_FROM() ), "cardinality should be 1 "); A.removeAllValuesFrom( dr ); - assertTrue( "Restriction should not be some values from gMonth", !A.hasAllValuesFrom( dr ) ); - assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.ALL_VALUES_FROM() )); + assertTrue( !A.hasAllValuesFrom( dr ), "Restriction should not be some values from gMonth" ); + assertEquals( 0, A.getCardinality( prof.ALL_VALUES_FROM() ), "cardinality should be 0 "); } }, new OntTestCase( "HasValueRestriction.hasValue", true, false, false ) { @@ -444,24 +437,24 @@ public void ontTest( OntModel m ) { HasValueRestriction A = m.createHasValueRestriction( NS + "A", p, b ); - assertEquals( "Restriction should be has value b", b, A.getHasValue() ); + assertEquals( b, A.getHasValue(), "Restriction should be has value b" ); assertTrue( A.getHasValue() instanceof Individual ); - assertTrue( "Restriction should be to have value b", A.hasValue( b ) ); - assertTrue( "Restriction should not be have value c", !A.hasValue( c ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.HAS_VALUE() )); + assertTrue( A.hasValue( b ), "Restriction should be to have value b" ); + assertTrue( !A.hasValue( c ), "Restriction should not be have value c" ); + assertEquals( 1, A.getCardinality( prof.HAS_VALUE() ), "cardinality should be 1 "); A.setHasValue( c ); - assertEquals( "Restriction should be has value c", c, A.getHasValue() ); - assertTrue( "Restriction should not be to have value b", !A.hasValue( b ) ); - assertTrue( "Restriction should not be have value c", A.hasValue( c ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.HAS_VALUE() )); + assertEquals( c, A.getHasValue(), "Restriction should be has value c" ); + assertTrue( !A.hasValue( b ), "Restriction should not be to have value b" ); + assertTrue( A.hasValue( c ), "Restriction should not be have value c" ); + assertEquals( 1, A.getCardinality( prof.HAS_VALUE() ), "cardinality should be 1 "); A.removeHasValue( c ); - assertTrue( "Restriction should not be to have value b", !A.hasValue( b ) ); - assertTrue( "Restriction should not be have value c", !A.hasValue( c ) ); - assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.HAS_VALUE() )); + assertTrue( !A.hasValue( b ), "Restriction should not be to have value b" ); + assertTrue( !A.hasValue( c ), "Restriction should not be have value c" ); + assertEquals( 0, A.getCardinality( prof.HAS_VALUE() ), "cardinality should be 0 "); } }, new OntTestCase( "SomeValuesFromRestriction.someValuesFrom", true, true, false ) { @@ -474,22 +467,22 @@ public void ontTest( OntModel m ) { SomeValuesFromRestriction A = m.createSomeValuesFromRestriction( NS + "A", p, B ); - assertEquals( "Restriction should be some values from B", B, A.getSomeValuesFrom() ); - assertTrue( "Restriction should be some values from B", A.hasSomeValuesFrom( B ) ); - assertTrue( "Restriction should not be some values from C", !A.hasSomeValuesFrom( C ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() )); + assertEquals( B, A.getSomeValuesFrom(), "Restriction should be some values from B" ); + assertTrue( A.hasSomeValuesFrom( B ), "Restriction should be some values from B" ); + assertTrue( !A.hasSomeValuesFrom( C ), "Restriction should not be some values from C" ); + assertEquals( 1, A.getCardinality( prof.SOME_VALUES_FROM() ), "cardinality should be 1 "); A.setSomeValuesFrom( C ); - assertEquals( "Restriction should be some values from C", C, A.getSomeValuesFrom() ); - assertTrue( "Restriction should not be some values from B", !A.hasSomeValuesFrom( B ) ); - assertTrue( "Restriction should be some values from C", A.hasSomeValuesFrom( C ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() )); + assertEquals( C, A.getSomeValuesFrom(), "Restriction should be some values from C" ); + assertTrue( !A.hasSomeValuesFrom( B ), "Restriction should not be some values from B" ); + assertTrue( A.hasSomeValuesFrom( C ), "Restriction should be some values from C" ); + assertEquals( 1, A.getCardinality( prof.SOME_VALUES_FROM() ), "cardinality should be 1 "); A.removeSomeValuesFrom( C ); - assertTrue( "Restriction should not be some values from C", !A.hasSomeValuesFrom( C ) ); - assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.SOME_VALUES_FROM() )); + assertTrue( !A.hasSomeValuesFrom( C ), "Restriction should not be some values from C" ); + assertEquals( 0, A.getCardinality( prof.SOME_VALUES_FROM() ), "cardinality should be 0 "); } }, new OntTestCase( "SomeValuesFromRestriction.SomeValuesFrom.datatype", true, true, false ) { @@ -500,22 +493,22 @@ public void ontTest( OntModel m ) { SomeValuesFromRestriction A = m.createSomeValuesFromRestriction( NS + "A", p, XSD.gDay ); - assertEquals( "Restriction should be some values from gDay", XSD.gDay, A.getSomeValuesFrom() ); - assertTrue( "Restriction should be some values from gDay", A.hasSomeValuesFrom( XSD.gDay ) ); - assertTrue( "Restriction should not be some values from decimal", !A.hasSomeValuesFrom( XSD.decimal ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() )); + assertEquals( XSD.gDay, A.getSomeValuesFrom(), "Restriction should be some values from gDay" ); + assertTrue( A.hasSomeValuesFrom( XSD.gDay ), "Restriction should be some values from gDay" ); + assertTrue( !A.hasSomeValuesFrom( XSD.decimal ), "Restriction should not be some values from decimal" ); + assertEquals( 1, A.getCardinality( prof.SOME_VALUES_FROM() ), "cardinality should be 1 "); A.setSomeValuesFrom( XSD.gMonth ); - assertEquals( "Restriction should be some values from gMonth", XSD.gMonth, A.getSomeValuesFrom() ); - assertTrue( "Restriction should not be some values from gDay", !A.hasSomeValuesFrom( XSD.gDay ) ); - assertTrue( "Restriction should be some values from gMonth", A.hasSomeValuesFrom( XSD.gMonth ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() )); + assertEquals( XSD.gMonth, A.getSomeValuesFrom(), "Restriction should be some values from gMonth" ); + assertTrue( !A.hasSomeValuesFrom( XSD.gDay ), "Restriction should not be some values from gDay" ); + assertTrue( A.hasSomeValuesFrom( XSD.gMonth ), "Restriction should be some values from gMonth" ); + assertEquals( 1, A.getCardinality( prof.SOME_VALUES_FROM() ), "cardinality should be 1 "); A.removeSomeValuesFrom( XSD.gMonth ); - assertTrue( "Restriction should not be some values from gMonth", !A.hasSomeValuesFrom( XSD.gMonth ) ); - assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.SOME_VALUES_FROM() )); + assertTrue( !A.hasSomeValuesFrom( XSD.gMonth ), "Restriction should not be some values from gMonth" ); + assertEquals( 0, A.getCardinality( prof.SOME_VALUES_FROM() ), "cardinality should be 0 "); } }, new OntTestCase( "SomeValuesFromRestriction.SomeValuesFrom.literal", true, true, false ) { @@ -526,10 +519,10 @@ public void ontTest( OntModel m ) { SomeValuesFromRestriction A = m.createSomeValuesFromRestriction( NS + "A", p, RDFS.Literal ); - assertEquals( "Restriction should be some values from literal", RDFS.Literal, A.getSomeValuesFrom() ); - assertTrue( "Restriction should be some values from literal", A.hasSomeValuesFrom( RDFS.Literal ) ); - assertTrue( "Restriction should not be some values from decimal", !A.hasSomeValuesFrom( XSD.decimal ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() )); + assertEquals( RDFS.Literal, A.getSomeValuesFrom(), "Restriction should be some values from literal" ); + assertTrue( A.hasSomeValuesFrom( RDFS.Literal ), "Restriction should be some values from literal" ); + assertTrue( !A.hasSomeValuesFrom( XSD.decimal ), "Restriction should not be some values from decimal" ); + assertEquals( 1, A.getCardinality( prof.SOME_VALUES_FROM() ), "cardinality should be 1 "); } }, new OntTestCase( "SomeValuesFromRestriction.SomeValuesFrom.datarange", true, false, false ) { @@ -543,16 +536,16 @@ public void ontTest( OntModel m ) { SomeValuesFromRestriction A = m.createSomeValuesFromRestriction( NS + "A", p, dr ); - assertEquals( "Restriction should be some values from dr", dr, A.getSomeValuesFrom() ); - assertTrue( "value should be a datarange", A.getSomeValuesFrom() instanceof DataRange ); - assertTrue( "Restriction should be some values from dr", A.hasSomeValuesFrom( dr ) ); - assertTrue( "Restriction should not be some values from decimal", !A.hasSomeValuesFrom( XSD.decimal ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() )); + assertEquals( dr, A.getSomeValuesFrom(), "Restriction should be some values from dr" ); + assertTrue( A.getSomeValuesFrom() instanceof DataRange, "value should be a datarange" ); + assertTrue( A.hasSomeValuesFrom( dr ), "Restriction should be some values from dr" ); + assertTrue( !A.hasSomeValuesFrom( XSD.decimal ), "Restriction should not be some values from decimal" ); + assertEquals( 1, A.getCardinality( prof.SOME_VALUES_FROM() ), "cardinality should be 1 "); A.removeSomeValuesFrom( dr ); - assertTrue( "Restriction should not be some values from gMonth", !A.hasSomeValuesFrom( dr ) ); - assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.SOME_VALUES_FROM() )); + assertTrue( !A.hasSomeValuesFrom( dr ), "Restriction should not be some values from gMonth" ); + assertEquals( 0, A.getCardinality( prof.SOME_VALUES_FROM() ), "cardinality should be 0 "); } }, new OntTestCase( "CardinalityRestriction.cardinality", true, true, false ) { @@ -563,23 +556,23 @@ public void ontTest( OntModel m ) { CardinalityRestriction A = m.createCardinalityRestriction( NS + "A", p, 3 ); - assertEquals( "Restriction should be cardinality 3", 3, A.getCardinality() ); - assertTrue( "Restriction should be cardinality 3", A.hasCardinality( 3 ) ); - assertTrue( "Restriction should not be cardinality 2", !A.hasCardinality( 2 ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.CARDINALITY() )); + assertEquals( 3, A.getCardinality(), "Restriction should be cardinality 3" ); + assertTrue( A.hasCardinality( 3 ), "Restriction should be cardinality 3" ); + assertTrue( !A.hasCardinality( 2 ), "Restriction should not be cardinality 2" ); + assertEquals( 1, A.getCardinality( prof.CARDINALITY() ), "cardinality should be 1 "); A.setCardinality( 2 ); - assertEquals( "Restriction should be cardinality 2", 2, A.getCardinality() ); - assertTrue( "Restriction should not be cardinality 3", !A.hasCardinality( 3 ) ); - assertTrue( "Restriction should be cardinality 2", A.hasCardinality( 2 ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.CARDINALITY() )); + assertEquals( 2, A.getCardinality(), "Restriction should be cardinality 2" ); + assertTrue( !A.hasCardinality( 3 ), "Restriction should not be cardinality 3" ); + assertTrue( A.hasCardinality( 2 ), "Restriction should be cardinality 2" ); + assertEquals( 1, A.getCardinality( prof.CARDINALITY() ), "cardinality should be 1 "); A.removeCardinality( 2 ); - assertTrue( "Restriction should not be cardinality 3", !A.hasCardinality( 3 ) ); - assertTrue( "Restriction should not be cardinality 2", !A.hasCardinality( 2 ) ); - assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.CARDINALITY() )); + assertTrue( !A.hasCardinality( 3 ), "Restriction should not be cardinality 3" ); + assertTrue( !A.hasCardinality( 2 ), "Restriction should not be cardinality 2" ); + assertEquals( 0, A.getCardinality( prof.CARDINALITY() ), "cardinality should be 0 "); } }, new OntTestCase( "MinCardinalityRestriction.minCardinality", true, true, false ) { @@ -590,23 +583,23 @@ public void ontTest( OntModel m ) { MinCardinalityRestriction A = m.createMinCardinalityRestriction( NS + "A", p, 3 ); - assertEquals( "Restriction should be min cardinality 3", 3, A.getMinCardinality() ); - assertTrue( "Restriction should be min cardinality 3", A.hasMinCardinality( 3 ) ); - assertTrue( "Restriction should not be min cardinality 2", !A.hasMinCardinality( 2 ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.MIN_CARDINALITY() )); + assertEquals( 3, A.getMinCardinality(), "Restriction should be min cardinality 3" ); + assertTrue( A.hasMinCardinality( 3 ), "Restriction should be min cardinality 3" ); + assertTrue( !A.hasMinCardinality( 2 ), "Restriction should not be min cardinality 2" ); + assertEquals( 1, A.getCardinality( prof.MIN_CARDINALITY() ), "cardinality should be 1 "); A.setMinCardinality( 2 ); - assertEquals( "Restriction should be min cardinality 2", 2, A.getMinCardinality() ); - assertTrue( "Restriction should not be min cardinality 3", !A.hasMinCardinality( 3 ) ); - assertTrue( "Restriction should be min cardinality 2", A.hasMinCardinality( 2 ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.MIN_CARDINALITY() )); + assertEquals( 2, A.getMinCardinality(), "Restriction should be min cardinality 2" ); + assertTrue( !A.hasMinCardinality( 3 ), "Restriction should not be min cardinality 3" ); + assertTrue( A.hasMinCardinality( 2 ), "Restriction should be min cardinality 2" ); + assertEquals( 1, A.getCardinality( prof.MIN_CARDINALITY() ), "cardinality should be 1 "); A.removeMinCardinality( 2 ); - assertTrue( "Restriction should not be cardinality 3", !A.hasMinCardinality( 3 ) ); - assertTrue( "Restriction should not be cardinality 2", !A.hasMinCardinality( 2 ) ); - assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.MIN_CARDINALITY() )); + assertTrue( !A.hasMinCardinality( 3 ), "Restriction should not be cardinality 3" ); + assertTrue( !A.hasMinCardinality( 2 ), "Restriction should not be cardinality 2" ); + assertEquals( 0, A.getCardinality( prof.MIN_CARDINALITY() ), "cardinality should be 0 "); } }, new OntTestCase( "MaxCardinalityRestriction.maxCardinality", true, true, false ) { @@ -617,23 +610,23 @@ public void ontTest( OntModel m ) { MaxCardinalityRestriction A = m.createMaxCardinalityRestriction( NS + "A", p, 3 ); - assertEquals( "Restriction should be max cardinality 3", 3, A.getMaxCardinality() ); - assertTrue( "Restriction should be max cardinality 3", A.hasMaxCardinality( 3 ) ); - assertTrue( "Restriction should not be max cardinality 2", !A.hasMaxCardinality( 2 ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.MAX_CARDINALITY() )); + assertEquals( 3, A.getMaxCardinality(), "Restriction should be max cardinality 3" ); + assertTrue( A.hasMaxCardinality( 3 ), "Restriction should be max cardinality 3" ); + assertTrue( !A.hasMaxCardinality( 2 ), "Restriction should not be max cardinality 2" ); + assertEquals( 1, A.getCardinality( prof.MAX_CARDINALITY() ), "cardinality should be 1 "); A.setMaxCardinality( 2 ); - assertEquals( "Restriction should be max cardinality 2", 2, A.getMaxCardinality() ); - assertTrue( "Restriction should not be max cardinality 3", !A.hasMaxCardinality( 3 ) ); - assertTrue( "Restriction should be max cardinality 2", A.hasMaxCardinality( 2 ) ); - assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.MAX_CARDINALITY() )); + assertEquals( 2, A.getMaxCardinality(), "Restriction should be max cardinality 2" ); + assertTrue( !A.hasMaxCardinality( 3 ), "Restriction should not be max cardinality 3" ); + assertTrue( A.hasMaxCardinality( 2 ), "Restriction should be max cardinality 2" ); + assertEquals( 1, A.getCardinality( prof.MAX_CARDINALITY() ), "cardinality should be 1 "); A.removeMaxCardinality( 2 ); - assertTrue( "Restriction should not be cardinality 3", !A.hasMaxCardinality( 3 ) ); - assertTrue( "Restriction should not be cardinality 2", !A.hasMaxCardinality( 2 ) ); - assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.MAX_CARDINALITY() )); + assertTrue( !A.hasMaxCardinality( 3 ), "Restriction should not be cardinality 3" ); + assertTrue( !A.hasMaxCardinality( 2 ), "Restriction should not be cardinality 2" ); + assertEquals( 0, A.getCardinality( prof.MAX_CARDINALITY() ), "cardinality should be 0 "); } }, new OntTestCase( "QualifiedRestriction.hasClassQ", false, false, false ) { @@ -646,19 +639,19 @@ public void ontTest( OntModel m ) { String nameA = "ABCBA"; QualifiedRestriction A = m.createMaxCardinalityQRestriction( NS + nameA, p, 3, c ); - assertEquals( "Restriction should hasClassQ c", c, A.getHasClassQ() ); - assertTrue( "Restriction should be hasClassQ c", A.hasHasClassQ( c ) ); - assertFalse( "Restriction should not be hasClassQ d", A.hasHasClassQ( d ) ); + assertEquals( c, A.getHasClassQ(), "Restriction should hasClassQ c" ); + assertTrue( A.hasHasClassQ( c ), "Restriction should be hasClassQ c" ); + assertFalse( A.hasHasClassQ( d ), "Restriction should not be hasClassQ d" ); A.setHasClassQ( d ); - assertEquals( "Restriction should hasClassQ d", d, A.getHasClassQ() ); - assertTrue( "Restriction should be hasClassQ d", A.hasHasClassQ( d ) ); - assertFalse( "Restriction should not be hasClassQ c", A.hasHasClassQ( c ) ); + assertEquals( d, A.getHasClassQ(), "Restriction should hasClassQ d" ); + assertTrue( A.hasHasClassQ( d ), "Restriction should be hasClassQ d" ); + assertFalse( A.hasHasClassQ( c ), "Restriction should not be hasClassQ c" ); - assertTrue( "Should be a qualified restriction", m.getResource( NS + nameA ).canAs( QualifiedRestriction.class ) ); + assertTrue( m.getResource( NS + nameA ).canAs( QualifiedRestriction.class ), "Should be a qualified restriction" ); A.removeHasClassQ( d ); - assertFalse( "Should not be a qualified restriction", m.getResource( NS + nameA ).canAs( QualifiedRestriction.class ) ); + assertFalse( m.getResource( NS + nameA ).canAs( QualifiedRestriction.class ), "Should not be a qualified restriction" ); } }, new OntTestCase( "CardinalityQRestriction.cardinality", false, false, false ) { @@ -669,19 +662,19 @@ public void ontTest( OntModel m ) { CardinalityQRestriction A = m.createCardinalityQRestriction( NS + "A", p, 3, c ); - assertEquals( "Restriction should cardinality 3", 3, A.getCardinalityQ() ); - assertTrue( "Restriction should be cardinality 3", A.hasCardinalityQ( 3 ) ); - assertFalse( "Restriction should not be cardinality 1", A.hasCardinalityQ( 1 ) ); + assertEquals( 3, A.getCardinalityQ(), "Restriction should cardinality 3" ); + assertTrue( A.hasCardinalityQ( 3 ), "Restriction should be cardinality 3" ); + assertFalse( A.hasCardinalityQ( 1 ), "Restriction should not be cardinality 1" ); A.setCardinalityQ( 1 ); - assertEquals( "Restriction should cardinality 1", 1, A.getCardinalityQ() ); - assertFalse( "Restriction should not be cardinality 3", A.hasCardinalityQ( 3 ) ); - assertTrue( "Restriction should be cardinality 1", A.hasCardinalityQ( 1 ) ); + assertEquals( 1, A.getCardinalityQ(), "Restriction should cardinality 1" ); + assertFalse( A.hasCardinalityQ( 3 ), "Restriction should not be cardinality 3" ); + assertTrue( A.hasCardinalityQ( 1 ), "Restriction should be cardinality 1" ); - assertTrue( "Should be a qualified cardinality restriction", m.getResource( NS + "A" ).canAs( CardinalityQRestriction.class ) ); + assertTrue( m.getResource( NS + "A" ).canAs( CardinalityQRestriction.class ), "Should be a qualified cardinality restriction" ); A.removeCardinalityQ( 1 ); - assertFalse( "Should not be a qualified cardinality restriction", m.getResource( NS + "A" ).canAs( CardinalityQRestriction.class ) ); + assertFalse( m.getResource( NS + "A" ).canAs( CardinalityQRestriction.class ), "Should not be a qualified cardinality restriction" ); } }, new OntTestCase( "MinCardinalityQRestriction.minCardinality", false, false, false ) { @@ -692,19 +685,19 @@ public void ontTest( OntModel m ) { MinCardinalityQRestriction A = m.createMinCardinalityQRestriction( NS + "A", p, 3, c ); - assertEquals( "Restriction should min cardinality 3", 3, A.getMinCardinalityQ() ); - assertTrue( "Restriction should be min cardinality 3", A.hasMinCardinalityQ( 3 ) ); - assertFalse( "Restriction should not be min cardinality 1", A.hasMinCardinalityQ( 1 ) ); + assertEquals( 3, A.getMinCardinalityQ(), "Restriction should min cardinality 3" ); + assertTrue( A.hasMinCardinalityQ( 3 ), "Restriction should be min cardinality 3" ); + assertFalse( A.hasMinCardinalityQ( 1 ), "Restriction should not be min cardinality 1" ); A.setMinCardinalityQ( 1 ); - assertEquals( "Restriction should min cardinality 1", 1, A.getMinCardinalityQ() ); - assertFalse( "Restriction should not be min cardinality 3", A.hasMinCardinalityQ( 3 ) ); - assertTrue( "Restriction should be min cardinality 1", A.hasMinCardinalityQ( 1 ) ); + assertEquals( 1, A.getMinCardinalityQ(), "Restriction should min cardinality 1" ); + assertFalse( A.hasMinCardinalityQ( 3 ), "Restriction should not be min cardinality 3" ); + assertTrue( A.hasMinCardinalityQ( 1 ), "Restriction should be min cardinality 1" ); - assertTrue( "Should be a qualified min cardinality restriction", m.getResource( NS + "A" ).canAs( MinCardinalityQRestriction.class ) ); + assertTrue( m.getResource( NS + "A" ).canAs( MinCardinalityQRestriction.class ), "Should be a qualified min cardinality restriction" ); A.removeMinCardinalityQ( 1 ); - assertFalse( "Should not be a qualified min cardinality restriction", m.getResource( NS + "A" ).canAs( MinCardinalityQRestriction.class ) ); + assertFalse( m.getResource( NS + "A" ).canAs( MinCardinalityQRestriction.class ), "Should not be a qualified min cardinality restriction" ); } }, new OntTestCase( "MaxCardinalityQRestriction.maxCardinality", false, false, false ) { @@ -715,19 +708,19 @@ public void ontTest( OntModel m ) { MaxCardinalityQRestriction A = m.createMaxCardinalityQRestriction( NS + "A", p, 3, c ); - assertEquals( "Restriction should max cardinality 3", 3, A.getMaxCardinalityQ() ); - assertTrue( "Restriction should be max cardinality 3", A.hasMaxCardinalityQ( 3 ) ); - assertFalse( "Restriction should not be max cardinality 1", A.hasMaxCardinalityQ( 1 ) ); + assertEquals( 3, A.getMaxCardinalityQ(), "Restriction should max cardinality 3" ); + assertTrue( A.hasMaxCardinalityQ( 3 ), "Restriction should be max cardinality 3" ); + assertFalse( A.hasMaxCardinalityQ( 1 ), "Restriction should not be max cardinality 1" ); A.setMaxCardinalityQ( 1 ); - assertEquals( "Restriction should max cardinality 1", 1, A.getMaxCardinalityQ() ); - assertFalse( "Restriction should not be max cardinality 3", A.hasMaxCardinalityQ( 3 ) ); - assertTrue( "Restriction should be max cardinality 1", A.hasMaxCardinalityQ( 1 ) ); + assertEquals( 1, A.getMaxCardinalityQ(), "Restriction should max cardinality 1" ); + assertFalse( A.hasMaxCardinalityQ( 3 ), "Restriction should not be max cardinality 3" ); + assertTrue( A.hasMaxCardinalityQ( 1 ), "Restriction should be max cardinality 1" ); - assertTrue( "Should be a qualified max cardinality restriction", m.getResource( NS + "A" ).canAs( MaxCardinalityQRestriction.class ) ); + assertTrue( m.getResource( NS + "A" ).canAs( MaxCardinalityQRestriction.class ), "Should be a qualified max cardinality restriction" ); A.removeMaxCardinalityQ( 1 ); - assertFalse( "Should not be a qualified max cardinality restriction", m.getResource( NS + "A" ).canAs( MaxCardinalityQRestriction.class ) ); + assertFalse( m.getResource( NS + "A" ).canAs( MaxCardinalityQRestriction.class ), "Should not be a qualified max cardinality restriction" ); } }, @@ -756,7 +749,7 @@ public void ontTest( OntModel m ) { OntClass A = m.createClass( NS + "ClassA" ); OntClass C = m.createClass( NS + "ClassC" ); - assertTrue( "A should be equiv to C", A.hasEquivalentClass( C ) ); + assertTrue( A.hasEquivalentClass( C ), "A should be equiv to C" ); } }, new OntTestCase( "OntClass.disjoint.fromFile", true, false, false ) { @@ -769,7 +762,7 @@ public void ontTest( OntModel m ) { OntClass A = m.createClass( NS + "ClassA" ); OntClass D = m.createClass( NS + "ClassD" ); - assertTrue( "A should be disjoint with D", A.isDisjointWith( D ) ); + assertTrue( A.isDisjointWith( D ), "A should be disjoint with D" ); } }, @@ -782,11 +775,11 @@ public void ontTest( OntModel m ) { Individual y = m.createIndividual( NS + "y", b ); OntClass a = m.createEnumeratedClass( NS + "A", m.createList( new RDFNode[] {x, y} ) ); - assertTrue( "enumerated class test not correct", a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", !a.isUnionClass() ); - assertTrue( "complement class test not correct", !a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( !a.isUnionClass(), "union class test not correct" ); + assertTrue( !a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); } }, new OntTestCase( "OntClass.isIntersectionClass", true, true, false ) { @@ -796,11 +789,11 @@ public void ontTest( OntModel m ) { OntClass c = m.createClass( NS + "C" ); OntClass a = m.createIntersectionClass( NS + "A", m.createList( new RDFNode[] {b,c} ) ); - assertTrue( "enumerated class test not correct", m_owlLiteLang || !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", a.isIntersectionClass() ); - assertTrue( "union class test not correct", m_owlLiteLang || !a.isUnionClass() ); - assertTrue( "complement class test not correct", m_owlLiteLang || !a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( m_owlLiteLang || !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( m_owlLiteLang || !a.isUnionClass(), "union class test not correct" ); + assertTrue( m_owlLiteLang || !a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); } }, new OntTestCase( "OntClass.isUnionClass", true, false, false ) { @@ -810,11 +803,11 @@ public void ontTest( OntModel m ) { OntClass c = m.createClass( NS + "C" ); OntClass a = m.createUnionClass( NS + "A", m.createList( new RDFNode[] {b,c} ) ); - assertTrue( "enumerated class test not correct", !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", a.isUnionClass() ); - assertTrue( "complement class test not correct", !a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( a.isUnionClass(), "union class test not correct" ); + assertTrue( !a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); } }, new OntTestCase( "OntClass.isComplementClass", true, false, false ) { @@ -823,11 +816,11 @@ public void ontTest( OntModel m ) { OntClass b = m.createClass( NS + "B" ); OntClass a = m.createComplementClass( NS + "A", b ); - assertTrue( "enumerated class test not correct", !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", !a.isUnionClass() ); - assertTrue( "complement class test not correct", a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( !a.isUnionClass(), "union class test not correct" ); + assertTrue( a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); } }, new OntTestCase( "OntClass.isRestriction", true, true, false ) { @@ -835,11 +828,11 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntClass a = m.createRestriction( null ); - assertTrue( "enumerated class test not correct", m_owlLiteLang || !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", m_owlLiteLang || !a.isUnionClass() ); - assertTrue( "complement class test not correct", m_owlLiteLang || !a.isComplementClass() ); - assertTrue( "restriction test not correct", a.isRestriction() ); + assertTrue( m_owlLiteLang || !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( m_owlLiteLang || !a.isUnionClass(), "union class test not correct" ); + assertTrue( m_owlLiteLang || !a.isComplementClass(), "complement class test not correct" ); + assertTrue( a.isRestriction(), "restriction test not correct" ); } }, @@ -849,22 +842,22 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntClass a = m.createClass( NS + "A" ); - assertTrue( "enumerated class test not correct", !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", !a.isUnionClass() ); - assertTrue( "complement class test not correct", !a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( !a.isUnionClass(), "union class test not correct" ); + assertTrue( !a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); OntClass b = m.createClass( NS + "B" ); Individual x = m.createIndividual( NS + "x", b ); Individual y = m.createIndividual( NS + "y", b ); a = a.convertToEnumeratedClass( m.createList( new RDFNode[] {x, y} ) ); - assertTrue( "enumerated class test not correct", a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", !a.isUnionClass() ); - assertTrue( "complement class test not correct", !a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( !a.isUnionClass(), "union class test not correct" ); + assertTrue( !a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); } }, new OntTestCase( "OntClass.toIntersectionClass", true, true, false ) { @@ -872,21 +865,21 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntClass a = m.createClass( NS + "A" ); - assertTrue( "enumerated class test not correct", m_owlLiteLang || !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", m_owlLiteLang || !a.isUnionClass() ); - assertTrue( "complement class test not correct", m_owlLiteLang || !a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( m_owlLiteLang || !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( m_owlLiteLang || !a.isUnionClass(), "union class test not correct" ); + assertTrue( m_owlLiteLang || !a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); OntClass b = m.createClass( NS + "B" ); OntClass c = m.createClass( NS + "C" ); a = a.convertToIntersectionClass( m.createList( new RDFNode[] {b,c} ) ); - assertTrue( "enumerated class test not correct", m_owlLiteLang || !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", a.isIntersectionClass() ); - assertTrue( "union class test not correct", m_owlLiteLang || !a.isUnionClass() ); - assertTrue( "complement class test not correct", m_owlLiteLang || !a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( m_owlLiteLang || !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( m_owlLiteLang || !a.isUnionClass(), "union class test not correct" ); + assertTrue( m_owlLiteLang || !a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); } }, new OntTestCase( "OntClass.toUnionClass", true, false, false ) { @@ -894,21 +887,21 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntClass a = m.createClass( NS + "A" ); - assertTrue( "enumerated class test not correct", !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", !a.isUnionClass() ); - assertTrue( "complement class test not correct", !a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( !a.isUnionClass(), "union class test not correct" ); + assertTrue( !a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); OntClass b = m.createClass( NS + "B" ); OntClass c = m.createClass( NS + "C" ); a = a.convertToUnionClass( m.createList( new RDFNode[] {b,c} ) ); - assertTrue( "enumerated class test not correct", m_owlLiteLang || !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", m_owlLiteLang || a.isUnionClass() ); - assertTrue( "complement class test not correct", m_owlLiteLang || !a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( m_owlLiteLang || !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( m_owlLiteLang || a.isUnionClass(), "union class test not correct" ); + assertTrue( m_owlLiteLang || !a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); } }, new OntTestCase( "OntClass.toComplementClass", true, false, false ) { @@ -916,20 +909,20 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntClass a = m.createClass( NS + "A" ); - assertTrue( "enumerated class test not correct", !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", !a.isUnionClass() ); - assertTrue( "complement class test not correct", !a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( !a.isUnionClass(), "union class test not correct" ); + assertTrue( !a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); OntClass b = m.createClass( NS + "B" ); a = a.convertToComplementClass( b ); - assertTrue( "enumerated class test not correct", m_owlLiteLang || !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", m_owlLiteLang || !a.isUnionClass() ); - assertTrue( "complement class test not correct", m_owlLiteLang || a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( m_owlLiteLang || !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( m_owlLiteLang || !a.isUnionClass(), "union class test not correct" ); + assertTrue( m_owlLiteLang || a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); } }, new OntTestCase( "OntClass.toRestriction", true, true, false ) { @@ -937,24 +930,23 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntClass a = m.createClass( NS + "A" ); - assertTrue( "enumerated class test not correct", m_owlLiteLang || !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", m_owlLiteLang || !a.isUnionClass() ); - assertTrue( "complement class test not correct", m_owlLiteLang || !a.isComplementClass() ); - assertTrue( "restriction test not correct", !a.isRestriction() ); + assertTrue( m_owlLiteLang || !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( m_owlLiteLang || !a.isUnionClass(), "union class test not correct" ); + assertTrue( m_owlLiteLang || !a.isComplementClass(), "complement class test not correct" ); + assertTrue( !a.isRestriction(), "restriction test not correct" ); ObjectProperty p = m.createObjectProperty( NS + "p" ); a = a.convertToRestriction( p ); - assertTrue( "enumerated class test not correct", m_owlLiteLang || !a.isEnumeratedClass() ); - assertTrue( "intersection class test not correct", !a.isIntersectionClass() ); - assertTrue( "union class test not correct", m_owlLiteLang || !a.isUnionClass() ); - assertTrue( "complement class test not correct", m_owlLiteLang || !a.isComplementClass() ); - assertTrue( "restriction test not correct", a.isRestriction() ); + assertTrue( m_owlLiteLang || !a.isEnumeratedClass(), "enumerated class test not correct" ); + assertTrue( !a.isIntersectionClass(), "intersection class test not correct" ); + assertTrue( m_owlLiteLang || !a.isUnionClass(), "union class test not correct" ); + assertTrue( m_owlLiteLang || !a.isComplementClass(), "complement class test not correct" ); + assertTrue( a.isRestriction(), "restriction test not correct" ); } }, - // restriction type testing new OntTestCase( "Restriction.isAllValuesFrom", true, true, false ) { @Override @@ -963,12 +955,12 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createAllValuesFromRestriction( null, p, b ); - assertTrue( "all values from test not correct", a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, new OntTestCase( "Restriction.isSomeValuesFrom", true, true, false ) { @@ -978,12 +970,12 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createSomeValuesFromRestriction( null, p, b ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, new OntTestCase( "Restriction.isHasValue", true, false, false ) { @@ -994,12 +986,12 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createHasValueRestriction( null, p, x ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, new OntTestCase( "Restriction.isCardinality", true, true, false ) { @@ -1008,12 +1000,12 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createCardinalityRestriction( null, p, 3 ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, new OntTestCase( "Restriction.isMinCardinality", true, true, false ) { @@ -1022,12 +1014,12 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createMinCardinalityRestriction( null, p, 1 ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, new OntTestCase( "Restriction.isMaxCardinality", true, true, false ) { @@ -1036,12 +1028,12 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createMaxCardinalityRestriction( null, p, 5 ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, @@ -1052,22 +1044,22 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createRestriction( p ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); OntClass b = m.createClass( NS + "B" ); a = a.convertToAllValuesFromRestriction( b ); - assertTrue( "all values from test not correct", a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, new OntTestCase( "Restriction.convertToSomeValuesFrom", true, true, false ) { @@ -1076,22 +1068,22 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createRestriction( p ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); OntClass b = m.createClass( NS + "B" ); a = a.convertToSomeValuesFromRestriction( b ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, new OntTestCase( "Restriction.convertToHasValue", true, false, false ) { @@ -1100,23 +1092,23 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createRestriction( p ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); OntClass b = m.createClass( NS + "B" ); Individual x = m.createIndividual( b ); a = a.convertToHasValueRestriction( x ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, new OntTestCase( "Restriction.convertCardinality", true, true, false ) { @@ -1125,21 +1117,21 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createRestriction( p ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); a = a.convertToCardinalityRestriction( 3 ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, new OntTestCase( "Restriction.convertMinCardinality", true, true, false ) { @@ -1148,21 +1140,21 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createRestriction( p ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); a = a.convertToMinCardinalityRestriction( 3 ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, new OntTestCase( "Restriction.convertMaxCardinality", true, true, false ) { @@ -1171,21 +1163,21 @@ public void ontTest( OntModel m ) { ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createRestriction( p ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( !a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); a = a.convertToMaxCardinalityRestriction( 3 ); - assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); - assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); - assertTrue( "has value test not correct", m_owlLiteLang || !a.isHasValueRestriction() ); - assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); - assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); - assertTrue( "max cardinality test not correct", a.isMaxCardinalityRestriction() ); + assertTrue( !a.isAllValuesFromRestriction(), "all values from test not correct" ); + assertTrue( !a.isSomeValuesFromRestriction(), "some values from test not correct" ); + assertTrue( m_owlLiteLang || !a.isHasValueRestriction(), "has value test not correct" ); + assertTrue( !a.isCardinalityRestriction(), "cardinality test not correct" ); + assertTrue( !a.isMinCardinalityRestriction(), "min cardinality test not correct" ); + assertTrue( a.isMaxCardinalityRestriction(), "max cardinality test not correct" ); } }, new OntTestCase( "OntClass.listInstances", true, true, true ) { @@ -1252,8 +1244,8 @@ public void ontTest( OntModel m ) { iteratorTest( C.listDeclaredProperties( false ), new Object[] { p, q, s} ); iteratorTest( C.listDeclaredProperties( true ), new Object[] {s} ); - assertNotNull( "declared property should be an ont prop", C.listDeclaredProperties( true ).next() ); - assertNotNull( "declared property should be an ont prop", C.listDeclaredProperties( false ).next() ); + assertNotNull( C.listDeclaredProperties( true ).next(), "declared property should be an ont prop" ); + assertNotNull( C.listDeclaredProperties( false ).next(), "declared property should be an ont prop" ); } }, new OntTestCase( "DataRange.oneOf", true, false, false ) { @@ -1266,22 +1258,22 @@ public void ontTest( OntModel m ) { DataRange d0 = m.createDataRange( lits ); - assertTrue( "datarange should contain x", d0.hasOneOf( x ) ); - assertTrue( "datarange should contain y", d0.hasOneOf( y ) ); - assertFalse( "datarange should not contain z", d0.hasOneOf( z ) ); + assertTrue( d0.hasOneOf( x ), "datarange should contain x" ); + assertTrue( d0.hasOneOf( y ), "datarange should contain y" ); + assertFalse( d0.hasOneOf( z ), "datarange should not contain z" ); d0.removeOneOf( z ); - assertTrue( "datarange should contain x", d0.hasOneOf( x ) ); - assertTrue( "datarange should contain y", d0.hasOneOf( y ) ); - assertFalse( "datarange should not contain z", d0.hasOneOf( z ) ); + assertTrue( d0.hasOneOf( x ), "datarange should contain x" ); + assertTrue( d0.hasOneOf( y ), "datarange should contain y" ); + assertFalse( d0.hasOneOf( z ), "datarange should not contain z" ); d0.removeOneOf( x ); - assertFalse( "datarange should not contain x", d0.hasOneOf( x ) ); - assertTrue( "datarange should contain y", d0.hasOneOf( y ) ); - assertFalse( "datarange should not contain z", d0.hasOneOf( z ) ); + assertFalse( d0.hasOneOf( x ), "datarange should not contain x" ); + assertTrue( d0.hasOneOf( y ), "datarange should contain y" ); + assertFalse( d0.hasOneOf( z ), "datarange should not contain z" ); d0.addOneOf( z ); - assertEquals( "datarange should be size 2", 2, d0.getOneOf().size() ); + assertEquals( 2, d0.getOneOf().size(), "datarange should be size 2" ); iteratorTest( d0.listOneOf(), new Object[] {y,z} ); d0.setOneOf( m.createList( new RDFNode[] {x} ) ); diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestCreateInOntModel.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestCreateInOntModel.java index 72d56a3b769..72b23ff73c9 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestCreateInOntModel.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestCreateInOntModel.java @@ -23,12 +23,17 @@ /////////////// package org.apache.jena.ontology.impl; - // Imports /////////////// -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; + +import org.apache.jena.test.JenaTestLib; import org.apache.jena.ontology.AllDifferent; import org.apache.jena.ontology.AllValuesFromRestriction; import org.apache.jena.ontology.AnnotationProperty; @@ -62,8 +67,6 @@ import org.apache.jena.rdf.model.Resource; import org.apache.jena.vocabulary.OWL; - - /** *

* Unit test cases for creating values in ontology models @@ -71,8 +74,9 @@ */ @SuppressWarnings("removal") public class TestCreateInOntModel - extends TestCase { + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// public static final String BASE = "http://jena.hpl.hp.com/testing/ontology"; @@ -402,11 +406,6 @@ public OntResource doCreate( OntModel m ) { // Constructors ////////////////////////////////// - public TestCreateInOntModel( String name ) { - super( name ); - } - - // External signature methods ////////////////////////////////// @@ -414,19 +413,17 @@ protected String getTestName() { return "TestCreate"; } - public static TestSuite suite() { - TestSuite s = new TestSuite( "TestCreate" ); - - for ( CreateTestCase testCase : testCases ) - { - s.addTest( testCase ); - } - - return s; + /** + * One dynamic test per entry of the {@code testCases} table. The JUnit3 + * original added each {@code CreateTestCase} to a {@code TestSuite}, so one + * entry remains one test. + */ + @TestFactory + public Stream createInOntModelTests() { + return Stream.of( testCases ) + .map( tc -> DynamicTest.dynamicTest( tc.getName(), () -> { tc.setUp(); tc.runTest(); } ) ); } - - // Internal implementation methods ////////////////////////////////// @@ -435,42 +432,44 @@ public static TestSuite suite() { //============================================================================== protected static class CreateTestCase - extends TestCase { + protected String m_name; protected String m_lang; protected String m_uri; public CreateTestCase( String name, String lang, String uri ) { - super( name ); + m_name = name; m_lang = lang; m_uri = uri; } - @Override + /** The name this case ran under in the JUnit3 suite. */ + public String getName() { + return m_name; + } + public void runTest() { OntModel m = ModelFactory.createOntologyModel( m_lang ); // do the creation step OntResource r = doCreate( m ); - assertNotNull( "Result of creation step should not be null", r ); + assertNotNull( r, "Result of creation step should not be null" ); if (m_uri == null) { - assertTrue( "Created resource should be anonymous", r.isAnon() ); + assertTrue( r.isAnon(), "Created resource should be anonymous" ); } else { - assertEquals( "Created resource has wrong uri", m_uri, r.getURI() ); + assertEquals( m_uri, r.getURI(), "Created resource has wrong uri" ); } - assertTrue( "Result test failed", test( r )); + assertTrue( test( r ), "Result test failed"); } - @Override public void setUp() { // ensure the ont doc manager is in a consistent state OntDocumentManager.getInstance().reset( true ); } - /* get the resource */ public OntResource doCreate( OntModel m ) { // to be overridden in sub-classes diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestFrameView.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestFrameView.java index 9584d58bcc7..03cee8e545b 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestFrameView.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestFrameView.java @@ -25,13 +25,16 @@ // Imports /////////////// -import junit.framework.TestCase; import org.apache.jena.ontology.*; import org.apache.jena.rdf.model.*; -import org.apache.jena.reasoner.test.TestUtil; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.apache.jena.test.JenaTestLib; /** *

@@ -40,8 +43,10 @@ */ @SuppressWarnings("removal") public class TestFrameView - extends TestCase { + + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// @@ -107,7 +112,7 @@ public class TestFrameView // External signature methods ////////////////////////////////// - @Override + @BeforeEach public void setUp() { OntDocumentManager.getInstance().reset(); OntDocumentManager.getInstance().clearCache(); @@ -121,7 +126,6 @@ public void setUp() { infB = mInf.getOntClass( NS + "B" ); infC = mInf.getOntClass( NS + "C" ); - noinfA = mNoInf.getOntClass( NS + "A" ); noinfB = mNoInf.getOntClass( NS + "B" ); noinfC = mNoInf.getOntClass( NS + "C" ); @@ -163,13 +167,13 @@ public void setUp() { noinfPintersect = mNoInf.getObjectProperty( NS + "intersectP" ); } - @Override + @AfterEach public void tearDown() { /* assistance with monitoring space leak System.gc(); System.gc(); Runtime r = Runtime.getRuntime(); - System.out.println( getName() + + System.out.println( getClass().getSimpleName() + " memory = " + r.freeMemory() + ", alloc = " + r.totalMemory() + ", % = " + Math.round( 100.0 * (double) r.freeMemory() / (double) r.totalMemory() )); @@ -182,11 +186,13 @@ public void tearDown() { // OntClass.listDeclaredProperties() tests ... + @Test public void testLDP_noinfA_nodirect() { - TestUtil.assertIteratorValues( this, noinfA.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(noinfA.listDeclaredProperties( false ), new Object[] {noinfPa, noinfQa, noinfG, noinfQb} ); } + @Test public void testHasDP_noinfA_nodirect() { // we only need a small number of tests on hasDP because it's the // main componenet of listDP @@ -194,196 +200,228 @@ public void testHasDP_noinfA_nodirect() { assertFalse( noinfA.hasDeclaredProperty( noinfPb, false ) ); } + @Test public void testLDP_noinfA_direct() { - TestUtil.assertIteratorValues( this, noinfA.listDeclaredProperties( true ), + OntTestUtil.assertIteratorValues(noinfA.listDeclaredProperties( true ), new Object[] {noinfPa, noinfQa, noinfG, noinfQb} ); } + @Test public void testLDP_infA_nodirect() { - TestUtil.assertIteratorValues( this, infA.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(infA.listDeclaredProperties( false ), new Object[] {infPa, infQa, infQb, noinfG} ); } + @Test public void testLDP_infA_direct() { - TestUtil.assertIteratorValues( this, infA.listDeclaredProperties( true ), + OntTestUtil.assertIteratorValues(infA.listDeclaredProperties( true ), new Object[] {infPa, infQa, infQb, noinfG} ); } + @Test public void testLDP_noinfB_nodirect() { - TestUtil.assertIteratorValues( this, noinfB.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(noinfB.listDeclaredProperties( false ), new Object[] {noinfPa, noinfPb, noinfQa, noinfG, noinfQb} ); } + @Test public void testLDP_noinfB_direct() { - TestUtil.assertIteratorValues( this, noinfB.listDeclaredProperties( true ), + OntTestUtil.assertIteratorValues(noinfB.listDeclaredProperties( true ), new Object[] {noinfPb} ); } + @Test public void testLDP_infB_nodirect() { - TestUtil.assertIteratorValues( this, infB.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(infB.listDeclaredProperties( false ), new Object[] {infPa, infPb, infQa, infQb, infG} ); } + @Test public void testLDP_infB_direct() { - TestUtil.assertIteratorValues( this, infB.listDeclaredProperties( true ), + OntTestUtil.assertIteratorValues(infB.listDeclaredProperties( true ), new Object[] {infPb} ); } + @Test public void testLDP_noinfC_nodirect() { // note that qB appears in the results because without inference it looks like a global - TestUtil.assertIteratorValues( this, noinfC.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(noinfC.listDeclaredProperties( false ), new Object[] {noinfPa, noinfPb, noinfPc, noinfQa, noinfG, noinfQb} ); } + @Test public void testLDP_noinfC_direct() { - TestUtil.assertIteratorValues( this, noinfC.listDeclaredProperties( true ), + OntTestUtil.assertIteratorValues(noinfC.listDeclaredProperties( true ), new Object[] {noinfPc} ); } + @Test public void testLDP_infC_nodirect() { - TestUtil.assertIteratorValues( this, infC.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(infC.listDeclaredProperties( false ), new Object[] {infPa, infPb, infPc, infQa, infQb, infG} ); } + @Test public void testLDP_infC_direct() { - TestUtil.assertIteratorValues( this, infC.listDeclaredProperties( true ), + OntTestUtil.assertIteratorValues(infC.listDeclaredProperties( true ), new Object[] {infPc} ); } - + @Test public void testLDP_noinfAnn_nodirect() { // note that qB appears in the results because without inference it looks like a global - TestUtil.assertIteratorValues( this, noinfAnn.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(noinfAnn.listDeclaredProperties( false ), new Object[] {noinfPann, noinfG, noinfQb} ); } + @Test public void testLDP_noinfAnn_direct() { - TestUtil.assertIteratorValues( this, noinfAnn.listDeclaredProperties( true ), + OntTestUtil.assertIteratorValues(noinfAnn.listDeclaredProperties( true ), new Object[] {noinfPann, noinfG, noinfQb} ); } + @Test public void testLDP_infAnn_nodirect() { - TestUtil.assertIteratorValues( this, infAnn.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(infAnn.listDeclaredProperties( false ), new Object[] {noinfPann, noinfG} ); } + @Test public void testLDP_infAnn_direct() { - TestUtil.assertIteratorValues( this, infAnn.listDeclaredProperties( true ), + OntTestUtil.assertIteratorValues(infAnn.listDeclaredProperties( true ), new Object[] {noinfPann, noinfG} ); } - + @Test public void testLDP_noinfUnion_nodirect() { - TestUtil.assertIteratorValues( this, noinfUnion1.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(noinfUnion1.listDeclaredProperties( false ), new Object[] {noinfG, noinfQb} ); - TestUtil.assertIteratorValues( this, noinfUnion2.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(noinfUnion2.listDeclaredProperties( false ), new Object[] {noinfG, noinfQb} ); } + @Test public void testLDP_infUnion_nodirect() { - TestUtil.assertIteratorValues( this, infUnion1.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(infUnion1.listDeclaredProperties( false ), new Object[] {infPunion, infG} ); - TestUtil.assertIteratorValues( this, infUnion2.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(infUnion2.listDeclaredProperties( false ), new Object[] {infPunion, infG} ); } + @Test public void testLDP_noinfIntersect_nodirect() { - TestUtil.assertIteratorValues( this, noinfIntersect1.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(noinfIntersect1.listDeclaredProperties( false ), new Object[] {noinfG, noinfQb} ); - TestUtil.assertIteratorValues( this, noinfIntersect2.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(noinfIntersect2.listDeclaredProperties( false ), new Object[] {noinfG, noinfQb} ); } + @Test public void testLDP_infIntersect_nodirect() { - TestUtil.assertIteratorValues( this, infIntersect1.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(infIntersect1.listDeclaredProperties( false ), new Object[] {infG} ); - TestUtil.assertIteratorValues( this, infIntersect2.listDeclaredProperties( false ), + OntTestUtil.assertIteratorValues(infIntersect2.listDeclaredProperties( false ), new Object[] {infG} ); } // OntProperty.listDeclaringProperties() tests ... + @Test public void testLDC_noinfPa_nodirect() { - TestUtil.assertIteratorValues( this, noinfPa.listDeclaringClasses( false ), + OntTestUtil.assertIteratorValues(noinfPa.listDeclaringClasses( false ), new Object[] {noinfA, noinfB, noinfC} ); } + @Test public void testLDC_infPa_nodirect() { - TestUtil.assertIteratorValues( this, infPa.listDeclaringClasses( false ), + OntTestUtil.assertIteratorValues(infPa.listDeclaringClasses( false ), new Object[] {infA, infB, infC} ); } + @Test public void testLDC_noinfPb_nodirect() { - TestUtil.assertIteratorValues( this, noinfPb.listDeclaringClasses( false ), + OntTestUtil.assertIteratorValues(noinfPb.listDeclaringClasses( false ), new Object[] {noinfB, noinfC} ); } + @Test public void testLDC_infPb_nodirect() { - TestUtil.assertIteratorValues( this, infPb.listDeclaringClasses( false ), + OntTestUtil.assertIteratorValues(infPb.listDeclaringClasses( false ), new Object[] {infC, infB} ); } + @Test public void testLDC_noinfPc_nodirect() { - TestUtil.assertIteratorValues( this, noinfPc.listDeclaringClasses( false ), + OntTestUtil.assertIteratorValues(noinfPc.listDeclaringClasses( false ), new Object[] {noinfC} ); } + @Test public void testLDC_infPc_nodirect() { - TestUtil.assertIteratorValues( this, infPc.listDeclaringClasses( false ), + OntTestUtil.assertIteratorValues(infPc.listDeclaringClasses( false ), new Object[] {infC} ); } + @Test public void testLDC_noinfPa_direct() { - TestUtil.assertIteratorValues( this, noinfPa.listDeclaringClasses( true ), + OntTestUtil.assertIteratorValues(noinfPa.listDeclaringClasses( true ), new Object[] {noinfA} ); } + @Test public void testLDC_infPa_direct() { - TestUtil.assertIteratorValues( this, infPa.listDeclaringClasses( true ), + OntTestUtil.assertIteratorValues(infPa.listDeclaringClasses( true ), new Object[] {infA} ); } + @Test public void testLDC_noinfPb_direct() { - TestUtil.assertIteratorValues( this, noinfPb.listDeclaringClasses( true ), + OntTestUtil.assertIteratorValues(noinfPb.listDeclaringClasses( true ), new Object[] {noinfB} ); } + @Test public void testLDC_infPb_direct() { - TestUtil.assertIteratorValues( this, infPb.listDeclaringClasses( true ), + OntTestUtil.assertIteratorValues(infPb.listDeclaringClasses( true ), new Object[] {infB} ); } + @Test public void testLDC_noinfPc_direct() { - TestUtil.assertIteratorValues( this, noinfPc.listDeclaringClasses( true ), + OntTestUtil.assertIteratorValues(noinfPc.listDeclaringClasses( true ), new Object[] {noinfC} ); } + @Test public void testLDC_infPc_direct() { - TestUtil.assertIteratorValues( this, infPc.listDeclaringClasses( true ), + OntTestUtil.assertIteratorValues(infPc.listDeclaringClasses( true ), new Object[] {infC} ); } + @Test public void testLDC_noinfG_direct() { - TestUtil.assertIteratorValues( this, noinfG.listDeclaringClasses( true ), + OntTestUtil.assertIteratorValues(noinfG.listDeclaringClasses( true ), new Object[] {noinfA, noinfAnn, noinfUnion1, noinfUnion2, mNoInf.getOntClass(NS+"Joint"),noinfIntersect1,noinfIntersect2}, 2 ); } + @Test public void testLDC_infG_direct() { - TestUtil.assertIteratorValues( this, infG.listDeclaringClasses( true ), + OntTestUtil.assertIteratorValues(infG.listDeclaringClasses( true ), new Object[] {infA, infAnn, mNoInf.getOntClass(NS+"Joint"),noinfIntersect1,noinfIntersect2}, 1 ); } + @Test public void testLDC_noinfG_nodirect() { - TestUtil.assertIteratorValues( this, noinfG.listDeclaringClasses( false ), + OntTestUtil.assertIteratorValues(noinfG.listDeclaringClasses( false ), new Object[] {noinfA, noinfB, noinfC, noinfUnion1, noinfUnion2, noinfAnn, mNoInf.getOntClass(NS+"Joint"),noinfIntersect1,noinfIntersect2}, 2 ); } + @Test public void testLDC_infG_nodirect() { - TestUtil.assertIteratorValues( this, infG.listDeclaringClasses( false ), + OntTestUtil.assertIteratorValues(infG.listDeclaringClasses( false ), new Object[] {infA, infB, infC, infAnn, noinfUnion1, noinfUnion2, mNoInf.getOntClass(NS+"Joint"),noinfIntersect1,noinfIntersect2}, 2 ); } - // Internal implementation methods ////////////////////////////////// diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestIndividual.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestIndividual.java index 4eb2c3cd93e..d5ea25169ce 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestIndividual.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestIndividual.java @@ -23,11 +23,9 @@ /////////////// package org.apache.jena.ontology.impl; - // Imports /////////////// -import junit.framework.TestSuite; import org.apache.jena.ontology.Individual; import org.apache.jena.ontology.OntClass; import org.apache.jena.ontology.OntModel; @@ -43,6 +41,9 @@ import java.io.StringReader; import java.util.Iterator; +import static org.junit.jupiter.api.Assertions.*; + +import org.apache.jena.test.JenaTestLib; /** *

@@ -50,32 +51,23 @@ *

*/ @SuppressWarnings("removal") -public class TestIndividual - extends OntTestBase +public class TestIndividual extends OntTestBase { + + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// // Static variables ////////////////////////////////// - - // Instance variables ////////////////////////////////// // Constructors ////////////////////////////////// - static public TestSuite suite() { - return new TestIndividual( "TestIndividual" ); - } - - public TestIndividual( String name ) { - super( name ); - } - - // External signature methods ////////////////////////////////// @@ -93,22 +85,22 @@ public void ontTest( OntModel m ) { Individual z = m.createIndividual( A ); x.addSameAs( y ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.SAME_AS() ) ); - assertEquals( "x should be the same as y", y, x.getSameAs() ); - assertTrue( "x should be the same as y", x.isSameAs( y ) ); + assertEquals( 1, x.getCardinality( prof.SAME_AS() ), "Cardinality should be 1" ); + assertEquals( y, x.getSameAs(), "x should be the same as y" ); + assertTrue( x.isSameAs( y ), "x should be the same as y" ); x.addSameAs( z ); - assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.SAME_AS() ) ); + assertEquals( 2, x.getCardinality( prof.SAME_AS() ), "Cardinality should be 2" ); iteratorTest( x.listSameAs(), new Object[] {z,y} ); x.setSameAs( z ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.SAME_AS() ) ); - assertEquals( "x should be same indiv. as z", z, x.getSameAs() ); + assertEquals( 1, x.getCardinality( prof.SAME_AS() ), "Cardinality should be 1" ); + assertEquals( z, x.getSameAs(), "x should be same indiv. as z" ); x.removeSameAs( y ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.SAME_AS() ) ); + assertEquals( 1, x.getCardinality( prof.SAME_AS() ), "Cardinality should be 1" ); x.removeSameAs( z ); - assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.SAME_AS() ) ); + assertEquals( 0, x.getCardinality( prof.SAME_AS() ), "Cardinality should be 0" ); } }, @@ -323,9 +315,9 @@ protected void ontTest( OntModel m ) { ""; m.read( new StringReader( SOURCE ), null ); Individual x = m.getIndividual( "http://jena.hpl.hp.com/test#x" ); - assertEquals( "Label on resource x", "a_label", x.getLabel( null) ); - assertEquals( "Label on resource x", "a_label", x.getLabel( "" ) ); - assertSame( "fr label on resource x", null, x.getLabel( "fr" ) ); + assertEquals( "a_label", x.getLabel( null), "Label on resource x" ); + assertEquals( "a_label", x.getLabel( "" ), "Label on resource x" ); + assertSame( null, x.getLabel( "fr" ), "fr label on resource x" ); } }, @@ -335,7 +327,7 @@ protected void ontTest( OntModel m ) { OntModel defModel = ModelFactory.createOntologyModel(); OntClass c = defModel.createClass( "http://example.com/test#A" ); Individual i = c.createIndividual(); - assertTrue( "i should be an individual", i.isIndividual() ); + assertTrue( i.isIndividual(), "i should be an individual" ); } }, /** User report of builtin classes showing up as individuals */ @@ -349,7 +341,7 @@ protected void ontTest( OntModel m ) { for (Iterator it = m.listClasses(); it.hasNext(); ) { OntClass ontClass = it.next(); - assertFalse( ontClass.getLocalName() + "should not be an individual", ontClass.isIndividual() ); + assertFalse( ontClass.isIndividual(), ontClass.getLocalName() + "should not be an individual" ); } } }, @@ -364,7 +356,7 @@ protected void ontTest( OntModel m ) { for (Iterator it=m.listClasses(); it.hasNext(); ) { OntClass ontClass = it.next(); - assertFalse( ontClass.getLocalName() + "should not be an individual", ontClass.isIndividual() ); + assertFalse( ontClass.isIndividual(), ontClass.getLocalName() + "should not be an individual" ); } } }, @@ -381,7 +373,7 @@ protected void ontTest( OntModel m ) { for (Iterator it = m.listClasses(); it.hasNext(); ) { OntClass ontClass = it.next(); - assertFalse( ontClass.getLocalName() + " should not be an individual", ontClass.isIndividual() ); + assertFalse( ontClass.isIndividual(), ontClass.getLocalName() + " should not be an individual" ); } } }, @@ -397,7 +389,7 @@ protected void ontTest( OntModel m ) { for (Iterator it = m.listClasses(); it.hasNext(); ) { OntClass ontClass = it.next(); - assertFalse( ontClass.getLocalName() + " should not be an individual", ontClass.isIndividual() ); + assertFalse( ontClass.isIndividual(), ontClass.getLocalName() + " should not be an individual" ); } } }, @@ -413,7 +405,7 @@ protected void ontTest( OntModel m ) { for (Iterator it = m.listClasses(); it.hasNext(); ) { OntClass ontClass = it.next(); - assertFalse( ontClass.getLocalName() + " should not be an individual", ontClass.isIndividual() ); + assertFalse( ontClass.isIndividual(), ontClass.getLocalName() + " should not be an individual" ); } } }, @@ -429,8 +421,8 @@ protected void ontTest( OntModel m ) { OntClass c2 = m.createClass(NS + "C2"); m.add( punned, RDF.type, c2 ); // punned is a class and and instance of c2 - assertFalse( "should not be an individual", c2.isIndividual() ); - assertTrue( "should be an individual", punned.isIndividual() ); + assertFalse( c2.isIndividual(), "should not be an individual" ); + assertTrue( punned.isIndividual(), "should be an individual" ); } }, @@ -444,12 +436,11 @@ protected void ontTest( OntModel m ) { OntClass c2 = m.createClass(NS + "C2"); m.add( punned, RDF.type, c2 ); // punned is a class and and instance of c2 - assertFalse( "should not be an individual", c2.isIndividual() ); - assertTrue( "should be an individual", punned.isIndividual() ); + assertFalse( c2.isIndividual(), "should not be an individual" ); + assertTrue( punned.isIndividual(), "should be an individual" ); } } - }; } diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestListSyntaxCategories.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestListSyntaxCategories.java index 592e1cf5bb0..6da65e69d28 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestListSyntaxCategories.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestListSyntaxCategories.java @@ -26,8 +26,14 @@ // Imports /////////////// -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; + +import org.apache.jena.test.JenaTestLib; import org.apache.jena.ontology.AllDifferent; import org.apache.jena.ontology.AnnotationProperty; import org.apache.jena.ontology.FunctionalProperty; @@ -64,13 +70,13 @@ */ @SuppressWarnings("removal") public class TestListSyntaxCategories - extends TestCase { + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// public static final String NS = "http://jena.hpl.hp.com/testing/ontology#"; - // Static variables ////////////////////////////////// @@ -668,34 +674,26 @@ public boolean test( Resource r ) { }, }; - // Instance variables ////////////////////////////////// // Constructors ////////////////////////////////// - public TestListSyntaxCategories( String name ) { - super( name ); - } - - - // External signature methods ////////////////////////////////// - public static TestSuite suite() { - TestSuite s = new TestSuite( "TestListSyntaxCategories" ); - - for ( DoListTest testCase : testCases ) - { - s.addTest( testCase ); - } - - return s; + /** + * One dynamic test per entry of the {@code testCases} table. The JUnit3 + * original added each {@code DoListTest} to a {@code TestSuite}, so one + * entry remains one test. + */ + @TestFactory + public Stream listSyntaxCategoryTests() { + return Stream.of( testCases ) + .map( tc -> DynamicTest.dynamicTest( tc.getName(), () -> { tc.setUp(); tc.runTest(); } ) ); } - // Internal implementation methods ////////////////////////////////// @@ -704,8 +702,8 @@ public static TestSuite suite() { //============================================================================== protected static class DoListTest - extends TestCase { + protected String m_name; protected String m_fileName; protected OntModelSpec m_spec; protected int m_count; @@ -717,7 +715,7 @@ protected DoListTest( String name, String fileName, OntModelSpec spec, int count } protected DoListTest( String name, String fileName, OntModelSpec spec, int count, String[] expected, boolean exExpected ) { - super( name ); + m_name = name; m_fileName = fileName; m_spec = spec; m_count = count; @@ -725,14 +723,16 @@ protected DoListTest( String name, String fileName, OntModelSpec spec, int count m_exExpected = exExpected; } - @Override + /** The name this case ran under in the JUnit3 suite. */ + public String getName() { + return m_name; + } + public void setUp() { // ensure the ont doc manager is in a consistent state OntDocumentManager.getInstance().reset( true ); } - - @Override public void runTest() { Logger logger = LoggerFactory.getLogger( getClass() ); OntModel m = ModelFactory.createOntologyModel( m_spec, null ); @@ -754,7 +754,7 @@ public void runTest() { exOccurred = true; } - assertEquals( "Ontology exception" + (m_exExpected ? " was " : " was not ") + "expected", m_exExpected, exOccurred ); + assertEquals( m_exExpected, exOccurred, "Ontology exception" + (m_exExpected ? " was " : " was not ") + "expected" ); if (!exOccurred) { List expected = expected( m ); @@ -764,7 +764,7 @@ public void runTest() { // now we walk the iterator while (i.hasNext()) { Resource res = i.next(); - assertTrue( "Should not fail node test on " + res, test( res )); + assertTrue( test( res ), "Should not fail node test on " + res); actual.add( res ); if (expected != null) { @@ -796,10 +796,10 @@ public void runTest() { } } - assertEquals( getName() + ": wrong number of results returned", m_count, actual.size() ); + assertEquals( m_count, actual.size(), getName() + ": wrong number of results returned" ); if (expected != null) { - assertTrue( "Did not find all expected resources in iterator", expected.isEmpty() ); - assertEquals( "Found extraneous results, not in expected list", 0, extraneous ); + assertTrue( expected.isEmpty(), "Did not find all expected resources in iterator" ); + assertEquals( 0, extraneous, "Found extraneous results, not in expected list" ); } } } diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntClass.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntClass.java index 3c0582e4f82..ced9e29f8d7 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntClass.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntClass.java @@ -23,6 +23,9 @@ /////////////// package org.apache.jena.ontology.impl; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; // Imports /////////////// @@ -33,13 +36,11 @@ import org.apache.jena.ontology.OntModelSpec; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Resource; -import org.apache.jena.reasoner.test.TestUtil; -import org.apache.jena.test.JenaTestBase; +import org.apache.jena.test.JenaTestLib; import org.apache.jena.vocabulary.OWL; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDFS; - /** *

* Misc. tests for OntClass, over and above those in @@ -48,8 +49,10 @@ */ @SuppressWarnings("removal") public class TestOntClass - extends JenaTestBase { + + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// @@ -64,13 +67,10 @@ public class TestOntClass // Constructors ////////////////////////////////// - public TestOntClass( String name ) { - super( name ); - } - // External signature methods ////////////////////////////////// + @Test public void testSuperClassNE() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); OntClass a = m.createClass( NS + "A" ); @@ -79,6 +79,7 @@ public void testSuperClassNE() { assertFalse( a.hasSuperClass() ); } + @Test public void testSubClassNE() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); OntClass a = m.createClass( NS + "A" ); @@ -87,6 +88,7 @@ public void testSubClassNE() { assertFalse( a.hasSubClass() ); } + @Test public void testCreateIndividual() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); OntClass a = m.createClass( NS + "A" ); @@ -97,6 +99,7 @@ public void testCreateIndividual() { assertTrue( j.hasRDFType(a) ); } + @Test public void testIsHierarchyRoot0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); OntClass a = m.createClass( NS + "A" ); @@ -106,6 +109,7 @@ public void testIsHierarchyRoot0() { assertFalse( b.isHierarchyRoot() ); } + @Test public void testIsHierarchyRoot1() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RULE_INF ); OntClass a = m.createClass( NS + "A" ); @@ -115,6 +119,7 @@ public void testIsHierarchyRoot1() { assertFalse( b.isHierarchyRoot() ); } + @Test public void testIsHierarchyRoot2() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RDFS_INF ); OntClass a = m.createClass( NS + "A" ); @@ -124,6 +129,7 @@ public void testIsHierarchyRoot2() { assertFalse( b.isHierarchyRoot() ); } + @Test public void testIsHierarchyRoot3() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_TRANS_INF ); OntClass a = m.createClass( NS + "A" ); @@ -133,6 +139,7 @@ public void testIsHierarchyRoot3() { assertFalse( b.isHierarchyRoot() ); } + @Test public void testIsHierarchyRoot4() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM ); OntClass a = m.createClass( NS + "A" ); @@ -142,6 +149,7 @@ public void testIsHierarchyRoot4() { assertFalse( b.isHierarchyRoot() ); } + @Test public void testIsHierarchyRoot5() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_LITE_MEM ); OntClass a = m.createClass( NS + "A" ); @@ -151,6 +159,7 @@ public void testIsHierarchyRoot5() { assertFalse( b.isHierarchyRoot() ); } + @Test public void testIsHierarchyRoot8() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM ); OntClass a = m.createClass( NS + "A" ); @@ -160,6 +169,7 @@ public void testIsHierarchyRoot8() { assertFalse( b.isHierarchyRoot() ); } + @Test public void testIsHierarchyRoot9() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM_RDFS_INF ); OntClass a = m.createClass( NS + "A" ); @@ -169,6 +179,7 @@ public void testIsHierarchyRoot9() { assertFalse( b.isHierarchyRoot() ); } + @Test public void testListSubClasses0() { // no inference OntModel m = createABCDEFModel( OntModelSpec.OWL_MEM ); @@ -178,12 +189,13 @@ public void testListSubClasses0() { OntClass d = m.getOntClass( NS + "D" ); OntClass e = m.getOntClass( NS + "E" ); - TestUtil.assertIteratorValues( this, a.listSubClasses(), new Object[] {b,c} ); - TestUtil.assertIteratorValues( this, a.listSubClasses( false ), new Object[] {b,c} ); - TestUtil.assertIteratorValues( this, a.listSubClasses( true ), new Object[] {b,c} ); - TestUtil.assertIteratorValues( this, b.listSubClasses( true ), new Object[] {d,e} ); + OntTestUtil.assertIteratorValues(a.listSubClasses(), new Object[] {b,c} ); + OntTestUtil.assertIteratorValues(a.listSubClasses( false ), new Object[] {b,c} ); + OntTestUtil.assertIteratorValues(a.listSubClasses( true ), new Object[] {b,c} ); + OntTestUtil.assertIteratorValues(b.listSubClasses( true ), new Object[] {d,e} ); } + @Test public void testListSubClasses1() { // rule inference OntModel m = createABCDEFModel( OntModelSpec.OWL_MEM_RULE_INF ); @@ -194,12 +206,13 @@ public void testListSubClasses1() { OntClass e = m.getOntClass( NS + "E" ); OntClass f = m.getOntClass( NS + "F" ); - TestUtil.assertIteratorValues( this, a.listSubClasses(), new Object[] {b,c,d,e,f} ); - TestUtil.assertIteratorValues( this, a.listSubClasses( false ), new Object[] {b,c,d,e,f} ); - TestUtil.assertIteratorValues( this, a.listSubClasses( true ), new Object[] {b,c} ); - TestUtil.assertIteratorValues( this, b.listSubClasses( true ), new Object[] {d,e} ); + OntTestUtil.assertIteratorValues(a.listSubClasses(), new Object[] {b,c,d,e,f} ); + OntTestUtil.assertIteratorValues(a.listSubClasses( false ), new Object[] {b,c,d,e,f} ); + OntTestUtil.assertIteratorValues(a.listSubClasses( true ), new Object[] {b,c} ); + OntTestUtil.assertIteratorValues(b.listSubClasses( true ), new Object[] {d,e} ); } + @Test public void testListSubClasses2() { // micro rule inference OntModel m = createABCDEFModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF ); @@ -210,12 +223,13 @@ public void testListSubClasses2() { OntClass e = m.getOntClass( NS + "E" ); OntClass f = m.getOntClass( NS + "F" ); - TestUtil.assertIteratorValues( this, a.listSubClasses(), new Object[] {b,c,d,e,f, OWL.Nothing} ); - TestUtil.assertIteratorValues( this, a.listSubClasses( false ), new Object[] {b,c,d,e,f, OWL.Nothing} ); - TestUtil.assertIteratorValues( this, a.listSubClasses( true ), new Object[] {b,c} ); - TestUtil.assertIteratorValues( this, b.listSubClasses( true ), new Object[] {d,e} ); + OntTestUtil.assertIteratorValues(a.listSubClasses(), new Object[] {b,c,d,e,f, OWL.Nothing} ); + OntTestUtil.assertIteratorValues(a.listSubClasses( false ), new Object[] {b,c,d,e,f, OWL.Nothing} ); + OntTestUtil.assertIteratorValues(a.listSubClasses( true ), new Object[] {b,c} ); + OntTestUtil.assertIteratorValues(b.listSubClasses( true ), new Object[] {d,e} ); } + @Test public void testListSuperClasses0() { // no inference OntModel m = createABCDEFModel( OntModelSpec.OWL_MEM ); @@ -224,12 +238,13 @@ public void testListSuperClasses0() { OntClass c = m.getOntClass( NS + "C" ); OntClass e = m.getOntClass( NS + "E" ); - TestUtil.assertIteratorValues( this, e.listSuperClasses(), new Object[] {b,c} ); - TestUtil.assertIteratorValues( this, e.listSuperClasses( false ), new Object[] {b,c} ); - TestUtil.assertIteratorValues( this, e.listSuperClasses( true ), new Object[] {b,c} ); - TestUtil.assertIteratorValues( this, b.listSuperClasses( true ), new Object[] {a} ); + OntTestUtil.assertIteratorValues(e.listSuperClasses(), new Object[] {b,c} ); + OntTestUtil.assertIteratorValues(e.listSuperClasses( false ), new Object[] {b,c} ); + OntTestUtil.assertIteratorValues(e.listSuperClasses( true ), new Object[] {b,c} ); + OntTestUtil.assertIteratorValues(b.listSuperClasses( true ), new Object[] {a} ); } + @Test public void testListSuperClasses1() { // rule inference OntModel m = createABCDEFModel( OntModelSpec.OWL_MEM_RULE_INF ); @@ -238,12 +253,13 @@ public void testListSuperClasses1() { OntClass c = m.getOntClass( NS + "C" ); OntClass e = m.getOntClass( NS + "E" ); - TestUtil.assertIteratorValues( this, e.listSuperClasses(), new Object[] {b,c,a,RDFS.Resource, OWL.Thing} ); - TestUtil.assertIteratorValues( this, e.listSuperClasses( false ), new Object[] {b,c,a,RDFS.Resource, OWL.Thing} ); - TestUtil.assertIteratorValues( this, e.listSuperClasses( true ), new Object[] {b,c} ); - TestUtil.assertIteratorValues( this, b.listSuperClasses( true ), new Object[] {a} ); + OntTestUtil.assertIteratorValues(e.listSuperClasses(), new Object[] {b,c,a,RDFS.Resource, OWL.Thing} ); + OntTestUtil.assertIteratorValues(e.listSuperClasses( false ), new Object[] {b,c,a,RDFS.Resource, OWL.Thing} ); + OntTestUtil.assertIteratorValues(e.listSuperClasses( true ), new Object[] {b,c} ); + OntTestUtil.assertIteratorValues(b.listSuperClasses( true ), new Object[] {a} ); } + @Test public void testListSuperClasses2() { // micro rule inference OntModel m = createABCDEFModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF); @@ -252,12 +268,13 @@ public void testListSuperClasses2() { OntClass c = m.getOntClass( NS + "C" ); OntClass e = m.getOntClass( NS + "E" ); - TestUtil.assertIteratorValues( this, e.listSuperClasses(), new Object[] {b,c,a, OWL.Thing} ); - TestUtil.assertIteratorValues( this, e.listSuperClasses( false ), new Object[] {b,c,a, OWL.Thing} ); - TestUtil.assertIteratorValues( this, e.listSuperClasses( true ), new Object[] {b,c} ); - TestUtil.assertIteratorValues( this, b.listSuperClasses( true ), new Object[] {a} ); + OntTestUtil.assertIteratorValues(e.listSuperClasses(), new Object[] {b,c,a, OWL.Thing} ); + OntTestUtil.assertIteratorValues(e.listSuperClasses( false ), new Object[] {b,c,a, OWL.Thing} ); + OntTestUtil.assertIteratorValues(e.listSuperClasses( true ), new Object[] {b,c} ); + OntTestUtil.assertIteratorValues(b.listSuperClasses( true ), new Object[] {a} ); } + @Test public void testListSuperClasses3() { OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntClass A = m.createClass( NS +"A"); @@ -268,11 +285,10 @@ public void testListSuperClasses3() { B.addSuperClass(C); C.addSuperClass(B); - TestUtil.assertIteratorValues( this, A.listSuperClasses( true ), new Object[] {B,C} ); + OntTestUtil.assertIteratorValues(A.listSuperClasses( true ), new Object[] {B,C} ); } - - + @Test public void testListInstances0() { // no inference OntModel m = createABCDEFModel( OntModelSpec.OWL_MEM ); @@ -282,13 +298,14 @@ public void testListInstances0() { Individual ia = a.createIndividual(); Individual ib = b.createIndividual(); - TestUtil.assertIteratorValues( this, a.listInstances(), new Object[] {ia} ); - TestUtil.assertIteratorValues( this, b.listInstances(), new Object[] {ib} ); + OntTestUtil.assertIteratorValues(a.listInstances(), new Object[] {ia} ); + OntTestUtil.assertIteratorValues(b.listInstances(), new Object[] {ib} ); - TestUtil.assertIteratorValues( this, a.listInstances(true), new Object[] {ia} ); - TestUtil.assertIteratorValues( this, b.listInstances(true), new Object[] {ib} ); + OntTestUtil.assertIteratorValues(a.listInstances(true), new Object[] {ia} ); + OntTestUtil.assertIteratorValues(b.listInstances(true), new Object[] {ib} ); } + @Test public void testListInstances1() { // no inference OntModel m = createABCDEFModel( OntModelSpec.OWL_MEM_RULE_INF ); @@ -304,13 +321,14 @@ public void testListInstances1() { Individual id = d.createIndividual(NS + "iD"); Individual ie = e.createIndividual(NS + "iE"); - TestUtil.assertIteratorValues( this, a.listInstances(), new Object[] {ia,ib,ic,id,ie} ); - TestUtil.assertIteratorValues( this, b.listInstances(), new Object[] {ib,id,ie} ); + OntTestUtil.assertIteratorValues(a.listInstances(), new Object[] {ia,ib,ic,id,ie} ); + OntTestUtil.assertIteratorValues(b.listInstances(), new Object[] {ib,id,ie} ); - TestUtil.assertIteratorValues( this, a.listInstances(true), new Object[] {ia} ); - TestUtil.assertIteratorValues( this, b.listInstances(true), new Object[] {ib} ); + OntTestUtil.assertIteratorValues(a.listInstances(true), new Object[] {ia} ); + OntTestUtil.assertIteratorValues(b.listInstances(true), new Object[] {ib} ); } + @Test public void testListInstances2() { // no inference OntModel m = createABCDEFModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF ); @@ -326,13 +344,14 @@ public void testListInstances2() { Individual id = d.createIndividual(NS + "iD"); Individual ie = e.createIndividual(NS + "iE"); - TestUtil.assertIteratorValues( this, a.listInstances(), new Object[] {ia,ib,ic,id,ie} ); - TestUtil.assertIteratorValues( this, b.listInstances(), new Object[] {ib,id,ie} ); + OntTestUtil.assertIteratorValues(a.listInstances(), new Object[] {ia,ib,ic,id,ie} ); + OntTestUtil.assertIteratorValues(b.listInstances(), new Object[] {ib,id,ie} ); - TestUtil.assertIteratorValues( this, a.listInstances(true), new Object[] {ia} ); - TestUtil.assertIteratorValues( this, b.listInstances(true), new Object[] {ib} ); + OntTestUtil.assertIteratorValues(a.listInstances(true), new Object[] {ia} ); + OntTestUtil.assertIteratorValues(b.listInstances(true), new Object[] {ib} ); } + @Test public void testDropIndividual() { OntModel m = createABCDEFModel( OntModelSpec.OWL_MEM ); OntClass a = m.getOntClass( NS + "A" ); @@ -362,6 +381,7 @@ public void testDropIndividual() { assertFalse( ia.hasOntClass( b ) ); } + @Test public void testDatatypeIsClassOwlFull() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); Resource c = m.createResource(); @@ -369,6 +389,7 @@ public void testDatatypeIsClassOwlFull() { assertTrue( c.canAs( OntClass.class )); } + @Test public void testDatatypeIsClassOwlDL() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM ); Resource c = m.createResource(); @@ -376,6 +397,7 @@ public void testDatatypeIsClassOwlDL() { assertTrue( c.canAs( OntClass.class )); } + @Test public void testDatatypeIsClassOwlLite() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_LITE_MEM ); Resource c = m.createResource(); @@ -383,6 +405,7 @@ public void testDatatypeIsClassOwlLite() { assertTrue( c.canAs( OntClass.class )); } + @Test public void testDatatypeIsClassOwlRDFS() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM ); Resource c = m.createResource(); @@ -390,6 +413,7 @@ public void testDatatypeIsClassOwlRDFS() { assertTrue( c.canAs( OntClass.class )); } + @Test public void testOwlThingNothingClass() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); @@ -437,7 +461,6 @@ protected OntModel createABCDEFModel( OntModelSpec spec ) { return m; } - //============================================================================== // Inner class definitions //============================================================================== diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntDocumentManager.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntDocumentManager.java index f911fe20cea..cef4fe7a35a 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntDocumentManager.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntDocumentManager.java @@ -23,12 +23,9 @@ /////////////// package org.apache.jena.ontology.impl; - // Imports /////////////// -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.ontology.OntClass; import org.apache.jena.ontology.OntDocumentManager; import org.apache.jena.ontology.OntDocumentManager.ReadFailureHandler; @@ -43,7 +40,6 @@ import org.apache.jena.rdf.model.Resource; import org.apache.jena.rdf.model.StmtIterator; import org.apache.jena.rdf.model.impl.RDFReaderFImpl; -import org.apache.jena.reasoner.test.TestUtil; import org.apache.jena.test.X_RDFReaderF; import org.apache.jena.vocabulary.OWL; import org.apache.jena.vocabulary.OntDocManagerVocab; @@ -58,7 +54,17 @@ import java.util.List; import java.util.Set; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.apache.jena.test.JenaTestLib; /** *

@@ -67,9 +73,10 @@ */ @SuppressWarnings("removal") public class TestOntDocumentManager - extends TestCase { + static { JenaTestLib.setup(); } + static { RDFReaderFImpl.alternative(new X_RDFReaderF()); } // Constants @@ -97,39 +104,16 @@ public class TestOntDocumentManager { "testing/ontology/testImport5", cnt(2), T, "file:testing/ontology/testImport5/ont-policy.rdf" } }; - // Instance variables ////////////////////////////////// - // Constructors ////////////////////////////////// - public TestOntDocumentManager( String s ) { - super( s ); - } - - public static TestSuite suite() { - TestSuite suite = new TestSuite( "TestOntDocumentManager" ); - - // add the fixed test cases - suite.addTestSuite( TestOntDocumentManager.class ); - - // add the data-driven test cases - for ( Object[] aS_testData : s_testData ) - { - suite.addTest( new DocManagerImportTest( (String) aS_testData[0], ( (Integer) aS_testData[1] ).intValue(), - ( (Boolean) aS_testData[2] ).booleanValue(), - (String) aS_testData[3] ) ); - } - return suite; - } - - // External signature methods ////////////////////////////////// - @Override + @BeforeEach public void setUp() { // ensure the ont doc manager is in a consistent state OntDocumentManager.getInstance().reset( true ); @@ -148,23 +132,27 @@ public void setUp() { } } + @Test public void testConstruct0() { OntDocumentManager m = new OntDocumentManager(); assertNotNull( m ); assertEquals( m.getMetadataSearchPath(), OntDocumentManager.DEFAULT_METADATA_PATH ); } + @Test public void testConstruct1() { OntDocumentManager mgr = new OntDocumentManager( "" ); - assertTrue( "Should be no specification loaded", !mgr.listDocuments().hasNext() ); + assertTrue( !mgr.listDocuments().hasNext(), "Should be no specification loaded" ); } + @Test public void testConstruct2() { // make sure we don't fail on null OntDocumentManager mgr = new OntDocumentManager( (String) null ); - assertTrue( "Should be no specification loaded", !mgr.listDocuments().hasNext() ); + assertTrue( !mgr.listDocuments().hasNext(), "Should be no specification loaded" ); } + @Test public void testConstruct3() { Model m = ModelFactory.createDefaultModel(); Resource r = m.createResource(); @@ -173,17 +161,19 @@ public void testConstruct3() { r.addProperty( OntDocManagerVocab.altURL, m.createResource("file:local.rdf") ); OntDocumentManager mgr = new OntDocumentManager( m ); - assertEquals( "cache URL not correct", "file:local.rdf", mgr.doAltURLMapping( "http://example.com/foo" )); + assertEquals( "file:local.rdf", mgr.doAltURLMapping( "http://example.com/foo" ), "cache URL not correct"); } + @Test public void testInitialisation() { OntDocumentManager mgr = new OntDocumentManager( "ont-policy-test.rdf" ); - assertTrue( "Should be at least one specification loaded", mgr.listDocuments().hasNext() ); - assertNotNull( "cache URL for owl should not be null", mgr.doAltURLMapping( "http://www.w3.org/2002/07/owl" )); - assertEquals( "cache URL for owl not correct", "file:vocabularies/owl.owl", mgr.doAltURLMapping( "http://www.w3.org/2002/07/owl" )); + assertTrue( mgr.listDocuments().hasNext(), "Should be at least one specification loaded" ); + assertNotNull( mgr.doAltURLMapping( "http://www.w3.org/2002/07/owl" ), "cache URL for owl should not be null"); + assertEquals( "file:vocabularies/owl.owl", mgr.doAltURLMapping( "http://www.w3.org/2002/07/owl" ), "cache URL for owl not correct"); } + @Test public void testGetInstance() { OntDocumentManager odm = OntDocumentManager.getInstance(); assertNotNull( odm ); @@ -192,6 +182,7 @@ public void testGetInstance() { assertSame( odm, odm2 ); } + @Test public void testSetMetadataSearchPath() { OntDocumentManager odm = new OntDocumentManager( "ont-policy-test.rdf" ); assertEquals( "ont-policy-test.rdf", odm.getMetadataSearchPath() ); @@ -211,6 +202,7 @@ public void testSetMetadataSearchPath() { assertEquals( "ont-policy-test.rdf", odm.getLoadedPolicyURL() ); } + @Test public void testConfigure0() { Model m = ModelFactory.createDefaultModel(); Resource r = m.createResource(); @@ -219,12 +211,13 @@ public void testConfigure0() { r.addProperty( OntDocManagerVocab.altURL, m.createResource("file:local.rdf") ); OntDocumentManager odm = new OntDocumentManager( "ont-policy-test.rdf" ); - TestUtil.assertIteratorLength( odm.listDocuments(), 3 ); + OntTestUtil.assertIteratorLength( odm.listDocuments(), 3 ); odm.configure( m, false ); - TestUtil.assertIteratorLength( odm.listDocuments(), 4 ); + OntTestUtil.assertIteratorLength( odm.listDocuments(), 4 ); } + @Test public void testConfigure1() { Model m = ModelFactory.createDefaultModel(); Resource r = m.createResource(); @@ -233,12 +226,13 @@ public void testConfigure1() { r.addProperty( OntDocManagerVocab.altURL, m.createResource("file:local.rdf") ); OntDocumentManager odm = new OntDocumentManager( "ont-policy-test.rdf" ); - TestUtil.assertIteratorLength( odm.listDocuments(), 3 ); + OntTestUtil.assertIteratorLength( odm.listDocuments(), 3 ); odm.configure( m ); - TestUtil.assertIteratorLength( odm.listDocuments(), 1 ); + OntTestUtil.assertIteratorLength( odm.listDocuments(), 1 ); } + @Test public void testConfigure2() { // create a simple policy Model m = ModelFactory.createDefaultModel(); @@ -249,10 +243,10 @@ public void testConfigure2() { OntDocumentManager mgr = new OntDocumentManager( (String) null ); assertTrue( mgr.getCacheModels() ); mgr.configure( m ); - assertFalse( "Docmgr configure() should have updated cache models flag", mgr.getCacheModels() ); + assertFalse( mgr.getCacheModels(), "Docmgr configure() should have updated cache models flag" ); } - + @Test public void testReset() { OntDocumentManager mgr = new OntDocumentManager( (String) null ); @@ -274,12 +268,14 @@ public void testReset() { assertTrue( mgr.getCacheModels() ); } + @Test public void testDoAltMapping() { OntDocumentManager odm = new OntDocumentManager( "ont-policy-test.rdf" ); assertEquals( "file:vocabularies/owl.owl", odm.doAltURLMapping( "http://www.w3.org/2002/07/owl" )); assertEquals( "http://example.com/nocache", odm.doAltURLMapping( "http://example.com/nocache" )); } + @Test public void testAddModel0() { OntDocumentManager odm = OntDocumentManager.getInstance(); Model m = ModelFactory.createDefaultModel(); @@ -289,6 +285,7 @@ public void testAddModel0() { assertSame( m, odm.getModel(uri)); } + @Test public void testAddModel1() { OntDocumentManager odm = OntDocumentManager.getInstance(); Model m0 = ModelFactory.createDefaultModel(); @@ -306,6 +303,7 @@ public void testAddModel1() { assertSame( m1, odm.getModel(uri)); } + @Test public void testClearCache0() { OntDocumentManager odm = OntDocumentManager.getInstance(); Model m = ModelFactory.createDefaultModel(); @@ -319,6 +317,7 @@ public void testClearCache0() { /** * Ensure that sub-model imports are not re-used after clearing the cache. */ + @Test public void testClearCache1() { OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM); spec.getDocumentManager().reset(); @@ -350,6 +349,7 @@ public void testClearCache1() { assertEquals( count0, subModel1.size() ); } + @Test public void testForget() { OntDocumentManager odm = new OntDocumentManager( "ont-policy-test.rdf" ); assertEquals( "file:vocabularies/owl.owl", odm.doAltURLMapping( "http://www.w3.org/2002/07/owl" ) ); @@ -364,6 +364,7 @@ public void testForget() { assertNull( odm.getModel( "http://www.w3.org/2002/07/owl#" )); } + @Test public void testGetOntology() { OntDocumentManager odm = new OntDocumentManager( "ont-policy-test.rdf" ); OntModel m = odm.getOntology( "http://www.w3.org/2002/07/owl", OntModelSpec.OWL_MEM ); @@ -373,6 +374,7 @@ public void testGetOntology() { assertSame( m, m1 ); } + @Test public void testProcessImports() { OntDocumentManager odm = new OntDocumentManager( "ont-policy-test.rdf" ); assertTrue( odm.getProcessImports() ); @@ -380,6 +382,7 @@ public void testProcessImports() { assertFalse( odm.getProcessImports() ); } + @Test public void testCacheModels() { OntDocumentManager odm = new OntDocumentManager( "ont-policy-test.rdf" ); assertTrue( odm.getCacheModels() ); @@ -387,13 +390,15 @@ public void testCacheModels() { assertFalse( odm.getCacheModels() ); } + @Test public void testManualAssociation() { OntDocumentManager odm = new OntDocumentManager( (String) null ); odm.addAltEntry( "http://www.w3.org/2002/07/owl", "file:foo.bar" ); - assertEquals( "Failed to retrieve cache location", "file:foo.bar", odm.doAltURLMapping( "http://www.w3.org/2002/07/owl" ) ); + assertEquals( "file:foo.bar", odm.doAltURLMapping( "http://www.w3.org/2002/07/owl" ), "Failed to retrieve cache location" ); } + @Test public void testRelativeNames() { OntModel m = ModelFactory.createOntologyModel(); m.getDocumentManager().addAltEntry( @@ -405,71 +410,74 @@ public void testRelativeNames() { assertFalse( m.getResource("file:testing/ontology/relativenames.rdf#A").canAs(OntClass.class)); } - - + @Test public void testIgnoreImport() { OntDocumentManager odm = new OntDocumentManager(); - TestUtil.assertIteratorLength( odm.listIgnoredImports(), 0 ); + OntTestUtil.assertIteratorLength( odm.listIgnoredImports(), 0 ); odm.addIgnoreImport( "file:testing/ontology/testImport3/c.owl" ); - TestUtil.assertIteratorLength( odm.listIgnoredImports(), 1 ); + OntTestUtil.assertIteratorLength( odm.listIgnoredImports(), 1 ); assertTrue( odm.ignoringImport( "file:testing/ontology/testImport3/c.owl")); assertFalse( odm.ignoringImport( "file:testing/ontology/foo.owl")); OntModelSpec spec = new OntModelSpec( null, odm, null, ProfileRegistry.OWL_LANG ); OntModel m = ModelFactory.createOntologyModel( spec, null ); - assertNotNull( "Ontology model should not be null", m ); + assertNotNull( m, "Ontology model should not be null" ); m.read( "file:testing/ontology/testImport3/a.owl" ); - assertEquals( "Marker count not correct", 2, countMarkers( m )); + assertEquals( 2, countMarkers( m ), "Marker count not correct"); odm.removeIgnoreImport( "file:testing/ontology/testImport3/c.owl" ); - TestUtil.assertIteratorLength( odm.listIgnoredImports(), 0 ); + OntTestUtil.assertIteratorLength( odm.listIgnoredImports(), 0 ); assertFalse( odm.ignoringImport( "file:testing/ontology/testImport3/c.owl")); } /** Simple case: a imports b, b imports c, remove c */ + @Test public void testUnloadImport1() { OntModel m = ModelFactory.createOntologyModel(); m.read( "file:testing/ontology/testImport3/a.owl" ); - assertEquals( "Marker count not correct", 3, countMarkers( m ) ); + assertEquals( 3, countMarkers( m ), "Marker count not correct" ); - assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should be imported" ); m.getDocumentManager().unloadImport( m, "file:testing/ontology/testImport3/c.owl" ); - assertEquals( "Marker count not correct", 2, countMarkers( m ) ); - assertFalse( "c should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); + assertEquals( 2, countMarkers( m ), "Marker count not correct" ); + assertFalse( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should not be imported" ); } /** case 2: a imports b, b imports c, remove b */ + @Test public void testUnloadImport2() { OntModel m = ModelFactory.createOntologyModel(); m.read( "file:testing/ontology/testImport3/a.owl" ); - assertEquals( "Marker count not correct", 3, countMarkers( m ) ); + assertEquals( 3, countMarkers( m ), "Marker count not correct" ); - assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); - assertTrue( "b should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should be imported" ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ), "b should be imported" ); m.getDocumentManager().unloadImport( m, "file:testing/ontology/testImport3/b.owl" ); - assertEquals( "Marker count not correct", 1, countMarkers( m ) ); - assertFalse( "c should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); - assertFalse( "b should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) ); + assertEquals( 1, countMarkers( m ), "Marker count not correct" ); + assertFalse( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should not be imported" ); + assertFalse( m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ), "b should not be imported" ); } /** case 3: a imports b, b imports c, a imports d, d imports c, remove b */ + @Test public void testUnloadImport3() { OntModel m = ModelFactory.createOntologyModel(); m.read( "file:testing/ontology/testImport6/a.owl" ); - assertEquals( "Marker count not correct", 4, countMarkers( m ) ); + assertEquals( 4, countMarkers( m ), "Marker count not correct" ); - assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport6/c.owl" ) ); - assertTrue( "b should be imported", m.hasLoadedImport( "file:testing/ontology/testImport6/b.owl" ) ); - assertTrue( "d should be imported", m.hasLoadedImport( "file:testing/ontology/testImport6/d.owl" ) ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport6/c.owl" ), "c should be imported" ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport6/b.owl" ), "b should be imported" ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport6/d.owl" ), "d should be imported" ); m.getDocumentManager().unloadImport( m, "file:testing/ontology/testImport6/b.owl" ); - assertEquals( "Marker count not correct", 3, countMarkers( m ) ); - assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport6/c.owl" ) ); - assertTrue( "d should be imported", m.hasLoadedImport( "file:testing/ontology/testImport6/d.owl" ) ); - assertFalse( "b should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport6/b.owl" ) ); + assertEquals( 3, countMarkers( m ), "Marker count not correct" ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport6/c.owl" ), "c should be imported" ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport6/d.owl" ), "d should be imported" ); + assertFalse( m.hasLoadedImport( "file:testing/ontology/testImport6/b.owl" ), "b should not be imported" ); } + @Test public void testDynamicImports1() { OntModel m = ModelFactory.createOntologyModel(); Resource a = m.getResource( "file:testing/ontology/testImport3/a.owl" ); @@ -477,12 +485,13 @@ public void testDynamicImports1() { m.add( a, m.getProfile().IMPORTS(), b ); // not dymamically imported by default - assertEquals( "Marker count not correct", 0, countMarkers( m ) ); + assertEquals( 0, countMarkers( m ), "Marker count not correct" ); - assertFalse( "c should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); - assertFalse( "b should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) ); + assertFalse( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should not be imported" ); + assertFalse( m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ), "b should not be imported" ); } + @Test public void testDynamicImports2() { OntModel m = ModelFactory.createOntologyModel(); Resource a = m.getResource( "file:testing/ontology/testImport3/a.owl" ); @@ -493,19 +502,20 @@ public void testDynamicImports2() { m.add( a, m.getProfile().IMPORTS(), b ); // dynamically imported - assertEquals( "Marker count not correct", 2, countMarkers( m ) ); + assertEquals( 2, countMarkers( m ), "Marker count not correct" ); - assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); - assertTrue( "b should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should be imported" ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ), "b should be imported" ); } + @Test public void testDynamicImports3() { OntModel m = ModelFactory.createOntologyModel(); m.read( "file:testing/ontology/testImport3/a.owl" ); - assertEquals( "Marker count not correct", 3, countMarkers( m ) ); + assertEquals( 3, countMarkers( m ), "Marker count not correct" ); - assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); - assertTrue( "b should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should be imported" ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ), "b should be imported" ); m.setDynamicImports( true ); @@ -513,28 +523,30 @@ public void testDynamicImports3() { Resource b = m.getResource( OntResolve.resolve("file:testing/ontology/testImport3/b.owl") ); m.remove( m.createStatement( a, m.getProfile().IMPORTS(), b ) ); - assertEquals( "Marker count not correct", 1, countMarkers( m ) ); - assertFalse( "c should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); - assertFalse( "b should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) ); + assertEquals( 1, countMarkers( m ), "Marker count not correct" ); + assertFalse( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should not be imported" ); + assertFalse( m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ), "b should not be imported" ); } + @Test public void testSearchPath() { OntDocumentManager o1 = new OntDocumentManager( "ont-policy-test.rdf" ); - assertEquals( "Did not return correct loaded search path", "ont-policy-test.rdf", o1.getLoadedPolicyURL() ); + assertEquals( "ont-policy-test.rdf", o1.getLoadedPolicyURL(), "Did not return correct loaded search path" ); OntDocumentManager o2 = new OntDocumentManager( "ont-policy-test.notexist.rdf;ont-policy-test.rdf" ); - assertEquals( "Did not return correct loaded search path", "ont-policy-test.rdf", o2.getLoadedPolicyURL() ); + assertEquals( "ont-policy-test.rdf", o2.getLoadedPolicyURL(), "Did not return correct loaded search path" ); OntDocumentManager o3 = new OntDocumentManager( (String) null ); - assertNull( "Most recent policy should be null", o3.getLoadedPolicyURL() ); + assertNull( o3.getLoadedPolicyURL(), "Most recent policy should be null" ); o3.setMetadataSearchPath( "ont-policy-test.rdf", true ); - assertEquals( "Did not return correct loaded search path", "ont-policy-test.rdf", o2.getLoadedPolicyURL() ); + assertEquals( "ont-policy-test.rdf", o2.getLoadedPolicyURL(), "Did not return correct loaded search path" ); o3.setMetadataSearchPath( "ont-policy-test.notexist.rdf", true ); - assertNull( "Most recent policy should be null", o3.getLoadedPolicyURL() ); + assertNull( o3.getLoadedPolicyURL(), "Most recent policy should be null" ); } + @Test public void testReadFailHandler0() { OntDocumentManager o1 = new OntDocumentManager( "ont-policy-test.rdf" ); assertNull( o1.getReadFailureHandler() ); @@ -553,6 +565,7 @@ public void testReadFailHandler0() { * is designed for domain names that are sure to be invalid. See * tools.ietf.org/html/rfc2606#section-2 */ + @Test public void testReadFailHandler1() { OntDocumentManager o1 = new OntDocumentManager( "ont-policy-test.rdf" ); @@ -569,6 +582,7 @@ public void testReadFailHandler1() { assertTrue( rfh.m_seen ); } + @Test public void testReadHook0() { TestReadHook rh = new TestReadHook( false ); OntDocumentManager o1 = new OntDocumentManager( "ont-policy-test.rdf" ); @@ -585,10 +599,11 @@ public void testReadHook0() { OntModel m = ModelFactory.createOntologyModel( spec ); m.read( new StringReader( source ), "http://example.com/foo#", "N3" ); - assertEquals( "Wrong number of calls to before load hook", 3, rh.m_before ); - assertEquals( "Wrong number of calls to after load hook", 3, rh.m_after ); + assertEquals( 3, rh.m_before, "Wrong number of calls to before load hook" ); + assertEquals( 3, rh.m_after, "Wrong number of calls to after load hook" ); } + @Test public void testReadHook1() { TestReadHook rh = new TestReadHook( true ); OntDocumentManager o1 = new OntDocumentManager( "ont-policy-test.rdf" ); @@ -602,11 +617,10 @@ public void testReadHook1() { OntModel m = ModelFactory.createOntologyModel( spec ); m.read( new StringReader( source ), "http://example.com/foo#", "N3" ); - assertEquals( "Wrong number of calls to before load hook", 1, rh.m_before ); - assertEquals( "Wrong number of calls to after load hook", 1, rh.m_after ); + assertEquals( 1, rh.m_before, "Wrong number of calls to before load hook" ); + assertEquals( 1, rh.m_after, "Wrong number of calls to after load hook" ); } - /* count the number of marker statements in the combined model */ public static int countMarkers( Model m ) { int count = 0; @@ -620,10 +634,22 @@ public static int countMarkers( Model m ) { return count; } + /** + * One dynamic test per row of {@code s_testData}. The JUnit3 suite() added + * the fixed test cases (now ordinary @Test methods) plus one + * DocManagerImportTest per row, so one row remains one test. + */ + @TestFactory + public Stream docManagerImportTests() { + return Stream.of( s_testData ) + .map( row -> new DocManagerImportTest( (String) row[0], ((Integer) row[1]).intValue(), + ((Boolean) row[2]).booleanValue(), (String) row[3] ) ) + .map( tc -> DynamicTest.dynamicTest( tc.getName(), tc::runTest ) ); + } + // Internal implementation methods ////////////////////////////////// - //============================================================================== // Inner class definitions //============================================================================== @@ -640,8 +666,8 @@ public static int countMarkers( Model m ) { * total. */ static class DocManagerImportTest - extends TestCase { + String m_name; String m_dir; int m_count; String m_path; @@ -649,7 +675,7 @@ static class DocManagerImportTest /* constuctor */ DocManagerImportTest( String dir, int count, boolean processImports, String path ) { - super( dir ); + m_name = dir; m_dir = dir; m_count = count; m_path = path; @@ -658,7 +684,11 @@ static class DocManagerImportTest // external contract methods - @Override + /** The name this case ran under in the JUnit3 suite. */ + public String getName() { + return m_name; + } + public void runTest() { OntDocumentManager dm = new OntDocumentManager(); @@ -671,7 +701,7 @@ public void runTest() { // now load the model - we always start from a.owl in the given directory OntModelSpec spec = new OntModelSpec( null, dm, null, ProfileRegistry.OWL_LANG ); OntModel m = ModelFactory.createOntologyModel( spec, null ); - assertNotNull( "Ontology model should not be null", m ); + assertNotNull( m, "Ontology model should not be null" ); String filename = "file:" + m_dir + "/a.owl"; @@ -680,7 +710,7 @@ public void runTest() { } catch (Throwable ex) { m.read(filename); } - assertEquals( "Marker count not correct: "+filename, m_count, countMarkers( m )); + assertEquals( m_count, countMarkers( m ), "Marker count not correct: "+filename); } } diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntGraph.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntGraph.java index de77911a8b2..7fa8c8aaba1 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntGraph.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntGraph.java @@ -21,23 +21,19 @@ package org.apache.jena.ontology.impl; -import junit.framework.TestSuite; -import org.apache.jena.graph.AbstractTestGraph; +import org.apache.jena.graph.BaseTestGraph_JU6; import org.apache.jena.graph.Graph; import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.test.JenaTestLib; /** Ensure that an OntGraph passes the graph tests. Clunky because it has to go via OntModel - there doesn't appear to be an OntGraph class. */ -public class TestOntGraph extends AbstractTestGraph +public class TestOntGraph extends BaseTestGraph_JU6 { - public TestOntGraph( String name ) - { super( name ); } - - public static TestSuite suite() - { return new TestSuite( TestOntGraph.class ); } + static { JenaTestLib.setup(); } @Override @SuppressWarnings("removal") diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntModel.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntModel.java index e4e6d6e1afc..c48ef75bd5d 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntModel.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntModel.java @@ -23,7 +23,6 @@ /////////////// package org.apache.jena.ontology.impl; - // Imports /////////////// @@ -43,8 +42,6 @@ import org.apache.jena.ontology.impl.OWLProfile.SupportsCheck; import org.apache.jena.rdf.model.*; import org.apache.jena.reasoner.rulesys.test.TestRuleSystemBugs; -import org.apache.jena.reasoner.test.TestUtil; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.test.JenaTestLib; import org.apache.jena.vocabulary.OWL; import org.apache.jena.vocabulary.RDF; @@ -61,7 +58,10 @@ import java.util.List; import java.util.Map; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** *

@@ -71,8 +71,10 @@ */ @SuppressWarnings("removal") public class TestOntModel - extends JenaTestBase { + + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// @@ -111,21 +113,17 @@ public class TestOntModel // Constructors ////////////////////////////////// - public TestOntModel( String name ) { - super( name ); - } - // External signature methods ////////////////////////////////// - @Override + @BeforeEach public void setUp() { // ensure the ont doc manager is in a consistent state OntDocumentManager.getInstance().reset( true ); } - /** Test writing the base model to an output stream */ + @Test public void testWriteOutputStream() { OntModel m = ModelFactory.createOntologyModel(); @@ -160,10 +158,11 @@ public void testWriteOutputStream() { mIn2.read( new ByteArrayInputStream( DOC.getBytes() ), BASE ); // should be the same - assertTrue( "InputStream write/read cycle failed (1)", mIn1.isIsomorphicWith( m.getBaseModel() ) ); - assertTrue( "InputStream write/read cycle failed (2)", mIn2.isIsomorphicWith( m.getBaseModel() ) ); + assertTrue( mIn1.isIsomorphicWith( m.getBaseModel() ), "InputStream write/read cycle failed (1)" ); + assertTrue( mIn2.isIsomorphicWith( m.getBaseModel() ), "InputStream write/read cycle failed (2)" ); } + @Test public void testGetBaseModelPrefixes() { OntModel om = ModelFactory.createOntologyModel(); om.setNsPrefix( "bill", "http://bill.and.ben/flowerpot#" ); @@ -175,6 +174,7 @@ public void testGetBaseModelPrefixes() { * The default namespace pefix of a non-base-model should not manifest as * the default namespace prefix of the base model or the Ont model. */ + @Test public void testPolyadicPrefixMapping() { final String IMPORTED_NAMESPACE = "http://imported#"; final String LOCAL_NAMESPACE = "http://local#"; @@ -186,6 +186,7 @@ public void testPolyadicPrefixMapping() { assertNull( ontModel.getNsURIPrefix( IMPORTED_NAMESPACE ) ); } + @Test public void testWritesPrefixes() { OntModel om = ModelFactory.createOntologyModel(); om.setNsPrefix( "spoo", "http://spoo.spoo.com/spoo#" ); @@ -199,6 +200,7 @@ public void testWritesPrefixes() { } /** Test writing the base model to an output stream */ + @Test public void testWriteWriter() { OntModel m = ModelFactory.createOntologyModel(); @@ -232,32 +234,34 @@ public void testWriteWriter() { mIn2.read( new StringReader( DOC ), BASE ); // should be the same - assertTrue( "Writer write/read cycle failed (1)", mIn1.isIsomorphicWith( m.getBaseModel() ) ); - assertTrue( "Writer write/read cycle failed (2)", mIn2.isIsomorphicWith( m.getBaseModel() ) ); + assertTrue( mIn1.isIsomorphicWith( m.getBaseModel() ), "Writer write/read cycle failed (1)" ); + assertTrue( mIn2.isIsomorphicWith( m.getBaseModel() ), "Writer write/read cycle failed (2)" ); } + @Test public void testGetOntology() { OntModel m = ModelFactory.createOntologyModel(); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createOntology( NS + "s" ); - assertEquals( "Result of get s", s, m.getOntology( NS + "s" ) ); - assertNull( "result of get q", m.getOntology( NS+"q") ); - assertNull( "result of get r", m.getOntology( NS+"r")); + assertEquals( s, m.getOntology( NS + "s" ), "Result of get s" ); + assertNull( m.getOntology( NS+"q"), "result of get q" ); + assertNull( m.getOntology( NS+"r"), "result of get r"); } - + @Test public void testGetIndividual() { OntModel m = ModelFactory.createOntologyModel(); OntClass c = m.createClass( NS +"c" ); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createIndividual( NS + "s", c ); - assertEquals( "Result of get s", s, m.getIndividual( NS + "s" ) ); - assertNull( "result of get q", m.getIndividual( NS+"q") ); + assertEquals( s, m.getIndividual( NS + "s" ), "Result of get s" ); + assertNull( m.getIndividual( NS+"q"), "result of get q" ); } /** User requested: allow null arguments when creating individuals */ + @Test public void testCreateIndividual() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); Resource i0 = m.createIndividual( OWL.Thing ); @@ -275,82 +279,84 @@ public void testCreateIndividual() { assertNotNull( i5 ); } + @Test public void testGetOntProperty() { OntModel m = ModelFactory.createOntologyModel(); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createOntProperty( NS + "s" ); - assertEquals( "Result of get s", s, m.getOntProperty( NS + "s" ) ); - assertNull( "result of get q", m.getOntProperty( NS+"q") ); - assertNull( "result of get r", m.getOntProperty( NS+"r")); + assertEquals( s, m.getOntProperty( NS + "s" ), "Result of get s" ); + assertNull( m.getOntProperty( NS+"q"), "result of get q" ); + assertNull( m.getOntProperty( NS+"r"), "result of get r"); } - + @Test public void testGetObjectProperty() { OntModel m = ModelFactory.createOntologyModel(); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createObjectProperty( NS + "s" ); - assertEquals( "Result of get s", s, m.getObjectProperty( NS + "s" ) ); - assertNull( "result of get q", m.getObjectProperty( NS+"q") ); - assertNull( "result of get r", m.getObjectProperty( NS+"r")); + assertEquals( s, m.getObjectProperty( NS + "s" ), "Result of get s" ); + assertNull( m.getObjectProperty( NS+"q"), "result of get q" ); + assertNull( m.getObjectProperty( NS+"r"), "result of get r"); } - + @Test public void testGetTransitiveProperty() { OntModel m = ModelFactory.createOntologyModel(); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createTransitiveProperty( NS + "s" ); - assertEquals( "Result of get s", s, m.getTransitiveProperty( NS + "s" ) ); - assertNull( "result of get q", m.getTransitiveProperty( NS+"q") ); - assertNull( "result of get r", m.getTransitiveProperty( NS+"r")); + assertEquals( s, m.getTransitiveProperty( NS + "s" ), "Result of get s" ); + assertNull( m.getTransitiveProperty( NS+"q"), "result of get q" ); + assertNull( m.getTransitiveProperty( NS+"r"), "result of get r"); } - + @Test public void testGetSymmetricProperty() { OntModel m = ModelFactory.createOntologyModel(); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createSymmetricProperty( NS + "s" ); - assertEquals( "Result of get s", s, m.getSymmetricProperty( NS + "s" ) ); - assertNull( "result of get q", m.getSymmetricProperty( NS+"q") ); - assertNull( "result of get r", m.getSymmetricProperty( NS+"r")); + assertEquals( s, m.getSymmetricProperty( NS + "s" ), "Result of get s" ); + assertNull( m.getSymmetricProperty( NS+"q"), "result of get q" ); + assertNull( m.getSymmetricProperty( NS+"r"), "result of get r"); } - + @Test public void testGetInverseFunctionalProperty() { OntModel m = ModelFactory.createOntologyModel(); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createInverseFunctionalProperty( NS + "s" ); - assertEquals( "Result of get s", s, m.getInverseFunctionalProperty( NS + "s" ) ); - assertNull( "result of get q", m.getInverseFunctionalProperty( NS+"q") ); - assertNull( "result of get r", m.getInverseFunctionalProperty( NS+"r")); + assertEquals( s, m.getInverseFunctionalProperty( NS + "s" ), "Result of get s" ); + assertNull( m.getInverseFunctionalProperty( NS+"q"), "result of get q" ); + assertNull( m.getInverseFunctionalProperty( NS+"r"), "result of get r"); } - + @Test public void testGetDatatypeProperty() { OntModel m = ModelFactory.createOntologyModel(); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createDatatypeProperty( NS + "s" ); - assertEquals( "Result of get s", s, m.getDatatypeProperty( NS + "s" ) ); - assertNull( "result of get q", m.getDatatypeProperty( NS+"q") ); - assertNull( "result of get r", m.getDatatypeProperty( NS+"r")); + assertEquals( s, m.getDatatypeProperty( NS + "s" ), "Result of get s" ); + assertNull( m.getDatatypeProperty( NS+"q"), "result of get q" ); + assertNull( m.getDatatypeProperty( NS+"r"), "result of get r"); } - + @Test public void testGetAnnotationProperty() { OntModel m = ModelFactory.createOntologyModel(); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createAnnotationProperty( NS + "s" ); - assertEquals( "Result of get s", s, m.getAnnotationProperty( NS + "s" ) ); - assertNull( "result of get q", m.getAnnotationProperty( NS+"q") ); - assertNull( "result of get r", m.getAnnotationProperty( NS+"r")); + assertEquals( s, m.getAnnotationProperty( NS + "s" ), "Result of get s" ); + assertNull( m.getAnnotationProperty( NS+"q"), "result of get q" ); + assertNull( m.getAnnotationProperty( NS+"r"), "result of get r"); } + @Test public void testGetOntResource() { OntModel m = ModelFactory.createOntologyModel(); OntResource r0 = m.getOntResource( NS + "a" ); @@ -367,78 +373,79 @@ public void testGetOntResource() { JenaTestLib.assertInstanceOf( OntResource.class, r3 ); } + @Test public void testGetOntClass() { OntModel m = ModelFactory.createOntologyModel(); Resource r = m.getResource( NS + "r" ); Resource r0 = m.getResource( NS + "r0" ); m.add( r, RDF.type, r0 ); Resource s = m.createClass( NS + "s" ); - assertEquals( "Result of get s", s, m.getOntClass( NS + "s" ) ); - assertNull( "result of get q", m.getOntClass( NS+"q") ); - assertNull( "result of get r", m.getOntClass( NS+"r")); + assertEquals( s, m.getOntClass( NS + "s" ), "Result of get s" ); + assertNull( m.getOntClass( NS+"q"), "result of get q" ); + assertNull( m.getOntClass( NS+"r"), "result of get r"); } - + @Test public void testGetComplementClass() { OntModel m = ModelFactory.createOntologyModel(); OntClass c = m.createClass( NS +"c" ); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createComplementClass( NS + "s", c ); - assertEquals( "Result of get s", s, m.getComplementClass( NS + "s" ) ); - assertNull( "result of get q", m.getComplementClass( NS+"q") ); - assertNull( "result of get r", m.getComplementClass( NS+"r")); + assertEquals( s, m.getComplementClass( NS + "s" ), "Result of get s" ); + assertNull( m.getComplementClass( NS+"q"), "result of get q" ); + assertNull( m.getComplementClass( NS+"r"), "result of get r"); } - + @Test public void testGetEnumeratedClass() { OntModel m = ModelFactory.createOntologyModel(); RDFList l = m.createList(); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createEnumeratedClass( NS + "s", l ); - assertEquals( "Result of get s", s, m.getEnumeratedClass( NS + "s" ) ); - assertNull( "result of get q", m.getEnumeratedClass( NS+"q") ); - assertNull( "result of get r", m.getEnumeratedClass( NS+"r")); + assertEquals( s, m.getEnumeratedClass( NS + "s" ), "Result of get s" ); + assertNull( m.getEnumeratedClass( NS+"q"), "result of get q" ); + assertNull( m.getEnumeratedClass( NS+"r"), "result of get r"); } - + @Test public void testGetUnionClass() { OntModel m = ModelFactory.createOntologyModel(); RDFList l = m.createList(); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createUnionClass( NS + "s", l ); - assertEquals( "Result of get s", s, m.getUnionClass( NS + "s" ) ); - assertNull( "result of get q", m.getUnionClass( NS+"q") ); - assertNull( "result of get r", m.getUnionClass( NS+"r")); + assertEquals( s, m.getUnionClass( NS + "s" ), "Result of get s" ); + assertNull( m.getUnionClass( NS+"q"), "result of get q" ); + assertNull( m.getUnionClass( NS+"r"), "result of get r"); } - + @Test public void testGetIntersectionClass() { OntModel m = ModelFactory.createOntologyModel(); RDFList l = m.createList(); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createIntersectionClass( NS + "s", l ); - assertEquals( "Result of get s", s, m.getIntersectionClass( NS + "s" ) ); - assertNull( "result of get q", m.getIntersectionClass( NS+"q") ); - assertNull( "result of get r", m.getIntersectionClass( NS+"r")); + assertEquals( s, m.getIntersectionClass( NS + "s" ), "Result of get s" ); + assertNull( m.getIntersectionClass( NS+"q"), "result of get q" ); + assertNull( m.getIntersectionClass( NS+"r"), "result of get r"); } - + @Test public void testGetRestriction() { OntModel m = ModelFactory.createOntologyModel(); Property p = m.createProperty( NS + "p" ); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createRestriction( NS + "s", p ); - assertEquals( "Result of get s", s, m.getRestriction( NS + "s" ) ); - assertNull( "result of get q", m.getRestriction( NS+"q") ); - assertNull( "result of get r", m.getRestriction( NS+"r")); + assertEquals( s, m.getRestriction( NS + "s" ), "Result of get s" ); + assertNull( m.getRestriction( NS+"q"), "result of get q" ); + assertNull( m.getRestriction( NS+"r"), "result of get r"); } - + @Test public void testGetHasValueRestriction() { OntModel m = ModelFactory.createOntologyModel(); Property p = m.createProperty( NS + "p" ); @@ -446,12 +453,12 @@ public void testGetHasValueRestriction() { Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createHasValueRestriction( NS + "s", p, c ); - assertEquals( "Result of get s", s, m.getHasValueRestriction( NS + "s" ) ); - assertNull( "result of get q", m.getHasValueRestriction( NS+"q") ); - assertNull( "result of get r", m.getHasValueRestriction( NS+"r")); + assertEquals( s, m.getHasValueRestriction( NS + "s" ), "Result of get s" ); + assertNull( m.getHasValueRestriction( NS+"q"), "result of get q" ); + assertNull( m.getHasValueRestriction( NS+"r"), "result of get r"); } - + @Test public void testGetSomeValuesFromRestriction() { OntModel m = ModelFactory.createOntologyModel(); Property p = m.createProperty( NS + "p" ); @@ -459,12 +466,12 @@ public void testGetSomeValuesFromRestriction() { Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createSomeValuesFromRestriction( NS + "s", p, c ); - assertEquals( "Result of get s", s, m.getSomeValuesFromRestriction( NS + "s" ) ); - assertNull( "result of get q", m.getSomeValuesFromRestriction( NS+"q") ); - assertNull( "result of get r", m.getSomeValuesFromRestriction( NS+"r")); + assertEquals( s, m.getSomeValuesFromRestriction( NS + "s" ), "Result of get s" ); + assertNull( m.getSomeValuesFromRestriction( NS+"q"), "result of get q" ); + assertNull( m.getSomeValuesFromRestriction( NS+"r"), "result of get r"); } - + @Test public void testGetAllValuesFromRestriction() { OntModel m = ModelFactory.createOntologyModel(); Property p = m.createProperty( NS + "p" ); @@ -472,55 +479,56 @@ public void testGetAllValuesFromRestriction() { Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createAllValuesFromRestriction( NS + "s", p, c ); - assertEquals( "Result of get s", s, m.getAllValuesFromRestriction( NS + "s" ) ); - assertNull( "result of get q", m.getAllValuesFromRestriction( NS+"q") ); - assertNull( "result of get r", m.getAllValuesFromRestriction( NS+"r")); + assertEquals( s, m.getAllValuesFromRestriction( NS + "s" ), "Result of get s" ); + assertNull( m.getAllValuesFromRestriction( NS+"q"), "result of get q" ); + assertNull( m.getAllValuesFromRestriction( NS+"r"), "result of get r"); } - + @Test public void testGetCardinalityRestriction() { OntModel m = ModelFactory.createOntologyModel(); Property p = m.createProperty( NS + "p" ); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createCardinalityRestriction( NS + "s", p, 1 ); - assertEquals( "Result of get s", s, m.getCardinalityRestriction( NS + "s" ) ); - assertNull( "result of get q", m.getCardinalityRestriction( NS+"q") ); - assertNull( "result of get r", m.getCardinalityRestriction( NS+"r")); + assertEquals( s, m.getCardinalityRestriction( NS + "s" ), "Result of get s" ); + assertNull( m.getCardinalityRestriction( NS+"q"), "result of get q" ); + assertNull( m.getCardinalityRestriction( NS+"r"), "result of get r"); } - + @Test public void testGetMinCardinalityRestriction() { OntModel m = ModelFactory.createOntologyModel(); Property p = m.createProperty( NS + "p" ); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createMinCardinalityRestriction( NS + "s", p, 1 ); - assertEquals( "Result of get s", s, m.getMinCardinalityRestriction( NS + "s" ) ); - assertNull( "result of get q", m.getMinCardinalityRestriction( NS+"q") ); - assertNull( "result of get r", m.getMinCardinalityRestriction( NS+"r")); + assertEquals( s, m.getMinCardinalityRestriction( NS + "s" ), "Result of get s" ); + assertNull( m.getMinCardinalityRestriction( NS+"q"), "result of get q" ); + assertNull( m.getMinCardinalityRestriction( NS+"r"), "result of get r"); } - + @Test public void testGetMaxCardinalityRestriction() { OntModel m = ModelFactory.createOntologyModel(); Property p = m.createProperty( NS + "p" ); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createMaxCardinalityRestriction( NS + "s", p, 1 ); - assertEquals( "Result of get s", s, m.getMaxCardinalityRestriction( NS + "s" ) ); - assertNull( "result of get q", m.getMaxCardinalityRestriction( NS+"q") ); - assertNull( "result of get r", m.getMaxCardinalityRestriction( NS+"r")); + assertEquals( s, m.getMaxCardinalityRestriction( NS + "s" ), "Result of get s" ); + assertNull( m.getMaxCardinalityRestriction( NS+"q"), "result of get q" ); + assertNull( m.getMaxCardinalityRestriction( NS+"r"), "result of get r"); } + @Test public void testGetSubgraphs() { OntModel m = ModelFactory.createOntologyModel(); m.read( "file:testing/ontology/testImport6/a.owl" ); - assertEquals( "Marker count not correct", 4, TestOntDocumentManager.countMarkers( m ) ); + assertEquals( 4, TestOntDocumentManager.countMarkers( m ), "Marker count not correct" ); List subs = m.getSubGraphs(); - assertEquals( "n subgraphs should be ", 3, subs.size() ); + assertEquals( 3, subs.size(), "n subgraphs should be " ); } private static boolean hasImport(Collection c, String x) { @@ -528,27 +536,28 @@ private static boolean hasImport(Collection c, String x) { return c.stream().anyMatch(elt->elt.endsWith(x2)); } - + @Test public void testListImportURIs() { OntModel m = ModelFactory.createOntologyModel(); m.read( "file:testing/ontology/testImport6/a.owl" ); Collection c = m.listImportedOntologyURIs(); - assertEquals( "Should be two non-closed import URI's", 2, c.size() ); - assertTrue( "b should be imported ", hasImport(c, "file:testing/ontology/testImport6/b.owl")); - assertFalse( "c should not be imported ", hasImport(c, "file:testing/ontology/testImport6/c.owl")); - assertTrue( "d should be imported ", hasImport(c, "file:testing/ontology/testImport6/d.owl")); + assertEquals( 2, c.size(), "Should be two non-closed import URI's" ); + assertTrue( hasImport(c, "file:testing/ontology/testImport6/b.owl"), "b should be imported "); + assertFalse( hasImport(c, "file:testing/ontology/testImport6/c.owl"), "c should not be imported "); + assertTrue( hasImport(c, "file:testing/ontology/testImport6/d.owl"), "d should be imported "); c = m.listImportedOntologyURIs( true ); - assertEquals( "Should be two non-closed import URI's", 3, c.size() ); - assertTrue( "b should be imported ", hasImport(c, "file:testing/ontology/testImport6/b.owl" )); - assertTrue( "c should be imported ", hasImport(c, "file:testing/ontology/testImport6/c.owl" )); - assertTrue( "d should be imported ", hasImport(c, "file:testing/ontology/testImport6/d.owl" )); + assertEquals( 3, c.size(), "Should be two non-closed import URI's" ); + assertTrue( hasImport(c, "file:testing/ontology/testImport6/b.owl" ), "b should be imported "); + assertTrue( hasImport(c, "file:testing/ontology/testImport6/c.owl" ), "c should be imported "); + assertTrue( hasImport(c, "file:testing/ontology/testImport6/d.owl" ), "d should be imported "); } /** Some tests for listing properties. See also {@link TestListSyntaxCategories} */ + @Test public void testListOntProperties0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); ObjectProperty op = m.createObjectProperty( NS + "op" ); @@ -567,6 +576,7 @@ public void testListOntProperties0() { assertTrue( iteratorContains( m.listOntProperties(), rdfp ) ); } + @Test public void testListOntProperties1() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF); ObjectProperty op = m.createObjectProperty( NS + "op" ); @@ -585,6 +595,7 @@ public void testListOntProperties1() { assertTrue( iteratorContains( m.listOntProperties(), rdfp ) ); } + @Test public void testListOntProperties2() { OntModelSpec owlDLReasoner = new OntModelSpec( OntModelSpec.OWL_DL_MEM ); owlDLReasoner.setReasoner( OntModelSpec.OWL_MEM_MICRO_RULE_INF.getReasoner() ); @@ -605,7 +616,7 @@ public void testListOntProperties2() { assertTrue( iteratorContains( m.listOntProperties(), rdfp ) ); } - + @Test public void testListAllOntProperties0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); ObjectProperty op = m.createObjectProperty( NS + "op" ); @@ -624,6 +635,7 @@ public void testListAllOntProperties0() { assertTrue( iteratorContains( m.listAllOntProperties(), rdfp ) ); } + @Test public void testListObjectProperties0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); ObjectProperty op = m.createObjectProperty( NS + "op" ); @@ -642,6 +654,7 @@ public void testListObjectProperties0() { assertFalse( iteratorContains( m.listObjectProperties(), rdfp ) ); } + @Test public void testListDatatypeProperties0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); ObjectProperty op = m.createObjectProperty( NS + "op" ); @@ -660,6 +673,7 @@ public void testListDatatypeProperties0() { assertFalse( iteratorContains( m.listDatatypeProperties(), rdfp ) ); } + @Test public void testListAnnotationProperties0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); ObjectProperty op = m.createObjectProperty( NS + "op" ); @@ -678,17 +692,18 @@ public void testListAnnotationProperties0() { assertFalse( iteratorContains( m.listAnnotationProperties(), rdfp ) ); } + @Test public void testListSubModels0() { OntModel m = ModelFactory.createOntologyModel(); m.read( "file:testing/ontology/testImport6/a.owl" ); - assertEquals( "Marker count not correct", 4, TestOntDocumentManager.countMarkers( m ) ); + assertEquals( 4, TestOntDocumentManager.countMarkers( m ), "Marker count not correct" ); List importModels = new ArrayList<>(); for (Iterator j = m.listSubModels(); j.hasNext(); ) { importModels.add( j.next() ); } - assertEquals( "n import models should be ", 3, importModels.size() ); + assertEquals( 3, importModels.size(), "n import models should be " ); int nImports = 0; @@ -698,20 +713,21 @@ public void testListSubModels0() { nImports += x.countSubModels(); } // listSubModels' default behaviour is *not* to include imports of sub-models - assertEquals( "Wrong number of sub-model imports", 0, nImports ); + assertEquals( 0, nImports, "Wrong number of sub-model imports" ); } + @Test public void testListSubModels1() { OntModel m = ModelFactory.createOntologyModel(); m.read( "file:testing/ontology/testImport6/a.owl" ); - assertEquals( "Marker count not correct", 4, TestOntDocumentManager.countMarkers( m ) ); + assertEquals( 4, TestOntDocumentManager.countMarkers( m ), "Marker count not correct" ); List importModels = new ArrayList<>(); for (Iterator j = m.listSubModels( true ); j.hasNext(); ) { importModels.add( j.next() ); } - assertEquals( "n import models should be ", 3, importModels.size() ); + assertEquals( 3, importModels.size(), "n import models should be " ); int nImports = 0; @@ -720,9 +736,10 @@ public void testListSubModels1() { // count the number of imports of each sub-model nImports += x.countSubModels(); } - assertEquals( "Wrong number of sub-model imports", 2, nImports ); + assertEquals( 2, nImports, "Wrong number of sub-model imports" ); } + @Test public void testGetImportedModel() { OntModel m = ModelFactory.createOntologyModel(); m.read( "file:testing/ontology/testImport6/a.owl" ); @@ -734,17 +751,18 @@ public void testGetImportedModel() { .getImportedModel( "file:testing/ontology/testImport6/c.owl" ); OntModel m4 = m.getImportedModel( "file:testing/ontology/testImport6/a.owl" ); - assertNotNull( "Import model b should not be null", m0 ); - assertNotNull( "Import model c should not be null", m1 ); - assertNotNull( "Import model d should not be null", m2 ); - assertNotNull( "Import model b-c should not be null", m3 ); - assertNull( "Import model a should be null", m4 ); + assertNotNull( m0, "Import model b should not be null" ); + assertNotNull( m1, "Import model c should not be null" ); + assertNotNull( m2, "Import model d should not be null" ); + assertNotNull( m3, "Import model b-c should not be null" ); + assertNull( m4, "Import model a should be null" ); } /** * Test that the supports checks that are defined in the OWL full profile are not * missing in the DL and Lite profiles, unless by design. * Not strictly a model test, but it has to go somewhere */ + @Test public void testProfiles() { List> notInDL = Arrays.asList( new Class[] {} ); List> notInLite = Arrays.asList( new Class[] {DataRange.class, HasValueRestriction.class} ); @@ -756,14 +774,11 @@ public void testProfiles() { for ( Map.Entry, SupportsCheck> entry : fullProfileMap.entrySet() ) { Class c = entry.getKey(); - assertTrue( "Key in OWL DL profile: " + c.getName(), - dlProfileMap.containsKey( c ) || notInDL.contains( c ) ); - assertTrue( "Key in OWL lite profile: " + c.getName(), - liteProfileMap.containsKey( c ) || notInLite.contains( c ) ); + assertTrue( dlProfileMap.containsKey( c ) || notInDL.contains( c ), "Key in OWL DL profile: " + c.getName() ); + assertTrue( liteProfileMap.containsKey( c ) || notInLite.contains( c ), "Key in OWL lite profile: " + c.getName() ); } } - /** Added by kers to ensure that bulk update works; should really be a test of the ontology Graph using AbstractTestGraph, but that fails because there @@ -771,6 +786,7 @@ public void testProfiles() {

Yet. */ + @Test public void testBulkAddWorks() { OntModel om1= ModelFactory.createOntologyModel(); @@ -778,6 +794,7 @@ public void testBulkAddWorks() om1.add( om2 ); } + @Test public void testRead() { String base0 = "http://example.com/test0"; String ns0 = base0 + "#"; @@ -788,17 +805,18 @@ public void testRead() { m.getDocumentManager().reset(); m.getDocumentManager().addAltEntry( base0, "file:testing/ontology/relativenames.rdf" ); m.read( base0, "RDF/XML" ); - assertNotNull( "Should be a class ns0:A", m.getOntClass( ns0 + "A" ) ); - assertNull( "Should not be a class ns1:A", m.getOntClass( ns1 + "A" ) ); + assertNotNull( m.getOntClass( ns0 + "A" ), "Should be a class ns0:A" ); + assertNull( m.getOntClass( ns1 + "A" ), "Should not be a class ns1:A" ); m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); m.getDocumentManager().reset(); m.getDocumentManager().addAltEntry( base0, "file:testing/ontology/relativenames.rdf" ); m.read( base0, base1, "RDF/XML" ); - assertNull( "Should not be a class ns0:A", m.getOntClass( ns0 + "A" ) ); - assertNotNull( "Should be a class ns1:A", m.getOntClass( ns1 + "A" ) ); + assertNull( m.getOntClass( ns0 + "A" ), "Should not be a class ns0:A" ); + assertNotNull( m.getOntClass( ns1 + "A" ), "Should be a class ns1:A" ); } + @Test public void testListDataRange() { String base = "http://jena.hpl.hp.com/test#"; String doc = @@ -828,14 +846,13 @@ public void testListDataRange() { m.read(new StringReader(doc), base); Iterator i = m.listDataRanges(); - assertTrue( "Should be at least one DataRange", i.hasNext() ); + assertTrue( i.hasNext(), "Should be at least one DataRange" ); Object dr = i.next(); JenaTestLib.assertInstanceOf( DataRange.class, dr ); - assertFalse( "Should no more DataRange", i.hasNext() ); + assertFalse( i.hasNext(), "Should no more DataRange" ); } - - + @Test public void testListHierarchyRoots0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); assertFalse( m.listHierarchyRootClasses().hasNext() ); @@ -843,6 +860,7 @@ public void testListHierarchyRoots0() { assertFalse( m.listHierarchyRootClasses().hasNext() ); } + @Test public void testListHierarchyRoots1() { String doc = "@prefix rdf: . " @@ -857,11 +875,11 @@ public void testListHierarchyRoots1() { m.read( new StringReader(doc), NS, "N3" ); OntClass a = m.getOntClass(NS+"A"); - TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), + OntTestUtil.assertIteratorValues(m.listHierarchyRootClasses(), new Object[] {a} ); } - + @Test public void testListHierarchyRoots2() { String doc = "@prefix rdf: . " @@ -876,11 +894,11 @@ public void testListHierarchyRoots2() { m.read( new StringReader(doc), NS, "N3" ); OntClass a = m.getOntClass(NS+"A"); - TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), + OntTestUtil.assertIteratorValues(m.listHierarchyRootClasses(), new Object[] {a} ); } - + @Test public void testListHierarchyRoots3() { String doc = "@prefix rdf: . " @@ -896,10 +914,11 @@ public void testListHierarchyRoots3() { m.read( new StringReader(doc), NS, "N3" ); OntClass a = m.getOntClass(NS+"A"); - TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), + OntTestUtil.assertIteratorValues(m.listHierarchyRootClasses(), new Object[] {a} ); } + @Test public void testListHierarchyRoots4() { String doc = "@prefix rdf: . " @@ -917,11 +936,12 @@ public void testListHierarchyRoots4() { OntClass a = m.getOntClass(NS+"A"); OntClass c = m.getOntClass(NS+"C"); - TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), + OntTestUtil.assertIteratorValues(m.listHierarchyRootClasses(), new Object[] {a,c} ); } /* Auto-loading of imports is off by default */ + @Test public void testLoadImports0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); Resource a = m.getResource( "file:testing/ontology/testImport3/a.owl" ); @@ -929,21 +949,21 @@ public void testLoadImports0() { m.add( a, m.getProfile().IMPORTS(), b ); // not dymamically imported by default - assertEquals( "Marker count not correct", 0, TestOntDocumentManager.countMarkers( m ) ); + assertEquals( 0, TestOntDocumentManager.countMarkers( m ), "Marker count not correct" ); - assertFalse( "c should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); - assertFalse( "b should not be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) ); + assertFalse( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should not be imported" ); + assertFalse( m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ), "b should not be imported" ); m.loadImports(); - assertEquals( "Marker count not correct", 2, TestOntDocumentManager.countMarkers( m ) ); + assertEquals( 2, TestOntDocumentManager.countMarkers( m ), "Marker count not correct" ); - assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); - assertTrue( "b should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should be imported" ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ), "b should be imported" ); } - /* Auto-loading of imports = on */ + @Test public void testLoadImports1() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); Resource a = m.getResource( "file:testing/ontology/testImport3/a.owl" ); @@ -952,21 +972,22 @@ public void testLoadImports1() { m.setDynamicImports( true ); m.add( a, m.getProfile().IMPORTS(), b ); - assertEquals( "Marker count not correct", 2, TestOntDocumentManager.countMarkers( m ) ); + assertEquals( 2, TestOntDocumentManager.countMarkers( m ), "Marker count not correct" ); - assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); - assertTrue( "b should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should be imported" ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ), "b should be imported" ); // this should have no effect m.loadImports(); - assertEquals( "Marker count not correct", 2, TestOntDocumentManager.countMarkers( m ) ); + assertEquals( 2, TestOntDocumentManager.countMarkers( m ), "Marker count not correct" ); - assertTrue( "c should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ) ); - assertTrue( "b should be imported", m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ) ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/c.owl" ), "c should be imported" ); + assertTrue( m.hasLoadedImport( "file:testing/ontology/testImport3/b.owl" ), "b should be imported" ); } /** Test that resources are attached to the right sub-models when importing */ + @Test public void testLoadImports2() { OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null); ontModel.read("file:testing/ontology/testImport8/a.owl"); @@ -986,6 +1007,7 @@ public void testLoadImports2() { } /** Test getting conclusions after loading imports */ + @Test public void testAddImports0() { OntModel base = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); @@ -1008,6 +1030,7 @@ public void testAddImports0() { assertTrue( a.hasSubClass( b ) ); } + @Test public void testAddImports1() { String ns = "http://jena.hpl.hp.com/2003/03/testont"; OntModel base = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); @@ -1015,7 +1038,6 @@ public void testAddImports1() { OntDocumentManager odm = OntDocumentManager.getInstance(); odm.addAltEntry( ns + "#a", "file:testing/ontology/testImport7/a.owl" ); - OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF, base ); Ontology oo = base.createOntology( ns ); @@ -1034,6 +1056,7 @@ public void testAddImports1() { /** * AddSubModel variant 2: base = no inf, import = no inf */ + @Test public void testaddSubModel0() { OntModel m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); OntModel m1 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); @@ -1052,6 +1075,7 @@ public void testaddSubModel0() { /** * AddSubModel variant 2: base = inf, import = no inf */ + @Test public void testaddSubModel1() { OntDocumentManager.getInstance().setProcessImports( false ); OntDocumentManager.getInstance().addAltEntry( "http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine", @@ -1074,6 +1098,7 @@ public void testaddSubModel1() { /** * Variant 3: base = no inf, import = inf */ + @Test public void testaddSubModel3() { OntModel m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); OntModel m1 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RDFS_INF ); @@ -1092,6 +1117,7 @@ public void testaddSubModel3() { /** * Variant 4: base = inf, import = inf */ + @Test public void testaddSubModel4() { OntModel m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RDFS_INF ); OntModel m1 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RDFS_INF ); @@ -1108,6 +1134,7 @@ public void testaddSubModel4() { } /** Remove a sub model (imported model) */ + @Test public void testremoveSubModel0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null ); m.read( "file:testing/ontology/testImport3/a.owl" ); @@ -1121,7 +1148,6 @@ public void testremoveSubModel0() { assertEquals( 0, m.getSubGraphs().size() ); } - /** Getting the deductions model of an OntModel * see also {@link TestRuleSystemBugs#testOntModelGetDeductions()} *

ijd: Feb 6th, 2008 - this test has been disabled for @@ -1156,6 +1182,7 @@ public void xxtestGetDeductionsModel0() { /** * Test that using closed models in imports does not raise an exception */ + @Test public void testImportClosedModel() { String SOURCEA= " i, Object x ) { return found; } - //============================================================================== // Inner class definitions //============================================================================== diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntModelSpec.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntModelSpec.java index b34507411b5..a5f7a9df47c 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntModelSpec.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntModelSpec.java @@ -21,15 +21,19 @@ package org.apache.jena.ontology.impl; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.ontology.OntModelSpec; -import org.apache.jena.test.JenaTestBase; +import org.apache.jena.test.JenaTestLib; @SuppressWarnings("removal") -public class TestOntModelSpec extends JenaTestBase +public class TestOntModelSpec { - public TestOntModelSpec( String name ) - { super( name ); } + static { JenaTestLib.setup(); } + @Test public void testEqualityAndDifference() { testEqualityAndDifference( OntModelSpec.OWL_MEM ); @@ -56,11 +60,13 @@ private void testEqualityAndDifference( OntModelSpec os ) assertEquals( os, new OntModelSpec( os ) ); } + @Test public void testAssembleRoot() { // TODO OntModelSpec.assemble( Resource root ) } + @Test public void testAssembleModel() { // TODO OntModelSpec.assemble( Model model ) diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntReasoning.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntReasoning.java index 4a5fbeac004..10d55fb33a5 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntReasoning.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntReasoning.java @@ -23,7 +23,6 @@ /////////////// package org.apache.jena.ontology.impl; - // Imports /////////////// import java.io.ByteArrayInputStream; @@ -34,11 +33,15 @@ import org.apache.jena.rdf.model.*; import org.apache.jena.reasoner.Reasoner; import org.apache.jena.reasoner.ReasonerRegistry; -import org.apache.jena.reasoner.test.TestUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.apache.jena.test.JenaTestLib; /** *

@@ -47,8 +50,10 @@ */ @SuppressWarnings("removal") public class TestOntReasoning - extends TestCase { + + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// public static final String BASE = "http://jena.hpl.hp.com/testing/ontology"; @@ -63,20 +68,16 @@ public class TestOntReasoning // Constructors ////////////////////////////////// - public TestOntReasoning( String name ) { - super( name ); - } - // External signature methods ////////////////////////////////// - @Override + @BeforeEach public void setUp() { // ensure the ont doc manager is in a consistent state OntDocumentManager.getInstance().reset( true ); } - + @Test public void testSubClassDirectTransInf1a() { OntModel m = ModelFactory.createOntologyModel( ProfileRegistry.OWL_LITE_LANG ); @@ -93,6 +94,7 @@ public void testSubClassDirectTransInf1a() { iteratorTest( A.listSubClasses( true ), new Object[] {B, C} ); } + @Test public void testSubClassDirectTransInf1b() { OntModel m = ModelFactory.createOntologyModel( ProfileRegistry.OWL_LITE_LANG ); @@ -110,6 +112,7 @@ public void testSubClassDirectTransInf1b() { iteratorTest( A.listSubClasses( true ), new Object[] {B, C} ); } + @Test public void testSubClassDirectTransInf2a() { // test the code path for generating direct sc with no reasoner OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_LITE_MEM ); @@ -129,6 +132,7 @@ public void testSubClassDirectTransInf2a() { iteratorTest( A.listSubClasses( true ), new Object[] {B, C} ); } + @Test public void testSubClassDirectTransInf2b() { // test the code path for generating direct sc with no reasoner OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_LITE_MEM ); @@ -149,6 +153,7 @@ public void testSubClassDirectTransInf2b() { iteratorTest( A.listSubClasses( true ), new Object[] {B, C} ); } + @Test public void testListSuperClassesDirect() { String ns = "http://example.org/test#"; OntModel m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); @@ -162,10 +167,10 @@ public void testListSuperClassesDirect() { c2.addEquivalentClass( c3 ); // now c1 is the direct super-class of c2, even allowing for the equiv with c3 - assertFalse( "pass 1: c0 should not be a direct super of c2", c2.hasSuperClass( c0, true ) ); - assertFalse( "pass 1: c3 should not be a direct super of c2", c2.hasSuperClass( c3, true ) ); - assertFalse( "pass 1: c2 should not be a direct super of c2", c2.hasSuperClass( c2, true ) ); - assertTrue( "pass 1: c1 should be a direct super of c2", c2.hasSuperClass( c1, true ) ); + assertFalse( c2.hasSuperClass( c0, true ), "pass 1: c0 should not be a direct super of c2" ); + assertFalse( c2.hasSuperClass( c3, true ), "pass 1: c3 should not be a direct super of c2" ); + assertFalse( c2.hasSuperClass( c2, true ), "pass 1: c2 should not be a direct super of c2" ); + assertTrue( c2.hasSuperClass( c1, true ), "pass 1: c1 should be a direct super of c2" ); // second pass - with inference m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RULE_INF ); @@ -179,12 +184,13 @@ public void testListSuperClassesDirect() { c2.addEquivalentClass( c3 ); // now c1 is the direct super-class of c2, even allowing for the equiv with c3 - assertFalse( "pass 2: c0 should not be a direct super of c2", c2.hasSuperClass( c0, true ) ); - assertFalse( "pass 2: c3 should not be a direct super of c2", c2.hasSuperClass( c3, true ) ); - assertFalse( "pass 2: c2 should not be a direct super of c2", c2.hasSuperClass( c2, true ) ); - assertTrue( "pass 2: c1 should be a direct super of c2", c2.hasSuperClass( c1, true ) ); + assertFalse( c2.hasSuperClass( c0, true ), "pass 2: c0 should not be a direct super of c2" ); + assertFalse( c2.hasSuperClass( c3, true ), "pass 2: c3 should not be a direct super of c2" ); + assertFalse( c2.hasSuperClass( c2, true ), "pass 2: c2 should not be a direct super of c2" ); + assertTrue( c2.hasSuperClass( c1, true ), "pass 2: c1 should be a direct super of c2" ); } + @Test public void testSubPropertyDirectTransInf1a() { OntModel m = ModelFactory.createOntologyModel( ProfileRegistry.OWL_LITE_LANG ); @@ -201,6 +207,7 @@ public void testSubPropertyDirectTransInf1a() { iteratorTest( p.listSubProperties( true ), new Object[] {q,r} ); } + @Test public void testSubPropertyDirectTransInf1b() { OntModel m = ModelFactory.createOntologyModel( ProfileRegistry.OWL_LITE_LANG ); @@ -218,6 +225,7 @@ public void testSubPropertyDirectTransInf1b() { iteratorTest( p.listSubProperties( true ), new Object[] {q,r} ); } + @Test public void testSubPropertyDirectTransInf2a() { // test the code path for generating direct sc with no reasoner OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_LITE_MEM ); @@ -237,6 +245,7 @@ public void testSubPropertyDirectTransInf2a() { iteratorTest( p.listSubProperties( true ), new Object[] {q,r} ); } + @Test public void testSubPropertyDirectTransInf2b() { // test the code path for generating direct sc with no reasoner OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_LITE_MEM ); @@ -257,6 +266,7 @@ public void testSubPropertyDirectTransInf2b() { iteratorTest( p.listSubProperties( true ), new Object[] {q,r} ); } + @Test public void testListDeclaredProperties0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RULE_INF, null ); @@ -310,6 +320,7 @@ public void testListDeclaredProperties0() { /** * Test LDP with anonymous classes */ + @Test public void testListDeclaredProperties1() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); OntProperty p = m.createOntProperty( NS + "p" ); @@ -317,10 +328,11 @@ public void testListDeclaredProperties1() { Restriction r = m.createMinCardinalityRestriction( null, p, 1 ); r.addSubClass( a ); Iterator i = a.listDeclaredProperties(); - TestUtil.assertIteratorLength( a.listDeclaredProperties(), 1 ); + OntTestUtil.assertIteratorLength( a.listDeclaredProperties(), 1 ); } /** Test LDP with resources in different sub-models */ + @Test public void testListDeclaredProperties2() { OntModel m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); @@ -341,15 +353,16 @@ public void testListDeclaredProperties2() { OntClass cc0 = m1.getOntClass( NS + "c0" ); assertNotNull( cc0 ); - TestUtil.assertIteratorValues( this, c1.listDeclaredProperties(), new Object[] {p0} ); - TestUtil.assertIteratorValues( this, c0.listDeclaredProperties(false), new Object[] {p0} ); - TestUtil.assertIteratorValues( this, cc0.listDeclaredProperties(false), new Object[] {p0} ); + OntTestUtil.assertIteratorValues(c1.listDeclaredProperties(), new Object[] {p0} ); + OntTestUtil.assertIteratorValues(c0.listDeclaredProperties(false), new Object[] {p0} ); + OntTestUtil.assertIteratorValues(cc0.listDeclaredProperties(false), new Object[] {p0} ); } /** * Problem reported by Andy Seaborne - combine abox and tbox in RDFS with * ontmodel */ + @Test public void testRDFSAbox() { String sourceT = "JENA-21 */ + @Test public void testBM0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RDFS_INF ); // should not throw NPE: m.listStatements( null, null, (RDFNode) null, null ); } - // Internal implementation methods ////////////////////////////////// @@ -495,24 +511,23 @@ protected void iteratorTest( Iterator i, Object[] expected ) { // debugging if (!expList.contains( next )) { - logger.debug( getName() + " - Unexpected iterator result: " + next ); + logger.debug( getClass().getSimpleName() + " - Unexpected iterator result: " + next ); } - assertTrue( "Value " + next + " was not expected as a result from this iterator ", expList.contains( next ) ); - assertTrue( "Value " + next + " was not removed from the list ", expList.remove( next ) ); + assertTrue( expList.contains( next ), "Value " + next + " was not expected as a result from this iterator " ); + assertTrue( expList.remove( next ), "Value " + next + " was not removed from the list " ); } if (!(expList.size() == 0)) { - logger.debug( getName() + " Expected iterator results not found" ); + logger.debug( getClass().getSimpleName() + " Expected iterator results not found" ); for ( Object anExpList : expList ) { - logger.debug( getName() + " - missing: " + anExpList ); + logger.debug( getClass().getSimpleName() + " - missing: " + anExpList ); } } - assertEquals( "There were expected elements from the iterator that were not found", 0, expList.size() ); + assertEquals( 0, expList.size(), "There were expected elements from the iterator that were not found" ); } - //============================================================================== // Inner class definitions //============================================================================== diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntResource.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntResource.java index a04ffe0d405..264b411b308 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntResource.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntResource.java @@ -23,10 +23,8 @@ /////////////// package org.apache.jena.ontology.impl; - // Imports /////////////// -import junit.framework.TestSuite; import org.apache.jena.ontology.*; import org.apache.jena.rdf.model.Literal; import org.apache.jena.rdf.model.NodeIterator; @@ -34,7 +32,9 @@ import org.apache.jena.rdf.model.Resource; import org.apache.jena.vocabulary.RDF; +import static org.junit.jupiter.api.Assertions.*; +import org.apache.jena.test.JenaTestLib; /** *

@@ -44,28 +44,21 @@ @SuppressWarnings("removal") public class TestOntResource extends OntTestBase { + + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// // Static variables ////////////////////////////////// - // Instance variables ////////////////////////////////// // Constructors ////////////////////////////////// - static public TestSuite suite() { - return new TestOntResource( "TestResource" ); - } - - public TestOntResource( String name ) { - super( name ); - } - - // External signature methods ////////////////////////////////// @@ -84,24 +77,24 @@ public void ontTest( OntModel m ) { OntResource c = m.getResource( NS + "c" ).as( OntResource.class ); a.addSameAs( b ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SAME_AS() ) ); - assertEquals( "a should be sameAs b", b, a.getSameAs() ); + assertEquals( 1, a.getCardinality( prof.SAME_AS() ), "Cardinality should be 1" ); + assertEquals( b, a.getSameAs(), "a should be sameAs b" ); a.addSameAs( c ); - assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.SAME_AS() ) ); + assertEquals( 2, a.getCardinality( prof.SAME_AS() ), "Cardinality should be 2" ); iteratorTest( a.listSameAs(), new Object[] {b, c} ); - assertTrue( "a should be the same as b", a.isSameAs( b ) ); - assertTrue( "a should be the same as c", a.isSameAs( c ) ); + assertTrue( a.isSameAs( b ), "a should be the same as b" ); + assertTrue( a.isSameAs( c ), "a should be the same as c" ); a.setSameAs( b ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SAME_AS() ) ); - assertEquals( "a should be sameAs b", b, a.getSameAs() ); + assertEquals( 1, a.getCardinality( prof.SAME_AS() ), "Cardinality should be 1" ); + assertEquals( b, a.getSameAs(), "a should be sameAs b" ); a.removeSameAs( c ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SAME_AS() ) ); + assertEquals( 1, a.getCardinality( prof.SAME_AS() ), "Cardinality should be 1" ); a.removeSameAs( b ); - assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.SAME_AS() ) ); + assertEquals( 0, a.getCardinality( prof.SAME_AS() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntResource.differentFrom", true, true, false ) { @@ -113,24 +106,24 @@ public void ontTest( OntModel m ) { OntResource c = m.getResource( NS + "c" ).as( OntResource.class ); a.addDifferentFrom( b ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DIFFERENT_FROM() ) ); - assertEquals( "a should be differentFrom b", b, a.getDifferentFrom() ); + assertEquals( 1, a.getCardinality( prof.DIFFERENT_FROM() ), "Cardinality should be 1" ); + assertEquals( b, a.getDifferentFrom(), "a should be differentFrom b" ); a.addDifferentFrom( c ); - assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.DIFFERENT_FROM() ) ); + assertEquals( 2, a.getCardinality( prof.DIFFERENT_FROM() ), "Cardinality should be 2" ); iteratorTest( a.listDifferentFrom(), new Object[] {b, c} ); - assertTrue( "a should be diff from b", a.isDifferentFrom( b ) ); - assertTrue( "a should be diff from c", a.isDifferentFrom( c ) ); + assertTrue( a.isDifferentFrom( b ), "a should be diff from b" ); + assertTrue( a.isDifferentFrom( c ), "a should be diff from c" ); a.setDifferentFrom( b ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DIFFERENT_FROM() ) ); - assertEquals( "a should be differentFrom b", b, a.getDifferentFrom() ); + assertEquals( 1, a.getCardinality( prof.DIFFERENT_FROM() ), "Cardinality should be 1" ); + assertEquals( b, a.getDifferentFrom(), "a should be differentFrom b" ); a.removeDifferentFrom( c ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DIFFERENT_FROM() ) ); + assertEquals( 1, a.getCardinality( prof.DIFFERENT_FROM() ), "Cardinality should be 1" ); a.removeDifferentFrom( b ); - assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.DIFFERENT_FROM() ) ); + assertEquals( 0, a.getCardinality( prof.DIFFERENT_FROM() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntResource.seeAlso", true, true, true ) { @@ -142,24 +135,24 @@ public void ontTest( OntModel m ) { OntResource c = m.getResource( NS + "c" ).as( OntResource.class ); a.addSeeAlso( b ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SEE_ALSO() ) ); - assertEquals( "a should be seeAlso b", b, a.getSeeAlso() ); + assertEquals( 1, a.getCardinality( prof.SEE_ALSO() ), "Cardinality should be 1" ); + assertEquals( b, a.getSeeAlso(), "a should be seeAlso b" ); a.addSeeAlso( c ); - assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.SEE_ALSO() ) ); + assertEquals( 2, a.getCardinality( prof.SEE_ALSO() ), "Cardinality should be 2" ); iteratorTest( a.listSeeAlso(), new Object[] {b, c} ); - assertTrue( "a should have seeAlso b", a.hasSeeAlso( b ) ); - assertTrue( "a should have seeAlso c", a.hasSeeAlso( c ) ); + assertTrue( a.hasSeeAlso( b ), "a should have seeAlso b" ); + assertTrue( a.hasSeeAlso( c ), "a should have seeAlso c" ); a.setSeeAlso( b ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SEE_ALSO() ) ); - assertEquals( "a should be seeAlso b", b, a.getSeeAlso() ); + assertEquals( 1, a.getCardinality( prof.SEE_ALSO() ), "Cardinality should be 1" ); + assertEquals( b, a.getSeeAlso(), "a should be seeAlso b" ); a.removeSeeAlso( c ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.SEE_ALSO() ) ); + assertEquals( 1, a.getCardinality( prof.SEE_ALSO() ), "Cardinality should be 1" ); a.removeSeeAlso( b ); - assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.SEE_ALSO() ) ); + assertEquals( 0, a.getCardinality( prof.SEE_ALSO() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntResource.isDefinedBy", true, true, true ) { @@ -171,24 +164,24 @@ public void ontTest( OntModel m ) { OntResource c = m.getResource( NS + "c" ).as( OntResource.class ); a.addIsDefinedBy( b ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.IS_DEFINED_BY() ) ); - assertEquals( "a should be isDefinedBy b", b, a.getIsDefinedBy() ); + assertEquals( 1, a.getCardinality( prof.IS_DEFINED_BY() ), "Cardinality should be 1" ); + assertEquals( b, a.getIsDefinedBy(), "a should be isDefinedBy b" ); a.addIsDefinedBy( c ); - assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.IS_DEFINED_BY() ) ); + assertEquals( 2, a.getCardinality( prof.IS_DEFINED_BY() ), "Cardinality should be 2" ); iteratorTest( a.listIsDefinedBy(), new Object[] {b, c} ); - assertTrue( "a should be defined by b", a.isDefinedBy( b ) ); - assertTrue( "a should be defined by c", a.isDefinedBy( c ) ); + assertTrue( a.isDefinedBy( b ), "a should be defined by b" ); + assertTrue( a.isDefinedBy( c ), "a should be defined by c" ); a.setIsDefinedBy( b ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.IS_DEFINED_BY() ) ); - assertEquals( "a should be isDefinedBy b", b, a.getIsDefinedBy() ); + assertEquals( 1, a.getCardinality( prof.IS_DEFINED_BY() ), "Cardinality should be 1" ); + assertEquals( b, a.getIsDefinedBy(), "a should be isDefinedBy b" ); a.removeDefinedBy( c ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.IS_DEFINED_BY() ) ); + assertEquals( 1, a.getCardinality( prof.IS_DEFINED_BY() ), "Cardinality should be 1" ); a.removeDefinedBy( b ); - assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.IS_DEFINED_BY() ) ); + assertEquals( 0, a.getCardinality( prof.IS_DEFINED_BY() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntResource.versionInfo", true, true, false ) { @@ -198,24 +191,24 @@ public void ontTest( OntModel m ) { OntResource a = m.getResource( NS + "a" ).as( OntResource.class ); a.addVersionInfo( "some info" ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.VERSION_INFO() ) ); - assertEquals( "a has wrong version info", "some info", a.getVersionInfo() ); + assertEquals( 1, a.getCardinality( prof.VERSION_INFO() ), "Cardinality should be 1" ); + assertEquals( "some info", a.getVersionInfo(), "a has wrong version info" ); a.addVersionInfo( "more info" ); - assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.VERSION_INFO() ) ); + assertEquals( 2, a.getCardinality( prof.VERSION_INFO() ), "Cardinality should be 2" ); iteratorTest( a.listVersionInfo(), new Object[] {"some info", "more info"} ); - assertTrue( "a should have some info", a.hasVersionInfo( "some info" ) ); - assertTrue( "a should have more info", a.hasVersionInfo( "more info" ) ); + assertTrue( a.hasVersionInfo( "some info" ), "a should have some info" ); + assertTrue( a.hasVersionInfo( "more info" ), "a should have more info" ); a.setVersionInfo( "new info" ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.VERSION_INFO() ) ); - assertEquals( "a has wrong version info", "new info", a.getVersionInfo() ); + assertEquals( 1, a.getCardinality( prof.VERSION_INFO() ), "Cardinality should be 1" ); + assertEquals( "new info", a.getVersionInfo(), "a has wrong version info" ); a.removeVersionInfo( "old info" ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.VERSION_INFO() ) ); + assertEquals( 1, a.getCardinality( prof.VERSION_INFO() ), "Cardinality should be 1" ); a.removeVersionInfo( "new info" ); - assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.VERSION_INFO() ) ); + assertEquals( 0, a.getCardinality( prof.VERSION_INFO() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntResource.label.nolang", true, true, true ) { @@ -225,24 +218,24 @@ public void ontTest( OntModel m ) { OntResource a = m.getResource( NS + "a" ).as( OntResource.class ); a.addLabel( "some info", null ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.LABEL() ) ); - assertEquals( "a has wrong label", "some info", a.getLabel( null ) ); + assertEquals( 1, a.getCardinality( prof.LABEL() ), "Cardinality should be 1" ); + assertEquals( "some info", a.getLabel( null ), "a has wrong label" ); a.addLabel( "more info", null ); - assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.LABEL() ) ); + assertEquals( 2, a.getCardinality( prof.LABEL() ), "Cardinality should be 2" ); iteratorTest( a.listLabels( null ), new Object[] {m.createLiteral( "some info" ), m.createLiteral( "more info" )} ); - assertTrue( "a should have label some info", a.hasLabel( "some info", null ) ); - assertTrue( "a should have label more info", a.hasLabel( "more info", null ) ); + assertTrue( a.hasLabel( "some info", null ), "a should have label some info" ); + assertTrue( a.hasLabel( "more info", null ), "a should have label more info" ); a.setLabel( "new info", null ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.LABEL() ) ); - assertEquals( "a has wrong label", "new info", a.getLabel( null ) ); + assertEquals( 1, a.getCardinality( prof.LABEL() ), "Cardinality should be 1" ); + assertEquals( "new info", a.getLabel( null ), "a has wrong label" ); a.removeLabel( "foo", null ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.LABEL() ) ); + assertEquals( 1, a.getCardinality( prof.LABEL() ), "Cardinality should be 1" ); a.removeLabel( "new info", null ); - assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.LABEL() ) ); + assertEquals( 0, a.getCardinality( prof.LABEL() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntResource.label.lang", true, true, true ) { @@ -251,33 +244,33 @@ public void ontTest( OntModel m ) { OntResource a = m.getResource( NS + "a" ).as( OntResource.class ); a.addLabel( "good", "EN" ); - assertEquals( "wrong label", "good", a.getLabel( null ) ); + assertEquals( "good", a.getLabel( null ), "wrong label" ); a.addLabel( "bon", "FR" ); - assertEquals( "wrong label", "good", a.getLabel( "EN" ) ); - assertEquals( "wrong label", null, a.getLabel( "EN-GB" ) ); // no literal with a specific enough language - assertEquals( "wrong label", "bon", a.getLabel( "FR" ) ); + assertEquals( "good", a.getLabel( "EN" ), "wrong label" ); + assertEquals( null, a.getLabel( "EN-GB" ), "wrong label" ); // no literal with a specific enough language + assertEquals( "bon", a.getLabel( "FR" ), "wrong label" ); - assertTrue( "a should have label good", a.hasLabel( "good", "EN" ) ); - assertTrue( "a should have label bon", a.hasLabel( "bon", "FR" ) ); - assertTrue( "a should note have label good (DE)", !a.hasLabel( "good", "DE" ) ); + assertTrue( a.hasLabel( "good", "EN" ), "a should have label good" ); + assertTrue( a.hasLabel( "bon", "FR" ), "a should have label bon" ); + assertTrue( !a.hasLabel( "good", "DE" ), "a should note have label good (DE)" ); a.addLabel( "spiffing", "EN-GB" ); a.addLabel( "duude", "EN-US" ); - assertEquals( "wrong label", "spiffing", a.getLabel( "EN-GB" ) ); - assertEquals( "wrong label", "duude", a.getLabel( "EN-US" ) ); - assertEquals( "wrong label", null, a.getLabel( "DE" ) ); + assertEquals( "spiffing", a.getLabel( "EN-GB" ), "wrong label" ); + assertEquals( "duude", a.getLabel( "EN-US" ), "wrong label" ); + assertEquals( null, a.getLabel( "DE" ), "wrong label" ); a.addLabel( "abcdef", "AB-CD" ); - assertEquals( "wrong label", "abcdef", a.getLabel( "AB" ) ); - assertEquals( "wrong label", null, a.getLabel( "AB-XY" ) ); + assertEquals( "abcdef", a.getLabel( "AB" ), "wrong label" ); + assertEquals( null, a.getLabel( "AB-XY" ), "wrong label" ); a.removeLabel( "abcde", "AB-CD" ); - assertEquals( "Cardinality should be 5", 5, a.getCardinality( a.getProfile().LABEL() ) ); + assertEquals( 5, a.getCardinality( a.getProfile().LABEL() ), "Cardinality should be 5" ); a.removeLabel( "abcdef", "AB-CD" ); - assertEquals( "Cardinality should be 4", 4, a.getCardinality( a.getProfile().LABEL() ) ); + assertEquals( 4, a.getCardinality( a.getProfile().LABEL() ), "Cardinality should be 4" ); } }, new OntTestCase( "OntResource.comment.nolang", true, true, true ) { @@ -287,24 +280,24 @@ public void ontTest( OntModel m ) { OntResource a = m.getResource( NS + "a" ).as( OntResource.class ); a.addComment( "some info", null ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.COMMENT() ) ); - assertEquals( "a has wrong comment", "some info", a.getComment( null ) ); + assertEquals( 1, a.getCardinality( prof.COMMENT() ), "Cardinality should be 1" ); + assertEquals( "some info", a.getComment( null ), "a has wrong comment" ); a.addComment( "more info", null ); - assertEquals( "Cardinality should be 2", 2, a.getCardinality( prof.COMMENT() ) ); + assertEquals( 2, a.getCardinality( prof.COMMENT() ), "Cardinality should be 2" ); iteratorTest( a.listComments( null ), new Object[] {m.createLiteral( "some info" ), m.createLiteral( "more info" )} ); - assertTrue( "a should have comment some info", a.hasComment( "some info", null ) ); - assertTrue( "a should have comment more info", a.hasComment( "more info", null ) ); + assertTrue( a.hasComment( "some info", null ), "a should have comment some info" ); + assertTrue( a.hasComment( "more info", null ), "a should have comment more info" ); a.setComment( "new info", null ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.COMMENT() ) ); - assertEquals( "a has wrong comment", "new info", a.getComment( null ) ); + assertEquals( 1, a.getCardinality( prof.COMMENT() ), "Cardinality should be 1" ); + assertEquals( "new info", a.getComment( null ), "a has wrong comment" ); a.removeComment( "foo", null ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.COMMENT() ) ); + assertEquals( 1, a.getCardinality( prof.COMMENT() ), "Cardinality should be 1" ); a.removeComment( "new info", null ); - assertEquals( "Cardinality should be 0", 0, a.getCardinality( prof.COMMENT() ) ); + assertEquals( 0, a.getCardinality( prof.COMMENT() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntResource.comment.lang", true, true, true ) { @@ -313,33 +306,33 @@ public void ontTest( OntModel m ) { OntResource a = m.getResource( NS + "a" ).as( OntResource.class ); a.addComment( "good", "EN" ); - assertEquals( "wrong comment", "good", a.getComment( null ) ); + assertEquals( "good", a.getComment( null ), "wrong comment" ); a.addComment( "bon", "FR" ); - assertEquals( "wrong comment", "good", a.getComment( "EN" ) ); - assertEquals( "wrong comment", null, a.getComment( "EN-GB" ) ); // no literal with a specific enough language - assertEquals( "wrong comment", "bon", a.getComment( "FR" ) ); + assertEquals( "good", a.getComment( "EN" ), "wrong comment" ); + assertEquals( null, a.getComment( "EN-GB" ), "wrong comment" ); // no literal with a specific enough language + assertEquals( "bon", a.getComment( "FR" ), "wrong comment" ); - assertTrue( "a should have label good", a.hasComment( "good", "EN" ) ); - assertTrue( "a should have label bon", a.hasComment( "bon", "FR" ) ); - assertTrue( "a should note have label good (DE)", !a.hasComment( "good", "DE" ) ); + assertTrue( a.hasComment( "good", "EN" ), "a should have label good" ); + assertTrue( a.hasComment( "bon", "FR" ), "a should have label bon" ); + assertTrue( !a.hasComment( "good", "DE" ), "a should note have label good (DE)" ); a.addComment( "spiffing", "EN-GB" ); a.addComment( "duude", "EN-US" ); - assertEquals( "wrong comment", "spiffing", a.getComment( "EN-GB" ) ); - assertEquals( "wrong comment", "duude", a.getComment( "EN-US" ) ); - assertEquals( "wrong comment", null, a.getComment( "DE" ) ); + assertEquals( "spiffing", a.getComment( "EN-GB" ), "wrong comment" ); + assertEquals( "duude", a.getComment( "EN-US" ), "wrong comment" ); + assertEquals( null, a.getComment( "DE" ), "wrong comment" ); a.addComment( "abcdef", "AB-CD" ); - assertEquals( "wrong comment", "abcdef", a.getComment( "AB" ) ); - assertEquals( "wrong comment", null, a.getComment( "AB-XY" ) ); + assertEquals( "abcdef", a.getComment( "AB" ), "wrong comment" ); + assertEquals( null, a.getComment( "AB-XY" ), "wrong comment" ); a.removeComment( "abcde", "AB-CD" ); - assertEquals( "Cardinality should be 5", 5, a.getCardinality( a.getProfile().COMMENT() ) ); + assertEquals( 5, a.getCardinality( a.getProfile().COMMENT() ), "Cardinality should be 5" ); a.removeComment( "abcdef", "AB-CD" ); - assertEquals( "Cardinality should be 4", 4, a.getCardinality( a.getProfile().COMMENT() ) ); + assertEquals( 4, a.getCardinality( a.getProfile().COMMENT() ), "Cardinality should be 4" ); } }, new OntTestCase( "OntResource.type (no inference)", true, true, true ) { @@ -350,11 +343,11 @@ public void ontTest( OntModel m ) { A.addSubClass( B ); OntResource a = m.getResource( NS + "a" ).as( OntResource.class ); - assertEquals( "Cardinality of rdf:type is wrong", 0, a.getCardinality( RDF.type ) ); + assertEquals( 0, a.getCardinality( RDF.type ), "Cardinality of rdf:type is wrong" ); a.addRDFType( B ); - assertEquals( "rdf:type of a is wrong", B, a.getRDFType() ); - assertEquals( "rdf:type of a is wrong", B, a.getRDFType( false ) ); + assertEquals( B, a.getRDFType(), "rdf:type of a is wrong" ); + assertEquals( B, a.getRDFType( false ), "rdf:type of a is wrong" ); iteratorTest( a.listRDFTypes( false ), new Object[] {B} ); // only B since we're not using an inference model iteratorTest( a.listRDFTypes( true ), new Object[] {B} ); @@ -363,19 +356,19 @@ public void ontTest( OntModel m ) { iteratorTest( a.listRDFTypes( false ), new Object[] {A,B} ); iteratorTest( a.listRDFTypes( true ), new Object[] {B} ); - assertTrue( "a should not be of class A direct", !a.hasRDFType( A, true )); - assertTrue( "a should not be of class B direct", a.hasRDFType( B, true )); + assertTrue( !a.hasRDFType( A, true ), "a should not be of class A direct"); + assertTrue( a.hasRDFType( B, true ), "a should not be of class B direct"); OntClass C = m.createClass( NS + "C" ); a.setRDFType( C ); - assertTrue( "a should be of class C", a.hasRDFType( C, false )); - assertTrue( "a should not be of class A", !a.hasRDFType( A, false )); - assertTrue( "a should not be of class B", !a.hasRDFType( B, false )); + assertTrue( a.hasRDFType( C, false ), "a should be of class C"); + assertTrue( !a.hasRDFType( A, false ), "a should not be of class A"); + assertTrue( !a.hasRDFType( B, false ), "a should not be of class B"); a.removeRDFType( B ); - assertEquals( "Cardinality should be 1", 1, a.getCardinality( RDF.type ) ); + assertEquals( 1, a.getCardinality( RDF.type ), "Cardinality should be 1" ); a.removeRDFType( C ); - assertEquals( "Cardinality should be 0", 0, a.getCardinality( RDF.type ) ); + assertEquals( 0, a.getCardinality( RDF.type ), "Cardinality should be 0" ); } }, new OntTestCase( "OntResource.remove", true, true, true ) { @@ -391,13 +384,13 @@ public void ontTest( OntModel m ) { C.addSubClass( D ); C.addSubClass( E ); - assertTrue( "super-class of E", E.hasSuperClass( C, false ) ); + assertTrue( E.hasSuperClass( C, false ), "super-class of E" ); iteratorTest( A.listSubClasses(), new Object[] {B,C} ); C.remove(); - assertTrue( "super-class of D", !D.hasSuperClass( C, false ) ); - assertTrue( "super-class of E", !E.hasSuperClass( C, false ) ); + assertTrue( !D.hasSuperClass( C, false ), "super-class of D" ); + assertTrue( !E.hasSuperClass( C, false ), "super-class of E" ); iteratorTest( A.listSubClasses(), new Object[] {B} ); } }, @@ -407,18 +400,18 @@ public void ontTest( OntModel m ) { Resource r = m.createResource(); r.addProperty( RDF.type, m.getProfile().CLASS() ); OntResource or = r.as( OntResource.class ); - assertFalse( "should not be annotation prop", or.isAnnotationProperty() ); - assertFalse( "should not be all different", or.isAllDifferent() ); - assertTrue( "should be class", or.isClass() ); - assertFalse( "should not be property", or.isProperty() ); - assertFalse( "should not be object property", or.isObjectProperty() ); - assertFalse( "should not be datatype property", or.isDatatypeProperty() ); - assertTrue( "should not be individual", owlFull() || !or.isIndividual() ); - assertFalse( "should not be data range", or.isDataRange() ); - assertFalse( "should not be ontology", or.isOntology() ); + assertFalse( or.isAnnotationProperty(), "should not be annotation prop" ); + assertFalse( or.isAllDifferent(), "should not be all different" ); + assertTrue( or.isClass(), "should be class" ); + assertFalse( or.isProperty(), "should not be property" ); + assertFalse( or.isObjectProperty(), "should not be object property" ); + assertFalse( or.isDatatypeProperty(), "should not be datatype property" ); + assertTrue( owlFull() || !or.isIndividual(), "should not be individual" ); + assertFalse( or.isDataRange(), "should not be data range" ); + assertFalse( or.isOntology(), "should not be ontology" ); RDFNode n = or.asClass(); - assertTrue( "Should be OntClass", n instanceof OntClass ); + assertTrue( n instanceof OntClass, "Should be OntClass" ); } }, new OntTestCase( "OntResource.asAnnotationProperty", true, true, false) { @@ -431,18 +424,18 @@ public void ontTest( OntModel m ) { r.addProperty( RDF.type, m.getProfile().ANNOTATION_PROPERTY() ); OntResource or = r.as( OntResource.class ); - assertTrue( "should be annotation prop", or.isAnnotationProperty() ); - assertFalse( "should not be all different", or.isAllDifferent() ); - assertFalse( "should not be class", or.isClass() ); - assertTrue( "should be property", or.isProperty() ); - assertFalse( "should not be object property", or.isObjectProperty() ); - assertFalse( "should not be datatype property", or.isDatatypeProperty() ); - assertFalse( "should not be individual", or.isIndividual() ); - assertFalse( "should not be data range", or.isDataRange() ); - assertFalse( "should not be ontology", or.isOntology() ); + assertTrue( or.isAnnotationProperty(), "should be annotation prop" ); + assertFalse( or.isAllDifferent(), "should not be all different" ); + assertFalse( or.isClass(), "should not be class" ); + assertTrue( or.isProperty(), "should be property" ); + assertFalse( or.isObjectProperty(), "should not be object property" ); + assertFalse( or.isDatatypeProperty(), "should not be datatype property" ); + assertFalse( or.isIndividual(), "should not be individual" ); + assertFalse( or.isDataRange(), "should not be data range" ); + assertFalse( or.isOntology(), "should not be ontology" ); RDFNode n = or.asAnnotationProperty(); - assertTrue( "Should be AnnotationProperty", n instanceof AnnotationProperty); + assertTrue( n instanceof AnnotationProperty, "Should be AnnotationProperty"); } }, new OntTestCase( "OntResource.asObjectProperty", true, true, false) { @@ -455,18 +448,18 @@ public void ontTest( OntModel m ) { r.addProperty( RDF.type, m.getProfile().OBJECT_PROPERTY() ); OntResource or = r.as( OntResource.class ); - assertFalse( "should not be annotation prop", or.isAnnotationProperty() ); - assertFalse( "should not be all different", or.isAllDifferent() ); - assertFalse( "should not be class", or.isClass() ); - assertTrue( "should be property", or.isProperty() ); - assertTrue( "should be object property", or.isObjectProperty() ); - assertFalse( "should not be datatype property", or.isDatatypeProperty() ); - assertFalse( "should not be individual", or.isIndividual() ); - assertFalse( "should not be data range", or.isDataRange() ); - assertFalse( "should not be ontology", or.isOntology() ); + assertFalse( or.isAnnotationProperty(), "should not be annotation prop" ); + assertFalse( or.isAllDifferent(), "should not be all different" ); + assertFalse( or.isClass(), "should not be class" ); + assertTrue( or.isProperty(), "should be property" ); + assertTrue( or.isObjectProperty(), "should be object property" ); + assertFalse( or.isDatatypeProperty(), "should not be datatype property" ); + assertFalse( or.isIndividual(), "should not be individual" ); + assertFalse( or.isDataRange(), "should not be data range" ); + assertFalse( or.isOntology(), "should not be ontology" ); RDFNode n = or.asObjectProperty(); - assertTrue( "Should be ObjectProperty", n instanceof ObjectProperty); + assertTrue( n instanceof ObjectProperty, "Should be ObjectProperty"); } }, new OntTestCase( "OntResource.asDatatypeProperty", true, true, false) { @@ -479,18 +472,18 @@ public void ontTest( OntModel m ) { r.addProperty( RDF.type, m.getProfile().DATATYPE_PROPERTY() ); OntResource or = r.as( OntResource.class ); - assertFalse( "should not be annotation prop", or.isAnnotationProperty() ); - assertFalse( "should not be all different", or.isAllDifferent() ); - assertFalse( "should not be class", or.isClass() ); - assertTrue( "should be property", or.isProperty() ); - assertFalse( "should not be object property", or.isObjectProperty() ); - assertTrue( "should be datatype property", or.isDatatypeProperty() ); - assertFalse( "should not be individual", or.isIndividual() ); - assertFalse( "should not be data range", or.isDataRange() ); - assertFalse( "should not be ontology", or.isOntology() ); + assertFalse( or.isAnnotationProperty(), "should not be annotation prop" ); + assertFalse( or.isAllDifferent(), "should not be all different" ); + assertFalse( or.isClass(), "should not be class" ); + assertTrue( or.isProperty(), "should be property" ); + assertFalse( or.isObjectProperty(), "should not be object property" ); + assertTrue( or.isDatatypeProperty(), "should be datatype property" ); + assertFalse( or.isIndividual(), "should not be individual" ); + assertFalse( or.isDataRange(), "should not be data range" ); + assertFalse( or.isOntology(), "should not be ontology" ); RDFNode n = or.asDatatypeProperty(); - assertTrue( "Should be DatatypeProperty", n instanceof DatatypeProperty); + assertTrue( n instanceof DatatypeProperty, "Should be DatatypeProperty"); } }, new OntTestCase( "OntResource.asAllDifferent", true, true, false) { @@ -503,18 +496,18 @@ public void ontTest( OntModel m ) { r.addProperty( RDF.type, m.getProfile().ALL_DIFFERENT() ); OntResource or = r.as( OntResource.class ); - assertFalse( "should not be annotation prop", or.isAnnotationProperty() ); - assertTrue( "should be all different", or.isAllDifferent() ); - assertFalse( "should not be class", or.isClass() ); - assertFalse( "should not be property", or.isProperty() ); - assertFalse( "should not be object property", or.isObjectProperty() ); - assertFalse( "should not be datatype property", or.isDatatypeProperty() ); - assertFalse( "should not be individual", or.isIndividual() ); - assertFalse( "should not be data range", or.isDataRange() ); - assertFalse( "should not be ontology", or.isOntology() ); + assertFalse( or.isAnnotationProperty(), "should not be annotation prop" ); + assertTrue( or.isAllDifferent(), "should be all different" ); + assertFalse( or.isClass(), "should not be class" ); + assertFalse( or.isProperty(), "should not be property" ); + assertFalse( or.isObjectProperty(), "should not be object property" ); + assertFalse( or.isDatatypeProperty(), "should not be datatype property" ); + assertFalse( or.isIndividual(), "should not be individual" ); + assertFalse( or.isDataRange(), "should not be data range" ); + assertFalse( or.isOntology(), "should not be ontology" ); RDFNode n = or.asAllDifferent(); - assertTrue( "Should be AnnotationProperty", n instanceof AllDifferent); + assertTrue( n instanceof AllDifferent, "Should be AnnotationProperty"); } }, new OntTestCase( "OntResource.asProperty", true, true, true ) { @@ -524,18 +517,18 @@ public void ontTest( OntModel m ) { r.addProperty( RDF.type, m.getProfile().PROPERTY() ); OntResource or = r.as( OntResource.class ); - assertFalse( "should not be annotation prop", or.isAnnotationProperty() ); - assertFalse( "should not be all different", or.isAllDifferent() ); - assertFalse( "should not be class", or.isClass() ); - assertTrue( "should be property", or.isProperty() ); - assertFalse( "should not be object property", or.isObjectProperty() ); - assertFalse( "should not be datatype property", or.isDatatypeProperty() ); - assertFalse( "should not be individual", or.isIndividual() ); - assertFalse( "should not be data range", or.isDataRange() ); - assertFalse( "should not be ontology", or.isOntology() ); + assertFalse( or.isAnnotationProperty(), "should not be annotation prop" ); + assertFalse( or.isAllDifferent(), "should not be all different" ); + assertFalse( or.isClass(), "should not be class" ); + assertTrue( or.isProperty(), "should be property" ); + assertFalse( or.isObjectProperty(), "should not be object property" ); + assertFalse( or.isDatatypeProperty(), "should not be datatype property" ); + assertFalse( or.isIndividual(), "should not be individual" ); + assertFalse( or.isDataRange(), "should not be data range" ); + assertFalse( or.isOntology(), "should not be ontology" ); RDFNode n = or.asProperty(); - assertTrue( "Should be OntProperty", n instanceof OntProperty); + assertTrue( n instanceof OntProperty, "Should be OntProperty"); } }, new OntTestCase( "OntResource.asIndividual", true, true, true ) { @@ -547,18 +540,18 @@ public void ontTest( OntModel m ) { r.addProperty( RDF.type, s ); OntResource or = r.as( OntResource.class ); - assertFalse( "should not be annotation prop", or.isAnnotationProperty() ); - assertFalse( "should not be all different", or.isAllDifferent() ); - assertFalse( "should not be class", or.isClass() ); - assertFalse( "should not be property", or.isProperty() ); - assertFalse( "should not be object property", or.isObjectProperty() ); - assertFalse( "should not be datatype property", or.isDatatypeProperty() ); - assertTrue( "should be individual", or.isIndividual() ); - assertFalse( "should not be data range", or.isDataRange() ); - assertFalse( "should not be ontology", or.isOntology() ); + assertFalse( or.isAnnotationProperty(), "should not be annotation prop" ); + assertFalse( or.isAllDifferent(), "should not be all different" ); + assertFalse( or.isClass(), "should not be class" ); + assertFalse( or.isProperty(), "should not be property" ); + assertFalse( or.isObjectProperty(), "should not be object property" ); + assertFalse( or.isDatatypeProperty(), "should not be datatype property" ); + assertTrue( or.isIndividual(), "should be individual" ); + assertFalse( or.isDataRange(), "should not be data range" ); + assertFalse( or.isOntology(), "should not be ontology" ); RDFNode n = or.asIndividual(); - assertTrue( "Should be individual", n instanceof Individual); + assertTrue( n instanceof Individual, "Should be individual"); } }, new OntTestCase( "OntResource.asDataRange", true, false, false ) { @@ -571,18 +564,18 @@ public void ontTest( OntModel m ) { r.addProperty( RDF.type, m.getProfile().DATARANGE() ); OntResource or = r.as( OntResource.class ); - assertFalse( "should not be annotation prop", or.isAnnotationProperty() ); - assertFalse( "should not be all different", or.isAllDifferent() ); - assertFalse( "should not be class", or.isClass() ); - assertFalse( "should not be property", or.isProperty() ); - assertFalse( "should not be object property", or.isObjectProperty() ); - assertFalse( "should not be datatype property", or.isDatatypeProperty() ); - assertFalse( "should not be individual", or.isIndividual() ); - assertTrue( "should be data range", or.isDataRange() ); - assertFalse( "should not be ontology", or.isOntology() ); + assertFalse( or.isAnnotationProperty(), "should not be annotation prop" ); + assertFalse( or.isAllDifferent(), "should not be all different" ); + assertFalse( or.isClass(), "should not be class" ); + assertFalse( or.isProperty(), "should not be property" ); + assertFalse( or.isObjectProperty(), "should not be object property" ); + assertFalse( or.isDatatypeProperty(), "should not be datatype property" ); + assertFalse( or.isIndividual(), "should not be individual" ); + assertTrue( or.isDataRange(), "should be data range" ); + assertFalse( or.isOntology(), "should not be ontology" ); RDFNode n = or.asDataRange(); - assertTrue( "Should be DataRange", n instanceof DataRange ); + assertTrue( n instanceof DataRange, "Should be DataRange" ); } }, new OntTestCase( "OntResource.asOntology", true, true, false ) { @@ -595,18 +588,18 @@ public void ontTest( OntModel m ) { r.addProperty( RDF.type, m.getProfile().ONTOLOGY() ); OntResource or = r.as( OntResource.class ); - assertFalse( "should not be annotation prop", or.isAnnotationProperty() ); - assertFalse( "should not be all different", or.isAllDifferent() ); - assertFalse( "should not be class", or.isClass() ); - assertFalse( "should not be property", or.isProperty() ); - assertFalse( "should not be object property", or.isObjectProperty() ); - assertFalse( "should not be datatype property", or.isDatatypeProperty() ); - assertFalse( "should not be individual", or.isIndividual() ); - assertFalse( "should not be data range", or.isDataRange() ); - assertTrue( "should be ontology", or.isOntology() ); + assertFalse( or.isAnnotationProperty(), "should not be annotation prop" ); + assertFalse( or.isAllDifferent(), "should not be all different" ); + assertFalse( or.isClass(), "should not be class" ); + assertFalse( or.isProperty(), "should not be property" ); + assertFalse( or.isObjectProperty(), "should not be object property" ); + assertFalse( or.isDatatypeProperty(), "should not be datatype property" ); + assertFalse( or.isIndividual(), "should not be individual" ); + assertFalse( or.isDataRange(), "should not be data range" ); + assertTrue( or.isOntology(), "should be ontology" ); RDFNode n = or.asOntology(); - assertTrue( "Should be Ontology", n instanceof Ontology); + assertTrue( n instanceof Ontology, "Should be Ontology"); } }, new OntTestCase( "OntResource.isLanguageTerm", true, true, true ) { @@ -614,10 +607,10 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { // class is defined (differently) in every profile OntResource or = m.getProfile().CLASS().inModel(m).as( OntResource.class ); - assertTrue( "should be a lang term", or.isOntLanguageTerm() ); + assertTrue( or.isOntLanguageTerm(), "should be a lang term" ); or = m.createOntResource( "http://foo/bar" ); - assertFalse( "should not be a lang term", or.isOntLanguageTerm() ); + assertFalse( or.isOntLanguageTerm(), "should not be a lang term" ); } }, new OntTestCase( "OntResource.getOntModel", true, true, true ) { @@ -637,7 +630,7 @@ public void ontTest( OntModel m ) { m.add( a, p, b ); Object bb = a.getPropertyValue( p ); assertEquals( b, bb ); - assertTrue( "Return value should be an OntResource", bb instanceof OntResource ); + assertTrue( bb instanceof OntResource, "Return value should be an OntResource" ); } }, new OntTestCase( "OntResource.getPropertyValue - missing prop", true, true, true ) { @@ -667,7 +660,7 @@ public void ontTest( OntModel m ) { RDFNode n = ni.nextNode(); if (n.isResource()) { assertEquals( b, n ); - assertTrue( "Return value should be an OntResource", n instanceof OntResource ); + assertTrue( n instanceof OntResource, "Return value should be an OntResource" ); } } } diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntTools.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntTools.java index 729d21f9358..099a0b66461 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntTools.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntTools.java @@ -23,11 +23,9 @@ /////////////// package org.apache.jena.ontology.impl; - // Imports /////////////// -import junit.framework.TestCase; import org.apache.jena.ontology.OntClass; import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModelSpec; @@ -41,6 +39,12 @@ import java.util.List; import java.util.function.Predicate; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.apache.jena.test.JenaTestLib; /** *

@@ -49,8 +53,10 @@ */ @SuppressWarnings("removal") public class TestOntTools - extends TestCase { + + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// @@ -79,11 +85,8 @@ public class TestOntTools // External signature methods ////////////////////////////////// - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() { + @BeforeEach + public void setUp() { m_model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF ); m_a = m_model.createClass( NS + "A" ); m_b = m_model.createClass( NS + "B" ); @@ -98,6 +101,7 @@ protected void setUp() { /** * Test method for org.apache.jena.ontology.OntTools#indexLCA */ + @Test public void testIndexLCA0() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -105,6 +109,7 @@ public void testIndexLCA0() { assertEquals( m_a, OntTools.getLCA( m_model, m_b, m_c ) ); } + @Test public void testIndexLCA1() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -112,6 +117,7 @@ public void testIndexLCA1() { assertEquals( m_a, OntTools.getLCA( m_model, m_c, m_b ) ); } + @Test public void testIndexLCA2() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -119,6 +125,7 @@ public void testIndexLCA2() { assertEquals( m_a, OntTools.getLCA( m_model, m_a, m_c ) ); } + @Test public void testIndexLCA3() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -126,6 +133,7 @@ public void testIndexLCA3() { assertEquals( m_a, OntTools.getLCA( m_model, m_b, m_a ) ); } + @Test public void testIndexLCA4() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -134,6 +142,7 @@ public void testIndexLCA4() { assertEquals( m_a, OntTools.getLCA( m_model, m_d, m_c ) ); } + @Test public void testIndexLCA5() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -142,6 +151,7 @@ public void testIndexLCA5() { assertEquals( m_a, OntTools.getLCA( m_model, m_c, m_d ) ); } + @Test public void testIndexLCA6() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -151,6 +161,7 @@ public void testIndexLCA6() { assertEquals( m_a, OntTools.getLCA( m_model, m_d, m_e ) ); } + @Test public void testIndexLCA7() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -160,6 +171,7 @@ public void testIndexLCA7() { assertEquals( m_a, OntTools.getLCA( m_model, m_e, m_d ) ); } + @Test public void testIndexLCA8() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -169,6 +181,7 @@ public void testIndexLCA8() { assertEquals( m_a, OntTools.getLCA( m_model, m_c, m_e ) ); } + @Test public void testIndexLCA9() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -178,6 +191,7 @@ public void testIndexLCA9() { assertEquals( m_a, OntTools.getLCA( m_model, m_b, m_c ) ); } + @Test public void testIndexLCA10() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -188,6 +202,7 @@ public void testIndexLCA10() { assertEquals( m_a, OntTools.getLCA( m_model, m_b, m_e ) ); } + @Test public void testIndexLCA11() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -198,6 +213,7 @@ public void testIndexLCA11() { assertEquals( m_a, OntTools.getLCA( m_model, m_b, m_f ) ); } + @Test public void testIndexLCA12() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -208,6 +224,7 @@ public void testIndexLCA12() { assertEquals( m_d, OntTools.getLCA( m_model, m_f, m_e ) ); } + @Test public void testIndexLCA13() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -220,6 +237,7 @@ public void testIndexLCA13() { } /** Disconnected trees */ + @Test public void testIndexLCA14() { m_a.addSubClass( m_b ); m_a.addSubClass( m_c ); @@ -233,6 +251,7 @@ public void testIndexLCA14() { static final Predicate ANY = s -> true; + @Test public void testShortestPath0() { Property p = m_model.createProperty( NS + "p" ); m_a.addProperty( p, m_b ); @@ -241,6 +260,7 @@ public void testShortestPath0() { new Property[] {p} ); } + @Test public void testShortestPath1() { Property p = m_model.createProperty( NS + "p" ); m_a.addProperty( p, m_b ); @@ -250,6 +270,7 @@ public void testShortestPath1() { new Property[] {p,p} ); } + @Test public void testShortestPath2() { Property p = m_model.createProperty( NS + "p" ); // a - b - c @@ -267,6 +288,7 @@ public void testShortestPath2() { new Property[] {p,p,p} ); } + @Test public void testShortestPath3() { Property p = m_model.createProperty( NS + "p" ); // a - b - c @@ -284,6 +306,7 @@ public void testShortestPath3() { new Property[] {p,p,p} ); } + @Test public void testShortestPath4() { Property p = m_model.createProperty( NS + "p" ); Property q = m_model.createProperty( NS + "q" ); @@ -303,6 +326,7 @@ public void testShortestPath4() { } /** Reflexive loop is allowed */ + @Test public void testShortestPath5() { Property p = m_model.createProperty( NS + "p" ); m_a.addProperty( p, m_a ); @@ -311,6 +335,7 @@ public void testShortestPath5() { new Property[] {p} ); } + @Test public void testShortestPath6() { Property p = m_model.createProperty( NS + "p" ); Property q = m_model.createProperty( NS + "q" ); @@ -323,6 +348,7 @@ public void testShortestPath6() { assertNull( OntTools.findShortestPath( m_model, m_a, m_c, new OntTools.PredicatesFilter( new Property[] {p,q} ) ) ); } + @Test public void testShortestPath7() { Property p = m_model.createProperty( NS + "p" ); Property q = m_model.createProperty( NS + "q" ); @@ -338,6 +364,7 @@ public void testShortestPath7() { } /** Find a literal target */ + @Test public void testShortestPath8() { Property p = m_model.createProperty( NS + "p" ); Property q = m_model.createProperty( NS + "q" ); @@ -357,6 +384,7 @@ public void testShortestPath8() { /** Tests on {@link OntTools#namedHierarchyRoots(OntModel)} */ + @Test public void testNamedHierarchyRoots0() { m_a.addSubClass( m_b ); m_b.addSubClass( m_c ); @@ -371,6 +399,7 @@ public void testNamedHierarchyRoots0() { assertTrue( nhr.contains( m_g )); } + @Test public void testNamedHierarchyRoots1() { m_a.addSubClass( m_b ); m_b.addSubClass( m_c ); @@ -389,6 +418,7 @@ public void testNamedHierarchyRoots1() { assertTrue( nhr.contains( m_g )); } + @Test public void testNamedHierarchyRoots2() { OntClass anon0 = m_model.createClass(); OntClass anon1 = m_model.createClass(); @@ -411,6 +441,7 @@ public void testNamedHierarchyRoots2() { } /** Test for no dups in the returned list */ + @Test public void testNamedHierarchyRoots3() { OntClass anon0 = m_model.createClass(); OntClass anon1 = m_model.createClass(); @@ -431,6 +462,7 @@ public void testNamedHierarchyRoots3() { } /** Test for indirect route to a non-root node */ + @Test public void testNamedHierarchyRoots4() { OntClass anon0 = m_model.createClass(); OntClass anon1 = m_model.createClass(); @@ -460,12 +492,11 @@ private void testPath( OntTools.Path path, Property[] expected ) { int i = 0; for ( Statement aPath : path ) { - assertEquals( "path position: " + i, expected[i], aPath.getPredicate() ); + assertEquals( expected[i], aPath.getPredicate(), "path position: " + i ); i++; } } - //============================================================================== // Inner class definitions //============================================================================== diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntology.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntology.java index 3ed05b2ecc8..ffc977cd24f 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntology.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntology.java @@ -23,12 +23,13 @@ /////////////// package org.apache.jena.ontology.impl; - // Imports /////////////// -import junit.framework.TestSuite; import org.apache.jena.ontology.*; +import static org.junit.jupiter.api.Assertions.*; + +import org.apache.jena.test.JenaTestLib; /** *

@@ -36,34 +37,23 @@ *

*/ @SuppressWarnings("removal") -public class TestOntology - extends OntTestBase +public class TestOntology extends OntTestBase { + + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// // Static variables ////////////////////////////////// - - // Instance variables ////////////////////////////////// // Constructors ////////////////////////////////// - static public TestSuite suite() { - return new TestOntology( "TestOntology" ); - } - - public TestOntology( String name ) { - super( name ); - } - - - - // External signature methods ////////////////////////////////// @@ -79,21 +69,21 @@ public void ontTest( OntModel m ) { Ontology z = m.createOntology( NS + "z" ); x.addImport( y ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.IMPORTS() ) ); - assertEquals( "x should import y", y, x.getImport() ); + assertEquals( 1, x.getCardinality( prof.IMPORTS() ), "Cardinality should be 1" ); + assertEquals( y, x.getImport(), "x should import y" ); x.addImport( z ); - assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.IMPORTS() ) ); + assertEquals( 2, x.getCardinality( prof.IMPORTS() ), "Cardinality should be 2" ); iteratorTest( x.listImports(), new Object[] {y,z} ); x.setImport( z ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.IMPORTS() ) ); - assertEquals( "x should import z", z, x.getImport() ); + assertEquals( 1, x.getCardinality( prof.IMPORTS() ), "Cardinality should be 1" ); + assertEquals( z, x.getImport(), "x should import z" ); x.removeImport( y ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.IMPORTS() ) ); + assertEquals( 1, x.getCardinality( prof.IMPORTS() ), "Cardinality should be 1" ); x.removeImport( z ); - assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.IMPORTS() ) ); + assertEquals( 0, x.getCardinality( prof.IMPORTS() ), "Cardinality should be 0" ); } }, new OntTestCase( "Ontology.backwardCompatibleWith", true, true, false ) { @@ -105,21 +95,21 @@ public void ontTest( OntModel m ) { Ontology z = m.createOntology( NS + "z" ); x.addBackwardCompatibleWith( y ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) ); - assertEquals( "x should be back comp with y", y, x.getBackwardCompatibleWith() ); + assertEquals( 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ), "Cardinality should be 1" ); + assertEquals( y, x.getBackwardCompatibleWith(), "x should be back comp with y" ); x.addBackwardCompatibleWith( z ); - assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) ); + assertEquals( 2, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ), "Cardinality should be 2" ); iteratorTest( x.listBackwardCompatibleWith(), new Object[] {y,z} ); x.setBackwardCompatibleWith( z ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) ); - assertEquals( "x should be back comp with z", z, x.getBackwardCompatibleWith() ); + assertEquals( 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ), "Cardinality should be 1" ); + assertEquals( z, x.getBackwardCompatibleWith(), "x should be back comp with z" ); x.removeBackwardCompatibleWith( y ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) ); + assertEquals( 1, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ), "Cardinality should be 1" ); x.removeBackwardCompatibleWith( z ); - assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ) ); + assertEquals( 0, x.getCardinality( prof.BACKWARD_COMPATIBLE_WITH() ), "Cardinality should be 0" ); } }, new OntTestCase( "Ontology.priorVersion", true, true, false ) { @@ -131,21 +121,21 @@ public void ontTest( OntModel m ) { Ontology z = m.createOntology( NS + "z" ); x.addPriorVersion( y ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.PRIOR_VERSION() ) ); - assertEquals( "x should have prior y", y, x.getPriorVersion() ); + assertEquals( 1, x.getCardinality( prof.PRIOR_VERSION() ), "Cardinality should be 1" ); + assertEquals( y, x.getPriorVersion(), "x should have prior y" ); x.addPriorVersion( z ); - assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.PRIOR_VERSION() ) ); + assertEquals( 2, x.getCardinality( prof.PRIOR_VERSION() ), "Cardinality should be 2" ); iteratorTest( x.listPriorVersion(), new Object[] {y,z} ); x.setPriorVersion( z ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.PRIOR_VERSION() ) ); - assertEquals( "x should have prior z", z, x.getPriorVersion() ); + assertEquals( 1, x.getCardinality( prof.PRIOR_VERSION() ), "Cardinality should be 1" ); + assertEquals( z, x.getPriorVersion(), "x should have prior z" ); x.removePriorVersion( y ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.PRIOR_VERSION() ) ); + assertEquals( 1, x.getCardinality( prof.PRIOR_VERSION() ), "Cardinality should be 1" ); x.removePriorVersion( z ); - assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.PRIOR_VERSION() ) ); + assertEquals( 0, x.getCardinality( prof.PRIOR_VERSION() ), "Cardinality should be 0" ); } }, new OntTestCase( "Ontology.incompatibleWith", true, true, false ) { @@ -157,21 +147,21 @@ public void ontTest( OntModel m ) { Ontology z = m.createOntology( NS + "z" ); x.addIncompatibleWith( y ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ) ); - assertEquals( "x should be in comp with y", y, x.getIncompatibleWith() ); + assertEquals( 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ), "Cardinality should be 1" ); + assertEquals( y, x.getIncompatibleWith(), "x should be in comp with y" ); x.addIncompatibleWith( z ); - assertEquals( "Cardinality should be 2", 2, x.getCardinality( prof.INCOMPATIBLE_WITH() ) ); + assertEquals( 2, x.getCardinality( prof.INCOMPATIBLE_WITH() ), "Cardinality should be 2" ); iteratorTest( x.listIncompatibleWith(), new Object[] {y,z} ); x.setIncompatibleWith( z ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ) ); - assertEquals( "x should be incomp with z", z, x.getIncompatibleWith() ); + assertEquals( 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ), "Cardinality should be 1" ); + assertEquals( z, x.getIncompatibleWith(), "x should be incomp with z" ); x.removeIncompatibleWith( y ); - assertEquals( "Cardinality should be 1", 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ) ); + assertEquals( 1, x.getCardinality( prof.INCOMPATIBLE_WITH() ), "Cardinality should be 1" ); x.removeIncompatibleWith( z ); - assertEquals( "Cardinality should be 0", 0, x.getCardinality( prof.INCOMPATIBLE_WITH() ) ); + assertEquals( 0, x.getCardinality( prof.INCOMPATIBLE_WITH() ), "Cardinality should be 0" ); } }, }; diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestProperty.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestProperty.java index eb9a66c967a..dbcae223458 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestProperty.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestProperty.java @@ -23,20 +23,19 @@ /////////////// package org.apache.jena.ontology.impl; - // Imports /////////////// import java.util.List; -import junit.framework.TestSuite; import org.apache.jena.ontology.*; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Property; -import org.apache.jena.reasoner.test.TestUtil; import org.apache.jena.util.FileManager; import org.apache.jena.vocabulary.RDF; +import static org.junit.jupiter.api.Assertions.*; +import org.apache.jena.test.JenaTestLib; /** *

@@ -44,32 +43,23 @@ *

*/ @SuppressWarnings("removal") -public class TestProperty - extends OntTestBase +public class TestProperty extends OntTestBase { + + static { JenaTestLib.setup(); } + // Constants ////////////////////////////////// // Static variables ////////////////////////////////// - - // Instance variables ////////////////////////////////// // Constructors ////////////////////////////////// - static public TestSuite suite() { - return new TestProperty( "TestProperty" ); - } - - public TestProperty( String name ) { - super( name ); - } - - // External signature methods ////////////////////////////////// @@ -85,25 +75,25 @@ public void ontTest( OntModel m ) { OntProperty r = m.createOntProperty( NS + "r" ); p.addSuperProperty( q ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.SUB_PROPERTY_OF() ) ); - assertEquals( "p have super-prop q", q, p.getSuperProperty() ); + assertEquals( 1, p.getCardinality( prof.SUB_PROPERTY_OF() ), "Cardinality should be 1" ); + assertEquals( q, p.getSuperProperty(), "p have super-prop q" ); p.addSuperProperty( r ); - assertEquals( "Cardinality should be 2", 2, p.getCardinality( prof.SUB_PROPERTY_OF() ) ); + assertEquals( 2, p.getCardinality( prof.SUB_PROPERTY_OF() ), "Cardinality should be 2" ); iteratorTest( p.listSuperProperties(), new Object[] {q, r} ); p.setSuperProperty( r ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.SUB_PROPERTY_OF() ) ); - assertEquals( "p shuold have super-prop r", r, p.getSuperProperty() ); + assertEquals( 1, p.getCardinality( prof.SUB_PROPERTY_OF() ), "Cardinality should be 1" ); + assertEquals( r, p.getSuperProperty(), "p shuold have super-prop r" ); p.removeSuperProperty( q ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.SUB_PROPERTY_OF() ) ); + assertEquals( 1, p.getCardinality( prof.SUB_PROPERTY_OF() ), "Cardinality should be 1" ); p.removeSuperProperty( r ); - assertEquals( "Cardinality should be 0", 0, p.getCardinality( prof.SUB_PROPERTY_OF() ) ); + assertEquals( 0, p.getCardinality( prof.SUB_PROPERTY_OF() ), "Cardinality should be 0" ); // for symmetry with listSuperClasses(), exclude the reflexive case List sp = p.listSuperProperties().toList(); - assertFalse( "super-properties should not include reflexive case", sp.contains( p ) ); + assertFalse( sp.contains( p ), "super-properties should not include reflexive case" ); } }, new OntTestCase( "OntProperty.sub-property", true, true, true ) { @@ -115,23 +105,23 @@ public void ontTest( OntModel m ) { OntProperty r = m.createOntProperty( NS + "r" ); p.addSubProperty( q ); - assertEquals( "Cardinality should be 1", 1, q.getCardinality( prof.SUB_PROPERTY_OF() ) ); - assertEquals( "p have sub-prop q", q, p.getSubProperty() ); + assertEquals( 1, q.getCardinality( prof.SUB_PROPERTY_OF() ), "Cardinality should be 1" ); + assertEquals( q, p.getSubProperty(), "p have sub-prop q" ); p.addSubProperty( r ); - assertEquals( "Cardinality should be 2", 2, q.getCardinality( prof.SUB_PROPERTY_OF() ) + r.getCardinality( prof.SUB_PROPERTY_OF() ) ); + assertEquals( 2, q.getCardinality( prof.SUB_PROPERTY_OF() ) + r.getCardinality( prof.SUB_PROPERTY_OF() ), "Cardinality should be 2" ); iteratorTest( p.listSubProperties(), new Object[] {q, r} ); iteratorTest( q.listSuperProperties(), new Object[] {p} ); iteratorTest( r.listSuperProperties(), new Object[] {p} ); p.setSubProperty( r ); - assertEquals( "Cardinality should be 1", 1, q.getCardinality( prof.SUB_PROPERTY_OF() ) + r.getCardinality( prof.SUB_PROPERTY_OF() ) ); - assertEquals( "p should have sub-prop r", r, p.getSubProperty() ); + assertEquals( 1, q.getCardinality( prof.SUB_PROPERTY_OF() ) + r.getCardinality( prof.SUB_PROPERTY_OF() ), "Cardinality should be 1" ); + assertEquals( r, p.getSubProperty(), "p should have sub-prop r" ); p.removeSubProperty( q ); - assertTrue( "Should have sub-prop r", p.hasSubProperty( r, false ) ); + assertTrue( p.hasSubProperty( r, false ), "Should have sub-prop r" ); p.removeSubProperty( r ); - assertTrue( "Should not have sub-prop r", !p.hasSubProperty( r, false ) ); + assertTrue( !p.hasSubProperty( r, false ), "Should not have sub-prop r" ); } }, new OntTestCase( "OntProperty.domain", true, true, true ) { @@ -143,21 +133,21 @@ public void ontTest( OntModel m ) { OntResource b = m.getResource( NS + "b" ).as( OntResource.class ); p.addDomain( a ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.DOMAIN() ) ); - assertEquals( "p have domain a", a, p.getDomain() ); + assertEquals( 1, p.getCardinality( prof.DOMAIN() ), "Cardinality should be 1" ); + assertEquals( a, p.getDomain(), "p have domain a" ); p.addDomain( b ); - assertEquals( "Cardinality should be 2", 2, p.getCardinality( prof.DOMAIN() ) ); + assertEquals( 2, p.getCardinality( prof.DOMAIN() ), "Cardinality should be 2" ); iteratorTest( p.listDomain(), new Object[] {a, b} ); p.setDomain( b ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.DOMAIN() ) ); - assertEquals( "p should have domain b", b, p.getDomain() ); + assertEquals( 1, p.getCardinality( prof.DOMAIN() ), "Cardinality should be 1" ); + assertEquals( b, p.getDomain(), "p should have domain b" ); p.removeDomain( a ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.DOMAIN() ) ); + assertEquals( 1, p.getCardinality( prof.DOMAIN() ), "Cardinality should be 1" ); p.removeDomain( b ); - assertEquals( "Cardinality should be 0", 0, p.getCardinality( prof.DOMAIN() ) ); + assertEquals( 0, p.getCardinality( prof.DOMAIN() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntProperty.range", true, true, true ) { @@ -169,21 +159,21 @@ public void ontTest( OntModel m ) { OntResource b = m.getResource( NS + "b" ).as( OntResource.class ); p.addRange( a ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.RANGE() ) ); - assertEquals( "p have range a", a, p.getRange() ); + assertEquals( 1, p.getCardinality( prof.RANGE() ), "Cardinality should be 1" ); + assertEquals( a, p.getRange(), "p have range a" ); p.addRange( b ); - assertEquals( "Cardinality should be 2", 2, p.getCardinality( prof.RANGE() ) ); + assertEquals( 2, p.getCardinality( prof.RANGE() ), "Cardinality should be 2" ); iteratorTest( p.listRange(), new Object[] {a, b} ); p.setRange( b ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.RANGE() ) ); - assertEquals( "p should have range b", b, p.getRange() ); + assertEquals( 1, p.getCardinality( prof.RANGE() ), "Cardinality should be 1" ); + assertEquals( b, p.getRange(), "p should have range b" ); p.removeRange( a ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.RANGE() ) ); + assertEquals( 1, p.getCardinality( prof.RANGE() ), "Cardinality should be 1" ); p.removeRange( b ); - assertEquals( "Cardinality should be 0", 0, p.getCardinality( prof.RANGE() ) ); + assertEquals( 0, p.getCardinality( prof.RANGE() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntProperty.equivalentProperty", true, true, false ) { @@ -195,21 +185,21 @@ public void ontTest( OntModel m ) { OntProperty r = m.createObjectProperty( NS + "r" ); p.addEquivalentProperty( q ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.EQUIVALENT_PROPERTY() ) ); - assertEquals( "p have equivalentProperty q", q, p.getEquivalentProperty() ); + assertEquals( 1, p.getCardinality( prof.EQUIVALENT_PROPERTY() ), "Cardinality should be 1" ); + assertEquals( q, p.getEquivalentProperty(), "p have equivalentProperty q" ); p.addEquivalentProperty( r ); - assertEquals( "Cardinality should be 2", 2, p.getCardinality( prof.EQUIVALENT_PROPERTY() ) ); + assertEquals( 2, p.getCardinality( prof.EQUIVALENT_PROPERTY() ), "Cardinality should be 2" ); iteratorTest( p.listEquivalentProperties(), new Object[] {q,r} ); p.setEquivalentProperty( r ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.EQUIVALENT_PROPERTY() ) ); - assertEquals( "p should have equivalentProperty r", r, p.getEquivalentProperty() ); + assertEquals( 1, p.getCardinality( prof.EQUIVALENT_PROPERTY() ), "Cardinality should be 1" ); + assertEquals( r, p.getEquivalentProperty(), "p should have equivalentProperty r" ); p.removeEquivalentProperty( q ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.EQUIVALENT_PROPERTY() ) ); + assertEquals( 1, p.getCardinality( prof.EQUIVALENT_PROPERTY() ), "Cardinality should be 1" ); p.removeEquivalentProperty( r ); - assertEquals( "Cardinality should be 0", 0, p.getCardinality( prof.EQUIVALENT_PROPERTY() ) ); + assertEquals( 0, p.getCardinality( prof.EQUIVALENT_PROPERTY() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntProperty.inverseOf", true, true, false ) { @@ -224,23 +214,23 @@ public void ontTest( OntModel m ) { assertEquals( null, p.getInverseOf() ); p.addInverseOf( q ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.INVERSE_OF() ) ); - assertEquals( "p should have inverse q", q, p.getInverseOf() ); - assertTrue( "inverse value should be an object property", p.getInverseOf() instanceof ObjectProperty ); - assertTrue( "inverse value should be an object property", q.getInverse() instanceof ObjectProperty ); + assertEquals( 1, p.getCardinality( prof.INVERSE_OF() ), "Cardinality should be 1" ); + assertEquals( q, p.getInverseOf(), "p should have inverse q" ); + assertTrue( p.getInverseOf() instanceof ObjectProperty, "inverse value should be an object property" ); + assertTrue( q.getInverse() instanceof ObjectProperty, "inverse value should be an object property" ); p.addInverseOf( r ); - assertEquals( "Cardinality should be 2", 2, p.getCardinality( prof.INVERSE_OF() ) ); + assertEquals( 2, p.getCardinality( prof.INVERSE_OF() ), "Cardinality should be 2" ); iteratorTest( p.listInverseOf(), new Object[] {q,r} ); p.setInverseOf( r ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.INVERSE_OF() ) ); - assertEquals( "p should have inverse r", r, p.getInverseOf() ); + assertEquals( 1, p.getCardinality( prof.INVERSE_OF() ), "Cardinality should be 1" ); + assertEquals( r, p.getInverseOf(), "p should have inverse r" ); p.removeInverseProperty( q ); - assertEquals( "Cardinality should be 1", 1, p.getCardinality( prof.INVERSE_OF() ) ); + assertEquals( 1, p.getCardinality( prof.INVERSE_OF() ), "Cardinality should be 1" ); p.removeInverseProperty( r ); - assertEquals( "Cardinality should be 0", 0, p.getCardinality( prof.INVERSE_OF() ) ); + assertEquals( 0, p.getCardinality( prof.INVERSE_OF() ), "Cardinality should be 0" ); } }, new OntTestCase( "OntProperty.subproperty.fromFile", true, true, true ) { @@ -267,7 +257,7 @@ public void ontTest( OntModel m ) { OntProperty p = m.getProperty( NS, "p" ).as( OntProperty.class ); OntClass A = m.getResource( NS + "ClassA").as( OntClass.class); - assertTrue( "p should have domain A", p.hasDomain( A ) ); + assertTrue( p.hasDomain( A ), "p should have domain A" ); } }, new OntTestCase( "OntProperty.range.fromFile", true, true, true ) { @@ -280,7 +270,7 @@ public void ontTest( OntModel m ) { OntProperty p = m.getProperty( NS, "p" ).as( OntProperty.class ); OntClass B = m.getResource( NS + "ClassB").as( OntClass.class); - assertTrue( "p should have domain B", p.hasRange( B ) ); + assertTrue( p.hasRange( B ), "p should have domain B" ); } }, new OntTestCase( "OntProperty.equivalentProeprty.fromFile", true, true, false ) { @@ -293,7 +283,7 @@ public void ontTest( OntModel m ) { OntProperty p = m.getProperty( NS, "p" ).as( OntProperty.class ); OntProperty r = m.getProperty( NS, "r" ).as( OntProperty.class ); - assertTrue( "p should have equiv prop r", p.hasEquivalentProperty( r ) ); + assertTrue( p.hasEquivalentProperty( r ), "p should have equiv prop r" ); } }, new OntTestCase( "OntProperty.inversePropertyOf.fromFile", true, true, false ) { @@ -306,7 +296,7 @@ public void ontTest( OntModel m ) { OntProperty p = m.getProperty( NS, "p" ).as( OntProperty.class ); OntProperty s = m.getProperty( NS, "s" ).as( OntProperty.class ); - assertTrue( "p should have inv prop s", p.isInverseOf( s ) ); + assertTrue( p.isInverseOf( s ), "p should have inv prop s" ); } }, @@ -316,13 +306,13 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntProperty p = m.createDatatypeProperty( NS + "p", true ); - assertTrue( "isFunctionalProperty not correct", p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); + assertTrue( p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); if (m_owlLang) { - assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); + assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, @@ -331,13 +321,13 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntProperty p = m.createObjectProperty( NS + "p", true ); - assertTrue( "isFunctionalProperty not correct", p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); + assertTrue( p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); if (m_owlLang) { - assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); + assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, @@ -346,13 +336,13 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntProperty p = m.createDatatypeProperty( NS + "p", false ); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); if (m_owlLang) { - assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); + assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, @@ -361,13 +351,13 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntProperty p = m.createObjectProperty( NS + "p", false ); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); if (m_owlLang) { - assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); + assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, @@ -376,13 +366,13 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntProperty p = m.createTransitiveProperty( NS + "p" ); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); // this should be true by entailment, but we have reasoning switched off - assertTrue( "isTransitiveProperty not correct", p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); // this should be true by entailment, but we have reasoning switched off + assertTrue( p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); if (m_owlLang) { - assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); + assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, @@ -391,13 +381,13 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntProperty p = m.createInverseFunctionalProperty( NS + "p" ); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); // this should be true by entailment, but we have reasoning switched off - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", p.isInverseFunctionalProperty() ); + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); // this should be true by entailment, but we have reasoning switched off + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); if (m_owlLang) { - assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); + assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, @@ -406,13 +396,13 @@ public void ontTest( OntModel m ) { public void ontTest( OntModel m ) { OntProperty p = m.createSymmetricProperty( NS + "p" ); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); // this should be true by entailment, but we have reasoning switched off - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); // this should be true by entailment, but we have reasoning switched off + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); if (m_owlLang) { - assertTrue( "isSymmetricProperty not correct", p.isSymmetricProperty() ); + assertTrue( p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, @@ -423,21 +413,21 @@ public void ontTest( OntModel m ) { pSimple.addProperty( RDF.type, RDF.Property ); OntProperty p = pSimple.as( OntProperty.class ); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); } + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } p = p.convertToFunctionalProperty(); - assertTrue( "isFunctionalProperty not correct", p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); } + assertTrue( p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, new OntTestCase( "OntProperty.convertToDatatypeProperty", true, true, false ) { @@ -447,21 +437,21 @@ public void ontTest( OntModel m ) { pSimple.addProperty( RDF.type, RDF.Property ); OntProperty p = pSimple.as( OntProperty.class ); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); } + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } p = p.convertToDatatypeProperty(); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); } + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, new OntTestCase( "OntProperty.convertToObjectProperty", true, true, false ) { @@ -471,21 +461,21 @@ public void ontTest( OntModel m ) { pSimple.addProperty( RDF.type, RDF.Property ); OntProperty p = pSimple.as( OntProperty.class ); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); } + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } p = p.convertToObjectProperty(); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); } + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, new OntTestCase( "OntProperty.convertToTransitiveProperty", true, true, false ) { @@ -495,21 +485,21 @@ public void ontTest( OntModel m ) { pSimple.addProperty( RDF.type, RDF.Property ); OntProperty p = pSimple.as( OntProperty.class ); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); } + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } p = p.convertToTransitiveProperty(); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); } + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, new OntTestCase( "OntProperty.convertToInverseFunctionalProperty", true, true, false ) { @@ -519,21 +509,21 @@ public void ontTest( OntModel m ) { pSimple.addProperty( RDF.type, RDF.Property ); OntProperty p = pSimple.as( OntProperty.class ); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); } + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } p = p.convertToInverseFunctionalProperty(); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); } + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, new OntTestCase( "OntProperty.convertToSymmetricProperty", true, true, false ) { @@ -543,21 +533,21 @@ public void ontTest( OntModel m ) { pSimple.addProperty( RDF.type, RDF.Property ); OntProperty p = pSimple.as( OntProperty.class ); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", !p.isSymmetricProperty() ); } + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( !p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } p = p.convertToSymmetricProperty(); - assertTrue( "isFunctionalProperty not correct", !p.isFunctionalProperty() ); - assertTrue( "isDatatypeProperty not correct", !p.isDatatypeProperty() ); - assertTrue( "isObjectProperty not correct", !p.isObjectProperty() ); - assertTrue( "isTransitiveProperty not correct", !p.isTransitiveProperty() ); - assertTrue( "isInverseFunctionalProperty not correct", !p.isInverseFunctionalProperty() ); - if (m_owlLang) {assertTrue( "isSymmetricProperty not correct", p.isSymmetricProperty() ); } + assertTrue( !p.isFunctionalProperty(), "isFunctionalProperty not correct" ); + assertTrue( !p.isDatatypeProperty(), "isDatatypeProperty not correct" ); + assertTrue( !p.isObjectProperty(), "isObjectProperty not correct" ); + assertTrue( !p.isTransitiveProperty(), "isTransitiveProperty not correct" ); + assertTrue( !p.isInverseFunctionalProperty(), "isInverseFunctionalProperty not correct" ); + if (m_owlLang) {assertTrue( p.isSymmetricProperty(), "isSymmetricProperty not correct" ); } } }, new OntTestCase( "ObjectProperty.inverse", true, true, false ) { @@ -567,12 +557,12 @@ public void ontTest( OntModel m ) { ObjectProperty q = m.createObjectProperty( NS + "q" ); ObjectProperty r = m.createObjectProperty( NS + "r" ); - assertFalse( "No inverse of p", p.hasInverse() ); + assertFalse( p.hasInverse(), "No inverse of p" ); assertEquals( null, p.getInverse() ); q.addInverseOf( p ); - assertTrue( "Inverse of p", p.hasInverse() ); - assertEquals( "inverse of p ", q, p.getInverse() ); + assertTrue( p.hasInverse(), "Inverse of p" ); + assertEquals( q, p.getInverse(), "inverse of p " ); r.addInverseOf( p ); iteratorTest( p.listInverse(), new Object[] {q,r} ); @@ -603,7 +593,7 @@ protected void ontTest( OntModel m ) { FileManager.getInternal().readModelInternal( m0, "file:testing/ontology/testImport9/a.ttl" ); OntProperty p0 = m0.getOntProperty( "http://incubator.apache.org/jena/2011/10/testont/b#propB" ); - TestUtil.assertIteratorLength( p0.listDomain(), 3 ); + OntTestUtil.assertIteratorLength( p0.listDomain(), 3 ); // repeat test - thus using previously cached model for import @@ -611,7 +601,7 @@ protected void ontTest( OntModel m ) { FileManager.getInternal().readModelInternal( m1, "file:testing/ontology/testImport9/a.ttl" ); OntProperty p1 = m1.getOntProperty( "http://incubator.apache.org/jena/2011/10/testont/b#propB" ); - TestUtil.assertIteratorLength( p1.listDomain(), 3 ); + OntTestUtil.assertIteratorLength( p1.listDomain(), 3 ); } } }; diff --git a/jena-core/src/test/java/org/apache/jena/ontology/makers/TS3_ModelMakers.java b/jena-core/src/test/java/org/apache/jena/ontology/makers/TS6_ModelMakers.java similarity index 74% rename from jena-core/src/test/java/org/apache/jena/ontology/makers/TS3_ModelMakers.java rename to jena-core/src/test/java/org/apache/jena/ontology/makers/TS6_ModelMakers.java index f7fff7be0b4..83de579b005 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/makers/TS3_ModelMakers.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/makers/TS6_ModelMakers.java @@ -21,12 +21,21 @@ package org.apache.jena.ontology.makers; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.junit.platform.suite.api.BeforeSuite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; -@RunWith(Suite.class) -@Suite.SuiteClasses({ +import org.apache.jena.test.JenaTestLib; + +@Suite +@SelectClasses({ TestGraphMaker.class, TestModelMakerImpl.class }) -public class TS3_ModelMakers {} + +public class TS6_ModelMakers { + @BeforeSuite + public static void beforeSuite() { + JenaTestLib.setup(); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/ontology/makers/TestGraphMaker.java b/jena-core/src/test/java/org/apache/jena/ontology/makers/TestGraphMaker.java index e09295f2b6f..8b6e6c7ab93 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/makers/TestGraphMaker.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/makers/TestGraphMaker.java @@ -21,8 +21,14 @@ package org.apache.jena.ontology.makers; +import static org.junit.jupiter.api.Assertions.*; + import java.util.Set; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import org.apache.jena.atlas.iterator.Iter; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphTestLib; @@ -32,14 +38,11 @@ import org.apache.jena.ontology.models.SimpleGraphMaker; import org.apache.jena.shared.AlreadyExistsException; import org.apache.jena.shared.DoesNotExistException; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.test.JenaTestLib; -public class TestGraphMaker extends JenaTestBase { +public class TestGraphMaker { - public TestGraphMaker(String name) { - super(name); - } + static { JenaTestLib.setup(); } public GraphMaker getGraphMaker() { return new SimpleGraphMaker(); @@ -47,12 +50,12 @@ public GraphMaker getGraphMaker() { private GraphMaker gf; - @Override + @BeforeEach public void setUp() { gf = getGraphMaker(); } - @Override + @AfterEach public void tearDown() { gf.close(); } @@ -61,17 +64,20 @@ public void tearDown() { * A trivial test that getGraph delivers a proper graph, not cheating with null, * and that getGraph() "always" delivers the same Graph. */ + @Test public void testGetGraph() { Graph g1 = gf.getGraph(); - assertFalse("should deliver a Graph", g1 == null); + assertFalse(g1 == null, "should deliver a Graph"); assertSame(g1, gf.getGraph()); g1.close(); } + @Test public void testCreateGraph() { JenaTestLib.assertDiffer("each created graph must differ", gf.createGraph(), gf.createGraph()); } + @Test public void testAnyName() { gf.createGraph("plain").close(); gf.createGraph("with.dot").close(); @@ -81,42 +87,44 @@ public void testAnyName() { /** * Test that we can't create a graph with the same name twice. */ + @Test public void testCannotCreateTwice() { String name = jName("bonsai"); gf.createGraph(name, true); - try { - gf.createGraph(name, true); - fail("should not be able to create " + name + " twice"); - } catch (AlreadyExistsException e) {} + assertThrows(AlreadyExistsException.class, + () -> gf.createGraph(name, true), + "should not be able to create " + name + " twice"); } private String jName(String name) { return "jena-test-AbstractTestGraphMaker-" + name; } + @Test public void testCanCreateTwice() { String name = jName("bridge"); Graph g1 = gf.createGraph(name, true); Graph g2 = gf.createGraph(name, false); - assertTrue("graphs should be the same", sameGraph(g1, g2)); + assertTrue(sameGraph(g1, g2), "graphs should be the same"); Graph g3 = gf.createGraph(name); - assertTrue("graphs should be the same", sameGraph(g1, g3)); + assertTrue(sameGraph(g1, g3), "graphs should be the same"); } /** * Test that we cannot open a graph that does not exist. */ + @Test public void testCannotOpenUncreated() { String name = jName("noSuchGraph"); - try { - gf.openGraph(name, true); - fail(name + " should not exist"); - } catch (DoesNotExistException e) {} + assertThrows(DoesNotExistException.class, + () -> gf.openGraph(name, true), + name + " should not exist"); } /** * Test that we *can* open a graph that hasn't been created */ + @Test public void testCanOpenUncreated() { String name = jName("willBeCreated"); Graph g1 = gf.openGraph(name); @@ -128,14 +136,14 @@ public void testCanOpenUncreated() { * Utility - test that a graph with the given name exists. */ private void testExists(String name) { - assertTrue(name + " should exist", gf.hasGraph(name)); + assertTrue(gf.hasGraph(name), name + " should exist"); } /** * Utility - test that no graph with the given name exists. */ private void testDoesNotExist(String name) { - assertFalse(name + " should exist", gf.hasGraph(name)); + assertFalse(gf.hasGraph(name), name + " should exist"); } /** @@ -143,14 +151,15 @@ private void testDoesNotExist(String name) { * graphs are "the same" here: we have a temporary work-around but it is not * sound. */ + @Test public void testCanFindCreatedGraph() { String alpha = jName("alpha"), beta = jName("beta"); Graph g1 = gf.createGraph(alpha, true); Graph h1 = gf.createGraph(beta, true); Graph g2 = gf.openGraph(alpha, true); Graph h2 = gf.openGraph(beta, true); - assertTrue("should find alpha", sameGraph(g1, g2)); - assertTrue("should find beta", sameGraph(h1, h2)); + assertTrue(sameGraph(g1, g2), "should find alpha"); + assertTrue(sameGraph(h1, h2), "should find beta"); } /** @@ -169,6 +178,7 @@ private boolean sameGraph(Graph g1, Graph g2) { * Test that we can remove a graph from the factory without disturbing another * graph's binding. */ + @Test public void testCanRemoveGraph() { String alpha = jName("bingo"), beta = jName("brillo"); gf.createGraph(alpha, true); @@ -180,30 +190,32 @@ public void testCanRemoveGraph() { testDoesNotExist(alpha); } + @Test public void testHasnt() { - assertFalse("no such graph", gf.hasGraph("john")); - assertFalse("no such graph", gf.hasGraph("paul")); - assertFalse("no such graph", gf.hasGraph("george")); + assertFalse(gf.hasGraph("john"), "no such graph"); + assertFalse(gf.hasGraph("paul"), "no such graph"); + assertFalse(gf.hasGraph("george"), "no such graph"); /* */ gf.createGraph("john", true); - assertTrue("john now exists", gf.hasGraph("john")); - assertFalse("no such graph", gf.hasGraph("paul")); - assertFalse("no such graph", gf.hasGraph("george")); + assertTrue(gf.hasGraph("john"), "john now exists"); + assertFalse(gf.hasGraph("paul"), "no such graph"); + assertFalse(gf.hasGraph("george"), "no such graph"); /* */ gf.createGraph("paul", true); - assertTrue("john still exists", gf.hasGraph("john")); - assertTrue("paul now exists", gf.hasGraph("paul")); - assertFalse("no such graph", gf.hasGraph("george")); + assertTrue(gf.hasGraph("john"), "john still exists"); + assertTrue(gf.hasGraph("paul"), "paul now exists"); + assertFalse(gf.hasGraph("george"), "no such graph"); /* */ gf.removeGraph("john"); - assertFalse("john has been removed", gf.hasGraph("john")); - assertTrue("paul still exists", gf.hasGraph("paul")); - assertFalse("no such graph", gf.hasGraph("george")); + assertFalse(gf.hasGraph("john"), "john has been removed"); + assertTrue(gf.hasGraph("paul"), "paul still exists"); + assertFalse(gf.hasGraph("george"), "no such graph"); } // Up to Jena5, the graph created did open/close counting. // But only some graph implements provided this. + @Test public void testCarefulClose() { Graph x = gf.createGraph("x"); Graph y = gf.openGraph("x"); @@ -216,6 +228,7 @@ public void testCarefulClose() { /** * Test that a maker with no graphs lists no names. */ + @Test public void testListNoGraphs() { Set s = gf.listGraphs().toSet(); if ( s.size() > 0 ) @@ -228,6 +241,7 @@ public void testListNoGraphs() { * the spelling that goes in is the one that comes out [should really be in a * separate test]. */ + @Test public void testListThreeGraphs() { String x = "x", y = "y/sub", z = "z:boo"; Graph X = gf.createGraph(x); @@ -244,6 +258,7 @@ public void testListThreeGraphs() { * Test that a maker with some things put in and then some removed gets the right * things listed. */ + @Test public void testListAfterDelete() { String x = "x_y", y = "y//zub", z = "a:b/c"; Graph X = gf.createGraph(x); diff --git a/jena-core/src/test/java/org/apache/jena/ontology/makers/TestModelMakerImpl.java b/jena-core/src/test/java/org/apache/jena/ontology/makers/TestModelMakerImpl.java index 6cadb9c282a..76bc9ea3cf0 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/makers/TestModelMakerImpl.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/makers/TestModelMakerImpl.java @@ -21,10 +21,14 @@ package org.apache.jena.ontology.makers; +import static org.junit.jupiter.api.Assertions.*; + import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphTestLib; import org.apache.jena.graph.Node; @@ -35,13 +39,14 @@ import org.apache.jena.test.JenaTestLib; import org.apache.jena.util.iterator.ExtendedIterator; import org.apache.jena.util.iterator.NullIterator; -import org.junit.Assert; /** * Test ModelMakerImpl using a mock GraphMaker. */ -public class TestModelMakerImpl extends TestCase +public class TestModelMakerImpl { + static { JenaTestLib.setup(); } + static class MockGraphMaker implements GraphMaker { List history = new ArrayList<>(); @@ -150,14 +155,9 @@ public void removeGraph( final String name ) private Graph graph; private GraphMaker graphMaker; - public TestModelMakerImpl( final String name ) - { - super(name); - } - private void checkHistory( final List expected ) { - Assert.assertEquals(expected, history()); + assertEquals(expected, history()); } private List history() @@ -165,7 +165,7 @@ private List history() return ((MockGraphMaker) maker.getGraphMaker()).history; } - @Override + @BeforeEach public void setUp() { graph = GraphTestLib.graphWith(""); @@ -173,77 +173,89 @@ public void setUp() maker = new ModelMakerImpl(graphMaker); } + @Test public void testClose() { maker.close(); checkHistory(JenaTestLib.listOfOne("close()")); } + @Test public void testCreateDefaultModel() { maker.createDefaultModel(); checkHistory(JenaTestLib.listOfOne("get()")); } + @Test public void testCreateFalse() { final Model m = maker.createModel("leaf", false); checkHistory(JenaTestLib.listOfOne("create(leaf,false)")); - Assert.assertTrue(m.getGraph() == graph); + assertTrue(m.getGraph() == graph); } + @Test public void testCreateFreshModel() { maker.createFreshModel(); checkHistory(JenaTestLib.listOfOne("create()")); } + @Test public void testCreateNamed() { final Model m = maker.createModel("petal"); checkHistory(JenaTestLib.listOfOne("create(petal,false)")); - Assert.assertTrue(m.getGraph() == graph); + assertTrue(m.getGraph() == graph); } + @Test public void testCreateTrue() { final Model m = maker.createModel("stem", true); checkHistory(JenaTestLib.listOfOne("create(stem,true)")); - Assert.assertTrue(m.getGraph() == graph); + assertTrue(m.getGraph() == graph); } + @Test public void testGetGraphMaker() { - Assert.assertTrue(maker.getGraphMaker() == graphMaker); + assertTrue(maker.getGraphMaker() == graphMaker); } + @Test public void testListGraphs() { maker.listModels().close(); checkHistory(JenaTestLib.listOfOne("listModels()")); } + @Test public void testOpen() { final Model m = maker.openModel("trunk"); checkHistory(JenaTestLib.listOfOne("open(trunk,false)")); - Assert.assertTrue(m.getGraph() == graph); + assertTrue(m.getGraph() == graph); } + @Test public void testOpenFalse() { final Model m = maker.openModel("branch", false); checkHistory(JenaTestLib.listOfOne("open(branch,false)")); - Assert.assertTrue(m.getGraph() == graph); + assertTrue(m.getGraph() == graph); } + @Test public void testOpenTrue() { final Model m = maker.openModel("bark", true); checkHistory(JenaTestLib.listOfOne("open(bark,true)")); - Assert.assertTrue(m.getGraph() == graph); + assertTrue(m.getGraph() == graph); } + @Test public void testRemove() { maker.removeModel("London"); diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil_JU6.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil_JU6.java new file mode 100644 index 00000000000..db3b6a35cfd --- /dev/null +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil_JU6.java @@ -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 + * + * https://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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.apache.jena.reasoner.test; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Iterator; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.Statement; + +/** + * Collection of utilities to assist with unit testing. + *

+ * JUnit6 counterpart of the {@code assertIterator*} methods of {@link TestUtil}. + * The {@code junit.framework.TestCase} argument of the originals has been + * dropped: it served only to label failure messages and to name the logger, + * both of which JUnit6 reports for itself. + */ +public class TestUtil_JU6 { + + private static final Logger LOG = LoggerFactory.getLogger( TestUtil_JU6.class ); + + /** + * Helper method to test an iterator against a list of objects - order independent + * @param it The iterator to test + * @param vals The expected values of the iterator + */ + public static void assertIteratorValues(Iterator it, Object[] vals) { + assertIteratorValues( it, vals, 0 ); + } + + /** + * Helper method to test an iterator against a list of objects - order independent, and + * can optionally check the count of anonymous resources. This allows us to test a + * iterator of resource values which includes both URI nodes and bNodes. + * @param it The iterator to test + * @param vals The expected values of the iterator + * @param countAnon If non zero, count the number of anonymous resources returned by it, + * and don't check these resources against the expected vals. + */ + public static void assertIteratorValues(Iterator it, Object[] vals, int countAnon ) { + boolean[] found = new boolean[vals.length]; + int anonFound = 0; + + for (int i = 0; i < vals.length; i++) found[i] = false; + + while (it.hasNext()) { + Object n = it.next(); + boolean gotit = false; + + // do bNodes separately + if (countAnon > 0 && isAnonValue( n )) { + anonFound++; + continue; + } + + for (int i = 0; i < vals.length; i++) { + if (n.equals(vals[i])) { + gotit = true; + found[i] = true; + } + } + if (!gotit) { + LOG.debug( "found unexpected iterator value: " + n); + } + assertTrue( gotit, "found unexpected iterator value: " + n); + } + + // check that no expected values were unfound + for (int i = 0; i < vals.length; i++) { + if (!found[i]) { + LOG.debug( "failed to find expected iterator value: " + vals[i]); + } + assertTrue( found[i], "failed to find expected iterator value: " + vals[i]); + } + + // check we got the right no. of anons + assertEquals( countAnon, anonFound, "iterator test did not find the right number of anon. nodes" ); + } + + /** + * Check the length of an iterator. + */ + public static void assertIteratorLength(Iterator it, int expectedLength) { + int length = 0; + while (it.hasNext()) { + it.next(); + length++; + } + assertEquals(expectedLength, length); + } + + /** + * For the purposes of counting, a value is anonymous if (a) it is an anonymous resource, + * or (b) it is a statement with a bNode subject or (c) it is a statement with a bNode + * object. This is because we cannot check bNode identity against fixed expected data values. + * @param n A value + * @return True if n is anonymous + */ + protected static boolean isAnonValue( Object n ) { + return ((n instanceof Resource) && ((Resource) n).isAnon()) || + ((n instanceof Statement) && ((Statement) n).getSubject().isAnon()) || + ((n instanceof Statement) && isAnonValue( ((Statement) n).getObject() )); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java index ec17a00e806..b323842a67d 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java @@ -73,8 +73,8 @@ static public TestSuite suite() { addTest(ts, "Reasoners", adaptJUnit4(org.apache.jena.reasoner.test.TS3_reasoners.class)); addTest(ts, "RuleReasoners", adaptJUnit4(org.apache.jena.reasoner.rulesys.TS3_RuleReasoners.class)); - addTest(ts, "Ontology ModelMaker", adaptJUnit4(org.apache.jena.ontology.makers.TS3_ModelMakers.class)); - addTest(ts, "Ontology", adaptJUnit4(org.apache.jena.ontology.impl.TS3_ont.class)); +//JU6 addTest(ts, "Ontology ModelMaker", adaptJUnit4(org.apache.jena.ontology.makers.TS3_ModelMakers.class)); +//JU6 addTest(ts, "Ontology", adaptJUnit4(org.apache.jena.ontology.impl.TS3_ont.class)); // Local TTL parser for tests - not fully compliant. //JU6 addTest(ts, "Turtle", adaptJUnit4(org.apache.jena.ttl_test.test_turtle.TS_TestTurtle.class)); diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java index 408810bcf58..864446eae02 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java @@ -31,6 +31,8 @@ import org.apache.jena.langtagx.TS6_LangTagX; import org.apache.jena.mem.TS6_GraphMem; import org.apache.jena.memvalue.TS6_GraphMemValue; +import org.apache.jena.ontology.impl.TS6_ont; +import org.apache.jena.ontology.makers.TS6_ModelMakers; import org.apache.jena.rdfxml.xmloutput.TS6_xmloutput; import org.apache.jena.shared.TS6_SharedPackage; import org.apache.jena.util.TS6_coreutil; @@ -58,6 +60,9 @@ TS6_Vocabularies.class, TS6_SharedPackage.class, + TS6_ModelMakers.class, + TS6_ont.class, + TS6_TestTurtle.class, }) From f3e81819c1a920ce5c57b79f3fc1a29387567cd5 Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Thu, 3 Sep 2026 19:28:06 +0100 Subject: [PATCH 02/12] Remove JenaTestBase in jena-core --- .../jena/assembler/AssemblerTestBase.java | 4 +- .../org/apache/jena/enhanced/TS3_enh.java | 4 +- .../apache/jena/graph/AbstractTestGraph.java | 4 +- .../apache/jena/graph/TestCoreGraphUtil.java | 3 +- .../org/apache/jena/graph/TestFactory.java | 3 +- .../apache/jena/graph/TestFindLiterals.java | 4 +- .../java/org/apache/jena/graph/TestGraph.java | 4 +- .../jena/graph/TestGraphBaseToString.java | 4 +- .../apache/jena/graph/TestGraphEvents.java | 4 +- .../graph/TestGraphMatchWithInference.java | 3 +- .../jena/graph/TestGraphPrefixMapping.java | 4 +- .../apache/jena/graph/TestLiteralLabels.java | 4 +- .../java/org/apache/jena/graph/TestNode.java | 4 +- .../jena/graph/TestRegisterGraphListener.java | 4 +- .../org/apache/jena/graph/TestReifier.java | 4 +- .../org/apache/jena/graph/TestTriple.java | 4 +- .../apache/jena/graph/TestTripleField.java | 4 +- .../compose/AbstractTestPrefixMapping.java | 4 +- .../graph/compose/TestMultiUnionReifier.java | 4 +- .../org/apache/jena/rdf/model/TestAnonID.java | 4 +- .../jena/rdf/model/TestDefaultModel.java | 4 +- .../jena/rdf/model/TestRDFWriterMap.java | 4 +- .../jena/rdf/model/helpers/ModelHelper.java | 6 +-- .../rulesys/test/TestConfigVocabulary.java | 4 +- .../test/TestRestrictionsDontNeedTyping.java | 4 +- .../reasoner/rulesys/test/TestSetRules.java | 4 +- .../jena/reasoner/test/TestCurrentRDFWG.java | 3 +- .../reasoner/test/TestInfPrefixMapping.java | 4 +- .../jena/reasoner/test/TestRDFSReasoners.java | 3 +- .../org/apache/jena/test/JenaTestBase.java | 38 ------------------- 30 files changed, 54 insertions(+), 97 deletions(-) delete mode 100644 jena-core/src/test/java/org/apache/jena/test/JenaTestBase.java diff --git a/jena-core/src/test/java/org/apache/jena/assembler/AssemblerTestBase.java b/jena-core/src/test/java/org/apache/jena/assembler/AssemblerTestBase.java index b6986ea6751..20e531d19ce 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/AssemblerTestBase.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/AssemblerTestBase.java @@ -21,6 +21,7 @@ package org.apache.jena.assembler; +import junit.framework.TestCase; import org.apache.jena.assembler.assemblers.AssemblerBase; import org.apache.jena.assembler.exceptions.CannotConstructException; import org.apache.jena.rdf.model.Model; @@ -29,7 +30,6 @@ import org.apache.jena.rdf.model.Resource; import org.apache.jena.shared.BrokenException; import org.apache.jena.shared.PrefixMapping; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.vocabulary.LocationMappingVocab; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDFS; @@ -40,7 +40,7 @@ * in subclasses to control the parser that is used to construct models and the * prefixes added to the model (these features added for Eyeball). */ -public class AssemblerTestBase extends JenaTestBase { +public class AssemblerTestBase extends TestCase { protected Class getAssemblerClass() { throw new BrokenException("this class must define getAssemblerClass"); diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TS3_enh.java b/jena-core/src/test/java/org/apache/jena/enhanced/TS3_enh.java index d968c0d9fd8..fa31bd2c8be 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TS3_enh.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/TS3_enh.java @@ -27,12 +27,12 @@ package org.apache.jena.enhanced; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.graph.*; import org.apache.jena.junit.NodeCreateUtils; import org.apache.jena.rdf.model.*; import org.apache.jena.shared.JenaException; -import org.apache.jena.test.JenaTestBase; /** * These tests give a small version of a model-like interface @@ -52,7 +52,7 @@ *These tests only test EnhNode polymorphism and not EnhGraph polymorphism. *EnhGraph polymorphism currently will not work. */ -public class TS3_enh extends JenaTestBase { +public class TS3_enh extends TestCase { static final private Personality split = new Personality<>(); diff --git a/jena-core/src/test/java/org/apache/jena/graph/AbstractTestGraph.java b/jena-core/src/test/java/org/apache/jena/graph/AbstractTestGraph.java index d9d55e15d2e..3fcb6600a08 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/AbstractTestGraph.java +++ b/jena-core/src/test/java/org/apache/jena/graph/AbstractTestGraph.java @@ -24,13 +24,13 @@ import java.io.InputStream; import java.util.*; +import junit.framework.TestCase; import org.apache.jena.junit.NodeCreateUtils; import org.apache.jena.memvalue.TrackingTripleIterator; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.impl.ReifierStd; import org.apache.jena.shared.JenaException; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.test.JenaTestLib; import org.apache.jena.util.CollectionFactory; import org.apache.jena.util.iterator.ClosableIterator; @@ -41,7 +41,7 @@ * be a Graph. The abstract method getGraph must be overridden in subclasses to * deliver a Graph of interest. */ -public abstract class AbstractTestGraph extends JenaTestBase { +public abstract class AbstractTestGraph extends TestCase { public AbstractTestGraph(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestCoreGraphUtil.java b/jena-core/src/test/java/org/apache/jena/graph/TestCoreGraphUtil.java index 76c3d947fe7..d31aed767f7 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestCoreGraphUtil.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestCoreGraphUtil.java @@ -23,10 +23,9 @@ import junit.framework.*; import org.apache.jena.graph.impl.*; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.util.iterator.*; -public class TestCoreGraphUtil extends JenaTestBase +public class TestCoreGraphUtil extends TestCase { public TestCoreGraphUtil(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestFactory.java b/jena-core/src/test/java/org/apache/jena/graph/TestFactory.java index 0501865e83f..077a99b9049 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestFactory.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestFactory.java @@ -22,9 +22,8 @@ package org.apache.jena.graph; import junit.framework.*; -import org.apache.jena.test.JenaTestBase; -public class TestFactory extends JenaTestBase { +public class TestFactory extends TestCase { public TestFactory(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestFindLiterals.java b/jena-core/src/test/java/org/apache/jena/graph/TestFindLiterals.java index 51ba8fb0da2..2d2b2001dba 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestFindLiterals.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestFindLiterals.java @@ -23,13 +23,13 @@ import java.util.Set; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.atlas.iterator.Iter; import org.apache.jena.graph.impl.LiteralLabelFactory; import org.apache.jena.junit.NodeCreateUtils; -import org.apache.jena.test.JenaTestBase; -public class TestFindLiterals extends JenaTestBase { +public class TestFindLiterals extends TestCase { public TestFindLiterals(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraph.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraph.java index b17e2540d8e..16bbccdd272 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraph.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraph.java @@ -27,16 +27,16 @@ */ import junit.framework.Test; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.graph.impl.WrappedGraph; import org.apache.jena.mem.GraphMemFast; import org.apache.jena.mem.GraphMemLegacy; import org.apache.jena.mem.GraphMemRoaring; import org.apache.jena.memvalue.GraphMemValue; -import org.apache.jena.test.JenaTestBase; @SuppressWarnings("deprecation") -public class TestGraph extends JenaTestBase { +public class TestGraph extends TestCase { public TestGraph(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphBaseToString.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphBaseToString.java index fb5e3c2bdad..dce640669e8 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphBaseToString.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphBaseToString.java @@ -26,16 +26,16 @@ import java.util.*; +import junit.framework.TestCase; import org.apache.jena.graph.impl.GraphBase; import org.apache.jena.junit.NodeCreateUtils; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.util.iterator.*; /** * Tests for the revisions to GraphBase.toString() to see that it's compact, ie * outputs no more than LIMIT triples. */ -public class TestGraphBaseToString extends JenaTestBase { +public class TestGraphBaseToString extends TestCase { private static final class LittleGraphBase extends GraphBase { Set triples = new HashSet<>(); diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphEvents.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphEvents.java index ea860a46f6b..fbdb1b3294d 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphEvents.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphEvents.java @@ -21,10 +21,10 @@ package org.apache.jena.graph; +import junit.framework.TestCase; import org.apache.jena.junit.NodeCreateUtils; -import org.apache.jena.test.JenaTestBase; -public class TestGraphEvents extends JenaTestBase { +public class TestGraphEvents extends TestCase { public TestGraphEvents(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphMatchWithInference.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphMatchWithInference.java index 34c641bd798..891cca4c609 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphMatchWithInference.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphMatchWithInference.java @@ -23,13 +23,12 @@ import junit.framework.*; import org.apache.jena.rdf.model.*; -import org.apache.jena.test.JenaTestBase; /** * Test that an inferred graph and an identical concrete graph compare as equal. */ -public class TestGraphMatchWithInference extends JenaTestBase { +public class TestGraphMatchWithInference extends TestCase { public TestGraphMatchWithInference(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphPrefixMapping.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphPrefixMapping.java index b0273af2f97..328f7ca8543 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphPrefixMapping.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphPrefixMapping.java @@ -21,12 +21,12 @@ package org.apache.jena.graph; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.graph.compose.AbstractTestPrefixMapping; import org.apache.jena.shared.PrefixMapping; -import org.apache.jena.test.JenaTestBase; -public class TestGraphPrefixMapping extends JenaTestBase { +public class TestGraphPrefixMapping extends TestCase { public TestGraphPrefixMapping(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabels.java b/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabels.java index d2b68822731..5e062e43a40 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabels.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabels.java @@ -22,15 +22,15 @@ package org.apache.jena.graph; import junit.framework.Test; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.datatypes.BaseDatatype; import org.apache.jena.datatypes.RDFDatatype; import org.apache.jena.graph.impl.LiteralLabel; import org.apache.jena.graph.impl.LiteralLabelFactory; -import org.apache.jena.test.JenaTestBase; // See also TestLiteralLabelSameValueAs, TestTypedLiterals -public class TestLiteralLabels extends JenaTestBase { +public class TestLiteralLabels extends TestCase { public TestLiteralLabels(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestNode.java b/jena-core/src/test/java/org/apache/jena/graph/TestNode.java index b4b1d9e0606..f7d6779f189 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestNode.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestNode.java @@ -21,6 +21,7 @@ package org.apache.jena.graph; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.atlas.lib.Creator; import org.apache.jena.datatypes.RDFDatatype; @@ -31,7 +32,6 @@ import org.apache.jena.junit.NodeCreateUtils; import org.apache.jena.shared.JenaException; import org.apache.jena.shared.PrefixMapping; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.test.JenaTestLib; import org.apache.jena.util.SplitIRI; import org.apache.jena.vocabulary.DC; @@ -44,7 +44,7 @@ * Exercise nodes. Make sure that the different node types do not overlap and that * the test predicates work properly on the different node kinds. */ -public class TestNode extends JenaTestBase { +public class TestNode extends TestCase { public TestNode(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestRegisterGraphListener.java b/jena-core/src/test/java/org/apache/jena/graph/TestRegisterGraphListener.java index 9f45d2953d7..aa60a6304f3 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestRegisterGraphListener.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestRegisterGraphListener.java @@ -24,13 +24,13 @@ import java.util.Iterator; import java.util.List; -import org.apache.jena.test.JenaTestBase; +import junit.framework.TestCase; /** * These tests are for listeners that add or delete other listeners. It motivates the * use of, e.g. CopyOnWriteArrayList for storing listeners. */ -public class TestRegisterGraphListener extends JenaTestBase { +public class TestRegisterGraphListener extends TestCase { private ComeAndGoListener all[]; private Graph graph; diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestReifier.java b/jena-core/src/test/java/org/apache/jena/graph/TestReifier.java index 49b896370ef..3d17fe03028 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestReifier.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestReifier.java @@ -23,6 +23,7 @@ import java.lang.reflect.Constructor; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.atlas.iterator.Iter; import org.apache.jena.junit.NodeCreateUtils; @@ -31,7 +32,6 @@ import org.apache.jena.shared.AlreadyReifiedException; import org.apache.jena.shared.CannotReifyException; import org.apache.jena.shared.JenaException; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.test.JenaTestLib; import org.apache.jena.vocabulary.RDF; @@ -39,7 +39,7 @@ * This class tests the reifiers of ordinary graphs. Old test suite - kept to ensure * compatibility for the one and only Standard mode */ -public class TestReifier extends JenaTestBase { +public class TestReifier extends TestCase { protected final Class graphClass; public TestReifier(String name) { diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestTriple.java b/jena-core/src/test/java/org/apache/jena/graph/TestTriple.java index 59a29c9f61c..1ac3d42dfa4 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestTriple.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestTriple.java @@ -23,16 +23,16 @@ import java.util.function.Function; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.graph.impl.LiteralLabel; import org.apache.jena.graph.impl.LiteralLabelFactory; import org.apache.jena.junit.NodeCreateUtils; import org.apache.jena.shared.PrefixMapping; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.test.JenaTestLib; -public class TestTriple extends JenaTestBase { +public class TestTriple extends TestCase { public TestTriple(String name) { super(name); diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestTripleField.java b/jena-core/src/test/java/org/apache/jena/graph/TestTripleField.java index cbd8a83f570..678ac316fcf 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestTripleField.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestTripleField.java @@ -21,12 +21,12 @@ package org.apache.jena.graph; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.graph.Triple.*; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.test.JenaTestLib; -public class TestTripleField extends JenaTestBase { +public class TestTripleField extends TestCase { public TestTripleField(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping.java b/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping.java index eaf0927ad34..32d874b0612 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping.java @@ -25,8 +25,8 @@ import java.util.List; import java.util.Map; +import junit.framework.TestCase; import org.apache.jena.shared.PrefixMapping; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.test.JenaTestLib; /** @@ -34,7 +34,7 @@ * prefixMapping to be tested. */ -public abstract class AbstractTestPrefixMapping extends JenaTestBase { +public abstract class AbstractTestPrefixMapping extends TestCase { public AbstractTestPrefixMapping(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnionReifier.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnionReifier.java index 01219276a33..69073fce778 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnionReifier.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnionReifier.java @@ -21,16 +21,16 @@ package org.apache.jena.graph.compose; +import junit.framework.TestCase; import org.apache.jena.graph.*; import org.apache.jena.junit.NodeCreateUtils; import org.apache.jena.rdf.model.impl.ReifierStd; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.util.iterator.ExtendedIterator; /** Test the reifier for multi-unions. */ -public class TestMultiUnionReifier extends JenaTestBase { +public class TestMultiUnionReifier extends TestCase { public TestMultiUnionReifier(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestAnonID.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestAnonID.java index 16cbf2271de..bd75ad08d17 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestAnonID.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestAnonID.java @@ -22,17 +22,17 @@ package org.apache.jena.rdf.model; import org.apache.jena.shared.impl.JenaParameters; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.test.JenaTestLib; import org.junit.Assert; +import junit.framework.TestCase; import junit.framework.TestSuite; /** * Test for anonID generation. (Originally test for the debugging hack that switches * off anonID generation.) */ -public class TestAnonID extends JenaTestBase { +public class TestAnonID extends TestCase { /** * Boilerplate for junit. This is its own test suite diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel.java index 85034fb3e6a..e24b578dd5d 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel.java @@ -21,6 +21,7 @@ package org.apache.jena.rdf.model; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.graph.GraphTestLib; import org.apache.jena.graph.Node; @@ -28,10 +29,9 @@ import org.apache.jena.junit.NodeCreateUtils; import org.apache.jena.rdf.model.impl.ModelCom; import org.apache.jena.shared.PropertyNotFoundException; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.test.JenaTestLib; -public class TestDefaultModel extends JenaTestBase { +public class TestDefaultModel extends TestCase { public TestDefaultModel(String name) { super(name); diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFWriterMap.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFWriterMap.java index 73bae7f6e3f..8d0d1a69142 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFWriterMap.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFWriterMap.java @@ -24,17 +24,17 @@ import java.util.HashMap; import java.util.Map; +import junit.framework.TestCase; import org.apache.jena.Jena; import org.apache.jena.rdf.model.impl.NTripleWriter; import org.apache.jena.rdfxml.xmloutput.impl.RDFXML_Abbrev; import org.apache.jena.rdfxml.xmloutput.impl.RDFXML_Basic; import org.apache.jena.shared.JenaException; import org.apache.jena.shared.NoWriterForLangException; -import org.apache.jena.test.JenaTestBase; import org.junit.Assert; -public class TestRDFWriterMap extends JenaTestBase { +public class TestRDFWriterMap extends TestCase { public static class RDFWriterMap implements RDFWriterF { protected final Map> map = new HashMap<>(); diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java b/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java index a847d4ada30..9422088c30b 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java @@ -23,6 +23,7 @@ import java.util.*; +import junit.framework.TestCase; import org.junit.Ignore; import org.apache.jena.graph.GraphTestLib; @@ -30,20 +31,19 @@ import org.apache.jena.junit.NodeCreateUtils; import org.apache.jena.rdf.model.*; import org.apache.jena.shared.PrefixMapping; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.util.CollectionFactory; /** provides useful functionality for testing models, eg building small models from strings, testing equality, etc. - Currently this class extends JenaTestBase and thus TestCase. + Currently this class extends TestCase. TODO: Refactoring should remove the TestCase dependency in future. */ @Ignore // ignore this class as a test case. -public class ModelHelper extends JenaTestBase +public class ModelHelper extends TestCase { private ModelHelper(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestConfigVocabulary.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestConfigVocabulary.java index a0a59ebf748..644f7f107d4 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestConfigVocabulary.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestConfigVocabulary.java @@ -21,10 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; +import junit.framework.TestCase; import org.apache.jena.rdf.model.Property; import org.apache.jena.rdf.model.Resource; import org.apache.jena.reasoner.ReasonerRegistry; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDFS; import org.apache.jena.vocabulary.ReasonerVocabulary; @@ -32,7 +32,7 @@ /** Tests for configuration vocabulary added as part of ModelSpec removal */ -public class TestConfigVocabulary extends JenaTestBase +public class TestConfigVocabulary extends TestCase { public TestConfigVocabulary( String name ) { super( name ); } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRestrictionsDontNeedTyping.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRestrictionsDontNeedTyping.java index c3b3028e70f..9e2fbbf5db6 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRestrictionsDontNeedTyping.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRestrictionsDontNeedTyping.java @@ -21,6 +21,7 @@ package org.apache.jena.reasoner.rulesys.test; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModelSpec; @@ -29,7 +30,6 @@ import org.apache.jena.rdf.model.ModelTestLib; import org.apache.jena.rdf.model.Property; import org.apache.jena.shared.PrefixMapping; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.vocabulary.RDF; /** @@ -38,7 +38,7 @@ explicit type (ie we're not caught in a forward rule -> backward rule layering problem). */ @SuppressWarnings("removal") -public class TestRestrictionsDontNeedTyping extends JenaTestBase +public class TestRestrictionsDontNeedTyping extends TestCase { public static TestSuite suite() { diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestSetRules.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestSetRules.java index 3ff5ef0ff23..1eb2930c8e1 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestSetRules.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestSetRules.java @@ -23,17 +23,17 @@ import java.util.*; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.rdf.model.*; import org.apache.jena.reasoner.*; import org.apache.jena.reasoner.rulesys.*; import org.apache.jena.reasoner.rulesys.impl.WrappedReasonerFactory; -import org.apache.jena.test.JenaTestBase; /** TestSetRules - tests to bring setRules into existence on RuleReasonerFactory. */ -public class TestSetRules extends JenaTestBase +public class TestSetRules extends TestCase { public TestSetRules( String name ) diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestCurrentRDFWG.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestCurrentRDFWG.java index eb0ef6154e0..10292774296 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestCurrentRDFWG.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestCurrentRDFWG.java @@ -31,7 +31,6 @@ import org.apache.jena.reasoner.ReasonerFactory; import org.apache.jena.reasoner.rulesys.RDFSRuleReasonerFactory; import org.apache.jena.shared.impl.JenaParameters; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.vocabulary.OWLResults; import org.apache.jena.vocabulary.RDFS; import org.apache.jena.vocabulary.ReasonerVocabulary; @@ -41,7 +40,7 @@ /** * Test the default RDFS reasoner against the current set of working group tests */ -public class TestCurrentRDFWG extends JenaTestBase { +public class TestCurrentRDFWG extends TestCase { /** Location of the test file directory */ public static final String TEST_DIR = "testing/wg20031010/"; diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfPrefixMapping.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfPrefixMapping.java index 48748622752..38a887f2675 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfPrefixMapping.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfPrefixMapping.java @@ -21,17 +21,17 @@ package org.apache.jena.reasoner.test; +import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.reasoner.InfGraph; -import org.apache.jena.test.JenaTestBase; /** Needs extending; relys on knowing that the only InfGraph currently used is the Jena-provided base. Needs to be made into an abstract test and parametrised with the InfGraph being tested (hence getInfGraph). */ -public class TestInfPrefixMapping extends JenaTestBase +public class TestInfPrefixMapping extends TestCase { public TestInfPrefixMapping( String name ) { super( name ); } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java index a9ed368213e..e986a56c95a 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java @@ -38,7 +38,6 @@ import org.apache.jena.reasoner.ValidityReport.Report; import org.apache.jena.reasoner.rulesys.RDFSFBRuleReasonerFactory; import org.apache.jena.reasoner.rulesys.RDFSRuleReasonerFactory; -import org.apache.jena.test.JenaTestBase; import org.apache.jena.vocabulary.RDFS; import org.apache.jena.vocabulary.ReasonerVocabulary; import org.slf4j.Logger; @@ -47,7 +46,7 @@ /** * Test the set of admissable RDFS reasoners. */ -public class TestRDFSReasoners extends JenaTestBase { +public class TestRDFSReasoners extends TestCase { /** Base URI for the test names */ public static final String NAMESPACE = "http://www.hpl.hp.com/semweb/2003/query_tester/"; diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaTestBase.java b/jena-core/src/test/java/org/apache/jena/test/JenaTestBase.java deleted file mode 100644 index a86ad6d85a0..00000000000 --- a/jena-core/src/test/java/org/apache/jena/test/JenaTestBase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.test; - -import junit.framework.TestCase; -import org.apache.jena.sys.JenaSystem; - -/** - * A basis for Jena test cases. - * See {@link JenaTestLib} for helper functions e.g. assertFalse and assertDiffer. - */ -public class JenaTestBase extends TestCase -{ - static { JenaSystem.init(); } - - public JenaTestBase(String name) { - super(name); - } -} From 890cff3a8f29f3c2e84bd5435f12cea9c92fda5f Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Mon, 7 Sep 2026 14:58:43 +0100 Subject: [PATCH 03/12] GH-3236: Convert EnhNode testing to JUnit6 --- .../org/apache/jena/enhanced/TS6_enh.java | 40 ++++ .../{TestAllImpl.java => T_AllImpl.java} | 26 +- ...{TestCommonImpl.java => T_CommonImpl.java} | 20 +- .../enhanced/{TestModel.java => T_Model.java} | 8 +- .../{TestModelImpl.java => T_ModelImpl.java} | 18 +- .../enhanced/{TestNode.java => T_Node.java} | 10 +- .../{TestObject.java => T_Object.java} | 4 +- ...{TestObjectImpl.java => T_ObjectImpl.java} | 16 +- .../{TestProperty.java => T_Property.java} | 6 +- ...tPropertyImpl.java => T_PropertyImpl.java} | 14 +- .../{TestSubject.java => T_Subject.java} | 6 +- ...estSubjectImpl.java => T_SubjectImpl.java} | 14 +- .../{TS3_enh.java => TestEnhanced.java} | 226 +++++++++--------- .../apache/jena/test/JenaCoreTestAll_JU4.java | 2 +- .../apache/jena/test/JenaCoreTestAll_JU6.java | 3 + 15 files changed, 231 insertions(+), 182 deletions(-) create mode 100644 jena-core/src/test/java/org/apache/jena/enhanced/TS6_enh.java rename jena-core/src/test/java/org/apache/jena/enhanced/{TestAllImpl.java => T_AllImpl.java} (77%) rename jena-core/src/test/java/org/apache/jena/enhanced/{TestCommonImpl.java => T_CommonImpl.java} (84%) rename jena-core/src/test/java/org/apache/jena/enhanced/{TestModel.java => T_Model.java} (90%) rename jena-core/src/test/java/org/apache/jena/enhanced/{TestModelImpl.java => T_ModelImpl.java} (74%) rename jena-core/src/test/java/org/apache/jena/enhanced/{TestNode.java => T_Node.java} (88%) rename jena-core/src/test/java/org/apache/jena/enhanced/{TestObject.java => T_Object.java} (93%) rename jena-core/src/test/java/org/apache/jena/enhanced/{TestObjectImpl.java => T_ObjectImpl.java} (83%) rename jena-core/src/test/java/org/apache/jena/enhanced/{TestProperty.java => T_Property.java} (90%) rename jena-core/src/test/java/org/apache/jena/enhanced/{TestPropertyImpl.java => T_PropertyImpl.java} (81%) rename jena-core/src/test/java/org/apache/jena/enhanced/{TestSubject.java => T_Subject.java} (90%) rename jena-core/src/test/java/org/apache/jena/enhanced/{TestSubjectImpl.java => T_SubjectImpl.java} (84%) rename jena-core/src/test/java/org/apache/jena/enhanced/{TS3_enh.java => TestEnhanced.java} (67%) diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TS6_enh.java b/jena-core/src/test/java/org/apache/jena/enhanced/TS6_enh.java new file mode 100644 index 00000000000..0e1edba40e5 --- /dev/null +++ b/jena-core/src/test/java/org/apache/jena/enhanced/TS6_enh.java @@ -0,0 +1,40 @@ +/* + * 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 + * + * https://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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.apache.jena.enhanced; + +import org.junit.platform.suite.api.BeforeSuite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; + +import org.apache.jena.test.JenaTestLib; + +@Suite +@SelectClasses({ + TestEnhanced.class +}) + +public class TS6_enh { + @BeforeSuite + public static void beforeSuite() { + JenaTestLib.setup(); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TestAllImpl.java b/jena-core/src/test/java/org/apache/jena/enhanced/T_AllImpl.java similarity index 77% rename from jena-core/src/test/java/org/apache/jena/enhanced/TestAllImpl.java rename to jena-core/src/test/java/org/apache/jena/enhanced/T_AllImpl.java index 0ec843c7484..eee7d43d09d 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TestAllImpl.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/T_AllImpl.java @@ -23,7 +23,7 @@ import org.apache.jena.graph.*; import org.apache.jena.rdf.model.*; -public class TestAllImpl extends TestCommonImpl implements TestSubject, TestProperty, TestObject { +public class T_AllImpl extends T_CommonImpl implements T_Subject, T_Property, T_Object { public static final Implementation factory = new Implementation() { @Override @@ -31,12 +31,12 @@ public boolean canWrap( Node n, EnhGraph eg ) { return true; } @Override public EnhNode wrap(Node n,EnhGraph eg) { - return new TestAllImpl(n,eg); + return new T_AllImpl(n,eg); } }; - /** Creates a new instance of TestAllImpl */ - private TestAllImpl(Node n,EnhGraph eg) { + /** Creates a new instance of T_AllImpl */ + private T_AllImpl(Node n,EnhGraph eg) { super( n, eg ); } @@ -44,9 +44,9 @@ private TestAllImpl(Node n,EnhGraph eg) { { // return convertTo( t ) != null; return - t == TestProperty.class ? isProperty() - : t == TestSubject.class ? isSubject() - : t == TestObject.class ? isObject() + t == T_Property.class ? isProperty() + : t == T_Subject.class ? isSubject() + : t == T_Object.class ? isObject() : false ; } @@ -67,24 +67,24 @@ public boolean isSubject() { } @Override - public TestObject anObject() { + public T_Object anObject() { if (!isProperty()) throw new IllegalStateException("Node is not the property of a triple."); - return enhGraph.getNodeAs(findPredicate().getObject(),TestObject.class); + return enhGraph.getNodeAs(findPredicate().getObject(),T_Object.class); } @Override - public TestProperty aProperty() { + public T_Property aProperty() { if (!isSubject()) throw new IllegalStateException("Node is not the subject of a triple."); - return enhGraph.getNodeAs(findSubject().getPredicate(),TestProperty.class); + return enhGraph.getNodeAs(findSubject().getPredicate(),T_Property.class); } @Override - public TestSubject aSubject() { + public T_Subject aSubject() { if (!isObject()) throw new IllegalStateException("Node is not the object of a triple."); - return enhGraph.getNodeAs(findObject().getSubject(),TestSubject.class); + return enhGraph.getNodeAs(findObject().getSubject(),T_Subject.class); } @Override diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TestCommonImpl.java b/jena-core/src/test/java/org/apache/jena/enhanced/T_CommonImpl.java similarity index 84% rename from jena-core/src/test/java/org/apache/jena/enhanced/TestCommonImpl.java rename to jena-core/src/test/java/org/apache/jena/enhanced/T_CommonImpl.java index 104b9e3cbb9..bdb8e8eb9d9 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TestCommonImpl.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/T_CommonImpl.java @@ -25,15 +25,15 @@ import org.apache.jena.shared.JenaException; import org.apache.jena.util.iterator.*; -class TestCommonImpl extends EnhNode implements TestNode { +class T_CommonImpl extends EnhNode implements T_Node { - /** Creates new TestCommonImpl */ - TestCommonImpl(Node n, EnhGraph m ) { + /** Creates new T_CommonImpl */ + T_CommonImpl(Node n, EnhGraph m ) { super(n,m); } /** - We can't return TestModel now, because it clashes with the getModel() + We can't return T_Model now, because it clashes with the getModel() in RDFNode, which we have to inherit because of the personality tests. Fortunately the EnhGraph test set doesn't /need/ getModel, so we give it return type Model and throw an exception if it's ever called. @@ -71,18 +71,18 @@ Triple findNode(Node s, Node p, Node o) { // Convenience routines, that wrap the generic // routines from EnhNode. @Override - public TestSubject asSubject() { - return asInternal(TestSubject.class); + public T_Subject asSubject() { + return asInternal(T_Subject.class); } @Override - public TestProperty asProperty() { - return asInternal(TestProperty.class); + public T_Property asProperty() { + return asInternal(T_Property.class); } @Override - public TestObject asObject() { - return asInternal(TestObject.class); + public T_Object asObject() { + return asInternal(T_Object.class); } public RDFNode inModel(Model m) { diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TestModel.java b/jena-core/src/test/java/org/apache/jena/enhanced/T_Model.java similarity index 90% rename from jena-core/src/test/java/org/apache/jena/enhanced/TestModel.java rename to jena-core/src/test/java/org/apache/jena/enhanced/T_Model.java index ea1180e3292..853b6b88aa8 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TestModel.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/T_Model.java @@ -26,9 +26,9 @@ * It allows you to access an arbitrary subject node, * or property node, or object node from the graph. */ -public interface TestModel { - TestSubject aSubject(); - TestProperty aProperty(); - TestObject anObject(); +public interface T_Model { + T_Subject aSubject(); + T_Property aProperty(); + T_Object anObject(); } diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TestModelImpl.java b/jena-core/src/test/java/org/apache/jena/enhanced/T_ModelImpl.java similarity index 74% rename from jena-core/src/test/java/org/apache/jena/enhanced/TestModelImpl.java rename to jena-core/src/test/java/org/apache/jena/enhanced/T_ModelImpl.java index 9b94945e066..8ed6dae892f 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TestModelImpl.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/T_ModelImpl.java @@ -24,10 +24,10 @@ import org.apache.jena.rdf.model.RDFNode; import org.apache.jena.util.iterator.*; -public class TestModelImpl extends EnhGraph implements TestModel { +public class T_ModelImpl extends EnhGraph implements T_Model { - /** Creates a new instance of TestModelImpl */ - public TestModelImpl(Graph g, Personality p) { + /** Creates a new instance of T_ModelImpl */ + public T_ModelImpl(Graph g, Personality p) { super(g,p); } private Triple aTriple() @@ -43,18 +43,18 @@ private Triple aTriple() } @Override - public TestObject anObject() { - return getNodeAs(aTriple().getObject(),TestObject.class); + public T_Object anObject() { + return getNodeAs(aTriple().getObject(),T_Object.class); } @Override - public TestProperty aProperty() { - return getNodeAs(aTriple().getPredicate(),TestProperty.class); + public T_Property aProperty() { + return getNodeAs(aTriple().getPredicate(),T_Property.class); } @Override - public TestSubject aSubject() { - return getNodeAs(aTriple().getSubject(),TestSubject.class); + public T_Subject aSubject() { + return getNodeAs(aTriple().getSubject(),T_Subject.class); } } diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TestNode.java b/jena-core/src/test/java/org/apache/jena/enhanced/T_Node.java similarity index 88% rename from jena-core/src/test/java/org/apache/jena/enhanced/TestNode.java rename to jena-core/src/test/java/org/apache/jena/enhanced/T_Node.java index 85be04acfcc..ee49cf14657 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TestNode.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/T_Node.java @@ -21,13 +21,13 @@ package org.apache.jena.enhanced; -public interface TestNode { +public interface T_Node { // Convenience routines for converting between different // views using the subinterfaces, // These are implemented in the base implementation class - // TestCommonImpl. - TestSubject asSubject(); - TestObject asObject(); - TestProperty asProperty(); + // T_CommonImpl. + T_Subject asSubject(); + T_Object asObject(); + T_Property asProperty(); } diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TestObject.java b/jena-core/src/test/java/org/apache/jena/enhanced/T_Object.java similarity index 93% rename from jena-core/src/test/java/org/apache/jena/enhanced/TestObject.java rename to jena-core/src/test/java/org/apache/jena/enhanced/T_Object.java index 99324eb1b3e..98e9e914898 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TestObject.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/T_Object.java @@ -26,7 +26,7 @@ /** * An interface for viewing object nodes in the graph. */ -public interface TestObject extends RDFNode, TestNode { +public interface T_Object extends RDFNode, T_Node { /** * Checks whether this node is right now the object of some @@ -39,5 +39,5 @@ public interface TestObject extends RDFNode, TestNode { * * @return the subject of a triple. */ - TestSubject aSubject(); + T_Subject aSubject(); } diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TestObjectImpl.java b/jena-core/src/test/java/org/apache/jena/enhanced/T_ObjectImpl.java similarity index 83% rename from jena-core/src/test/java/org/apache/jena/enhanced/TestObjectImpl.java rename to jena-core/src/test/java/org/apache/jena/enhanced/T_ObjectImpl.java index 9ca26342b1b..0eef2ac3fef 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TestObjectImpl.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/T_ObjectImpl.java @@ -24,9 +24,9 @@ import org.apache.jena.rdf.model.RDFNode; /** - * See {@link TestObject} for more detailed documentation. + * See {@link T_Object} for more detailed documentation. */ -public class TestObjectImpl extends TestCommonImpl implements TestObject { +public class T_ObjectImpl extends T_CommonImpl implements T_Object { /** The required field is the factory field, of * class Implementation. @@ -40,14 +40,14 @@ public class TestObjectImpl extends TestCommonImpl implements TestObject { Note the constructor can/should be private. */ @Override public EnhNode wrap(Node n,EnhGraph eg) - { return new TestObjectImpl(n,eg); } + { return new T_ObjectImpl(n,eg); } @Override public boolean canWrap( Node n, EnhGraph eg ) { return true; } }; - /** Creates a new instance of TestAllImpl */ - private TestObjectImpl(Node n,EnhGraph eg) { + /** Creates a new instance of T_AllImpl */ + private T_ObjectImpl(Node n,EnhGraph eg) { super( n, eg ); } @@ -65,12 +65,12 @@ public boolean isObject() { * (If the underlying graph has changed for the worse will * users prefer an early and unambiguous exception at this point). * - * @see org.apache.jena.enhanced.TestObject#aSubject() + * @see org.apache.jena.enhanced.T_Object#aSubject() */ @Override - public TestSubject aSubject() { + public T_Subject aSubject() { if (!isObject()) throw new IllegalStateException("Node is not the object of a triple."); - return enhGraph.getNodeAs(findObject().getSubject(),TestSubject.class); + return enhGraph.getNodeAs(findObject().getSubject(),T_Subject.class); } } diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TestProperty.java b/jena-core/src/test/java/org/apache/jena/enhanced/T_Property.java similarity index 90% rename from jena-core/src/test/java/org/apache/jena/enhanced/TestProperty.java rename to jena-core/src/test/java/org/apache/jena/enhanced/T_Property.java index 7b4ab3d4a10..471c31a1513 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TestProperty.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/T_Property.java @@ -24,10 +24,10 @@ import org.apache.jena.rdf.model.RDFNode; /** - * @see TestObject + * @see T_Object */ -public interface TestProperty extends RDFNode, TestNode { +public interface T_Property extends RDFNode, T_Node { boolean isProperty(); - TestObject anObject(); + T_Object anObject(); } diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TestPropertyImpl.java b/jena-core/src/test/java/org/apache/jena/enhanced/T_PropertyImpl.java similarity index 81% rename from jena-core/src/test/java/org/apache/jena/enhanced/TestPropertyImpl.java rename to jena-core/src/test/java/org/apache/jena/enhanced/T_PropertyImpl.java index c91d3741478..295b2648d0b 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TestPropertyImpl.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/T_PropertyImpl.java @@ -24,21 +24,21 @@ import org.apache.jena.rdf.model.RDFNode; /** - * @see TestObjectImpl + * @see T_ObjectImpl */ -public class TestPropertyImpl extends TestCommonImpl implements TestProperty { +public class T_PropertyImpl extends T_CommonImpl implements T_Property { public static final Implementation factory = new Implementation() { @Override public EnhNode wrap(Node n,EnhGraph eg) { - return new TestPropertyImpl(n,eg); + return new T_PropertyImpl(n,eg); } @Override public boolean canWrap( Node n, EnhGraph eg ) { return true; } }; - /** Creates a new instance of TestAllImpl */ - private TestPropertyImpl(Node n,EnhGraph eg) { + /** Creates a new instance of T_AllImpl */ + private T_PropertyImpl(Node n,EnhGraph eg) { super( n, eg ); } @@ -51,10 +51,10 @@ public boolean isProperty() { } @Override - public TestObject anObject() { + public T_Object anObject() { if (!isProperty()) throw new IllegalStateException("Node is not the property of a triple."); - return enhGraph.getNodeAs(findPredicate().getObject(),TestObject.class); + return enhGraph.getNodeAs(findPredicate().getObject(),T_Object.class); } } diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TestSubject.java b/jena-core/src/test/java/org/apache/jena/enhanced/T_Subject.java similarity index 90% rename from jena-core/src/test/java/org/apache/jena/enhanced/TestSubject.java rename to jena-core/src/test/java/org/apache/jena/enhanced/T_Subject.java index a59f608c821..fd6c243f518 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TestSubject.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/T_Subject.java @@ -24,10 +24,10 @@ import org.apache.jena.rdf.model.RDFNode; /** - * @see TestObject + * @see T_Object */ -public interface TestSubject extends RDFNode, TestNode { +public interface T_Subject extends RDFNode, T_Node { boolean isSubject(); - TestProperty aProperty(); + T_Property aProperty(); } diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TestSubjectImpl.java b/jena-core/src/test/java/org/apache/jena/enhanced/T_SubjectImpl.java similarity index 84% rename from jena-core/src/test/java/org/apache/jena/enhanced/TestSubjectImpl.java rename to jena-core/src/test/java/org/apache/jena/enhanced/T_SubjectImpl.java index ea6131ee6c5..6fb950132f6 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TestSubjectImpl.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/T_SubjectImpl.java @@ -24,9 +24,9 @@ import org.apache.jena.graph.*; import org.apache.jena.rdf.model.RDFNode; /** - * @see TestObjectImpl + * @see T_ObjectImpl */ -public class TestSubjectImpl extends TestCommonImpl implements TestSubject { +public class T_SubjectImpl extends T_CommonImpl implements T_Subject { public static final Implementation factory = new Implementation() { @Override @@ -34,12 +34,12 @@ public boolean canWrap( Node n, EnhGraph eg ) { return true; } @Override public EnhNode wrap(Node n,EnhGraph eg) { - return new TestSubjectImpl(n,eg); + return new T_SubjectImpl(n,eg); } }; - /** Creates a new instance of TestAllImpl */ - private TestSubjectImpl(Node n,EnhGraph eg) { + /** Creates a new instance of T_AllImpl */ + private T_SubjectImpl(Node n,EnhGraph eg) { super( n, eg ); } @@ -52,9 +52,9 @@ public boolean isSubject() { } @Override - public TestProperty aProperty() { + public T_Property aProperty() { if (!isSubject()) throw new IllegalStateException("Node is not the subject of a triple."); - return enhGraph.getNodeAs(findSubject().getPredicate(),TestProperty.class); + return enhGraph.getNodeAs(findSubject().getPredicate(),T_Property.class); } } diff --git a/jena-core/src/test/java/org/apache/jena/enhanced/TS3_enh.java b/jena-core/src/test/java/org/apache/jena/enhanced/TestEnhanced.java similarity index 67% rename from jena-core/src/test/java/org/apache/jena/enhanced/TS3_enh.java rename to jena-core/src/test/java/org/apache/jena/enhanced/TestEnhanced.java index fa31bd2c8be..9f28016396e 100644 --- a/jena-core/src/test/java/org/apache/jena/enhanced/TS3_enh.java +++ b/jena-core/src/test/java/org/apache/jena/enhanced/TestEnhanced.java @@ -19,26 +19,34 @@ * SPDX-License-Identifier: Apache-2.0 */ -/* - * EnhancedTestSuite.java - * - * Created on 27 November 2002, 04:53 - */ - package org.apache.jena.enhanced; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.jena.graph.*; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +import org.apache.jena.graph.Graph; +import org.apache.jena.graph.GraphMemFactory; +import org.apache.jena.graph.GraphTestLib; +import org.apache.jena.graph.Node; +import org.apache.jena.graph.NodeFactory; import org.apache.jena.junit.NodeCreateUtils; -import org.apache.jena.rdf.model.*; +import org.apache.jena.rdf.model.Literal; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.Property; +import org.apache.jena.rdf.model.RDFNode; +import org.apache.jena.rdf.model.RDFVisitor; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.ResourceFactory; +import org.apache.jena.rdf.model.StatementTerm; import org.apache.jena.shared.JenaException; +import org.apache.jena.test.JenaTestLib; /** * These tests give a small version of a model-like interface - {@link TestModel} with different views - * over the nodes in the graph {@link TestSubject}, - *{@link TestProperty} {@link TestObject} + {@link T_Model} with different views + * over the nodes in the graph {@link T_Subject}, + *{@link T_Property} {@link T_Object} *Any node can be any one of these three, but the interface only works *if the node is the subject, property or object, respectively, of some triple in the graph. @@ -52,7 +60,9 @@ *These tests only test EnhNode polymorphism and not EnhGraph polymorphism. *EnhGraph polymorphism currently will not work. */ -public class TS3_enh extends TestCase { +public class TestEnhanced { + + static { JenaTestLib.setup(); } static final private Personality split = new Personality<>(); @@ -67,31 +77,23 @@ public class TS3_enh extends TestCase { // Note this does not guarantee that the only implementations // of each interface will be the one specified. // See bitOfBoth. - split.add( TestObject.class, TestObjectImpl.factory ); - split.add( TestSubject.class, TestSubjectImpl.factory ); - split.add( TestProperty.class, TestPropertyImpl.factory ); + split.add( T_Object.class, T_ObjectImpl.factory ); + split.add( T_Subject.class, T_SubjectImpl.factory ); + split.add( T_Property.class, T_PropertyImpl.factory ); - combo.add( TestObject.class, TestAllImpl.factory ); - combo.add( TestSubject.class, TestAllImpl.factory ); - combo.add( TestProperty.class, TestAllImpl.factory ); + combo.add( T_Object.class, T_AllImpl.factory ); + combo.add( T_Subject.class, T_AllImpl.factory ); + combo.add( T_Property.class, T_AllImpl.factory ); - bitOfBoth.add( TestObject.class, TestObjectImpl.factory ); - bitOfBoth.add( TestSubject.class, TestSubjectImpl.factory ); - bitOfBoth.add( TestProperty.class, TestAllImpl.factory ); + bitOfBoth.add( T_Object.class, T_ObjectImpl.factory ); + bitOfBoth.add( T_Subject.class, T_SubjectImpl.factory ); + bitOfBoth.add( T_Property.class, T_AllImpl.factory ); // broken is misconfigured and must throw an exception. - broken.add(TestObject.class, TestObjectImpl.factory ); - broken.add( TestSubject.class, TestSubjectImpl.factory ); - broken.add( TestProperty.class, TestObjectImpl.factory ); + broken.add(T_Object.class, T_ObjectImpl.factory ); + broken.add( T_Subject.class, T_SubjectImpl.factory ); + broken.add( T_Property.class, T_ObjectImpl.factory ); } - /** Creates a new instance of EnhancedTestSuite */ - public TS3_enh(String name) { - super(name); - } - - public static TestSuite suite() { - return new TestSuite(TS3_enh.class); - } // Create the graph to test. // These are model tests so use a same-value model. @@ -103,6 +105,7 @@ private static Graph graphToTest() { * test that equals works on an EnhNode (after hedgehog introduced FrontsNode it * didn't). */ + @Test public void testEquals() { EnhNode a = new EnhNode(NodeCreateUtils.create("eg:example"), null); assertEquals(a, a); @@ -111,29 +114,29 @@ public void testEquals() { /** * View n as intf. This is supported iff rslt. */ - private static void miniAsSupports(String title, TestNode n, Class intf, boolean rslt ) { - assertTrue(title +":sanity",n instanceof Polymorphic); + private static void miniAsSupports(String title, T_Node n, Class intf, boolean rslt ) { + assertTrue(n instanceof Polymorphic, title +":sanity"); // It is always possible to view any node with any interface. - TestNode as1 = (TestNode)((EnhNode)n).viewAs(intf); - TestNode as2 = (TestNode)((EnhNode)n).viewAs(intf); + T_Node as1 = (T_Node)((EnhNode)n).viewAs(intf); + T_Node as2 = (T_Node)((EnhNode)n).viewAs(intf); // caching should ensure we get the same result both times. - assertTrue( title + ":idempotency", as1==as2 ); + assertTrue( as1==as2, title + ":idempotency" ); // Whether the interface is actually useable depends on the underlying // graph. This factoid is the rslt parameter. - assertEquals( title +":support",rslt,((EnhNode) as1).supports( intf ) ); + assertEquals( rslt, ((EnhNode) as1).supports( intf ), title +":support" ); } - private static void oneNodeAsSupports(String title, TestNode n, boolean rslts[] ) { + private static void oneNodeAsSupports(String title, T_Node n, boolean rslts[] ) { // Try n with all three interfaces. - miniAsSupports(title+"/TestSubject",n,TestSubject.class,rslts[0]); - miniAsSupports(title+"/TestProperty",n,TestProperty.class,rslts[1]); - miniAsSupports(title+"/TestObject",n,TestObject.class,rslts[2]); + miniAsSupports(title+"/T_Subject",n,T_Subject.class,rslts[0]); + miniAsSupports(title+"/T_Property",n,T_Property.class,rslts[1]); + miniAsSupports(title+"/T_Object",n,T_Object.class,rslts[2]); } - private static void manyNodeAsSupports(String title, TestNode n[], boolean rslts[][] ) { + private static void manyNodeAsSupports(String title, T_Node n[], boolean rslts[][] ) { // Try each n with each interface. for (int i=0;i p) { Graph g = graphToTest(); - TestModel model = new TestModelImpl(g,p); + T_Model model = new T_ModelImpl(g,p); // create some data GraphTestLib.graphAdd( g, "x R y;" ); - // The graph has three nodes, extract them as TestNode's, + // The graph has three nodes, extract them as T_Node's, // using the minimalist ModelAPI. - TestNode nodes[] = new TestNode[]{ + T_Node nodes[] = new T_Node[]{ model.aSubject(), model.aProperty(), model.anObject() @@ -171,9 +174,9 @@ private static void basic(String title, Personality p) { GraphTestLib.graphAdd(g,"y R x;" ); // The expected results are now different. - // (A node is appropriate for the TestSubject interface if it is + // (A node is appropriate for the T_Subject interface if it is // the subject of some triple in the graph, so the third node - // can now be a TestSubject). + // can now be a T_Subject). manyNodeAsSupports(title+"(b)",nodes, new boolean[][]{ new boolean[]{true,false,true}, // nodes[0] is subj and obj, but not prop @@ -184,9 +187,9 @@ private static void basic(String title, Personality p) { g.delete( GraphTestLib.triple( "x R y" ) ); // The expected results are now different again. - // (A node is appropriate for the TestSubject interface if it is + // (A node is appropriate for the T_Subject interface if it is // the subject of some triple in the graph, so the third node - // can now be a TestSubject). + // can now be a T_Subject). manyNodeAsSupports(title+"(c)",nodes, new boolean[][]{ @@ -211,7 +214,7 @@ private static void basic(String title, Personality p) { // or not, we just try it. // Obviously sometimes it is broken, which should be reported using // an IllegalStateException. - private void canImplement(String title, TestNode n, int wh, boolean rslt ) { + private void canImplement(String title, T_Node n, int wh, boolean rslt ) { try { switch (wh) { case S: @@ -224,19 +227,19 @@ private void canImplement(String title, TestNode n, int wh, boolean rslt ) { n.asObject().aSubject(); break; } - assertTrue("IllegalStateException expected.",rslt); + assertTrue(rslt, "IllegalStateException expected."); } catch (IllegalStateException e) { - assertFalse("IllegalStateException at the wrong time.",rslt); + assertFalse(rslt, "IllegalStateException at the wrong time."); } } - private void canImplement(String title, TestNode n, boolean rslts[] ) { - canImplement(title+"/TestSubject",n,S,rslts[0]); - canImplement(title+"/TestProperty",n,P,rslts[1]); - canImplement(title+"/TestObject",n,O,rslts[2]); + private void canImplement(String title, T_Node n, boolean rslts[] ) { + canImplement(title+"/T_Subject",n,S,rslts[0]); + canImplement(title+"/T_Property",n,P,rslts[1]); + canImplement(title+"/T_Object",n,O,rslts[2]); } - private void canImplement(String title, TestNode n[], boolean rslts[][] ) { + private void canImplement(String title, T_Node n[], boolean rslts[][] ) { for (int i=0;i p) { Graph g = graphToTest(); - TestModel model = new TestModelImpl(g,p); + T_Model model = new T_ModelImpl(g,p); // create some data GraphTestLib.graphAdd( g, "a b c;" ); - TestNode nodes[] = new TestNode[]{ + T_Node nodes[] = new T_Node[]{ model.aSubject(), model.aProperty(), model.anObject() @@ -285,7 +288,7 @@ private void follow(String title, Personality p) { }); // Another twist. - canImplement(title+"(c)",new TestNode[]{ + canImplement(title+"(c)",new T_Node[]{ nodes[1].asSubject().aProperty(), nodes[2].asObject().aSubject(), nodes[0].asProperty().anObject() @@ -295,55 +298,59 @@ private void follow(String title, Personality p) { new boolean[]{true,false,false}, new boolean[]{false,false,true} }); - assertTrue("Recreated node",nodes[0].asProperty().anObject().equals(nodes[2])); + assertTrue(nodes[0].asProperty().anObject().equals(nodes[2]), "Recreated node"); } + @Test public void testSplitBasic() { basic("Split: ",split); } + @Test public void testComboBasic() { basic("Combo: ",combo); } + @Test public void testSplitFollow() { follow("Split: ",split); } + @Test public void testComboFollow() { follow("Combo: ",combo); } + @Test public void testBitOfBothBasic() { basic("bob: ",bitOfBoth); } + @Test public void testBitOfBothFollow() { follow("bob: ",bitOfBoth); } + @Test public void testBitOfBothSurprise() { // bitOfBoth is a surprising personality ... // we can have two different java objects implementing the same interface. Graph g = graphToTest(); - TestModel model = new TestModelImpl(g,bitOfBoth); + T_Model model = new T_ModelImpl(g,bitOfBoth); // create some data GraphTestLib.graphAdd( g, "a a a;" ); - TestSubject testSubjectImpl = model.aSubject(); - assertTrue("BitOfBoth makes subjects using TestSubjectImpl", - testSubjectImpl instanceof TestSubjectImpl); - TestProperty testAllImpl = testSubjectImpl.aProperty(); - assertTrue("BitOfBoth makes properties using TestAllImpl", - testAllImpl instanceof TestAllImpl); - assertTrue("turning a TestAllImpl into a TestSubject is a no-op", - testAllImpl == testAllImpl.asSubject() ); - assertTrue("turning a TestAllImpl into a TestSubject is a no-op", - testSubjectImpl != testAllImpl.asSubject() ); - assertTrue("turning a TestAllImpl into a TestSubject is a no-op", - testSubjectImpl.asSubject() != testSubjectImpl.asSubject().asProperty().asSubject() ); + T_Subject testSubjectImpl = model.aSubject(); + assertTrue(testSubjectImpl instanceof T_SubjectImpl, + "BitOfBoth makes subjects using T_SubjectImpl"); + T_Property testAllImpl = testSubjectImpl.aProperty(); + assertTrue(testAllImpl instanceof T_AllImpl, + "BitOfBoth makes properties using T_AllImpl"); + assertTrue(testAllImpl == testAllImpl.asSubject(), + "turning a T_AllImpl into a T_Subject is a no-op"); + assertTrue(testSubjectImpl != testAllImpl.asSubject(), + "turning a T_AllImpl into a T_Subject is a no-op"); + assertTrue(testSubjectImpl.asSubject() != testSubjectImpl.asSubject().asProperty().asSubject(), + "turning a T_AllImpl into a T_Subject is a no-op"); } + @Test public void testBrokenBasic() { - try { - // Any of the tests ought to work up and til the point - // that they don't. At that point they need to detect the - // error and throw the PersonalityConfigException. - basic("Broken: ",broken); - fail("broken is a misconfigured personality, but it wasn't detected."); - } - catch (PersonalityConfigException e ) { - - } + // Any of the tests ought to work up and til the point + // that they don't. At that point they need to detect the + // error and throw the PersonalityConfigException. + assertThrows(PersonalityConfigException.class, + ()->basic("Broken: ",broken), + "broken is a misconfigured personality, but it wasn't detected."); } static class Example extends EnhNode implements RDFNode { @@ -388,15 +395,15 @@ public Object visitWith( RDFVisitor rv ) { return null; } } + @Test public void testSimple() { Graph g = graphToTest(); Personality ours = BuiltinPersonalities.model.copy().add(Example.class, Example.factory); EnhGraph eg = new EnhGraph(g, ours); - Node n = NodeFactory.createURI("spoo:bar"); EnhNode eNode = new EnhNode(NodeFactory.createURI("spoo:bar"), eg); EnhNode eBlank = new EnhNode(NodeFactory.createBlankNode(), eg); - assertTrue("URI node can be an Example", eNode.supports(Example.class)); - assertFalse("Blank node cannot be an Example", eBlank.supports(Example.class)); + assertTrue(eNode.supports(Example.class), "URI node can be an Example"); + assertFalse(eBlank.supports(Example.class), "Blank node cannot be an Example"); } static class AnotherExample { @@ -413,6 +420,7 @@ public boolean canWrap(Node n, EnhGraph g) { }; } + @Test public void testAlreadyLinkedViewException() { Graph g = graphToTest(); Personality ours = BuiltinPersonalities.model.copy().add(Example.class, Example.factory); @@ -422,10 +430,9 @@ public void testAlreadyLinkedViewException() { EnhNode multiplexed = new Example(n, eg); multiplexed.as(Property.class); eNode.viewAs(Example.class); - try { - eNode.addView(multiplexed); - fail("should raise an AlreadyLinkedViewException "); - } catch (AlreadyLinkedViewException e) {} + assertThrows(AlreadyLinkedViewException.class, + ()->eNode.addView(multiplexed), + "should raise an AlreadyLinkedViewException"); } /** @@ -433,21 +440,20 @@ public void testAlreadyLinkedViewException() { * supported by the enhanced graph generates an UnsupportedPolymorphism * exception. */ + @Test public void testNullPointerTrap() { Graph g = graphToTest(); EnhGraph eg = new EnhGraph(g, new Personality()); Node n = NodeCreateUtils.create("eh:something"); EnhNode en = new EnhNode(n, eg); - try { - en.as(Property.class); - fail("oops"); - } catch (UnsupportedPolymorphismException e) { - assertEquals(en, e.getBadNode()); - assertTrue("exception should have cuplprit graph", eg == ((EnhNode)e.getBadNode()).getGraph()); - assertSame("exception should have culprit class", Property.class, e.getBadClass()); - } + UnsupportedPolymorphismException e = + assertThrows(UnsupportedPolymorphismException.class, ()->en.as(Property.class)); + assertEquals(en, e.getBadNode()); + assertTrue(eg == ((EnhNode)e.getBadNode()).getGraph(), "exception should have cuplprit graph"); + assertSame(Property.class, e.getBadClass(), "exception should have culprit class"); } + @Test public void testNullPointerTrapInCanSupport() { Graph g = graphToTest(); EnhGraph eg = new EnhGraph(g, new Personality()); @@ -456,6 +462,7 @@ public void testNullPointerTrapInCanSupport() { assertFalse(en.canAs(Property.class)); } + @Test public void testAsToOwnClassWithNoModel() { Resource r = ResourceFactory.createResource(); assertEquals(null, r.getModel()); @@ -463,20 +470,19 @@ public void testAsToOwnClassWithNoModel() { assertSame(r, r.as(Resource.class)); } + @Test public void testCanAsReturnsFalseIfNoModel() { Resource r = ResourceFactory.createResource(); assertEquals(false, r.canAs(Example.class)); } + @Test public void testAsThrowsPolymorphismExceptionIfNoModel() { Resource r = ResourceFactory.createResource(); - try { - r.as(Example.class); - fail("should throw UnsupportedPolymorphismException"); - } catch (UnsupportedPolymorphismException e) { - assertTrue(e.getBadNode() instanceof EnhNode); - assertEquals(null, ((EnhNode)e.getBadNode()).getGraph()); - assertEquals(Example.class, e.getBadClass()); - } + UnsupportedPolymorphismException e = + assertThrows(UnsupportedPolymorphismException.class, ()->r.as(Example.class)); + assertTrue(e.getBadNode() instanceof EnhNode); + assertEquals(null, ((EnhNode)e.getBadNode()).getGraph()); + assertEquals(Example.class, e.getBadClass()); } } diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java index b323842a67d..bd789ea41f0 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java @@ -44,7 +44,7 @@ static public TestSuite suite() { // ** COMPLEX // Generates tests. - addTest(ts, "Enhanced", org.apache.jena.enhanced.TS3_enh.suite()); +//JU6 addTest(ts, "Enhanced", org.apache.jena.enhanced.TS3_enh.suite()); addTest(ts, "Graph", adaptJUnit4(org.apache.jena.graph.TS3_graph.class)); //JU6 addTest(ts, "Mem", adaptJUnit4(org.apache.jena.mem.TS4_GraphMem.class)); diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java index 864446eae02..5a2c797abe8 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java @@ -27,6 +27,7 @@ import org.apache.jena.core_ttl.tests.TS6_TestTurtle; import org.apache.jena.datatypes.TS6_dt; +import org.apache.jena.enhanced.TS6_enh; import org.apache.jena.irix.TS6_IRIx2; import org.apache.jena.langtagx.TS6_LangTagX; import org.apache.jena.mem.TS6_GraphMem; @@ -49,6 +50,8 @@ TS6_LangTagX.class, TS6_dt.class, + TS6_enh.class, + TS6_GraphMem.class, TS6_GraphMemValue.class, From 063a8c3412b3bfc6c8c1c4b1ad7eae37a20db0be Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Mon, 7 Sep 2026 15:12:07 +0100 Subject: [PATCH 04/12] GH-3236: Convert TestDefaultModel to JUnit6 --- .../org/apache/jena/rdf/model/TS6_Model.java | 40 +++++++++++++ ...ltModel.java => TestDefaultModel_JU6.java} | 57 +++++++++++-------- .../apache/jena/test/JenaCoreTestAll_JU4.java | 2 +- .../apache/jena/test/JenaCoreTestAll_JU6.java | 3 + 4 files changed, 76 insertions(+), 26 deletions(-) create mode 100644 jena-core/src/test/java/org/apache/jena/rdf/model/TS6_Model.java rename jena-core/src/test/java/org/apache/jena/rdf/model/{TestDefaultModel.java => TestDefaultModel_JU6.java} (91%) diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TS6_Model.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TS6_Model.java new file mode 100644 index 00000000000..3949795fd38 --- /dev/null +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TS6_Model.java @@ -0,0 +1,40 @@ +/* + * 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 + * + * https://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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.apache.jena.rdf.model; + +import org.junit.platform.suite.api.BeforeSuite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; + +import org.apache.jena.test.JenaTestLib; + +@Suite +@SelectClasses({ + TestDefaultModel_JU6.class +}) + +public class TS6_Model { + @BeforeSuite + public static void beforeSuite() { + JenaTestLib.setup(); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel_JU6.java similarity index 91% rename from jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel.java rename to jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel_JU6.java index e24b578dd5d..cb71d48a240 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel_JU6.java @@ -21,8 +21,12 @@ package org.apache.jena.rdf.model; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.GraphTestLib; import org.apache.jena.graph.Node; import org.apache.jena.graph.Triple; @@ -31,17 +35,9 @@ import org.apache.jena.shared.PropertyNotFoundException; import org.apache.jena.test.JenaTestLib; -public class TestDefaultModel extends TestCase { - - public TestDefaultModel(String name) { - super(name); - } +public class TestDefaultModel_JU6 { - static public TestSuite suite() { - TestSuite ts = new TestSuite(); - ts.addTestSuite(TestDefaultModel.class); - return ts; - } + static { JenaTestLib.setup(); } public Model newModel() { return ModelFactory.createDefaultModel(); @@ -49,39 +45,44 @@ public Model newModel() { private Model model; - @Override + @BeforeEach public void setUp() { model = newModel(); } - @Override + @AfterEach public void tearDown() { model.close(); } + @Test public void testTransactions() { if ( model.supportsTransactions() ) model.executeInTxn(() -> {}); } + @Test public void testCreateResourceFromNode() { RDFNode S = model.getRDFNode(NodeCreateUtils.create("spoo:S")); JenaTestLib.assertInstanceOf(Resource.class, S); assertEquals("spoo:S", ((Resource)S).getURI()); } + @Test public void testCreateLiteralFromNode() { RDFNode S = model.getRDFNode(NodeCreateUtils.create("42")); JenaTestLib.assertInstanceOf(Literal.class, S); assertEquals("42", ((Literal)S).getLexicalForm()); } + @Test public void testCreateBlankFromNode() { RDFNode S = model.getRDFNode(NodeCreateUtils.create("_Blank")); JenaTestLib.assertInstanceOf(Resource.class, S); assertEquals(new AnonId("_Blank"), ((Resource)S).getId()); } + @Test public void testIsEmpty() { Statement S1 = ModelTestLib.statement(model, "model rdf:type nonEmpty"); Statement S2 = ModelTestLib.statement(model, "pinky rdf:type Pig"); @@ -96,6 +97,7 @@ public void testIsEmpty() { assertTrue(model.isEmpty()); } + @Test public void testContainsResource() { ModelTestLib.modelAdd(model, "x R y; _a P _b"); assertTrue(model.containsResource(ModelTestLib.resource(model, "x"))); @@ -112,6 +114,7 @@ public void testContainsResource() { * Test the new version of getProperty(), which delivers null for not-found * properties. */ + @Test public void testGetProperty() { ModelTestLib.modelAdd(model, "x P a; x P b; x R c"); Resource x = ModelTestLib.resource(model, "x"); @@ -125,6 +128,7 @@ public void testGetProperty() { * Tests {@link Resource#getProperty(Property, String)} and * {@link Resource#getRequiredProperty(Property, String)}. */ + @Test public void testGetPropertyWithLanguage() { model.add(ModelTestLib.resource(model, "x"), ModelTestLib.property(model, "P"), "a", "pt"); model.add(ModelTestLib.resource(model, "x"), ModelTestLib.property(model, "P"), "b", "en"); @@ -145,16 +149,16 @@ public void testGetPropertyWithLanguage() { final Resource x = ModelTestLib.resource(model, "x"); assertEquals("a", x.getRequiredProperty(ModelTestLib.property(model, "P"), "pt").getString()); assertEquals("b", x.getRequiredProperty(ModelTestLib.property(model, "P"), "en").getString()); - try { - x.getRequiredProperty(ModelTestLib.property(model, "P"), "ja"); - fail("Must thrown PropertyNotFoundException."); - } catch (PropertyNotFoundException e) {} + assertThrows(PropertyNotFoundException.class, + ()->x.getRequiredProperty(ModelTestLib.property(model, "P"), "ja"), + "Must thrown PropertyNotFoundException."); final Literal l = x.getRequiredProperty(ModelTestLib.property(model, "R")).getLiteral(); assertTrue("d".equals(l.getString()) || "e".equals(l.getString())); assertTrue("de".equals(l.getLanguage()) || "fr".equals(l.getLanguage())); } } + @Test public void testToStatement() { Triple t = GraphTestLib.triple("a P b"); Statement s = model.asStatement(t); @@ -163,6 +167,7 @@ public void testToStatement() { assertEquals(GraphTestLib.node("b"), s.getObject().asNode()); } + @Test public void testAsRDF() { testPresentAsRDFNode(GraphTestLib.node("a"), Resource.class); testPresentAsRDFNode(GraphTestLib.node("17"), Literal.class); @@ -175,21 +180,21 @@ private void testPresentAsRDFNode(Node n, Class nodeClass) { JenaTestLib.assertInstanceOf(nodeClass, r); } + @Test public void testURINodeAsResource() { Node n = GraphTestLib.node("a"); Resource r = model.wrapAsResource(n); assertSame(n, r.asNode()); } + @Test public void testLiteralNodeAsResourceFails() { - try { - model.wrapAsResource(GraphTestLib.node("17")); - fail("should fail to convert literal to Resource"); - } catch (UnsupportedOperationException e) { - JenaTestLib.pass(); - } + assertThrows(UnsupportedOperationException.class, + ()->model.wrapAsResource(GraphTestLib.node("17")), + "should fail to convert literal to Resource"); } + @Test public void testRemoveAll() { testRemoveAll(""); testRemoveAll("a RR b"); @@ -200,7 +205,7 @@ public void testRemoveAll() { protected void testRemoveAll(String statements) { ModelTestLib.modelAdd(model, statements); assertSame(model, model.removeAll()); - assertEquals("model should have size 0 following removeAll(): ", 0, model.size()); + assertEquals(0, model.size(), "model should have size 0 following removeAll(): "); } /** @@ -229,6 +234,7 @@ protected void testRemoveAll(String statements) { * mean emptiness isn't available. This is why we go round the houses and test * that expected ~= initialContent + addedStuff - removed - initialContent. */ + @Test public void testRemoveSPO() { ModelCom mc = (ModelCom)ModelFactory.createDefaultModel(); for ( String[] aCase : cases ) { @@ -249,6 +255,7 @@ public void testRemoveSPO() { } } + @Test public void testIsClosedDelegatedToGraph() { Model m = newModel(); assertFalse(m.isClosed()); diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java index bd789ea41f0..4810dd31220 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java @@ -53,7 +53,7 @@ static public TestSuite suite() { // ** COMPLEX addTest(ts, "Model1", org.apache.jena.rdf.model.TS3_Model1.suite()); // ** COMPLEX - addTest(ts, "Default Model", org.apache.jena.rdf.model.TestDefaultModel.suite()); +//JU6 addTest(ts, "Default Model", org.apache.jena.rdf.model.TestDefaultModel.suite()); // Test suite building addTest(ts, "XML Input [ARP1]", org.apache.jena.rdfxml.arp1tests.TS3_xmlinput1.suite()); diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java index 5a2c797abe8..22962c3246f 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java @@ -34,6 +34,7 @@ import org.apache.jena.memvalue.TS6_GraphMemValue; import org.apache.jena.ontology.impl.TS6_ont; import org.apache.jena.ontology.makers.TS6_ModelMakers; +import org.apache.jena.rdf.model.TS6_Model; import org.apache.jena.rdfxml.xmloutput.TS6_xmloutput; import org.apache.jena.shared.TS6_SharedPackage; import org.apache.jena.util.TS6_coreutil; @@ -55,6 +56,8 @@ TS6_GraphMem.class, TS6_GraphMemValue.class, + TS6_Model.class, + TS6_xmloutput.class, TS6_coreutil.class, From 68b7c9536c1eecd68b85a9e5a8d692e59335a451 Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Mon, 7 Sep 2026 16:46:34 +0100 Subject: [PATCH 05/12] GH-3236: Convert rdf.model to JUnit6 --- .../AbstractTestPrefixMapping_JU6.java | 510 ++++++++++++++++++ .../jena/graph/compose/TS3_compose.java | 82 --- .../compose/TS6_compose.java} | 29 +- .../apache/jena/graph/compose/TestDelta.java | 29 +- .../jena/graph/compose/TestDifference.java | 68 +-- .../jena/graph/compose/TestDisjointUnion.java | 18 +- .../apache/jena/graph/compose/TestDyadic.java | 30 +- .../jena/graph/compose/TestIntersection.java | 66 +-- .../jena/graph/compose/TestMultiUnion.java | 113 ++-- .../graph/compose/TestMultiUnionReifier.java | 73 --- .../compose/TestPolyadicPrefixMapping.java | 25 +- .../apache/jena/graph/compose/TestUnion.java | 14 +- .../rdf/model/AbstractContainerMethods.java | 73 +-- .../jena/rdf/model/AbstractModelTestBase.java | 98 ++-- .../jena/rdf/model/AbstractTestPackage.java | 130 ----- .../jena/rdf/model/IsomorphicTests.java | 324 ----------- .../org/apache/jena/rdf/model/TS6_Model.java | 51 +- .../jena/rdf/model/TestAddAndContains.java | 90 ++-- .../apache/jena/rdf/model/TestAddModel.java | 33 +- .../apache/jena/rdf/model/TestAltMethods.java | 46 +- .../org/apache/jena/rdf/model/TestAnonID.java | 22 +- .../apache/jena/rdf/model/TestBagMethods.java | 9 +- .../jena/rdf/model/TestConcurrency.java | 271 +++++----- .../rdf/model/TestContainerConstructors.java | 42 +- .../apache/jena/rdf/model/TestContainers.java | 17 +- .../apache/jena/rdf/model/TestContains.java | 69 +-- .../jena/rdf/model/TestCopyInOutOfModel.java | 49 +- ...ltModel_JU6.java => TestDefaultModel.java} | 2 +- .../jena/rdf/model/TestGetFromModel.java | 44 +- .../jena/rdf/model/TestHiddenStatements.java | 15 +- .../apache/jena/rdf/model/TestIterators.java | 53 +- .../org/apache/jena/rdf/model/TestList.java | 145 ++--- .../jena/rdf/model/TestListStatements.java | 40 +- .../jena/rdf/model/TestListSubjects.java | 37 +- .../jena/rdf/model/TestListSubjectsEtc.java | 38 +- .../jena/rdf/model/TestLiteralImpl.java | 47 +- .../apache/jena/rdf/model/TestLiterals.java | 92 ++-- .../jena/rdf/model/TestLiteralsInModel.java | 54 +- .../org/apache/jena/rdf/model/TestModel.java | 98 ++-- .../jena/rdf/model/TestModelBulkUpdate.java | 37 +- .../jena/rdf/model/TestModelEvents.java | 98 ++-- .../jena/rdf/model/TestModelFactory.java | 24 +- .../jena/rdf/model/TestModelPolymorphism.java | 21 +- .../apache/jena/rdf/model/TestModelRead.java | 29 +- .../rdf/model/TestModelSetOperations.java | 72 +-- .../apache/jena/rdf/model/TestNamespace.java | 26 +- .../rdf/model/TestObjectOfProperties.java | 35 +- .../apache/jena/rdf/model/TestObjects.java | 49 +- .../apache/jena/rdf/model/TestProperties.java | 16 +- .../apache/jena/rdf/model/TestRDFNodes.java | 161 +++--- .../jena/rdf/model/TestRDFWriterMap.java | 122 ----- .../jena/rdf/model/TestReaderEvents.java | 17 +- .../apache/jena/rdf/model/TestReaders.java | 29 +- .../apache/jena/rdf/model/TestRemoveSPO.java | 21 +- .../jena/rdf/model/TestResourceFactory.java | 88 +-- .../jena/rdf/model/TestResourceImpl.java | 100 ++-- .../jena/rdf/model/TestResourceMethods.java | 76 ++- .../apache/jena/rdf/model/TestResources.java | 167 +++--- .../apache/jena/rdf/model/TestSeqMethods.java | 317 +++++------ .../rdf/model/TestSimpleListStatements.java | 72 ++- .../jena/rdf/model/TestStatementCreation.java | 103 ++-- .../jena/rdf/model/TestStatementMethods.java | 181 ++++--- .../jena/rdf/model/TestStatementTerms.java | 49 +- .../apache/jena/rdf/model/TestStatements.java | 52 +- .../jena/rdf/model/helpers/ModelCreators.java | 68 +++ .../jena/rdf/model/helpers/ModelHelper.java | 28 - .../apache/jena/test/JenaCoreTestAll_JU4.java | 4 +- .../apache/jena/test/JenaCoreTestAll_JU6.java | 3 + 68 files changed, 2701 insertions(+), 2410 deletions(-) create mode 100644 jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping_JU6.java delete mode 100644 jena-core/src/test/java/org/apache/jena/graph/compose/TS3_compose.java rename jena-core/src/test/java/org/apache/jena/{rdf/model/TS3_Model1.java => graph/compose/TS6_compose.java} (61%) mode change 100755 => 100644 jena-core/src/test/java/org/apache/jena/graph/compose/TestDelta.java mode change 100755 => 100644 jena-core/src/test/java/org/apache/jena/graph/compose/TestDifference.java mode change 100755 => 100644 jena-core/src/test/java/org/apache/jena/graph/compose/TestDyadic.java mode change 100755 => 100644 jena-core/src/test/java/org/apache/jena/graph/compose/TestIntersection.java mode change 100755 => 100644 jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnion.java delete mode 100644 jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnionReifier.java mode change 100755 => 100644 jena-core/src/test/java/org/apache/jena/graph/compose/TestUnion.java delete mode 100644 jena-core/src/test/java/org/apache/jena/rdf/model/AbstractTestPackage.java delete mode 100644 jena-core/src/test/java/org/apache/jena/rdf/model/IsomorphicTests.java rename jena-core/src/test/java/org/apache/jena/rdf/model/{TestDefaultModel_JU6.java => TestDefaultModel.java} (99%) delete mode 100644 jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFWriterMap.java create mode 100644 jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelCreators.java diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping_JU6.java b/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping_JU6.java new file mode 100644 index 00000000000..243b1093ea0 --- /dev/null +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping_JU6.java @@ -0,0 +1,510 @@ +/* + * 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 + * + * https://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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.apache.jena.graph.compose; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.jena.shared.PrefixMapping; +import org.apache.jena.test.JenaTestLib; + +/** + * Test prefix mappings - subclass this test and override getMapping() to deliver the + * prefixMapping to be tested. + */ + +public abstract class AbstractTestPrefixMapping_JU6 { + + /** + * Subclasses implement to return a new, empty prefixMapping of their preferred + * kind. + */ + abstract protected PrefixMapping getMapping(); + + static final String crispURI = "http://crisp.nosuch.net/"; + static final String ropeURI = "scheme:rope/string#"; + static final String butterURI = "ftp://ftp.nowhere.at.all/cream#"; + + /** + * The empty prefix is specifically allowed [for the default namespace]. + */ + @Test + public void testEmptyPrefix() { + addGetTest("", crispURI); + } + + @Test + public void testStrPrefix1() { + addGetTest("abc", "http://example/"); + } + + @Test + public void testStrPrefix2() { + // U+1F607 - smiling face with halo + String prefix = new String(Character.toChars(0x1F607)); + addGetTest(prefix, "http://example/"); + } + + private void addGetTest(String prefix, String uri) { + PrefixMapping pmap = getMapping(); + pmap.setNsPrefix(prefix, uri); + assertEquals(uri, pmap.getNsPrefixURI(prefix)); + } + + static final String[] badNames = {"", "foo:bar", "with a space", "-argument"}; + + /** + * Test that various illegal names are trapped. + */ + @Test + public void testCheckNames() { + PrefixMapping ns = getMapping(); + for ( String bad : badNames ) { + try { + ns.setNsPrefix(bad, crispURI); + fail("'" + bad + "' is an illegal prefix and should be trapped"); + } catch (PrefixMapping.IllegalPrefixException e) { + JenaTestLib.pass(); + } + } + } + + @Test + public void testNullURITrapped() { + try { + getMapping().setNsPrefix("xy", null); + fail("should trap null URI in setNsPrefix"); + } catch (NullPointerException e) { + JenaTestLib.pass(); + } + } + + /** + * test that a PrefixMapping maps names to URIs. The names and URIs are all fully + * distinct - overlapping names/uris are dealt with in other tests. + */ + @Test + public void testPrefixMappingMapping() { + String toast = "ftp://ftp.nowhere.not/"; + JenaTestLib.assertDiffer("crisp and toast must differ", crispURI, toast); + /* */ + PrefixMapping ns = getMapping(); + assertEquals(null, ns.getNsPrefixURI("crisp"), "crisp should be unset"); + assertEquals(null, ns.getNsPrefixURI("toast"), "toast should be unset"); + assertEquals(null, ns.getNsPrefixURI("butter"), "butter should be unset"); + /* */ + ns.setNsPrefix("crisp", crispURI); + assertEquals(crispURI, ns.getNsPrefixURI("crisp"), "crisp should be set"); + assertEquals(null, ns.getNsPrefixURI("toast"), "toast should still be unset"); + assertEquals(null, ns.getNsPrefixURI("butter"), "butter should still be unset"); + /* */ + ns.setNsPrefix("toast", toast); + assertEquals(crispURI, ns.getNsPrefixURI("crisp"), "crisp should be set"); + assertEquals(toast, ns.getNsPrefixURI("toast"), "toast should be set"); + assertEquals(null, ns.getNsPrefixURI("butter"), "butter should still be unset"); + } + + /** + * Test that we can run the prefix mapping in reverse - from URIs to prefixes. + * uriB is a prefix of uriA to try and ensure that the ordering of the map + * doesn't matter. + */ + @Test + public void testReversePrefixMapping() { + PrefixMapping ns = getMapping(); + String uriA = "http://jena.hpl.hp.com/A#", uriB = "http://jena.hpl.hp.com/"; + String uriC = "http://jena.hpl.hp.com/Csharp/"; + String prefixA = "aa", prefixB = "bb"; + ns.setNsPrefix(prefixA, uriA).setNsPrefix(prefixB, uriB); + assertEquals(null, ns.getNsURIPrefix(uriC)); + assertEquals(prefixA, ns.getNsURIPrefix(uriA)); + assertEquals(prefixB, ns.getNsURIPrefix(uriB)); + } + + /** + * test that we can extract a proper Map from a PrefixMapping + */ + @Test + public void testPrefixMappingMap() { + PrefixMapping ns = getCrispyRope(); + Map map = ns.getNsPrefixMap(); + assertEquals(2, map.size(), "map should have two elements"); + assertEquals(crispURI, map.get("crisp")); + assertEquals("scheme:rope/string#", map.get("rope")); + } + + /** + * test that the Map returned by getNsPrefixMap does not alias (parts of) the + * secret internal map of the PrefixMapping + */ + @Test + public void testPrefixMappingSecret() { + PrefixMapping ns = getCrispyRope(); + Map map = ns.getNsPrefixMap(); + // The map may be unmodifiable in which case put throws + // UnsupportedOperationException + try { + map.put("crisp", "with/onions"); + map.put("sandwich", "with/cheese"); + } catch (UnsupportedOperationException ex) {} + + assertEquals(crispURI, ns.getNsPrefixURI("crisp")); + assertEquals(ropeURI, ns.getNsPrefixURI("rope")); + assertEquals(null, ns.getNsPrefixURI("sandwich")); + } + + private PrefixMapping getCrispyRope() { + PrefixMapping ns = getMapping(); + ns.setNsPrefix("crisp", crispURI); + ns.setNsPrefix("rope", ropeURI); + return ns; + } + + /** + * these are strings that should not change when they are prefix-expanded with + * crisp and rope as legal prefixes. + */ + static final String[] dontChange = {"", "http://www.somedomain.something/whatever#", "crispy:cabbage", "cris:isOnInfiniteEarths", + "rop:tangled/web", "roped:abseiling"}; + + /** + * these are the required mappings which the test cases below should satisfy: an + * array of 2-arrays, where element 0 is the string to expand and element 1 is + * the string it should expand to. + */ + static final String[][] expansions = {{"crisp:pathPart", crispURI + "pathPart"}, {"rope:partPath", ropeURI + "partPath"}, + {"crisp:path:part", crispURI + "path:part"},}; + + @Test + public void testExpandPrefix() { + PrefixMapping ns = getMapping(); + ns.setNsPrefix("crisp", crispURI); + ns.setNsPrefix("rope", ropeURI); + /* */ + for ( String aDontChange : dontChange ) { + assertEquals(aDontChange, ns.expandPrefix(aDontChange), "should be unchanged"); + } + /* */ + for ( String[] expansion : expansions ) { + assertEquals(expansion[1], ns.expandPrefix(expansion[0]), "should expand correctly"); + } + } + + @Test + public void testUseEasyPrefix() { + testUseEasyPrefix("prefix mapping impl", getMapping()); + testShortForm("prefix mapping impl", getMapping()); + } + + public static void testUseEasyPrefix(String title, PrefixMapping ns) { + testShortForm(title, ns); + } + + public static void testShortForm(String title, PrefixMapping ns) { + ns.setNsPrefix("crisp", crispURI); + ns.setNsPrefix("butter", butterURI); + assertEquals("", ns.shortForm(""), title); + assertEquals(ropeURI, ns.shortForm(ropeURI), title); + assertEquals("crisp:tail", ns.shortForm(crispURI + "tail"), title); + assertEquals("butter:here:we:are", ns.shortForm(butterURI + "here:we:are"), title); + } + + @Test + public void testEasyQName() { + PrefixMapping ns = getMapping(); + String alphaURI = "http://seasonal.song/preamble/"; + ns.setNsPrefix("alpha", alphaURI); + assertEquals("alpha:rowboat", ns.qnameFor(alphaURI + "rowboat")); + } + + @Test + public void testNoQNameNoPrefix() { + PrefixMapping ns = getMapping(); + String alphaURI = "http://seasonal.song/preamble/"; + ns.setNsPrefix("alpha", alphaURI); + assertEquals(null, ns.qnameFor("eg:rowboat")); + } + + @Test + public void testNoQNameBadLocal() { + PrefixMapping ns = getMapping(); + String alphaURI = "http://seasonal.song/preamble/"; + ns.setNsPrefix("alpha", alphaURI); + assertEquals(null, ns.qnameFor(alphaURI + "12345")); + } + + /** + * The tests implied by the email where Chris suggested adding qnameFor; + * shortForm generates illegal qnames but qnameFor does not. + */ + @Test + public void testQnameFromEmail() { + String uri = "http://some.long.uri/for/a/namespace#"; + PrefixMapping ns = getMapping(); + ns.setNsPrefix("x", uri); + assertEquals(null, ns.qnameFor(uri)); + assertEquals(null, ns.qnameFor(uri + "non/fiction")); + } + + /** + * test that we can add the maplets from another PrefixMapping without losing our + * own. + */ + @Test + public void testAddOtherPrefixMapping() { + PrefixMapping a = getMapping(); + PrefixMapping b = getMapping(); + assertFalse(a == b, "must have two diffferent maps"); + a.setNsPrefix("crisp", crispURI); + a.setNsPrefix("rope", ropeURI); + b.setNsPrefix("butter", butterURI); + assertEquals(null, b.getNsPrefixURI("crisp")); + assertEquals(null, b.getNsPrefixURI("rope")); + b.setNsPrefixes(a); + checkContainsMapping(b); + } + + private void checkContainsMapping(PrefixMapping b) { + assertEquals(crispURI, b.getNsPrefixURI("crisp")); + assertEquals(ropeURI, b.getNsPrefixURI("rope")); + assertEquals(butterURI, b.getNsPrefixURI("butter")); + } + + /** + * as for testAddOtherPrefixMapping, except that it's a plain Map we're adding. + */ + @Test + public void testAddMap() { + PrefixMapping b = getMapping(); + Map map = new HashMap<>(); + map.put("crisp", crispURI); + map.put("rope", ropeURI); + b.setNsPrefix("butter", butterURI); + b.setNsPrefixes(map); + checkContainsMapping(b); + } + + @Test + public void testAddDefaultMap() { + PrefixMapping pm = getMapping(); + PrefixMapping root = PrefixMapping.Factory.create(); + pm.setNsPrefix("a", "aPrefix:"); + pm.setNsPrefix("b", "bPrefix:"); + root.setNsPrefix("a", "pootle:"); + root.setNsPrefix("z", "bPrefix:"); + root.setNsPrefix("c", "cootle:"); + assertSame(pm, pm.withDefaultMappings(root)); + assertEquals("aPrefix:", pm.getNsPrefixURI("a")); + assertEquals(null, pm.getNsPrefixURI("z")); + assertEquals("bPrefix:", pm.getNsPrefixURI("b")); + assertEquals("cootle:", pm.getNsPrefixURI("c")); + } + + @Test + public void testSecondPrefixRetainsExistingMap() { + PrefixMapping A = getMapping(); + A.setNsPrefix("a", crispURI); + A.setNsPrefix("b", crispURI); + assertEquals(crispURI, A.getNsPrefixURI("a")); + assertEquals(crispURI, A.getNsPrefixURI("b")); + } + + @Test + public void testSecondPrefixReplacesReverseMap() { + PrefixMapping A = getMapping(); + A.setNsPrefix("a", crispURI); + A.setNsPrefix("b", crispURI); + assertEquals("b", A.getNsURIPrefix(crispURI)); + } + + @Test + public void testSecondPrefixDeletedUncoversPreviousMap() { + PrefixMapping A = getMapping(); + A.setNsPrefix("x", crispURI); + A.setNsPrefix("y", crispURI); + A.removeNsPrefix("y"); + assertEquals("x", A.getNsURIPrefix(crispURI)); + } + + /** + * Test that the empty prefix does not wipe an existing prefix for the same URI. + */ + @Test + public void testEmptyDoesNotWipeURI() { + PrefixMapping pm = getMapping(); + pm.setNsPrefix("frodo", ropeURI); + pm.setNsPrefix("", ropeURI); + assertEquals(ropeURI, pm.getNsPrefixURI("frodo")); + } + + /** + * Test that adding a new prefix mapping for U does not throw away a default + * mapping for U. + */ + @Test + public void testSameURIKeepsDefault() { + PrefixMapping A = getMapping(); + A.setNsPrefix("", crispURI); + A.setNsPrefix("crisp", crispURI); + assertEquals(crispURI, A.getNsPrefixURI("")); + } + + @Test + public void testReturnsSelf() { + PrefixMapping A = getMapping(); + assertSame(A, A.setNsPrefix("crisp", crispURI)); + assertSame(A, A.setNsPrefixes(A)); + assertSame(A, A.setNsPrefixes(new HashMap())); + assertSame(A, A.removeNsPrefix("rhubarb")); + } + + @Test + public void testRemovePrefix() { + String hURI = "http://test.remove.prefixes/prefix#"; + String bURI = "http://other.test.remove.prefixes/prefix#"; + PrefixMapping A = getMapping(); + A.setNsPrefix("hr", hURI); + A.setNsPrefix("br", bURI); + A.removeNsPrefix("hr"); + assertEquals(null, A.getNsPrefixURI("hr")); + assertEquals(bURI, A.getNsPrefixURI("br")); + } + + @Test + public void testClear() { + String hURI = "http://test.remove.prefixes/prefix#"; + String bURI = "http://other.test.remove.prefixes/prefix#"; + PrefixMapping A = getMapping(); + A.setNsPrefix("hr", hURI); + A.setNsPrefix("br", bURI); + A.clearNsPrefixMap(); + + assertEquals(null, A.getNsPrefixURI("hr")); + assertEquals(null, A.getNsPrefixURI("br")); + + assertEquals(null, A.getNsURIPrefix(hURI)); + assertEquals(null, A.getNsURIPrefix(bURI)); + } + + @Test + public void testNoMapping() { + String hURI = "http://test.prefixes/prefix#"; + PrefixMapping A = getMapping(); + assertTrue(A.hasNoMappings()); + A.setNsPrefix("hr", hURI); + assertFalse(A.hasNoMappings()); + } + + @Test + public void testNumPrefixes() { + String hURI = "http://test.prefixes/prefix#"; + PrefixMapping A = getMapping(); + assertEquals(0, A.numPrefixes()); + A.setNsPrefix("hr", hURI); + assertEquals(1, A.numPrefixes()); + } + + @Test + public void testEquality() { + testEquals(""); + testEquals("", "x=a", false); + testEquals("x=a", "", false); + testEquals("x=a"); + testEquals("x=a y=b", "y=b x=a", true); + testEquals("x=a x=b", "x=b x=a", false); + } + + protected void testEquals(String S) { + testEquals(S, S, true); + } + + protected void testEquals(String S, String T, boolean expected) { + testEqualsBase(S, T, expected); + testEqualsBase(T, S, expected); + } + + public void testEqualsBase(String S, String T, boolean expected) { + testEquals(S, T, expected, getMapping(), getMapping()); + testEquals(S, T, expected, PrefixMapping.Factory.create(), getMapping()); + } + + protected void testEquals(String S, String T, boolean expected, PrefixMapping A, PrefixMapping B) { + fill(A, S); + fill(B, T); + String title = "usual: '" + S + "', testing: '" + T + "', should be " + (expected ? "equal" : "different"); + assertEquals(expected, A.samePrefixMappingAs(B), title); + assertEquals(expected, B.samePrefixMappingAs(A), title); + } + + protected void fill(PrefixMapping pm, String settings) { + List L = JenaTestLib.listOfStrings(settings); + for ( String setting : L ) { + int eq = setting.indexOf('='); + pm.setNsPrefix(setting.substring(0, eq), setting.substring(eq + 1)); + } + } + + // we now allow namespaces to end with non-punctuational characters + @Test + public void testAllowNastyNamespace() { + getMapping().setNsPrefix("abc", "def"); + } + + @Test + public void testLock() { + PrefixMapping A = getMapping(); + assertSame(A, A.lock()); + /* */ + try { + A.setNsPrefix("crisp", crispURI); + fail("mapping should be frozen"); + } catch (PrefixMapping.JenaLockedException e) { + JenaTestLib.pass(); + } + /* */ + try { + A.setNsPrefixes(A); + fail("mapping should be frozen"); + } catch (PrefixMapping.JenaLockedException e) { + JenaTestLib.pass(); + } + /* */ + try { + A.setNsPrefixes(new HashMap()); + fail("mapping should be frozen"); + } catch (PrefixMapping.JenaLockedException e) { + JenaTestLib.pass(); + } + /* */ + try { + A.removeNsPrefix("toast"); + fail("mapping should be frozen"); + } catch (PrefixMapping.JenaLockedException e) { + JenaTestLib.pass(); + } + } +} diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TS3_compose.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TS3_compose.java deleted file mode 100644 index e4ef07da191..00000000000 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TS3_compose.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.graph.compose; - -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.jena.graph.Graph; -import org.apache.jena.graph.GraphMemFactory; -import org.apache.jena.rdf.model.AbstractTestPackage; -import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.rdf.model.helpers.ModelCreator; - -public class TS3_compose extends TestCase { - - public static TestSuite suite() { - TestSuite result = new TestSuite(); - - ModelCreator gmf1 = ()-> { - Graph graph = new Intersection(GraphMemFactory.createGraphMemForModel(), GraphMemFactory.createGraphMemForModel()); - Model model = ModelFactory.createModelForGraph(graph); - return model; - }; - - AbstractTestPackage atp = new AbstractTestPackage("Intersection", gmf1) {}; - for ( int i = 0; i < atp.testCount(); i++ ) { - result.addTest(atp.testAt(i)); - } - - ModelCreator gmf2 = ()-> { - Graph graph = new Difference(GraphMemFactory.createGraphMemForModel(), GraphMemFactory.createGraphMemForModel()); - Model model = ModelFactory.createModelForGraph(graph); - return model; - }; - - - atp = new AbstractTestPackage("Difference", gmf2) {}; - for ( int i = 0; i < atp.testCount(); i++ ) { - result.addTest(atp.testAt(i)); - } - - ModelCreator gmf3 = ()-> { - Graph graph = new Union(GraphMemFactory.createGraphMemForModel(), GraphMemFactory.createGraphMemForModel()); - Model model = ModelFactory.createModelForGraph(graph); - return model; - }; - - atp = new AbstractTestPackage("Union", gmf3) {}; - for ( int i = 0; i < atp.testCount(); i++ ) { - result.addTest(atp.testAt(i)); - } - /* */ - result.addTest(TestDelta.suite()); - result.addTest(TestUnion.suite()); - result.addTest(TestDisjointUnion.suite()); - result.addTest(TestDifference.suite()); - result.addTest(TestIntersection.suite()); - result.addTest(TestMultiUnion.suite()); - /* */ - result.addTest(TestPolyadicPrefixMapping.suite()); - return result; - } -} diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TS3_Model1.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TS6_compose.java similarity index 61% rename from jena-core/src/test/java/org/apache/jena/rdf/model/TS3_Model1.java rename to jena-core/src/test/java/org/apache/jena/graph/compose/TS6_compose.java index 762f6be3d34..142c96dc7ab 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TS3_Model1.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TS6_compose.java @@ -19,20 +19,29 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.apache.jena.rdf.model; +package org.apache.jena.graph.compose; -import junit.framework.TestSuite; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import org.junit.platform.suite.api.BeforeSuite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; +import org.apache.jena.test.JenaTestLib; -public class TS3_Model1 extends AbstractTestPackage { - // AbstractTestPackage creates a large test suite of many test classes. +@Suite +@SelectClasses({ + TestDelta.class, + TestUnion.class, + TestDisjointUnion.class, + TestDifference.class, + TestIntersection.class, + TestMultiUnion.class, - static public TestSuite suite() { - return new TS3_Model1(); - } + TestPolyadicPrefixMapping.class +}) - public TS3_Model1() { - super("Model", ModelCreator.plain); +public class TS6_compose { + @BeforeSuite + public static void beforeSuite() { + JenaTestLib.setup(); } } diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDelta.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDelta.java old mode 100755 new mode 100644 index 00406844e1e..8220654077d --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDelta.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDelta.java @@ -21,36 +21,33 @@ package org.apache.jena.graph.compose; -import junit.framework.TestSuite; -import org.apache.jena.graph.AbstractTestGraph; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +import org.apache.jena.graph.BaseTestGraph_JU6; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphTestLib; import org.apache.jena.graph.Triple; -public class TestDelta extends AbstractTestGraph { +public class TestDelta extends BaseTestGraph_JU6 { private static final String DEFAULT_TRIPLES = "x R y; p S q"; - public TestDelta(String name) { - super(name); - } - - public static TestSuite suite() { - return new TestSuite(TestDelta.class); - } - @Override public Graph getNewGraph() { Graph gBase = GraphTestLib.graphWith(""); return new Delta(gBase); } + @Test public void testDeltaMirrorsBase() { Graph base = GraphTestLib.graphWith(DEFAULT_TRIPLES); Delta delta = new Delta(base); GraphTestLib.assertIsomorphic(base, delta); } + @Test public void testAddGoesToAdditions() { Graph base = GraphTestLib.graphWith(DEFAULT_TRIPLES); Delta delta = new Delta(base); @@ -61,6 +58,7 @@ public void testAddGoesToAdditions() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith(DEFAULT_TRIPLES + "; x R z"), delta); } + @Test public void testDeleteGoesToDeletions() { Graph base = GraphTestLib.graphWith(DEFAULT_TRIPLES); Delta delta = new Delta(base); @@ -70,6 +68,7 @@ public void testDeleteGoesToDeletions() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith("p S q"), delta); } + @Test public void testRedundantAddNoOp() { Graph base = GraphTestLib.graphWith(DEFAULT_TRIPLES); Delta delta = new Delta(base); @@ -80,6 +79,7 @@ public void testRedundantAddNoOp() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith(DEFAULT_TRIPLES), delta); } + @Test public void testRedundantDeleteNoOp() { Graph base = GraphTestLib.graphWith(DEFAULT_TRIPLES); Delta delta = new Delta(base); @@ -90,6 +90,7 @@ public void testRedundantDeleteNoOp() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith(DEFAULT_TRIPLES), delta); } + @Test public void testAddThenDelete() { Graph base = GraphTestLib.graphWith(DEFAULT_TRIPLES); Delta delta = new Delta(base); @@ -101,6 +102,7 @@ public void testAddThenDelete() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith(DEFAULT_TRIPLES), delta); } + @Test public void testDeleteThenAdd() { Graph base = GraphTestLib.graphWith(DEFAULT_TRIPLES); Delta delta = new Delta(base); @@ -112,6 +114,7 @@ public void testDeleteThenAdd() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith(DEFAULT_TRIPLES), delta); } + @Test public void testAddAndDelete() { Graph base = GraphTestLib.graphWith(DEFAULT_TRIPLES); Delta delta = new Delta(base); @@ -125,6 +128,7 @@ public void testAddAndDelete() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith("x R y; x R z; a T b"), delta); } + @Test public void testTerms1() { Triple t1 = GraphTestLib.triple("s p 1"); Triple t01 = GraphTestLib.triple("s p 01"); @@ -140,6 +144,7 @@ public void testTerms1() { assertTrue(delta.contains(t01)); } + @Test public void testTerms2() { Triple t1 = GraphTestLib.triple("s p 1"); Triple t01 = GraphTestLib.triple("s p 01"); @@ -153,6 +158,7 @@ public void testTerms2() { assertFalse(delta.getAdditions().contains(GraphTestLib.triple("s p 1"))); } + @Test public void testTerms3() { Triple t1 = GraphTestLib.triple("s p 1"); Triple t01 = GraphTestLib.triple("s p 01"); @@ -170,6 +176,7 @@ public void testTerms3() { assertFalse(delta.getAdditions().contains(t01)); } + @Test public void testTerms4() { Triple t1 = GraphTestLib.triple("s p 1"); Triple t01 = GraphTestLib.triple("s p 01"); diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDifference.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDifference.java old mode 100755 new mode 100644 index eaab0bff9cf..f41761050dc --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDifference.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDifference.java @@ -21,17 +21,13 @@ package org.apache.jena.graph.compose; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphTestLib; public class TestDifference extends TestDyadic { - public TestDifference( String name ) - { super( name ); } - - public static TestSuite suite() - { return new TestSuite( TestDifference.class ); } @Override public Graph getNewGraph() @@ -44,74 +40,78 @@ public Difference differenceOf(String s1, String s2) { return new Difference( GraphTestLib.graphWith( s1 ), GraphTestLib.graphWith( s2 ) ); } + @Test public void testStaticDifference() { - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), differenceOf( "", "" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y" ), differenceOf( "x R y", "" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), differenceOf( "", "x R y" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), differenceOf( "x R y", "x R y" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "p R q" ), differenceOf( "x R y; p R q", "r A s; x R y" ) ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), differenceOf( "", "" ) ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y" ), differenceOf( "x R y", "" ) ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), differenceOf( "", "x R y" ) ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), differenceOf( "x R y", "x R y" ) ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "p R q" ), differenceOf( "x R y; p R q", "r A s; x R y" ) ); } + @Test public void testDifferenceReflectsChangesToOperands() { Graph l = GraphTestLib.graphWith( "x R y" ); Graph r = GraphTestLib.graphWith( "x R y" ); Difference diff = new Difference( l, r ); GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), diff); r.delete( GraphTestLib.triple( "x R y" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y" ), diff ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y" ), diff ); l.add( GraphTestLib.triple( "x R z" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y; x R z" ), diff ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y; x R z" ), diff ); r.add( GraphTestLib.triple( "x R z" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y" ), diff ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y" ), diff ); } + @Test public void testAdd() { Graph l = GraphTestLib.graphWith( "x R y" ); Graph r = GraphTestLib.graphWith( "x R y; x R z" ); Difference diff = new Difference( l, r ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), diff ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), diff ); // case 1: add to the left operand diff.add( GraphTestLib.triple( "p S q" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "p S q" ), diff ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y; p S q" ), l ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y; x R z" ), r ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "p S q" ), diff ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y; p S q" ), l ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y; x R z" ), r ); // case 2: remove from the right, and add to the left operand diff.add( GraphTestLib.triple( "x R z" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R z; p S q" ), diff ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y; x R z; p S q" ), l ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y" ), r ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R z; p S q" ), diff ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y; x R z; p S q" ), l ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y" ), r ); // case 3: remove from the right operand diff.add( GraphTestLib.triple( "x R y" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y; x R z; p S q" ), diff ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y; x R z; p S q" ), l ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), r ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y; x R z; p S q" ), diff ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y; x R z; p S q" ), l ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), r ); } + @Test public void testDelete() { Graph l = GraphTestLib.graphWith( "x R y; x R z" ); Graph r = GraphTestLib.graphWith( "x R y" ); Difference diff = new Difference( l, r ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R z" ), diff ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R z" ), diff ); // case 1: remove non-existent triple is a no-op diff.delete( GraphTestLib.triple( "p S q" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R z" ), diff ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y; x R z" ), l ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y" ), r ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R z" ), diff ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y; x R z" ), l ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y" ), r ); // case 2: remove triple that exists in both - removes from left diff.delete( GraphTestLib.triple( "x R y" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R z" ), diff ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R z" ), l ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y" ), r ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R z" ), diff ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R z" ), l ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y" ), r ); // case 3: remove triple that exists in left is removed diff.delete( GraphTestLib.triple( "x R z" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), diff ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), l ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y" ), r ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), diff ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), l ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y" ), r ); } } diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDisjointUnion.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDisjointUnion.java index 5c2058b3819..1290609ba16 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDisjointUnion.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDisjointUnion.java @@ -21,7 +21,10 @@ package org.apache.jena.graph.compose; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphTestLib; @@ -29,13 +32,6 @@ * TestDisjointUnion - test that DisjointUnion works, as well as we can. */ public class TestDisjointUnion extends TestDyadic { - public TestDisjointUnion(String name) { - super(name); - } - - public static TestSuite suite() { - return new TestSuite(TestDisjointUnion.class); - } @Override public Graph getNewGraph() { @@ -43,16 +39,19 @@ public Graph getNewGraph() { return new DisjointUnion(gBase, g1); } + @Test public void testEmptyUnion() { DisjointUnion du = new DisjointUnion(Graph.emptyGraph, Graph.emptyGraph); assertEquals(true, du.isEmpty()); } + @Test public void testLeftUnion() { Graph g = GraphTestLib.graphWith(""); testSingleComponent(g, new DisjointUnion(g, Graph.emptyGraph)); } + @Test public void testRightUnion() { Graph g = GraphTestLib.graphWith(""); testSingleComponent(g, new DisjointUnion(Graph.emptyGraph, g)); @@ -67,6 +66,7 @@ protected void testSingleComponent(Graph g, DisjointUnion du) { GraphTestLib.assertIsomorphic(g, du); } + @Test public void testBothComponents() { Graph L = GraphTestLib.graphWith(""), R = GraphTestLib.graphWith(""); Graph du = new DisjointUnion(L, R); @@ -77,6 +77,7 @@ public void testBothComponents() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith("x P y; A rdf:type Route"), du); } + @Test public void testRemoveBoth() { Graph L = GraphTestLib.graphWith("x R y; a P b"), R = GraphTestLib.graphWith("x R y; p Q r"); Graph du = new DisjointUnion(L, R); @@ -85,6 +86,7 @@ public void testRemoveBoth() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith("p Q r"), R); } + @Test public void testAddLeftOnlyIfNecessary() { Graph L = GraphTestLib.graphWith(""), R = GraphTestLib.graphWith("x R y"); Graph du = new DisjointUnion(L, R); diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDyadic.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDyadic.java old mode 100755 new mode 100644 index 87848944f8a..cd0fd3e695c --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDyadic.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDyadic.java @@ -21,24 +21,20 @@ package org.apache.jena.graph.compose; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.StringTokenizer; -import junit.framework.TestSuite; -import org.apache.jena.graph.AbstractTestGraph; +import org.apache.jena.graph.BaseTestGraph_JU6; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphMemFactory; import org.apache.jena.graph.Triple; import org.apache.jena.util.iterator.ExtendedIterator; import org.apache.jena.util.iterator.NiceIterator; -public abstract class TestDyadic extends AbstractTestGraph { - public TestDyadic(String name) { - super(name); - } - - public static TestSuite suite() { - return new TestSuite(TestDyadic.class); - } +public abstract class TestDyadic extends BaseTestGraph_JU6 { static private ExtendedIterator things(final String x) { return new NiceIterator() { @@ -58,19 +54,21 @@ public String next() { /** * Test the things() iterator generating utility function. */ + @Test public void testThings() { ExtendedIterator it1 = things("now is the time"); ExtendedIterator it2 = things("now is the time"); ExtendedIterator mt1 = things(""); ExtendedIterator mt2 = things(""); - assertEquals("mt1.hasNext()", false, mt1.hasNext()); - assertEquals("mt2.hasNext()", false, mt2.hasNext()); - assertEquals("andThen(mt1,mt2).hasNext()", false, mt1.andThen(mt2).hasNext()); - assertEquals("butNot(it1,it2).hasNext()", false, CompositionBase.butNot(it1, it2).hasNext()); - assertEquals("x y z @butNot z", true, CompositionBase.butNot(things("x y z"), things("z")).hasNext()); - assertEquals("x y z @butNot a", true, CompositionBase.butNot(things("x y z"), things("z")).hasNext()); + assertEquals(false, mt1.hasNext(), "mt1.hasNext()"); + assertEquals(false, mt2.hasNext(), "mt2.hasNext()"); + assertEquals(false, mt1.andThen(mt2).hasNext(), "andThen(mt1,mt2).hasNext()"); + assertEquals(false, CompositionBase.butNot(it1, it2).hasNext(), "butNot(it1,it2).hasNext()"); + assertEquals(true, CompositionBase.butNot(things("x y z"), things("z")).hasNext(), "x y z @butNot z"); + assertEquals(true, CompositionBase.butNot(things("x y z"), things("z")).hasNext(), "x y z @butNot a"); } + @Test public void testDyadicOperands() { Graph g = GraphMemFactory.createDefaultGraph(); Graph h = GraphMemFactory.createDefaultGraph(); diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestIntersection.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestIntersection.java old mode 100755 new mode 100644 index 5fb47d88226..9853ca063e3 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestIntersection.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestIntersection.java @@ -21,17 +21,13 @@ package org.apache.jena.graph.compose; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphTestLib; public class TestIntersection extends TestDyadic { - public TestIntersection( String name ) - { super( name ); } - - public static TestSuite suite() - { return new TestSuite( TestIntersection.class ); } @Override public Graph getNewGraph() @@ -44,80 +40,84 @@ public Intersection intersectionOf(String s1, String s2) { return new Intersection( GraphTestLib.graphWith( s1 ), GraphTestLib.graphWith( s2 ) ); } + @Test public void testStaticIntersection() { - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), intersectionOf( "", "" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), intersectionOf( "x R y", "" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), intersectionOf( "", "x R y" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y" ), intersectionOf( "x R y", "x R y" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y" ), intersectionOf( "x R y; p R q", "r A s; x R y" ) ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), intersectionOf( "", "" ) ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), intersectionOf( "x R y", "" ) ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), intersectionOf( "", "x R y" ) ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y" ), intersectionOf( "x R y", "x R y" ) ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y" ), intersectionOf( "x R y; p R q", "r A s; x R y" ) ); } + @Test public void testIntersectionReflectsChangesToOperands() { Graph l = GraphTestLib.graphWith( "x R y" ); Graph r = GraphTestLib.graphWith( "p S q" ); Intersection isec = new Intersection( l, r ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), isec ); // add to the left what is already in the right l.add( GraphTestLib.triple( "p S q" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "p S q" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "p S q" ), isec ); // add to the right what is already in the left r.add( GraphTestLib.triple( "x R y" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "p S q; x R y" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "p S q; x R y" ), isec ); // add to a single graph is not reflected l.add( GraphTestLib.triple( "p S o" ) ); r.add( GraphTestLib.triple( "x R z" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "p S q; x R y" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "p S q; x R y" ), isec ); // remove from the left l.delete( GraphTestLib.triple( "x R y" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "p S q" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "p S q" ), isec ); // remove from the right r.delete( GraphTestLib.triple( "p S q" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), isec ); } + @Test public void testAdd() { Graph l = GraphTestLib.graphWith( "x R y" ); Graph r = GraphTestLib.graphWith( "p S q" ); Intersection isec = new Intersection( l, r ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), isec ); isec.add( GraphTestLib.triple( "r A s" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "r A s" ), isec ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y; r A s" ), l ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "p S q; r A s" ), r ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "r A s" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y; r A s" ), l ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "p S q; r A s" ), r ); isec.add( GraphTestLib.triple ( "x R y" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "r A s; x R y" ), isec ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y; r A s" ), l ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "p S q; r A s; x R y" ), r ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "r A s; x R y" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y; r A s" ), l ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "p S q; r A s; x R y" ), r ); isec.add( GraphTestLib.triple ( "p S q" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "p S q; r A s; x R y" ), isec ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "p S q; r A s; x R y" ), l ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "p S q; r A s; x R y" ), r ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "p S q; r A s; x R y" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "p S q; r A s; x R y" ), l ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "p S q; r A s; x R y" ), r ); } + @Test public void testDelete() { Graph l = GraphTestLib.graphWith( "r A s; x R y" ); Graph r = GraphTestLib.graphWith( "x R y; p S q" ); Intersection isec = new Intersection( l, r ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y" ), isec ); // removing non-contained triples is a no-op isec.delete( GraphTestLib.triple( "r A s" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "r A s; x R y" ), l); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "r A s; x R y" ), l); isec.delete( GraphTestLib.triple( "p S q" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y; p S q" ), r); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y; p S q" ), r); // removing a contained triple removes it from the left operand isec.delete( GraphTestLib.triple( "x R y" ) ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "" ), isec ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "r A s" ), l ); - GraphTestLib.assertIsomorphic( GraphTestLib.graphWith( "x R y; p S q" ), r ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "" ), isec ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "r A s" ), l ); + GraphTestLib.assertIsomorphic(GraphTestLib.graphWith( "x R y; p S q" ), r ); } } diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnion.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnion.java old mode 100755 new mode 100644 index ece406e5419..27acadc03c1 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnion.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnion.java @@ -23,6 +23,9 @@ /////////////// package org.apache.jena.graph.compose; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; // Imports /////////////// @@ -31,32 +34,23 @@ import java.util.Iterator; import java.util.List; -import junit.framework.TestSuite; -import org.apache.jena.graph.AbstractTestGraph; +import org.apache.jena.graph.BaseTestGraph_JU6; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphTestLib; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; - /** *

* Unit tests for multi-union graph. *

*/ -public class TestMultiUnion extends AbstractTestGraph +public class TestMultiUnion extends BaseTestGraph_JU6 { - public TestMultiUnion( String s ) { - super( s ); - } - // External signature methods ////////////////////////////////// - public static TestSuite suite() - { return new TestSuite( TestMultiUnion.class ); } - @Override public Graph getNewGraph() { @@ -64,12 +58,13 @@ public Graph getNewGraph() return new MultiUnion( new Graph[] {gBase, g1} ); } - + @Test public void testEmptyGraph() { Graph m = new MultiUnion(); - assertEquals( "Empty model should have size zero", 0, m.size() ); + assertEquals(0, m.size(), "Empty model should have size zero"); } + @Test public void testGraphSize1() { Graph g0 = GraphTestLib.graphWith( "x p y" ); Graph g1 = GraphTestLib.graphWith( "x p z; z p zz" ); // disjoint with g0 @@ -88,19 +83,19 @@ public void testGraphSize1() { int s1 = g1.size(); int s2 = g2.size(); - assertEquals( "Size of union of g0 and g1 not correct", s0+s1, m01.size() ); - assertEquals( "Size of union of g1 and g0 not correct", s0+s1, m10.size() ); + assertEquals(s0+s1, m01.size(), "Size of union of g0 and g1 not correct"); + assertEquals(s0+s1, m10.size(), "Size of union of g1 and g0 not correct"); - assertEquals( "Size of union of g1 and g2 not correct", s1+s2, m12.size() ); - assertEquals( "Size of union of g2 and g1 not correct", s1+s2, m21.size() ); + assertEquals(s1+s2, m12.size(), "Size of union of g1 and g2 not correct"); + assertEquals(s1+s2, m21.size(), "Size of union of g2 and g1 not correct"); - assertEquals( "Size of union of g0 and g2 not correct", s0+s2 - 1, m02.size() ); - assertEquals( "Size of union of g2 and g0 not correct", s0+s2 - 1, m20.size() ); + assertEquals(s0+s2 - 1, m02.size(), "Size of union of g0 and g2 not correct"); + assertEquals(s0+s2 - 1, m20.size(), "Size of union of g2 and g0 not correct"); - assertEquals( "Size of union of g0 with itself not correct", s0, m00.size() ); + assertEquals(s0, m00.size(), "Size of union of g0 with itself not correct"); } - + @Test public void testGraphSize2() { Graph g0 = GraphTestLib.graphWith( "x p y" ); Graph g1 = GraphTestLib.graphWith( "x p z; z p zz" ); // disjoint with g0 @@ -119,19 +114,19 @@ public void testGraphSize2() { int s1 = g1.size(); int s2 = g2.size(); - assertEquals( "Size of union of g0 and g1 not correct", s0+s1, m01.size() ); - assertEquals( "Size of union of g1 and g0 not correct", s0+s1, m10.size() ); + assertEquals(s0+s1, m01.size(), "Size of union of g0 and g1 not correct"); + assertEquals(s0+s1, m10.size(), "Size of union of g1 and g0 not correct"); - assertEquals( "Size of union of g1 and g2 not correct", s1+s2, m12.size() ); - assertEquals( "Size of union of g2 and g1 not correct", s1+s2, m21.size() ); + assertEquals(s1+s2, m12.size(), "Size of union of g1 and g2 not correct"); + assertEquals(s1+s2, m21.size(), "Size of union of g2 and g1 not correct"); - assertEquals( "Size of union of g0 and g2 not correct", s0+s2 - 1, m02.size() ); - assertEquals( "Size of union of g2 and g0 not correct", s0+s2 - 1, m20.size() ); + assertEquals(s0+s2 - 1, m02.size(), "Size of union of g0 and g2 not correct"); + assertEquals(s0+s2 - 1, m20.size(), "Size of union of g2 and g0 not correct"); - assertEquals( "Size of union of g0 with itself not correct", s0, m00.size() ); + assertEquals(s0, m00.size(), "Size of union of g0 with itself not correct"); } - + @Test public void testGraphAddSize() { Graph g0 = GraphTestLib.graphWith( "x p y" ); Graph g1 = GraphTestLib.graphWith( "x p z; z p zz" ); // disjoint with g0 @@ -143,29 +138,29 @@ public void testGraphAddSize() { MultiUnion m0 = new MultiUnion( new Graph[] {g0} ); - assertEquals( "Size of union of g0 not correct", s0, m0.size() ); + assertEquals(s0, m0.size(), "Size of union of g0 not correct"); m0.addGraph( g1 ); - assertEquals( "Size of union of g1 and g0 not correct", s0+s1, m0.size() ); + assertEquals(s0+s1, m0.size(), "Size of union of g1 and g0 not correct"); m0.addGraph( g2 ); - assertEquals( "Size of union of g0, g1 and g2 not correct", s0+s1+s2 -1, m0.size() ); + assertEquals(s0+s1+s2 -1, m0.size(), "Size of union of g0, g1 and g2 not correct"); m0.removeGraph( g1 ); - assertEquals( "Size of union of g0 and g2 not correct", s0+s2 -1, m0.size() ); + assertEquals(s0+s2 -1, m0.size(), "Size of union of g0 and g2 not correct"); m0.removeGraph( g0 ); - assertEquals( "Size of union of g2 not correct", s2, m0.size() ); + assertEquals(s2, m0.size(), "Size of union of g2 not correct"); // remove again m0.removeGraph( g0 ); - assertEquals( "Size of union of g2 not correct", s2, m0.size() ); + assertEquals(s2, m0.size(), "Size of union of g2 not correct"); m0.removeGraph( g2 ); - assertEquals( "Size of empty union not correct", 0, m0.size() ); + assertEquals(0, m0.size(), "Size of empty union not correct"); } - + @Test public void testAdd() { Graph g0 = GraphTestLib.graphWith( "x p y" ); Graph g1 = GraphTestLib.graphWith( "x p z; z p zz" ); // disjoint with g0 @@ -181,9 +176,9 @@ public void testAdd() { // add a triple to the union m.add( GraphTestLib.triple( "a q b" ) ); - assertEquals( "m.size should have increased by one", m0 + 1, m.size() ); - assertEquals( "g0.size should have increased by one", s0 + 1, g0.size() ); - assertEquals( "g1 size should be constant", s1, g1.size() ); + assertEquals(m0 + 1, m.size(), "m.size should have increased by one"); + assertEquals(s0 + 1, g0.size(), "g0.size should have increased by one"); + assertEquals(s1, g1.size(), "g1 size should be constant"); // change the designated receiver and try again m.setBaseGraph( g1 ); @@ -195,9 +190,9 @@ public void testAdd() { m.add( GraphTestLib.triple( "a1 q b1" )); - assertEquals( "m.size should have increased by one", m0 + 1, m.size() ); - assertEquals( "g0 size should be constant", s0, g0.size() ); - assertEquals( "g1.size should have increased by one", s1 + 1, g1.size() ); + assertEquals(m0 + 1, m.size(), "m.size should have increased by one"); + assertEquals(s0, g0.size(), "g0 size should be constant"); + assertEquals(s1 + 1, g1.size(), "g1.size should have increased by one"); // check that we can't make g2 the designated updater boolean expected = false; @@ -207,10 +202,10 @@ public void testAdd() { catch (IllegalArgumentException e) { expected = true; } - assertTrue( "Should not have been able to make g2 the updater", expected ); + assertTrue(expected, "Should not have been able to make g2 the updater"); } - + @Test public void testDelete() { Graph g0 = GraphTestLib.graphWith( "x p y" ); Graph g1 = GraphTestLib.graphWith( "x p z; z p zz" ); // disjoint with g0 @@ -234,50 +229,49 @@ public void testDelete() { checkDeleteSizes( 0, 0, 0, g0, g1, m ); } - + @Test public void testContains() { Graph g0 = GraphTestLib.graphWith( "x p y" ); Graph g1 = GraphTestLib.graphWith( "x p z; z p zz" ); // disjoint with g0 MultiUnion m = new MultiUnion( new Graph[] {g0, g1} ); - assertTrue( "m should contain triple", m.contains( GraphTestLib.triple( "x p y "))); - assertTrue( "m should contain triple", m.contains( GraphTestLib.triple( "x p z "))); - assertTrue( "m should contain triple", m.contains( GraphTestLib.triple( "z p zz "))); + assertTrue(m.contains( GraphTestLib.triple( "x p y ")), "m should contain triple"); + assertTrue(m.contains( GraphTestLib.triple( "x p z ")), "m should contain triple"); + assertTrue(m.contains( GraphTestLib.triple( "z p zz ")), "m should contain triple"); - assertFalse( "m should not contain triple", m.contains( GraphTestLib.triple( "zz p z "))); + assertFalse(m.contains( GraphTestLib.triple( "zz p z ")), "m should not contain triple"); } - /* Test using a model to wrap a multi union */ + @Test public void testModel() { Graph g0 = GraphTestLib.graphWith( "x p y" ); MultiUnion u = new MultiUnion( new Graph[] {g0} ); Model m = ModelFactory.createModelForGraph( u ); - assertEquals( "Model size not correct", 1, m.size() ); + assertEquals(1, m.size(), "Model size not correct"); Graph g1 = GraphTestLib.graphWith( "x p z; z p zz" ); // disjoint with g0 u.addGraph( g1 ); - assertEquals( "Model size not correct", 3, m.size() ); + assertEquals(3, m.size(), "Model size not correct"); // adds one more statement to the model m.read( GraphTestLib.getFileName("ontology/list0.rdf") ); - assertEquals( "Model size not correct", 4, m.size() ); + assertEquals(4, m.size(), "Model size not correct"); // debug m.write( System.out ); } - // Internal implementation methods ////////////////////////////////// protected void checkDeleteSizes( int s0, int s1, int m0, Graph g0, Graph g1, Graph m ) { - assertEquals( "Delete check: g0 size", s0, g0.size() ); - assertEquals( "Delete check: g1 size", s1, g1.size() ); - assertEquals( "Delete check: m size", m0, m.size() ); + assertEquals(s0, g0.size(), "Delete check: g0 size"); + assertEquals(s1, g1.size(), "Delete check: g1 size"); + assertEquals(m0, m.size(), "Delete check: m size"); } protected Iterator iterateOver( T x0 ) { @@ -299,11 +293,8 @@ protected Iterator iterateOver( T x0, T x1, T x2 ) { return l.iterator(); } - - //============================================================================== // Inner class definitions //============================================================================== - } diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnionReifier.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnionReifier.java deleted file mode 100644 index 69073fce778..00000000000 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnionReifier.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.graph.compose; - -import junit.framework.TestCase; -import org.apache.jena.graph.*; -import org.apache.jena.junit.NodeCreateUtils; -import org.apache.jena.rdf.model.impl.ReifierStd; -import org.apache.jena.util.iterator.ExtendedIterator; - -/** - Test the reifier for multi-unions. -*/ -public class TestMultiUnionReifier extends TestCase { - public TestMultiUnionReifier(String name) { - super(name); - } - - public void testX() { - MultiUnion mu = multi("a P b; !b Q c; ~c R d", ""); - for ( ExtendedIterator it = GraphUtil.findAll(mu) ; it.hasNext() ; ) { - System.err.println("]] " + it.next()); - } - } - - private MultiUnion multi( String a, String b ) - { - Graph A = graph( a ), B = graph( b ); - return new MultiUnion( new Graph[] {A, B} ); - } - - static int count = 0; - - private Graph graph(String facts) { - Graph result = GraphMemFactory.createDefaultGraph(); - String[] factArray = facts.split(";"); - for ( String aFactArray : factArray ) { - String fact = aFactArray.trim(); - if ( fact.equals("") ) - {} - else if ( fact.charAt(0) == '!' ) { - Triple t = NodeCreateUtils.createTriple(fact.substring(1)); - result.add(t); - ReifierStd.reifyAs(result, NodeCreateUtils.create("_r" + ++count), t); - } else if ( fact.charAt(0) == '~' ) { - Triple t = NodeCreateUtils.createTriple(fact.substring(1)); - ReifierStd.reifyAs(result, NodeCreateUtils.create("_r" + ++count), t); - } else { - result.add(NodeCreateUtils.createTriple(fact)); - } - } - return result; - } -} diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestPolyadicPrefixMapping.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestPolyadicPrefixMapping.java index 1f2d1ef6675..3ab3187818a 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestPolyadicPrefixMapping.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestPolyadicPrefixMapping.java @@ -21,18 +21,15 @@ package org.apache.jena.graph.compose; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.*; import org.apache.jena.shared.PrefixMapping; -public class TestPolyadicPrefixMapping extends AbstractTestPrefixMapping { - public TestPolyadicPrefixMapping(String name) { - super(name); - } - - public static TestSuite suite() { - return new TestSuite(TestPolyadicPrefixMapping.class); - } +public class TestPolyadicPrefixMapping extends AbstractTestPrefixMapping_JU6 { Graph gBase; Graph g1, g2; @@ -45,7 +42,7 @@ public static TestSuite suite() { protected static final String alpha = "something:alpha#"; protected static final String beta = "something:beta#"; - @Override + @BeforeEach public void setUp() { gBase = GraphMemFactory.createDefaultGraph(); g1 = GraphMemFactory.createDefaultGraph(); @@ -67,6 +64,7 @@ protected PrefixMapping getMapping() { * base mapping over-rides all others (c) non-overridden mappings in other maps * are visible */ + @Test public void testOnlyBaseMutated() { poly.getPrefixMapping().setNsPrefix("a", alpha); assertEquals(null, g1.getPrefixMapping().getNsPrefixURI("a")); @@ -74,6 +72,7 @@ public void testOnlyBaseMutated() { assertEquals(alpha, gBase.getPrefixMapping().getNsPrefixURI("a")); } + @Test public void testUpdatesVisible() { g1.getPrefixMapping().setNsPrefix("a", alpha); g2.getPrefixMapping().setNsPrefix("b", beta); @@ -81,12 +80,14 @@ public void testUpdatesVisible() { assertEquals(beta, poly.getPrefixMapping().getNsPrefixURI("b")); } + @Test public void testUpdatesOverridden() { g1.getPrefixMapping().setNsPrefix("x", alpha); poly.getPrefixMapping().setNsPrefix("x", beta); assertEquals(beta, poly.getPrefixMapping().getNsPrefixURI("x")); } + @Test public void testQNameComponents() { g1.getPrefixMapping().setNsPrefix("x", alpha); g2.getPrefixMapping().setNsPrefix("y", beta); @@ -98,6 +99,7 @@ public void testQNameComponents() { * Test that the default namespace of a sub-graph doesn't appear as a default * namespace of the polyadic graph. */ + @Test public void testSubgraphsDontPolluteDefaultPrefix() { String imported = "http://imported#", local = "http://local#"; g1.getPrefixMapping().setNsPrefix("", imported); @@ -105,12 +107,14 @@ public void testSubgraphsDontPolluteDefaultPrefix() { assertEquals(null, poly.getPrefixMapping().getNsURIPrefix(imported)); } + @Test public void testPolyDoesntSeeImportedDefaultPrefix() { String imported = "http://imported#"; g1.getPrefixMapping().setNsPrefix("", imported); assertEquals(null, poly.getPrefixMapping().getNsPrefixURI("")); } + @Test public void testPolyMapOverridesFromTheLeft() { g1.getPrefixMapping().setNsPrefix("a", "eh:/U1"); g2.getPrefixMapping().setNsPrefix("a", "eh:/U2"); @@ -118,6 +122,7 @@ public void testPolyMapOverridesFromTheLeft() { assertEquals("eh:/U1", a); } + @Test public void testPolyMapHandlesBase() { g1.getPrefixMapping().setNsPrefix("", "eh:/U1"); g2.getPrefixMapping().setNsPrefix("", "eh:/U2"); diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestUnion.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestUnion.java old mode 100755 new mode 100644 index cb84c93a315..07c90a0eac9 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestUnion.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestUnion.java @@ -21,18 +21,12 @@ package org.apache.jena.graph.compose; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphTestLib; public class TestUnion extends TestDyadic { - public TestUnion(String name) { - super(name); - } - - public static TestSuite suite() { - return new TestSuite(TestUnion.class); - } @Override public Graph getNewGraph() { @@ -44,6 +38,7 @@ public Union unionOf(String s1, String s2) { return new Union(GraphTestLib.graphWith(s1), GraphTestLib.graphWith(s2)); } + @Test public void testStaticUnion() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith(""), unionOf("", "")); GraphTestLib.assertIsomorphic(GraphTestLib.graphWith("x R y"), unionOf("x R y", "")); @@ -52,6 +47,7 @@ public void testStaticUnion() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith("x R y"), unionOf("x R y", "x R y")); } + @Test public void testUnionReflectsChangesToOperands() { Graph l = GraphTestLib.graphWith("x R y"); Graph r = GraphTestLib.graphWith("x R y"); @@ -72,6 +68,7 @@ public void testUnionReflectsChangesToOperands() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith("x R z; p S q"), u); } + @Test public void testAdd() { Graph l = GraphTestLib.graphWith("x R y"); Graph r = GraphTestLib.graphWith("x R y; p S q"); @@ -90,6 +87,7 @@ public void testAdd() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith("x R y; p S q"), r); } + @Test public void testDelete() { Graph l = GraphTestLib.graphWith("x R y; x R z"); Graph r = GraphTestLib.graphWith("x R y; p S q"); diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/AbstractContainerMethods.java b/jena-core/src/test/java/org/apache/jena/rdf/model/AbstractContainerMethods.java index 4e43aa4f3e9..53c6525b96e 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/AbstractContainerMethods.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/AbstractContainerMethods.java @@ -21,53 +21,56 @@ package org.apache.jena.rdf.model; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.vocabulary.RDF; public abstract class AbstractContainerMethods extends AbstractModelTestBase { protected Resource resource; - public AbstractContainerMethods(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - protected abstract Container createContainer(); protected abstract Resource getContainerType(); @Override + @BeforeEach public void setUp() { super.setUp(); resource = model.createResource(); } + @Test public void testContainerOfIntegers() { final int num = 10; final Container c = createContainer(); for ( int i = 0; i < num; i += 1 ) { c.add(i); } - Assert.assertEquals(num, c.size()); + assertEquals(num, c.size()); final NodeIterator it = c.iterator(); for ( int i = 0; i < num; i += 1 ) { - Assert.assertEquals(i, ((Literal)it.nextNode()).getInt()); + assertEquals(i, ((Literal)it.nextNode()).getInt()); } - Assert.assertFalse(it.hasNext()); + assertFalse(it.hasNext()); } + @Test public void testContainerOfIntegersRemovingA() { final boolean[] retain = {true, true, true, false, false, false, false, false, true, true}; testContainerOfIntegersWithRemoving(retain); } + @Test public void testContainerOfIntegersRemovingB() { final boolean[] retain = {false, true, true, false, false, false, false, false, true, false}; testContainerOfIntegersWithRemoving(retain); } + @Test public void testContainerOfIntegersRemovingC() { final boolean[] retain = {false, false, false, false, false, false, false, false, false, false}; testContainerOfIntegersWithRemoving(retain); @@ -90,56 +93,58 @@ protected void testContainerOfIntegersWithRemoving(final boolean[] retain) { final NodeIterator s = c.iterator(); while (s.hasNext()) { final int v = ((Literal)s.nextNode()).getInt(); - Assert.assertFalse(found[v]); + assertFalse(found[v]); found[v] = true; } for ( int i = 0; i < num; i += 1 ) { - Assert.assertEquals("element " + i, retain[i], found[i]); + assertEquals(retain[i], found[i], "element " + i); } } + @Test public void testEmptyContainer() { final Container c = createContainer(); - Assert.assertTrue(model.contains(c, RDF.type, getContainerType())); - Assert.assertEquals(0, c.size()); - Assert.assertFalse(c.contains(AbstractModelTestBase.tvBoolean)); - Assert.assertFalse(c.contains(AbstractModelTestBase.tvByte)); - Assert.assertFalse(c.contains(AbstractModelTestBase.tvShort)); - Assert.assertFalse(c.contains(AbstractModelTestBase.tvInt)); - Assert.assertFalse(c.contains(AbstractModelTestBase.tvLong)); - Assert.assertFalse(c.contains(AbstractModelTestBase.tvChar)); - Assert.assertFalse(c.contains(AbstractModelTestBase.tvFloat)); - Assert.assertFalse(c.contains(AbstractModelTestBase.tvString)); + assertTrue(model.contains(c, RDF.type, getContainerType())); + assertEquals(0, c.size()); + assertFalse(c.contains(AbstractModelTestBase.tvBoolean)); + assertFalse(c.contains(AbstractModelTestBase.tvByte)); + assertFalse(c.contains(AbstractModelTestBase.tvShort)); + assertFalse(c.contains(AbstractModelTestBase.tvInt)); + assertFalse(c.contains(AbstractModelTestBase.tvLong)); + assertFalse(c.contains(AbstractModelTestBase.tvChar)); + assertFalse(c.contains(AbstractModelTestBase.tvFloat)); + assertFalse(c.contains(AbstractModelTestBase.tvString)); } + @Test public void testFillingContainer() { final Container c = createContainer(); final String lang = "fr"; final Literal tvLiteral = model.createLiteral("test 12 string 2"); // Resource tvResObj = model.createResource( new ResTestObjF() ); c.add(AbstractModelTestBase.tvBoolean); - Assert.assertTrue(c.contains(AbstractModelTestBase.tvBoolean)); + assertTrue(c.contains(AbstractModelTestBase.tvBoolean)); c.add(AbstractModelTestBase.tvByte); - Assert.assertTrue(c.contains(AbstractModelTestBase.tvByte)); + assertTrue(c.contains(AbstractModelTestBase.tvByte)); c.add(AbstractModelTestBase.tvShort); - Assert.assertTrue(c.contains(AbstractModelTestBase.tvShort)); + assertTrue(c.contains(AbstractModelTestBase.tvShort)); c.add(AbstractModelTestBase.tvInt); - Assert.assertTrue(c.contains(AbstractModelTestBase.tvInt)); + assertTrue(c.contains(AbstractModelTestBase.tvInt)); c.add(AbstractModelTestBase.tvLong); - Assert.assertTrue(c.contains(AbstractModelTestBase.tvLong)); + assertTrue(c.contains(AbstractModelTestBase.tvLong)); c.add(AbstractModelTestBase.tvChar); - Assert.assertTrue(c.contains(AbstractModelTestBase.tvChar)); + assertTrue(c.contains(AbstractModelTestBase.tvChar)); c.add(AbstractModelTestBase.tvFloat); - Assert.assertTrue(c.contains(AbstractModelTestBase.tvFloat)); + assertTrue(c.contains(AbstractModelTestBase.tvFloat)); c.add(AbstractModelTestBase.tvString); - Assert.assertTrue(c.contains(AbstractModelTestBase.tvString)); + assertTrue(c.contains(AbstractModelTestBase.tvString)); c.add(AbstractModelTestBase.tvString, lang); - Assert.assertTrue(c.contains(AbstractModelTestBase.tvString, lang)); + assertTrue(c.contains(AbstractModelTestBase.tvString, lang)); c.add(tvLiteral); - Assert.assertTrue(c.contains(tvLiteral)); - // c.add( tvResObj ); assertTrue( c.contains( tvResObj ) ); + assertTrue(c.contains(tvLiteral)); + // c.add( tvResObj ); assertTrue(c.contains( tvResObj ) ); c.add(AbstractModelTestBase.tvLitObj); - Assert.assertTrue(c.contains(AbstractModelTestBase.tvLitObj)); - Assert.assertEquals(11, c.size()); + assertTrue(c.contains(AbstractModelTestBase.tvLitObj)); + assertEquals(11, c.size()); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/AbstractModelTestBase.java b/jena-core/src/test/java/org/apache/jena/rdf/model/AbstractModelTestBase.java index 254e8c8a64f..8bae12b51bb 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/AbstractModelTestBase.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/AbstractModelTestBase.java @@ -26,15 +26,72 @@ import java.net.URISyntaxException; import java.net.URL; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.Parameter; + import org.apache.jena.rdf.model.helpers.ModelCreator; +import org.apache.jena.rdf.model.helpers.ModelHelper; +import org.apache.jena.shared.PrefixMapping; /** - * Base for test cases about Models. All derived classes will use the getModel to get the + * Base for test cases about Models. All derived classes will use the model field for the * model created in the setUp method. createModel will create a model using the - * TestingModelFactory methods. + * {@link ModelCreator} the class is parameterized with. + *

+ * Derived classes are annotated {@code @ParameterizedClass} with + * {@code @MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators")}, + * which supplies the modelFactory field. */ -public abstract class AbstractModelTestBase extends TestCase { +public abstract class AbstractModelTestBase { + + @Parameter + protected ModelCreator modelFactory; + + protected Model model; + + /** + * Create a new model. + * + * @return A new model from the modelFactory. + */ + public final Model createModel() { + return modelFactory.create(); + } + + /** + * A new model, with the extended prefixes, containing the given facts. + * Replaces {@code ModelHelper.modelWithStatements(this, facts)}, which needed + * a {@code AbstractModelTestBase} to call back into. + */ + protected Model modelWithStatements(final String facts) { + return ModelHelper.modelAdd(createExtendedModel(), facts); + } + + /** A new model, with the extended prefixes. Replaces {@code ModelHelper.createModel(this)}. */ + protected Model createExtendedModel() { + Model result = createModel(); + result.setNsPrefixes(PrefixMapping.Extended); + return result; + } + + /** + * sets the model instance variable + */ + @BeforeEach + public void setUp() { + model = createModel(); + } + + /** + * Closes the model instance variable and shuts it down. + */ + @AfterEach + public void tearDown() { + model.close(); + model = null; + } + protected static String getFileName(final String fn) { URL u = AbstractModelTestBase.class.getClassLoader().getResource(fn); if ( u == null ) { @@ -98,37 +155,4 @@ public String toString() { protected static final double dDelta = 0.000000005; protected static final float fDelta = 0.000005f; - protected Model model; - private final ModelCreator modelFactory; - - public AbstractModelTestBase(ModelCreator modelFactory, final String name) { - super(name); - this.modelFactory = modelFactory; - } - - /** - * Create a new model. - * - * @return A new model from the modelFactory. - */ - public final Model createModel() { - return modelFactory.create(); - } - - /** - * sets the model instance variable - */ - @Override - public void setUp() { - model = createModel(); - } - - /** - * Closes the model instance variable and shuts it down. - */ - @Override - public void tearDown() { - model.close(); - model = null; - } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/AbstractTestPackage.java b/jena-core/src/test/java/org/apache/jena/rdf/model/AbstractTestPackage.java deleted file mode 100644 index 836dcb46c45..00000000000 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/AbstractTestPackage.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.rdf.model; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.List; - -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.jena.rdf.model.helpers.ModelCreator; - - -/** - * Collected test suite for the .model package. - */ -public class AbstractTestPackage extends TestSuite -{ - protected AbstractTestPackage( String suiteName, ModelCreator modelFactory ) { - super(suiteName); - - // Rewrite a Junit4/6 parameterized tests? - // Replace by creating the instance here. Test. - - addTestSuite(TestModelFactory.class); - - addTest(TestSimpleListStatements.class, modelFactory); - addTest(TestModelPolymorphism.class, modelFactory); - addTest(TestStatements.class, modelFactory); - addTest(TestRDFNodes.class, modelFactory); - addTest(TestIterators.class, modelFactory); - - addTest(TestContains.class, modelFactory); - addTest(TestLiteralImpl.class, modelFactory); - addTest(TestResourceImpl.class, modelFactory); - addTest(TestStatementTerms.class, modelFactory); - - addTest(TestHiddenStatements.class, modelFactory); - addTest(TestNamespace.class, modelFactory); - addTest(TestModelBulkUpdate.class, modelFactory); - - addTest(new TestConcurrency()); - - addTest(TestContainers.class, modelFactory); - addTest(TestModel.class, modelFactory); - addTest(TestModelSetOperations.class, modelFactory); - addTest(TestModelEvents.class, modelFactory); - addTest(TestReaderEvents.class, modelFactory); - addTest(TestList.class, modelFactory); - - //addTest(TestAnonID.class); - addTestSuite(TestAnonID.class); - - addTest(TestLiteralsInModel.class, modelFactory); - addTest(TestRemoveSPO.class, modelFactory); - addTest(TestListSubjectsEtc.class, modelFactory); - addTest(TestModelRead.class, modelFactory); - addTestSuite(TestProperties.class); - addTest(TestContainerConstructors.class, modelFactory); - addTest(TestAltMethods.class, modelFactory); - addTest(TestBagMethods.class, modelFactory); - addTest(TestSeqMethods.class, modelFactory); - addTest(TestAddAndContains.class, modelFactory); - addTest(TestAddModel.class, modelFactory); - addTest(TestGetFromModel.class, modelFactory); - addTest(TestListSubjects.class, modelFactory); - addTest(TestLiterals.class, modelFactory); - addTest(TestObjects.class, modelFactory); - addTest(TestResourceMethods.class, modelFactory); - addTest(TestResources.class, modelFactory); - addTest(TestStatementMethods.class, modelFactory); - addTest(TestStatementCreation.class, modelFactory); - addTest(TestReaders.class, modelFactory); - addTest(TestObjectOfProperties.class, modelFactory); - addTest(TestCopyInOutOfModel.class, modelFactory); - // These tests are probabilistic testing. - // See notes in the class. - //addTest(IsomorphicTests.class, modelFactory); - } - - private void addTest(final Class testClass, ModelCreator modelFactory) { - final Object[] args = new Object[2]; - args[0] = modelFactory; - - final List> parameterTypes = List.of(ModelCreator.class, String.class); - Constructor c; - try { - @SuppressWarnings("unchecked") - Constructor cc = (Constructor)testClass.getConstructor(parameterTypes.toArray(new Class[parameterTypes.size()])); - c = cc; - } catch (final SecurityException | NoSuchMethodException e) { - e.printStackTrace(); - throw new RuntimeException(e.getMessage(), e); - } - - for ( final Method m : testClass.getMethods() ) { - if ( m.getParameterTypes().length == 0 ) { - if ( m.getName().startsWith("test") ) { - args[1] = m.getName(); - try { - addTest(c.newInstance(args)); - } catch (final IllegalArgumentException | InvocationTargetException | IllegalAccessException | InstantiationException e) { - e.printStackTrace(); - throw new RuntimeException(e.getMessage(), e); - } - } - } - } - } -} \ No newline at end of file diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/IsomorphicTests.java b/jena-core/src/test/java/org/apache/jena/rdf/model/IsomorphicTests.java deleted file mode 100644 index 0cc92f78723..00000000000 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/IsomorphicTests.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.rdf.model; - -import java.util.Random; - -import org.apache.jena.rdf.model.helpers.ModelCreator; -import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; - -public class IsomorphicTests extends AbstractModelTestBase { - // This is not part of the standard test suite - // It's not stable enough for inclusion in the automatic test suite. - // Often, they pass, but there is a significant number of times they don't. - // It also seems to be machine-dependent - failures are more frequent - // on Apache Jenkins (hardware influencing "random" numbers?) - - /** - * A theoretical graph for testing purposes. All nodes are anonymous resources. - * All edges are labelled rdf:value. The basic DiHyperCube consists of the nodes - * being the corners of a hypercube (e.g. in 3D a cube) with the statements being - * the edges of the cube, directed from one corner labelled 2^n-1 to the opposite - * corner labelled 0. The labels are not present in the model. This basic graph - * is then extended, for test purposes by duplicating a node. - */ - static class DiHyperCube extends java.lang.Object { - static int bitCount(final int i) { - return java.math.BigInteger.valueOf(i).bitCount(); - } - - /* We have two DiHyperCube's to one we have added N a1's to the other we have - * added N b1's Returns true if they are equal. */ - static boolean equal(final int a1, final int b1) { - return DiHyperCube.bitCount(a1) == DiHyperCube.bitCount(b1); - } - - /* We have two DiHyperCube's to one we have added N a1's and N a2's. to the - * other we have added N b1's and N b2's. Returns true if they are equal. */ - static boolean equal(final int a1, final int a2, final int b1, final int b2) { - return (DiHyperCube.bitCount(a1 ^ a2) == DiHyperCube.bitCount(b1 ^ b2)) - && (DiHyperCube.bitCount(a1 & a2) == DiHyperCube.bitCount(b1 & b2)) - && (DiHyperCube.bitCount(a1 | a2) == DiHyperCube.bitCount(b1 | b2)) - && (Math.min(DiHyperCube.bitCount(a1), DiHyperCube.bitCount(a2)) == Math.min(DiHyperCube.bitCount(b1), - DiHyperCube.bitCount(b2))); - } - - final private Resource corners[]; - - final private int dim; - - final private Model model; - - /** Creates new DiHyperCube */ - public DiHyperCube(final int dimension, final Model m) { - dim = dimension; - model = m; - corners = new Resource[1 << dim]; - for ( int i = 0 ; i < corners.length ; i++ ) { - corners[i] = m.createResource(); - } - for ( int i = 0 ; i < corners.length ; i++ ) { - addDown(i, corners[i]); - } - } - - private void addDown(final int corner, final Resource r) { - for ( int j = 0 ; j < dim ; j++ ) { - final int bit = 1 << j; - if ( (corner & bit) != 0 ) { - model.add(r, RDF.value, corners[corner ^ bit]); - } - } - } - - DiHyperCube dupe(final int corner) { - final Resource dup = model.createResource(); - for ( int j = 0 ; j < dim ; j++ ) { - final int bit = 1 << j; - if ( (corner & bit) != 0 ) { - model.add(dup, RDF.value, corners[corner ^ bit]); - } else { - model.add(corners[corner ^ bit], RDF.value, dup); - } - } - return this; - } - - } - - /** - * A theoretical graph for testing purposes. All nodes are anonymous resources. - * All edges are labelled rdf:value. The basic HyperCube consists of the nodes - * being the corners of a hypercube (e.g. in 3D a cube) with the statements being - * the edges of the cube, in both directions. The labels are not present in the - * model. This basic graph is then extended, for test purposes by duplicating a - * node. Or by adding/deleting an edge between two nodes. - */ - static class HyperCube extends java.lang.Object { - static int bitCount(final int i) { - return java.math.BigInteger.valueOf(i).bitCount(); - } - - /* We have two HyperCube's to one we have added N a1's and M a2's. to the - * other we have added N b1's and M b2's. or we have toggled an edge between - * a1 and a2, and between b1 and b2. Returns true if they are equal. */ - static boolean equal(final int a1, final int a2, final int b1, final int b2) { - return HyperCube.bitCount(a1 ^ a2) == HyperCube.bitCount(b1 ^ b2); - } - - final private Resource corners[]; - - final private int dim; - - final private Model model; - - /** Creates new DiHyperCube */ - public HyperCube(final int dimension, final Model m) { - dim = dimension; - model = m; - corners = new Resource[1 << dim]; - for ( int i = 0 ; i < corners.length ; i++ ) { - corners[i] = m.createResource(); - } - for ( int i = 0 ; i < corners.length ; i++ ) { - add(i, corners[i]); - } - } - - private void add(final int corner, final Resource r) { - for ( int j = 0 ; j < dim ; j++ ) { - final int bit = 1 << j; - model.add(r, RDF.value, corners[corner ^ bit]); - } - } - - HyperCube dupe(final int corner) { - final Resource dup = model.createResource(); - add(corner, dup); - return this; - } - - HyperCube toggle(final int from, final int to) { - final Resource f = corners[from]; - final Resource t = corners[to]; - final Statement s = model.createStatement(f, RDF.value, t); - if ( model.contains(s) ) { - model.remove(s); - } else { - model.add(s); - } - return this; - } - - } - - private static int QUANTITY = 10; - private static int DIMENSION = 6; - private final int sz = 1 << IsomorphicTests.DIMENSION; - - private Random random; - - private Model model2; - - public IsomorphicTests(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - - @Override - public void setUp() { - super.setUp(); - random = new Random(); - model2 = createModel(); - } - - @Override - public void tearDown() { - model.close(); - super.tearDown(); - } - - private void test2DiHyperCube(int quantity, final boolean type) { - if ( IsomorphicTests.QUANTITY < 6 ) { - // (Guessing) If the number is too small, the probability - // of passing the test is too small. - return; - } - for ( int i = 0 ; i < quantity ; i++ ) { - int a1, b1; - do { - a1 = random.nextInt(sz); - b1 = random.nextInt(sz); - } while (type != DiHyperCube.equal(a1, b1)); - - new DiHyperCube(IsomorphicTests.DIMENSION, model).dupe(a1).dupe(a1).dupe(a1); - - new DiHyperCube(IsomorphicTests.DIMENSION, model2).dupe(b1).dupe(b1).dupe(b1); - - Assert.assertEquals(type, model.isIsomorphicWith(model2)); - } - } - - public void test2DiHyperCubeFalse() { - test2DiHyperCube(IsomorphicTests.QUANTITY, false); - } - - public void test2DiHyperCubeTrue() { - test2DiHyperCube(IsomorphicTests.QUANTITY, true); - } - - public void test2HyperCube() { - - for ( int i = 0 ; i < IsomorphicTests.QUANTITY ; i++ ) { - int a1, b1; - a1 = random.nextInt(sz); - b1 = random.nextInt(sz); - new HyperCube(IsomorphicTests.DIMENSION, model).dupe(a1).dupe(a1).dupe(a1); - new HyperCube(IsomorphicTests.DIMENSION, model2).dupe(b1).dupe(b1).dupe(b1); - Assert.assertTrue("Models not isomorphic", model.isIsomorphicWith(model2)); - } - } - - private void test4DiHyperCube(int quantity, final boolean type) { - - for ( int i = 0 ; i < quantity ; i++ ) { - int a1, b1, a2, b2; - do { - a1 = random.nextInt(sz); - b1 = random.nextInt(sz); - a2 = random.nextInt(sz); - b2 = random.nextInt(sz); - } while (type != DiHyperCube.equal(a1, a2, b1, b2)); - - new DiHyperCube(IsomorphicTests.DIMENSION, model).dupe(a1).dupe(a1).dupe(a1).dupe(a2).dupe(a2).dupe(a2); - - new DiHyperCube(IsomorphicTests.DIMENSION, model2).dupe(b1).dupe(b1).dupe(b1).dupe(b2).dupe(b2).dupe(b2); - final String msg = "(" + a1 + "," + a2 + "),(" + b1 + "," + b2 + ")"; - Assert.assertEquals(msg, type, model.isIsomorphicWith(model2)); - } - - } - - public void test4DiHyperCubeFalse() { - test4DiHyperCube(IsomorphicTests.QUANTITY, false); - } - - public void test4DiHyperCubeTrue() { - test4DiHyperCube(IsomorphicTests.QUANTITY, true); - } - - private void test4HyperCube(int quantity, final boolean type) { - - for ( int i = 0 ; i < quantity ; i++ ) { - int a1, b1, a2, b2; - do { - a1 = random.nextInt(sz); - b1 = random.nextInt(sz); - a2 = random.nextInt(sz); - b2 = random.nextInt(sz); - } while (type != HyperCube.equal(a1, a2, b1, b2)); - - new HyperCube(IsomorphicTests.DIMENSION, model).dupe(a1).dupe(a1).dupe(a1).dupe(a2).dupe(a2).dupe(a2); - new HyperCube(IsomorphicTests.DIMENSION, model2).dupe(b1).dupe(b1).dupe(b1).dupe(b2).dupe(b2).dupe(b2); - - final String msg = "(" + a1 + "," + a2 + "),(" + b1 + "," + b2 + ")"; - Assert.assertEquals(msg, type, model.isIsomorphicWith(model2)); - } - } - - public void test4HyperCubeFalse() { - // Pragmatically, needs more loops - test4HyperCube(2 * IsomorphicTests.QUANTITY, false); - } - - public void test4HyperCubeTrue() { - test4HyperCube(IsomorphicTests.QUANTITY, true); - } - - private void test4ToggleHyperCube(int quantity, final boolean type) { - - for ( int i = 0 ; i < quantity ; i++ ) { - int a1, b1, a2, b2; - do { - a1 = random.nextInt(sz); - b1 = random.nextInt(sz); - a2 = random.nextInt(sz); - b2 = random.nextInt(sz); - } while (type != HyperCube.equal(a1, a2, b1, b2)); - new HyperCube(IsomorphicTests.DIMENSION, model).toggle(a1, a2); - - new HyperCube(IsomorphicTests.DIMENSION, model2).toggle(b1, b2); - - final String msg = "(" + a1 + "," + a2 + "),(" + b1 + "," + b2 + ")"; - Assert.assertEquals(msg, type, model.isIsomorphicWith(model2)); - } - } - - public void test4ToggleHyperCubeFalse() { - test4ToggleHyperCube(2 * IsomorphicTests.QUANTITY, false); - } - - public void test4ToggleHyperCubeTrue() { - test4ToggleHyperCube(IsomorphicTests.QUANTITY, true); - } - -} diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TS6_Model.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TS6_Model.java index 3949795fd38..29a5846ef7a 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TS6_Model.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TS6_Model.java @@ -29,7 +29,56 @@ @Suite @SelectClasses({ - TestDefaultModel_JU6.class + TestDefaultModel.class, + + // Not model-parameterized. + TestAnonID.class, + TestListStatements.class, + TestResourceFactory.class, + TestConcurrency.class, + TestModelFactory.class, + TestProperties.class, + + // Parameterized over ModelCreators.creators(). + TestContains.class, + TestStatements.class, + TestAddAndContains.class, + TestAddModel.class, + TestAltMethods.class, + TestBagMethods.class, + TestContainerConstructors.class, + TestContainers.class, + TestCopyInOutOfModel.class, + TestGetFromModel.class, + TestHiddenStatements.class, + TestIterators.class, + TestList.class, + TestListSubjects.class, + TestListSubjectsEtc.class, + TestLiteralImpl.class, + TestLiterals.class, + TestLiteralsInModel.class, + TestModel.class, + TestModelBulkUpdate.class, + TestModelEvents.class, + TestModelPolymorphism.class, + TestModelRead.class, + TestModelSetOperations.class, + TestNamespace.class, + TestObjectOfProperties.class, + TestObjects.class, + TestRDFNodes.class, + TestReaderEvents.class, + TestReaders.class, + TestRemoveSPO.class, + TestResourceImpl.class, + TestResourceMethods.class, + TestResources.class, + TestSeqMethods.class, + TestSimpleListStatements.class, + TestStatementCreation.class, + TestStatementMethods.class, + TestStatementTerms.class }) public class TS6_Model { diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestAddAndContains.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestAddAndContains.java index 81e60760363..3fe122df6d4 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestAddAndContains.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestAddAndContains.java @@ -21,21 +21,26 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestAddAndContains extends AbstractModelTestBase { protected Resource S; protected Property P; - public TestAddAndContains(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - @Override + @BeforeEach public void setUp() { super.setUp(); S = model.createResource("http://nowhere.man/subject"); @@ -43,105 +48,120 @@ public void setUp() { } @Override + @AfterEach public void tearDown() { S = null; P = null; super.tearDown(); } + @Test public void testAddContainLiteralByStatement() { final Literal L = model.createTypedLiteral(210); final Statement s = model.createStatement(S, RDF.value, L); - Assert.assertTrue(model.add(s).contains(s)); - Assert.assertTrue(model.contains(S, RDF.value)); + assertTrue(model.add(s).contains(s)); + assertTrue(model.contains(S, RDF.value)); } + @Test public void testAddContainsBoolean() { model.addLiteral(S, P, AbstractModelTestBase.tvBoolean); - Assert.assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvBoolean)); + assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvBoolean)); } + @Test public void testAddContainsByte() { model.addLiteral(S, P, AbstractModelTestBase.tvByte); - Assert.assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvByte)); + assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvByte)); } + @Test public void testAddContainsChar() { model.addLiteral(S, P, AbstractModelTestBase.tvChar); - Assert.assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvChar)); + assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvChar)); } + @Test public void testAddContainsDouble() { model.addLiteral(S, P, AbstractModelTestBase.tvDouble); - Assert.assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvDouble)); + assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvDouble)); } + @Test public void testAddContainsFloat() { model.addLiteral(S, P, AbstractModelTestBase.tvFloat); - Assert.assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvFloat)); + assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvFloat)); } + @Test public void testAddContainsInt() { model.addLiteral(S, P, AbstractModelTestBase.tvInt); - Assert.assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvInt)); + assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvInt)); } + @Test public void testAddContainsLanguagedString() { model.add(S, P, "test string", "en"); - Assert.assertFalse(model.contains(S, P, "test string")); - Assert.assertTrue(model.contains(S, P, "test string", "en")); + assertFalse(model.contains(S, P, "test string")); + assertTrue(model.contains(S, P, "test string", "en")); } + @Test public void testAddContainsLong() { model.addLiteral(S, P, AbstractModelTestBase.tvLong); - Assert.assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvLong)); + assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvLong)); } + @Test public void testAddContainsPlainString() { model.add(S, P, "test string"); - Assert.assertTrue(model.contains(S, P, "test string")); - Assert.assertFalse(model.contains(S, P, "test string", "en")); + assertTrue(model.contains(S, P, "test string")); + assertFalse(model.contains(S, P, "test string", "en")); } // public void testAddContainsObject() // { // LitTestObj O = new LitTestObj( 12345 ); // model.addLiteral( S, P, O ); - // assertTrue( model.containsLiteral( S, P, O ) ); + // assertTrue(model.containsLiteral( S, P, O ) ); // } + @Test public void testAddContainsResource() { final Resource r = model.createResource(); model.add(S, P, r); - Assert.assertTrue(model.contains(S, P, r)); + assertTrue(model.contains(S, P, r)); } + @Test public void testAddContainsShort() { model.addLiteral(S, P, AbstractModelTestBase.tvShort); - Assert.assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvShort)); + assertTrue(model.containsLiteral(S, P, AbstractModelTestBase.tvShort)); } + @Test public void testAddDuplicateLeavesSizeSame() { final Statement s = model.createStatement(S, RDF.value, "something"); model.add(s); final long size = model.size(); model.add(s); - Assert.assertEquals(size, model.size()); + assertEquals(size, model.size()); } + @Test public void testEmpty() { - Assert.assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvBoolean)); - Assert.assertFalse(model.contains(S, P, model.createResource())); - Assert.assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvByte)); - Assert.assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvShort)); - Assert.assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvInt)); - Assert.assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvLong)); - Assert.assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvChar)); - Assert.assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvFloat)); - Assert.assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvDouble)); - Assert.assertFalse(model.containsLiteral(S, P, new LitTestObj(12345))); - Assert.assertFalse(model.contains(S, P, "test string")); - Assert.assertFalse(model.contains(S, P, "test string", "en")); + assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvBoolean)); + assertFalse(model.contains(S, P, model.createResource())); + assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvByte)); + assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvShort)); + assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvInt)); + assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvLong)); + assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvChar)); + assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvFloat)); + assertFalse(model.containsLiteral(S, P, AbstractModelTestBase.tvDouble)); + assertFalse(model.containsLiteral(S, P, new LitTestObj(12345))); + assertFalse(model.contains(S, P, "test string")); + assertFalse(model.contains(S, P, "test string", "en")); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestAddModel.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestAddModel.java index 1c5ffa041cb..2925ca6aa2e 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestAddModel.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestAddModel.java @@ -21,21 +21,25 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestAddModel extends AbstractModelTestBase { private Model model2; - public TestAddModel(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - protected void assertContainsAll(final Model model, final Model model2) { for ( final StmtIterator s = model2.listStatements() ; s.hasNext() ; ) { - Assert.assertTrue(model.contains(s.nextStatement())); + assertTrue(model.contains(s.nextStatement())); } } @@ -45,44 +49,49 @@ protected void assertSameStatements(final Model model, final Model model2) { } @Override + @BeforeEach public void setUp() { super.setUp(); model2 = createModel(); } @Override + @AfterEach public void tearDown() { super.tearDown(); model2.close(); } + @Test public void testAddByIterator() { ModelHelper.modelAdd(model, "a P b; c P d; x Q 1; y Q 2"); model2.add(model.listStatements()); - Assert.assertEquals(model.size(), model2.size()); + assertEquals(model.size(), model2.size()); assertSameStatements(model, model2); model.add(model.createResource(), RDF.value, model.createResource()); model.add(model.createResource(), RDF.value, model.createResource()); model.add(model.createResource(), RDF.value, model.createResource()); final StmtIterator s = model.listStatements(); model2.remove(s.nextStatement()).remove(s); - Assert.assertEquals(0, model2.size()); + assertEquals(0, model2.size()); } + @Test public void testAddByModel() { ModelHelper.modelAdd(model, "a P b; c P d; x Q 1; y Q 2"); model2.add(model); - Assert.assertEquals(model.size(), model2.size()); + assertEquals(model.size(), model2.size()); assertSameStatements(model, model2); } + @Test public void testRemoveByModel() { ModelHelper.modelAdd(model, "a P b; c P d; x Q 1; y Q 2"); model2.add(model).remove(model); - Assert.assertEquals(0, model2.size()); - Assert.assertFalse(model2.listStatements().hasNext()); + assertEquals(0, model2.size()); + assertFalse(model2.listStatements().hasNext()); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestAltMethods.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestAltMethods.java index 330e7b54417..376869ca662 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestAltMethods.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestAltMethods.java @@ -21,14 +21,17 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestAltMethods extends AbstractContainerMethods { - public TestAltMethods(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } @Override protected Container createContainer() { @@ -40,6 +43,7 @@ protected Resource getContainerType() { return RDF.Alt; } + @Test public void testDefaults() { final Alt a = model.createAlt(); final Literal tvLiteral = model.createLiteral("test 12 string 2"); @@ -49,25 +53,25 @@ public void testDefaults() { final Seq tvSeq = model.createSeq(); // final Resource tvResource = model.createResource(); - Assert.assertEquals(tvLiteral, a.setDefault(tvLiteral).getDefault()); - Assert.assertEquals(tvLiteral, a.getDefaultLiteral()); - Assert.assertEquals(tvResource, a.setDefault(tvResource).getDefaultResource()); - Assert.assertEquals(AbstractModelTestBase.tvByte, a.setDefault(AbstractModelTestBase.tvByte).getDefaultByte()); - Assert.assertEquals(AbstractModelTestBase.tvShort, a.setDefault(AbstractModelTestBase.tvShort).getDefaultShort()); - Assert.assertEquals(AbstractModelTestBase.tvInt, a.setDefault(AbstractModelTestBase.tvInt).getDefaultInt()); - Assert.assertEquals(AbstractModelTestBase.tvLong, a.setDefault(AbstractModelTestBase.tvLong).getDefaultLong()); - Assert.assertEquals(AbstractModelTestBase.tvFloat, a.setDefault(AbstractModelTestBase.tvFloat).getDefaultFloat(), + assertEquals(tvLiteral, a.setDefault(tvLiteral).getDefault()); + assertEquals(tvLiteral, a.getDefaultLiteral()); + assertEquals(tvResource, a.setDefault(tvResource).getDefaultResource()); + assertEquals(AbstractModelTestBase.tvByte, a.setDefault(AbstractModelTestBase.tvByte).getDefaultByte()); + assertEquals(AbstractModelTestBase.tvShort, a.setDefault(AbstractModelTestBase.tvShort).getDefaultShort()); + assertEquals(AbstractModelTestBase.tvInt, a.setDefault(AbstractModelTestBase.tvInt).getDefaultInt()); + assertEquals(AbstractModelTestBase.tvLong, a.setDefault(AbstractModelTestBase.tvLong).getDefaultLong()); + assertEquals(AbstractModelTestBase.tvFloat, a.setDefault(AbstractModelTestBase.tvFloat).getDefaultFloat(), AbstractModelTestBase.fDelta); - Assert.assertEquals(AbstractModelTestBase.tvDouble, a.setDefault(AbstractModelTestBase.tvDouble).getDefaultDouble(), + assertEquals(AbstractModelTestBase.tvDouble, a.setDefault(AbstractModelTestBase.tvDouble).getDefaultDouble(), AbstractModelTestBase.dDelta); - Assert.assertEquals(AbstractModelTestBase.tvChar, a.setDefault(AbstractModelTestBase.tvChar).getDefaultChar()); - Assert.assertEquals(AbstractModelTestBase.tvString, a.setDefault(AbstractModelTestBase.tvString).getDefaultString()); - // assertEquals( tvResObj, a.setDefault( tvResObj ).getDefaultResource() + assertEquals(AbstractModelTestBase.tvChar, a.setDefault(AbstractModelTestBase.tvChar).getDefaultChar()); + assertEquals(AbstractModelTestBase.tvString, a.setDefault(AbstractModelTestBase.tvString).getDefaultString()); + // assertEquals(tvResObj, a.setDefault( tvResObj ).getDefaultResource() // ); - // assertEquals( tvLitObj, a.setDefault( tvLitObj ).getDefaultObject( + // assertEquals(tvLitObj, a.setDefault( tvLitObj ).getDefaultObject( // new LitTestObjF() ) ); - Assert.assertEquals(tvAlt, a.setDefault(tvAlt).getDefaultAlt()); - Assert.assertEquals(tvBag, a.setDefault(tvBag).getDefaultBag()); - Assert.assertEquals(tvSeq, a.setDefault(tvSeq).getDefaultSeq()); + assertEquals(tvAlt, a.setDefault(tvAlt).getDefaultAlt()); + assertEquals(tvBag, a.setDefault(tvBag).getDefaultBag()); + assertEquals(tvSeq, a.setDefault(tvSeq).getDefaultSeq()); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestAnonID.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestAnonID.java index bd75ad08d17..b557c2015b7 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestAnonID.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestAnonID.java @@ -21,32 +21,26 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.shared.impl.JenaParameters; import org.apache.jena.test.JenaTestLib; -import org.junit.Assert; -import junit.framework.TestCase; -import junit.framework.TestSuite; - /** * Test for anonID generation. (Originally test for the debugging hack that switches * off anonID generation.) */ -public class TestAnonID extends TestCase { +public class TestAnonID { /** * Boilerplate for junit. This is its own test suite */ - public static TestSuite suite() { - return new TestSuite(TestAnonID.class); - } /** * Boilerplate for junit */ - public TestAnonID(final String name) { - super(name); - } /** * Check that anonIDs are distinct whichever state the flag is in. @@ -67,6 +61,7 @@ public void doTestAnonID() { /** * Check that anonIDs are distinct whichever state the flag is in. */ + @Test public void testAnonID() { final boolean prior = JenaParameters.disableBNodeUIDGeneration; try { @@ -83,11 +78,12 @@ public void testAnonID() { * Test that creation of an AnonId from an AnonId string preserves that string * and is equal to the original AnonId. */ + @Test public void testAnonIdPreserved() { final AnonId anon = AnonId.create(); final String id = anon.toString(); - Assert.assertEquals(anon, AnonId.create(id)); - Assert.assertEquals(id, AnonId.create(id).toString()); + assertEquals(anon, AnonId.create(id)); + assertEquals(id, AnonId.create(id).toString()); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestBagMethods.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestBagMethods.java index 515c0bf3529..1e65e453b49 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestBagMethods.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestBagMethods.java @@ -21,13 +21,14 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.vocabulary.RDF; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestBagMethods extends AbstractContainerMethods { - public TestBagMethods(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } @Override protected Container createContainer() { diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestConcurrency.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestConcurrency.java index 7658a426e0c..6032d650586 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestConcurrency.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestConcurrency.java @@ -21,12 +21,21 @@ package org.apache.jena.rdf.model; -import junit.framework.*; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.Named; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.shared.Lock; -public class TestConcurrency extends TestSuite { +/** Test suite to exercise the locking. */ +public class TestConcurrency { - // Test suite to exercise the locking static long SLEEP = 100; static int threadCount = 0; @@ -34,179 +43,155 @@ public class TestConcurrency extends TestSuite { final static Model model1 = ModelFactory.createDefaultModel(); final static Model model2 = ModelFactory.createDefaultModel(); - public TestConcurrency() { - super("Model concurrency control"); - - if ( true ) { + /** + * The lock nesting cases: outer model and lock, inner model and lock, and whether + * entering the inner critical section is expected to fail. Lock promotion (READ + * then WRITE) fails only on the same model, inner and outer. + */ + static Stream nestingCases() { + return Stream.of( // Same model: inner and outer - addTest(new Nesting("Lock nesting 1 - same model", model1, Lock.READ, Lock.READ, false)); - addTest(new Nesting("Lock nesting 2 - same model", model1, Lock.WRITE, Lock.WRITE, false)); - addTest(new Nesting("Lock nesting 3 - same model", model1, Lock.READ, Lock.WRITE, true)); - addTest(new Nesting("Lock nesting 4 - same model", model1, Lock.WRITE, Lock.READ, false)); + nesting("Lock nesting 1 - same model", model1, Lock.READ, model1, Lock.READ, false), + nesting("Lock nesting 2 - same model", model1, Lock.WRITE, model1, Lock.WRITE, false), + nesting("Lock nesting 3 - same model", model1, Lock.READ, model1, Lock.WRITE, true), + nesting("Lock nesting 4 - same model", model1, Lock.WRITE, model1, Lock.READ, false), // Different model: inner and outer - addTest(new Nesting("Lock nesting 1 - different models", model1, Lock.READ, model2, Lock.READ, false)); - addTest(new Nesting("Lock nesting 2 - different models", model1, Lock.WRITE, model2, Lock.WRITE, false)); - addTest(new Nesting("Lock nesting 3 - different models", model1, Lock.READ, model2, Lock.WRITE, false)); - addTest(new Nesting("Lock nesting 4 - different models", model1, Lock.WRITE, model2, Lock.READ, false)); - } - if ( true ) { - // Crude test - addTest(new Parallel("Parallel concurrency test")); - } - + nesting("Lock nesting 1 - different models", model1, Lock.READ, model2, Lock.READ, false), + nesting("Lock nesting 2 - different models", model1, Lock.WRITE, model2, Lock.WRITE, false), + nesting("Lock nesting 3 - different models", model1, Lock.READ, model2, Lock.WRITE, false), + nesting("Lock nesting 4 - different models", model1, Lock.WRITE, model2, Lock.READ, false)); } - static class Nesting extends TestCase { - Model outerModel; - Model innerModel; - boolean outerLock; - boolean innerLock; - boolean exceptionExpected; - - // Same model - Nesting(String testName, Model model, boolean lock1, boolean lock2, boolean exExpected) { - this(testName, model, lock1, model, lock2, exExpected); - } + private static Arguments nesting(String testName, Model outerModel, boolean outerLock, + Model innerModel, boolean innerLock, boolean exceptionExpected) { + return Arguments.of(Named.of(testName, testName), outerModel, outerLock, innerModel, innerLock, exceptionExpected); + } - // Potentially different models - Nesting(String testName, Model model1, boolean lock1, Model model2, boolean lock2, boolean exExpected) { - super(testName); - outerModel = model1; - outerLock = lock1; - innerModel = model2; - innerLock = lock2; - exceptionExpected = exExpected; - } + @ParameterizedTest(name = "{0}") + @MethodSource("nestingCases") + public void testLockNesting(String testName, Model outerModel, boolean outerLock, + Model innerModel, boolean innerLock, boolean exceptionExpected) { + boolean gotException = false; + try { + outerModel.enterCriticalSection(outerLock); - @Override - protected void runTest() { - boolean gotException = false; try { - outerModel.enterCriticalSection(outerLock); - try { - try { - // Should fail if outerLock is READ and innerLock is WRITE - // and its on the same model, inner and outer. - innerModel.enterCriticalSection(innerLock); - - } finally { - innerModel.leaveCriticalSection(); - } - } catch (Exception ex) { - gotException = true; - } + // Should fail if outerLock is READ and innerLock is WRITE + // and its on the same model, inner and outer. + innerModel.enterCriticalSection(innerLock); - } finally { - outerModel.leaveCriticalSection(); + } finally { + innerModel.leaveCriticalSection(); + } + } catch (Exception ex) { + gotException = true; } - if ( exceptionExpected ) - assertTrue("Failed to get expected lock promotion error", gotException); - else - assertTrue("Got unexpected lock promotion error", !gotException); + } finally { + outerModel.leaveCriticalSection(); } + + if ( exceptionExpected ) + assertTrue(gotException, "Failed to get expected lock promotion error"); + else + assertTrue(!gotException, "Got unexpected lock promotion error"); } - static class Parallel extends TestCase { - int threadTotal = 10; + // Crude test + int threadTotal = 10; + + @Test + public void testParallel() { + Model model = ModelFactory.createDefaultModel(); + Thread threads[] = new Thread[threadTotal]; - Parallel(String testName) { - super(testName); + boolean getReadLock = Lock.READ; + for ( int i = 0 ; i < threadTotal ; i++ ) { + String nextId = "T" + Integer.toString(++threadCount); + threads[i] = new Operation(model, getReadLock); + threads[i].setName(nextId); + threads[i].start(); + + getReadLock = !getReadLock; } - @Override - protected void runTest() { - Model model = ModelFactory.createDefaultModel(); - Thread threads[] = new Thread[threadTotal]; - - boolean getReadLock = Lock.READ; - for ( int i = 0 ; i < threadTotal ; i++ ) { - String nextId = "T" + Integer.toString(++threadCount); - threads[i] = new Operation(model, getReadLock); - threads[i].setName(nextId); - threads[i].start(); - - getReadLock = !getReadLock; - } + boolean problems = false; + for ( int i = 0 ; i < threadTotal ; i++ ) { + try { + threads[i].join(200 * SLEEP); + } catch (InterruptedException intEx) {} + } - boolean problems = false; - for ( int i = 0 ; i < threadTotal ; i++ ) { + // Try again for any we missed. + for ( int i = 0 ; i < threadTotal ; i++ ) { + if ( threads[i].isAlive() ) try { threads[i].join(200 * SLEEP); } catch (InterruptedException intEx) {} + if ( threads[i].isAlive() ) { + System.out.println("Thread " + threads[i].getName() + " failed to finish"); + problems = true; } - - // Try again for any we missed. - for ( int i = 0 ; i < threadTotal ; i++ ) { - if ( threads[i].isAlive() ) - try { - threads[i].join(200 * SLEEP); - } catch (InterruptedException intEx) {} - if ( threads[i].isAlive() ) { - System.out.println("Thread " + threads[i].getName() + " failed to finish"); - problems = true; - } - } - - assertTrue("Some thread failed to finish", !problems); } - class Operation extends Thread { - Model model; - boolean readLock; + assertTrue(!problems, "Some thread failed to finish"); + } - Operation(Model m, boolean withReadLock) { - model = m; - readLock = withReadLock; - } + class Operation extends Thread { + Model model; + boolean readLock; - @Override - public void run() { - for ( int i = 0 ; i < 2 ; i++ ) { - try { - model.enterCriticalSection(readLock); - if ( readLock ) - readOperation(false); - else - writeOperation(false); - } finally { - model.leaveCriticalSection(); - } - } - } + Operation(Model m, boolean withReadLock) { + model = m; + readLock = withReadLock; } - // Operations ---------------------------------------------- - volatile int writers = 0; - - // The example model operations - void doStuff(String label, boolean doThrow) { - String id = Thread.currentThread().getName(); - // Puase a while to cause other threads to (try to) enter the region. - try { - Thread.sleep(SLEEP); - } catch (InterruptedException intEx) {} - if ( doThrow ) - throw new RuntimeException(label); + @Override + public void run() { + for ( int i = 0 ; i < 2 ; i++ ) { + try { + model.enterCriticalSection(readLock); + if ( readLock ) + readOperation(false); + else + writeOperation(false); + } finally { + model.leaveCriticalSection(); + } + } } + } + // Operations ---------------------------------------------- + + volatile int writers = 0; + + // The example model operations + void doStuff(String label, boolean doThrow) { + String id = Thread.currentThread().getName(); + // Puase a while to cause other threads to (try to) enter the region. + try { + Thread.sleep(SLEEP); + } catch (InterruptedException intEx) {} + if ( doThrow ) + throw new RuntimeException(label); + } - // Example operations + // Example operations - public void readOperation(boolean doThrow) { - if ( writers > 0 ) - System.err.println("Concurrency error: writers around!"); - doStuff("read operation", false); - if ( writers > 0 ) - System.err.println("Concurrency error: writers around!"); - } + public void readOperation(boolean doThrow) { + if ( writers > 0 ) + System.err.println("Concurrency error: writers around!"); + doStuff("read operation", false); + if ( writers > 0 ) + System.err.println("Concurrency error: writers around!"); + } - public void writeOperation(boolean doThrow) { - writers++; - doStuff("write operation", false); - writers--; + public void writeOperation(boolean doThrow) { + writers++; + doStuff("write operation", false); + writers--; - } } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestContainerConstructors.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestContainerConstructors.java index faa285f4303..7873d1abbea 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestContainerConstructors.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestContainerConstructors.java @@ -21,52 +21,60 @@ package org.apache.jena.rdf.model; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.vocabulary.RDF; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestContainerConstructors extends AbstractModelTestBase { - public TestContainerConstructors(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } + @Test public void testCreateAnonAlt() { final Alt tv = model.createAlt(); - Assert.assertTrue(tv.isAnon()); - Assert.assertTrue(model.contains(tv, RDF.type, RDF.Alt)); + assertTrue(tv.isAnon()); + assertTrue(model.contains(tv, RDF.type, RDF.Alt)); } + @Test public void testCreateAnonBag() { final Bag tv = model.createBag(); - Assert.assertTrue(tv.isAnon()); - Assert.assertTrue(model.contains(tv, RDF.type, RDF.Bag)); + assertTrue(tv.isAnon()); + assertTrue(model.contains(tv, RDF.type, RDF.Bag)); } + @Test public void testCreateAnonSeq() { final Seq tv = model.createSeq(); - Assert.assertTrue(tv.isAnon()); - Assert.assertTrue(model.contains(tv, RDF.type, RDF.Seq)); + assertTrue(tv.isAnon()); + assertTrue(model.contains(tv, RDF.type, RDF.Seq)); } + @Test public void testCreateNamedAlt() { final String uri = "http://aldabaran/sirius"; final Alt tv = model.createAlt(uri); - Assert.assertEquals(uri, tv.getURI()); - Assert.assertTrue(model.contains(tv, RDF.type, RDF.Alt)); + assertEquals(uri, tv.getURI()); + assertTrue(model.contains(tv, RDF.type, RDF.Alt)); } + @Test public void testCreateNamedBag() { final String uri = "http://aldabaran/foo"; final Bag tv = model.createBag(uri); - Assert.assertEquals(uri, tv.getURI()); - Assert.assertTrue(model.contains(tv, RDF.type, RDF.Bag)); + assertEquals(uri, tv.getURI()); + assertTrue(model.contains(tv, RDF.type, RDF.Bag)); } + @Test public void testCreateNamedSeq() { final String uri = "http://aldabaran/andromeda"; final Seq tv = model.createSeq(uri); - Assert.assertEquals(uri, tv.getURI()); - Assert.assertTrue(model.contains(tv, RDF.type, RDF.Seq)); + assertEquals(uri, tv.getURI()); + assertTrue(model.contains(tv, RDF.type, RDF.Seq)); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestContainers.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestContainers.java index 3d15e167d2b..a7dd3b9ff7b 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestContainers.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestContainers.java @@ -21,24 +21,25 @@ package org.apache.jena.rdf.model; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.*; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; /** * Tests for containers. */ +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestContainers extends AbstractModelTestBase { - public TestContainers(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - + @Test public void testCanAsContainer() { final String seqUri = "http://example.com/#seq"; model.createSeq(seqUri); final Resource res = model.createResource(seqUri); - Assert.assertTrue(res.canAs(Seq.class)); - Assert.assertTrue(res.canAs(Container.class)); + assertTrue(res.canAs(Seq.class)); + assertTrue(res.canAs(Container.class)); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestContains.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestContains.java index 6fd16cebcb4..6c67c29f6cc 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestContains.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestContains.java @@ -21,18 +21,20 @@ package org.apache.jena.rdf.model; -import org.apache.jena.graph.GraphMemFactory; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.graph.Graph; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import org.apache.jena.graph.GraphMemFactory; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.rdf.model.impl.ModelCom; -import org.junit.Assert; - +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestContains extends AbstractModelTestBase { - public TestContains(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } private Property prop(final String uri) { return ResourceFactory.createProperty("eh:/" + uri); @@ -42,44 +44,47 @@ private Resource res(final String uri) { return ResourceFactory.createResource("eh:/" + uri); } + @Test public void testContains() { - testContains(false, "", "x"); - testContains(false, "a R b", "x"); - testContains(false, "a R b; c P d", "x"); + checkContains(false, "", "x"); + checkContains(false, "a R b", "x"); + checkContains(false, "a R b; c P d", "x"); /* */ - testContains(false, "a R b", "z"); + checkContains(false, "a R b", "z"); /* */ - testContains(true, "x R y", "x"); - testContains(true, "a P b", "P"); - testContains(true, "i Q j", "j"); - testContains(true, "x R y; a P b; i Q j", "y"); + checkContains(true, "x R y", "x"); + checkContains(true, "a P b", "P"); + checkContains(true, "i Q j", "j"); + checkContains(true, "x R y; a P b; i Q j", "y"); /* */ - testContains(true, "x R y; a P b; i Q j", "y"); - testContains(true, "x R y; a P b; i Q j", "R"); - testContains(true, "x R y; a P b; i Q j", "a"); + checkContains(true, "x R y; a P b; i Q j", "y"); + checkContains(true, "x R y; a P b; i Q j", "R"); + checkContains(true, "x R y; a P b; i Q j", "a"); } - public void testContains(final boolean yes, final String facts, final String resource) { - final Model m = ModelHelper.modelWithStatements(this, facts); + public void checkContains(final boolean yes, final String facts, final String resource) { + final Model m = modelWithStatements(facts); final RDFNode r = ModelHelper.rdfNode(m, resource); - if ( ModelHelper.modelWithStatements(this, facts).containsResource(r) != yes ) { - Assert.fail("[" + facts + "] should" + (yes ? "" : " not") + " contain " + resource); + if ( modelWithStatements(facts).containsResource(r) != yes ) { + fail("[" + facts + "] should" + (yes ? "" : " not") + " contain " + resource); } } + @Test public void testContainsWithNull() { - testCWN(false, "", null, null, null); - testCWN(true, "x R y", null, null, null); - testCWN(false, "x R y", null, null, res("z")); - testCWN(true, "x RR y", res("x"), prop("RR"), null); - testCWN(true, "a BB c", null, prop("BB"), res("c")); - testCWN(false, "a BB c", null, prop("ZZ"), res("c")); + checkCWN(false, "", null, null, null); + checkCWN(true, "x R y", null, null, null); + checkCWN(false, "x R y", null, null, res("z")); + checkCWN(true, "x RR y", res("x"), prop("RR"), null); + checkCWN(true, "a BB c", null, prop("BB"), res("c")); + checkCWN(false, "a BB c", null, prop("ZZ"), res("c")); } - public void testCWN(final boolean yes, final String facts, final Resource S, final Property P, final RDFNode O) { - Assert.assertEquals(yes, ModelHelper.modelWithStatements(this, facts).contains(S, P, O)); + public void checkCWN(final boolean yes, final String facts, final Resource S, final Property P, final RDFNode O) { + assertEquals(yes, modelWithStatements(facts).contains(S, P, O)); } + @Test public void testModelComContainsSPcallsContainsSPO() { final Graph g = GraphMemFactory.createDefaultGraph(); final boolean[] wasCalled = {false}; @@ -91,7 +96,7 @@ public boolean contains(final Resource s, final Property p, final RDFNode o) { return super.contains(s, p, o); } }; - Assert.assertFalse(m.contains(ModelHelper.resource("r"), ModelHelper.property("p"))); - Assert.assertTrue("contains(S,P) should call contains(S,P,O)", wasCalled[0]); + assertFalse(m.contains(ModelHelper.resource("r"), ModelHelper.property("p"))); + assertTrue(wasCalled[0], "contains(S,P) should call contains(S,P,O)"); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestCopyInOutOfModel.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestCopyInOutOfModel.java index bb647e6ff09..87b0886651c 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestCopyInOutOfModel.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestCopyInOutOfModel.java @@ -21,20 +21,22 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestCopyInOutOfModel extends AbstractModelTestBase { private Resource S; private Property P; private RDFNode O; - public TestCopyInOutOfModel(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - @Override + @BeforeEach public void setUp() { super.setUp(); S = ResourceFactory.createResource(); @@ -45,30 +47,31 @@ public void setUp() { /** * test moving things between models */ + @Test public void testCopyStatement() { final Model model2 = createModel(); final Statement stmt = model.createStatement(S, P, O); - Assert.assertEquals(model, stmt.getModel()); - Assert.assertEquals(0, model.size()); - Assert.assertEquals(model, stmt.getSubject().getModel()); - Assert.assertEquals(model, stmt.getPredicate().getModel()); - Assert.assertEquals(model, stmt.getObject().getModel()); + assertEquals(model, stmt.getModel()); + assertEquals(0, model.size()); + assertEquals(model, stmt.getSubject().getModel()); + assertEquals(model, stmt.getPredicate().getModel()); + assertEquals(model, stmt.getObject().getModel()); model.add(stmt); - Assert.assertEquals(1, model.size()); - Assert.assertEquals(model, stmt.getSubject().getModel()); - Assert.assertEquals(model, stmt.getPredicate().getModel()); - Assert.assertEquals(model, stmt.getObject().getModel()); + assertEquals(1, model.size()); + assertEquals(model, stmt.getSubject().getModel()); + assertEquals(model, stmt.getPredicate().getModel()); + assertEquals(model, stmt.getObject().getModel()); model2.add(stmt); - Assert.assertEquals(1, model.size()); - Assert.assertEquals(model, stmt.getSubject().getModel()); - Assert.assertEquals(model, stmt.getPredicate().getModel()); - Assert.assertEquals(model, stmt.getObject().getModel()); - Assert.assertEquals(1, model2.size()); + assertEquals(1, model.size()); + assertEquals(model, stmt.getSubject().getModel()); + assertEquals(model, stmt.getPredicate().getModel()); + assertEquals(model, stmt.getObject().getModel()); + assertEquals(1, model2.size()); final Statement stmt2 = model2.listStatements().next(); - Assert.assertEquals(model2, stmt2.getSubject().getModel()); - Assert.assertEquals(model2, stmt2.getPredicate().getModel()); - Assert.assertEquals(model2, stmt2.getObject().getModel()); + assertEquals(model2, stmt2.getSubject().getModel()); + assertEquals(model2, stmt2.getPredicate().getModel()); + assertEquals(model2, stmt2.getObject().getModel()); } /* try { Statement stmt; StmtIterator sIter; // System.out.println("Beginning " + * test); diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel_JU6.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel.java similarity index 99% rename from jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel_JU6.java rename to jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel.java index cb71d48a240..ca5e2f93427 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel_JU6.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestDefaultModel.java @@ -35,7 +35,7 @@ import org.apache.jena.shared.PropertyNotFoundException; import org.apache.jena.test.JenaTestLib; -public class TestDefaultModel_JU6 { +public class TestDefaultModel { static { JenaTestLib.setup(); } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestGetFromModel.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestGetFromModel.java index 26ec8f7376f..811c9a724f2 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestGetFromModel.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestGetFromModel.java @@ -21,20 +21,25 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestGetFromModel extends AbstractModelTestBase { protected Resource S; protected Property P; - public TestGetFromModel(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - @Override + @BeforeEach public void setUp() { super.setUp(); S = model.createResource("http://nowhere.man/subject"); @@ -42,58 +47,65 @@ public void setUp() { } @Override + @AfterEach public void tearDown() { S = null; P = null; super.tearDown(); } + @Test public void testGetAlt() { final String uri = "http://aldabaran.hpl.hp.com/rdf/test4/" + 160; model.createAlt(uri); final Alt a = model.getAlt(uri); - Assert.assertEquals(uri, a.getURI()); - Assert.assertTrue(model.contains(a, RDF.type, RDF.Alt)); + assertEquals(uri, a.getURI()); + assertTrue(model.contains(a, RDF.type, RDF.Alt)); } // public void testGetResourceFactory() // { // String uri = "http://aldabaran.hpl.hp.com/rdf/test4/a" + 120; // Resource r = model.getResource( uri, new ResTestObjF() ); - // assertEquals( uri, r.getURI() ); + // assertEquals(uri, r.getURI() ); // } + @Test public void testGetBag() { final String uri = "http://aldabaran.hpl.hp.com/rdf/test4/" + 150; model.createBag(uri); final Bag b = model.getBag(uri); - Assert.assertEquals(uri, b.getURI()); - Assert.assertTrue(model.contains(b, RDF.type, RDF.Bag)); + assertEquals(uri, b.getURI()); + assertTrue(model.contains(b, RDF.type, RDF.Bag)); } + @Test public void testGetPropertyOneArg() { final String uri = "http://aldabaran.hpl.hp.com/rdf/test4/a" + 130; final Property p = model.getProperty(uri); - Assert.assertEquals(uri, p.getURI()); + assertEquals(uri, p.getURI()); } + @Test public void testGetPropertyTwoArgs() { final String ns = "http://aldabaran.hpl.hp.com/rdf/test4/a" + 140 + "/"; final Property p = model.getProperty(ns, "foo"); - Assert.assertEquals(ns + "foo", p.getURI()); + assertEquals(ns + "foo", p.getURI()); } + @Test public void testGetResource() { final String uri = "http://aldabaran.hpl.hp.com/rdf/test4/a" + 110; final Resource r = model.getResource(uri); - Assert.assertEquals(uri, r.getURI()); + assertEquals(uri, r.getURI()); } + @Test public void testGetSeq() { final String uri = "http://aldabaran.hpl.hp.com/rdf/test4/" + 170; model.createSeq(uri); final Seq s = model.getSeq(uri); - Assert.assertEquals(uri, s.getURI()); - Assert.assertTrue(model.contains(s, RDF.type, RDF.Seq)); + assertEquals(uri, s.getURI()); + assertTrue(model.contains(s, RDF.type, RDF.Seq)); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestHiddenStatements.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestHiddenStatements.java index 19d156328b0..be6e4910ae1 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestHiddenStatements.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestHiddenStatements.java @@ -21,19 +21,21 @@ package org.apache.jena.rdf.model; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.shared.PrefixMapping; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestHiddenStatements extends AbstractModelTestBase { - public TestHiddenStatements(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } public void assertSameMapping(final PrefixMapping L, final PrefixMapping R) { if ( sameMapping(L, R) == false ) { - Assert.fail("wanted " + L + " but got " + R); + fail("wanted " + L + " but got " + R); } } @@ -47,6 +49,7 @@ public boolean sameMapping(final PrefixMapping L, final PrefixMapping R) { * Test that withHiddenStatements copies the prefix mapping TODO add some extra * prefies for checking; should check for non- default models. */ + @Test public void testPrefixCopied() { model.setNsPrefixes(PrefixMapping.Standard); assertSameMapping(PrefixMapping.Standard, model); diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestIterators.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestIterators.java index 329d2b76bd9..ea782efbe2d 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestIterators.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestIterators.java @@ -21,10 +21,17 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestIterators extends AbstractModelTestBase { int num = 5; Resource subject[] = new Resource[num]; @@ -34,11 +41,8 @@ public class TestIterators extends AbstractModelTestBase { String suri = "http://aldabaran/test6/s"; String puri = "http://aldabaran/test6/"; - public TestIterators(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - @Override + @BeforeEach public void setUp() { super.setUp(); @@ -61,6 +65,7 @@ public void setUp() { * bug detected in StatementIteratorImpl - next does not advance current, so * remove doesn't work with next; this test should expose the bug. */ + @Test public void testIteratorRemove() { final StmtIterator it = model.listStatements(); try { @@ -68,7 +73,7 @@ public void testIteratorRemove() { it.next(); it.remove(); } - Assert.assertEquals("Remove failed", 0, model.size()); + assertEquals(0, model.size(), "Remove failed"); } catch (UnsupportedOperationException ex) { throw ex; } finally { @@ -77,6 +82,7 @@ public void testIteratorRemove() { } + @Test public void testListObjects() { int count = 0; NodeIterator iter; @@ -85,9 +91,10 @@ public void testListObjects() { iter.nextNode(); count++; } - Assert.assertEquals(num * num, count); + assertEquals(num * num, count); } + @Test public void testNamespaceIterator() { final boolean predf[] = new boolean[num]; for ( int i = 0 ; i < num ; i++ ) { @@ -100,17 +107,18 @@ public void testNamespaceIterator() { for ( int i = 0 ; i < num ; i++ ) { if ( ns.equals(predicate[i].getNameSpace()) ) { found = true; - Assert.assertFalse("Should not have found " + predicate[i] + " already.", predf[i]); + assertFalse(predf[i], "Should not have found " + predicate[i] + " already."); predf[i] = true; } } - Assert.assertTrue("Should have found " + ns, found); + assertTrue(found, "Should have found " + ns); } for ( int i = 0 ; i < num ; i++ ) { - Assert.assertTrue("Should have found " + predicate[i], predf[i]); + assertTrue(predf[i], "Should have found " + predicate[i]); } } + @Test public void testObjectsOfProperty() { NodeIterator iter; @@ -126,14 +134,15 @@ public void testObjectsOfProperty() { } for ( int i = 0 ; i < (num * num) ; i++ ) { if ( (i % num) == 0 ) { - Assert.assertTrue(object[i]); + assertTrue(object[i]); } else { - Assert.assertFalse(object[i]); + assertFalse(object[i]); } } } + @Test public void testObjectsOfPropertyAndValue() { NodeIterator iter; final boolean[] object = new boolean[num]; @@ -149,10 +158,11 @@ public void testObjectsOfPropertyAndValue() { object[i] = true; } for ( int i = 0 ; i < (num) ; i++ ) { - Assert.assertTrue(object[i]); + assertTrue(object[i]); } } + @Test public void testResourceIterator() { final boolean subjf[] = new boolean[num]; @@ -169,14 +179,14 @@ public void testResourceIterator() { for ( int i = 0 ; i < num ; i++ ) { if ( subj.equals(subject[i]) ) { found = true; - Assert.assertFalse("Should not have found " + subject[i] + " already.", subjf[i]); + assertFalse(subjf[i], "Should not have found " + subject[i] + " already."); subjf[i] = true; } } - Assert.assertTrue("Should have found " + subj, found); + assertTrue(found, "Should have found " + subj); } for ( int i = 0 ; i < num ; i++ ) { - Assert.assertTrue("Should have found " + subject[i], subjf[i]); + assertTrue(subjf[i], "Should have found " + subject[i]); } // System.err.println( @@ -198,10 +208,11 @@ public void testResourceIterator() { } + @Test public void testStatementIter() { final int numStmts = num * num; final boolean stmtf[] = new boolean[numStmts]; - Assert.assertEquals(numStmts, model.size()); + assertEquals(numStmts, model.size()); for ( int i = 0 ; i < numStmts ; i++ ) { stmtf[i] = false; } @@ -213,14 +224,14 @@ public void testStatementIter() { for ( int i = 0 ; i < numStmts ; i++ ) { if ( stmt.equals(stmts[i]) ) { found = true; - Assert.assertFalse("Should not have found " + stmts[i] + " already.", stmtf[i]); + assertFalse(stmtf[i], "Should not have found " + stmts[i] + " already."); stmtf[i] = true; } } - Assert.assertTrue("Should have found " + stmt, found); + assertTrue(found, "Should have found " + stmt); } for ( int i = 0 ; i < numStmts ; i++ ) { - Assert.assertTrue("Should have found " + stmts[i], stmtf[i]); + assertTrue(stmtf[i], "Should have found " + stmts[i]); } } // SEE the tests in model.test: TestReifiedStatements and diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestList.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestList.java index 359a37b48fb..6e2b7be5124 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestList.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestList.java @@ -21,6 +21,12 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + // Imports // ///////////// import java.util.ArrayList; @@ -28,9 +34,7 @@ import java.util.Iterator; import java.util.List; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +43,8 @@ * A collection of unit tests for the standard implementation of {@link RDFList} . *

*/ +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestList extends AbstractModelTestBase { // Constants // //////////////////////////////// @@ -61,8 +67,8 @@ protected static void iteratorTest(final Iterator i, final Object[] expected logger.debug("TestList - Unexpected iterator result: " + next); } - Assert.assertTrue("Value " + next + " was not expected as a result from this iterator ", expList.contains(next)); - Assert.assertTrue("Value " + next + " was not removed from the list ", expList.remove(next)); + assertTrue(expList.contains(next), "Value " + next + " was not expected as a result from this iterator "); + assertTrue(expList.remove(next), "Value " + next + " was not removed from the list "); } if ( !(expList.size() == 0) ) { @@ -71,7 +77,7 @@ protected static void iteratorTest(final Iterator i, final Object[] expected logger.debug("TestList - missing: " + object); } } - Assert.assertEquals("There were expected elements from the iterator that were not found", 0, expList.size()); + assertEquals(0, expList.size(), "There were expected elements from the iterator that were not found"); } // Static variables @@ -107,15 +113,11 @@ protected static void iteratorTest(final Iterator i, final Object[] expected // public ListTest( String n ) {super(n);} - public TestList(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - protected void checkValid(final String testName, final RDFList l, final boolean validExpected) { l.setStrict(true); final boolean valid = l.isValid(); // for debugging ... String s = l.getValidityErrorMessage(); - Assert.assertEquals("Validity test " + testName + " returned wrong isValid() result", validExpected, valid); + assertEquals(validExpected, valid, "Validity test " + testName + " returned wrong isValid() result"); } // Internal implementation methods @@ -123,16 +125,17 @@ protected void checkValid(final String testName, final RDFList l, final boolean protected RDFList getListRoot(final Model m) { final Resource root = m.getResource(TestList.NS + "root"); - Assert.assertNotNull("Root resource should not be null", root); + assertNotNull(root, "Root resource should not be null"); final Resource listHead = root.getRequiredProperty(m.getProperty(TestList.NS + "p")).getResource(); final RDFList l = listHead.as(RDFList.class); - Assert.assertNotNull("as(RDFList) should not return null for root", l); + assertNotNull(l, "as(RDFList) should not return null for root"); return l; } + @Test public void testAdd() { final Resource root = model.createResource(TestList.NS + "root"); @@ -149,7 +152,7 @@ public void testAdd() { final RDFList list0 = list.with(element); checkValid("addTest0", list0, true); - Assert.assertTrue("added'ed lists should be equal", list.equals(nil) || list0.equals(list)); + assertTrue(list.equals(nil) || list0.equals(list), "added'ed lists should be equal"); list = list0; } @@ -161,10 +164,11 @@ public void testAdd() { final Model m0 = ModelFactory.createDefaultModel(); m0.read(getFileName("ontology/list5.rdf")); - Assert.assertTrue("Add'ed and read models should be the same", m0.isIsomorphicWith(model)); + assertTrue(m0.isIsomorphicWith(model), "Add'ed and read models should be the same"); } + @Test public void testAppend() { model.read(getFileName("ontology/list5.rdf")); @@ -188,16 +192,17 @@ public void testAppend() { // original list should be unchanged checkValid("appendTest0", root, true); - Assert.assertEquals("Original list should be unchanged", rootLen, root.size()); + assertEquals(rootLen, root.size(), "Original list should be unchanged"); checkValid("appendTest1", list, true); - Assert.assertEquals("Original list should be unchanged", listLen, list.size()); + assertEquals(listLen, list.size(), "Original list should be unchanged"); // new list should be length of combined checkValid("appendTest2", appended, true); - Assert.assertEquals("Appended list not correct length", rootLen + listLen, appended.size()); + assertEquals(rootLen + listLen, appended.size(), "Appended list not correct length"); } + @Test public void testApply() { model.read(getFileName("ontology/list5.rdf")); @@ -215,10 +220,11 @@ public void apply(final RDFNode n) { final MyApply f = new MyApply(); root.apply(f); - Assert.assertEquals("Result of apply should be concatentation of local names", "abcde", f.collect); + assertEquals("abcde", f.collect, "Result of apply should be concatentation of local names"); } + @Test public void testConcatenate() { model.read(getFileName("ontology/list5.rdf")); @@ -241,13 +247,14 @@ public void testConcatenate() { // original list should be unchanged checkValid("concatTest0", list, true); - Assert.assertEquals("Original list should be unchanged", listLen, list.size()); + assertEquals(listLen, list.size(), "Original list should be unchanged"); // but lhs list has changed checkValid("concatTest1", root, true); - Assert.assertEquals("Root list should be new length", rootLen + listLen, root.size()); + assertEquals(rootLen + listLen, root.size(), "Root list should be new length"); } + @Test public void testConcatenate2() { model.read(getFileName("ontology/list5.rdf")); @@ -265,9 +272,10 @@ public void testConcatenate2() { checkValid("concatTest3", aList, true); final RDFList root = getListRoot(model); - Assert.assertTrue("Constructed and loaded lists should be the same", aList.sameListAs(root)); + assertTrue(aList.sameListAs(root), "Constructed and loaded lists should be the same"); } + @Test public void testCons() { final Resource root = model.createResource(TestList.NS + "root"); final Property p = model.createProperty(TestList.NS, "p"); @@ -283,7 +291,7 @@ public void testCons() { final RDFList list0 = list.cons(element); checkValid("constest1", list0, true); - Assert.assertTrue("cons'ed lists should not be equal", !list0.equals(list)); + assertTrue(!list0.equals(list), "cons'ed lists should not be equal"); list = list0; } @@ -295,20 +303,22 @@ public void testCons() { final Model m0 = ModelFactory.createDefaultModel(); m0.read(getFileName("ontology/list5.rdf")); - Assert.assertTrue("Cons'ed and read models should be the same", m0.isIsomorphicWith(model)); + assertTrue(m0.isIsomorphicWith(model), "Cons'ed and read models should be the same"); } + @Test public void testCount() { for ( int i = 0 ; i <= 5 ; i++ ) { model.removeAll(); model.read(getFileName("ontology/list" + i + ".rdf")); final RDFList l0 = getListRoot(model); - Assert.assertEquals("List size should be " + i, i, l0.size()); + assertEquals(i, l0.size(), "List size should be " + i); } } + @Test public void testHead() { model.read(getFileName("ontology/list5.rdf")); @@ -316,11 +326,12 @@ public void testHead() { final String[] names = {"a", "b", "c", "d", "e"}; for ( final String name : names ) { - Assert.assertEquals("head of list has incorrect URI", TestList.NS + name, ((Resource)l0.getHead()).getURI()); + assertEquals(TestList.NS + name, ((Resource)l0.getHead()).getURI(), "head of list has incorrect URI"); l0 = l0.getTail(); } } + @Test public void testIndex1() { model.read(getFileName("ontology/list5.rdf")); @@ -331,11 +342,12 @@ public void testIndex1() { // check the indexes are correct for ( int i = 0 ; i < toGet.length ; i++ ) { - Assert.assertTrue("list should contain element " + i, l1.contains(toGet[i])); - Assert.assertEquals("list element " + i + " is not correct", i, l1.indexOf(toGet[i])); + assertTrue(l1.contains(toGet[i]), "list should contain element " + i); + assertEquals(i, l1.indexOf(toGet[i]), "list element " + i + " is not correct"); } } + @Test public void testIndex2() { final Resource nil = model.getResource(RDF.nil.getURI()); @@ -350,11 +362,12 @@ public void testIndex2() { // now index them back again for ( int j = 0 ; j < 10 ; j++ ) { - Assert.assertEquals("index of j'th item should be j", j, list.indexOf(r, j)); + assertEquals(j, list.indexOf(r, j), "index of j'th item should be j"); } } + @Test public void testListEquals() { final Resource nil = model.getResource(RDF.nil.getURI()); final RDFList nilList = nil.as(RDFList.class); @@ -387,11 +400,12 @@ public void testListEquals() { final RDFList l1 = nilList.append(Arrays.asList((Resource[])testSpec[i][1]).iterator()); final boolean expected = ((Boolean)testSpec[i][2]).booleanValue(); - Assert.assertEquals("sameListAs testSpec[" + i + "] incorrect", expected, l0.sameListAs(l1)); - Assert.assertEquals("sameListAs testSpec[" + i + "] (swapped) incorrect", expected, l1.sameListAs(l0)); + assertEquals(expected, l0.sameListAs(l1), "sameListAs testSpec[" + i + "] incorrect"); + assertEquals(expected, l1.sameListAs(l0), "sameListAs testSpec[" + i + "] (swapped) incorrect"); } } + @Test public void testListGet() { model.read(getFileName("ontology/list5.rdf")); @@ -402,7 +416,7 @@ public void testListGet() { // test normal gets for ( int i = 0 ; i < toGet.length ; i++ ) { - Assert.assertEquals("list element " + i + " is not correct", toGet[i], l1.get(i)); + assertEquals(toGet[i], l1.get(i), "list element " + i + " is not correct"); } // now test we get an exception for going beyong the end of the list @@ -413,9 +427,10 @@ public void testListGet() { gotEx = true; } - Assert.assertTrue("Should see exception raised by accessing beyond end of list", gotEx); + assertTrue(gotEx, "Should see exception raised by accessing beyond end of list"); } + @Test public void testMap1() { model.read(getFileName("ontology/list5.rdf")); @@ -424,6 +439,7 @@ public void testMap1() { } + @Test public void testReduce() { model.read(getFileName("ontology/list5.rdf")); @@ -436,9 +452,10 @@ public Object reduce(final RDFNode n, final Object acc) { } }; - Assert.assertEquals("Result of reduce should be concatentation of local names", "abcde", root.reduce(f, "")); + assertEquals("abcde", root.reduce(f, ""), "Result of reduce should be concatentation of local names"); } + @Test public void testRemove() { final Resource nil = model.getResource(RDF.nil.getURI()); @@ -464,32 +481,33 @@ public void testRemove() { list1.removeList(); // model should now be empty - Assert.assertEquals("Model should be empty after deleting two lists", 0, model.size()); + assertEquals(0, model.size(), "Model should be empty after deleting two lists"); // selective remove RDFList list2 = (nil.as(RDFList.class)).cons(r2).cons(r1).cons(r0); - Assert.assertTrue("list should contain x ", list2.contains(r0)); - Assert.assertTrue("list should contain y ", list2.contains(r1)); - Assert.assertTrue("list should contain z ", list2.contains(r2)); + assertTrue(list2.contains(r0), "list should contain x "); + assertTrue(list2.contains(r1), "list should contain y "); + assertTrue(list2.contains(r2), "list should contain z "); list2 = list2.remove(r1); - Assert.assertTrue("list should contain x ", list2.contains(r0)); - Assert.assertTrue("list should contain y ", !list2.contains(r1)); - Assert.assertTrue("list should contain z ", list2.contains(r2)); + assertTrue(list2.contains(r0), "list should contain x "); + assertTrue(!list2.contains(r1), "list should contain y "); + assertTrue(list2.contains(r2), "list should contain z "); list2 = list2.remove(r0); - Assert.assertTrue("list should contain x ", !list2.contains(r0)); - Assert.assertTrue("list should contain y ", !list2.contains(r1)); - Assert.assertTrue("list should contain z ", list2.contains(r2)); + assertTrue(!list2.contains(r0), "list should contain x "); + assertTrue(!list2.contains(r1), "list should contain y "); + assertTrue(list2.contains(r2), "list should contain z "); list2 = list2.remove(r2); - Assert.assertTrue("list should contain x ", !list2.contains(r0)); - Assert.assertTrue("list should contain y ", !list2.contains(r1)); - Assert.assertTrue("list should contain z ", !list2.contains(r2)); - Assert.assertTrue("list should be empty", list2.isEmpty()); + assertTrue(!list2.contains(r0), "list should contain x "); + assertTrue(!list2.contains(r1), "list should contain y "); + assertTrue(!list2.contains(r2), "list should contain z "); + assertTrue(list2.isEmpty(), "list should be empty"); } + @Test public void testReplace() { model.read(getFileName("ontology/list5.rdf")); @@ -505,7 +523,7 @@ public void testReplace() { // then check them for ( int i = 0 ; i < toSet.length ; i++ ) { - Assert.assertEquals("list element " + i + " is not correct", toSet[i], l1.get(i)); + assertEquals(toSet[i], l1.get(i), "list element " + i + " is not correct"); } // now test we get an exception for going beyong the end of the list @@ -516,10 +534,11 @@ public void testReplace() { gotEx = true; } - Assert.assertTrue("Should see exception raised by accessing beyond end of list", gotEx); + assertTrue(gotEx, "Should see exception raised by accessing beyond end of list"); } + @Test public void testSetHead() { final Resource root = model.createResource(TestList.NS + "root"); @@ -538,14 +557,15 @@ public void testSetHead() { final RDFList l1 = getListRoot(model); checkValid("sethead1", l1, true); - Assert.assertEquals("List head should be 'fred'", "fred", ((Literal)l1.getHead()).getString()); + assertEquals("fred", ((Literal)l1.getHead()).getString(), "List head should be 'fred'"); l1.setHead(model.createTypedLiteral(42)); checkValid("sethead2", l1, true); - Assert.assertEquals("List head should be '42'", 42, ((Literal)l1.getHead()).getInt()); + assertEquals(42, ((Literal)l1.getHead()).getInt(), "List head should be '42'"); } + @Test public void testSetTail() { final Model m = ModelFactory.createDefaultModel(); @@ -570,11 +590,11 @@ public void testSetTail() { m.add(list1, RDF.rest, nil); final RDFList l2 = list1.as(RDFList.class); - Assert.assertNotNull("as(RDFList) should not return null for root", l2); + assertNotNull(l2, "as(RDFList) should not return null for root"); checkValid("settail2", l2, true); - Assert.assertEquals("l1 should have length 1", 1, l1.size()); - Assert.assertEquals("l2 should have length 1", 1, l2.size()); + assertEquals(1, l1.size(), "l1 should have length 1"); + assertEquals(1, l2.size(), "l2 should have length 1"); // use set tail to join the lists together l1.setTail(l2); @@ -582,11 +602,12 @@ public void testSetTail() { checkValid("settail3", l1, true); checkValid("settail4", l2, true); - Assert.assertEquals("l1 should have length 2", 2, l1.size()); - Assert.assertEquals("l2 should have length 1", 1, l2.size()); + assertEquals(2, l1.size(), "l1 should have length 2"); + assertEquals(1, l2.size(), "l2 should have length 1"); } + @Test public void testTail() { for ( int i = 0 ; i <= 5 ; i++ ) { model.read(getFileName("ontology/list" + i + ".rdf")); @@ -598,10 +619,11 @@ public void testTail() { l0 = l0.getTail(); } - Assert.assertTrue("Should have reached the end of the list after " + i + " getTail()'s", l0.isEmpty()); + assertTrue(l0.isEmpty(), "Should have reached the end of the list after " + i + " getTail()'s"); } } + @Test public void testValidity() { final Resource root = model.createResource(TestList.NS + "root"); final Property p = model.createProperty(TestList.NS, "p"); @@ -630,6 +652,7 @@ public void testValidity() { checkValid("valid5", l1, true); } + @Test public void testStmtGetList() { Resource root = model.createResource(TestList.NS + "root"); Property p = model.createProperty(TestList.NS, "p"); @@ -645,9 +668,10 @@ public void testStmtGetList() { RDFList list1 = model.getList(obj); boolean b = list0.sameListAs(list1); - assertTrue("Different lists: expected: " + list0 + " : got: " + list1, b); + assertTrue(b, "Different lists: expected: " + list0 + " : got: " + list1); } + @Test public void testModelGetList() { Resource root = model.createResource(TestList.NS + "root"); Property p = model.createProperty(TestList.NS, "p"); @@ -661,9 +685,10 @@ public void testModelGetList() { RDFList list1 = model.listStatements(r, p, (Resource)null).next().getList(); boolean b = list0.sameListAs(list1); - assertTrue("Different lists: expected: " + list0 + " : got: " + list1, b); + assertTrue(b, "Different lists: expected: " + list0 + " : got: " + list1); } + @Test public void testModelGetEmptyList() { Resource root = model.createResource(TestList.NS + "root"); Property p = model.createProperty(TestList.NS, "p"); @@ -675,7 +700,7 @@ public void testModelGetEmptyList() { RDFList list1 = model.listStatements(r, p, (Resource)null).next().getList(); boolean b = list0.sameListAs(list1); - assertTrue("Different lists: expected: " + list0 + " : got: " + list1, b); + assertTrue(b, "Different lists: expected: " + list0 + " : got: " + list1); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestListStatements.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestListStatements.java index 548bd719b93..d1b62926ae6 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestListStatements.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestListStatements.java @@ -21,25 +21,25 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + import java.util.List; -import junit.framework.JUnit4TestAdapter; import org.apache.jena.vocabulary.RDF; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TestListStatements { private static Model m; private static Resource s; private static Property p; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() { TestListStatements.m = ModelFactory.createDefaultModel(); - final Resource s = TestListStatements.m.createResource("http://www.a.com/s"); - final Property p = TestListStatements.m.createProperty("http://www.a.com/p"); + s = TestListStatements.m.createResource("http://www.a.com/s"); + p = TestListStatements.m.createProperty("http://www.a.com/p"); TestListStatements.m.add(s, p, TestListStatements.m.createResource("http://www.a.com/o")); TestListStatements.m.add(s, p, "texte", "fr"); @@ -48,11 +48,7 @@ public static void setUpBeforeClass() { TestListStatements.m.add(TestListStatements.m.createLiteralStatement(s, p, 1789)); } - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TestListStatements.class); - } - - @AfterClass + @AfterAll public static void tearDownAfterClass() { TestListStatements.m = null; TestListStatements.s = null; @@ -62,43 +58,43 @@ public static void tearDownAfterClass() { @Test public final void thereAre2LitsWoLang() { final StmtIterator it = TestListStatements.m.listStatements(TestListStatements.s, TestListStatements.p, null, ""); - Assert.assertTrue(it.toList().size() == 2); + assertTrue(it.toList().size() == 2); } @Test public final void thereAre4Literals() { final StmtIterator it = TestListStatements.m.listStatements(TestListStatements.s, TestListStatements.p, null, null); - Assert.assertTrue(it.toList().size() == 4); + assertTrue(it.toList().size() == 4); } @Test public final void thereIsOneFrench() { final StmtIterator it = TestListStatements.m.listStatements(TestListStatements.s, TestListStatements.p, null, "fr"); final List lis = it.toList(); - Assert.assertTrue(lis.size() == 1); - Assert.assertTrue(lis.get(0).getObject().toString().equals("texte@fr")); + assertTrue(lis.size() == 1); + assertTrue(lis.get(0).getObject().toString().equals("\"texte\"@fr")); } @Test public final void theresAreTwoText() { final StmtIterator it = TestListStatements.m.listStatements(TestListStatements.s, TestListStatements.p, "text", null); final List lis = it.toList(); - Assert.assertTrue(lis.size() == 2); + assertTrue(lis.size() == 2); } @Test public final void theresOneTextEN() { final StmtIterator it = TestListStatements.m.listStatements(TestListStatements.s, TestListStatements.p, "text", "en"); final List lis = it.toList(); - Assert.assertTrue(lis.size() == 1); - Assert.assertTrue(lis.get(0).getObject().toString().equals("text@en")); + assertTrue(lis.size() == 1); + assertTrue(lis.get(0).getObject().toString().equals("\"text\"@en")); } @Test public final void theresOneTextWoLang() { final StmtIterator it = TestListStatements.m.listStatements(TestListStatements.s, TestListStatements.p, "text", ""); final List lis = it.toList(); - Assert.assertTrue(lis.size() == 1); + assertTrue(lis.size() == 1); } @Test @@ -109,7 +105,7 @@ public final void theresOneWithABNodeObject() { StmtIterator it = m.listStatements(null, null, anon); final List lis = it.toList(); - Assert.assertTrue(lis.size() == 1); + assertTrue(lis.size() == 1); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestListSubjects.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestListSubjects.java index 18c30d0a566..e8d30f7153b 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestListSubjects.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestListSubjects.java @@ -21,20 +21,26 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; -import org.junit.Assert; - -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.shared.PropertyNotFoundException; import org.apache.jena.test.JenaTestLib; import org.apache.jena.util.iterator.WrappedIterator; import org.apache.jena.vocabulary.RDF; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestListSubjects extends AbstractModelTestBase { static final String subjectPrefix = "http://aldabaran/test8/s"; @@ -57,14 +63,10 @@ public class TestListSubjects extends AbstractModelTestBase { String[] tvStrings = {"test8 testing string 1", "test8 testing string 2"}; String[] langs = {"en", "fr"}; - public TestListSubjects(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - protected void assertEquiv(final Set set, final Iterator iterator) { final List L = WrappedIterator.create(iterator).toList(); - Assert.assertEquals(set.size(), L.size()); - Assert.assertEquals(set, new HashSet<>(L)); + assertEquals(set.size(), L.size()); + assertEquals(set, new HashSet<>(L)); } protected void fillModel() { @@ -120,10 +122,11 @@ protected void fillModel() { // model.addLiteral( resource( "X" ), property( "P" ), new Object() ); // List answers = model.listResourcesWithProperty( property( "P" ), d // ).toList(); - // assertEquals( listOfOne( resource( "S" ) ), answers ); + // assertEquals(listOfOne( resource( "S" ) ), answers ); // } @Override + @BeforeEach public void setUp() { super.setUp(); fillModel(); @@ -137,16 +140,18 @@ protected Set subjectsTo(final String prefix, final int limit) { return result; } + @Test public void testGetRequiredProperty() { model.getRequiredProperty(subjects[1], predicates[1]); try { model.getRequiredProperty(subjects[1], RDF.value); - Assert.fail("should not find absent property"); + fail("should not find absent property"); } catch (final PropertyNotFoundException e) { JenaTestLib.pass(); } } + @Test public void testListSubjects() { assertEquiv(subjectsTo(TestListSubjects.subjectPrefix, 5), model.listResourcesWithProperty(predicates[4])); @@ -196,19 +201,19 @@ public void testListSubjects() { assertEquiv(subjectsTo(TestListSubjects.subjectPrefix, 0), model.listSubjectsWithProperty(predicates[0], tvStrings[1], langs[1])); - // assertEquiv( subjectsTo( subjectPrefix, 2 ), + // assertEquiv(subjectsTo( subjectPrefix, 2 ), // model.listResourcesWithProperty( predicates[0], tvLitObjs[0] ) ); // - // assertEquiv( subjectsTo( subjectPrefix, 0 ), + // assertEquiv(subjectsTo( subjectPrefix, 0 ), // model.listResourcesWithProperty( predicates[0], tvLitObjs[1] ) ); // - // assertEquiv( subjectsTo( subjectPrefix, 0 ), + // assertEquiv(subjectsTo( subjectPrefix, 0 ), // model.listResourcesWithProperty( predicates[0], tvResObjs[0] ) ); // - // assertEquiv( subjectsTo( subjectPrefix, 0 ), + // assertEquiv(subjectsTo( subjectPrefix, 0 ), // model.listResourcesWithProperty( predicates[0], tvResObjs[1] ) ); - // assertEquiv( new HashSet( Arrays.asList( objects ) ), + // assertEquiv(new HashSet( Arrays.asList( objects ) ), // model.listObjectsOfProperty( predicates[1] ) ); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestListSubjectsEtc.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestListSubjectsEtc.java index 04a10773d0a..dbf6a91f325 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestListSubjectsEtc.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestListSubjectsEtc.java @@ -21,60 +21,66 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.test.JenaTestLib; -import org.junit.Assert; - /** * TestListSubjectsEtc - tests for listSubjects, listObjects [and listPredicates, if * it were to exist] TODO make preperly generic, add missing test cases [we're * relying, at root, on SimpleQueryHandler] */ +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestListSubjectsEtc extends AbstractModelTestBase { - public TestListSubjectsEtc(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } + @Test public void testListObjectsNoRemove() { - final Model m = ModelHelper.modelWithStatements(this, "a P b; b Q c; c R a"); + final Model m = modelWithStatements("a P b; b Q c; c R a"); final NodeIterator it = m.listObjects(); it.next(); try { it.remove(); - Assert.fail("listObjects should not support .remove()"); + fail("listObjects should not support .remove()"); } catch (final UnsupportedOperationException e) { JenaTestLib.pass(); } } + @Test public void testListSubjectsNoRemove() { - final Model m = ModelHelper.modelWithStatements(this, "a P b; b Q c; c R a"); + final Model m = modelWithStatements("a P b; b Q c; c R a"); final ResIterator it = m.listSubjects(); it.next(); try { it.remove(); - Assert.fail("listSubjects should not support .remove()"); + fail("listSubjects should not support .remove()"); } catch (final UnsupportedOperationException e) { JenaTestLib.pass(); } } + @Test public void testListSubjectsWorksAfterRemoveProperties() { - final Model m = ModelHelper.modelWithStatements(this, "p1 before terminal; p2 before terminal"); + final Model m = modelWithStatements("p1 before terminal; p2 before terminal"); m.createResource("eh:/p1").removeProperties(); - ModelHelper.assertIsoModels(ModelHelper.modelWithStatements(this, "p2 before terminal"), m); - Assert.assertEquals(ModelHelper.resourceSet("p2"), m.listSubjects().toSet()); + ModelHelper.assertIsoModels(modelWithStatements("p2 before terminal"), m); + assertEquals(ModelHelper.resourceSet("p2"), m.listSubjects().toSet()); } + @Test public void testListSubjectsWorksAfterRemovePropertiesWIthLots() { - final Model m = ModelHelper.modelWithStatements(this, "p2 before terminal"); + final Model m = modelWithStatements("p2 before terminal"); for ( int i = 0 ; i < 100 ; i += 1 ) { ModelHelper.modelAdd(m, "p1 hasValue " + i); } m.createResource("eh:/p1").removeProperties(); - ModelHelper.assertIsoModels(ModelHelper.modelWithStatements(this, "p2 before terminal"), m); - Assert.assertEquals(ModelHelper.resourceSet("p2"), m.listSubjects().toSet()); + ModelHelper.assertIsoModels(modelWithStatements("p2 before terminal"), m); + assertEquals(ModelHelper.resourceSet("p2"), m.listSubjects().toSet()); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiteralImpl.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiteralImpl.java index 3ba093d298b..d597102f0b4 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiteralImpl.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiteralImpl.java @@ -21,22 +21,27 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.datatypes.DatatypeFormatException; import org.apache.jena.datatypes.TypeMapper; import org.apache.jena.datatypes.xsd.XSDDatatype; import org.apache.jena.graph.Node; import org.apache.jena.graph.NodeFactory; import org.apache.jena.graph.impl.AdhocDatatype; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.test.JenaTestLib; -import org.junit.Assert; - /** * TestLiteralImpl - minimal, this is the first time an extra test has been needed * above the regression testing. */ +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestLiteralImpl extends AbstractModelTestBase { static class UniqueValueClass1 { String value; @@ -64,13 +69,10 @@ public String toString() { } } - public TestLiteralImpl(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - /** * Test that a literal node can be as'ed into a literal. */ + @Test public void testAsLiteral() { ModelHelper.literal(model, "17").as(Literal.class); } @@ -78,10 +80,11 @@ public void testAsLiteral() { /** * Test that a non-literal node cannot be as'ed into a literal */ + @Test public void testCannotAsNonLiteral() { try { ModelHelper.resource(model, "plumPie").as(Literal.class); - Assert.fail("non-literal cannot be converted to literal"); + fail("non-literal cannot be converted to literal"); } catch (final LiteralRequiredException l) { JenaTestLib.pass(); } @@ -90,6 +93,7 @@ public void testCannotAsNonLiteral() { /** * Test that a literal node can be as'ed into a number */ + @Test public void testAsNumber() { int number = ModelHelper.literal(model, "17").getInt(); assertEquals(17, number); @@ -98,6 +102,7 @@ public void testAsNumber() { /** * Test that a literal that is not a number cannot be as'ed into a number */ + @Test public void testCannotAsNonNumber() { try { Node node = NodeFactory.createLiteralDT("1984", XSDDatatype.XSDgYear); @@ -118,16 +123,18 @@ public void testCannotAsNonNumber() { } } + @Test public void testInModel() { final Model m1 = createModel(); final Model m2 = createModel(); final Literal l1 = m1.createLiteral("17"); final Literal l2 = l1.inModel(m2); - Assert.assertEquals(l1, l2); - Assert.assertSame(m2, l2.getModel()); + assertEquals(l1, l2); + assertSame(m2, l2.getModel()); } + @Test public void testLiteralHasModel() { testLiteralHasModel(model, model.createLiteral("hello, world")); testLiteralHasModel(model, model.createLiteral("hello, world", "en-GB")); @@ -137,14 +144,15 @@ public void testLiteralHasModel() { } private void testLiteralHasModel(final Model m, final Literal lit) { - Assert.assertSame(m, lit.getModel()); + assertSame(m, lit.getModel()); } + @Test public void testSameAdhocClassUS() { try { final UniqueValueClass1 ra = new UniqueValueClass1("rhubarb"); final UniqueValueClass1 rb = new UniqueValueClass1("cottage"); - Assert.assertNull("not expecting registered RDF Datatype", TypeMapper.getInstance().getTypeByValue(ra)); + assertNull(TypeMapper.getInstance().getTypeByValue(ra), "not expecting registered RDF Datatype"); final Literal la = model.createTypedLiteral(ra); // Sets the type // mapper // - contaminates it @@ -152,31 +160,32 @@ public void testSameAdhocClassUS() { // UniqueValueClass1 final Literal lb = model.createTypedLiteral(rb); JenaTestLib.assertInstanceOf(AdhocDatatype.class, la.getDatatype()); - Assert.assertSame(la.getDatatype(), lb.getDatatype()); - Assert.assertNotNull(TypeMapper.getInstance().getTypeByValue(ra)); + assertSame(la.getDatatype(), lb.getDatatype()); + assertNotNull(TypeMapper.getInstance().getTypeByValue(ra)); } finally { TypeMapper.reset(); } } // Tests are not necessarily run in order so use UniqueValueClass2 + @Test public void testTypedLiteralTypesAndValues() { // Resource r = model.createResource( "eh:/rhubarb" ); final UniqueValueClass2 r = new UniqueValueClass2("rhubarb"); - Assert.assertNull("not expecting registered RDF Datatype", TypeMapper.getInstance().getTypeByValue(r)); + assertNull(TypeMapper.getInstance().getTypeByValue(r), "not expecting registered RDF Datatype"); final Literal typed = model.createTypedLiteral(r); // Sets the type // mapper - // contaminates it // with // UniqueValueClass2 final Literal string = model.createLiteral(r.value); - Assert.assertEquals(string.getLexicalForm(), typed.getLexicalForm()); - Assert.assertEquals(string.getLanguage(), typed.getLanguage()); + assertEquals(string.getLexicalForm(), typed.getLexicalForm()); + assertEquals(string.getLanguage(), typed.getLanguage()); JenaTestLib.assertDiffer(string.getDatatypeURI(), typed.getDatatypeURI()); - Assert.assertNotNull("a datatype should have been invented for Resource[Impl]", typed.getDatatype()); + assertNotNull(typed.getDatatype(), "a datatype should have been invented for Resource[Impl]"); JenaTestLib.assertDiffer(typed, string); JenaTestLib.assertDiffer(typed.getValue(), string.getValue()); - Assert.assertEquals(r, typed.getValue()); + assertEquals(r, typed.getValue()); JenaTestLib.assertDiffer(typed.hashCode(), string.hashCode()); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiterals.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiterals.java index e14b15fe5a8..9ee2e09dcc2 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiterals.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiterals.java @@ -21,44 +21,47 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; -import org.apache.jena.test.JenaTestLib; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; -public class TestLiterals extends AbstractModelTestBase { +import org.apache.jena.test.JenaTestLib; - public TestLiterals(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") +public class TestLiterals extends AbstractModelTestBase { protected void assertInRange(final long min, final long x, final long max) { if ( (min <= x) && (x <= max) ) { return; } else { - Assert.fail("outside range: " + x + " min: " + min + " max: " + max); + fail("outside range: " + x + " min: " + min + " max: " + max); } } protected void assertOutsideRange(final long min, final long x, final long max) { if ( (min <= x) && (x <= max) ) { - Assert.fail("inside range: " + x + " min: " + min + " max: " + max); + fail("inside range: " + x + " min: " + min + " max: " + max); } } + @Test public void testBooleans() { - Assert.assertTrue(model.createTypedLiteral(true).getBoolean()); - Assert.assertFalse(model.createTypedLiteral(false).getBoolean()); + assertTrue(model.createTypedLiteral(true).getBoolean()); + assertFalse(model.createTypedLiteral(false).getBoolean()); } protected void testByte(final Model model, final byte tv) { final Literal l = model.createTypedLiteral(tv); - Assert.assertEquals(tv, l.getByte()); - Assert.assertEquals(tv, l.getShort()); - Assert.assertEquals(tv, l.getInt()); - Assert.assertEquals(tv, l.getLong()); + assertEquals(tv, l.getByte()); + assertEquals(tv, l.getShort()); + assertEquals(tv, l.getInt()); + assertEquals(tv, l.getLong()); } + @Test public void testByteLiterals() { testByte(model, (byte)0); testByte(model, (byte)-1); @@ -67,9 +70,10 @@ public void testByteLiterals() { } protected void testCharacter(final Model model, final char tv) { - Assert.assertEquals(tv, model.createTypedLiteral(tv).getChar()); + assertEquals(tv, model.createTypedLiteral(tv).getChar()); } + @Test public void testCharacterLiterals() { testCharacter(model, 'A'); testCharacter(model, 'a'); @@ -82,9 +86,10 @@ public void testCharacterLiterals() { } protected void testDouble(final Model model, final double tv) { - Assert.assertEquals(tv, model.createTypedLiteral(tv).getDouble(), AbstractModelTestBase.dDelta); + assertEquals(tv, model.createTypedLiteral(tv).getDouble(), AbstractModelTestBase.dDelta); } + @Test public void testDoubleLiterals() { testDouble(model, 0.0); testDouble(model, 1.0); @@ -95,9 +100,10 @@ public void testDoubleLiterals() { } protected void testFloat(final Model model, final float tv) { - Assert.assertEquals(tv, model.createTypedLiteral(tv).getFloat(), AbstractModelTestBase.fDelta); + assertEquals(tv, model.createTypedLiteral(tv).getFloat(), AbstractModelTestBase.fDelta); } + @Test public void testFloatLiterals() { testFloat(model, 0.0f); testFloat(model, 1.0f); @@ -117,21 +123,22 @@ public void testFloatLiterals() { protected void testInt(final Model model, final int tv) { final Literal l = model.createTypedLiteral(tv); try { - Assert.assertEquals(tv, l.getByte()); + assertEquals(tv, l.getByte()); assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE); } catch (final IllegalArgumentException e) { assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE); } try { - Assert.assertEquals(tv, l.getShort()); + assertEquals(tv, l.getShort()); assertInRange(Short.MIN_VALUE, tv, Short.MAX_VALUE); } catch (final IllegalArgumentException e) { assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE); } - Assert.assertEquals(tv, l.getInt()); - Assert.assertEquals(tv, l.getLong()); + assertEquals(tv, l.getInt()); + assertEquals(tv, l.getLong()); } + @Test public void testIntLiterals() { testInt(model, 0); testInt(model, -1); @@ -141,11 +148,12 @@ public void testIntLiterals() { protected void testLanguagedString(final Model model, final String tv, final String lang) { final Literal l = model.createLiteral(tv, lang); - Assert.assertEquals(tv, l.getString()); - Assert.assertEquals(tv, l.getLexicalForm()); - Assert.assertEquals(lang, l.getLanguage()); + assertEquals(tv, l.getString()); + assertEquals(tv, l.getLexicalForm()); + assertEquals(lang, l.getLanguage()); } + @Test public void testLanguagedStringLiterals() { testLanguagedString(model, "", "en"); testLanguagedString(model, "chat", "fr"); @@ -154,26 +162,27 @@ public void testLanguagedStringLiterals() { protected void testLong(final Model model, final long tv) { final Literal l = model.createTypedLiteral(tv); try { - Assert.assertEquals(tv, l.getByte()); + assertEquals(tv, l.getByte()); assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE); } catch (final IllegalArgumentException e) { assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE); } try { - Assert.assertEquals(tv, l.getShort()); + assertEquals(tv, l.getShort()); assertInRange(Short.MIN_VALUE, tv, Short.MAX_VALUE); } catch (final IllegalArgumentException e) { assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE); } try { - Assert.assertEquals(tv, l.getInt()); + assertEquals(tv, l.getInt()); assertInRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE); } catch (final IllegalArgumentException e) { assertOutsideRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE); } - Assert.assertEquals(tv, l.getLong()); + assertEquals(tv, l.getLong()); } + @Test public void testLongLiterals() { testLong(model, 0); testLong(model, -1); @@ -183,11 +192,12 @@ public void testLongLiterals() { protected void testPlainString(final Model model, final String tv) { final Literal l = model.createLiteral(tv); - Assert.assertEquals(tv, l.getString()); - Assert.assertEquals(tv, l.getLexicalForm()); - Assert.assertEquals("", l.getLanguage()); + assertEquals(tv, l.getString()); + assertEquals(tv, l.getLexicalForm()); + assertEquals("", l.getLanguage()); } + @Test public void testPlainStringLiterals() { testPlainString(model, ""); testPlainString(model, "A test string"); @@ -197,16 +207,17 @@ public void testPlainStringLiterals() { protected void testShort(final Model model, final short tv) { final Literal l = model.createTypedLiteral(tv); try { - Assert.assertEquals(tv, l.getByte()); + assertEquals(tv, l.getByte()); assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE); } catch (final IllegalArgumentException e) { assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE); } - Assert.assertEquals(tv, l.getShort()); - Assert.assertEquals(tv, l.getInt()); - Assert.assertEquals(tv, l.getLong()); + assertEquals(tv, l.getShort()); + assertEquals(tv, l.getInt()); + assertEquals(tv, l.getLong()); } + @Test public void testShortLiterals() { testShort(model, (short)0); testShort(model, (short)-1); @@ -214,20 +225,21 @@ public void testShortLiterals() { testShort(model, Short.MAX_VALUE); } + @Test public void testStringLiteralEquality() { - Assert.assertEquals(model.createLiteral("A"), model.createLiteral("A")); - Assert.assertEquals(model.createLiteral("Alpha"), model.createLiteral("Alpha")); + assertEquals(model.createLiteral("A"), model.createLiteral("A")); + assertEquals(model.createLiteral("Alpha"), model.createLiteral("Alpha")); JenaTestLib.assertDiffer(model.createLiteral("Alpha"), model.createLiteral("Beta")); JenaTestLib.assertDiffer(model.createLiteral("A", "en"), model.createLiteral("A")); JenaTestLib.assertDiffer(model.createLiteral("A"), model.createLiteral("A", "en")); JenaTestLib.assertDiffer(model.createLiteral("A", "en"), model.createLiteral("A", "fr")); - Assert.assertEquals(model.createLiteral("A", "en"), model.createLiteral("A", "en")); + assertEquals(model.createLiteral("A", "en"), model.createLiteral("A", "en")); } // protected void testLiteralObject( Model model, int x ) // { // LitTestObj tv = new LitTestObj( x ); // LitTestObjF factory = new LitTestObjF(); - // assertEquals( tv, model.createTypedLiteral( tv ).getObject( factory ) ); + // assertEquals(tv, model.createTypedLiteral( tv ).getObject( factory ) ); // } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiteralsInModel.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiteralsInModel.java index c7aa40cdf8d..50dbb32d49d 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiteralsInModel.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestLiteralsInModel.java @@ -21,67 +21,77 @@ package org.apache.jena.rdf.model; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestLiteralsInModel extends AbstractModelTestBase { private Resource X; private Property P; - public TestLiteralsInModel(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - @Override + @BeforeEach public void setUp() { super.setUp(); X = ModelHelper.resource("X"); P = ModelHelper.property("P"); } + @Test public void testAddWithBooleanObject() { model.addLiteral(X, P, true); - Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(true))); - Assert.assertTrue(model.containsLiteral(X, P, true)); + assertTrue(model.contains(X, P, model.createTypedLiteral(true))); + assertTrue(model.containsLiteral(X, P, true)); } + @Test public void testAddWithCharObject() { model.addLiteral(X, P, 'x'); - Assert.assertTrue(model.contains(X, P, model.createTypedLiteral('x'))); - Assert.assertTrue(model.containsLiteral(X, P, 'x')); + assertTrue(model.contains(X, P, model.createTypedLiteral('x'))); + assertTrue(model.containsLiteral(X, P, 'x')); } + @Test public void testAddWithDoubleObject() { model.addLiteral(X, P, 14.0d); - Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(14.0d))); - Assert.assertTrue(model.containsLiteral(X, P, 14.0d)); + assertTrue(model.contains(X, P, model.createTypedLiteral(14.0d))); + assertTrue(model.containsLiteral(X, P, 14.0d)); } + @Test public void testAddWithFloatObject() { model.addLiteral(X, P, 14.0f); - Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(14.0f))); - Assert.assertTrue(model.containsLiteral(X, P, 14.0f)); + assertTrue(model.contains(X, P, model.createTypedLiteral(14.0f))); + assertTrue(model.containsLiteral(X, P, 14.0f)); } + @Test public void testAddWithIntObject() { model.addLiteral(X, P, 99); - Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(99))); - Assert.assertTrue(model.containsLiteral(X, P, 99)); + assertTrue(model.contains(X, P, model.createTypedLiteral(99))); + assertTrue(model.containsLiteral(X, P, 99)); } + @Test public void testAddWithLiteralObject() { final Literal lit = model.createLiteral("spoo"); model.addLiteral(X, P, lit); - Assert.assertTrue(model.contains(X, P, lit)); - Assert.assertTrue(model.containsLiteral(X, P, lit)); + assertTrue(model.contains(X, P, lit)); + assertTrue(model.containsLiteral(X, P, lit)); } + @Test public void testAddWithLongObject() { model.addLiteral(X, P, 99L); - Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(99L))); - Assert.assertTrue(model.containsLiteral(X, P, 99L)); + assertTrue(model.contains(X, P, model.createTypedLiteral(99L))); + assertTrue(model.containsLiteral(X, P, 99L)); } // that version of addLiteral is deprecated; test removed. @@ -89,7 +99,7 @@ public void testAddWithLongObject() { // { // Object z = new Date(); // model.addLiteral( X, P, z ); - // assertTrue( model.contains( X, P, model.createTypedLiteral( z ) ) ); - // assertTrue( model.containsLiteral( X, P, z ) ); + // assertTrue(model.contains( X, P, model.createTypedLiteral( z ) ) ); + // assertTrue(model.containsLiteral( X, P, z ) ); // } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModel.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModel.java index 27e92ee1021..12a3c7beab9 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModel.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModel.java @@ -21,19 +21,24 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.util.ArrayList; import java.util.List; -import org.junit.Assert; - import org.apache.jena.graph.GraphTestLib; import org.apache.jena.graph.Node; import org.apache.jena.graph.Triple; import org.apache.jena.junit.NodeCreateUtils; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.test.JenaTestLib; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestModel extends AbstractModelTestBase { /** @@ -48,108 +53,116 @@ public class TestModel extends AbstractModelTestBase { {"x R y; a P b", "x R ??", "a P b"}, {"x R y; a P b", "x ?? y", "a P b"}, {"x R y; a P b", "?? ?? ??", ""}, {"x R y; a P b; c P d", "?? P ??", "x R y"}, {"x R y; a P b; x S y", "x ?? ??", "a P b"},}; - public TestModel(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - protected Model copy(final Model m) { return createModel().add(m); } + @Test public void testAsRDF() { testPresentAsRDFNode(GraphTestLib.node("a"), Resource.class); testPresentAsRDFNode(GraphTestLib.node("17"), Literal.class); testPresentAsRDFNode(GraphTestLib.node("_b"), Resource.class); } + @Test public void testContainsResource() { ModelHelper.modelAdd(model, "x R y; _a P _b"); - Assert.assertTrue(model.containsResource(ModelHelper.resource(model, "x"))); - Assert.assertTrue(model.containsResource(ModelHelper.resource(model, "R"))); - Assert.assertTrue(model.containsResource(ModelHelper.resource(model, "y"))); - Assert.assertTrue(model.containsResource(ModelHelper.resource(model, "_a"))); - Assert.assertTrue(model.containsResource(ModelHelper.resource(model, "P"))); - Assert.assertTrue(model.containsResource(ModelHelper.resource(model, "_b"))); - Assert.assertFalse(model.containsResource(ModelHelper.resource(model, "i"))); - Assert.assertFalse(model.containsResource(ModelHelper.resource(model, "_j"))); + assertTrue(model.containsResource(ModelHelper.resource(model, "x"))); + assertTrue(model.containsResource(ModelHelper.resource(model, "R"))); + assertTrue(model.containsResource(ModelHelper.resource(model, "y"))); + assertTrue(model.containsResource(ModelHelper.resource(model, "_a"))); + assertTrue(model.containsResource(ModelHelper.resource(model, "P"))); + assertTrue(model.containsResource(ModelHelper.resource(model, "_b"))); + assertFalse(model.containsResource(ModelHelper.resource(model, "i"))); + assertFalse(model.containsResource(ModelHelper.resource(model, "_j"))); } + @Test public void testCreateBlankFromNode() { final RDFNode S = model.getRDFNode(NodeCreateUtils.create("_Blank")); JenaTestLib.assertInstanceOf(Resource.class, S); - Assert.assertEquals(new AnonId("_Blank"), ((Resource)S).getId()); + assertEquals(new AnonId("_Blank"), ((Resource)S).getId()); } + @Test public void testCreateLiteralFromNode() { final RDFNode S = model.getRDFNode(NodeCreateUtils.create("42")); JenaTestLib.assertInstanceOf(Literal.class, S); - Assert.assertEquals("42", ((Literal)S).getLexicalForm()); + assertEquals("42", ((Literal)S).getLexicalForm()); } + @Test public void testCreateListFromEmptyIterator() { RDFList list = model.createList(new ArrayList().iterator()); - Assert.assertEquals(0, list.size()); + assertEquals(0, list.size()); } + @Test public void testCreateSingletonListFromIterator() { List expected = new ArrayList<>(); expected.add(model.createResource()); RDFList list = model.createList(expected.iterator()); - Assert.assertEquals(expected, list.asJavaList()); + assertEquals(expected, list.asJavaList()); } + @Test public void testCreateListFromIterator() { List expected = new ArrayList<>(); expected.add(model.createResource()); expected.add(model.createResource()); expected.add(model.createResource()); RDFList list = model.createList(expected.iterator()); - Assert.assertEquals(expected, list.asJavaList()); + assertEquals(expected, list.asJavaList()); } + @Test public void testCreateResourceFromNode() { final RDFNode S = model.getRDFNode(NodeCreateUtils.create("spoo:S")); JenaTestLib.assertInstanceOf(Resource.class, S); - Assert.assertEquals("spoo:S", ((Resource)S).getURI()); + assertEquals("spoo:S", ((Resource)S).getURI()); } /** * Test the new version of getProperty(), which delivers null for not-found * properties. */ + @Test public void testGetProperty() { ModelHelper.modelAdd(model, "x P a; x P b; x R c"); final Resource x = ModelHelper.resource(model, "x"); - Assert.assertEquals(ModelHelper.resource(model, "c"), x.getProperty(ModelHelper.property(model, "R")).getObject()); + assertEquals(ModelHelper.resource(model, "c"), x.getProperty(ModelHelper.property(model, "R")).getObject()); final RDFNode ob = x.getProperty(ModelHelper.property(model, "P")).getObject(); - Assert.assertTrue(ob.equals(ModelHelper.resource(model, "a")) || ob.equals(ModelHelper.resource(model, "b"))); - Assert.assertNull(x.getProperty(ModelHelper.property(model, "noSuchPropertyHere"))); + assertTrue(ob.equals(ModelHelper.resource(model, "a")) || ob.equals(ModelHelper.resource(model, "b"))); + assertNull(x.getProperty(ModelHelper.property(model, "noSuchPropertyHere"))); } + @Test public void testIsClosedDelegatedToGraph() { - Assert.assertFalse(model.isClosed()); + assertFalse(model.isClosed()); model.close(); - Assert.assertTrue(model.isClosed()); + assertTrue(model.isClosed()); } + @Test public void testIsEmpty() { final Statement S1 = ModelHelper.statement(model, "model rdf:type nonEmpty"); final Statement S2 = ModelHelper.statement(model, "pinky rdf:type Pig"); - Assert.assertTrue(model.isEmpty()); + assertTrue(model.isEmpty()); model.add(S1); - Assert.assertFalse(model.isEmpty()); + assertFalse(model.isEmpty()); model.add(S2); - Assert.assertFalse(model.isEmpty()); + assertFalse(model.isEmpty()); model.remove(S1); - Assert.assertFalse(model.isEmpty()); + assertFalse(model.isEmpty()); model.remove(S2); - Assert.assertTrue(model.isEmpty()); + assertTrue(model.isEmpty()); } + @Test public void testLiteralNodeAsResourceFails() { try { model.wrapAsResource(GraphTestLib.node("17")); - Assert.fail("should fail to convert literal to Resource"); + fail("should fail to convert literal to Resource"); } catch (final UnsupportedOperationException e) { JenaTestLib.pass(); } @@ -157,10 +170,11 @@ public void testLiteralNodeAsResourceFails() { private void testPresentAsRDFNode(final Node n, final Class nodeClass) { final RDFNode r = model.asRDFNode(n); - Assert.assertSame(n, r.asNode()); + assertSame(n, r.asNode()); JenaTestLib.assertInstanceOf(nodeClass, r); } + @Test public void testRemoveAll() { testRemoveAll(""); testRemoveAll("a RR b"); @@ -170,8 +184,8 @@ public void testRemoveAll() { protected void testRemoveAll(final String statements) { ModelHelper.modelAdd(model, statements); - Assert.assertSame(model, model.removeAll()); - Assert.assertEquals("model should have size 0 following removeAll(): ", 0, model.size()); + assertSame(model, model.removeAll()); + assertEquals(0, model.size(), "model should have size 0 following removeAll(): "); } /** @@ -179,6 +193,7 @@ protected void testRemoveAll(final String statements) { * mean emptyness isn't available. This is why we go round the houses and test * that expected ~= initialContent + addedStuff - removed - initialContent. */ + @Test public void testRemoveSPO() { final Model mc = createModel(); for ( final String[] case1 : cases ) { @@ -191,7 +206,7 @@ public void testRemoveSPO() { final Resource S = (Resource)(s.equals(Node.ANY) ? null : mc.getRDFNode(s)); final Property P = ((p.equals(Node.ANY) ? null : mc.getRDFNode(p).as(Property.class))); final RDFNode O = o.equals(Node.ANY) ? null : mc.getRDFNode(o); - final Model expected = ModelHelper.modelWithStatements(this, case1[2]); + final Model expected = modelWithStatements(case1[2]); content.removeAll(S, P, O); final Model finalContent = copy(content).remove(baseContent); ModelHelper.assertIsoModels(case1[1], expected, finalContent); @@ -199,22 +214,25 @@ public void testRemoveSPO() { } } + @Test public void testToStatement() { final Triple t = GraphTestLib.triple("a P b"); final Statement s = model.asStatement(t); - Assert.assertEquals(GraphTestLib.node("a"), s.getSubject().asNode()); - Assert.assertEquals(GraphTestLib.node("P"), s.getPredicate().asNode()); - Assert.assertEquals(GraphTestLib.node("b"), s.getObject().asNode()); + assertEquals(GraphTestLib.node("a"), s.getSubject().asNode()); + assertEquals(GraphTestLib.node("P"), s.getPredicate().asNode()); + assertEquals(GraphTestLib.node("b"), s.getObject().asNode()); } + @Test public void testTransactions() { if ( model.supportsTransactions() ) model.executeInTxn(() -> {}); } + @Test public void testURINodeAsResource() { final Node n = GraphTestLib.node("a"); final Resource r = model.wrapAsResource(n); - Assert.assertSame(n, r.asNode()); + assertSame(n, r.asNode()); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelBulkUpdate.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelBulkUpdate.java index 0a4a160cadf..12efcf4560e 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelBulkUpdate.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelBulkUpdate.java @@ -21,54 +21,59 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.util.Arrays; import java.util.List; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; -import org.junit.Assert; - /** * Tests of the Model-level bulk update API. */ +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestModelBulkUpdate extends AbstractModelTestBase { - public TestModelBulkUpdate(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } + @Test public void testBulkByModel() { - Assert.assertEquals("precondition: model must be empty", 0, model.size()); - final Model A = ModelHelper.modelWithStatements(this, "clouds offer rain; trees offer shelter"); - final Model B = ModelHelper.modelWithStatements(this, "x R y; y Q z; z P x"); + assertEquals(0, model.size(), "precondition: model must be empty"); + final Model A = modelWithStatements("clouds offer rain; trees offer shelter"); + final Model B = modelWithStatements("x R y; y Q z; z P x"); model.add(A); ModelHelper.assertIsoModels(A, model); model.add(B); model.remove(A); ModelHelper.assertIsoModels(B, model); model.remove(B); - Assert.assertEquals("", 0, model.size()); + assertEquals(0, model.size(), ""); } + @Test public void testBulkRemoveSelf() { - final Model m = ModelHelper.modelWithStatements(this, "they sing together; he sings alone"); + final Model m = modelWithStatements("they sing together; he sings alone"); m.remove(m); - Assert.assertEquals("", 0, m.size()); + assertEquals(0, m.size(), ""); } public void testContains(final Model m, final List statements) { for ( Statement statement : statements ) { - Assert.assertTrue("it should be here", m.contains(statement)); + assertTrue(m.contains(statement), "it should be here"); } } public void testContains(final Model m, final Statement[] statements) { for ( final Statement statement : statements ) { - Assert.assertTrue("it should be here", m.contains(statement)); + assertTrue(m.contains(statement), "it should be here"); } } + @Test public void testMBU() { final Statement[] sArray = ModelHelper.statements(model, "moon orbits earth; earth orbits sun"); final List sList = Arrays.asList(ModelHelper.statements(model, "I drink tea; you drink coffee")); @@ -88,13 +93,13 @@ public void testMBU() { public void testOmits(final Model m, final List statements) { for ( Statement statement : statements ) { - Assert.assertFalse("it should not be here", m.contains(statement)); + assertFalse(m.contains(statement), "it should not be here"); } } public void testOmits(final Model m, final Statement[] statements) { for ( final Statement statement : statements ) { - Assert.assertFalse("it should not be here", m.contains(statement)); + assertFalse(m.contains(statement), "it should not be here"); } } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelEvents.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelEvents.java index 087b79f93d8..a372edb9846 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelEvents.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelEvents.java @@ -21,24 +21,29 @@ package org.apache.jena.rdf.model; -import java.util.*; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; -import org.junit.Assert; +import java.util.*; import org.apache.jena.atlas.iterator.Iter; import org.apache.jena.rdf.listeners.ChangedListener; import org.apache.jena.rdf.listeners.NullListener; import org.apache.jena.rdf.listeners.ObjectListener; import org.apache.jena.rdf.listeners.StatementListener; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.rdf.model.helpers.RecordingModelListener; import org.apache.jena.rdf.model.impl.StmtIteratorImpl; - /** * Tests for model events and listeners. */ +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestModelEvents extends AbstractModelTestBase { static class OL extends ObjectListener { private Object recorded; @@ -61,9 +66,9 @@ private Object comparable(final Object x) { } public void recent(final String wantHow, final Object value) { - Assert.assertTrue(RecordingModelListener.checkEquality(comparable(value), comparable(recorded))); + assertTrue(RecordingModelListener.checkEquality(comparable(value), comparable(recorded))); // Assert.assertEquals(comparable(value), comparable(recorded)); - Assert.assertEquals(wantHow, how); + assertEquals(wantHow, how); recorded = how = null; } @@ -109,10 +114,6 @@ public void removedStatement(final Statement s) { protected RecordingModelListener SL; - public TestModelEvents(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - public void another(final Map m, final Object x) { Integer n = m.get(x); if ( n == null ) { @@ -135,32 +136,36 @@ protected StmtIterator asIterator(final Statement[] statements) { public void assertSameBag(final List wanted, final List got) { - Assert.assertEquals(asBag(wanted), asBag(got)); + assertEquals(asBag(wanted), asBag(got)); } @Override + @BeforeEach public void setUp() { super.setUp(); SL = new RecordingModelListener(); } + @Test public void testAddInPieces() { model.register(SL); model.add(ModelHelper.resource(model, "S"), ModelHelper.property(model, "P"), ModelHelper.resource(model, "O")); SL.assertHas(new Object[]{"add", ModelHelper.statement(model, "S P O")}); } + @Test public void testAddModel() { model.register(SL); - final Model m = ModelHelper.modelWithStatements(this, "NT beats S; S beats H; H beats D"); + final Model m = modelWithStatements("NT beats S; S beats H; H beats D"); model.add(m); SL.assertHas(new Object[]{"addModel", m}); } + @Test public void testAddSingleStatements() { final Statement S1 = ModelHelper.statement(model, "S P O"); final Statement S2 = ModelHelper.statement(model, "A B C"); - Assert.assertFalse(SL.has(new Object[]{"add", S1})); + assertFalse(SL.has(new Object[]{"add", S1})); model.register(SL); model.add(S1); SL.assertHas(new Object[]{"add", S1}); @@ -170,6 +175,7 @@ public void testAddSingleStatements() { SL.assertHas(new Object[]{"add", S1, "add", S2, "add", S1}); } + @Test public void testAddStatementArray() { model.register(SL); final Statement[] s = ModelHelper.statements(model, "a P b; c Q d"); @@ -177,6 +183,7 @@ public void testAddStatementArray() { SL.assertHas(new Object[]{"add[]", Arrays.asList(s)}); } + @Test public void testAddStatementIterator() { model.register(SL); final Statement[] sa = ModelHelper.statements(model, "x R y; a P b; x R y"); @@ -185,6 +192,7 @@ public void testAddStatementIterator() { SL.assertHas(new Object[]{"addIterator", Arrays.asList(sa)}); } + @Test public void testAddStatementList() { model.register(SL); final List L = Arrays.asList(ModelHelper.statements(model, "b I g; model U g")); @@ -192,41 +200,44 @@ public void testAddStatementList() { SL.assertHas(new Object[]{"addList", L}); } + @Test public void testChangedListener() { final ChangedListener CL = new ChangedListener(); model.register(CL); - Assert.assertFalse(CL.hasChanged()); + assertFalse(CL.hasChanged()); model.add(ModelHelper.statement(model, "S P O")); - Assert.assertTrue(CL.hasChanged()); - Assert.assertFalse(CL.hasChanged()); + assertTrue(CL.hasChanged()); + assertFalse(CL.hasChanged()); model.remove(ModelHelper.statement(model, "ab CD ef")); - Assert.assertTrue(CL.hasChanged()); + assertTrue(CL.hasChanged()); model.add(ModelHelper.statements(model, "gh IJ kl")); - Assert.assertTrue(CL.hasChanged()); + assertTrue(CL.hasChanged()); model.remove(ModelHelper.statements(model, "mn OP qr")); - Assert.assertTrue(CL.hasChanged()); + assertTrue(CL.hasChanged()); model.add(asIterator(ModelHelper.statements(model, "st UV wx"))); - Assert.assertTrue(CL.hasChanged()); - Assert.assertFalse(CL.hasChanged()); + assertTrue(CL.hasChanged()); + assertFalse(CL.hasChanged()); model.remove(asIterator(ModelHelper.statements(model, "yz AB cd"))); - Assert.assertTrue(CL.hasChanged()); - model.add(ModelHelper.modelWithStatements(this, "ef GH ij")); - Assert.assertTrue(CL.hasChanged()); - model.remove(ModelHelper.modelWithStatements(this, "kl MN op")); - Assert.assertTrue(CL.hasChanged()); + assertTrue(CL.hasChanged()); + model.add(modelWithStatements("ef GH ij")); + assertTrue(CL.hasChanged()); + model.remove(modelWithStatements("kl MN op")); + assertTrue(CL.hasChanged()); model.add(Arrays.asList(ModelHelper.statements(model, "rs TU vw"))); - Assert.assertTrue(CL.hasChanged()); + assertTrue(CL.hasChanged()); model.remove(Arrays.asList(ModelHelper.statements(model, "xy wh q"))); - Assert.assertTrue(CL.hasChanged()); + assertTrue(CL.hasChanged()); } + @Test public void testDeleteModel() { model.register(SL); - final Model m = ModelHelper.modelWithStatements(this, "NT beats S; S beats H; H beats D"); + final Model m = modelWithStatements("NT beats S; S beats H; H beats D"); model.remove(m); SL.assertHas(new Object[]{"removeModel", m}); } + @Test public void testDeleteStatementArray() { model.register(SL); final Statement[] s = ModelHelper.statements(model, "a P b; c Q d"); @@ -234,6 +245,7 @@ public void testDeleteStatementArray() { SL.assertHas(new Object[]{"remove[]", Arrays.asList(s)}); } + @Test public void testDeleteStatementIterator() { model.register(SL); final Statement[] sa = ModelHelper.statements(model, "x R y; a P b; x R y"); @@ -242,6 +254,7 @@ public void testDeleteStatementIterator() { SL.assertHas(new Object[]{"removeIterator", Arrays.asList(sa)}); } + @Test public void testDeleteStatementList() { model.register(SL); final List lst = Arrays.asList(ModelHelper.statements(model, "b I g; model U g")); @@ -249,6 +262,7 @@ public void testDeleteStatementList() { SL.assertHas(new Object[]{"removeList", lst}); } + @Test public void testGeneralEvent() { model.register(SL); final Object e = new int[]{}; @@ -258,14 +272,15 @@ public void testGeneralEvent() { public void testGot(final WatchStatementListener sl, final String how, final String template) { assertSameBag(Arrays.asList(ModelHelper.statements(model, template)), sl.contents()); - Assert.assertEquals(how, sl.getAddOrRem()); - Assert.assertTrue(sl.contents().size() == 0); + assertEquals(how, sl.getAddOrRem()); + assertTrue(sl.contents().size() == 0); } /** * Test that the null listener doesn't appear to do anything. Or at least doesn't * crash .... */ + @Test public void testNullListener() { final ModelChangedListener NL = new NullListener(); model.register(NL); @@ -275,12 +290,13 @@ public void testNullListener() { model.remove(ModelHelper.statements(model, "g H i; j K l")); model.add(asIterator(ModelHelper.statements(model, "model N o; p Q r"))); model.remove(asIterator(ModelHelper.statements(model, "s T u; v W x"))); - model.add(ModelHelper.modelWithStatements(this, "leaves fall softly")); - model.remove(ModelHelper.modelWithStatements(this, "water drips endlessly")); + model.add(modelWithStatements("leaves fall softly")); + model.remove(modelWithStatements("water drips endlessly")); model.add(Arrays.asList(ModelHelper.statements(model, "xx RR yy"))); model.remove(Arrays.asList(ModelHelper.statements(model, "aa VV rr"))); } + @Test public void testObjectListener() { final OL ll = new OL(); model.register(ll); @@ -297,10 +313,10 @@ public void testObjectListener() { model.remove(sList2); ll.recent("rem", sList2); /* */ - final Model m1 = ModelHelper.modelWithStatements(this, "vv WW xx; yy ZZ aa"); + final Model m1 = modelWithStatements("vv WW xx; yy ZZ aa"); model.add(m1); ll.recent("add", m1); - final Model m2 = ModelHelper.modelWithStatements(this, "a B g; d E z"); + final Model m2 = modelWithStatements("a B g; d E z"); model.remove(m2); ll.recent("rem", m2); /* */ @@ -319,10 +335,12 @@ public void testObjectListener() { ll.recent("rem", asIterator(si2)); } + @Test public void testRegistrationCompiles() { - Assert.assertSame(model, model.register(new RecordingModelListener())); + assertSame(model, model.register(new RecordingModelListener())); } + @Test public void testRemoveSingleStatements() { final Statement S = ModelHelper.statement(model, "D E F"); model.register(SL); @@ -331,6 +349,7 @@ public void testRemoveSingleStatements() { SL.assertHas(new Object[]{"add", S, "remove", S}); } + @Test public void testTripleListener() { final WatchStatementListener sl = new WatchStatementListener(); model.register(sl); @@ -354,12 +373,13 @@ public void testTripleListener() { model.remove(asIterator(ModelHelper.statements(model, "l M n; o P q"))); testGot(sl, "rem", "l M n; o P q"); /* */ - model.add(ModelHelper.modelWithStatements(this, "r S t; u V w; x Y z")); + model.add(modelWithStatements("r S t; u V w; x Y z")); testGot(sl, "add", "r S t; u V w; x Y z"); - model.remove(ModelHelper.modelWithStatements(this, "a E i; o U y")); + model.remove(modelWithStatements("a E i; o U y")); testGot(sl, "rem", "a E i; o U y"); } + @Test public void testTwoListeners() { final Statement S = ModelHelper.statement(model, "S P O"); final RecordingModelListener SL1 = new RecordingModelListener(); @@ -370,6 +390,7 @@ public void testTwoListeners() { SL1.assertHas(new Object[]{"add", S}); } + @Test public void testUnregisterWorks() { model.register(SL); model.unregister(SL); @@ -377,6 +398,7 @@ public void testUnregisterWorks() { SL.assertHas(new Object[]{}); } + @Test public void testUnregistrationCompiles() { model.unregister(new RecordingModelListener()); } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelFactory.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelFactory.java index 3ad76e6c650..02de6fa6414 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelFactory.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelFactory.java @@ -21,7 +21,10 @@ package org.apache.jena.rdf.model; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.compose.Union; import org.apache.jena.reasoner.InfGraph; import org.apache.jena.reasoner.Reasoner; @@ -29,23 +32,19 @@ import org.apache.jena.reasoner.rulesys.Rule; import org.apache.jena.test.JenaTestLib; -import org.junit.Assert; - /** * Tests the ModelFactory code. Very skeletal at the moment. It's really testing that * the methods actually exists, but it doesn't check much in the way of behaviour. */ -public class TestModelFactory extends TestCase { - - public TestModelFactory(final String name) { - super(name); - } +public class TestModelFactory { + @Test public void testAssembleModelFromModel() { // TODO Model ModelFactory.assembleModelFrom( Model singleRoot ) } + @Test public void testAssmbleModelFromRoot() { // TODO Model assembleModelFrom( Resource root ) } @@ -54,17 +53,19 @@ public void testAssmbleModelFromRoot() { * Test that ModelFactory.createDefaultModel() exists. [Should check that the * Model is truly a "default" model.] */ + @Test public void testCreateDefaultModel() { ModelFactory.createDefaultModel().close(); } + @Test public void testCreateInfModel() { final String rule = "-> (eg:r eg:p eg:v)."; final Reasoner r = new GenericRuleReasoner(Rule.parseRules(rule)); final InfGraph ig = r.bind(ModelFactory.createDefaultModel().getGraph()); final InfModel im = ModelFactory.createInfModel(ig); JenaTestLib.assertInstanceOf(InfModel.class, im); - Assert.assertEquals(1, im.size()); + assertEquals(1, im.size()); } /** @@ -72,12 +73,13 @@ public void testCreateInfModel() { * graphs. (We don't check that Union works - that's done in the Union tests, we * hope.) */ + @Test public void testCreateUnion() { final Model m1 = ModelFactory.createDefaultModel(); final Model m2 = ModelFactory.createDefaultModel(); final Model m = ModelFactory.createUnion(m1, m2); JenaTestLib.assertInstanceOf(Union.class, m.getGraph()); - Assert.assertSame(m1.getGraph(), ((Union)m.getGraph()).getL()); - Assert.assertSame(m2.getGraph(), ((Union)m.getGraph()).getR()); + assertSame(m1.getGraph(), ((Union)m.getGraph()).getL()); + assertSame(m2.getGraph(), ((Union)m.getGraph()).getR()); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelPolymorphism.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelPolymorphism.java index 4aad5b92fbc..463125dbe34 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelPolymorphism.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelPolymorphism.java @@ -21,22 +21,23 @@ package org.apache.jena.rdf.model; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.*; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestModelPolymorphism extends AbstractModelTestBase { - public TestModelPolymorphism(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - + @Test public void testPoly() { final Resource r = model.createResource("http://www.electric-hedgehog.net/a-o-s.html"); - Assert.assertFalse("the Resouce should not be null", r == null); - Assert.assertTrue("the Resource can be a Property", r.canAs(Property.class)); + assertFalse(r == null, "the Resouce should not be null"); + assertTrue(r.canAs(Property.class), "the Resource can be a Property"); final Property p = r.as(Property.class); - Assert.assertFalse("the Property should not be null", p == null); - Assert.assertFalse("the Resource and Property should not be identical", r == p); + assertFalse(p == null, "the Property should not be null"); + assertFalse(r == p, "the Resource and Property should not be identical"); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelRead.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelRead.java index 11f03a62df9..95a6378447d 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelRead.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelRead.java @@ -21,9 +21,12 @@ package org.apache.jena.rdf.model; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,38 +34,36 @@ /** * TestModelRead - test that the model.read operation(s) exist. */ +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestModelRead extends AbstractModelTestBase { protected static Logger logger = LoggerFactory.getLogger(TestModelRead.class); - public TestModelRead(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - - public TestModelRead() { - this(ModelCreator.plain, "TestModelRead"); - } - + @Test public void testDefaultLangXML() { final Model model = ModelFactory.createDefaultModel(); model.read(getFileName("modelReading/plain.rdf"), null, null); } + @Test public void testLoadsSimpleModel() { final Model expected = createModel(); expected.read(getFileName("modelReading/simple.n3"), "N3"); - Assert.assertSame(model, model.read(getFileName("modelReading/simple.n3"), "base", "N3")); + assertSame(model, model.read(getFileName("modelReading/simple.n3"), "base", "N3")); ModelHelper.assertIsoModels(expected, model); } + @Test public void testReturnsSelf() { - Assert.assertSame(model, model.read(getFileName("modelReading/empty.n3"), "base", "N3")); - Assert.assertTrue(model.isEmpty()); + assertSame(model, model.read(getFileName("modelReading/empty.n3"), "base", "N3")); + assertTrue(model.isEmpty()); } + @Test public void testSimpleLoadExplicitBase() { final Model mBasedExplicit = createModel(); mBasedExplicit.read(getFileName("modelReading/based.n3"), "http://example/", "N3"); - ModelHelper.assertIsoModels(ModelHelper.modelWithStatements(this, "http://example/ ja:predicate ja:object"), mBasedExplicit); + ModelHelper.assertIsoModels(modelWithStatements("http://example/ ja:predicate ja:object"), mBasedExplicit); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelSetOperations.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelSetOperations.java index 946ed0304fe..279ff8893e7 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelSetOperations.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestModelSetOperations.java @@ -21,98 +21,106 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; -import org.apache.jena.rdf.model.helpers.ModelHelper; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; -import org.junit.Assert; +import org.apache.jena.rdf.model.helpers.ModelHelper; /** * A revamped version of the regression set-operation tests. */ +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestModelSetOperations extends AbstractModelTestBase { private Model model2; - public TestModelSetOperations(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - @Override + @BeforeEach public void setUp() { super.setUp(); model2 = createModel(); } @Override + @AfterEach public void tearDown() { super.tearDown(); model2.close(); } + @Test public void testDifference() { ModelHelper.modelAdd(model, "a P b; w R x"); ModelHelper.modelAdd(model2, "w R x; y S z"); final Model dm = model.difference(model2); for ( final StmtIterator it = dm.listStatements() ; it.hasNext() ; ) { final Statement s = it.nextStatement(); - Assert.assertTrue(model.contains(s) && !model2.contains(s)); + assertTrue(model.contains(s) && !model2.contains(s)); } for ( final StmtIterator it = model.union(model2).listStatements() ; it.hasNext() ; ) { final Statement s = it.nextStatement(); - Assert.assertEquals(model.contains(s) && !model2.contains(s), dm.contains(s)); + assertEquals(model.contains(s) && !model2.contains(s), dm.contains(s)); } - Assert.assertTrue(dm.containsAny(model)); - Assert.assertTrue(dm.containsAny(model.listStatements())); - Assert.assertFalse(dm.containsAny(model2)); - Assert.assertFalse(dm.containsAny(model2.listStatements())); - Assert.assertTrue(model.containsAll(dm)); + assertTrue(dm.containsAny(model)); + assertTrue(dm.containsAny(model.listStatements())); + assertFalse(dm.containsAny(model2)); + assertFalse(dm.containsAny(model2.listStatements())); + assertTrue(model.containsAll(dm)); } + @Test public void testIntersection() { ModelHelper.modelAdd(model, "a P b; w R x"); ModelHelper.modelAdd(model2, "w R x; y S z"); final Model im = model.intersection(model2); - Assert.assertFalse(model.containsAll(model2)); - Assert.assertFalse(model2.containsAll(model)); - Assert.assertTrue(model.containsAll(im)); - Assert.assertTrue(model2.containsAll(im)); + assertFalse(model.containsAll(model2)); + assertFalse(model2.containsAll(model)); + assertTrue(model.containsAll(im)); + assertTrue(model2.containsAll(im)); for ( final StmtIterator it = im.listStatements() ; it.hasNext() ; ) { final Statement s = it.nextStatement(); - Assert.assertTrue(model.contains(s) && model2.contains(s)); + assertTrue(model.contains(s) && model2.contains(s)); } for ( final StmtIterator it = im.listStatements() ; it.hasNext() ; ) { - Assert.assertTrue(model.contains(it.nextStatement())); + assertTrue(model.contains(it.nextStatement())); } for ( final StmtIterator it = im.listStatements() ; it.hasNext() ; ) { - Assert.assertTrue(model2.contains(it.nextStatement())); + assertTrue(model2.contains(it.nextStatement())); } - Assert.assertTrue(model.containsAll(im.listStatements())); - Assert.assertTrue(model2.containsAll(im.listStatements())); + assertTrue(model.containsAll(im.listStatements())); + assertTrue(model2.containsAll(im.listStatements())); } + @Test public void testUnion() { ModelHelper.modelAdd(model, "a P b; w R x"); ModelHelper.modelAdd(model2, "w R x; y S z"); final Model um = model.union(model2); - Assert.assertFalse(model.containsAll(model2)); - Assert.assertFalse(model2.containsAll(model)); - Assert.assertTrue(um.containsAll(model)); - Assert.assertTrue(um.containsAll(model2)); + assertFalse(model.containsAll(model2)); + assertFalse(model2.containsAll(model)); + assertTrue(um.containsAll(model)); + assertTrue(um.containsAll(model2)); for ( final StmtIterator it = um.listStatements() ; it.hasNext() ; ) { final Statement s = it.nextStatement(); - Assert.assertTrue(model.contains(s) || model2.contains(s)); + assertTrue(model.contains(s) || model2.contains(s)); } for ( final StmtIterator it = model.listStatements() ; it.hasNext() ; ) { - Assert.assertTrue(um.contains(it.nextStatement())); + assertTrue(um.contains(it.nextStatement())); } for ( final StmtIterator it = model2.listStatements() ; it.hasNext() ; ) { - Assert.assertTrue(um.contains(it.nextStatement())); + assertTrue(um.contains(it.nextStatement())); } - Assert.assertTrue(um.containsAll(model.listStatements())); - Assert.assertTrue(um.containsAll(model2.listStatements())); + assertTrue(um.containsAll(model.listStatements())); + assertTrue(um.containsAll(model2.listStatements())); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestNamespace.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestNamespace.java index 0fa47bbe105..15a9779fa73 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestNamespace.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestNamespace.java @@ -21,6 +21,12 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -30,16 +36,13 @@ import java.util.StringTokenizer; import org.apache.jena.graph.compose.AbstractTestPrefixMapping; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.rdf.model.impl.ModelCom; import org.apache.jena.util.CollectionFactory; -import org.junit.Assert; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestNamespace extends AbstractModelTestBase { - public TestNamespace(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } /** * turn a semi-separated set of P=U definitions into a namespace map. @@ -74,15 +77,17 @@ private Set set(final String element) { * have a namespace definition for eg and rdf, and not for spoo so we see if we * can extract them (or not, for spoo). */ + @Test public void testReadPrefixes() { model.read(getFileName("wg/rdf-ns-prefix-confusion/test0014.rdf")); final Map ns = model.getNsPrefixMap(); // System.err.println( ">> " + ns ); - Assert.assertEquals("namespace eg", "http://example.org/", ns.get("eg")); - Assert.assertEquals("namespace rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", ns.get("rdf")); - Assert.assertEquals("not present", null, ns.get("spoo")); + assertEquals("http://example.org/", ns.get("eg"), "namespace eg"); + assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#", ns.get("rdf"), "namespace rdf"); + assertEquals(null, ns.get("spoo"), "not present"); } + @Test public void testUseEasyPrefix() { AbstractTestPrefixMapping.testUseEasyPrefix("default model", ModelFactory.createDefaultModel()); } @@ -94,6 +99,7 @@ public void testUseEasyPrefix() { * used on properties don't reliably get used. Maybe they shouldn't be - but it * seems odd. */ + @Test public void testWritePrefixes() throws IOException { ModelCom.addNamespaces(model, makePrefixes("fred=ftp://net.fred.org/;spoo=http://spoo.net/")); model.add(ModelHelper.statement(model, "http://spoo.net/S http://spoo.net/P http://spoo.net/O")); @@ -106,8 +112,8 @@ public void testWritePrefixes() throws IOException { m2.read(bin, "http://example/base/", "RDF/XML"); final Map ns = m2.getNsPrefixMap(); - Assert.assertEquals("namespace spoo", "http://spoo.net/", ns.get("spoo")); - Assert.assertEquals("namespace fred", "ftp://net.fred.org/", ns.get("fred")); + assertEquals("http://spoo.net/", ns.get("spoo"), "namespace spoo"); + assertEquals("ftp://net.fred.org/", ns.get("fred"), "namespace fred"); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestObjectOfProperties.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestObjectOfProperties.java index 1f10c62892a..aed5133e0ab 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestObjectOfProperties.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestObjectOfProperties.java @@ -21,10 +21,15 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestObjectOfProperties extends AbstractModelTestBase { /* boolean predf[] = new boolean[num]; * @@ -56,28 +61,24 @@ public class TestObjectOfProperties extends AbstractModelTestBase { // Literal tvLitObj[]; // Resource tvResObj[] =; - public TestObjectOfProperties(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - private void assertFoundAll(final boolean[] subjf) { for ( int i = 0 ; i < num ; i++ ) { - Assert.assertTrue("Should have found " + subject[i], subjf[i]); + assertTrue(subjf[i], "Should have found " + subject[i]); } } private void assertFoundNone(final boolean[] subjf) { for ( int i = 0 ; i < num ; i++ ) { - Assert.assertFalse("Should not have found " + subject[i], subjf[i]); + assertFalse(subjf[i], "Should not have found " + subject[i]); } } private void checkBooleanSubjects(final boolean[] subjf) { for ( int i = 0 ; i < num ; i++ ) { if ( subjf[i] ) { - Assert.assertFalse(i > 1); + assertFalse(i > 1); } else { - Assert.assertFalse(i < 2); + assertFalse(i < 2); } } } @@ -93,15 +94,16 @@ private void processIterator(final ResIterator rIter, final boolean[] subjf) { for ( int i = 0 ; i < num ; i++ ) { if ( subj.equals(subject[i]) ) { found = true; - Assert.assertFalse("Should not have found " + subject[i] + " already", subjf[i]); + assertFalse(subjf[i], "Should not have found " + subject[i] + " already"); subjf[i] = true; } } - Assert.assertTrue("Should have found " + subj, found); + assertTrue(found, "Should have found " + subj); } } @Override + @BeforeEach public void setUp() { super.setUp(); // tvLitObj = { model.createTypedLiteral(new LitTestObjF()), @@ -156,6 +158,7 @@ public void setUp() { } + @Test public void testListObjectsOfProperty() { final boolean objf[] = new boolean[numObj]; @@ -166,18 +169,19 @@ public void testListObjectsOfProperty() { for ( int i = 0 ; i < numObj ; i++ ) { if ( obj.equals(object[i]) ) { found = true; - Assert.assertFalse("Should not have found " + object[i] + " already", objf[i]); + assertFalse(objf[i], "Should not have found " + object[i] + " already"); objf[i] = true; } } - Assert.assertTrue("Should have found " + obj, found); + assertTrue(found, "Should have found " + obj); } for ( int i = 0 ; i < numObj ; i++ ) { - Assert.assertTrue("Should have found " + object[i], objf[i]); + assertTrue(objf[i], "Should have found " + object[i]); } } + @Test public void testListResourcesWIthProperty() { final boolean subjf[] = new boolean[num]; processIterator(model.listResourcesWithProperty(predicate[4]), subjf); @@ -235,6 +239,7 @@ public void testListResourcesWIthProperty() { assertFoundNone(subjf); } + @Test public void testListSubjectsWithProperty() { final boolean subjf[] = new boolean[num]; processIterator(model.listSubjectsWithProperty(predicate[0], tvStringArray[0]), subjf); diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestObjects.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestObjects.java index b3eb36b33fb..b439e69ca77 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestObjects.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestObjects.java @@ -21,17 +21,24 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.util.HashSet; import java.util.List; import java.util.Set; -import org.junit.Assert; - import org.apache.jena.atlas.iterator.Iter; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.vocabulary.RDF; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestObjects extends AbstractModelTestBase { protected Resource S; @@ -45,10 +52,6 @@ public class TestObjects extends AbstractModelTestBase { protected static final String predicatePrefix = "http://aldabaran/test6/"; - public TestObjects(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - protected Set fill(final Model model) { final Set statements = new HashSet<>(); for ( int i = 0 ; i < TestObjects.numberSubjects ; i += 1 ) { @@ -60,7 +63,7 @@ protected Set fill(final Model model) { statements.add(s); } } - Assert.assertEquals(TestObjects.numberSubjects * TestObjects.numberPredicates, model.size()); + assertEquals(TestObjects.numberSubjects * TestObjects.numberPredicates, model.size()); return statements; } @@ -89,6 +92,7 @@ protected Set predicateSet(final int limit) { } @Override + @BeforeEach public void setUp() { super.setUp(); S = model.createResource("http://nowhere.man/subject"); @@ -104,34 +108,39 @@ protected Set subjectSet(final int limit) { } @Override + @AfterEach public void tearDown() { S = null; P = null; super.tearDown(); } + @Test public void testListNamespaces() { fill(model); final List L = model.listNameSpaces().toList(); - Assert.assertEquals(TestObjects.numberPredicates, L.size()); + assertEquals(TestObjects.numberPredicates, L.size()); final Set wanted = predicateSet(TestObjects.numberPredicates); - Assert.assertEquals(wanted, new HashSet<>(L)); + assertEquals(wanted, new HashSet<>(L)); } + @Test public void testListObjects() { fill(model); final Set wanted = literalsUpto(TestObjects.numberSubjects * TestObjects.numberPredicates); - Assert.assertEquals(wanted, Iter.toSet(model.listObjects())); + assertEquals(wanted, Iter.toSet(model.listObjects())); } + @Test public void testListObjectsOfPropertyByProperty() { fill(model); final List L = Iter.toList(model.listObjectsOfProperty(ModelHelper.property(TestObjects.predicatePrefix + "0/p"))); - Assert.assertEquals(TestObjects.numberSubjects, L.size()); + assertEquals(TestObjects.numberSubjects, L.size()); final Set wanted = literalsFor(0); - Assert.assertEquals(wanted, new HashSet<>(L)); + assertEquals(wanted, new HashSet<>(L)); } + @Test public void testListObjectsOfPropertyBySubject() { final int size = 10; final Resource s = model.createResource(); @@ -139,24 +148,26 @@ public void testListObjectsOfPropertyBySubject() { model.addLiteral(s, RDF.value, i); } final List L = Iter.toList(model.listObjectsOfProperty(s, RDF.value)); - Assert.assertEquals(size, L.size()); + assertEquals(size, L.size()); final Set wanted = literalsUpto(size); - Assert.assertEquals(wanted, new HashSet<>(L)); + assertEquals(wanted, new HashSet<>(L)); } + @Test public void testListStatements() { final Set statements = fill(model); final List L = model.listStatements().toList(); - Assert.assertEquals(statements.size(), L.size()); - Assert.assertEquals(statements, new HashSet<>(L)); + assertEquals(statements.size(), L.size()); + assertEquals(statements, new HashSet<>(L)); } + @Test public void testListSubjects() { fill(model); final List L = model.listSubjects().toList(); - Assert.assertEquals(TestObjects.numberSubjects, L.size()); + assertEquals(TestObjects.numberSubjects, L.size()); final Set wanted = subjectSet(TestObjects.numberSubjects); - Assert.assertEquals(wanted, Iter.toSet(L.iterator())); + assertEquals(wanted, Iter.toSet(L.iterator())); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestProperties.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestProperties.java index 9130e4acf10..388f316f835 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestProperties.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestProperties.java @@ -21,21 +21,21 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.rdf.model.impl.PropertyImpl; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDFS; -import org.junit.Assert; -import junit.framework.TestCase; -public class TestProperties extends TestCase { - public TestProperties(final String name) { - super(name); - } +public class TestProperties { protected Property createProperty(final String uri) { return new PropertyImpl(uri); } + @Test public void testNonOrdinalRDFURIs() { testRDFOrdinalValue(0, "x"); testRDFOrdinalValue(0, "x1"); @@ -45,6 +45,7 @@ public void testNonOrdinalRDFURIs() { testRDFOrdinalValue(0, "_xff"); } + @Test public void testNonRDFElementURIsHaveOrdinal0() { testOrdinalValue(0, "foo:bar"); testOrdinalValue(0, "foo:bar1"); @@ -54,9 +55,10 @@ public void testNonRDFElementURIsHaveOrdinal0() { private void testOrdinalValue(final int i, final String URI) { final String message = "property should have expected ordinal value for " + URI; - Assert.assertEquals(message, i, createProperty(URI).getOrdinal()); + assertEquals(i, createProperty(URI).getOrdinal(), message); } + @Test public void testOrdinalValues() { testRDFOrdinalValue(1, "_1"); testRDFOrdinalValue(2, "_2"); diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFNodes.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFNodes.java index baf62936091..2390497b85f 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFNodes.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFNodes.java @@ -21,120 +21,132 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.util.ArrayList; import java.util.List; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.test.JenaTestLib; -import org.junit.Assert; - /** * This class tests various properties of RDFNodes. */ +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestRDFNodes extends AbstractModelTestBase { - public TestRDFNodes(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - + @Test public void testInModel() { - final Model m1 = ModelHelper.modelWithStatements(this, ""); - final Model m2 = ModelHelper.modelWithStatements(this, ""); + final Model m1 = modelWithStatements(""); + final Model m2 = modelWithStatements(""); final Resource r1 = ModelHelper.resource(m1, "r1"); final Resource r2 = ModelHelper.resource(m1, "_r2"); /* */ - Assert.assertEquals(r1.getModel(), m1); - Assert.assertEquals(r2.getModel(), m1); - Assert.assertFalse(r1.isAnon()); - Assert.assertTrue(r2.isAnon()); + assertEquals(r1.getModel(), m1); + assertEquals(r2.getModel(), m1); + assertFalse(r1.isAnon()); + assertTrue(r2.isAnon()); /* */ - Assert.assertEquals(r1.inModel(m2).getModel(), m2); - Assert.assertEquals(r2.inModel(m2).getModel(), m2); + assertEquals(r1.inModel(m2).getModel(), m2); + assertEquals(r2.inModel(m2).getModel(), m2); /* */ - Assert.assertEquals(r1, r1.inModel(m2)); - Assert.assertEquals(r2, r2.inModel(m2)); + assertEquals(r1, r1.inModel(m2)); + assertEquals(r2, r2.inModel(m2)); } + @Test public void testIsAnon() { - final Model m = ModelHelper.modelWithStatements(this, ""); - Assert.assertEquals(false, m.createResource("eh:/foo").isAnon()); - Assert.assertEquals(true, m.createResource().isAnon()); - Assert.assertEquals(false, m.createTypedLiteral(17).isAnon()); - Assert.assertEquals(false, m.createTypedLiteral("hello").isAnon()); + final Model m = modelWithStatements(""); + assertEquals(false, m.createResource("eh:/foo").isAnon()); + assertEquals(true, m.createResource().isAnon()); + assertEquals(false, m.createTypedLiteral(17).isAnon()); + assertEquals(false, m.createTypedLiteral("hello").isAnon()); } + @Test public void testIsLiteral() { - final Model m = ModelHelper.modelWithStatements(this, ""); - Assert.assertEquals(false, m.createResource("eh:/foo").isLiteral()); - Assert.assertEquals(false, m.createResource().isLiteral()); - Assert.assertEquals(true, m.createTypedLiteral(17).isLiteral()); - Assert.assertEquals(true, m.createTypedLiteral("hello").isLiteral()); + final Model m = modelWithStatements(""); + assertEquals(false, m.createResource("eh:/foo").isLiteral()); + assertEquals(false, m.createResource().isLiteral()); + assertEquals(true, m.createTypedLiteral(17).isLiteral()); + assertEquals(true, m.createTypedLiteral("hello").isLiteral()); } + @Test public void testIsResource() { - final Model m = ModelHelper.modelWithStatements(this, ""); + final Model m = modelWithStatements(""); Statement stmt = ModelHelper.statement("S P O"); StatementTerm tripleTerm = m.createStatementTerm(stmt); - Assert.assertEquals(true, m.createResource("eh:/foo").isResource()); - Assert.assertEquals(true, m.createResource().isResource()); - Assert.assertEquals(false, m.createTypedLiteral(17).isResource()); - Assert.assertEquals(false, m.createTypedLiteral("hello").isResource()); - Assert.assertEquals(false, tripleTerm.isResource()); + assertEquals(true, m.createResource("eh:/foo").isResource()); + assertEquals(true, m.createResource().isResource()); + assertEquals(false, m.createTypedLiteral(17).isResource()); + assertEquals(false, m.createTypedLiteral("hello").isResource()); + assertEquals(false, tripleTerm.isResource()); } + @Test public void testIsURIResource() { - final Model m = ModelHelper.modelWithStatements(this, ""); - Assert.assertEquals(true, m.createResource("eh:/foo").isURIResource()); - Assert.assertEquals(false, m.createResource().isURIResource()); - Assert.assertEquals(false, m.createTypedLiteral(17).isURIResource()); - Assert.assertEquals(false, m.createTypedLiteral("hello").isURIResource()); + final Model m = modelWithStatements(""); + assertEquals(true, m.createResource("eh:/foo").isURIResource()); + assertEquals(false, m.createResource().isURIResource()); + assertEquals(false, m.createTypedLiteral(17).isURIResource()); + assertEquals(false, m.createTypedLiteral("hello").isURIResource()); } + @Test public void testIsStatementTerm1() { - final Model m = ModelHelper.modelWithStatements(this, ""); + final Model m = modelWithStatements(""); Statement stmt = ModelHelper.statement("S P O"); StatementTerm tripleTerm = m.createStatementTerm(stmt); - Assert.assertEquals(false, m.createResource("eh:/foo").isStatementTerm()); - Assert.assertEquals(false, m.createResource().isStatementTerm()); - Assert.assertEquals(false, m.createTypedLiteral(17).isStatementTerm()); - Assert.assertEquals(false, m.createTypedLiteral("hello").isStatementTerm()); - Assert.assertEquals(true, tripleTerm.isStatementTerm()); + assertEquals(false, m.createResource("eh:/foo").isStatementTerm()); + assertEquals(false, m.createResource().isStatementTerm()); + assertEquals(false, m.createTypedLiteral(17).isStatementTerm()); + assertEquals(false, m.createTypedLiteral("hello").isStatementTerm()); + assertEquals(true, tripleTerm.isStatementTerm()); } + @Test public void testIsStatementTerm2() { - final Model m = ModelHelper.modelWithStatements(this, ""); + final Model m = modelWithStatements(""); Statement stmt = ModelHelper.statement("S P O"); StatementTerm tripleTerm = m.createStatementTerm(stmt); - Assert.assertEquals(false, tripleTerm.isAnon()); - Assert.assertEquals(false, tripleTerm.isURIResource()); - Assert.assertEquals(false, tripleTerm.isLiteral()); - Assert.assertEquals(false, tripleTerm.isResource()); - Assert.assertEquals(true, tripleTerm.isStatementTerm()); + assertEquals(false, tripleTerm.isAnon()); + assertEquals(false, tripleTerm.isURIResource()); + assertEquals(false, tripleTerm.isLiteral()); + assertEquals(false, tripleTerm.isResource()); + assertEquals(true, tripleTerm.isStatementTerm()); } + @Test public void testLiteralAsResourceThrows() { - final Model m = ModelHelper.modelWithStatements(this, ""); + final Model m = modelWithStatements(""); final Resource r = m.createResource("eh:/spoo"); try { r.asLiteral(); - Assert.fail("should not be able to do Resource.asLiteral()"); + fail("should not be able to do Resource.asLiteral()"); } catch (final LiteralRequiredException e) {} } + @Test public void testRDFNodeAsLiteral() { - final Model m = ModelHelper.modelWithStatements(this, ""); + final Model m = modelWithStatements(""); final Literal l = m.createLiteral("hello, world"); - Assert.assertSame(l, l.asLiteral()); + assertSame(l, l.asLiteral()); } + @Test public void testRDFNodeAsResource() { - final Model m = ModelHelper.modelWithStatements(this, ""); + final Model m = modelWithStatements(""); final Resource r = m.createResource("eh:/spoo"); - Assert.assertSame(r, r.asResource()); + assertSame(r, r.asResource()); } + @Test public void testRDFVisitor() { final List history = new ArrayList<>(); final Model m = ModelFactory.createDefaultModel(); @@ -149,23 +161,23 @@ public void testRDFVisitor() { @Override public Object visitBlank(final Resource R, final AnonId id) { history.add("blank"); - Assert.assertTrue("must visit correct node", R == S); - Assert.assertEquals("must have correct field", R.getId(), id); + assertTrue(R == S, "must visit correct node"); + assertEquals(R.getId(), id, "must have correct field"); return "blank result"; } @Override public Object visitLiteral(final Literal L) { history.add("literal"); - Assert.assertTrue("must visit correct node", L == O); + assertTrue(L == O, "must visit correct node"); return "literal result"; } @Override public Object visitURI(final Resource R, final String uri) { history.add("uri"); - Assert.assertTrue("must visit correct node", R == P); - Assert.assertEquals("must have correct field", R.getURI(), uri); + assertTrue(R == P, "must visit correct node"); + assertEquals(R.getURI(), uri, "must have correct field"); return "uri result"; } @@ -176,36 +188,39 @@ public Object visitStmt(StatementTerm statementTerm, Statement statement) { } }; /* */ - Assert.assertEquals("blank result", S.visitWith(rv)); - Assert.assertEquals("uri result", P.visitWith(rv)); - Assert.assertEquals("literal result", O.visitWith(rv)); - Assert.assertEquals("statement term result", ST.visitWith(rv)); + assertEquals("blank result", S.visitWith(rv)); + assertEquals("uri result", P.visitWith(rv)); + assertEquals("literal result", O.visitWith(rv)); + assertEquals("statement term result", ST.visitWith(rv)); - Assert.assertEquals(JenaTestLib.listOfStrings("blank uri literal statementTerm"), history); + assertEquals(JenaTestLib.listOfStrings("blank uri literal statementTerm"), history); } + @Test public void testRemoveAllBoring() { - final Model m1 = ModelHelper.modelWithStatements(this, "x P a; y Q b"); - final Model m2 = ModelHelper.modelWithStatements(this, "x P a; y Q b"); + final Model m1 = modelWithStatements("x P a; y Q b"); + final Model m2 = modelWithStatements("x P a; y Q b"); ModelHelper.resource(m2, "x").removeAll(ModelHelper.property(m2, "Z")); ModelHelper.assertIsoModels("m2 should be unchanged", m1, m2); } + @Test public void testRemoveAllRemoves() { final String ps = "x P a; x P b", rest = "x Q c; y P a; y Q b"; - final Model m = ModelHelper.modelWithStatements(this, ps + "; " + rest); + final Model m = modelWithStatements(ps + "; " + rest); final Resource r = ModelHelper.resource(m, "x"); final Resource r2 = r.removeAll(ModelHelper.property(m, "P")); - Assert.assertSame("removeAll should deliver its receiver", r, r2); - ModelHelper.assertIsoModels("x's P-values should go", ModelHelper.modelWithStatements(this, rest), m); + assertSame(r, r2, "removeAll should deliver its receiver"); + ModelHelper.assertIsoModels("x's P-values should go", modelWithStatements(rest), m); } + @Test public void testResourceAsLiteralThrows() { - final Model m = ModelHelper.modelWithStatements(this, ""); + final Model m = modelWithStatements(""); final Literal l = m.createLiteral("hello, world"); try { l.asResource(); - Assert.fail("should not be able to do Literal.asResource()"); + fail("should not be able to do Literal.asResource()"); } catch (final ResourceRequiredException e) {} } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFWriterMap.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFWriterMap.java deleted file mode 100644 index 8d0d1a69142..00000000000 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestRDFWriterMap.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.rdf.model; - -import java.util.HashMap; -import java.util.Map; - -import junit.framework.TestCase; -import org.apache.jena.Jena; -import org.apache.jena.rdf.model.impl.NTripleWriter; -import org.apache.jena.rdfxml.xmloutput.impl.RDFXML_Abbrev; -import org.apache.jena.rdfxml.xmloutput.impl.RDFXML_Basic; -import org.apache.jena.shared.JenaException; -import org.apache.jena.shared.NoWriterForLangException; - -import org.junit.Assert; - -public class TestRDFWriterMap extends TestCase { - public static class RDFWriterMap implements RDFWriterF { - protected final Map> map = new HashMap<>(); - - public RDFWriterMap(final boolean preloadDefaults) { - if ( preloadDefaults ) { - loadDefaults(); - } - } - - @Override - public RDFWriterI getWriter(final String lang) { - final Class result = map.get(lang); - if ( result == null ) { - throw new NoWriterForLangException(lang); - } - try { - return result.getConstructor().newInstance(); - } catch (final Exception e) { - throw new JenaException(e); - } - } - - private void loadDefaults() { - setWriterClassName(TestRDFWriterMap.RDF_XML, Jena.PATH + ".rdfxml.xmloutput.impl.RDFXML_Basic"); - setWriterClassName(TestRDFWriterMap.RDF_XML_ABBREV, Jena.PATH + ".rdfxml.xmloutput.impl.RDFXML_Abbrev"); - setWriterClassName(TestRDFWriterMap.NTRIPLE, Jena.PATH + ".rdf.model.impl.NTripleWriter"); - setWriterClassName(TestRDFWriterMap.NTRIPLES, Jena.PATH + ".rdf.model.impl.NTripleWriter"); - } - - private String setWriterClassName(final String lang, String className) { - try { - final Class old = map.get(lang); - final Class c = Class.forName(className); - if ( RDFWriterI.class.isAssignableFrom(c) ) { - @SuppressWarnings("unchecked") - final Class x = (Class)c; - map.put(lang, x); - } - return old == null ? null : old.getName(); - } catch (final ClassNotFoundException e) { - throw new JenaException(e); - } - } - } - - public static final String RDF_XML = "RDF/XML"; - public static final String RDF_XML_ABBREV = "RDF/XML-ABBREV"; - public static final String NTRIPLE = "N-TRIPLE"; - public static final String NTRIPLES = "N-TRIPLES"; - - public TestRDFWriterMap(final String name) { - super(name); - } - - public void testDefaultWriter() { - final RDFWriterF x = new RDFWriterMap(true); - Assert.assertEquals(x.getWriter("RDF/XML").getClass(), x.getWriter(null).getClass()); - } - - /* public void testMe() { Assert.fail("SPOO"); } */ - - private void testWriterAbsent(final String w) { - final RDFWriterF x = new RDFWriterMap(false); - try { - x.getWriter(w); - } catch (final NoWriterForLangException e) { - Assert.assertEquals(w, e.getMessage()); - } - } - - public void testWritersAbsent() { - testWriterAbsent(TestRDFWriterMap.RDF_XML); - testWriterAbsent(TestRDFWriterMap.RDF_XML_ABBREV); - testWriterAbsent(TestRDFWriterMap.NTRIPLE); - testWriterAbsent(TestRDFWriterMap.NTRIPLES); - } - - public void testWritersPresent() { - final RDFWriterF x = new RDFWriterMap(true); - Assert.assertEquals(RDFXML_Basic.class, x.getWriter(TestRDFWriterMap.RDF_XML).getClass()); - Assert.assertEquals(RDFXML_Abbrev.class, x.getWriter(TestRDFWriterMap.RDF_XML_ABBREV).getClass()); - Assert.assertEquals(NTripleWriter.class, x.getWriter(TestRDFWriterMap.NTRIPLE).getClass()); - Assert.assertEquals(NTripleWriter.class, x.getWriter(TestRDFWriterMap.NTRIPLES).getClass()); - } -} diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestReaderEvents.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestReaderEvents.java index 75a41e4a85a..98882ec3ef2 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestReaderEvents.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestReaderEvents.java @@ -21,25 +21,23 @@ package org.apache.jena.rdf.model; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.io.StringReader; import org.apache.jena.graph.GraphEvents; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.RecordingModelListener; - /** * TestReaderEvents - test that reader events are issued */ +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestReaderEvents extends AbstractModelTestBase { - public TestReaderEvents(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - - public TestReaderEvents() { - this(ModelCreator.plain, "TestReaderEvents"); - } + @Test public void testNTriplesReaderEvents() { testReaderEvent("N-TRIPLE", ""); } @@ -55,6 +53,7 @@ public void testReaderEvent(final String language, final String emptyModel) { L.assertHasEnd(new Object[]{"someEvent", model, GraphEvents.finishRead}); } + @Test public void testXMLReaderEvents() { final String emptyModel = ""; testReaderEvent("RDF/XML", emptyModel); diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestReaders.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestReaders.java index 4a7c122b75f..11d87ac2bac 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestReaders.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestReaders.java @@ -21,46 +21,50 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.io.IOException; import java.net.ConnectException; import java.net.NoRouteToHostException; import java.net.UnknownHostException; -import org.junit.Assert; - -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.impl.NTripleReader; import org.apache.jena.shared.JenaException; import org.slf4j.LoggerFactory; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestReaders extends AbstractModelTestBase { - public TestReaders(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } -// public TestReaders() { -// this(new TS3_Model1.PlainModelFactory(), "TestReaders"); -// } + public TestReaders() {} /** * Test to ensure that the reader is set. */ + @Test public void testGetNTripleReader() { final RDFReaderI reader = new NTripleReader(); - Assert.assertNotNull(reader); + assertNotNull(reader); } + @Test public void testReadLocalNTriple() { model.read(getInputStream("TestReaders.nt"), "", "N-TRIPLE"); - Assert.assertEquals("Wrong size model", 5, model.size()); + assertEquals(5, model.size(), "Wrong size model"); final StmtIterator iter = model.listStatements(null, null, "foo\"\\\n\r\tbar"); - Assert.assertTrue("No next statement found", iter.hasNext()); + assertTrue(iter.hasNext(), "No next statement found"); } + @Test public void testReadLocalRDF() { model.read(getInputStream("TestReaders.rdf"), "http://example.org/"); } + @Test public void testReadRemoteNTriple() { try { model.read("https://www.w3.org/2000/10/rdf-tests/rdfcore/" + "rdf-containers-syntax-vs-schema/test001.nt", "N-TRIPLE"); @@ -74,6 +78,7 @@ public void testReadRemoteNTriple() { } } + @Test public void testReadRemoteRDF() { try { model.read("https://www.w3.org/2000/10/rdf-tests/rdfcore/" + "rdf-containers-syntax-vs-schema/test001.rdf"); diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestRemoveSPO.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestRemoveSPO.java index 53cbb3f6483..58561a1dfdc 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestRemoveSPO.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestRemoveSPO.java @@ -21,25 +21,27 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.util.ArrayList; import java.util.List; -import org.junit.Assert; - import org.apache.jena.graph.Graph; import org.apache.jena.graph.Triple; import org.apache.jena.graph.impl.WrappedGraph; import org.apache.jena.junit.NodeCreateUtils; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.test.JenaTestLib; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestRemoveSPO extends AbstractModelTestBase { - public TestRemoveSPO(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - + @Test public void testRemoveSPOCallsGraphDeleteTriple() { final List deleted = new ArrayList<>(); final Graph base = new WrappedGraph(model.getGraph()) { @@ -50,10 +52,11 @@ public void delete(final Triple t) { }; model = ModelFactory.createModelForGraph(base); model.remove(ModelHelper.resource("R"), ModelHelper.property("P"), ModelHelper.rdfNode(model, "17")); - Assert.assertEquals(JenaTestLib.listOfOne(NodeCreateUtils.createTriple("R P 17")), deleted); + assertEquals(JenaTestLib.listOfOne(NodeCreateUtils.createTriple("R P 17")), deleted); } + @Test public void testRemoveSPOReturnsModel() { - Assert.assertSame(model, model.remove(ModelHelper.resource("R"), ModelHelper.property("P"), ModelHelper.rdfNode(model, "17"))); + assertSame(model, model.remove(ModelHelper.resource("R"), ModelHelper.property("P"), ModelHelper.rdfNode(model, "17"))); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceFactory.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceFactory.java index 2321057f20c..73de9ab8f1d 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceFactory.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceFactory.java @@ -21,17 +21,18 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; import org.apache.jena.datatypes.RDFDatatype; import org.apache.jena.datatypes.xsd.XSDDatatype; -import org.junit.Assert; -import junit.framework.TestCase; -import junit.framework.TestSuite; -public class TestResourceFactory extends TestCase { +public class TestResourceFactory { class TestFactory implements ResourceFactory.Interface { @@ -96,76 +97,75 @@ public Literal createTypedLiteral(final String string, final RDFDatatype datatyp static final String uri2 = "http://example.org/example#a2"; - public static TestSuite suite() { - return new TestSuite(TestResourceFactory.class); - } - - public TestResourceFactory(final String name) { - super(name); - } - + @Test public void testCreateLiteral() { final Literal l = ResourceFactory.createPlainLiteral("lex"); - Assert.assertTrue(l.getLexicalForm().equals("lex")); - Assert.assertTrue(l.getLanguage().equals("")); - Assert.assertNull(l.getDatatype()); - Assert.assertNull(l.getDatatypeURI()); + assertTrue(l.getLexicalForm().equals("lex")); + assertTrue(l.getLanguage().equals("")); + assertNotNull(l.getDatatype()); + assertNotNull(l.getDatatypeURI()); } + @Test public void testCreateProperty() { final Property p1 = ResourceFactory.createProperty(TestResourceFactory.uri1); - Assert.assertTrue(p1.getURI().equals(TestResourceFactory.uri1)); + assertTrue(p1.getURI().equals(TestResourceFactory.uri1)); final Property p2 = ResourceFactory.createProperty(TestResourceFactory.uri1, "2"); - Assert.assertTrue(p2.getURI().equals(TestResourceFactory.uri1 + "2")); + assertTrue(p2.getURI().equals(TestResourceFactory.uri1 + "2")); } + @Test public void testCreateResource() { Resource r1 = ResourceFactory.createResource(); - Assert.assertTrue(r1.isAnon()); + assertTrue(r1.isAnon()); final Resource r2 = ResourceFactory.createResource(); - Assert.assertTrue(r2.isAnon()); - Assert.assertTrue(!r1.equals(r2)); + assertTrue(r2.isAnon()); + assertTrue(!r1.equals(r2)); r1 = ResourceFactory.createResource(TestResourceFactory.uri1); - Assert.assertTrue(r1.getURI().equals(TestResourceFactory.uri1)); + assertTrue(r1.getURI().equals(TestResourceFactory.uri1)); } + @Test public void testCreateStatement() { final Resource s = ResourceFactory.createResource(); final Property p = ResourceFactory.createProperty(TestResourceFactory.uri2); final Resource o = ResourceFactory.createResource(); final Statement stmt = ResourceFactory.createStatement(s, p, o); - Assert.assertTrue(stmt.getSubject().equals(s)); - Assert.assertTrue(stmt.getPredicate().equals(p)); - Assert.assertTrue(stmt.getObject().equals(o)); + assertTrue(stmt.getSubject().equals(s)); + assertTrue(stmt.getPredicate().equals(p)); + assertTrue(stmt.getObject().equals(o)); } + @Test public void testCreateTypedLiteral() { final Literal l = ResourceFactory.createTypedLiteral("22", XSDDatatype.XSDinteger); - Assert.assertTrue(l.getLexicalForm().equals("22")); - Assert.assertTrue(l.getLanguage().equals("")); - Assert.assertTrue(l.getDatatype() == XSDDatatype.XSDinteger); - Assert.assertTrue(l.getDatatypeURI().equals(XSDDatatype.XSDinteger.getURI())); + assertTrue(l.getLexicalForm().equals("22")); + assertTrue(l.getLanguage().equals("")); + assertTrue(l.getDatatype() == XSDDatatype.XSDinteger); + assertTrue(l.getDatatypeURI().equals(XSDDatatype.XSDinteger.getURI())); } + @Test public void testCreateTypedLiteralObject() { final Literal l = ResourceFactory.createTypedLiteral(22); - Assert.assertEquals("22", l.getLexicalForm()); - Assert.assertEquals("", l.getLanguage()); - Assert.assertEquals(XSDDatatype.XSDint, l.getDatatype()); + assertEquals("22", l.getLexicalForm()); + assertEquals("", l.getLanguage()); + assertEquals(XSDDatatype.XSDint, l.getDatatype()); } + @Test public void testCreateTypedLiteralOverload() { final Calendar testCal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); testCal.set(1999, 4, 30, 15, 9, 32); testCal.set(Calendar.MILLISECOND, 0); // ms field can be undefined on // Linux final Literal lc = ResourceFactory.createTypedLiteral(testCal); - Assert.assertEquals("calendar overloading test", - ResourceFactory.createTypedLiteral("1999-05-30T15:09:32Z", XSDDatatype.XSDdateTime), lc); + assertEquals(ResourceFactory.createTypedLiteral("1999-05-30T15:09:32Z", XSDDatatype.XSDdateTime), lc, "calendar overloading test"); } + @Test public void testCreateStatementTerm() { final Resource s = ResourceFactory.createResource(); final Property p = ResourceFactory.createProperty(TestResourceFactory.uri2); @@ -173,31 +173,33 @@ public void testCreateStatementTerm() { final Statement stmt0 = ResourceFactory.createStatement(s, p, o); final StatementTerm stmtTerm = ResourceFactory.createStatementTerm(stmt0); - Assert.assertEquals(stmt0, stmtTerm.getStatement()); + assertEquals(stmt0, stmtTerm.getStatement()); final Statement stmt = stmtTerm.getStatement(); - Assert.assertTrue(stmt.getSubject().equals(s)); - Assert.assertTrue(stmt.getPredicate().equals(p)); - Assert.assertTrue(stmt.getObject().equals(o)); + assertTrue(stmt.getSubject().equals(s)); + assertTrue(stmt.getPredicate().equals(p)); + assertTrue(stmt.getObject().equals(o)); } + @Test public void testGetInstance() { ResourceFactory.getInstance(); final Resource r1 = ResourceFactory.createResource(); - Assert.assertTrue(r1.isAnon()); + assertTrue(r1.isAnon()); final Resource r2 = ResourceFactory.createResource(); - Assert.assertTrue(r2.isAnon()); - Assert.assertTrue(!r1.equals(r2)); + assertTrue(r2.isAnon()); + assertTrue(!r1.equals(r2)); } + @Test public void testSetInstance() { final Resource r = ResourceFactory.createResource(); final ResourceFactory.Interface oldFactory = ResourceFactory.getInstance(); final ResourceFactory.Interface factory = new TestFactory(r); try { ResourceFactory.setInstance(factory); - Assert.assertTrue(factory.equals(ResourceFactory.getInstance())); - Assert.assertTrue(ResourceFactory.createResource() == r); + assertTrue(factory.equals(ResourceFactory.getInstance())); + assertTrue(ResourceFactory.createResource() == r); } finally { ResourceFactory.setInstance(oldFactory); } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceImpl.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceImpl.java index 5e622ec64f0..158739160e3 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceImpl.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceImpl.java @@ -21,72 +21,84 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.test.JenaTestLib; import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; /** * TestResourceImpl - fresh tests, make sure as-ing works a bit. */ +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestResourceImpl extends AbstractModelTestBase { - public TestResourceImpl(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } + @Test public void testAddLiteralPassesLiteralUnmodified() { final Resource r = model.createResource(); final Literal lit = model.createLiteral("spoo"); r.addLiteral(RDF.value, lit); - Assert.assertTrue("model should contain unmodified literal", model.contains(null, RDF.value, lit)); + assertTrue(model.contains(null, RDF.value, lit), "model should contain unmodified literal"); } + @Test public void testAddTypedPropertyBoolean() { final Resource r = model.createResource(); r.addLiteral(RDF.value, true); - Assert.assertEquals(model.createTypedLiteral(true), r.getProperty(RDF.value).getLiteral()); + assertEquals(model.createTypedLiteral(true), r.getProperty(RDF.value).getLiteral()); } + @Test public void testAddTypedPropertyChar() { final Resource r = model.createResource(); r.addLiteral(RDF.value, 'x'); - Assert.assertEquals(model.createTypedLiteral('x'), r.getProperty(RDF.value).getLiteral()); + assertEquals(model.createTypedLiteral('x'), r.getProperty(RDF.value).getLiteral()); } + @Test public void testAddTypedPropertyDouble() { final Resource r = model.createResource(); r.addLiteral(RDF.value, 1.0d); - Assert.assertEquals(model.createTypedLiteral(1.0d), r.getProperty(RDF.value).getLiteral()); + assertEquals(model.createTypedLiteral(1.0d), r.getProperty(RDF.value).getLiteral()); } + @Test public void testAddTypedPropertyFloat() { final Resource r = model.createResource(); r.addLiteral(RDF.value, 1.0f); - Assert.assertEquals(model.createTypedLiteral(1.0f), r.getProperty(RDF.value).getLiteral()); + assertEquals(model.createTypedLiteral(1.0f), r.getProperty(RDF.value).getLiteral()); } + @Test public void testAddTypedPropertyInt() { // Model model = ModelFactory.createDefaultModel(); // Resource r = model.createResource(); // r.addLiteral( RDF.value, 1 ); - // assertEquals( model.createTypedLiteral( 1 ), r.getProperty( RDF.value + // assertEquals(model.createTypedLiteral( 1 ), r.getProperty( RDF.value // ).getLiteral() ); } + @Test public void testAddTypedPropertyLong() { final Resource r = model.createResource(); r.addLiteral(RDF.value, 1L); - Assert.assertEquals(model.createTypedLiteral(1L), r.getProperty(RDF.value).getLiteral()); + assertEquals(model.createTypedLiteral(1L), r.getProperty(RDF.value).getLiteral()); } + @Test public void testAddTypedPropertyObject() { final Object z = new Object(); final Resource r = model.createResource(); r.addLiteral(RDF.value, z); - Assert.assertEquals(model.createTypedLiteral(z), r.getProperty(RDF.value).getLiteral()); + assertEquals(model.createTypedLiteral(z), r.getProperty(RDF.value).getLiteral()); } + @Test public void testAddTypedPropertyString() { } @@ -94,10 +106,11 @@ public void testAddTypedPropertyString() { /** * Test that a literal node cannot be as'ed into a resource. */ + @Test public void testAsLiteral() { try { ModelHelper.literal(model, "17").as(Resource.class); - Assert.fail("literals cannot be resources"); + fail("literals cannot be resources"); } catch (final ResourceRequiredException e) { JenaTestLib.pass(); } @@ -106,92 +119,107 @@ public void testAsLiteral() { /** * Test that a non-literal node can be as'ed into a resource */ + @Test public void testCannotAsNonLiteral() { ModelHelper.resource(model, "plumPie").as(Resource.class); } + @Test public void testGetLocalNameReturnsLocalName() { - Assert.assertEquals("xyz", ModelHelper.resource("eh:xyz").getLocalName()); + assertEquals("xyz", ModelHelper.resource("eh:xyz").getLocalName()); } + @Test public void testGetModel() { - Assert.assertSame(model, model.createResource("eh:/wossname").getModel()); + assertSame(model, model.createResource("eh:/wossname").getModel()); } + @Test public void testGetPropertyResourceValueReturnsNull() { - final Model model = ModelHelper.modelWithStatements(this, "x p 17"); + final Model model = modelWithStatements("x p 17"); final Resource r = model.createResource("eh:/x"); - Assert.assertNull(r.getPropertyResourceValue(ModelHelper.property("q"))); - Assert.assertNull(r.getPropertyResourceValue(ModelHelper.property("p"))); + assertNull(r.getPropertyResourceValue(ModelHelper.property("q"))); + assertNull(r.getPropertyResourceValue(ModelHelper.property("p"))); } + @Test public void testGetPropertyResourceValueReturnsResource() { - final Model model = ModelHelper.modelWithStatements(this, "x p 17; x p y"); + final Model model = modelWithStatements("x p 17; x p y"); final Resource r = model.createResource("eh:/x"); final Resource value = r.getPropertyResourceValue(ModelHelper.property("p")); - Assert.assertEquals(ModelHelper.resource("y"), value); + assertEquals(ModelHelper.resource("y"), value); } + @Test public void testHasTypedPropertyBoolean() { final Resource r = model.createResource(); r.addLiteral(RDF.value, false); - Assert.assertTrue(r.hasLiteral(RDF.value, false)); + assertTrue(r.hasLiteral(RDF.value, false)); } + @Test public void testHasTypedPropertyChar() { final Resource r = model.createResource(); r.addLiteral(RDF.value, 'x'); - Assert.assertTrue(r.hasLiteral(RDF.value, 'x')); + assertTrue(r.hasLiteral(RDF.value, 'x')); } + @Test public void testHasTypedPropertyDouble() { final Resource r = model.createResource(); r.addLiteral(RDF.value, 1.0d); - Assert.assertTrue(r.hasLiteral(RDF.value, 1.0d)); + assertTrue(r.hasLiteral(RDF.value, 1.0d)); } + @Test public void testHasTypedPropertyFloat() { final Resource r = model.createResource(); r.addLiteral(RDF.value, 1.0f); - Assert.assertTrue(r.hasLiteral(RDF.value, 1.0f)); + assertTrue(r.hasLiteral(RDF.value, 1.0f)); } + @Test public void testHasTypedPropertyInt() { final Resource r = model.createResource(); r.addLiteral(RDF.value, 1); - Assert.assertTrue(r.hasLiteral(RDF.value, 1)); + assertTrue(r.hasLiteral(RDF.value, 1)); } + @Test public void testHasTypedPropertyLong() { final Resource r = model.createResource(); r.addLiteral(RDF.value, 1L); - Assert.assertTrue(r.hasLiteral(RDF.value, 1L)); + assertTrue(r.hasLiteral(RDF.value, 1L)); } + @Test public void testHasTypedPropertyObject() { final Object z = new Object(); final Resource r = model.createResource(); r.addLiteral(RDF.value, z); - Assert.assertTrue(r.hasLiteral(RDF.value, z)); + assertTrue(r.hasLiteral(RDF.value, z)); } + @Test public void testHasTypedPropertyString() { } + @Test public void testHasURI() { - Assert.assertTrue(ModelHelper.resource("eh:xyz").hasURI("eh:xyz")); - Assert.assertFalse(ModelHelper.resource("eh:xyz").hasURI("eh:1yz")); - Assert.assertFalse(ResourceFactory.createResource().hasURI("42")); + assertTrue(ModelHelper.resource("eh:xyz").hasURI("eh:xyz")); + assertFalse(ModelHelper.resource("eh:xyz").hasURI("eh:1yz")); + assertFalse(ResourceFactory.createResource().hasURI("42")); } + @Test public void testNameSpace() { - Assert.assertEquals("eh:", ModelHelper.resource("eh:xyz").getNameSpace()); - Assert.assertEquals("http://d/", ModelHelper.resource("http://d/stuff").getNameSpace()); - Assert.assertEquals("ftp://dd.com/12345", ModelHelper.resource("ftp://dd.com/12345").getNameSpace()); - Assert.assertEquals("http://domain/spoo#", ModelHelper.resource("http://domain/spoo#anchor").getNameSpace()); - Assert.assertEquals("ftp://abd/def#ghi#", ModelHelper.resource("ftp://abd/def#ghi#e11-2").getNameSpace()); + assertEquals("eh:", ModelHelper.resource("eh:xyz").getNameSpace()); + assertEquals("http://d/", ModelHelper.resource("http://d/stuff").getNameSpace()); + assertEquals("ftp://dd.com/12345", ModelHelper.resource("ftp://dd.com/12345").getNameSpace()); + assertEquals("http://domain/spoo#", ModelHelper.resource("http://domain/spoo#anchor").getNameSpace()); + assertEquals("ftp://abd/def#ghi#", ModelHelper.resource("ftp://abd/def#ghi#e11-2").getNameSpace()); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceMethods.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceMethods.java index 03d08eb420d..714b7c69bea 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceMethods.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestResourceMethods.java @@ -21,14 +21,20 @@ package org.apache.jena.rdf.model; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; import org.apache.jena.atlas.iterator.Iter; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.shared.PropertyNotFoundException; import org.apache.jena.test.JenaTestLib; import org.apache.jena.vocabulary.RDF; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestResourceMethods extends AbstractModelTestBase { protected Resource r; @@ -38,11 +44,8 @@ public class TestResourceMethods extends AbstractModelTestBase { protected Resource tvResource; - public TestResourceMethods(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - @Override + @BeforeEach public void setUp() { super.setUp(); tvLiteral = model.createLiteral("test 12 string 2"); @@ -56,94 +59,113 @@ public void setUp() { .addProperty(RDF.value, tvLiteral).addProperty(RDF.value, tvResource); } + @Test public void testAllSubjectsCorrect() { testHasSubjectR(model.listStatements()); testHasSubjectR(r.listProperties()); } + @Test public void testBoolean() { - Assert.assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvBoolean)); + assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvBoolean)); } + @Test public void testByte() { - Assert.assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvByte)); + assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvByte)); } + @Test public void testChar() { - Assert.assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvChar)); + assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvChar)); } + @Test public void testCorrectSubject() { - Assert.assertEquals(r, r.getRequiredProperty(RDF.value).getSubject()); + assertEquals(r, r.getRequiredProperty(RDF.value).getSubject()); } + @Test public void testCountsCorrect() { - Assert.assertEquals(13, Iter.toList(model.listStatements()).size()); - Assert.assertEquals(13, Iter.toList(r.listProperties(RDF.value)).size()); - Assert.assertEquals(0, Iter.toList(r.listProperties(RDF.type)).size()); + assertEquals(13, Iter.toList(model.listStatements()).size()); + assertEquals(13, Iter.toList(r.listProperties(RDF.value)).size()); + assertEquals(0, Iter.toList(r.listProperties(RDF.type)).size()); } + @Test public void testDouble() { - Assert.assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvDouble)); + assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvDouble)); } + @Test public void testFloat() { - Assert.assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvFloat)); + assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvFloat)); } protected void testHasSubjectR(final StmtIterator it) { while (it.hasNext()) { - Assert.assertEquals(r, it.nextStatement().getSubject()); + assertEquals(r, it.nextStatement().getSubject()); } } + @Test public void testInt() { - Assert.assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvInt)); + assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvInt)); } + @Test public void testLiteral() { - Assert.assertTrue(r.hasProperty(RDF.value, tvLiteral)); + assertTrue(r.hasProperty(RDF.value, tvLiteral)); } + @Test public void testLong() { - Assert.assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvLong)); + assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvLong)); } + @Test public void testNoSuchPropertyException() { try { r.getRequiredProperty(RDF.type); - Assert.fail("missing property should throw exception"); + fail("missing property should throw exception"); } catch (final PropertyNotFoundException e) { JenaTestLib.pass(); } } + @Test public void testNoSuchPropertyNull() { - Assert.assertNull(r.getProperty(RDF.type)); + assertNull(r.getProperty(RDF.type)); } + @Test public void testObject() { - Assert.assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvObject)); + assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvObject)); } + @Test public void testRemoveProperties() { r.removeProperties(); - Assert.assertEquals(false, model.listStatements(r, null, (RDFNode)null).hasNext()); + assertEquals(false, model.listStatements(r, null, (RDFNode)null).hasNext()); } + @Test public void testResource() { - Assert.assertTrue(r.hasProperty(RDF.value, tvResource)); + assertTrue(r.hasProperty(RDF.value, tvResource)); } + @Test public void testShort() { - Assert.assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvShort)); + assertTrue(r.hasLiteral(RDF.value, AbstractModelTestBase.tvShort)); } + @Test public void testString() { - Assert.assertTrue(r.hasProperty(RDF.value, AbstractModelTestBase.tvString)); + assertTrue(r.hasProperty(RDF.value, AbstractModelTestBase.tvString)); } + @Test public void testStringWithLanguage() { - Assert.assertTrue(r.hasProperty(RDF.value, AbstractModelTestBase.tvString, lang)); + assertTrue(r.hasProperty(RDF.value, AbstractModelTestBase.tvString, lang)); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestResources.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestResources.java index af35ba7347a..06f7b7a68c7 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestResources.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestResources.java @@ -21,29 +21,31 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.util.HashSet; import java.util.Set; -import org.junit.Assert; - import org.apache.jena.atlas.iterator.Iter; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.shared.InvalidPropertyURIException; import org.apache.jena.shared.PropertyNotFoundException; import org.apache.jena.test.JenaTestLib; import org.apache.jena.vocabulary.RDF; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestResources extends AbstractModelTestBase { - public TestResources(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } protected void checkNumericContent(final Container cont2, final int num) { final NodeIterator nit = cont2.iterator(); for ( int i = 0 ; i < num ; i += 1 ) { - Assert.assertEquals(i, ((Literal)nit.nextNode()).getInt()); + assertEquals(i, ((Literal)nit.nextNode()).getInt()); } - Assert.assertFalse(nit.hasNext()); + assertFalse(nit.hasNext()); } protected void retainOnlySpecified(final Container cont2, final int num, final boolean[] retain) { @@ -54,14 +56,14 @@ protected void retainOnlySpecified(final Container cont2, final int num, final b nit.remove(); } } - Assert.assertFalse(nit.hasNext()); + assertFalse(nit.hasNext()); } protected void seeWhatsThere(final Container cont2, final boolean[] found) { final NodeIterator nit = cont2.iterator(); while (nit.hasNext()) { final int v = ((Literal)nit.nextNode()).getInt(); - Assert.assertFalse(found[v]); + assertFalse(found[v]); found[v] = true; } } @@ -81,30 +83,30 @@ private void containerTest(final Model model, final Container cont1, final Conta model.createSeq(); final String lang = "en"; // - Assert.assertEquals(0, cont1.size()); - Assert.assertEquals(0, cont2.size()); + assertEquals(0, cont1.size()); + assertEquals(0, cont2.size()); // - Assert.assertTrue(cont1.add(AbstractModelTestBase.tvBoolean).contains(AbstractModelTestBase.tvBoolean)); - Assert.assertTrue(cont1.add(AbstractModelTestBase.tvByte).contains(AbstractModelTestBase.tvByte)); - Assert.assertTrue(cont1.add(AbstractModelTestBase.tvShort).contains(AbstractModelTestBase.tvShort)); - Assert.assertTrue(cont1.add(AbstractModelTestBase.tvInt).contains(AbstractModelTestBase.tvInt)); - Assert.assertTrue(cont1.add(AbstractModelTestBase.tvLong).contains(AbstractModelTestBase.tvLong)); - Assert.assertTrue(cont1.add(AbstractModelTestBase.tvFloat).contains(AbstractModelTestBase.tvFloat)); - Assert.assertTrue(cont1.add(AbstractModelTestBase.tvDouble).contains(AbstractModelTestBase.tvDouble)); - Assert.assertTrue(cont1.add(AbstractModelTestBase.tvChar).contains(AbstractModelTestBase.tvChar)); - Assert.assertTrue(cont1.add(AbstractModelTestBase.tvString).contains(AbstractModelTestBase.tvString)); - Assert.assertFalse(cont1.contains(AbstractModelTestBase.tvString, lang)); - Assert.assertTrue(cont1.add(AbstractModelTestBase.tvString, lang).contains(AbstractModelTestBase.tvString, lang)); - Assert.assertTrue(cont1.add(tvLiteral).contains(tvLiteral)); - // assertTrue( cont1.add( tvResObj ).contains( tvResObj ) ); - Assert.assertTrue(cont1.add(tvLitObj).contains(tvLitObj)); - Assert.assertEquals(12, cont1.size()); + assertTrue(cont1.add(AbstractModelTestBase.tvBoolean).contains(AbstractModelTestBase.tvBoolean)); + assertTrue(cont1.add(AbstractModelTestBase.tvByte).contains(AbstractModelTestBase.tvByte)); + assertTrue(cont1.add(AbstractModelTestBase.tvShort).contains(AbstractModelTestBase.tvShort)); + assertTrue(cont1.add(AbstractModelTestBase.tvInt).contains(AbstractModelTestBase.tvInt)); + assertTrue(cont1.add(AbstractModelTestBase.tvLong).contains(AbstractModelTestBase.tvLong)); + assertTrue(cont1.add(AbstractModelTestBase.tvFloat).contains(AbstractModelTestBase.tvFloat)); + assertTrue(cont1.add(AbstractModelTestBase.tvDouble).contains(AbstractModelTestBase.tvDouble)); + assertTrue(cont1.add(AbstractModelTestBase.tvChar).contains(AbstractModelTestBase.tvChar)); + assertTrue(cont1.add(AbstractModelTestBase.tvString).contains(AbstractModelTestBase.tvString)); + assertFalse(cont1.contains(AbstractModelTestBase.tvString, lang)); + assertTrue(cont1.add(AbstractModelTestBase.tvString, lang).contains(AbstractModelTestBase.tvString, lang)); + assertTrue(cont1.add(tvLiteral).contains(tvLiteral)); + // assertTrue(cont1.add( tvResObj ).contains( tvResObj ) ); + assertTrue(cont1.add(tvLitObj).contains(tvLitObj)); + assertEquals(12, cont1.size()); // final int num = 10; for ( int i = 0 ; i < num ; i += 1 ) { cont2.add(i); } - Assert.assertEquals(num, cont2.size()); + assertEquals(num, cont2.size()); checkNumericContent(cont2, num); // final boolean[] found = new boolean[num]; @@ -112,83 +114,94 @@ private void containerTest(final Model model, final Container cont1, final Conta retainOnlySpecified(cont2, num, retain); seeWhatsThere(cont2, found); for ( int i = 0 ; i < num ; i += 1 ) { - Assert.assertEquals(i + "th element of array", retain[i], found[i]); + assertEquals(retain[i], found[i], i + "th element of array"); } } + @Test public void testCreateAnonResource() { final Resource r = model.createResource(); - Assert.assertTrue(r.isAnon()); - Assert.assertNull(r.getURI()); - Assert.assertNull(r.getNameSpace()); - Assert.assertNull(r.getLocalName()); + assertTrue(r.isAnon()); + assertNull(r.getURI()); + assertNull(r.getNameSpace()); + assertNull(r.getLocalName()); } + @Test public void testCreateAnonResourceWithNull() { final Resource r = model.createResource((String)null); - Assert.assertTrue(r.isAnon()); - Assert.assertNull(r.getURI()); - Assert.assertNull(r.getNameSpace()); - Assert.assertNull(r.getLocalName()); + assertTrue(r.isAnon()); + assertNull(r.getURI()); + assertNull(r.getNameSpace()); + assertNull(r.getLocalName()); } + @Test public void testCreateNamedResource() { final String uri = "http://aldabaran.hpl.hp.com/foo"; - Assert.assertEquals(uri, model.createResource(uri).getURI()); + assertEquals(uri, model.createResource(uri).getURI()); } + @Test public void testCreateNullPropertyFails() { try { model.createProperty(null); - Assert.fail("should not create null property"); + fail("should not create null property"); } catch (final InvalidPropertyURIException e) { JenaTestLib.pass(); } } + @Test public void testCreatePropertyOneArg() { final Property p = model.createProperty("abc/def"); - Assert.assertEquals("abc/", p.getNameSpace()); - Assert.assertEquals("def", p.getLocalName()); - Assert.assertEquals("abc/def", p.getURI()); + assertEquals("abc/", p.getNameSpace()); + assertEquals("def", p.getLocalName()); + assertEquals("abc/def", p.getURI()); } + @Test public void testCreatePropertyStrangeURI() { final String uri = RDF.getURI() + "_345"; final Property p = model.createProperty(uri); - Assert.assertEquals(RDF.getURI(), p.getNameSpace()); - Assert.assertEquals("_345", p.getLocalName()); - Assert.assertEquals(uri, p.getURI()); + assertEquals(RDF.getURI(), p.getNameSpace()); + assertEquals("_345", p.getLocalName()); + assertEquals(uri, p.getURI()); } + @Test public void testCreatePropertyStrangeURITwoArgs() { final String local = "_345"; final Property p = model.createProperty(RDF.getURI(), local); - Assert.assertEquals(RDF.getURI(), p.getNameSpace()); - Assert.assertEquals(local, p.getLocalName()); - Assert.assertEquals(RDF.getURI() + local, p.getURI()); + assertEquals(RDF.getURI(), p.getNameSpace()); + assertEquals(local, p.getLocalName()); + assertEquals(RDF.getURI() + local, p.getURI()); } + @Test public void testCreatePropertyTwoArgs() { final Property p = model.createProperty("abc/", "def"); - Assert.assertEquals("abc/", p.getNameSpace()); - Assert.assertEquals("def", p.getLocalName()); - Assert.assertEquals("abc/def", p.getURI()); + assertEquals("abc/", p.getNameSpace()); + assertEquals("def", p.getLocalName()); + assertEquals("abc/def", p.getURI()); } + @Test public void testCreateTypedAnonResource() { final Resource r = model.createResource(RDF.Property); - Assert.assertTrue(r.isAnon()); - Assert.assertTrue(model.contains(r, RDF.type, RDF.Property)); + assertTrue(r.isAnon()); + assertTrue(model.contains(r, RDF.type, RDF.Property)); } + @Test public void testCreateTypedNamedresource() { final String uri = "http://aldabaran.hpl.hp.com/foo"; final Resource r = model.createResource(uri, RDF.Property); - Assert.assertEquals(uri, r.getURI()); - Assert.assertTrue(model.contains(r, RDF.type, RDF.Property)); + assertEquals(uri, r.getURI()); + assertTrue(model.contains(r, RDF.type, RDF.Property)); } + @Test public void testEnhancedResources() { final Resource r = model.createResource(); resourceTest(model, r, 0); @@ -208,40 +221,40 @@ private void resourceTest(final Model model, final Resource r, final int numProp final Resource tvResource = model.createResource(); final String lang = "fr"; // - Assert.assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvBoolean).hasLiteral(RDF.value, AbstractModelTestBase.tvBoolean)); - Assert.assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvByte).hasLiteral(RDF.value, AbstractModelTestBase.tvByte)); - Assert.assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvShort).hasLiteral(RDF.value, AbstractModelTestBase.tvShort)); - Assert.assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvInt).hasLiteral(RDF.value, AbstractModelTestBase.tvInt)); - Assert.assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvLong).hasLiteral(RDF.value, AbstractModelTestBase.tvLong)); - Assert.assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvChar).hasLiteral(RDF.value, AbstractModelTestBase.tvChar)); - Assert.assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvFloat).hasLiteral(RDF.value, AbstractModelTestBase.tvFloat)); - Assert.assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvDouble).hasLiteral(RDF.value, AbstractModelTestBase.tvDouble)); - Assert.assertTrue(r.addProperty(RDF.value, AbstractModelTestBase.tvString).hasProperty(RDF.value, AbstractModelTestBase.tvString)); - Assert.assertTrue(r.addProperty(RDF.value, AbstractModelTestBase.tvString, lang).hasProperty(RDF.value, + assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvBoolean).hasLiteral(RDF.value, AbstractModelTestBase.tvBoolean)); + assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvByte).hasLiteral(RDF.value, AbstractModelTestBase.tvByte)); + assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvShort).hasLiteral(RDF.value, AbstractModelTestBase.tvShort)); + assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvInt).hasLiteral(RDF.value, AbstractModelTestBase.tvInt)); + assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvLong).hasLiteral(RDF.value, AbstractModelTestBase.tvLong)); + assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvChar).hasLiteral(RDF.value, AbstractModelTestBase.tvChar)); + assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvFloat).hasLiteral(RDF.value, AbstractModelTestBase.tvFloat)); + assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvDouble).hasLiteral(RDF.value, AbstractModelTestBase.tvDouble)); + assertTrue(r.addProperty(RDF.value, AbstractModelTestBase.tvString).hasProperty(RDF.value, AbstractModelTestBase.tvString)); + assertTrue(r.addProperty(RDF.value, AbstractModelTestBase.tvString, lang).hasProperty(RDF.value, AbstractModelTestBase.tvString, lang)); - Assert.assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvObject).hasLiteral(RDF.value, AbstractModelTestBase.tvObject)); - Assert.assertTrue(r.addProperty(RDF.value, tvLiteral).hasProperty(RDF.value, tvLiteral)); - Assert.assertTrue(r.addProperty(RDF.value, tvResource).hasProperty(RDF.value, tvResource)); - Assert.assertTrue(r.getRequiredProperty(RDF.value).getSubject().equals(r)); + assertTrue(r.addLiteral(RDF.value, AbstractModelTestBase.tvObject).hasLiteral(RDF.value, AbstractModelTestBase.tvObject)); + assertTrue(r.addProperty(RDF.value, tvLiteral).hasProperty(RDF.value, tvLiteral)); + assertTrue(r.addProperty(RDF.value, tvResource).hasProperty(RDF.value, tvResource)); + assertTrue(r.getRequiredProperty(RDF.value).getSubject().equals(r)); // final Property p = model.createProperty("foo/", "bar"); try { r.getRequiredProperty(p); - Assert.fail("should detect missing property"); + fail("should detect missing property"); } catch (final PropertyNotFoundException e) { JenaTestLib.pass(); } // - Assert.assertEquals(13, Iter.toSet(r.listProperties(RDF.value)).size()); - Assert.assertEquals(setOf(r), Iter.toSet(r.listProperties(RDF.value).mapWith(Statement::getSubject))); + assertEquals(13, Iter.toSet(r.listProperties(RDF.value)).size()); + assertEquals(setOf(r), Iter.toSet(r.listProperties(RDF.value).mapWith(Statement::getSubject))); // - Assert.assertEquals(0, Iter.toSet(r.listProperties(p)).size()); - Assert.assertEquals(new HashSet(), Iter.toSet(r.listProperties(p).mapWith(Statement::getSubject))); + assertEquals(0, Iter.toSet(r.listProperties(p)).size()); + assertEquals(new HashSet(), Iter.toSet(r.listProperties(p).mapWith(Statement::getSubject))); // - Assert.assertEquals(13 + numProps, Iter.toSet(r.listProperties()).size()); - Assert.assertEquals(setOf(r), Iter.toSet(r.listProperties().mapWith(Statement::getSubject))); + assertEquals(13 + numProps, Iter.toSet(r.listProperties()).size()); + assertEquals(setOf(r), Iter.toSet(r.listProperties().mapWith(Statement::getSubject))); // r.removeProperties(); - Assert.assertEquals(0, r.listProperties().toList().size()); + assertEquals(0, r.listProperties().toList().size()); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestSeqMethods.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestSeqMethods.java index f488e45c7e5..e6553cec39d 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestSeqMethods.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestSeqMethods.java @@ -21,19 +21,22 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.util.ArrayList; import java.util.List; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.test.JenaTestLib; import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; -import junit.framework.TestSuite; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestSeqMethods extends AbstractContainerMethods { - public static TestSuite suite() { - return new TestSuite(TestSeqMethods.class); - } protected LitTestObj aLitTestObj; @@ -50,10 +53,6 @@ public static TestSuite suite() { protected static final String lang = "fr"; protected static final int num = 10; - public TestSeqMethods(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - protected boolean[] bools(final String s) { final boolean[] result = new boolean[s.length()]; for ( int i = 0 ; i < s.length() ; i += 1 ) { @@ -68,7 +67,7 @@ protected Container createContainer() { } public void error(final String test, final int n) { - Assert.fail(test + " -- " + n); + fail(test + " -- " + n); } @Override @@ -77,6 +76,7 @@ protected Resource getContainerType() { } @Override + @BeforeEach public void setUp() { super.setUp(); aLitTestObj = new LitTestObj(12345); @@ -89,6 +89,7 @@ public void setUp() { tvSeq = model.createSeq(); } + @Test public void testMoreIndexing() { final int num = 10; final Seq seq = model.createSeq(); @@ -98,18 +99,18 @@ public void testMoreIndexing() { try { seq.add(0, false); - Assert.fail("cannot at at position 0"); + fail("cannot at at position 0"); } catch (final SeqIndexBoundsException e) { JenaTestLib.pass(); } seq.add(num + 1, false); - Assert.assertEquals(num + 1, seq.size()); + assertEquals(num + 1, seq.size()); seq.remove(num + 1); try { seq.add(num + 2, false); - Assert.fail("cannot add past the end"); + fail("cannot add past the end"); } catch (final SeqIndexBoundsException e) { JenaTestLib.pass(); } @@ -117,10 +118,10 @@ public void testMoreIndexing() { final int size = seq.size(); for ( int i = 1 ; i <= (num - 1) ; i += 1 ) { seq.add(i, 1000 + i); - Assert.assertEquals(1000 + i, seq.getInt(i)); - Assert.assertEquals(0, seq.getInt(i + 1)); - Assert.assertEquals(size + i, seq.size()); - Assert.assertEquals(num - i - 1, seq.getInt(size)); + assertEquals(1000 + i, seq.getInt(i)); + assertEquals(0, seq.getInt(i + 1)); + assertEquals(size + i, seq.size()); + assertEquals(num - i - 1, seq.getInt(size)); } } @@ -143,22 +144,26 @@ protected void testRemove(final boolean[] retain) { } } // - Assert.assertFalse(nIter.hasNext()); - Assert.assertEquals(retained, seq.iterator().toList()); + assertFalse(nIter.hasNext()); + assertEquals(retained, seq.iterator().toList()); } + @Test public void testRemoveA() { testRemove(bools("tttffffftt")); } + @Test public void testRemoveB() { testRemove(bools("ftftttttft")); } + @Test public void testRemoveC() { testRemove(bools("ffffffffff")); } + @Test public void testSeq4() { final String test = "temp"; int n = 58305; @@ -290,6 +295,7 @@ public void testSeq4() { } } + @Test public void testSeq5() { final Seq seq5 = model.createSeq(); final String test = "seq5"; @@ -342,6 +348,7 @@ public void testSeq5() { } } + @Test public void testSeq6() { final String test = "seq6"; int n = 0; @@ -472,6 +479,7 @@ public void testSeq6() { } } + @Test public void testSeq7() { final Seq seq7 = model.createSeq(); final String test = "seq7"; @@ -741,6 +749,7 @@ public void testSeq7() { } } + @Test public void testSeqAccessByIndexing() { // LitTestObj tvObject = new LitTestObj(12345); final Literal tvLiteral = model.createLiteral("test 12 string 2"); @@ -753,124 +762,127 @@ public void testSeqAccessByIndexing() { // final Seq seq = model.createSeq(); seq.add(true); - Assert.assertEquals(true, seq.getBoolean(1)); + assertEquals(true, seq.getBoolean(1)); seq.add((byte)1); - Assert.assertEquals((byte)1, seq.getByte(2)); + assertEquals((byte)1, seq.getByte(2)); seq.add((short)2); - Assert.assertEquals((short)2, seq.getShort(3)); + assertEquals((short)2, seq.getShort(3)); seq.add(-1); - Assert.assertEquals(-1, seq.getInt(4)); + assertEquals(-1, seq.getInt(4)); seq.add(-2); - Assert.assertEquals(-2, seq.getLong(5)); + assertEquals(-2, seq.getLong(5)); seq.add('!'); - Assert.assertEquals('!', seq.getChar(6)); + assertEquals('!', seq.getChar(6)); seq.add(123.456f); - Assert.assertEquals(123.456f, seq.getFloat(7), 0.00005); + assertEquals(123.456f, seq.getFloat(7), 0.00005); seq.add(12345.67890); - Assert.assertEquals(12345.67890, seq.getDouble(8), 0.00000005); + assertEquals(12345.67890, seq.getDouble(8), 0.00000005); seq.add("some string"); - Assert.assertEquals("some string", seq.getString(9)); + assertEquals("some string", seq.getString(9)); seq.add(tvLitObj); - // assertEquals( tvLitObj, seq.getObject( 10, new LitTestObjF() ) ); + // assertEquals(tvLitObj, seq.getObject( 10, new LitTestObjF() ) ); seq.add(tvResource); - Assert.assertEquals(tvResource, seq.getResource(11)); + assertEquals(tvResource, seq.getResource(11)); // seq.add( tvResObj ); - // assertEquals( tvResObj, seq.getResource( 12, new ResTestObjF() ) ); + // assertEquals(tvResObj, seq.getResource( 12, new ResTestObjF() ) ); seq.add(tvLiteral); - Assert.assertEquals(tvLiteral, seq.getLiteral(12)); + assertEquals(tvLiteral, seq.getLiteral(12)); seq.add(tvBag); - Assert.assertEquals(tvBag, seq.getBag(13)); + assertEquals(tvBag, seq.getBag(13)); seq.add(tvAlt); - Assert.assertEquals(tvAlt, seq.getAlt(14)); + assertEquals(tvAlt, seq.getAlt(14)); seq.add(tvSeq); - Assert.assertEquals(tvSeq, seq.getSeq(15)); + assertEquals(tvSeq, seq.getSeq(15)); // try { seq.getInt(16); - Assert.fail("there is no element 16"); + fail("there is no element 16"); } catch (final SeqIndexBoundsException e) { JenaTestLib.pass(); } try { seq.getInt(0); - Assert.fail("there is no element 0"); + fail("there is no element 0"); } catch (final SeqIndexBoundsException e) { JenaTestLib.pass(); } } + @Test public void testSeqAdd() { final Seq seq = model.createSeq(); - Assert.assertEquals(0, seq.size()); - Assert.assertTrue(model.contains(seq, RDF.type, RDF.Seq)); + assertEquals(0, seq.size()); + assertTrue(model.contains(seq, RDF.type, RDF.Seq)); // seq.add(AbstractModelTestBase.tvBoolean); - Assert.assertTrue(seq.contains(AbstractModelTestBase.tvBoolean)); - Assert.assertFalse(seq.contains(!AbstractModelTestBase.tvBoolean)); + assertTrue(seq.contains(AbstractModelTestBase.tvBoolean)); + assertFalse(seq.contains(!AbstractModelTestBase.tvBoolean)); // seq.add(AbstractModelTestBase.tvByte); - Assert.assertTrue(seq.contains(AbstractModelTestBase.tvByte)); - Assert.assertFalse(seq.contains((byte)101)); + assertTrue(seq.contains(AbstractModelTestBase.tvByte)); + assertFalse(seq.contains((byte)101)); // seq.add(AbstractModelTestBase.tvShort); - Assert.assertTrue(seq.contains(AbstractModelTestBase.tvShort)); - Assert.assertFalse(seq.contains((short)102)); + assertTrue(seq.contains(AbstractModelTestBase.tvShort)); + assertFalse(seq.contains((short)102)); // seq.add(AbstractModelTestBase.tvInt); - Assert.assertTrue(seq.contains(AbstractModelTestBase.tvInt)); - Assert.assertFalse(seq.contains(-101)); + assertTrue(seq.contains(AbstractModelTestBase.tvInt)); + assertFalse(seq.contains(-101)); // seq.add(AbstractModelTestBase.tvLong); - Assert.assertTrue(seq.contains(AbstractModelTestBase.tvLong)); - Assert.assertFalse(seq.contains(-102)); + assertTrue(seq.contains(AbstractModelTestBase.tvLong)); + assertFalse(seq.contains(-102)); // seq.add(AbstractModelTestBase.tvChar); - Assert.assertTrue(seq.contains(AbstractModelTestBase.tvChar)); - Assert.assertFalse(seq.contains('?')); + assertTrue(seq.contains(AbstractModelTestBase.tvChar)); + assertFalse(seq.contains('?')); // seq.add(123.456f); - Assert.assertTrue(seq.contains(123.456f)); - Assert.assertFalse(seq.contains(456.123f)); + assertTrue(seq.contains(123.456f)); + assertFalse(seq.contains(456.123f)); // seq.add(-123.456d); - Assert.assertTrue(seq.contains(-123.456d)); - Assert.assertFalse(seq.contains(-456.123d)); + assertTrue(seq.contains(-123.456d)); + assertFalse(seq.contains(-456.123d)); // seq.add("a string"); - Assert.assertTrue(seq.contains("a string")); - Assert.assertFalse(seq.contains("a necklace")); + assertTrue(seq.contains("a string")); + assertFalse(seq.contains("a necklace")); // seq.add(model.createLiteral("another string")); - Assert.assertTrue(seq.contains("another string")); - Assert.assertFalse(seq.contains("another necklace")); + assertTrue(seq.contains("another string")); + assertFalse(seq.contains("another necklace")); // seq.add(new LitTestObj(12345)); - Assert.assertTrue(seq.contains(new LitTestObj(12345))); - Assert.assertFalse(seq.contains(new LitTestObj(54321))); + assertTrue(seq.contains(new LitTestObj(12345))); + assertFalse(seq.contains(new LitTestObj(54321))); // // Resource present = model.createResource( new ResTestObjF() ); // Resource absent = model.createResource( new ResTestObjF() ); // seq.add( present ); - // assertTrue( seq.contains( present ) ); - // assertFalse( seq.contains( absent ) ); + // assertTrue(seq.contains( present ) ); + // assertFalse(seq.contains( absent ) ); // - Assert.assertEquals(11, seq.size()); + assertEquals(11, seq.size()); } + @Test public void testSeqAddInts() { final int num = 10; final Seq seq = model.createSeq(); for ( int i = 0 ; i < num ; i += 1 ) { seq.add(i); } - Assert.assertEquals(num, seq.size()); + assertEquals(num, seq.size()); final List L = seq.iterator().toList(); - Assert.assertEquals(num, L.size()); + assertEquals(num, L.size()); for ( int i = 0 ; i < num ; i += 1 ) { - Assert.assertEquals(i, ((Literal)L.get(i)).getInt()); + assertEquals(i, ((Literal)L.get(i)).getInt()); } } + @Test public void testSeqInsertByIndexing() { // LitTestObj tvObject = new LitTestObj(12345); final Literal tvLiteral = model.createLiteral("test 12 string 2"); @@ -884,56 +896,57 @@ public void testSeqInsertByIndexing() { final Seq seq = model.createSeq(); seq.add(model.createResource()); seq.add(1, true); - Assert.assertEquals(true, seq.getBoolean(1)); + assertEquals(true, seq.getBoolean(1)); seq.add(1, (byte)1); - Assert.assertEquals((byte)1, seq.getByte(1)); + assertEquals((byte)1, seq.getByte(1)); seq.add(1, (short)2); - Assert.assertEquals((short)2, seq.getShort(1)); + assertEquals((short)2, seq.getShort(1)); seq.add(1, -1); - Assert.assertEquals(-1, seq.getInt(1)); + assertEquals(-1, seq.getInt(1)); seq.add(1, -2); - Assert.assertEquals(-2, seq.getLong(1)); + assertEquals(-2, seq.getLong(1)); seq.add(1, '!'); - Assert.assertEquals('!', seq.getChar(1)); + assertEquals('!', seq.getChar(1)); seq.add(1, 123.456f); - Assert.assertEquals(123.456f, seq.getFloat(1), 0.00005); + assertEquals(123.456f, seq.getFloat(1), 0.00005); seq.add(1, 12345.67890); - Assert.assertEquals(12345.67890, seq.getDouble(1), 0.00000005); + assertEquals(12345.67890, seq.getDouble(1), 0.00000005); seq.add(1, "some string"); - Assert.assertEquals("some string", seq.getString(1)); + assertEquals("some string", seq.getString(1)); seq.add(1, tvLitObj); - // assertEquals( tvLitObj, seq.getObject( 1, new LitTestObjF() ) ); + // assertEquals(tvLitObj, seq.getObject( 1, new LitTestObjF() ) ); seq.add(1, tvResource); - Assert.assertEquals(tvResource, seq.getResource(1)); + assertEquals(tvResource, seq.getResource(1)); // seq.add( 1, tvResObj ); - // assertEquals( tvResObj, seq.getResource( 1, new ResTestObjF() ) ); + // assertEquals(tvResObj, seq.getResource( 1, new ResTestObjF() ) ); seq.add(1, tvLiteral); - Assert.assertEquals(tvLiteral, seq.getLiteral(1)); + assertEquals(tvLiteral, seq.getLiteral(1)); seq.add(1, tvBag); - Assert.assertEquals(tvBag, seq.getBag(1)); + assertEquals(tvBag, seq.getBag(1)); seq.add(1, tvAlt); - Assert.assertEquals(tvAlt, seq.getAlt(1)); + assertEquals(tvAlt, seq.getAlt(1)); seq.add(1, tvSeq); - Assert.assertEquals(tvSeq, seq.getSeq(1)); + assertEquals(tvSeq, seq.getSeq(1)); // - Assert.assertEquals(0, seq.indexOf(1234543)); - Assert.assertEquals(1, seq.indexOf(tvSeq)); - Assert.assertEquals(2, seq.indexOf(tvAlt)); - Assert.assertEquals(3, seq.indexOf(tvBag)); - Assert.assertEquals(4, seq.indexOf(tvLiteral)); - Assert.assertEquals(5, seq.indexOf(tvResource)); - Assert.assertEquals(6, seq.indexOf(tvLitObj)); - Assert.assertEquals(7, seq.indexOf("some string")); - Assert.assertEquals(8, seq.indexOf(12345.67890)); - Assert.assertEquals(9, seq.indexOf(123.456f)); - Assert.assertEquals(10, seq.indexOf('!')); - Assert.assertEquals(11, seq.indexOf(-2)); - Assert.assertEquals(12, seq.indexOf(-1)); - Assert.assertEquals(13, seq.indexOf((short)2)); - Assert.assertEquals(14, seq.indexOf((byte)1)); - Assert.assertEquals(15, seq.indexOf(true)); + assertEquals(0, seq.indexOf(1234543)); + assertEquals(1, seq.indexOf(tvSeq)); + assertEquals(2, seq.indexOf(tvAlt)); + assertEquals(3, seq.indexOf(tvBag)); + assertEquals(4, seq.indexOf(tvLiteral)); + assertEquals(5, seq.indexOf(tvResource)); + assertEquals(6, seq.indexOf(tvLitObj)); + assertEquals(7, seq.indexOf("some string")); + assertEquals(8, seq.indexOf(12345.67890)); + assertEquals(9, seq.indexOf(123.456f)); + assertEquals(10, seq.indexOf('!')); + assertEquals(11, seq.indexOf(-2)); + assertEquals(12, seq.indexOf(-1)); + assertEquals(13, seq.indexOf((short)2)); + assertEquals(14, seq.indexOf((byte)1)); + assertEquals(15, seq.indexOf(true)); } + @Test public void testSet() { // NodeIterator nIter; // StmtIterator sIter; @@ -951,82 +964,82 @@ public void testSet() { } seq.set(5, AbstractModelTestBase.tvBoolean); - Assert.assertEquals(AbstractModelTestBase.tvBoolean, seq.getBoolean(5)); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + assertEquals(AbstractModelTestBase.tvBoolean, seq.getBoolean(5)); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); seq.set(5, AbstractModelTestBase.tvByte); - Assert.assertEquals(AbstractModelTestBase.tvByte, seq.getByte(5)); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + assertEquals(AbstractModelTestBase.tvByte, seq.getByte(5)); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); seq.set(5, AbstractModelTestBase.tvShort); - Assert.assertEquals(AbstractModelTestBase.tvShort, seq.getShort(5)); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + assertEquals(AbstractModelTestBase.tvShort, seq.getShort(5)); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); seq.set(5, AbstractModelTestBase.tvInt); - Assert.assertEquals(AbstractModelTestBase.tvInt, seq.getInt(5)); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + assertEquals(AbstractModelTestBase.tvInt, seq.getInt(5)); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); seq.set(5, AbstractModelTestBase.tvLong); - Assert.assertEquals(AbstractModelTestBase.tvLong, seq.getLong(5)); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + assertEquals(AbstractModelTestBase.tvLong, seq.getLong(5)); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); seq.set(5, AbstractModelTestBase.tvString); - Assert.assertEquals(AbstractModelTestBase.tvString, seq.getString(5)); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + assertEquals(AbstractModelTestBase.tvString, seq.getString(5)); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); seq.set(5, AbstractModelTestBase.tvBoolean); - Assert.assertEquals(AbstractModelTestBase.tvBoolean, seq.getBoolean(5)); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + assertEquals(AbstractModelTestBase.tvBoolean, seq.getBoolean(5)); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); seq.set(5, AbstractModelTestBase.tvFloat); - Assert.assertEquals(AbstractModelTestBase.tvFloat, seq.getFloat(5), 0.00005); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + assertEquals(AbstractModelTestBase.tvFloat, seq.getFloat(5), 0.00005); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); seq.set(5, AbstractModelTestBase.tvDouble); - Assert.assertEquals(AbstractModelTestBase.tvDouble, seq.getDouble(5), 0.000000005); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + assertEquals(AbstractModelTestBase.tvDouble, seq.getDouble(5), 0.000000005); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); seq.set(5, tvLiteral); - Assert.assertEquals(tvLiteral, seq.getLiteral(5)); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + assertEquals(tvLiteral, seq.getLiteral(5)); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); seq.set(5, tvResource); - Assert.assertEquals(tvResource, seq.getResource(5)); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + assertEquals(tvResource, seq.getResource(5)); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); seq.set(5, AbstractModelTestBase.tvLitObj); - // assertEquals( tvLitObj, seq.getObject( 5, new LitTestObjF() ) ); - Assert.assertEquals(3, seq.getInt(4)); - Assert.assertEquals(5, seq.getInt(6)); - Assert.assertEquals(num, seq.size()); + // assertEquals(tvLitObj, seq.getObject( 5, new LitTestObjF() ) ); + assertEquals(3, seq.getInt(4)); + assertEquals(5, seq.getInt(6)); + assertEquals(num, seq.size()); // seq.set( 5, tvResObj ); - // assertEquals( tvResObj, seq.getResource( 5, new ResTestObjF() ) ); - // assertEquals( 3, seq.getInt( 4 ) ); - // assertEquals( 5, seq.getInt( 6 ) ); - // assertEquals( num, seq.size() ); + // assertEquals(tvResObj, seq.getResource( 5, new ResTestObjF() ) ); + // assertEquals(3, seq.getInt( 4 ) ); + // assertEquals(5, seq.getInt( 6 ) ); + // assertEquals(num, seq.size() ); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestSimpleListStatements.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestSimpleListStatements.java index 16d76e69767..0c219686c7e 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestSimpleListStatements.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestSimpleListStatements.java @@ -21,13 +21,20 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import java.util.List; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestSimpleListStatements extends AbstractModelTestBase { static boolean booleanValue = true; @@ -39,15 +46,11 @@ public class TestSimpleListStatements extends AbstractModelTestBase { static String stringValue = "stringValue"; static String langValue = "en"; - public TestSimpleListStatements(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - public void checkReturns(final String things, final StmtIterator it) { - final Model wanted = ModelHelper.modelWithStatements(this, things); + final Model wanted = modelWithStatements(things); final Model got = modelWithStatements(it); if ( wanted.isIsomorphicWith(got) == false ) { - Assert.fail("wanted " + wanted + " got " + got); + fail("wanted " + wanted + " got " + got); } } @@ -60,6 +63,7 @@ public Model modelWithStatements(final StmtIterator it) { } @Override + @BeforeEach public void setUp() { super.setUp(); model.createResource("http://example.org/boolean").addLiteral(RDF.value, booleanValue); @@ -71,6 +75,7 @@ public void setUp() { model.createResource("http://example.org/langString").addProperty(RDF.value, stringValue, langValue); } + @Test public void testAll() { final StmtIterator iter = model.listStatements(null, null, (RDFNode)null); int i = 0; @@ -78,9 +83,10 @@ public void testAll() { i++; iter.next(); } - Assert.assertEquals(7, i); + assertEquals(7, i); } + @Test public void testAllString() { final StmtIterator iter = model.listStatements(null, null, (String)null); int i = 0; @@ -88,52 +94,58 @@ public void testAllString() { i++; iter.next(); } - Assert.assertEquals(7, i); + assertEquals(7, i); } + @Test public void testBoolean() { final List got = model.listLiteralStatements(null, null, TestSimpleListStatements.booleanValue).toList(); - Assert.assertEquals(1, got.size()); + assertEquals(1, got.size()); final Statement it = got.get(0); - Assert.assertEquals(ModelHelper.resource("http://example.org/boolean"), it.getSubject()); - Assert.assertEquals(model.createTypedLiteral(TestSimpleListStatements.booleanValue), it.getObject()); + assertEquals(ModelHelper.resource("http://example.org/boolean"), it.getSubject()); + assertEquals(model.createTypedLiteral(TestSimpleListStatements.booleanValue), it.getObject()); } + @Test public void testChar() { final List got = model.listLiteralStatements(null, null, TestSimpleListStatements.charValue).toList(); - Assert.assertEquals(1, got.size()); + assertEquals(1, got.size()); final Statement it = got.get(0); - Assert.assertEquals(ModelHelper.resource("http://example.org/char"), it.getSubject()); - Assert.assertEquals(model.createTypedLiteral(TestSimpleListStatements.charValue), it.getObject()); + assertEquals(ModelHelper.resource("http://example.org/char"), it.getSubject()); + assertEquals(model.createTypedLiteral(TestSimpleListStatements.charValue), it.getObject()); } + @Test public void testDouble() { final List got = model.listLiteralStatements(null, null, TestSimpleListStatements.doubleValue).toList(); - Assert.assertEquals(1, got.size()); + assertEquals(1, got.size()); final Statement it = got.get(0); - Assert.assertEquals(ModelHelper.resource("http://example.org/double"), it.getSubject()); - Assert.assertEquals(model.createTypedLiteral(TestSimpleListStatements.doubleValue), it.getObject()); + assertEquals(ModelHelper.resource("http://example.org/double"), it.getSubject()); + assertEquals(model.createTypedLiteral(TestSimpleListStatements.doubleValue), it.getObject()); } + @Test public void testFloat() { final List got = model.listLiteralStatements(null, null, TestSimpleListStatements.floatValue).toList(); - Assert.assertEquals(1, got.size()); + assertEquals(1, got.size()); final Statement it = got.get(0); - Assert.assertEquals(ModelHelper.resource("http://example.org/float"), it.getSubject()); - Assert.assertEquals(model.createTypedLiteral(TestSimpleListStatements.floatValue), it.getObject()); + assertEquals(ModelHelper.resource("http://example.org/float"), it.getSubject()); + assertEquals(model.createTypedLiteral(TestSimpleListStatements.floatValue), it.getObject()); } + @Test public void testLangString() { final StmtIterator iter = model.listStatements(null, null, TestSimpleListStatements.stringValue, TestSimpleListStatements.langValue); int i = 0; while (iter.hasNext()) { i++; - Assert.assertEquals(iter.nextStatement().getSubject().getURI(), "http://example.org/langString"); + assertEquals(iter.nextStatement().getSubject().getURI(), "http://example.org/langString"); } - Assert.assertEquals(1, i); + assertEquals(1, i); } + @Test public void testListStatementsSPO() { final Resource A = ModelHelper.resource(model, "A"), X = ModelHelper.resource(model, "X"); @@ -150,21 +162,23 @@ public void testListStatementsSPO() { checkReturns(S3, model.listStatements(X, null, Y)); } + @Test public void testLong() { final List got = model.listLiteralStatements(null, null, TestSimpleListStatements.longValue).toList(); - Assert.assertEquals(1, got.size()); + assertEquals(1, got.size()); final Statement it = got.get(0); - Assert.assertEquals(ModelHelper.resource("http://example.org/long"), it.getSubject()); - Assert.assertEquals(model.createTypedLiteral(TestSimpleListStatements.longValue), it.getObject()); + assertEquals(ModelHelper.resource("http://example.org/long"), it.getSubject()); + assertEquals(model.createTypedLiteral(TestSimpleListStatements.longValue), it.getObject()); } + @Test public void testString() { final StmtIterator iter = model.listStatements(null, null, TestSimpleListStatements.stringValue); int i = 0; while (iter.hasNext()) { i++; - Assert.assertEquals(iter.nextStatement().getSubject().getURI(), "http://example.org/string"); + assertEquals(iter.nextStatement().getSubject().getURI(), "http://example.org/string"); } - Assert.assertEquals(1, i); + assertEquals(1, i); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementCreation.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementCreation.java index 56902154ee8..3daf4403ccb 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementCreation.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementCreation.java @@ -21,11 +21,18 @@ package org.apache.jena.rdf.model; -import org.apache.jena.datatypes.xsd.XSDDatatype; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; -import org.junit.Assert; +import org.apache.jena.datatypes.xsd.XSDDatatype; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestStatementCreation extends AbstractModelTestBase { static final String subjURI = "http://aldabaran.hpl.hp.com/foo"; @@ -34,11 +41,8 @@ public class TestStatementCreation extends AbstractModelTestBase { protected Resource r; protected Property p; - public TestStatementCreation(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - @Override + @BeforeEach public void setUp() { super.setUp(); r = model.createResource(TestStatementCreation.subjURI); @@ -46,100 +50,113 @@ public void setUp() { } @Override + @AfterEach public void tearDown() { r = null; p = null; super.tearDown(); } + @Test public void testCreateStatementByteMax() { final Statement s = model.createLiteralStatement(r, p, Byte.MAX_VALUE); - Assert.assertEquals(r, s.getSubject()); - Assert.assertEquals(p, s.getPredicate()); - Assert.assertEquals(Byte.MAX_VALUE, s.getByte()); + assertEquals(r, s.getSubject()); + assertEquals(p, s.getPredicate()); + assertEquals(Byte.MAX_VALUE, s.getByte()); } + @Test public void testCreateStatementChar() { final Statement s = model.createLiteralStatement(r, p, '$'); - Assert.assertEquals(r, s.getSubject()); - Assert.assertEquals(p, s.getPredicate()); - Assert.assertEquals('$', s.getChar()); + assertEquals(r, s.getSubject()); + assertEquals(p, s.getPredicate()); + assertEquals('$', s.getChar()); } + @Test public void testCreateStatementDouble() { final Statement s = model.createStatement(r, p, model.createTypedLiteral(12345.67890d)); - Assert.assertEquals(r, s.getSubject()); - Assert.assertEquals(p, s.getPredicate()); - Assert.assertEquals(12345.67890d, s.getDouble(), 0.0000005); + assertEquals(r, s.getSubject()); + assertEquals(p, s.getPredicate()); + assertEquals(12345.67890d, s.getDouble(), 0.0000005); } + @Test public void testCreateStatementFactory() { final LitTestObj tv = new LitTestObj(Long.MIN_VALUE); final Statement s = model.createLiteralStatement(r, p, tv); - Assert.assertEquals(r, s.getSubject()); - Assert.assertEquals(p, s.getPredicate()); - // assertEquals( tv, s.getObject( new LitTestObjF() ) ); + assertEquals(r, s.getSubject()); + assertEquals(p, s.getPredicate()); + // assertEquals(tv, s.getObject( new LitTestObjF() ) ); } + @Test public void testCreateStatementFloat() { final Statement s = model.createStatement(r, p, model.createTypedLiteral(123.456f)); - Assert.assertEquals(r, s.getSubject()); - Assert.assertEquals(p, s.getPredicate()); - Assert.assertEquals(123.456f, s.getFloat(), 0.0005); + assertEquals(r, s.getSubject()); + assertEquals(p, s.getPredicate()); + assertEquals(123.456f, s.getFloat(), 0.0005); } + @Test public void testCreateStatementIntMax() { final Statement s = model.createLiteralStatement(r, p, Integer.MAX_VALUE); - Assert.assertEquals(r, s.getSubject()); - Assert.assertEquals(p, s.getPredicate()); - Assert.assertEquals(Integer.MAX_VALUE, s.getInt()); + assertEquals(r, s.getSubject()); + assertEquals(p, s.getPredicate()); + assertEquals(Integer.MAX_VALUE, s.getInt()); } + @Test public void testCreateStatementLongMax() { final Statement s = model.createLiteralStatement(r, p, Long.MAX_VALUE); - Assert.assertEquals(r, s.getSubject()); - Assert.assertEquals(p, s.getPredicate()); - Assert.assertEquals(Long.MAX_VALUE, s.getLong()); + assertEquals(r, s.getSubject()); + assertEquals(p, s.getPredicate()); + assertEquals(Long.MAX_VALUE, s.getLong()); } + @Test public void testCreateStatementResource() { final Resource tv = model.createResource(); final Statement s = model.createStatement(r, p, tv); - Assert.assertEquals(r, s.getSubject()); - Assert.assertEquals(p, s.getPredicate()); - Assert.assertEquals(tv, s.getResource()); + assertEquals(r, s.getSubject()); + assertEquals(p, s.getPredicate()); + assertEquals(tv, s.getResource()); } + @Test public void testCreateStatementShortMax() { final Statement s = model.createLiteralStatement(r, p, Short.MAX_VALUE); - Assert.assertEquals(r, s.getSubject()); - Assert.assertEquals(p, s.getPredicate()); - Assert.assertEquals(Short.MAX_VALUE, s.getShort()); + assertEquals(r, s.getSubject()); + assertEquals(p, s.getPredicate()); + assertEquals(Short.MAX_VALUE, s.getShort()); } + @Test public void testCreateStatementString() { final String string = "this is a plain string", lang = "en"; final Statement s = model.createStatement(r, p, string); - Assert.assertEquals(r, s.getSubject()); - Assert.assertEquals(p, s.getPredicate()); - Assert.assertEquals(string, s.getString()); - Assert.assertEquals(lang, model.createStatement(r, p, string, lang).getLanguage()); + assertEquals(r, s.getSubject()); + assertEquals(p, s.getPredicate()); + assertEquals(string, s.getString()); + assertEquals(lang, model.createStatement(r, p, string, lang).getLanguage()); } + @Test public void testCreateStatementTrue() { final Statement s = model.createLiteralStatement(r, p, true); - Assert.assertEquals(r, s.getSubject()); - Assert.assertEquals(p, s.getPredicate()); - Assert.assertEquals(true, s.getBoolean()); + assertEquals(r, s.getSubject()); + assertEquals(p, s.getPredicate()); + assertEquals(true, s.getBoolean()); } + @Test public void testCreateStatementTypeLiteral() { final Model model = ModelFactory.createDefaultModel(); final Resource R = model.createResource("http://example/r"); final Property P = model.createProperty("http://example/p"); model.add(R, P, "2", XSDDatatype.XSDinteger); final Literal L = ResourceFactory.createTypedLiteral("2", XSDDatatype.XSDinteger); - Assert.assertTrue(model.contains(R, P, L)); - Assert.assertFalse(model.contains(R, P, "2")); + assertTrue(model.contains(R, P, L)); + assertFalse(model.contains(R, P, "2")); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementMethods.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementMethods.java index 44055c79f84..f540f753ba4 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementMethods.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementMethods.java @@ -21,28 +21,31 @@ package org.apache.jena.rdf.model; -import org.apache.jena.rdf.model.helpers.ModelCreator; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.test.JenaTestLib; import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestStatementMethods extends AbstractModelTestBase { protected Resource r; - public TestStatementMethods(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } - protected void checkChangedStatementSP(final Statement changed) { - Assert.assertEquals(r, changed.getSubject()); - Assert.assertEquals(RDF.value, changed.getPredicate()); + assertEquals(r, changed.getSubject()); + assertEquals(RDF.value, changed.getPredicate()); } protected void checkCorrectStatements(final Statement sTrue, final Statement changed) { - Assert.assertFalse(model.contains(sTrue)); - Assert.assertFalse(model.containsLiteral(r, RDF.value, true)); - Assert.assertTrue(model.contains(changed)); + assertFalse(model.contains(sTrue)); + assertFalse(model.containsLiteral(r, RDF.value, true)); + assertTrue(model.contains(changed)); } protected Statement loadInitialStatement() { @@ -52,210 +55,235 @@ protected Statement loadInitialStatement() { } @Override + @BeforeEach public void setUp() { super.setUp(); r = model.createResource(); } + @Test public void testAlt() { final Alt tvAlt = model.createAlt(); - Assert.assertEquals(tvAlt, model.createStatement(r, RDF.value, tvAlt).getAlt()); + assertEquals(tvAlt, model.createStatement(r, RDF.value, tvAlt).getAlt()); } + @Test public void testBag() { final Bag tvBag = model.createBag(); - Assert.assertEquals(tvBag, model.createStatement(r, RDF.value, tvBag).getBag()); + assertEquals(tvBag, model.createStatement(r, RDF.value, tvBag).getBag()); } + @Test public void testBoolean() { final Statement s = model.createLiteralStatement(r, RDF.value, true); - Assert.assertEquals(model.createTypedLiteral(true), s.getObject()); - Assert.assertEquals(true, s.getBoolean()); + assertEquals(model.createTypedLiteral(true), s.getObject()); + assertEquals(true, s.getBoolean()); } + @Test public void testByte() { final Statement s = model.createLiteralStatement(r, RDF.value, AbstractModelTestBase.tvByte); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvByte), s.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvByte, s.getLong()); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvByte), s.getObject()); + assertEquals(AbstractModelTestBase.tvByte, s.getLong()); } + @Test public void testChangeObjectBoolean() { final Statement sTrue = loadInitialStatement(); final Statement sFalse = sTrue.changeLiteralObject(false); checkChangedStatementSP(sFalse); - Assert.assertEquals(model.createTypedLiteral(false), sFalse.getObject()); - Assert.assertEquals(false, sFalse.getBoolean()); + assertEquals(model.createTypedLiteral(false), sFalse.getObject()); + assertEquals(false, sFalse.getBoolean()); checkCorrectStatements(sTrue, sFalse); - Assert.assertTrue(model.containsLiteral(r, RDF.value, false)); + assertTrue(model.containsLiteral(r, RDF.value, false)); } + @Test public void testChangeObjectByte() { final Statement sTrue = loadInitialStatement(); final Statement changed = sTrue.changeLiteralObject(AbstractModelTestBase.tvByte); checkChangedStatementSP(changed); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvByte), changed.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvByte, changed.getByte()); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvByte), changed.getObject()); + assertEquals(AbstractModelTestBase.tvByte, changed.getByte()); checkCorrectStatements(sTrue, changed); - Assert.assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvByte)); + assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvByte)); } + @Test public void testChangeObjectChar() { final Statement sTrue = loadInitialStatement(); final Statement changed = sTrue.changeLiteralObject(AbstractModelTestBase.tvChar); checkChangedStatementSP(changed); - Assert.assertEquals(AbstractModelTestBase.tvChar, changed.getChar()); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvChar), changed.getObject()); + assertEquals(AbstractModelTestBase.tvChar, changed.getChar()); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvChar), changed.getObject()); checkCorrectStatements(sTrue, changed); - Assert.assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvChar)); + assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvChar)); } + @Test public void testChangeObjectDouble() { final Statement sTrue = loadInitialStatement(); final Statement changed = sTrue.changeLiteralObject(AbstractModelTestBase.tvDouble); checkChangedStatementSP(changed); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvDouble), changed.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvDouble, changed.getDouble(), AbstractModelTestBase.dDelta); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvDouble), changed.getObject()); + assertEquals(AbstractModelTestBase.tvDouble, changed.getDouble(), AbstractModelTestBase.dDelta); checkCorrectStatements(sTrue, changed); - Assert.assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvDouble)); + assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvDouble)); } + @Test public void testChangeObjectFloat() { final Statement sTrue = loadInitialStatement(); final Statement changed = sTrue.changeLiteralObject(AbstractModelTestBase.tvFloat); checkChangedStatementSP(changed); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvFloat), changed.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvFloat, changed.getFloat(), AbstractModelTestBase.fDelta); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvFloat), changed.getObject()); + assertEquals(AbstractModelTestBase.tvFloat, changed.getFloat(), AbstractModelTestBase.fDelta); checkCorrectStatements(sTrue, changed); - Assert.assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvFloat)); + assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvFloat)); } + @Test public void testChangeObjectInt() { final Statement sTrue = loadInitialStatement(); final Statement changed = sTrue.changeLiteralObject(AbstractModelTestBase.tvInt); checkChangedStatementSP(changed); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvInt), changed.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvInt, changed.getInt()); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvInt), changed.getObject()); + assertEquals(AbstractModelTestBase.tvInt, changed.getInt()); checkCorrectStatements(sTrue, changed); - Assert.assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvInt)); + assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvInt)); } + @Test public void testChangeObjectLiteral() { final Statement sTrue = loadInitialStatement(); model.remove(sTrue); - Assert.assertFalse(model.contains(sTrue)); - Assert.assertFalse(model.containsLiteral(r, RDF.value, true)); + assertFalse(model.contains(sTrue)); + assertFalse(model.containsLiteral(r, RDF.value, true)); } // public void testResObj() // { // Resource tvResObj = model.createResource( new ResTestObjF() ); - // assertEquals( tvResObj, model.createStatement( r, RDF.value, tvResObj + // assertEquals(tvResObj, model.createStatement( r, RDF.value, tvResObj // ).getResource() ); // } // public void testLitObj() // { - // assertEquals( tvLitObj, model.createLiteralStatement( r, RDF.value, + // assertEquals(tvLitObj, model.createLiteralStatement( r, RDF.value, // tvLitObj ).getObject( new LitTestObjF() ) ); // } + @Test public void testChangeObjectLong() { final Statement sTrue = loadInitialStatement(); final Statement changed = sTrue.changeLiteralObject(AbstractModelTestBase.tvLong); checkChangedStatementSP(changed); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvLong), changed.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvLong, changed.getLong()); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvLong), changed.getObject()); + assertEquals(AbstractModelTestBase.tvLong, changed.getLong()); checkCorrectStatements(sTrue, changed); - Assert.assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvLong)); + assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvLong)); } + @Test public void testChangeObjectShort() { final Statement sTrue = loadInitialStatement(); final Statement changed = sTrue.changeLiteralObject(AbstractModelTestBase.tvShort); checkChangedStatementSP(changed); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvShort), changed.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvShort, changed.getShort()); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvShort), changed.getObject()); + assertEquals(AbstractModelTestBase.tvShort, changed.getShort()); checkCorrectStatements(sTrue, changed); - Assert.assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvShort)); + assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvShort)); } + @Test public void testChangeObjectString() { final Statement sTrue = loadInitialStatement(); final Statement changed = sTrue.changeObject(AbstractModelTestBase.tvString); checkChangedStatementSP(changed); - Assert.assertEquals(AbstractModelTestBase.tvString, changed.getString()); + assertEquals(AbstractModelTestBase.tvString, changed.getString()); checkCorrectStatements(sTrue, changed); - Assert.assertTrue(model.contains(r, RDF.value, AbstractModelTestBase.tvString)); + assertTrue(model.contains(r, RDF.value, AbstractModelTestBase.tvString)); } + @Test public void testChangeObjectStringWithLanguage() { final String lang = "en"; final Statement sTrue = loadInitialStatement(); final Statement changed = sTrue.changeObject(AbstractModelTestBase.tvString, lang); checkChangedStatementSP(changed); - Assert.assertEquals(AbstractModelTestBase.tvString, changed.getString()); - Assert.assertEquals(lang, changed.getLanguage()); + assertEquals(AbstractModelTestBase.tvString, changed.getString()); + assertEquals(lang, changed.getLanguage()); checkCorrectStatements(sTrue, changed); - Assert.assertTrue(model.contains(r, RDF.value, AbstractModelTestBase.tvString, lang)); + assertTrue(model.contains(r, RDF.value, AbstractModelTestBase.tvString, lang)); } + @Test public void testChangeObjectYByte() { final Statement sTrue = loadInitialStatement(); final Statement changed = sTrue.changeLiteralObject(AbstractModelTestBase.tvByte); checkChangedStatementSP(changed); - Assert.assertEquals(AbstractModelTestBase.tvByte, changed.getByte()); + assertEquals(AbstractModelTestBase.tvByte, changed.getByte()); checkCorrectStatements(sTrue, changed); - Assert.assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvByte)); + assertTrue(model.containsLiteral(r, RDF.value, AbstractModelTestBase.tvByte)); } + @Test public void testChar() { final Statement s = model.createLiteralStatement(r, RDF.value, AbstractModelTestBase.tvChar); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvChar), s.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvChar, s.getChar()); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvChar), s.getObject()); + assertEquals(AbstractModelTestBase.tvChar, s.getChar()); } + @Test public void testDouble() { final Statement s = model.createLiteralStatement(r, RDF.value, AbstractModelTestBase.tvDouble); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvDouble), s.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvDouble, s.getDouble(), AbstractModelTestBase.dDelta); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvDouble), s.getObject()); + assertEquals(AbstractModelTestBase.tvDouble, s.getDouble(), AbstractModelTestBase.dDelta); } + @Test public void testFloat() { final Statement s = model.createLiteralStatement(r, RDF.value, AbstractModelTestBase.tvFloat); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvFloat), s.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvFloat, s.getFloat(), AbstractModelTestBase.fDelta); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvFloat), s.getObject()); + assertEquals(AbstractModelTestBase.tvFloat, s.getFloat(), AbstractModelTestBase.fDelta); } + @Test public void testGetLiteralFailure() { try { model.createStatement(r, RDF.value, r).getLiteral(); - Assert.fail("should trap non-literal object"); + fail("should trap non-literal object"); } catch (final LiteralRequiredException e) { JenaTestLib.pass(); } } + @Test public void testGetResource() { - Assert.assertEquals(r, model.createStatement(r, RDF.value, r).getResource()); + assertEquals(r, model.createStatement(r, RDF.value, r).getResource()); } + @Test public void testGetResourceFailure() { try { model.createLiteralStatement(r, RDF.value, false).getResource(); - Assert.fail("should trap non-resource object"); + fail("should trap non-resource object"); } catch (final ResourceRequiredException e) { JenaTestLib.pass(); } } + @Test public void testGetTrueBoolean() { - Assert.assertEquals(true, model.createLiteralStatement(r, RDF.value, true).getLiteral().getBoolean()); + assertEquals(true, model.createLiteralStatement(r, RDF.value, true).getLiteral().getBoolean()); } + @Test public void testInt() { final Statement s = model.createLiteralStatement(r, RDF.value, AbstractModelTestBase.tvInt); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvInt), s.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvInt, s.getInt()); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvInt), s.getObject()); + assertEquals(AbstractModelTestBase.tvInt, s.getInt()); } // public void testChangeObjectResObject() @@ -264,37 +292,42 @@ public void testInt() { // Statement sTrue = loadInitialStatement(); // Statement changed = sTrue.changeObject( tvResObj ); // checkChangedStatementSP( changed ); - // assertEquals( tvResObj, changed.getResource() ); + // assertEquals(tvResObj, changed.getResource() ); // checkCorrectStatements( sTrue, changed ); - // assertTrue( model.contains( r, RDF.value, tvResObj ) ); + // assertTrue(model.contains( r, RDF.value, tvResObj ) ); // } + @Test public void testLong() { final Statement s = model.createLiteralStatement(r, RDF.value, AbstractModelTestBase.tvLong); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvLong), s.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvLong, s.getLong()); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvLong), s.getObject()); + assertEquals(AbstractModelTestBase.tvLong, s.getLong()); } + @Test public void testSeq() { final Seq tvSeq = model.createSeq(); - Assert.assertEquals(tvSeq, model.createStatement(r, RDF.value, tvSeq).getSeq()); + assertEquals(tvSeq, model.createStatement(r, RDF.value, tvSeq).getSeq()); } + @Test public void testShort() { final Statement s = model.createLiteralStatement(r, RDF.value, AbstractModelTestBase.tvShort); - Assert.assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvShort), s.getObject()); - Assert.assertEquals(AbstractModelTestBase.tvShort, s.getShort()); + assertEquals(model.createTypedLiteral(AbstractModelTestBase.tvShort), s.getObject()); + assertEquals(AbstractModelTestBase.tvShort, s.getShort()); } + @Test public void testString() { - Assert.assertEquals(AbstractModelTestBase.tvString, + assertEquals(AbstractModelTestBase.tvString, model.createStatement(r, RDF.value, AbstractModelTestBase.tvString).getString()); } + @Test public void testStringWithLanguage() { final String lang = "fr"; - Assert.assertEquals(AbstractModelTestBase.tvString, + assertEquals(AbstractModelTestBase.tvString, model.createStatement(r, RDF.value, AbstractModelTestBase.tvString, lang).getString()); - Assert.assertEquals(lang, model.createStatement(r, RDF.value, AbstractModelTestBase.tvString, lang).getLanguage()); + assertEquals(lang, model.createStatement(r, RDF.value, AbstractModelTestBase.tvString, lang).getLanguage()); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementTerms.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementTerms.java index fa7a1b21f83..3e74eba2a70 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementTerms.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatementTerms.java @@ -21,17 +21,20 @@ package org.apache.jena.rdf.model; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.vocabulary.RDF; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestStatementTerms extends AbstractModelTestBase { - public TestStatementTerms(ModelCreator modelFactory, String name) { - super(modelFactory, name); - } + @Test public void testStatementTerms() { String fakeURI = "fake:URI"; Resource S = model.createResource(); @@ -39,14 +42,14 @@ public void testStatementTerms() { RDFNode O = model.createTypedLiteral("42", fakeURI); Statement stmt = model.createStatement(S, P, O); - Assert.assertTrue(model.isEmpty()); + assertTrue(model.isEmpty()); StatementTerm stmtTerm = model.createStatementTerm(stmt); - Assert.assertTrue(model.isEmpty()); + assertTrue(model.isEmpty()); - Assert.assertEquals(S, stmtTerm.getStatement().getSubject()); - Assert.assertEquals(P, stmtTerm.getStatement().getPredicate()); - Assert.assertEquals(O, stmtTerm.getStatement().getObject()); + assertEquals(S, stmtTerm.getStatement().getSubject()); + assertEquals(P, stmtTerm.getStatement().getPredicate()); + assertEquals(O, stmtTerm.getStatement().getObject()); } private static StatementTerm create(Model model) { @@ -60,6 +63,7 @@ private static StatementTerm create(Model model) { return stmtTerm; } + @Test public void testStatementReifierAnon() { String fakeURI = "fake:URI"; Resource S = model.createResource(); @@ -68,21 +72,22 @@ public void testStatementReifierAnon() { Statement stmt = model.createStatement(S, P, O); Resource r = model.createReifier(stmt); - Assert.assertFalse(model.isEmpty()); - Assert.assertEquals(1, model.size()); + assertFalse(model.isEmpty()); + assertEquals(1, model.size()); Statement s = model.listStatements().next(); RDFNode x = s.getObject(); - Assert.assertTrue(s.getSubject().isAnon()); - Assert.assertTrue(s.getPredicate().equals(RDF.reifies)); - Assert.assertTrue(s.getObject().isStatementTerm()); + assertTrue(s.getSubject().isAnon()); + assertTrue(s.getPredicate().equals(RDF.reifies)); + assertTrue(s.getObject().isStatementTerm()); StatementTerm st = s.getObject().asStatementTerm(); - Assert.assertTrue(st != null); - Assert.assertEquals(st.getStatement(), stmt); + assertTrue(st != null); + assertEquals(st.getStatement(), stmt); } + @Test public void testStatementReifierResource() { String fakeURI = "fake:URI"; String reifURI = "reifier:URI"; @@ -95,13 +100,13 @@ public void testStatementReifierResource() { Statement stmt = model.createStatement(S, P, O); Resource r = model.createReifier(reifier, stmt); - Assert.assertEquals(reifURI, r.getURI()); + assertEquals(reifURI, r.getURI()); - Assert.assertFalse(model.isEmpty()); - Assert.assertEquals(1, model.size()); + assertFalse(model.isEmpty()); + assertEquals(1, model.size()); StatementTerm st = r.getProperty(RDF.reifies).getObject().asStatementTerm(); - Assert.assertTrue(st != null); - Assert.assertEquals(st.getStatement(), stmt); + assertTrue(st != null); + assertEquals(st.getStatement(), stmt); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatements.java b/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatements.java index caf45aecc60..6ff2deb2174 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatements.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/TestStatements.java @@ -21,18 +21,22 @@ package org.apache.jena.rdf.model; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + import org.apache.jena.graph.FrontsTriple; -import org.apache.jena.rdf.model.helpers.ModelCreator; import org.apache.jena.rdf.model.helpers.ModelHelper; import org.apache.jena.test.JenaTestLib; import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.rdf.model.helpers.ModelCreators#creators") public class TestStatements extends AbstractModelTestBase { - public TestStatements(ModelCreator modelFactory, final String name) { - super(modelFactory, name); - } + @Test public void testOtherStuff() { final Model A = createModel(); final Model B = createModel(); @@ -42,33 +46,35 @@ public void testOtherStuff() { final RDFNode O = A.createResource("jena:O"); A.add(S, P, O); B.add(S, P, O); - Assert.assertTrue("X1", A.isIsomorphicWith(B)); + assertTrue(A.isIsomorphicWith(B), "X1"); /* */ A.add(R, RDF.subject, S); B.add(R, RDF.predicate, P); - Assert.assertFalse("X2", A.isIsomorphicWith(B)); + assertFalse(A.isIsomorphicWith(B), "X2"); /* */ A.add(R, RDF.predicate, P); B.add(R, RDF.subject, S); - Assert.assertTrue("X3", A.isIsomorphicWith(B)); + assertTrue(A.isIsomorphicWith(B), "X3"); /* */ A.add(R, RDF.object, O); B.add(R, RDF.type, RDF.Statement); - Assert.assertFalse("X4", A.isIsomorphicWith(B)); + assertFalse(A.isIsomorphicWith(B), "X4"); /* */ A.add(R, RDF.type, RDF.Statement); B.add(R, RDF.object, O); - Assert.assertTrue("X5", A.isIsomorphicWith(B)); + assertTrue(A.isIsomorphicWith(B), "X5"); } + @Test public void testPortingBlankNodes() { final Model B = createModel(); final Resource anon = model.createResource(); final Resource bAnon = anon.inModel(B); - Assert.assertTrue("moved resource should still be blank", bAnon.isAnon()); - Assert.assertEquals("move resource should equal original", anon, bAnon); + assertTrue(bAnon.isAnon(), "moved resource should still be blank"); + assertEquals(anon, bAnon, "move resource should equal original"); } + @Test public void testSet() { final Model A = createModel(); createModel(); @@ -79,29 +85,31 @@ public void testSet() { final Statement spo = A.createStatement(S, P, O); A.add(spo); final Statement sps = A.createStatement(S, P, S); - Assert.assertEquals(sps, spo.changeObject(S)); - Assert.assertFalse(A.contains(spo)); - Assert.assertTrue(A.contains(sps)); + assertEquals(sps, spo.changeObject(S)); + assertFalse(A.contains(spo)); + assertTrue(A.contains(sps)); } /** * Feeble test that toString'ing a Statement[Impl] will display the data-type of * its object if it has one. */ + @Test public void testStatementPrintsType() { final String fakeURI = "fake:URI"; final Resource S = model.createResource(); final Property P = ModelHelper.property(model, "PP"); final RDFNode O = model.createTypedLiteral("42", fakeURI); final Statement st = model.createStatement(S, P, O); - Assert.assertTrue(st.toString().indexOf(fakeURI) > 0); + assertTrue(st.toString().indexOf(fakeURI) > 0); } + @Test public void testStatmentMap1Selectors() { final Statement stmt = ModelHelper.statement("sub pred obj"); - Assert.assertEquals(ModelHelper.resource("sub"), stmt.getSubject()); - Assert.assertEquals(ModelHelper.resource("pred"), stmt.getPredicate()); - Assert.assertEquals(ModelHelper.resource("obj"), stmt.getObject()); + assertEquals(ModelHelper.resource("sub"), stmt.getSubject()); + assertEquals(ModelHelper.resource("pred"), stmt.getPredicate()); + assertEquals(ModelHelper.resource("obj"), stmt.getObject()); } /** @@ -109,16 +117,18 @@ public void testStatmentMap1Selectors() { * constructed by a different model should test equal to the resource extracted * from that statement, even if it's a bnode. */ + @Test public void testStuff() { final Model red = createModel(); final Model blue = createModel(); final Resource r = red.createResource(); final Property p = red.createProperty(""); final Statement s = blue.createStatement(r, p, r); - Assert.assertEquals("subject preserved", r, s.getSubject()); - Assert.assertEquals("object preserved", r, s.getObject()); + assertEquals(r, s.getSubject(), "subject preserved"); + assertEquals(r, s.getObject(), "object preserved"); } + @Test public void testTripleWrapper() { JenaTestLib.assertInstanceOf(FrontsTriple.class, ModelHelper.statement(model, "s p o")); } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelCreators.java b/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelCreators.java new file mode 100644 index 00000000000..cd5e4105b83 --- /dev/null +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelCreators.java @@ -0,0 +1,68 @@ +/* + * 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 + * + * https://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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.apache.jena.rdf.model.helpers; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.Named; +import org.junit.jupiter.params.provider.Arguments; + +import org.apache.jena.graph.Graph; +import org.apache.jena.graph.GraphMemFactory; +import org.apache.jena.graph.compose.Difference; +import org.apache.jena.graph.compose.Intersection; +import org.apache.jena.graph.compose.Union; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; + +/** + * The {@link ModelCreator}s that the {@code rdf.model} tests run against. + *

+ * The JUnit 3 suite built the whole package once per creator - once with + * {@link ModelCreator#plain} and three more times with the composition graphs. A + * parameterized test class covers all four in one place. + */ +public class ModelCreators { + + private static Model composed(Graph graph) { + return ModelFactory.createModelForGraph(graph); + } + + public static final ModelCreator plain = ModelCreator.plain; + + public static final ModelCreator intersection = + ()->composed(new Intersection(GraphMemFactory.createGraphMemForModel(), GraphMemFactory.createGraphMemForModel())); + + public static final ModelCreator difference = + ()->composed(new Difference(GraphMemFactory.createGraphMemForModel(), GraphMemFactory.createGraphMemForModel())); + + public static final ModelCreator union = + ()->composed(new Union(GraphMemFactory.createGraphMemForModel(), GraphMemFactory.createGraphMemForModel())); + + /** Argument source for {@code @ParameterizedClass} model tests. */ + public static Stream creators() { + return Stream.of(Arguments.of(Named.of("plain", plain)), + Arguments.of(Named.of("Intersection", intersection)), + Arguments.of(Named.of("Difference", difference)), + Arguments.of(Named.of("Union", union))); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java b/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java index 9422088c30b..c64a71b9f04 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java @@ -48,7 +48,6 @@ public class ModelHelper extends TestCase private ModelHelper(String name) { super(name); } - protected static Model aModel; static { @@ -58,13 +57,6 @@ private ModelHelper(String name) protected static final Model empty = ModelFactory.createDefaultModel(); - protected static Model extendedModel(AbstractModelTestBase base) - { - Model result = base.createModel(); - result.setNsPrefixes( PrefixMapping.Extended ); - return result; - } - protected static String nice( RDFNode n ) { return GraphTestLib.nice( n.asNode() ); } @@ -168,26 +160,6 @@ public static Model modelAdd( Model m, String facts ) return m; } - /** - makes a model with a given reiifcation style, initialised with statements parsed - from a string. - - @param facts a string in semicolon-separated "S P O" format - @return a model containing those facts - */ - public static Model modelWithStatements( AbstractModelTestBase base, String facts ) - { return modelAdd( createModel( base ), facts ); } - - /** - make a model and give it Extended prefixes - */ - public static Model createModel( AbstractModelTestBase base ) - { - Model result = base.createModel(); - result.setNsPrefixes( PrefixMapping.Extended ); - return result; - } - /** Answer a default model; it exists merely to abbreviate the rather long explicit invocation. diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java index 4810dd31220..3db97c36e45 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java @@ -51,7 +51,7 @@ static public TestSuite suite() { //JU6 addTest(ts, "MemValue", adaptJUnit4(org.apache.jena.memvalue.TS3_GraphMemValue.class)); // ** COMPLEX - addTest(ts, "Model1", org.apache.jena.rdf.model.TS3_Model1.suite()); +//JU6 addTest(ts, "Model1", org.apache.jena.rdf.model.TS3_Model1.suite()); // ** COMPLEX //JU6 addTest(ts, "Default Model", org.apache.jena.rdf.model.TestDefaultModel.suite()); @@ -68,7 +68,7 @@ static public TestSuite suite() { //JU6 addTest(ts, "Shared", adaptJUnit4(org.apache.jena.shared.TS_SharedPackage.class)); // ** COMPLEX - addTest(ts, "Composed graphs", org.apache.jena.graph.compose.TS3_compose.suite() ); +//JU6 addTest(ts, "Composed graphs", org.apache.jena.graph.compose.TS3_compose.suite() ); addTest(ts, "Reasoners", adaptJUnit4(org.apache.jena.reasoner.test.TS3_reasoners.class)); addTest(ts, "RuleReasoners", adaptJUnit4(org.apache.jena.reasoner.rulesys.TS3_RuleReasoners.class)); diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java index 22962c3246f..92020ee5ff8 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java @@ -27,6 +27,7 @@ import org.apache.jena.core_ttl.tests.TS6_TestTurtle; import org.apache.jena.datatypes.TS6_dt; +import org.apache.jena.graph.compose.TS6_compose; import org.apache.jena.enhanced.TS6_enh; import org.apache.jena.irix.TS6_IRIx2; import org.apache.jena.langtagx.TS6_LangTagX; @@ -66,6 +67,8 @@ TS6_Vocabularies.class, TS6_SharedPackage.class, + TS6_compose.class, + TS6_ModelMakers.class, TS6_ont.class, From 098b431e64dffe045d5b1de2360997cc10b6b31a Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Mon, 7 Sep 2026 16:57:02 +0100 Subject: [PATCH 06/12] .claude coding conventions --- .../java-coding-conventions.md | 61 ++++++++++++++++++ .../source-code-conventions.md | 64 +++++++++++++++++++ .../xml-formatting-conventions.md | 13 ++++ 3 files changed, 138 insertions(+) create mode 100644 .claude/skills/coding-conventions/java-coding-conventions.md create mode 100644 .claude/skills/coding-conventions/source-code-conventions.md create mode 100644 .claude/skills/coding-conventions/xml-formatting-conventions.md diff --git a/.claude/skills/coding-conventions/java-coding-conventions.md b/.claude/skills/coding-conventions/java-coding-conventions.md new file mode 100644 index 00000000000..78604c04837 --- /dev/null +++ b/.claude/skills/coding-conventions/java-coding-conventions.md @@ -0,0 +1,61 @@ +--- +name: java-coding-conventions +description: House style for writing and reviewing Java and XML code in this repository. Use this skill whenever you are writing new Java code, editing existing Java files, generating code samples in Java, reviewing or refactoring Java code, or touching XML files (pom.xml, etc.) in this repo. Enforces brace style, indentation, and Javadoc conventions specific to this codebase — apply automatically, don't wait for the user to ask about "style" or "conventions" explicitly. +--- + +# Java Coding Conventions + +House style for this repository. Apply these rules by default to every Java and XML file you write or edit here, without being asked each time. + +## Java rules + +### Indentation +- **4 spaces per indent level.** No tabs, anywhere, ever. +- Continuation lines (wrapped method args, chained calls, long expressions) indent by an extra 8 spaces (two levels) from the start of the statement, to visually distinguish them from a new block. + +### Braces — K&R "Egyptian brackets" +- The opening brace `{` stays on the **same line** as the declaration/statement, preceded by a single space. +- The closing brace `}` starts a new line, aligned with the start of the opening statement. +- `else`, `catch`, `finally` go on the **same line** as the preceding closing brace. +- Braces are **not required** for single-line, single statement ones. +- Braces are **required** for multi-line code blocks. + +```java +public class OrderService { + + public int computeTotal(List items) { + int total = 0; + for (Item item : items) { + if (item.isTaxable()) { + total += item.getPriceWithTax(); + } else { + total += item.getPrice(); + } + } + return total; + } + + public void process() { + try { + doWork(); + } catch (IOException e) { + log.error("Failed to process", e); + } finally { + cleanup(); + } + } +} +``` + +### Javadoc / comments +- **No `@author` tags**, in any file, ever — not on new files, not when editing old ones. If you encounter an existing `@author` tag while editing a file for another reason, leave it unless the user asks you to clean it up (don't do drive-by removals that bloat an unrelated diff). +- Javadoc is otherwise written normally: `/** ... */` blocks above public classes/methods, `@param`, `@return`, `@throws` as appropriate. + +### Other conventions (standard "common Java style" — flag deviations if you see them) +- One top-level public class per file, filename matches the class name. +- `UpperCamelCase` for classes/interfaces/enums, `lowerCamelCase` for methods/fields/variables, `UPPER_SNAKE_CASE` for constants. +- Opening brace of a class/method body counts as level 0; the first statement inside is indented one level (4 spaces) from the class/method declaration. +- Import order: standard groups (java.*, javax.*, third-party, then project packages), alphabetized within each group, with a blank line between groups. +- Imports: Use wildcard imports for packages with 5 or more class imports. +- Imports: Use wildcard static imports for 5 or more imports. +- Line length: wrap around 80–100 columns rather than let lines run on indefinitely diff --git a/.claude/skills/coding-conventions/source-code-conventions.md b/.claude/skills/coding-conventions/source-code-conventions.md new file mode 100644 index 00000000000..a3347812a4c --- /dev/null +++ b/.claude/skills/coding-conventions/source-code-conventions.md @@ -0,0 +1,64 @@ +--- +name: source-code-conventions +description: House style for writing and reviewing XML code in this repository. +--- + +## Source Code Conventions + +- Java must have a license header at the top of the file, followed by one blank line + +```java +/* + * 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 + * + * https://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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +``` + +- XML file must have a license header starting at the second line of the file +and followed by one blank line + +```xml + +``` + +- Shell Bash scripts should have a license header after the `#!` line and +followed by a blank line. + +``` +## Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0 +``` diff --git a/.claude/skills/coding-conventions/xml-formatting-conventions.md b/.claude/skills/coding-conventions/xml-formatting-conventions.md new file mode 100644 index 00000000000..0c039a4077c --- /dev/null +++ b/.claude/skills/coding-conventions/xml-formatting-conventions.md @@ -0,0 +1,13 @@ +--- +name: xml-formatting-conventions +description: House style for writing and reviewing XML code in this repository. +--- + +## XML Formatting Conventions + +- **2 spaces per indent level.** No tabs. +- One attribute per line only when a tag has many attributes and would otherwise run long; short tags keep attributes inline. +- Self-closing tags (``) for elements with no children/content. +- Closing tags aligned with the indentation level of their opening tag. + +(Note: keep XML indentation at 2 spaces even though Java in the same repo uses 4 — they're intentionally different.) From 3d21b04ed9242aac8527f3c16f2d072b07a7db7f Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Mon, 7 Sep 2026 17:33:19 +0100 Subject: [PATCH 07/12] GH-3236: Recover TestNodeToTriplesMapMem --- .../test/java/org/apache/jena/memvalue/TS6_GraphMemValue.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jena-core/src/test/java/org/apache/jena/memvalue/TS6_GraphMemValue.java b/jena-core/src/test/java/org/apache/jena/memvalue/TS6_GraphMemValue.java index e887cff46a3..6237a5abcb1 100644 --- a/jena-core/src/test/java/org/apache/jena/memvalue/TS6_GraphMemValue.java +++ b/jena-core/src/test/java/org/apache/jena/memvalue/TS6_GraphMemValue.java @@ -33,6 +33,8 @@ TestGraphMemModel.class, TestGraphTripleStoreMem.class, + TestNodeToTriplesMapMem.class, + TestConcurrentModificationException.TestArrayBunchCME.class, TestConcurrentModificationException.TestHashedBunchCME.class, From cc213b899355384bc1390ce2e44a1212de511f17 Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Mon, 7 Sep 2026 18:03:53 +0100 Subject: [PATCH 08/12] GH-3236: Convert jena.graph to JUnit6 --- ...eTestGraph_JU6.java => BaseTestGraph.java} | 4 +- .../org/apache/jena/graph/GraphCreators.java | 62 +++ .../org/apache/jena/graph/MetaTestGraph.java | 75 +-- .../graph/{TS3_graph.java => TS6_graph.java} | 30 +- .../apache/jena/graph/TestCoreGraphUtil.java | 23 +- .../org/apache/jena/graph/TestDateTime.java | 25 +- .../org/apache/jena/graph/TestFactory.java | 12 +- .../apache/jena/graph/TestFindLiterals.java | 39 +- .../java/org/apache/jena/graph/TestGraph.java | 67 +-- .../jena/graph/TestGraphBaseToString.java | 25 +- .../apache/jena/graph/TestGraphEvents.java | 12 +- .../apache/jena/graph/TestGraphListener.java | 30 +- .../graph/TestGraphMatchWithInference.java | 17 +- .../org/apache/jena/graph/TestGraphPlain.java | 10 +- .../jena/graph/TestGraphPrefixMapping.java | 16 +- .../org/apache/jena/graph/TestGraphUtil.java | 4 +- .../graph/TestLiteralLabelSameValueAs.java | 12 +- .../apache/jena/graph/TestLiteralLabels.java | 26 +- .../java/org/apache/jena/graph/TestNode.java | 189 ++++--- .../jena/graph/TestNodeCreateStrings.java | 5 +- .../apache/jena/graph/TestNodeEdgeCases.java | 4 +- .../org/apache/jena/graph/TestNodeExtras.java | 20 +- .../jena/graph/TestRDFStringLiterals.java | 79 +-- .../jena/graph/TestRegisterGraphListener.java | 16 +- .../org/apache/jena/graph/TestReifier.java | 101 ++-- .../org/apache/jena/graph/TestTriple.java | 43 +- .../apache/jena/graph/TestTripleField.java | 26 +- .../apache/jena/graph/TestTypedLiterals.java | 364 +++++++------ .../compose/AbstractTestPrefixMapping.java | 79 ++- .../AbstractTestPrefixMapping_JU6.java | 510 ------------------ .../apache/jena/graph/compose/TestDelta.java | 4 +- .../apache/jena/graph/compose/TestDyadic.java | 4 +- .../jena/graph/compose/TestMultiUnion.java | 4 +- .../compose/TestPolyadicPrefixMapping.java | 2 +- .../jena/memvalue/TestGraphMemModel.java | 2 +- .../jena/ontology/impl/TestOntGraph.java | 4 +- .../test}/AbstractTestGraph.java | 18 +- .../jena/reasoner/test/TestInfGraph.java | 1 - .../apache/jena/test/JenaCoreTestAll_JU4.java | 2 +- .../apache/jena/test/JenaCoreTestAll_JU6.java | 3 + 40 files changed, 814 insertions(+), 1155 deletions(-) rename jena-core/src/test/java/org/apache/jena/graph/{BaseTestGraph_JU6.java => BaseTestGraph.java} (99%) create mode 100644 jena-core/src/test/java/org/apache/jena/graph/GraphCreators.java rename jena-core/src/test/java/org/apache/jena/graph/{TS3_graph.java => TS6_graph.java} (75%) delete mode 100644 jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping_JU6.java rename jena-core/src/test/java/org/apache/jena/{graph => reasoner/test}/AbstractTestGraph.java (97%) diff --git a/jena-core/src/test/java/org/apache/jena/graph/BaseTestGraph_JU6.java b/jena-core/src/test/java/org/apache/jena/graph/BaseTestGraph.java similarity index 99% rename from jena-core/src/test/java/org/apache/jena/graph/BaseTestGraph_JU6.java rename to jena-core/src/test/java/org/apache/jena/graph/BaseTestGraph.java index a2a3682f334..910784b4c98 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/BaseTestGraph_JU6.java +++ b/jena-core/src/test/java/org/apache/jena/graph/BaseTestGraph.java @@ -40,7 +40,7 @@ import org.apache.jena.util.iterator.ClosableIterator; import org.apache.jena.util.iterator.ExtendedIterator; -public abstract class BaseTestGraph_JU6 { +public abstract class BaseTestGraph { /** * Returns a Graph to take part in the test. Must be overridden in a subclass. @@ -881,7 +881,7 @@ private void testIsomorphismXMLFile(int i, boolean result) { private InputStream getInputStream(int n, int n2, String suffix) { String urlStr = String.format("regression/testModelEquals/%s-%s.%s", n, n2, suffix); - return BaseTestGraph_JU6.class.getClassLoader().getResourceAsStream(urlStr); + return BaseTestGraph.class.getClassLoader().getResourceAsStream(urlStr); } private void testIsomorphismFile(int n, String lang, String suffix, boolean result) { diff --git a/jena-core/src/test/java/org/apache/jena/graph/GraphCreators.java b/jena-core/src/test/java/org/apache/jena/graph/GraphCreators.java new file mode 100644 index 00000000000..13d94bc0987 --- /dev/null +++ b/jena-core/src/test/java/org/apache/jena/graph/GraphCreators.java @@ -0,0 +1,62 @@ +/* + * 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 + * + * https://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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.apache.jena.graph; + +import java.util.function.Supplier; +import java.util.stream.Stream; + +import org.junit.jupiter.api.Named; +import org.junit.jupiter.params.provider.Arguments; + +import org.apache.jena.graph.impl.WrappedGraph; +import org.apache.jena.mem.GraphMemFast; +import org.apache.jena.mem.GraphMemLegacy; +import org.apache.jena.mem.GraphMemRoaring; +import org.apache.jena.memvalue.GraphMemValue; + +/** + * The graph implementations the general graph tests run against. + *

+ * The JUnit 3 suite built one test case per test method per implementation, by + * reflection. A parameterized test class covers all five in one place. + */ +@SuppressWarnings("deprecation") +public class GraphCreators { + + private static Arguments named(String name, Supplier maker) { + return Arguments.of(Named.of(name, maker)); + } + + /** The five implementations the general graph tests are run against. */ + public static Stream graphs() { + return Stream.of(named("GraphMemValue", GraphMemValue::new), + named("WrappedGraphMem", ()->new WrappedGraph(GraphMemFactory.createDefaultGraph())), + named("GraphMemFast", GraphMemFast::new), + named("GraphMemLegacy", GraphMemLegacy::new), + named("GraphMemRoaring", GraphMemRoaring::new)); + } + + /** Just {@code GraphMemFast} - the implementation {@link TestGraphListener} uses for its copy. */ + public static Stream graphMemFast() { + return Stream.of(named("GraphMemFast", GraphMemFast::new)); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/graph/MetaTestGraph.java b/jena-core/src/test/java/org/apache/jena/graph/MetaTestGraph.java index 67d537135d2..007f9cd4919 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/MetaTestGraph.java +++ b/jena-core/src/test/java/org/apache/jena/graph/MetaTestGraph.java @@ -21,76 +21,25 @@ package org.apache.jena.graph; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; +import java.util.function.Supplier; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.jena.shared.JenaException; -import org.apache.jena.test.JenaTestLib; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; /** - * MetaTestGraph + * Runs the general graph contract ({@link BaseTestGraph}) against each of the graph + * implementations supplied by {@link GraphCreators#graphs}. */ -public class MetaTestGraph extends AbstractTestGraph { - protected final Class graphClass; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.graph.GraphCreators#graphs") +public class MetaTestGraph extends BaseTestGraph { - public MetaTestGraph(Class graphClass, String name) { - super(name); - this.graphClass = graphClass; - } - - public MetaTestGraph(String name) { - super(name); - graphClass = null; - } - - /** - * Construct a suite of tests from the test class testClass by - * instantiating it three times, once each for the three reification styles, and - * applying it to the graph graphClass. - */ - public static TestSuite suite(Class testClass, Class graphClass) { - TestSuite result = new TestSuite(); - result.addTest(suiteX(testClass, graphClass)); - result.setName("Meta " + testClass.getName()); - return result; - } - - public static TestSuite suiteX(Class testClass, Class graphClass) { - TestSuite result = new TestSuite(); - for ( Class c = testClass ; Test.class.isAssignableFrom(c) ; c = c.getSuperclass() ) { - Method[] methods = c.getDeclaredMethods(); - addTestMethods(result, testClass, methods, graphClass); - } - result.setName(testClass.getName()); - return result; - } - - public static void addTestMethods(TestSuite result, Class testClass, Method[] methods, - Class graphClass) { - for ( Method method : methods ) { - if ( JenaTestLib.isPublicTestMethod(method) ) { - result.addTest(makeTest(testClass, graphClass, method.getName())); - } - } - } - - public static TestCase makeTest(Class testClass, Class graphClass, String name) { - Constructor cons = JenaTestLib.getConstructor(testClass, new Class[]{Class.class, String.class}); - if ( cons == null ) - throw new JenaException("cannot find MetaTestGraph constructor"); - try { - return (TestCase)cons.newInstance(new Object[]{graphClass, name}); - } catch (Exception e) { - throw new JenaException(e); - } - } + @Parameter + protected Supplier graphMaker; @Override public Graph getNewGraph() { - return GraphTestLib.getGraph(this, graphClass); + return graphMaker.get(); } - } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TS3_graph.java b/jena-core/src/test/java/org/apache/jena/graph/TS6_graph.java similarity index 75% rename from jena-core/src/test/java/org/apache/jena/graph/TS3_graph.java rename to jena-core/src/test/java/org/apache/jena/graph/TS6_graph.java index cb5e5715066..8b01f3f8135 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TS3_graph.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TS6_graph.java @@ -21,11 +21,19 @@ package org.apache.jena.graph; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.junit.platform.suite.api.BeforeSuite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; + +import org.apache.jena.test.JenaTestLib; + +@Suite +@SelectClasses({ + // Parameterized over GraphCreators.graphs(). + MetaTestGraph.class, + TestReifier.class, + TestGraphListener.class, -@RunWith(Suite.class) -@Suite.SuiteClasses( { TestFindLiterals.class, TestLiteralLabels.class, TestLiteralLabelSameValueAs.class, @@ -33,7 +41,6 @@ TestNodeCreateStrings.class, TestTriple.class, TestTripleField.class, - TestReifier.class, TestTypedLiterals.class, TestDateTime.class, TestFactory.class, @@ -47,10 +54,13 @@ TestNodeExtras.class, TestRDFStringLiterals.class, TestNodeEdgeCases.class, - - // Has to be in a specific package. - org.apache.jena.graph.TestGraphUtil.class - + TestGraphUtil.class, + TestRegisterGraphListener.class }) -public class TS3_graph { } +public class TS6_graph { + @BeforeSuite + public static void beforeSuite() { + JenaTestLib.setup(); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestCoreGraphUtil.java b/jena-core/src/test/java/org/apache/jena/graph/TestCoreGraphUtil.java index d31aed767f7..954a4f32780 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestCoreGraphUtil.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestCoreGraphUtil.java @@ -21,19 +21,15 @@ package org.apache.jena.graph; -import junit.framework.*; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.impl.*; import org.apache.jena.util.iterator.*; -public class TestCoreGraphUtil extends TestCase +public class TestCoreGraphUtil { - public TestCoreGraphUtil(String name) - { super(name); } - - public static TestSuite suite() - { - return new TestSuite(TestCoreGraphUtil.class); - } private static class Bool { @@ -41,6 +37,7 @@ private static class Bool Bool( boolean value ) { this.value = value; } } + @Test public void testFindAll() { final Bool foundAll = new Bool( false ); @@ -48,14 +45,14 @@ public void testFindAll() { @Override public ExtendedIterator graphBaseFind( Triple t ) { - assertEquals( Node.ANY, t.getSubject() ); - assertEquals( Node.ANY, t.getPredicate() ); - assertEquals( Node.ANY, t.getObject() ); + assertEquals(Node.ANY, t.getSubject() ); + assertEquals(Node.ANY, t.getPredicate() ); + assertEquals(Node.ANY, t.getObject() ); foundAll.value = true; return null; } }; GraphUtil.findAll( mock ); - assertTrue( "find(ANY, ANY, ANY) called", foundAll.value ); + assertTrue(foundAll.value, "find(ANY, ANY, ANY) called"); } } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestDateTime.java b/jena-core/src/test/java/org/apache/jena/graph/TestDateTime.java index 99dc2bf0a04..f695a5de1e6 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestDateTime.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestDateTime.java @@ -21,37 +21,32 @@ package org.apache.jena.graph; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.io.StringReader; import java.io.StringWriter; import java.util.Calendar; import java.util.GregorianCalendar; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.datatypes.xsd.AbstractDateTime; import org.apache.jena.datatypes.xsd.XSDDatatype; import org.apache.jena.datatypes.xsd.XSDDateTime; import org.apache.jena.rdf.model.*; -import org.junit.Assert; /** * Tests behaviour of the AbstractDateTime support, specifically for comparison * operations. This complements the main tests in TestTypedLiterals. */ -public class TestDateTime extends TestCase { +public class TestDateTime { /** * Boilerplate for junit */ - public TestDateTime(String name) { - super(name); - } /** * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite(TestDateTime.class); - } static final XSDDateTime time0 = makeDateTime("2009-08-13T17:54:40.348Z"); static final XSDDateTime time1 = makeDateTime("2009-08-13T18:54:39Z"); @@ -70,6 +65,7 @@ static XSDDateTime makeDateTime(String time) { return (XSDDateTime)XSDDatatype.XSDdateTime.parse(time); } + @Test public void testXSDOrder() { assertEquals(time0.compare(time1), AbstractDateTime.LESS_THAN); assertEquals(time1.compare(time2), AbstractDateTime.LESS_THAN); @@ -87,6 +83,7 @@ public void testXSDOrder() { assertEquals(time5.compare(time10), AbstractDateTime.EQUAL); } + @Test public void testJavaOrder() { assertEquals(time0.compareTo(time1), AbstractDateTime.LESS_THAN); assertEquals(time1.compareTo(time2), AbstractDateTime.LESS_THAN); @@ -98,6 +95,7 @@ public void testJavaOrder() { assertEquals(time7.compareTo(time8), AbstractDateTime.LESS_THAN); } + @Test public void testRoundTripping1() { Model m = ModelFactory.createDefaultModel(); Property startTime = m.createProperty("http://jena.hpl.hp.com/test#startTime"); @@ -122,16 +120,19 @@ public void testRoundTripping1() { } // Test that the string and calendar versions are the same. + @Test public void testRoundTripping2() { // String lex = "2013-04-16T15:40:07.3Z"; testCalendarRT(1366126807300L); } + @Test public void testRoundTripping3() { // String lex = "2013-04-16T15:40:07.31Z"; testCalendarRT(1366126807310L); } + @Test public void testRoundTripping4() { // String lex = "2013-04-16T15:40:07.301Z"; testCalendarRT(1366126807301L); @@ -143,8 +144,8 @@ private static void testCalendarRT(long value) { Literal lit1 = ResourceFactory.createTypedLiteral(cal); Literal lit2 = ResourceFactory.createTypedLiteral(lit1.getLexicalForm(), lit1.getDatatype()); - Assert.assertEquals("equals: ", lit1, lit2); - Assert.assertEquals("hash code: ", lit1.hashCode(), lit2.hashCode()); + assertEquals(lit1, lit2, "equals: "); + assertEquals(lit1.hashCode(), lit2.hashCode(), "hash code: "); } } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestFactory.java b/jena-core/src/test/java/org/apache/jena/graph/TestFactory.java index 077a99b9049..35a0233a017 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestFactory.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestFactory.java @@ -21,17 +21,11 @@ package org.apache.jena.graph; -import junit.framework.*; +import org.junit.jupiter.api.Test; -public class TestFactory extends TestCase { - public TestFactory(String name) { - super(name); - } - - public static TestSuite suite() { - return new TestSuite(TestFactory.class); - } +public class TestFactory { + @Test public void testFactory() { GraphMemFactory.createDefaultGraph(); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestFindLiterals.java b/jena-core/src/test/java/org/apache/jena/graph/TestFindLiterals.java index 2d2b2001dba..3bbf4a44a68 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestFindLiterals.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestFindLiterals.java @@ -21,85 +21,95 @@ package org.apache.jena.graph; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.Set; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.atlas.iterator.Iter; import org.apache.jena.graph.impl.LiteralLabelFactory; import org.apache.jena.junit.NodeCreateUtils; -public class TestFindLiterals extends TestCase { - public TestFindLiterals(String name) { - super(name); - } +public class TestFindLiterals { - public static junit.framework.Test suite() { - return new TestSuite(TestFindLiterals.class); - } private void runTest(String graph, int size, String search, String results) { Graph g = GraphTestLib.graphWith(graph); Node literal = NodeCreateUtils.create(search); - assertEquals("graph has wrong size", size, g.size()); + assertEquals(size, g.size(), "graph has wrong size"); Set got = g.find(Node.ANY, Node.ANY, literal).mapWith(t -> t.getObject()).toSet(); assertEquals(GraphTestLib.nodeSet(results), got); } + @Test public void test01() { runTest("a P 'simple'", 1, "'simple'", "'simple'"); } + @Test public void test02() { runTest("a P 'simple'xsd:string", 1, "'simple'", "'simple'xsd:string"); } + @Test public void test03() { runTest("a P 'simple'", 1, "'simple'xsd:string", "'simple'"); } + @Test public void test04() { runTest("a P 'simple'xsd:string", 1, "'simple'xsd:string", "'simple'xsd:string"); } private final int expected = 1; // 2 for RDF 1.0 + @Test public void test05() { runTest("a P 'simple'; a P 'simple'xsd:string", expected, "'simple'", "'simple' 'simple'xsd:string"); } + @Test public void test06() { runTest("a P 'simple'; a P 'simple'xsd:string", expected, "'simple'xsd:string", "'simple' 'simple'xsd:string"); } + @Test public void test07() { runTest("a P 1", 1, "1", "1"); } + @Test public void test08() { runTest("a P '1'xsd:float", 1, "'1'xsd:float", "'1'xsd:float"); } + @Test public void test09() { runTest("a P '1'xsd:double", 1, "'1'xsd:double", "'1'xsd:double"); } + @Test public void test10() { runTest("a P '1'xsd:float", 1, "'1'xsd:float", "'1'xsd:float"); } + @Test public void test11() { runTest("a P '1.1'xsd:float", 1, "'1'xsd:float", ""); } + @Test public void test12() { runTest("a P '1'xsd:double", 1, "'1'xsd:int", ""); } + @Test public void test13() { runTest("a P 'abc'rdf:XMLLiteral", 1, "'abc'", ""); } + @Test public void test14() { runTest("a P 'abc'", 1, "'abc'rdf:XMLLiteral", ""); } @@ -107,34 +117,42 @@ public void test14() { // // floats & doubles are not compatible // + @Test public void test15() { runTest("a P '1'xsd:float", 1, "'1'xsd:double", ""); } + @Test public void test16() { runTest("a P '1'xsd:double", 1, "'1'xsd:float", ""); } + @Test public void test17() { runTest("a P 1", 1, "'1'", ""); } + @Test public void test18() { runTest("a P 1", 1, "'1'xsd:integer", "'1'xsd:integer"); } + @Test public void test19() { runTest("a P 1", 1, "'1'", ""); } + @Test public void test20() { runTest("a P '1'xsd:short", 1, "'1'xsd:integer", "'1'xsd:short"); } + @Test public void test21() { runTest("a P '1'xsd:int", 1, "'1'xsd:integer", "'1'xsd:int"); } + @Test public void testFloatVsDouble() { Node A = NodeCreateUtils.create("'1'xsd:float"); Node B = NodeCreateUtils.create("'1'xsd:double"); @@ -144,6 +162,7 @@ public void testFloatVsDouble() { } @SuppressWarnings("deprecation") + @Test public void testProgrammaticValues() { Node ab = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral((byte)42)); Node as = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral((short)42)); diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraph.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraph.java index 16bbccdd272..40da57fd5c2 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraph.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraph.java @@ -21,61 +21,24 @@ package org.apache.jena.graph; -/** - Tests that check GraphMem and WrappedGraph for correctness against the Graph - and reifier test suites. -*/ +import org.junit.jupiter.api.Test; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.graph.impl.WrappedGraph; -import org.apache.jena.mem.GraphMemFast; -import org.apache.jena.mem.GraphMemLegacy; -import org.apache.jena.mem.GraphMemRoaring; -import org.apache.jena.memvalue.GraphMemValue; - -@SuppressWarnings("deprecation") -public class TestGraph extends TestCase { - public TestGraph(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(TestGraph.class); - - result.addTest(suite(MetaTestGraph.class, GraphMemValue.class)); - result.addTest(suite(TestReifier.class, GraphMemValue.class)); - - result.addTest(suite(MetaTestGraph.class, WrappedGraphMem.class)); - result.addTest(suite(TestReifier.class, WrappedGraphMem.class)); - - result.addTest(suite(MetaTestGraph.class, GraphMemFast.class)); - result.addTest(suite(TestReifier.class, GraphMemFast.class)); - - result.addTest(suite(MetaTestGraph.class, GraphMemLegacy.class)); - result.addTest(suite(TestReifier.class, GraphMemLegacy.class)); - result.addTest(suite(MetaTestGraph.class, GraphMemRoaring.class)); - result.addTest(suite(TestReifier.class, GraphMemRoaring.class)); - - result.addTest(TestGraphListener.suite()); - result.addTestSuite(TestRegisterGraphListener.class); - return result; - } - - public static TestSuite suite(Class classWithTests, Class graphClass) { - return MetaTestGraph.suite(classWithTests, graphClass); - } +/** + * Tests that check GraphMem and WrappedGraph for correctness against the Graph + * and reifier test suites. + *

+ * The suites themselves are {@link MetaTestGraph}, {@link TestReifier} and + * {@link TestGraphListener}, parameterized over {@link GraphCreators#graphs}. + */ +public class TestGraph { /** * Trivial [incomplete] test that a Wrapped graph pokes through to the underlying * graph. */ + @Test public void testWrappedSame() { Graph m = GraphMemFactory.createDefaultGraph(); Graph w = new WrappedGraph(m); @@ -84,14 +47,4 @@ public void testWrappedSame() { GraphTestLib.graphAdd(w, "i write this; you read that"); GraphTestLib.assertIsomorphic(w, m); } - - /** - * Class to provide a constructor that produces a wrapper round a - * default choice of in-memory graph. - */ - public static class WrappedGraphMem extends WrappedGraph { - public WrappedGraphMem() { - super(GraphMemFactory.createDefaultGraph()); - } - } } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphBaseToString.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphBaseToString.java index dce640669e8..eed9dd3871d 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphBaseToString.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphBaseToString.java @@ -21,12 +21,15 @@ package org.apache.jena.graph; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import static org.apache.jena.graph.impl.GraphBase.TOSTRING_TRIPLE_BASE; import static org.apache.jena.graph.impl.GraphBase.TOSTRING_TRIPLE_LIMIT; import java.util.*; -import junit.framework.TestCase; import org.apache.jena.graph.impl.GraphBase; import org.apache.jena.junit.NodeCreateUtils; import org.apache.jena.util.iterator.*; @@ -35,7 +38,7 @@ * Tests for the revisions to GraphBase.toString() to see that it's compact, ie * outputs no more than LIMIT triples. */ -public class TestGraphBaseToString extends TestCase { +public class TestGraphBaseToString { private static final class LittleGraphBase extends GraphBase { Set triples = new HashSet<>(); @@ -50,28 +53,28 @@ protected ExtendedIterator graphBaseFind(Triple m) { } } - public TestGraphBaseToString(String name) { - super(name); - } - + @Test public void testToStringBaseAndLimit() { - assertTrue("triple base count must be greater than 0", 0 < GraphBase.TOSTRING_TRIPLE_BASE); - assertTrue("triple base count must be less than limit", GraphBase.TOSTRING_TRIPLE_BASE < GraphBase.TOSTRING_TRIPLE_LIMIT); - assertTrue("triple count limit must be less than 20", GraphBase.TOSTRING_TRIPLE_LIMIT < 20); + assertTrue(0 < GraphBase.TOSTRING_TRIPLE_BASE, "triple base count must be greater than 0"); + assertTrue(GraphBase.TOSTRING_TRIPLE_BASE < GraphBase.TOSTRING_TRIPLE_LIMIT, "triple base count must be less than limit"); + assertTrue(GraphBase.TOSTRING_TRIPLE_LIMIT < 20, "triple count limit must be less than 20"); } + @Test public void testEllipsisAbsentForSmallModels() { Graph g = new LittleGraphBase(); addTriples(g, 1, TOSTRING_TRIPLE_BASE); - assertFalse("small model must not contain ellipsis cut-off", g.toString().contains("\\.\\.\\.")); + assertFalse(g.toString().contains("\\.\\.\\."), "small model must not contain ellipsis cut-off"); } + @Test public void testEllipsisPresentForLargeModels() { Graph g = new LittleGraphBase(); addTriples(g, 1, TOSTRING_TRIPLE_LIMIT + 1); - assertFalse("large model must contain ellipsis cut-off", g.toString().contains("\\.\\.\\.")); + assertFalse(g.toString().contains("\\.\\.\\."), "large model must contain ellipsis cut-off"); } + @Test public void testStringTripleCount() { Graph g = new LittleGraphBase(); int baseCount = TOSTRING_TRIPLE_BASE; diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphEvents.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphEvents.java index fbdb1b3294d..f916aea136a 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphEvents.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphEvents.java @@ -21,20 +21,22 @@ package org.apache.jena.graph; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.junit.NodeCreateUtils; -public class TestGraphEvents extends TestCase { - public TestGraphEvents(String name) { - super(name); - } +public class TestGraphEvents { + @Test public void testGraphEventContent() { testGraphEventContents("testing", "an example"); testGraphEventContents("toasting", Boolean.TRUE); testGraphEventContents("tasting", NodeCreateUtils.createTriple("we are here")); } + @Test public void testGraphEventsRemove() { testGraphEventsRemove("s", "p", "o"); testGraphEventsRemove("s", "p", "17"); diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphListener.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphListener.java index 9db23d22ebc..a8988195dc7 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphListener.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphListener.java @@ -25,25 +25,29 @@ import java.util.Iterator; import java.util.List; -import junit.framework.TestSuite; -import org.apache.jena.mem.GraphMemFast; +import java.util.function.Supplier; + +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; /** * Version of graph tests that set up a listener that copies all changes and verifies * that after every notification modified graph and original are isomorphic. */ -public class TestGraphListener extends MetaTestGraph { - public TestGraphListener(String name) { - super(name); - } +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.graph.GraphCreators#graphMemFast") +public class TestGraphListener extends BaseTestGraph { + + /** + * The implementation used for the listener's copy of the graph. Extending + * MetaTestGraph_JU6 would inherit its argument source as well as this one, running + * every test once per implementation on top of these. + */ + @Parameter + protected Supplier graphMaker; - public TestGraphListener(Class graphClass, String name) { - super(graphClass, name); - } - public static TestSuite suite() { - return MetaTestGraph.suite(TestGraphListener.class, GraphMemFast.class); - } /** * A listener to check that a graph is being tracked correctly by its events. */ @@ -54,7 +58,7 @@ protected class CheckChanges implements GraphListener { public CheckChanges(String description, Graph g) { original = g; desc = description; - copy = TestGraphListener.super.getNewGraph(); + copy = graphMaker.get(); } protected void verify() { diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphMatchWithInference.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphMatchWithInference.java index 891cca4c609..3f7007811ac 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphMatchWithInference.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphMatchWithInference.java @@ -21,23 +21,18 @@ package org.apache.jena.graph; -import junit.framework.*; -import org.apache.jena.rdf.model.*; +import org.junit.jupiter.api.Test; + +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; /** * Test that an inferred graph and an identical concrete graph compare as equal. */ -public class TestGraphMatchWithInference extends TestCase { - public TestGraphMatchWithInference(String name) { - super(name); - } - - public static TestSuite suite() { - TestSuite result = new TestSuite(TestGraphMatchWithInference.class); - return result; - } +public class TestGraphMatchWithInference { + @Test public void testBasic() { Model mrdfs = ModelFactory.createRDFSModel(ModelFactory.createDefaultModel()); Model concrete = ModelFactory.createDefaultModel(); diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphPlain.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphPlain.java index 66ed20452d1..3e7cf5fe7c8 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphPlain.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphPlain.java @@ -21,23 +21,21 @@ package org.apache.jena.graph; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import java.util.List; import org.apache.jena.graph.impl.GraphPlain; import org.apache.jena.util.iterator.ExtendedIterator; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; @SuppressWarnings("deprecation") public class TestGraphPlain { private static Graph graph; - @BeforeClass + @BeforeAll public static void setUp() { // GraphMem is the old in-memory graph which has value-based indexing. // It is not the default graph implementation. diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphPrefixMapping.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphPrefixMapping.java index 328f7ca8543..d7efd278e7b 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphPrefixMapping.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphPrefixMapping.java @@ -21,20 +21,16 @@ package org.apache.jena.graph; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.compose.AbstractTestPrefixMapping; import org.apache.jena.shared.PrefixMapping; -public class TestGraphPrefixMapping extends TestCase { - public TestGraphPrefixMapping(String name) { - super(name); - } - - public static TestSuite suite() { - return new TestSuite(TestGraphPrefixMapping.class); - } +public class TestGraphPrefixMapping { + @Test public void testGraphPrefixMapping() { Graph g = GraphMemFactory.createDefaultGraph(); AbstractTestPrefixMapping.testUseEasyPrefix("from Graph", g.getPrefixMapping()); diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphUtil.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphUtil.java index 81e4328f3d1..a42d3739903 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphUtil.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphUtil.java @@ -21,9 +21,9 @@ package org.apache.jena.graph; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; // Test for the compare by src.size and step dst case. public class TestGraphUtil { diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabelSameValueAs.java b/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabelSameValueAs.java index cf5a661f3c6..19645a70240 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabelSameValueAs.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabelSameValueAs.java @@ -21,13 +21,12 @@ package org.apache.jena.graph; -import static org.junit.Assert.*; -import junit.framework.JUnit4TestAdapter; +import static org.junit.jupiter.api.Assertions.*; import org.apache.jena.datatypes.RDFDatatype; import org.apache.jena.datatypes.xsd.XSDDatatype; import org.apache.jena.graph.impl.LiteralLabel; import org.apache.jena.graph.impl.LiteralLabelFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; // See also TestTypedLiterals /** @@ -36,13 +35,10 @@ public class TestLiteralLabelSameValueAs { public TestLiteralLabelSameValueAs() {} - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TestLiteralLabelSameValueAs.class); - } private static void testSameValueAs(LiteralLabel lit1, LiteralLabel lit2, boolean sameValue) { - assertEquals("lit1 sameValueAs lit2", sameValue, lit1.sameValueAs(lit2)); - assertEquals("lit2 sameValueAs lit1", sameValue, lit2.sameValueAs(lit1)); + assertEquals(sameValue, lit1.sameValueAs(lit2), "lit1 sameValueAs lit2"); + assertEquals(sameValue, lit2.sameValueAs(lit1), "lit2 sameValueAs lit1"); if ( !sameValue ) { // ! SameValue => ! equals assertFalse(lit1.equals(lit2)); diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabels.java b/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabels.java index 5e062e43a40..7f0d979d049 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabels.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestLiteralLabels.java @@ -21,59 +21,61 @@ package org.apache.jena.graph; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.datatypes.BaseDatatype; import org.apache.jena.datatypes.RDFDatatype; import org.apache.jena.graph.impl.LiteralLabel; import org.apache.jena.graph.impl.LiteralLabelFactory; // See also TestLiteralLabelSameValueAs, TestTypedLiterals -public class TestLiteralLabels extends TestCase { - public TestLiteralLabels(String name) { - super(name); - } +public class TestLiteralLabels { - public static Test suite() { - return new TestSuite(TestLiteralLabels.class); - } + @Test public void testHashCode() { LiteralLabel ll = LiteralLabelFactory.createByValue("test", null); ll.hashCode(); } + @Test public void testHashCode2() { LiteralLabel ll1 = LiteralLabelFactory.createByValue("test", null); LiteralLabel ll2 = LiteralLabelFactory.createByValue("test", null); assertEquals(ll1.hashCode(), ll2.hashCode()); } + @Test public void testHashCodesForBase64Binary_1() { LiteralLabel A = GraphTestLib.node("'0123'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral(); LiteralLabel B = GraphTestLib.node("'0123'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral(); assertEquals(A.hashCode(), B.hashCode()); } + @Test public void testHashCodesForBase64Binary_2() { LiteralLabel A = GraphTestLib.node("'illgeal'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral(); LiteralLabel B = GraphTestLib.node("'illgeal'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral(); assertEquals(A.hashCode(), B.hashCode()); } + @Test public void testHashCodesForHexBinary_1() { LiteralLabel A = GraphTestLib.node("'0123'http://www.w3.org/2001/XMLSchema#hexBinary").getLiteral(); LiteralLabel B = GraphTestLib.node("'0123'http://www.w3.org/2001/XMLSchema#hexBinary").getLiteral(); assertEquals(A.hashCode(), B.hashCode()); } + @Test public void testHashCodesForHexBinary_2() { LiteralLabel A = GraphTestLib.node("'illegal'http://www.w3.org/2001/XMLSchema#hexBinary").getLiteral(); LiteralLabel B = GraphTestLib.node("'illegal'http://www.w3.org/2001/XMLSchema#hexBinary").getLiteral(); assertEquals(A.hashCode(), B.hashCode()); } + @Test public void testDatatypeIsEqualsNotCalledIfSecondOperandIsNotTyped() { RDFDatatype d = new BaseDatatype("eh:/FakeDataType") { @Override @@ -87,6 +89,7 @@ public boolean isEqual(LiteralLabel A, LiteralLabel B) { assertFalse(A.sameValueAs(B)); } + @Test public void testEquality1() { LiteralLabel A = LiteralLabelFactory.createTypedLiteral("xyz"); LiteralLabel B = LiteralLabelFactory.createTypedLiteral("xyz"); @@ -95,6 +98,7 @@ public void testEquality1() { assertEquals(A.hashCode(), B.hashCode()); } + @Test public void testEquality2() { LiteralLabel A = LiteralLabelFactory.createTypedLiteral("xyz"); LiteralLabel B = LiteralLabelFactory.createTypedLiteral("XYZ"); @@ -102,6 +106,7 @@ public void testEquality2() { assertFalse(A.sameValueAs(B)); } + @Test public void testEquality3() { LiteralLabel A = LiteralLabelFactory.createLang("xyz", "en-us"); LiteralLabel B = LiteralLabelFactory.createLang("xyz", "en-uk"); @@ -109,6 +114,7 @@ public void testEquality3() { assertFalse(A.sameValueAs(B)); } + @Test public void testEquality4() { LiteralLabel A = LiteralLabelFactory.createLang("xyz", "en-UK"); LiteralLabel B = LiteralLabelFactory.createLang("xyz", "en-uk"); diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestNode.java b/jena-core/src/test/java/org/apache/jena/graph/TestNode.java index f7d6779f189..0a31ccc14e4 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestNode.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestNode.java @@ -21,8 +21,10 @@ package org.apache.jena.graph; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.atlas.lib.Creator; import org.apache.jena.datatypes.RDFDatatype; import org.apache.jena.datatypes.TypeMapper; @@ -44,63 +46,62 @@ * Exercise nodes. Make sure that the different node types do not overlap and that * the test predicates work properly on the different node kinds. */ -public class TestNode extends TestCase { - public TestNode(String name) { - super(name); - } - - public static TestSuite suite() { - return new TestSuite(TestNode.class); - } +public class TestNode { private static final String U = "http://some.domain.name/magic/spells.incant"; private static final String N = "Alice"; private static final LiteralLabel L = LiteralLabelFactory.createLang("ashes are burning", "en"); private static final String A = BlankNodeId.createFreshId(); + @Test public void testBlanks() { - assertTrue("anonymous nodes are blank", NodeFactory.createBlankNode().isBlank()); - assertFalse("anonymous nodes aren't literal", NodeFactory.createBlankNode().isLiteral()); - assertFalse("anonymous nodes aren't URIs", NodeFactory.createBlankNode().isURI()); - assertFalse("anonymous nodes aren't variables", NodeFactory.createBlankNode().isVariable()); - assertEquals("anonymous nodes have the right id", NodeFactory.createBlankNode(A).getBlankNodeLabel(), A); + assertTrue(NodeFactory.createBlankNode().isBlank(), "anonymous nodes are blank"); + assertFalse(NodeFactory.createBlankNode().isLiteral(), "anonymous nodes aren't literal"); + assertFalse(NodeFactory.createBlankNode().isURI(), "anonymous nodes aren't URIs"); + assertFalse(NodeFactory.createBlankNode().isVariable(), "anonymous nodes aren't variables"); + assertEquals(NodeFactory.createBlankNode(A).getBlankNodeLabel(), A, "anonymous nodes have the right id"); } @SuppressWarnings("deprecation") + @Test public void testLiterals() { - assertFalse("literal nodes aren't blank", NodeFactory.createLiteral(L).isBlank()); - assertTrue("literal nodes are literal", NodeFactory.createLiteral(L).isLiteral()); - assertFalse("literal nodes aren't variables", NodeFactory.createLiteral(L).isVariable()); - assertFalse("literal nodes aren't URIs", NodeFactory.createLiteral(L).isURI()); - assertEquals("literal nodes preserve value", NodeFactory.createLiteral(L).getLiteral(), L); + assertFalse(NodeFactory.createLiteral(L).isBlank(), "literal nodes aren't blank"); + assertTrue(NodeFactory.createLiteral(L).isLiteral(), "literal nodes are literal"); + assertFalse(NodeFactory.createLiteral(L).isVariable(), "literal nodes aren't variables"); + assertFalse(NodeFactory.createLiteral(L).isURI(), "literal nodes aren't URIs"); + assertEquals(NodeFactory.createLiteral(L).getLiteral(), L, "literal nodes preserve value"); } + @Test public void testURIs() { - assertFalse("URI nodes aren't blank", NodeFactory.createURI(U).isBlank()); - assertFalse("URI nodes aren't literal", NodeFactory.createURI(U).isLiteral()); - assertFalse("URI nodes aren't variables", NodeFactory.createURI(U).isVariable()); - assertTrue("URI nodes are URIs", NodeFactory.createURI(U).isURI()); - assertEquals("URI nodes preserve URI", NodeFactory.createURI(U).getURI(), U); + assertFalse(NodeFactory.createURI(U).isBlank(), "URI nodes aren't blank"); + assertFalse(NodeFactory.createURI(U).isLiteral(), "URI nodes aren't literal"); + assertFalse(NodeFactory.createURI(U).isVariable(), "URI nodes aren't variables"); + assertTrue(NodeFactory.createURI(U).isURI(), "URI nodes are URIs"); + assertEquals(NodeFactory.createURI(U).getURI(), U, "URI nodes preserve URI"); } + @Test public void testVariables() { - assertFalse("variable nodes aren't blank", NodeFactory.createVariable(N).isBlank()); - assertFalse("variable nodes aren't literal", NodeFactory.createVariable(N).isLiteral()); - assertFalse("variable nodes aren't URIs", NodeFactory.createVariable(N).isURI()); - assertTrue("variable nodes are variable", NodeFactory.createVariable(N).isVariable()); - assertEquals("variable nodes keep their name", N, NodeFactory.createVariable(N).getName()); - assertEquals("variable nodes keep their name", N + "x", NodeFactory.createVariable(N + "x").getName()); + assertFalse(NodeFactory.createVariable(N).isBlank(), "variable nodes aren't blank"); + assertFalse(NodeFactory.createVariable(N).isLiteral(), "variable nodes aren't literal"); + assertFalse(NodeFactory.createVariable(N).isURI(), "variable nodes aren't URIs"); + assertTrue(NodeFactory.createVariable(N).isVariable(), "variable nodes are variable"); + assertEquals(N, NodeFactory.createVariable(N).getName(), "variable nodes keep their name"); + assertEquals(N + "x", NodeFactory.createVariable(N + "x").getName(), "variable nodes keep their name"); } + @Test public void testANY() { - assertFalse("ANY nodes aren't blank", Node.ANY.isBlank()); - assertFalse("ANY nodes aren't literals", Node.ANY.isLiteral()); - assertFalse("ANY nodes aren't URIs", Node.ANY.isURI()); - assertFalse("ANY nodes aren't variables", Node.ANY.isVariable()); - assertFalse("ANY nodes aren't blank", Node.ANY.isBlank()); - assertFalse("ANY nodes aren't blank", Node.ANY.isBlank()); + assertFalse(Node.ANY.isBlank(), "ANY nodes aren't blank"); + assertFalse(Node.ANY.isLiteral(), "ANY nodes aren't literals"); + assertFalse(Node.ANY.isURI(), "ANY nodes aren't URIs"); + assertFalse(Node.ANY.isVariable(), "ANY nodes aren't variables"); + assertFalse(Node.ANY.isBlank(), "ANY nodes aren't blank"); + assertFalse(Node.ANY.isBlank(), "ANY nodes aren't blank"); } + @Test public void testNodeVariableConstructor() { assertEquals(NodeFactory.createVariable("hello"), new Node_Variable("hello")); assertEquals(NodeFactory.createVariable("world"), new Node_Variable("world")); @@ -135,11 +136,12 @@ private Object[][] eqTestCases() { {NodeFactory.createLiteral(LLang1), "9"}, {NodeFactory.createLiteral(LLang2), "10"},}; } + @Test public void testNodeEquals() { Object[][] tests = eqTestCases(); for ( Object[] I : tests ) { - assertFalse(I[0] + " should not equal null", I[0].equals(null)); - assertFalse(I[0] + "should not equal 'String'", I[0].equals("String")); + assertFalse(I[0].equals(null), I[0] + " should not equal null"); + assertFalse(I[0].equals("String"), I[0] + "should not equal 'String'"); for ( Object[] J : tests ) { testEquality(I[1].equals(J[1]), I[0], J[0]); } @@ -149,7 +151,7 @@ public void testNodeEquals() { private void testEquality(boolean testEq, Object x, Object y) { String testName = getType(x) + " " + x + " and " + getType(y) + " " + y; if ( testEq ) - assertEquals(testName + "should be equal", x, y); + assertEquals(x, y, testName + "should be equal"); else JenaTestLib.assertDiffer(testName + " should differ", x, y); } @@ -160,16 +162,17 @@ private String getType(Object x) { } @SuppressWarnings("deprecation") + @Test public void testEquals() { JenaTestLib.assertDiffer("different variables", NodeFactory.createVariable("xx"), NodeFactory.createVariable("yy")); - assertEquals("same vars", NodeFactory.createVariable("aa"), NodeFactory.createVariable("aa")); - assertEquals("same URI", NodeFactory.createURI(U), NodeFactory.createURI(U)); - assertEquals("same anon", NodeFactory.createBlankNode(A), NodeFactory.createBlankNode(A)); - assertEquals("same literal", NodeFactory.createLiteral(L), NodeFactory.createLiteral(L)); - assertFalse("distinct URIs", NodeFactory.createURI(U) == NodeFactory.createURI(U)); - assertFalse("distinct hyphens", NodeFactory.createBlankNode(A) == NodeFactory.createBlankNode(A)); - assertFalse("distinct literals", NodeFactory.createLiteral(L) == NodeFactory.createLiteral(L)); - assertFalse("distinct vars", NodeFactory.createVariable("aa") == NodeFactory.createVariable("aa")); + assertEquals(NodeFactory.createVariable("aa"), NodeFactory.createVariable("aa"), "same vars"); + assertEquals(NodeFactory.createURI(U), NodeFactory.createURI(U), "same URI"); + assertEquals(NodeFactory.createBlankNode(A), NodeFactory.createBlankNode(A), "same anon"); + assertEquals(NodeFactory.createLiteral(L), NodeFactory.createLiteral(L), "same literal"); + assertFalse(NodeFactory.createURI(U) == NodeFactory.createURI(U), "distinct URIs"); + assertFalse(NodeFactory.createBlankNode(A) == NodeFactory.createBlankNode(A), "distinct hyphens"); + assertFalse(NodeFactory.createLiteral(L) == NodeFactory.createLiteral(L), "distinct literals"); + assertFalse(NodeFactory.createVariable("aa") == NodeFactory.createVariable("aa"), "distinct vars"); } /** @@ -177,12 +180,13 @@ public void testEquals() { * appropriate to that Node. */ @SuppressWarnings("deprecation") + @Test public void testLabels() { String id = BlankNodeId.createFreshId(); - assertEquals("get URI value", U, NodeFactory.createURI(U).getURI()); - assertEquals("get blank value", id, NodeFactory.createBlankNode(id).getBlankNodeLabel()); - assertEquals("get literal value", L, NodeFactory.createLiteral(L).getLiteral()); - assertEquals("get variable name", N, NodeFactory.createVariable(N).getName()); + assertEquals(U, NodeFactory.createURI(U).getURI(), "get URI value"); + assertEquals(id, NodeFactory.createBlankNode(id).getBlankNodeLabel(), "get blank value"); + assertEquals(L, NodeFactory.createLiteral(L).getLiteral(), "get literal value"); + assertEquals(N, NodeFactory.createVariable(N).getName(), "get variable name"); } /** @@ -190,6 +194,7 @@ public void testLabels() { * exception. */ @SuppressWarnings("deprecation") + @Test public void testFailingLabels() { Node u = NodeFactory.createURI(U), b = NodeFactory.createBlankNode(); Node l = NodeFactory.createLiteral(L), v = NodeFactory.createVariable(N); @@ -244,11 +249,13 @@ public void testGetLiteralFails(Node n) { } catch (UnsupportedOperationException e) {} } + @Test public void testGetBlankNodeLabelString() { Node n = NodeFactory.createBlankNode(); assertNotNull(n.getBlankNodeLabel()); } + @Test public void testVariableSupport() { assertEquals(new Node_Variable("xxx"), new Node_Variable("xxx")); JenaTestLib.assertDiffer(new Node_Variable("xxx"), new Node_Variable("yyy")); @@ -257,6 +264,7 @@ public void testVariableSupport() { /** * Test that the create method does sensible things on null and "" */ + @Test public void testCreateBadString() { try { NodeCreateUtils.create(null); @@ -271,51 +279,59 @@ public void testCreateBadString() { /** * Test that anonymous nodes are created with the correct labels */ + @Test public void testCreateBlankNode() { String idA = "_xxx"; String idB = "_yyy"; Node a = NodeCreateUtils.create(idA); Node b = NodeCreateUtils.create(idB); - assertTrue("both must be bnodes", a.isBlank() && b.isBlank()); + assertTrue(a.isBlank() && b.isBlank(), "both must be bnodes"); assertEquals(NodeFactory.createBlankNode(idA).getBlankNodeLabel(), a.getBlankNodeLabel()); assertEquals(NodeFactory.createBlankNode(idB).getBlankNodeLabel(), b.getBlankNodeLabel()); } + @Test public void testCreateVariable() { String V = "wobbly"; Node v = NodeCreateUtils.create("?" + V); - assertTrue("must be a variable", v.isVariable()); - assertEquals("name must be correct", V, v.getName()); + assertTrue(v.isVariable(), "must be a variable"); + assertEquals(V, v.getName(), "name must be correct"); } + @Test public void testCreateANY() { - assertEquals("?? must denote ANY", Node.ANY, NodeCreateUtils.create("??")); + assertEquals(Node.ANY, NodeCreateUtils.create("??"), "?? must denote ANY"); } + @Test public void testCreatePlainLiteralSingleQuotes() { Node n = NodeCreateUtils.create("'xxx'"); assertEquals("xxx", n.getLiteralLexicalForm()); assertString(n); } + @Test public void testCreatePlainLiteralDoubleQuotes() { Node n = NodeCreateUtils.create("\"xxx\""); assertEquals("xxx", n.getLiteralLexicalForm()); assertString(n); } + @Test public void testCreateLiteralBackslashEscape() { testStringConversion("xx\\x", "'xx\\\\x'"); testStringConversion("xx\\x\\y", "'xx\\\\x\\\\y'"); testStringConversion("\\xyz\\", "'\\\\xyz\\\\'"); } + @Test public void testCreateLiteralQuoteEscapes() { testStringConversion("x\'y", "'x\\'y'"); testStringConversion("x\"y", "'x\\\"y'"); testStringConversion("x\'y\"z", "'x\\\'y\\\"z'"); } + @Test public void testCreateLiteralOtherEscapes() { testStringConversion(" ", "'\\s'"); testStringConversion("\t", "'\\t'"); @@ -329,6 +345,7 @@ protected void testStringConversion(String wanted, String template) { assertString(n); } + @Test public void testCreateLanguagedLiteralEN1() { Node n = NodeCreateUtils.create("'chat'en-UK"); assertEquals("chat", n.getLiteralLexicalForm()); @@ -336,6 +353,7 @@ public void testCreateLanguagedLiteralEN1() { assertEquals("en-UK", n.getLiteralLanguage()); } + @Test public void testCreateLanguagedLiteralEN2() { Node n1 = NodeCreateUtils.create("'chat'en-UK"); Node n2 = NodeCreateUtils.create("'chat'EN-UK"); @@ -344,6 +362,7 @@ public void testCreateLanguagedLiteralEN2() { assertTrue(n1.equals(n2)); } + @Test public void testCreateLanguagedLiteralXY() { Node n = NodeCreateUtils.create("\"chat\"xy-AB"); assertEquals("chat", n.getLiteralLexicalForm()); @@ -351,6 +370,7 @@ public void testCreateLanguagedLiteralXY() { assertLangString(n); } + @Test public void testCreateTypedLiteralInteger() { Node n = NodeCreateUtils.create("'42'xsd:integer"); assertEquals("42", n.getLiteralLexicalForm()); @@ -358,6 +378,7 @@ public void testCreateTypedLiteralInteger() { assertEquals(expand("xsd:integer"), n.getLiteralDatatypeURI()); } + @Test public void testCreateTypedLiteralBoolean() { Node n = NodeCreateUtils.create("\"true\"xsd:boolean"); assertEquals("true", n.getLiteralLexicalForm()); @@ -365,16 +386,19 @@ public void testCreateTypedLiteralBoolean() { assertEquals(expand("xsd:boolean"), n.getLiteralDatatypeURI()); } + @Test public void testGetPlainLiteralLexicalForm() { Node n = NodeCreateUtils.create("'stuff'"); assertEquals("stuff", n.getLiteralLexicalForm()); } + @Test public void testGetNumericLiteralLexicalForm() { Node n = NodeCreateUtils.create("17"); assertEquals("17", n.getLiteralLexicalForm()); } + @Test public void testTypesExpandPrefix() { testTypeExpandsPrefix("rdf:spoo"); testTypeExpandsPrefix("rdfs:bar"); @@ -389,6 +413,7 @@ private void testTypeExpandsPrefix(String type) { assertEquals(wanted, n.getLiteralDatatypeURI()); } + @Test public void testCreateURI() { String uri = "http://www.electric-hedgehog.net/"; testCreateURI(uri); @@ -400,6 +425,7 @@ public void testCreateURI() { testCreateURI("owl:wol", OWL.getURI() + "wol"); } + @Test public void testCreateURIOtherMap() { String myNS = "eh:foo/bar#", suffix = "something"; PrefixMapping mine = PrefixMapping.Factory.create().setNsPrefix("mine", myNS); @@ -421,11 +447,13 @@ private void testCreateURI(String in, String wanted) { } } + @Test public void testCreatePrefixed() { PrefixMapping pm = PrefixMapping.Factory.create(); NodeCreateUtils.create(pm, "xyz"); } + @Test public void testToStringWithPrefixMapping() { PrefixMapping pm = PrefixMapping.Factory.create(); String prefix = "spoo", ns = "abc:def/ghi#"; @@ -434,14 +462,16 @@ public void testToStringWithPrefixMapping() { assertEquals(prefix + ":" + suffix, NodeCreateUtils.create(ns + suffix).toString(pm)); } + @Test public void testNodeHelp() { - assertTrue("node() making URIs", GraphTestLib.node("hello").isURI()); - assertTrue("node() making literals", GraphTestLib.node("123").isLiteral()); - assertTrue("node() making literals", GraphTestLib.node("'hello'").isLiteral()); - assertTrue("node() making hyphens", GraphTestLib.node("_x").isBlank()); - assertTrue("node() making variables", GraphTestLib.node("?x").isVariable()); + assertTrue(GraphTestLib.node("hello").isURI(), "node() making URIs"); + assertTrue(GraphTestLib.node("123").isLiteral(), "node() making literals"); + assertTrue(GraphTestLib.node("'hello'").isLiteral(), "node() making literals"); + assertTrue(GraphTestLib.node("_x").isBlank(), "node() making hyphens"); + assertTrue(GraphTestLib.node("?x").isVariable(), "node() making variables"); } + @Test public void testVisitorPatternNode() { NodeVisitor returnNode = new NodeVisitor() { @Override @@ -509,6 +539,7 @@ private void visitExamples(NodeVisitor nv) { ng.visitWith(nv); } + @Test public void testVisitorPatternValue() { NodeVisitor checkValue = new NodeVisitor() { @Override @@ -561,6 +592,7 @@ public Object visitGraph(Node_Graph it, Graph graph) { * Test that the appropriate elements of the visitor are called exactly once; * this relies on the order of the visits in visitExamples. */ + @Test public void testVisitorPatternCalled() { final String[] strings = new String[]{""}; NodeVisitor checkCalled = new NodeVisitor() { @@ -609,17 +641,18 @@ public Object visitGraph(Node_Graph it, Graph graph) { }; String desired = " uri variable blank literal any termTriple termGraph"; visitExamples(checkCalled); - assertEquals("all visits must have been made", desired, strings[0]); + assertEquals(desired, strings[0], "all visits must have been made"); } + @Test public void testSimpleMatches() { assertTrue(NodeCreateUtils.create("S").sameTermAs(NodeCreateUtils.create("S"))); - assertFalse("", NodeCreateUtils.create("S").sameTermAs(NodeCreateUtils.create("T"))); + assertFalse(NodeCreateUtils.create("S").sameTermAs(NodeCreateUtils.create("T")), ""); assertTrue(NodeCreateUtils.create("_X").sameTermAs(NodeCreateUtils.create("_X"))); - assertFalse("", NodeCreateUtils.create("_X").sameTermAs(NodeCreateUtils.create("_Y"))); + assertFalse(NodeCreateUtils.create("_X").sameTermAs(NodeCreateUtils.create("_Y")), ""); assertTrue(NodeCreateUtils.create("10").sameTermAs(NodeCreateUtils.create("10"))); - assertFalse("", NodeCreateUtils.create("10").sameTermAs(NodeCreateUtils.create("11"))); + assertFalse(NodeCreateUtils.create("10").sameTermAs(NodeCreateUtils.create("11")), ""); // Jena6. nulls no longer allowed. try { @@ -633,6 +666,7 @@ public void testSimpleMatches() { // assertFalse("", Node.ANY.sameTermAs(null)); } + @Test public void testDataSameValue() { TypeMapper tm = TypeMapper.getInstance(); RDFDatatype dt1 = tm.getTypeByValue(Integer.valueOf(10)); @@ -640,9 +674,10 @@ public void testDataSameValue() { Node a = NodeFactory.createLiteralDT("10", dt1); Node b = NodeFactory.createLiteralDT("10", dt2); JenaTestLib.assertDiffer("types must make a difference", a, b); - assertTrue("A and B must express the same value", a.sameValueAs(b)); + assertTrue(a.sameValueAs(b), "A and B must express the same value"); } + @Test public void testLiteralToString() { TypeMapper tm = TypeMapper.getInstance(); RDFDatatype dtInt = tm.getTypeByValue(Integer.valueOf(10)); @@ -654,42 +689,51 @@ public void testLiteralToString() { assertEquals("\"10\"^^xsd:int", typed.toString()); } + @Test public void testGetIndexingValueURI() { Node u = NodeCreateUtils.create("eh:/telephone"); assertSame(u, u.getIndexingValue()); } + @Test public void testGetIndexingValueBlank() { Node b = NodeCreateUtils.create("_television"); assertSame(b, b.getIndexingValue()); } + @Test public void testGetIndexingValuePlainString() { testIndexingValueLiteral(() -> NodeCreateUtils.create("'literally'")); } + @Test public void testGetIndexingValueLanguagedString() { testIndexingValueLiteral(() -> NodeCreateUtils.create("'chat'fr")); } + @Test public void testGetIndexingValueXSDString() { testIndexingValueLiteral(() -> NodeCreateUtils.create("'string'xsd:string")); } // JENA-1936 + @Test public void testGetIndexingValueHexBinary1() { testIndexingValueLiteral(() -> NodeCreateUtils.create("''xsd:hexBinary")); } + @Test public void testGetIndexingValueHexBinary2() { testIndexingValueLiteral(() -> NodeCreateUtils.create("'ABCD'xsd:hexBinary")); } + @Test public void testGetIndexingValueBase64Binary1() { testIndexingValueLiteral(() -> NodeCreateUtils.create("''xsd:base64Binary")); } // "sure." encodes to "c3VyZS4=" + @Test public void testGetIndexingValueBase64Binary2() { testIndexingValueLiteral(() -> NodeCreateUtils.create("'c3VyZS4='xsd:base64Binary")); } @@ -706,15 +750,18 @@ private void testIndexingValueLiteral(Node n1, Node n2) { assertEquals(n1.getLiteral().getIndexingValue().hashCode(), n2.getIndexingValue().hashCode()); } + @Test public void testGetLiteralValuePlainString() { Node s = NodeCreateUtils.create("'aString'"); assertSame(s.getLiteral().getValue(), s.getLiteralValue()); } + @Test public void testGetLiteralDatatypePlainString() { assertString(NodeCreateUtils.create("'plain'")); } + @Test public void testConcrete() { assertTrue(NodeCreateUtils.create("S").isConcrete()); assertTrue(NodeCreateUtils.create("_P").isConcrete()); @@ -731,17 +778,19 @@ public void testConcrete() { * test that URI nodes have namespace/localname splits which are consistent with * Util.splitNamepace. */ + @Test public void testNamespace() { for ( String uri : someURIs ) { int split = SplitIRI.splitXML(uri); Node n = NodeCreateUtils.create(uri); - assertEquals("check namespace", uri.substring(0, split), n.getNameSpace()); - assertEquals("check localname", uri.substring(split), n.getLocalName()); + assertEquals(uri.substring(0, split), n.getNameSpace(), "check namespace"); + assertEquals(uri.substring(split), n.getLocalName(), "check localname"); } } protected static String[] someNodes = {"42", "'hello'", "_anon", "'robotic'tick", "'teriffic'abc:def"}; + @Test public void testHasURI() { for ( String someURI : someURIs ) { testHasURI(someURI); @@ -753,8 +802,8 @@ public void testHasURI() { protected void testHasURI(String uri) { Node n = NodeCreateUtils.create(uri); - assertTrue(uri, !n.isURI() || n.hasURI(uri)); - assertFalse(uri, n.hasURI(uri + "x")); + assertTrue(!n.isURI() || n.hasURI(uri), uri); + assertFalse(n.hasURI(uri + "x"), uri); } private static void assertString(Node n) { diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestNodeCreateStrings.java b/jena-core/src/test/java/org/apache/jena/graph/TestNodeCreateStrings.java index efabd02f756..19d59c7b6f1 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestNodeCreateStrings.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestNodeCreateStrings.java @@ -21,11 +21,10 @@ package org.apache.jena.graph; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import org.apache.jena.rdf.model.impl.Util; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Testing making string-like RDF terms */ public class TestNodeCreateStrings { diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestNodeEdgeCases.java b/jena-core/src/test/java/org/apache/jena/graph/TestNodeEdgeCases.java index 4812831baec..15625d0b00c 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestNodeEdgeCases.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestNodeEdgeCases.java @@ -21,11 +21,11 @@ package org.apache.jena.graph; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; import org.apache.jena.datatypes.xsd.impl.RDFDirLangString; import org.apache.jena.datatypes.xsd.impl.RDFLangString; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestNodeEdgeCases { diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestNodeExtras.java b/jena-core/src/test/java/org/apache/jena/graph/TestNodeExtras.java index 95ad98c8397..284ae949575 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestNodeExtras.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestNodeExtras.java @@ -21,13 +21,13 @@ package org.apache.jena.graph; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.apache.jena.junit.NodeCreateUtils; import org.apache.jena.rdf.model.impl.Util; import org.apache.jena.vocabulary.RDF; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** More tests for {@link Node Nodes}. */ public class TestNodeExtras { @@ -102,16 +102,20 @@ public void term_triple_4() { assertFalse(nt1.sameValueAs(nt9)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void term_triple_bad_1() { - Node n = NodeFactory.createLiteralString("abc"); - n.getTriple(); + assertThrows(UnsupportedOperationException.class, ()->{ + Node n = NodeFactory.createLiteralString("abc"); + n.getTriple(); + }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void term_triple_bad_2() { - Node n = NodeFactory.createURI("http://example/abc"); - n.getTriple(); + assertThrows(UnsupportedOperationException.class, ()->{ + Node n = NodeFactory.createURI("http://example/abc"); + n.getTriple(); + }); } @Test diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestRDFStringLiterals.java b/jena-core/src/test/java/org/apache/jena/graph/TestRDFStringLiterals.java index 346b7f14bf0..f7a0e02359a 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestRDFStringLiterals.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestRDFStringLiterals.java @@ -22,10 +22,9 @@ package org.apache.jena.graph; import static org.apache.jena.graph.TextDirection.RTL; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.apache.jena.datatypes.RDFDatatype; import org.apache.jena.datatypes.xsd.XSDDatatype; @@ -130,14 +129,18 @@ public void dirLangString01() { test(n, "abc", "en", RTL, RDF.dtDirLangString, "abc@en"); } - @Test(expected = JenaException.class) + @Test public void dirLangString02() { - Node n = NodeFactory.createLiteralDirLang("abc", "en", "LTR"); + assertThrows(JenaException.class, ()->{ + Node n = NodeFactory.createLiteralDirLang("abc", "en", "LTR"); + }); } - @Test(expected = JenaException.class) + @Test public void dirLangString03() { - Node n = NodeFactory.createLiteralDirLang("abc", "en", "unk"); + assertThrows(JenaException.class, ()->{ + Node n = NodeFactory.createLiteralDirLang("abc", "en", "unk"); + }); } @Test @@ -146,9 +149,11 @@ public void dirLangString04() { test(n, "abc", "en", null, RDF.dtLangString, "abc@en"); } - @Test(expected = JenaException.class) + @Test public void dirLangString05() { - Node n = NodeFactory.createLiteralDirLang("abc", "en", "x"); + assertThrows(JenaException.class, ()->{ + Node n = NodeFactory.createLiteralDirLang("abc", "en", "x"); + }); } // -- Via createLiteralLang splitting lang tags on "--" @@ -172,53 +177,67 @@ public void dirLangString_equality() { assertNotEquals(nDirLangString1, nDirLangString4); } - @Test(expected = JenaException.class) + @Test public void dirLangString11() { - Node n = NodeFactory.createLiteralLang("abc", "en--LTR"); + assertThrows(JenaException.class, ()->{ + Node n = NodeFactory.createLiteralLang("abc", "en--LTR"); + }); } - @Test(expected = JenaException.class) + @Test public void dirLangString12() { - Node n = NodeFactory.createLiteralLang("abc", "en--"); + assertThrows(JenaException.class, ()->{ + Node n = NodeFactory.createLiteralLang("abc", "en--"); + }); } // Errors - @Test(expected = JenaException.class) + @Test public void rdfStringBad01() { - // No lang but with a direction - Node n = NodeFactory.createLiteralDirLang("abc", null, TextDirection.LTR); + assertThrows(JenaException.class, ()->{ + // No lang but with a direction + Node n = NodeFactory.createLiteralDirLang("abc", null, TextDirection.LTR); + }); } - @Test(expected = JenaException.class) + @Test public void rdfStringBad02() { - // No lang but with a direction - Node n = NodeFactory.createLiteralDirLang("abc", "", TextDirection.LTR); + assertThrows(JenaException.class, ()->{ + // No lang but with a direction + Node n = NodeFactory.createLiteralDirLang("abc", "", TextDirection.LTR); + }); } - @Test(expected = NullPointerException.class) + @Test public void rdfStringBad03() { - Node n = NodeFactory.createLiteralString((String)null); + assertThrows(NullPointerException.class, ()->{ + Node n = NodeFactory.createLiteralString((String)null); + }); } - @Test(expected = NullPointerException.class) + @Test public void rdfStringBad04() { - Node n = NodeFactory.createLiteralLang((String)null, "en"); + assertThrows(NullPointerException.class, ()->{ + Node n = NodeFactory.createLiteralLang((String)null, "en"); + }); } - @Test(expected = NullPointerException.class) + @Test public void rdfStringBad05() { - Node n = NodeFactory.createLiteralDirLang((String)null, "en", TextDirection.LTR); + assertThrows(NullPointerException.class, ()->{ + Node n = NodeFactory.createLiteralDirLang((String)null, "en", TextDirection.LTR); + }); } // ---- private static void test(Node node, String lexicalForm, String lang, TextDirection textDir, RDFDatatype datatype, String indexingValue) { - assertEquals("Lexical form:", lexicalForm, node.getLiteralLexicalForm()); - assertEquals("Language:", lang, node.getLiteralLanguage()); - assertEquals("Text Direction:", textDir, node.getLiteralBaseDirection()); - assertEquals("Datatype:", datatype, node.getLiteralDatatype()); - assertEquals("Indexing:", indexingValue, node.getIndexingValue()); + assertEquals(lexicalForm, node.getLiteralLexicalForm(), "Lexical form:"); + assertEquals(lang, node.getLiteralLanguage(), "Language:"); + assertEquals(textDir, node.getLiteralBaseDirection(), "Text Direction:"); + assertEquals(datatype, node.getLiteralDatatype(), "Datatype:"); + assertEquals(indexingValue, node.getIndexingValue(), "Indexing:"); } } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestRegisterGraphListener.java b/jena-core/src/test/java/org/apache/jena/graph/TestRegisterGraphListener.java index aa60a6304f3..a455e7839a6 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestRegisterGraphListener.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestRegisterGraphListener.java @@ -21,16 +21,18 @@ package org.apache.jena.graph; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.Iterator; import java.util.List; -import junit.framework.TestCase; - /** * These tests are for listeners that add or delete other listeners. It motivates the * use of, e.g. CopyOnWriteArrayList for storing listeners. */ -public class TestRegisterGraphListener extends TestCase { +public class TestRegisterGraphListener { private ComeAndGoListener all[]; private Graph graph; @@ -107,9 +109,6 @@ public void notifyDeleteTriple(Graph g, Triple t) {} public void notifyEvent(Graph source, Object value) {} } - public TestRegisterGraphListener(String name) { - super(name); - } private void testAddingTriple(int addMe, ComeAndGoListener...allx) { graph = GraphTestLib.newGraph(); @@ -126,6 +125,7 @@ private void testAddingTriple(int addMe, ComeAndGoListener...allx) { } } + @Test public void testAddOne() { testAddingTriple(2, new ComeAndGoListener() { @Override @@ -135,6 +135,7 @@ void doSomeDamage() { }, new SimpleListener(), new SimpleListener()); } + @Test public void testDelete2nd() { testAddingTriple(3, new ComeAndGoListener() { @Override @@ -144,6 +145,7 @@ void doSomeDamage() { }, new SimpleListener(), new SimpleListener()); } + @Test public void testDelete1st() { testAddingTriple(3, new SimpleListener(), new ComeAndGoListener() { @Override @@ -153,6 +155,7 @@ void doSomeDamage() { }, new SimpleListener()); } + @Test public void testDeleteSelf() { testAddingTriple(3, new ComeAndGoListener() { @Override @@ -162,6 +165,7 @@ void doSomeDamage() { }, new SimpleListener(), new SimpleListener()); } + @Test public void testDeleteAndAddSelf() { testAddingTriple(3, new ComeAndGoListener() { @Override diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestReifier.java b/jena-core/src/test/java/org/apache/jena/graph/TestReifier.java index 3d17fe03028..c9265972849 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestReifier.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestReifier.java @@ -21,17 +21,21 @@ package org.apache.jena.graph; -import java.lang.reflect.Constructor; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.function.Supplier; + +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.atlas.iterator.Iter; import org.apache.jena.junit.NodeCreateUtils; -import org.apache.jena.mem.GraphMemFast; import org.apache.jena.rdf.model.impl.ReifierStd; import org.apache.jena.shared.AlreadyReifiedException; import org.apache.jena.shared.CannotReifyException; -import org.apache.jena.shared.JenaException; import org.apache.jena.test.JenaTestLib; import org.apache.jena.vocabulary.RDF; @@ -39,33 +43,15 @@ * This class tests the reifiers of ordinary graphs. Old test suite - kept to ensure * compatibility for the one and only Standard mode */ -public class TestReifier extends TestCase { - protected final Class graphClass; +@ParameterizedClass(name = "{0}") +@MethodSource("org.apache.jena.graph.GraphCreators#graphs") +public class TestReifier { - public TestReifier(String name) { - super(name); - graphClass = null; - } - - public TestReifier(Class graphClass, String name) { - super(name); - this.graphClass = graphClass; - } + @Parameter + protected Supplier graphMaker; private Graph getGraph() { - try { - Constructor cons = JenaTestLib.getConstructor(graphClass, new Class[]{}); - if ( cons != null ) - return (Graph)cons.newInstance(); - Constructor cons2 = JenaTestLib.getConstructor(graphClass, new Class[]{this.getClass()}); - if ( cons2 != null ) - return (Graph)cons2.newInstance(this); - throw new JenaException("no suitable graph constructor found for " + graphClass); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new JenaException(e); - } + return graphMaker.get(); } private final Graph getGraphWith(String facts) { @@ -86,6 +72,7 @@ protected final Graph graphWithIf(boolean cond, String facts) { return graphWithUnless(!cond, facts); } + @Test public void testGetGraphNotNull() { assertNotNull(getGraph()); } @@ -93,6 +80,7 @@ public void testGetGraphNotNull() { /** * Check that the standard reifier will note, but not hide, reification quads. */ + @Test public void testStandard() { Graph g = getGraph(); assertFalse(ReifierStd.hasTriple(g, GraphTestLib.triple("s p o"))); @@ -111,6 +99,7 @@ public void testStandard() { * Test that the Standard reifier will expose implicit quads arising from * reifyAs(). */ + @Test public void testStandardExplode() { Graph g = getGraph(); ReifierStd.reifyAs(g, GraphTestLib.node("a"), GraphTestLib.triple("p Q r")); @@ -124,6 +113,7 @@ public void testStandardExplode() { * 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() { Graph g = getGraph(); GraphTestLib.graphAdd(g, "x rdf:subject A; x rdf:predicate P; x rdf:object O; x rdf:type rdf:Statement"); @@ -132,14 +122,17 @@ public void testOverspecificationSuppressesReification() { assertEquals(null, ReifierStd.getTriple(g, GraphTestLib.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"); } @@ -158,6 +151,7 @@ protected void testReificationClash(String clashingStatement) { * Test that reifying a triple explicitly has some effect on the graph only for * Standard reifiers. */ + @Test public void testManifestQuads() { Graph g = getGraph(); ReifierStd.reifyAs(g, GraphTestLib.node("A"), GraphTestLib.triple("S P O")); @@ -165,65 +159,73 @@ public void testManifestQuads() { GraphTestLib.assertIsomorphic(GraphTestLib.graphWith(reified), g); } + @Test public void testHiddenVsReification() { Graph g = getGraph(); ReifierStd.reifyAs(g, GraphTestLib.node("A"), GraphTestLib.triple("S P O")); assertTrue(ReifierStd.findEither(g, Triple.ANY, false).hasNext()); } + @Test public void testRetrieveTriplesByNode() { Graph G = getGraph(); Node N = NodeFactory.createBlankNode(), M = NodeFactory.createBlankNode(); ReifierStd.reifyAs(G, N, GraphTestLib.triple("x R y")); - assertEquals("gets correct triple", GraphTestLib.triple("x R y"), ReifierStd.getTriple(G, N)); + assertEquals(GraphTestLib.triple("x R y"), ReifierStd.getTriple(G, N), "gets correct triple"); ReifierStd.reifyAs(G, M, GraphTestLib.triple("p S q")); JenaTestLib.assertDiffer("the anon nodes must be distinct", N, M); - assertEquals("gets correct triple", GraphTestLib.triple("p S q"), ReifierStd.getTriple(G, M)); + assertEquals(GraphTestLib.triple("p S q"), ReifierStd.getTriple(G, M), "gets correct triple"); - 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"))); + assertTrue(ReifierStd.hasTriple(G, M), "node is known bound"); + assertTrue(ReifierStd.hasTriple(G, N), "node is known bound"); + assertFalse(ReifierStd.hasTriple(G, NodeFactory.createURI("any:thing")), "node is known unbound"); } + @Test public void testRetrieveTriplesByTriple() { Graph G = getGraph(); Triple T = GraphTestLib.triple("x R y"), T2 = GraphTestLib.triple("y R x"); Node N = GraphTestLib.node("someNode"); ReifierStd.reifyAs(G, N, T); - assertTrue("R must have T", ReifierStd.hasTriple(G, T)); - assertFalse("R must not have T2", ReifierStd.hasTriple(G, T2)); + assertTrue(ReifierStd.hasTriple(G, T), "R must have T"); + assertFalse(ReifierStd.hasTriple(G, T2), "R must not have T2"); } + @Test public void testReifyAs() { Graph G = getGraph(); Node X = NodeFactory.createURI("some:uri"); - assertEquals("node used", X, ReifierStd.reifyAs(G, X, GraphTestLib.triple("x R y"))); - assertEquals("retrieves correctly", GraphTestLib.triple("x R y"), ReifierStd.getTriple(G, X)); + assertEquals(X, ReifierStd.reifyAs(G, X, GraphTestLib.triple("x R y")), "node used"); + assertEquals(GraphTestLib.triple("x R y"), ReifierStd.getTriple(G, X), "retrieves correctly"); } + @Test public void testAllNodes() { Graph G = getGraph(); ReifierStd.reifyAs(G, GraphTestLib.node("x"), GraphTestLib.triple("cows eat grass")); ReifierStd.reifyAs(G, GraphTestLib.node("y"), GraphTestLib.triple("pigs can fly")); ReifierStd.reifyAs(G, GraphTestLib.node("z"), GraphTestLib.triple("dogs may bark")); - assertEquals("", GraphTestLib.nodeSet("z y x"), Iter.toSet(ReifierStd.allNodes(G))); + assertEquals(GraphTestLib.nodeSet("z y x"), Iter.toSet(ReifierStd.allNodes(G)), ""); } + @Test public void testRemoveByNode() { Graph G = getGraph(); Node X = GraphTestLib.node("x"), Y = GraphTestLib.node("y"); ReifierStd.reifyAs(G, X, GraphTestLib.triple("x R a")); ReifierStd.reifyAs(G, Y, GraphTestLib.triple("y R a")); ReifierStd.remove(G, X, GraphTestLib.triple("x R a")); - assertFalse("triple X has gone", ReifierStd.hasTriple(G, X)); - assertEquals("triple Y still there", GraphTestLib.triple("y R a"), ReifierStd.getTriple(G, Y)); + assertFalse(ReifierStd.hasTriple(G, X), "triple X has gone"); + assertEquals(GraphTestLib.triple("y R a"), ReifierStd.getTriple(G, Y), "triple Y still there"); } + @Test public void testRemoveFromNothing() { Graph G = getGraph(); G.delete(GraphTestLib.triple("quint rdf:subject S")); } + @Test public void testException() { Graph G = getGraph(); Node X = GraphTestLib.node("x"); @@ -235,6 +237,7 @@ public void testException() { } catch (AlreadyReifiedException e) {} } + @Test public void testKevinCaseA() { Graph G = getGraph(); Node X = GraphTestLib.node("x"), a = GraphTestLib.node("a"), b = GraphTestLib.node("b"), c = GraphTestLib.node("c"); @@ -242,6 +245,7 @@ public void testKevinCaseA() { ReifierStd.reifyAs(G, X, Triple.create(a, b, c)); } + @Test public void testKevinCaseB() { Graph G = getGraph(); Node X = GraphTestLib.node("x"), Y = GraphTestLib.node("y"); @@ -255,6 +259,7 @@ public void testKevinCaseB() { } } + @Test public void testQuadRemove() { Graph g = getGraph(); assertEquals(0, g.size()); @@ -274,6 +279,7 @@ public void testQuadRemove() { assertEquals(0, g.size()); } + @Test public void testEmpty() { Graph g = getGraph(); assertTrue(g.isEmpty()); @@ -287,27 +293,33 @@ public void testEmpty() { assertFalse(g.isEmpty()); } + @Test public void testReifierEmptyFind() { Graph g = getGraph(); assertEquals(GraphTestLib.tripleSet(""), ReifierStd.findExposed(g, Triple.ANY).toSet()); } + @Test public void testReifierFindSubject() { testReifierFind("x rdf:subject S"); } + @Test public void testReifierFindObject() { testReifierFind("x rdf:object O"); } + @Test public void testReifierFindPredicate() { testReifierFind("x rdf:predicate P"); } + @Test public void testReifierFindComplete() { testReifierFind("x rdf:predicate P; x rdf:subject S; x rdf:object O; x rdf:type rdf:Statement"); } + @Test public void testReifierFindFilter() { Graph g = getGraph(); GraphTestLib.graphAdd(g, "s rdf:subject S"); @@ -324,11 +336,4 @@ protected void testReifierFind(String triples, String pattern) { assertEquals(GraphTestLib.tripleSet(triples), ReifierStd.findExposed(g, GraphTestLib.triple(pattern)).toSet()); } - public static TestSuite suite() { - TestSuite result = new TestSuite(); - result.addTest(MetaTestGraph.suite(TestReifier.class, GraphMemFast.class)); - result.setName(TestReifier.class.getSimpleName()); - return result; - } - } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestTriple.java b/jena-core/src/test/java/org/apache/jena/graph/TestTriple.java index 1ac3d42dfa4..7129878013f 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestTriple.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestTriple.java @@ -21,10 +21,12 @@ package org.apache.jena.graph; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.function.Function; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.graph.impl.LiteralLabel; import org.apache.jena.graph.impl.LiteralLabelFactory; @@ -32,20 +34,13 @@ import org.apache.jena.shared.PrefixMapping; import org.apache.jena.test.JenaTestLib; -public class TestTriple extends TestCase { - - public TestTriple(String name) { - super(name); - } - - public static TestSuite suite() { - return new TestSuite(TestTriple.class); - } +public class TestTriple { private static final String U = "http://some.domain.name/magic/spells.incant"; private static final String N = "Alice"; private static final LiteralLabel L = LiteralLabelFactory.createLang("ashes are burning", "en"); + @Test public void testTripleEquals() { // create some nodes to test String id = BlankNodeId.createFreshId(); @@ -89,14 +84,14 @@ public void testTripleEquals() { } } - assertEquals("triple, null", triples[0].equals(null), false); + assertEquals(triples[0].equals(null), false, "triple, null"); JenaTestLib.assertDiffer("triple, string", triples[0], "string"); // now compare each triple with each other triple for ( int i = 0 ; i < triples.length ; i++ ) { for ( int j = 0 ; j < triples.length ; j++ ) { if ( expected[i][j] ) { - assertEquals("triples " + i + ", " + j, triples[i], triples[j]); + assertEquals(triples[i], triples[j], "triples " + i + ", " + j); } else { JenaTestLib.assertDiffer("triples" + i + ", " + j, triples[i], triples[j]); } @@ -104,11 +99,13 @@ public void testTripleEquals() { } } + @Test public void testTripleCreate() { Node S = NodeCreateUtils.create("s"), P = NodeCreateUtils.create("p"), O = NodeCreateUtils.create("o"); assertEquals(Triple.create(S, P, O), Triple.create(S, P, O)); } + @Test public void testTripleCreateFromString() { Node S = NodeCreateUtils.create("a"), P = NodeCreateUtils.create("_P"), O = NodeCreateUtils.create("?c"); assertEquals(Triple.create(S, P, O), NodeCreateUtils.createTriple("a _P ?c")); @@ -117,6 +114,7 @@ public void testTripleCreateFromString() { /** * Test that triple-creation respects prefixes, assuming that node creation does. */ + @Test public void testTriplePrefixes() { Node S = NodeCreateUtils.create("rdf:alpha"), P = NodeCreateUtils.create("dc:creator"); Node O = NodeCreateUtils.create("spoo:notmapped"); @@ -124,6 +122,7 @@ public void testTriplePrefixes() { assertEquals(Triple.create(S, P, O), t); } + @Test public void testTripleCreationMapped() { PrefixMapping pm = PrefixMapping.Factory.create().setNsPrefix("a", "ftp://foo/").setNsPrefix("b", "http://spoo/"); Triple wanted = NodeCreateUtils.createTriple("ftp://foo/x http://spoo/y c:z"); @@ -131,12 +130,14 @@ public void testTripleCreationMapped() { assertEquals(wanted, got); } + @Test public void testPlainTripleMatches() { testMatches("S P O"); testMatches("_S _P _O"); testMatches("1 2 3"); } + @Test public void testAnyTripleMatches() { testMatches("?? P O", "Z P O"); testMatches("S ?? O", "S Q O"); @@ -155,12 +156,14 @@ private void testMatches(String pattern, String triple) { assertTrue(NodeCreateUtils.createTriple(pattern).matches(NodeCreateUtils.createTriple(triple))); } + @Test public void testPlainTripleDoesntMatch() { testMatchFails("S P O", "Z P O"); testMatchFails("S P O", "S Q O"); testMatchFails("S P O", "S P oh"); } + @Test public void testAnyTripleDoesntMatch() { testMatchFails("?? P O", "S P oh"); testMatchFails("S ?? O", "Z R O"); @@ -171,6 +174,7 @@ public void testMatchFails(String pattern, String triple) { assertFalse(NodeCreateUtils.createTriple(pattern).matches(NodeCreateUtils.createTriple(triple))); } + @Test public void testMatchesNodes() { assertTrue(NodeCreateUtils.createTriple("S P O").matches(GraphTestLib.node("S"), GraphTestLib.node("P"), GraphTestLib.node("O"))); assertTrue(NodeCreateUtils.createTriple("?? P O").matches(GraphTestLib.node("Z"), GraphTestLib.node("P"), GraphTestLib.node("O"))); @@ -182,6 +186,7 @@ public void testMatchesNodes() { assertFalse(NodeCreateUtils.createTriple("S P O").matches(GraphTestLib.node("Z"), GraphTestLib.node("P"), GraphTestLib.node("I"))); } + @Test public void testConcrete() { assertTrue(NodeCreateUtils.createTriple("S P O").isConcrete()); assertTrue(NodeCreateUtils.createTriple("S P 11").isConcrete()); @@ -202,26 +207,30 @@ public void testConcrete() { * Primarily to make sure that literals get quoted and stuff comes out in some * kind of coherent order. */ + @Test public void testTripleToStringOrdering() { Triple t1 = NodeCreateUtils.createTriple("subject predicate object"); - assertTrue("subject must be present", t1.toString().contains("subject")); - assertTrue("subject must preceed predicate", t1.toString().indexOf("subject") < t1.toString().indexOf("predicate")); - assertTrue("predicate must preceed object", t1.toString().indexOf("predicate") < t1.toString().indexOf("object")); + assertTrue(t1.toString().contains("subject"), "subject must be present"); + assertTrue(t1.toString().indexOf("subject") < t1.toString().indexOf("predicate"), "subject must preceed predicate"); + assertTrue(t1.toString().indexOf("predicate") < t1.toString().indexOf("object"), "predicate must preceed object"); } + @Test public void testTripleToStringQuoting() { Triple t1 = NodeCreateUtils.createTriple("subject predicate 'object'"); assertTrue(t1.toString().indexOf("object") > 0); } + @Test public void testTripleToStringWithPrefixing() { PrefixMapping pm = PrefixMapping.Factory.create(); pm.setNsPrefix("spoo", "eg://domain.dom/spoo#"); Triple t1 = NodeCreateUtils.createTriple("eg://domain.dom/spoo#a b c"); - // assertEquals( "spoo:a ", t1.toString( pm ) ); + // assertEquals("spoo:a ", t1.toString( pm ) ); assertEquals("spoo:a eh:/b eh:/c", t1.toString(pm)); } + @Test public void testTripleMaps() { assertEquals(GraphTestLib.node("x"), getSubject.apply(NodeCreateUtils.createTriple("x P z"))); assertEquals(GraphTestLib.node("P"), getPredicate.apply(NodeCreateUtils.createTriple("x P z"))); diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestTripleField.java b/jena-core/src/test/java/org/apache/jena/graph/TestTripleField.java index 678ac316fcf..9af0ffe59ec 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestTripleField.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestTripleField.java @@ -21,68 +21,74 @@ package org.apache.jena.graph; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.Triple.*; import org.apache.jena.test.JenaTestLib; -public class TestTripleField extends TestCase { - public TestTripleField(String name) { - super(name); - } - - public static TestSuite suite() { - return new TestSuite(TestTripleField.class); - } +public class TestTripleField { + @Test public void testFieldsExistAndAreTyped() { JenaTestLib.assertInstanceOf(Triple.Field.class, Triple.Field.fieldSubject); JenaTestLib.assertInstanceOf(Triple.Field.class, Triple.Field.fieldObject); JenaTestLib.assertInstanceOf(Triple.Field.class, Triple.Field.fieldPredicate); } + @Test public void testGetSubject() { assertEquals(GraphTestLib.node("s"), Field.fieldSubject.getField(GraphTestLib.triple("s p o"))); } + @Test public void testGetObject() { assertEquals(GraphTestLib.node("o"), Field.fieldObject.getField(GraphTestLib.triple("s p o"))); } + @Test public void testGetPredicate() { assertEquals(GraphTestLib.node("p"), Field.fieldPredicate.getField(GraphTestLib.triple("s p o"))); } + @Test public void testFilterSubject() { assertTrue(Field.fieldSubject.filterOn(GraphTestLib.node("a")).test(GraphTestLib.triple("a P b"))); assertFalse(Field.fieldSubject.filterOn(GraphTestLib.node("x")).test(GraphTestLib.triple("a P b"))); } + @Test public void testFilterObject() { assertTrue(Field.fieldObject.filterOn(GraphTestLib.node("b")).test(GraphTestLib.triple("a P b"))); assertFalse(Field.fieldObject.filterOn(GraphTestLib.node("c")).test(GraphTestLib.triple("a P b"))); } + @Test public void testFilterPredicate() { assertTrue(Field.fieldPredicate.filterOn(GraphTestLib.node("P")).test(GraphTestLib.triple("a P b"))); assertFalse(Field.fieldPredicate.filterOn(GraphTestLib.node("Q")).test(GraphTestLib.triple("a P b"))); } + @Test public void testFilterOnConcreteSubject() { assertTrue(Field.fieldSubject.filterOnConcrete(GraphTestLib.node("a")).test(GraphTestLib.triple("a P b"))); assertFalse(Field.fieldSubject.filterOnConcrete(GraphTestLib.node("x")).test(GraphTestLib.triple("a P b"))); } + @Test public void testFilterOnConcreteObject() { assertTrue(Field.fieldObject.filterOnConcrete(GraphTestLib.node("b")).test(GraphTestLib.triple("a P b"))); assertFalse(Field.fieldObject.filterOnConcrete(GraphTestLib.node("c")).test(GraphTestLib.triple("a P b"))); } + @Test public void testFilterOnConcretePredicate() { assertTrue(Field.fieldPredicate.filterOnConcrete(GraphTestLib.node("P")).test(GraphTestLib.triple("a P b"))); assertFalse(Field.fieldPredicate.filterOnConcrete(GraphTestLib.node("Q")).test(GraphTestLib.triple("a P b"))); } + @Test public void testFilterByTriple() { assertTrue(Field.fieldSubject.filterOn(GraphTestLib.triple("s P o")).test(GraphTestLib.triple("s Q p"))); assertFalse(Field.fieldSubject.filterOn(GraphTestLib.triple("s P o")).test(GraphTestLib.triple("x Q p"))); diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestTypedLiterals.java b/jena-core/src/test/java/org/apache/jena/graph/TestTypedLiterals.java index 35e2868eada..f9b81003327 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestTypedLiterals.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestTypedLiterals.java @@ -21,13 +21,15 @@ package org.apache.jena.graph; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.math.BigDecimal; import java.math.BigInteger; import java.text.SimpleDateFormat; import java.util.*; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.commons.codec.binary.Hex; import org.apache.jena.datatypes.BaseDatatype; import org.apache.jena.datatypes.DatatypeFormatException; @@ -41,13 +43,12 @@ import org.apache.jena.shared.impl.JenaParameters; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.XSD; -import org.junit.Assert; /** * Unit test for the typed literal machinery - including RDFDatatype, TypeMapper and * LiteralLabel. See also TestLiteralLabelSameValueAs */ -public class TestTypedLiterals extends TestCase { +public class TestTypedLiterals { /** dummy model used as a literal factory */ private Model m = ModelFactory.createDefaultModel(); @@ -56,20 +57,14 @@ public class TestTypedLiterals extends TestCase { /* static { Locale.setDefault(Locale.ITALY); * TimeZone.setDefault(TimeZone.getTimeZone("CEST")); } */ - public TestTypedLiterals(String name) { - super(name); - } - /** * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite(TestTypedLiterals.class); - } /** * Test the base functioning of unknown datatypes */ + @Test public void testUnknownDatatype() { String typeURI = "urn:jena-dt:unknown"; String typeURI2 = "urn:jena-dt:unknown2"; @@ -95,9 +90,9 @@ public void testUnknownDatatype() { // Check typed accessors try { l3.getInt(); - assertTrue("Allowed int conversion", false); + assertTrue(false, "Allowed int conversion"); } catch (DatatypeFormatException e) {} - assertEquals("Extract value", l1.getValue(), new BaseDatatype.TypedValue("foo", typeURI)); + assertEquals(l1.getValue(), new BaseDatatype.TypedValue("foo", typeURI), "Extract value"); JenaParameters.enableSilentAcceptanceOfUnknownDatatypes = false; boolean foundException = false; @@ -107,7 +102,7 @@ public void testUnknownDatatype() { foundException = true; } JenaParameters.enableSilentAcceptanceOfUnknownDatatypes = originalFlag; - assertTrue("Detected unknown datatype", foundException); + assertTrue(foundException, "Detected unknown datatype"); // Check we can create a literal of an unregistered java type without // anything blowing up @@ -119,6 +114,7 @@ public void testUnknownDatatype() { /** * Tests the base functioning of a user defined datatype */ + @Test public void testUserDef() { // Register the user defined type for rationals RDFDatatype rtype = RationalType.theRationalType; @@ -135,18 +131,19 @@ public void testUserDef() { assertDiffer("values should be tested!", l1, l3); // Check typed accessors - assertSame("Datatype incorrect", l1.getDatatype(), rtype); - assertEquals("Datatype uri incorrect", l1.getDatatypeURI(), RationalType.theTypeURI); + assertSame(l1.getDatatype(), rtype, "Datatype incorrect"); + assertEquals(l1.getDatatypeURI(), RationalType.theTypeURI, "Datatype uri incorrect"); Object val = l1.getValue(); - assertTrue("Value space check", val instanceof Rational); - assertTrue("Value check", ((Rational)val).getNumerator() == 3); - assertTrue("Value check", ((Rational)val).getDenominator() == 5); + assertTrue(val instanceof Rational, "Value space check"); + assertTrue(((Rational)val).getNumerator() == 3, "Value check"); + assertTrue(((Rational)val).getDenominator() == 5, "Value check"); try { l1.getInt(); - assertTrue("Allowed int conversion", false); + assertTrue(false, "Allowed int conversion"); } catch (DatatypeFormatException e) {} } + @Test public void testRDFLangString_1() { // Registration RDFDatatype dt = TypeMapper.getInstance().getTypeByName(RDF.langString.getURI()); @@ -154,6 +151,7 @@ public void testRDFLangString_1() { assertTrue(RDF.dtLangString == dt); } + @Test public void testRDFLangString_2() { // "abc"^^rdf:langString (no language tag) Literal ll1 = m.createTypedLiteral("abc", RDFLangString.rdfLangString); @@ -165,6 +163,7 @@ public void testRDFLangString_2() { /** * Tests basic XSD integer types() */ + @Test public void testXSDbasics() { String xsdIntURI = "http://www.w3.org/2001/XMLSchema#int"; @@ -174,11 +173,11 @@ public void testXSDbasics() { Literal l4 = m.createTypedLiteral("63"); // default map assertSameValueAs("Default map failed", l1, l2); - assertEquals("Value wrong", l1.getValue(), Integer.valueOf(42)); - assertEquals("class wrong", l1.getValue().getClass(), Integer.class); - assertEquals("Value accessor problem", l1.getInt(), 42); - assertEquals("wrong type name", l2.getDatatypeURI(), xsdIntURI); - assertEquals("wrong type", l2.getDatatype(), XSDDatatype.XSDint); + assertEquals(l1.getValue(), Integer.valueOf(42), "Value wrong"); + assertEquals(l1.getValue().getClass(), Integer.class, "class wrong"); + assertEquals(l1.getInt(), 42, "Value accessor problem"); + assertEquals(l2.getDatatypeURI(), xsdIntURI, "wrong type name"); + assertEquals(l2.getDatatype(), XSDDatatype.XSDint, "wrong type"); assertDiffer("Not value sensitive", l1, l4); checkIllegalLiteral("zap", XSDDatatype.XSDint); checkIllegalLiteral("42.1", XSDDatatype.XSDint); @@ -191,12 +190,12 @@ public void testXSDbasics() { l2 = m.createTypedLiteral("42.42", XSDDatatype.XSDfloat); Literal l3 = m.createTypedLiteral("42.42", XSDDatatype.XSDdouble); - assertEquals("class wrong", l1.getValue().getClass(), Double.class); + assertEquals(l1.getValue().getClass(), Double.class, "class wrong"); assertFloatEquals("value wrong", ((Double)(l1.getValue())).floatValue(), 42.42); - assertEquals("class wrong", l2.getValue().getClass(), Float.class); + assertEquals(l2.getValue().getClass(), Float.class, "class wrong"); assertFloatEquals("value wrong", ((Float)(l2.getValue())).floatValue(), 42.42); assertFloatEquals("Value accessor problem", l1.getFloat(), 42.42); - assertEquals("wrong type", l2.getDatatype(), XSDDatatype.XSDfloat); + assertEquals(l2.getDatatype(), XSDDatatype.XSDfloat, "wrong type"); assertSameValueAs("equality fn", l1, l3); // Minimal check on long, short, byte @@ -276,18 +275,19 @@ public void testXSDbasics() { checkLegalLiteral("true", XSDDatatype.XSDboolean, Boolean.class, true); checkLegalLiteral("false", XSDDatatype.XSDboolean, Boolean.class, false); l1 = m.createTypedLiteral(true); - assertEquals("boolean mapping", XSDDatatype.XSDboolean, l1.getDatatype()); + assertEquals(XSDDatatype.XSDboolean, l1.getDatatype(), "boolean mapping"); // String types checkLegalLiteral("hello world", XSDDatatype.XSDstring, String.class, "hello world"); l1 = m.createTypedLiteral("foo bar"); - assertEquals("string mapping", XSDDatatype.XSDstring, l1.getDatatype()); + assertEquals(XSDDatatype.XSDstring, l1.getDatatype(), "string mapping"); } /** * Some selected equality tests which caused problems in WG tests */ + @Test public void testMiscEquality() { Literal l1 = m.createTypedLiteral("10", "http://www.w3.org/2001/XMLSchema#integer"); Literal l3 = m.createTypedLiteral("010", "http://www.w3.org/2001/XMLSchema#integer"); @@ -303,6 +303,7 @@ public void testMiscEquality() { * Check that creating a typed literal from an object traps the interesting * special cases of String and Calendar. */ + @Test public void testOverloads() { // First case string overloads an explicit type boolean old = JenaParameters.enableEagerLiteralValidation; @@ -316,7 +317,7 @@ public void testOverloads() { } catch (DatatypeFormatException e1) { test1 = true; } - assertTrue("detected illegal string, direct", test1); + assertTrue(test1, "detected illegal string, direct"); boolean test2 = false; try { @@ -325,7 +326,7 @@ public void testOverloads() { } catch (DatatypeFormatException e2) { test2 = true; } - assertTrue("detected illegal string, overloaded", test2); + assertTrue(test2, "detected illegal string, overloaded"); // Overloading of calendar convenience functions Calendar testCal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); @@ -333,7 +334,7 @@ public void testOverloads() { testCal.set(Calendar.MILLISECOND, 0); // ms field can be undefined on // Linux Literal lc = m.createTypedLiteral((Object)testCal); - assertEquals("calendar overloading test", m.createTypedLiteral("1999-05-30T15:09:32Z", XSDDatatype.XSDdateTime), lc); + assertEquals(m.createTypedLiteral("1999-05-30T15:09:32Z", XSDDatatype.XSDdateTime), lc, "calendar overloading test"); } finally { JenaParameters.enableEagerLiteralValidation = old; @@ -343,6 +344,7 @@ public void testOverloads() { /** * Test plain literal/xsd:string/xsd:int equality operations */ + @Test public void testPlainSameValueAs() { Literal lString = m.createTypedLiteral("10", XSDDatatype.XSDstring); Literal lPlain = m.createTypedLiteral("10", (RDFDatatype)null); @@ -353,7 +355,7 @@ public void testPlainSameValueAs() { assertSameValueAs("Null type = plain literal", lPlain, lPlain2); assertSameValueAs("Null type = plain literal", lPlain, lPlain3); assertSameValueAs("Null type = plain literal", lPlain2, lPlain3); - assertEquals("null type mean xsd:string", XSDDatatype.XSDstring, lPlain3.getDatatype()); + assertEquals(XSDDatatype.XSDstring, lPlain3.getDatatype(), "null type mean xsd:string"); assertDiffer("String != int", lString, lInt); assertDiffer("Plain != int", lPlain, lInt); assertDiffer("Plain != int", lPlain2, lInt); @@ -365,6 +367,7 @@ public void testPlainSameValueAs() { /** * Test cases of numeric comparison. */ + @Test public void testNumberSameValueAs() { Literal lDouble = m.createTypedLiteral("5", XSDDatatype.XSDdouble); Literal lDouble2 = m.createTypedLiteral("5.5", XSDDatatype.XSDdouble); @@ -403,6 +406,7 @@ public void testNumberSameValueAs() { /** * Check basic handling of big integers and decimals */ + @Test public void testBigNums() { Literal l1 = m.createTypedLiteral("12345678901234567890", XSDDatatype.XSDinteger); Literal l2 = m.createTypedLiteral("12345678901234567891", XSDDatatype.XSDinteger); @@ -436,6 +440,7 @@ public void testBigNums() { * Test case for retrieving a value like 3.00 from a probe like 3.0. This test is * value sensitive. */ + @Test public void testDecimalFind() { Graph graph = GraphMemFactory.createDefaultGraphSameValue(); RDFDatatype dt = XSDDatatype.XSDdecimal; @@ -451,6 +456,7 @@ public void testDecimalFind() { /** * Test the internal machinery of decimal normalization directly */ + @Test public void testDecimalCanonicalize() { doTestDecimalCanonicalize("0.500", "0.5", BigDecimal.class); doTestDecimalCanonicalize("0.50", "0.5", BigDecimal.class); @@ -474,67 +480,73 @@ private void doTestDecimalCanonicalize(String value, String expected, Class /** * Test data/time wrappers */ + @Test public void testDateTime_1() { // Duration Literal l1 = m.createTypedLiteral("P1Y2M3DT5H6M7.50S", XSDDatatype.XSDduration); - assertEquals("duration data type", XSDDatatype.XSDduration, l1.getDatatype()); - assertEquals("duration java type", XSDDuration.class, l1.getValue().getClass()); - assertEquals("duration value", 1, ((XSDDuration)l1.getValue()).getYears()); - assertEquals("duration value", 2, ((XSDDuration)l1.getValue()).getMonths()); - assertEquals("duration value", 3, ((XSDDuration)l1.getValue()).getDays()); - assertEquals("duration value", 5, ((XSDDuration)l1.getValue()).getHours()); - assertEquals("duration value", 6, ((XSDDuration)l1.getValue()).getMinutes()); - assertEquals("duration value", 7, ((XSDDuration)l1.getValue()).getFullSeconds()); - assertEquals("duration value", BigDecimal.valueOf(75, 1), ((XSDDuration)l1.getValue()).getBigSeconds()); + assertEquals(XSDDatatype.XSDduration, l1.getDatatype(), "duration data type"); + assertEquals(XSDDuration.class, l1.getValue().getClass(), "duration java type"); + assertEquals(1, ((XSDDuration)l1.getValue()).getYears(), "duration value"); + assertEquals(2, ((XSDDuration)l1.getValue()).getMonths(), "duration value"); + assertEquals(3, ((XSDDuration)l1.getValue()).getDays(), "duration value"); + assertEquals(5, ((XSDDuration)l1.getValue()).getHours(), "duration value"); + assertEquals(6, ((XSDDuration)l1.getValue()).getMinutes(), "duration value"); + assertEquals(7, ((XSDDuration)l1.getValue()).getFullSeconds(), "duration value"); + assertEquals(BigDecimal.valueOf(75, 1), ((XSDDuration)l1.getValue()).getBigSeconds(), "duration value"); assertFloatEquals("duration value", 18367.5, ((XSDDuration)l1.getValue()).getTimePart()); - assertEquals("serialization", "P1Y2M3DT5H6M7.5S", l1.getValue().toString()); - assertTrue("equality test", l1.sameValueAs(m.createTypedLiteral("P1Y2M3DT5H6M7.5S", XSDDatatype.XSDduration))); - assertTrue("inequality test", l1 != m.createTypedLiteral("P1Y2M2DT5H6M7.5S", XSDDatatype.XSDduration)); + assertEquals("P1Y2M3DT5H6M7.5S", l1.getValue().toString(), "serialization"); + assertTrue(l1.sameValueAs(m.createTypedLiteral("P1Y2M3DT5H6M7.5S", XSDDatatype.XSDduration)), "equality test"); + assertTrue(l1 != m.createTypedLiteral("P1Y2M2DT5H6M7.5S", XSDDatatype.XSDduration), "inequality test"); } + @Test public void testDateTime_2() { Literal l1 = m.createTypedLiteral("P1Y2M3DT5H0M", XSDDatatype.XSDduration); - assertEquals("serialization", "P1Y2M3DT5H", l1.getValue().toString()); + assertEquals("P1Y2M3DT5H", l1.getValue().toString(), "serialization"); } + @Test public void testDateTime_3() { Literal l1 = m.createTypedLiteral("P1Y", XSDDatatype.XSDduration); - assertEquals("duration data type", XSDDatatype.XSDduration, l1.getDatatype()); - assertEquals("duration java type", XSDDuration.class, l1.getValue().getClass()); - assertEquals("duration value", 1, ((XSDDuration)l1.getValue()).getYears()); - assertEquals("serialization", "P1Y", l1.getValue().toString()); - assertTrue("equality test", l1.sameValueAs(m.createTypedLiteral("P1Y", XSDDatatype.XSDduration))); - assertTrue("inequality test", l1 != m.createTypedLiteral("P1Y", XSDDatatype.XSDduration)); + assertEquals(XSDDatatype.XSDduration, l1.getDatatype(), "duration data type"); + assertEquals(XSDDuration.class, l1.getValue().getClass(), "duration java type"); + assertEquals(1, ((XSDDuration)l1.getValue()).getYears(), "duration value"); + assertEquals("P1Y", l1.getValue().toString(), "serialization"); + assertTrue(l1.sameValueAs(m.createTypedLiteral("P1Y", XSDDatatype.XSDduration)), "equality test"); + assertTrue(l1 != m.createTypedLiteral("P1Y", XSDDatatype.XSDduration), "inequality test"); } + @Test public void testDateTime_4() { Literal l1 = m.createTypedLiteral("-P120D", XSDDatatype.XSDduration); Literal l2 = m.createTypedLiteral(l1.getValue()); assertEquals("-P120D", l2.getLexicalForm()); } + @Test public void testDateTime_5() { Literal d1 = m.createTypedLiteral("PT1H1M1S", XSDDatatype.XSDduration); Literal d2 = m.createTypedLiteral("PT1H1M1.1S", XSDDatatype.XSDduration); - assertTrue("duration compare", !d1.sameValueAs(d2)); + assertTrue(!d1.sameValueAs(d2), "duration compare"); XSDDuration dur1 = (XSDDuration)d1.getValue(); XSDDuration dur2 = (XSDDuration)d2.getValue(); - assertEquals("duration compare order", 1, dur2.compare(dur1)); + assertEquals(1, dur2.compare(dur1), "duration compare order"); } + @Test public void testDateTime_6() { // dateTime Literal l1 = m.createTypedLiteral("1999-05-31T02:09:32Z", XSDDatatype.XSDdateTime); XSDDateTime xdt = (XSDDateTime)l1.getValue(); - assertEquals("dateTime data type", XSDDatatype.XSDdateTime, l1.getDatatype()); - assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); - assertEquals("dateTime value", 1999, xdt.getYears()); - assertEquals("dateTime value", 5, xdt.getMonths()); - assertEquals("dateTime value", 31, xdt.getDays()); - assertEquals("dateTime value", 2, xdt.getHours()); - assertEquals("dateTime value", 9, xdt.getMinutes()); - assertEquals("dateTime value", 32, xdt.getFullSeconds()); - assertEquals("serialization", "1999-05-31T02:09:32Z", l1.getValue().toString()); + assertEquals(XSDDatatype.XSDdateTime, l1.getDatatype(), "dateTime data type"); + assertEquals(XSDDateTime.class, l1.getValue().getClass(), "dateTime java type"); + assertEquals(1999, xdt.getYears(), "dateTime value"); + assertEquals(5, xdt.getMonths(), "dateTime value"); + assertEquals(31, xdt.getDays(), "dateTime value"); + assertEquals(2, xdt.getHours(), "dateTime value"); + assertEquals(9, xdt.getMinutes(), "dateTime value"); + assertEquals(32, xdt.getFullSeconds(), "dateTime value"); + assertEquals("1999-05-31T02:09:32Z", l1.getValue().toString(), "serialization"); Calendar cal = xdt.asCalendar(); Calendar testCal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); testCal.set(1999, 4, 31, 2, 9, 32); @@ -548,21 +560,22 @@ public void testDateTime_6() { * testCal.get(Calendar.MINUTE) ); assertEquals("calendar value", * cal.get(Calendar.SECOND), testCal.get(Calendar.SECOND) ); */ testCal.set(Calendar.MILLISECOND, 0); // ms field can be undefined on Linux - assertEquals("calendar value", cal, testCal); - assertEquals("equality test", l1, m.createTypedLiteral("1999-05-31T02:09:32Z", XSDDatatype.XSDdateTime)); - assertTrue("inequality test", l1 != m.createTypedLiteral("1999-04-31T02:09:32Z", XSDDatatype.XSDdateTime)); + assertEquals(cal, testCal, "calendar value"); + assertEquals(l1, m.createTypedLiteral("1999-05-31T02:09:32Z", XSDDatatype.XSDdateTime), "equality test"); + assertTrue(l1 != m.createTypedLiteral("1999-04-31T02:09:32Z", XSDDatatype.XSDdateTime), "inequality test"); Calendar testCal2 = new GregorianCalendar(TimeZone.getTimeZone("GMT")); testCal2.set(1999, 4, 30, 15, 9, 32); testCal2.set(Calendar.MILLISECOND, 0); // ms field can be undefined on // Linux Literal lc = m.createTypedLiteral(testCal2); - assertEquals("calendar 24 hour test", m.createTypedLiteral("1999-05-30T15:09:32Z", XSDDatatype.XSDdateTime), lc); + assertEquals(m.createTypedLiteral("1999-05-30T15:09:32Z", XSDDatatype.XSDdateTime), lc, "calendar 24 hour test"); - assertEquals("calendar value", cal, testCal); - assertEquals("equality test", l1, m.createTypedLiteral("1999-05-31T02:09:32Z", XSDDatatype.XSDdateTime)); + assertEquals(cal, testCal, "calendar value"); + assertEquals(l1, m.createTypedLiteral("1999-05-31T02:09:32Z", XSDDatatype.XSDdateTime), "equality test"); } + @Test public void testDateTime_7() { Calendar testCal3 = new GregorianCalendar(TimeZone.getTimeZone("GMT")); testCal3.clear(); @@ -579,9 +592,10 @@ public void testDateTime_7() { Resource r1 = m.getResource(uri1); Property p = m.getProperty(urip); XSDDateTime returnedDateTime = (XSDDateTime)r1.getProperty(p).getLiteral().getValue(); - assertEquals("deserialized calendar value", testCal3, returnedDateTime.asCalendar()); + assertEquals(testCal3, returnedDateTime.asCalendar(), "deserialized calendar value"); } + @Test public void testDateTime_8() { // dateTime to calendar with milliseconds Calendar testCal4 = new GregorianCalendar(TimeZone.getTimeZone("GMT")); @@ -597,13 +611,14 @@ public void testDateTime_8() { // Internal helper private void doDateTimeTest(Calendar cal, String lex, double time) { Literal lc4 = m.createTypedLiteral(cal); - assertEquals("serialization", lex, lc4.getValue().toString()); - assertEquals("calendar ms test", m.createTypedLiteral(lex, XSDDatatype.XSDdateTime), lc4); + assertEquals(lex, lc4.getValue().toString(), "serialization"); + assertEquals(m.createTypedLiteral(lex, XSDDatatype.XSDdateTime), lc4, "calendar ms test"); XSDDateTime dt4 = (XSDDateTime)lc4.getValue(); - assertTrue("Fraction time check", Math.abs(dt4.getSeconds() - time) < 0.0001); + assertTrue(Math.abs(dt4.getSeconds() - time) < 0.0001, "Fraction time check"); assertEquals(dt4.asCalendar(), cal); } + @Test public void testDateTime_9() { // Years before 1000 : xsd:dateTime requires at least a four digit year. // GregorianCalendar does not handle negative years. (.get(YEAR) triggers @@ -617,8 +632,8 @@ public void testDateTime_9() { XSDDateTime xdtM = new XSDDateTime(calM1); LiteralLabel xdtM_ll = LiteralLabelFactory.createByValue(xdtM, XSDDatatype.XSDdateTime); - assertTrue("Pre-1000 calendar value", xdtM_ll.isWellFormed()); - assertTrue("Pre-1000 calendar value", xdtM_ll.getLexicalForm().matches("^[0-9]{4}-.*")); + assertTrue(xdtM_ll.isWellFormed(), "Pre-1000 calendar value"); + assertTrue(xdtM_ll.getLexicalForm().matches("^[0-9]{4}-.*"), "Pre-1000 calendar value"); } // Illegal dateTimes boolean ok = false; @@ -631,126 +646,135 @@ public void testDateTime_9() { } finally { JenaParameters.enableEagerLiteralValidation = old; } - assertTrue("Early detection of invalid literals", ok); + assertTrue(ok, "Early detection of invalid literals"); } // date + @Test public void testDateTime_10() { Literal l1 = m.createTypedLiteral("1999-05-31", XSDDatatype.XSDdate); - assertEquals("dateTime data type", XSDDatatype.XSDdate, l1.getDatatype()); - assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); + assertEquals(XSDDatatype.XSDdate, l1.getDatatype(), "dateTime data type"); + assertEquals(XSDDateTime.class, l1.getValue().getClass(), "dateTime java type"); XSDDateTime xdt = (XSDDateTime)l1.getValue(); - assertEquals("dateTime value", 1999, xdt.getYears()); - assertEquals("dateTime value", 5, xdt.getMonths()); - assertEquals("dateTime value", 31, xdt.getDays()); + assertEquals(1999, xdt.getYears(), "dateTime value"); + assertEquals(5, xdt.getMonths(), "dateTime value"); + assertEquals(31, xdt.getDays(), "dateTime value"); try { xdt.getHours(); - assertTrue("Failed to prevent illegal access", false); + assertTrue(false, "Failed to prevent illegal access"); } catch (IllegalDateTimeFieldException e) {} } // time + @Test public void testDateTime_11() { Literal l1 = m.createTypedLiteral("12:56:32", XSDDatatype.XSDtime); - assertEquals("dateTime data type", XSDDatatype.XSDtime, l1.getDatatype()); - assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); + assertEquals(XSDDatatype.XSDtime, l1.getDatatype(), "dateTime data type"); + assertEquals(XSDDateTime.class, l1.getValue().getClass(), "dateTime java type"); XSDDateTime xdt = (XSDDateTime)l1.getValue(); - assertEquals("dateTime value", 12, xdt.getHours()); - assertEquals("dateTime value", 56, xdt.getMinutes()); - assertEquals("dateTime value", 32, xdt.getFullSeconds()); + assertEquals(12, xdt.getHours(), "dateTime value"); + assertEquals(56, xdt.getMinutes(), "dateTime value"); + assertEquals(32, xdt.getFullSeconds(), "dateTime value"); try { xdt.getDays(); - assertTrue("Failed to prevent illegal access", false); + assertTrue(false, "Failed to prevent illegal access"); } catch (IllegalDateTimeFieldException e) {} } // gYearMonth + @Test public void testDateTime_12() { Literal l1 = m.createTypedLiteral("1999-05", XSDDatatype.XSDgYearMonth); - assertEquals("dateTime data type", XSDDatatype.XSDgYearMonth, l1.getDatatype()); - assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); + assertEquals(XSDDatatype.XSDgYearMonth, l1.getDatatype(), "dateTime data type"); + assertEquals(XSDDateTime.class, l1.getValue().getClass(), "dateTime java type"); XSDDateTime xdt = (XSDDateTime)l1.getValue(); - assertEquals("dateTime value", 1999, xdt.getYears()); - assertEquals("dateTime value", 5, xdt.getMonths()); + assertEquals(1999, xdt.getYears(), "dateTime value"); + assertEquals(5, xdt.getMonths(), "dateTime value"); try { xdt.getDays(); - assertTrue("Failed to prevent illegal access", false); + assertTrue(false, "Failed to prevent illegal access"); } catch (IllegalDateTimeFieldException e) {} // gYear } + @Test public void testDateTime_13() { Literal l1 = m.createTypedLiteral("1999", XSDDatatype.XSDgYear); - assertEquals("dateTime data type", XSDDatatype.XSDgYear, l1.getDatatype()); - assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); + assertEquals(XSDDatatype.XSDgYear, l1.getDatatype(), "dateTime data type"); + assertEquals(XSDDateTime.class, l1.getValue().getClass(), "dateTime java type"); XSDDateTime xdt = (XSDDateTime)l1.getValue(); - assertEquals("dateTime value", 1999, xdt.getYears()); + assertEquals(1999, xdt.getYears(), "dateTime value"); try { xdt.getMonths(); - assertTrue("Failed to prevent illegal access", false); + assertTrue(false, "Failed to prevent illegal access"); } catch (IllegalDateTimeFieldException e) {} // gMonth } + @Test public void testDateTime_14() { Literal l1 = m.createTypedLiteral("--05--", XSDDatatype.XSDgMonth); - assertEquals("dateTime data type", XSDDatatype.XSDgMonth, l1.getDatatype()); - assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); + assertEquals(XSDDatatype.XSDgMonth, l1.getDatatype(), "dateTime data type"); + assertEquals(XSDDateTime.class, l1.getValue().getClass(), "dateTime java type"); XSDDateTime xdt = (XSDDateTime)l1.getValue(); - assertEquals("dateTime value", 5, xdt.getMonths()); + assertEquals(5, xdt.getMonths(), "dateTime value"); try { xdt.getYears(); - assertTrue("Failed to prevent illegal access", false); + assertTrue(false, "Failed to prevent illegal access"); } catch (IllegalDateTimeFieldException e) {} } // gMonthDay + @Test public void testDateTime_15() { Literal l1 = m.createTypedLiteral("--05-25", XSDDatatype.XSDgMonthDay); - assertEquals("dateTime data type", XSDDatatype.XSDgMonthDay, l1.getDatatype()); - assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); + assertEquals(XSDDatatype.XSDgMonthDay, l1.getDatatype(), "dateTime data type"); + assertEquals(XSDDateTime.class, l1.getValue().getClass(), "dateTime java type"); XSDDateTime xdt = (XSDDateTime)l1.getValue(); - assertEquals("dateTime value", 5, xdt.getMonths()); - assertEquals("dateTime value", 25, xdt.getDays()); + assertEquals(5, xdt.getMonths(), "dateTime value"); + assertEquals(25, xdt.getDays(), "dateTime value"); try { xdt.getYears(); - assertTrue("Failed to prevent illegal access", false); + assertTrue(false, "Failed to prevent illegal access"); } catch (IllegalDateTimeFieldException e) {} } // gDay + @Test public void testDateTime_16() { Literal l1 = m.createTypedLiteral("---25", XSDDatatype.XSDgDay); - assertEquals("dateTime data type", XSDDatatype.XSDgDay, l1.getDatatype()); - assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); + assertEquals(XSDDatatype.XSDgDay, l1.getDatatype(), "dateTime data type"); + assertEquals(XSDDateTime.class, l1.getValue().getClass(), "dateTime java type"); XSDDateTime xdt = (XSDDateTime)l1.getValue(); - assertEquals("dateTime value", 25, xdt.getDays()); + assertEquals(25, xdt.getDays(), "dateTime value"); try { xdt.getMonths(); - assertTrue("Failed to prevent illegal access", false); + assertTrue(false, "Failed to prevent illegal access"); } catch (IllegalDateTimeFieldException e) {} } + @Test public void testDateTime_17() { // Creation of datetime from a date object Calendar ncal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); ncal.set(2003, 11, 8, 10, 50, 42); ncal.set(Calendar.MILLISECOND, 0); Literal l1 = m.createTypedLiteral(ncal); - assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); - assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); - assertEquals("DateTime from date", "2003-12-08T10:50:42Z", l1.getValue().toString()); + assertEquals(XSDDatatype.XSDdateTime, l1.getDatatype(), "DateTime from date"); + assertEquals(XSDDateTime.class, l1.getValue().getClass(), "DateTime from date"); + assertEquals("2003-12-08T10:50:42Z", l1.getValue().toString(), "DateTime from date"); } // Thanks to Greg Shueler for DST patch and test case ////// some of below code from java.util.GregorianCalendar javadoc/////// // create a Pacific Standard Time time zone + @Test public void testDateTime_18() { SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "America/Los_Angeles"); @@ -763,24 +787,25 @@ public void testDateTime_18() { ncal.set(Calendar.MILLISECOND, 0); // System.err.println("cal is: "+ncal); Literal l1 = m.createTypedLiteral(ncal); - assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); - assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); - assertEquals("DateTime from date", "2004-03-21T20:50:42Z", l1.getValue().toString()); + assertEquals(XSDDatatype.XSDdateTime, l1.getDatatype(), "DateTime from date"); + assertEquals(XSDDateTime.class, l1.getValue().getClass(), "DateTime from date"); + assertEquals("2004-03-21T20:50:42Z", l1.getValue().toString(), "DateTime from date"); // System.err.println("date is: "+ncal.getTime()); ncal = new GregorianCalendar(pdt); ncal.set(2004, 03, 21, 12, 50, 42);// within daylight savings time ncal.set(Calendar.MILLISECOND, 0); // System.err.println("cal is: "+ncal); l1 = m.createTypedLiteral(ncal); - assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); - assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); - assertEquals("DateTime from date", "2004-04-21T19:50:42Z", l1.getValue().toString()); + assertEquals(XSDDatatype.XSDdateTime, l1.getDatatype(), "DateTime from date"); + assertEquals(XSDDateTime.class, l1.getValue().getClass(), "DateTime from date"); + assertEquals("2004-04-21T19:50:42Z", l1.getValue().toString(), "DateTime from date"); // System.err.println("date is: "+ncal.getTime()); } /** * Test query applied to graphs containing typed values */ + @Test public void testTypedContains() { Model model = ModelFactory.createModelSameValue(); Property p = model.createProperty("urn:x-eg/p"); @@ -798,6 +823,7 @@ public void testTypedContains() { /** * Test the isValidLiteral machinery */ + @Test public void testIsValidLiteral() { Literal l = m.createTypedLiteral("1000", XSDDatatype.XSDinteger); LiteralLabel ll = l.asNode().getLiteral(); @@ -863,11 +889,13 @@ public void testIsValidLiteral() { } // These should not be used in data but we test they don't crash anything. + @Test public void testIsValidLiteral1() { Literal lit = m.createTypedLiteral("100", XSDDatatype.XSD + "#anyType"); assertFalse(XSDDatatype.XSDinteger.isValidLiteral(lit.asNode().getLiteral())); } + @Test public void testIsValidLiteral2() { Literal lit = m.createTypedLiteral("100", XSDDatatype.XSD + "#anySimpleType"); assertFalse(XSDDatatype.XSDinteger.isValidLiteral(lit.asNode().getLiteral())); @@ -878,96 +906,103 @@ public void testIsValidLiteral2() { /** * Test binary types base64 and hexbinary */ + @Test public void testBinary1() { // Check byte[] maps onto a binary type - specifically base64Binary. byte[] data = new byte[]{12, 42, 99}; Literal l = m.createTypedLiteral(data); LiteralLabel ll = l.asNode().getLiteral(); - assertTrue("binary test 1", ll.getDatatype() instanceof XSDbinary); + assertTrue(ll.getDatatype() instanceof XSDbinary, "binary test 1"); // base64 is registered for byte[] // hexBinary is not registered as a type for byte[] - assertTrue("binary test 1a", ll.getDatatype() instanceof XSDbase64Binary); - assertEquals("binary test 1b", "DCpj", ll.getLexicalForm()); + assertTrue(ll.getDatatype() instanceof XSDbase64Binary, "binary test 1a"); + assertEquals("DCpj", ll.getLexicalForm(), "binary test 1b"); } + @Test public void testBinary2() { // Check round tripping from value LiteralLabel l2 = m.createTypedLiteral("DCpj", XSDDatatype.XSDbase64Binary).asNode().getLiteral(); Object data2 = l2.getValue(); - assertTrue("binary test 3", data2 instanceof byte[]); + assertTrue(data2 instanceof byte[], "binary test 3"); byte[] data2b = (byte[])data2; - assertEquals("binary test 4", data2b[0], data[0]); - assertEquals("binary test 5", data2b[1], data[1]); - assertEquals("binary test 6", data2b[2], data[2]); + assertEquals(data2b[0], data[0], "binary test 4"); + assertEquals(data2b[1], data[1], "binary test 5"); + assertEquals(data2b[2], data[2], "binary test 6"); } + @Test public void testBinary3() { // Check hexBinary Literal l = m.createTypedLiteral(data, XSDDatatype.XSDhexBinary); LiteralLabel ll = l.asNode().getLiteral(); - assertEquals("binary test 1b", ll.getDatatype(), XSDDatatype.XSDhexBinary); - assertEquals("binary test 2b", Hex.encodeHexString(data, false), ll.getLexicalForm()); + assertEquals(ll.getDatatype(), XSDDatatype.XSDhexBinary, "binary test 1b"); + assertEquals(Hex.encodeHexString(data, false), ll.getLexicalForm(), "binary test 2b"); // Check round tripping from value LiteralLabel l2 = m.createTypedLiteral(ll.getLexicalForm(), XSDDatatype.XSDhexBinary).asNode().getLiteral(); Object data2 = l2.getValue(); - assertTrue("binary test 3b", data2 instanceof byte[]); + assertTrue(data2 instanceof byte[], "binary test 3b"); byte[] data2b = ((byte[])data2); - assertEquals("binary test 4b", data2b[0], data[0]); - assertEquals("binary test 5b", data2b[1], data[1]); - assertEquals("binary test 6b", data2b[2], data[2]); + assertEquals(data2b[0], data[0], "binary test 4b"); + assertEquals(data2b[1], data[1], "binary test 5b"); + assertEquals(data2b[2], data[2], "binary test 6b"); assertEquals(l2, ll); } + @Test public void testBinary4() { Literal la = m.createTypedLiteral("GpM7", XSDDatatype.XSDbase64Binary); Literal lb = m.createTypedLiteral("GpM7", XSDDatatype.XSDbase64Binary); la.sameValueAs(lb); - assertTrue("equality test", la.sameValueAs(lb)); + assertTrue(la.sameValueAs(lb), "equality test"); data = new byte[]{15, (byte)0xB7}; Literal l = m.createTypedLiteral(data, XSDDatatype.XSDhexBinary); - assertEquals("hexBinary encoding", "0FB7", l.getLexicalForm()); + assertEquals("0FB7", l.getLexicalForm(), "hexBinary encoding"); } + @Test public void testBinaryIndexing1() { Literal x1 = m.createTypedLiteral("", XSDDatatype.XSDbase64Binary); Literal x2 = m.createTypedLiteral("", XSDDatatype.XSDbase64Binary); - assertEquals("base64Binary indexing hashCode", x1.asNode().getIndexingValue().hashCode(), - x2.asNode().getIndexingValue().hashCode()); - assertEquals("base64Binary indexing", x1.asNode().getIndexingValue(), x2.asNode().getIndexingValue()); + assertEquals(x1.asNode().getIndexingValue().hashCode(), x2.asNode().getIndexingValue().hashCode(), "base64Binary indexing hashCode"); + assertEquals(x1.asNode().getIndexingValue(), x2.asNode().getIndexingValue(), "base64Binary indexing"); } + @Test public void testBinaryIndexing2() { Literal x1 = m.createTypedLiteral("GpM7", XSDDatatype.XSDbase64Binary); Literal x2 = m.createTypedLiteral("GpM7", XSDDatatype.XSDbase64Binary); - assertEquals("base64Binary indexing hashCode", x1.asNode().getIndexingValue().hashCode(), - x2.asNode().getIndexingValue().hashCode()); - assertEquals("base64Binary indexing", x1.asNode().getIndexingValue(), x2.asNode().getIndexingValue()); + assertEquals(x1.asNode().getIndexingValue().hashCode(), x2.asNode().getIndexingValue().hashCode(), "base64Binary indexing hashCode"); + assertEquals(x1.asNode().getIndexingValue(), x2.asNode().getIndexingValue(), "base64Binary indexing"); } + @Test public void testBinaryIndexing3() { Literal x1 = m.createTypedLiteral("", XSDDatatype.XSDhexBinary); Literal x2 = m.createTypedLiteral("", XSDDatatype.XSDhexBinary); - assertEquals("hexBinary indexing hashCode", x1.asNode().getIndexingValue().hashCode(), x2.asNode().getIndexingValue().hashCode()); - assertEquals("hexBinary indexing", x1.asNode().getIndexingValue(), x2.asNode().getIndexingValue()); + assertEquals(x1.asNode().getIndexingValue().hashCode(), x2.asNode().getIndexingValue().hashCode(), "hexBinary indexing hashCode"); + assertEquals(x1.asNode().getIndexingValue(), x2.asNode().getIndexingValue(), "hexBinary indexing"); } + @Test public void testBinaryIndexing4() { Literal x1 = m.createTypedLiteral("AABB", XSDDatatype.XSDhexBinary); Literal x2 = m.createTypedLiteral("AABB", XSDDatatype.XSDhexBinary); - assertEquals("hexBinary indexing hashCode", x1.asNode().getIndexingValue().hashCode(), x2.asNode().getIndexingValue().hashCode()); - assertEquals("hexBinary indexing", x1.asNode().getIndexingValue(), x2.asNode().getIndexingValue()); + assertEquals(x1.asNode().getIndexingValue().hashCode(), x2.asNode().getIndexingValue().hashCode(), "hexBinary indexing hashCode"); + assertEquals(x1.asNode().getIndexingValue(), x2.asNode().getIndexingValue(), "hexBinary indexing"); } /** * Test that XSD anyURI is not sameValueAs XSD string (Xerces returns a string as * the value for both) */ + @Test public void testXSDanyURI() { Node node1 = NodeFactory.createLiteralDT("http://example/", XSDDatatype.XSDanyURI); Node node2 = NodeFactory.createLiteralDT("http://example/", XSDDatatype.XSDstring); @@ -977,15 +1012,17 @@ public void testXSDanyURI() { /** * Test a user error report concerning date/time literals from JENA-1503 */ + @Test public void testDateTimeBug3() { final String testLex = "-0001-02-03T04:05:06"; Node n = NodeFactory.createLiteralDT(testLex, XSDDatatype.XSDdateTime); - assertEquals("Got wrong XSDDateTime representation!", testLex, n.getLiteralValue().toString()); + assertEquals(testLex, n.getLiteralValue().toString(), "Got wrong XSDDateTime representation!"); } /** * Test a user error report concerning date/time literals */ + @Test public void testDateTimeBug() { // Bug in serialization String XSDDateURI = XSD.date.getURI(); @@ -1030,6 +1067,7 @@ private static Date getDateFromPattern(String ts, String[] formats, TimeZone tz) return date; } + @Test public void testDateTimeBug2() throws Exception { String[] timezonelist = {"GMT", "America/New_York", "America/Chicago",}; @@ -1056,7 +1094,7 @@ public void testDateTimeBug2() throws Exception { int xhr = xdt.getHours(); int dhr = cal.get(Calendar.HOUR_OF_DAY); int dif = (xhr - dhr + offset) % 24; - Assert.assertEquals("Difference between cal and xdt", 0, dif); + assertEquals(0, dif, "Difference between cal and xdt"); // //System.out.println("xhr="+xhr+",dhr="+dhr+",dif="+dif); // System.out.println("" @@ -1073,6 +1111,7 @@ public void testDateTimeBug2() throws Exception { /** * Test global parameter flags. */ + @Test public void testFlags() { boolean originalFlag = JenaParameters.enableEagerLiteralValidation; JenaParameters.enableEagerLiteralValidation = true; @@ -1083,7 +1122,7 @@ public void testFlags() { foundException = true; } JenaParameters.enableEagerLiteralValidation = originalFlag; - assertTrue("Early datatype format exception", foundException); + assertTrue(foundException, "Early datatype format exception"); JenaParameters.enableEagerLiteralValidation = false; foundException = false; @@ -1092,7 +1131,7 @@ public void testFlags() { l = m.createTypedLiteral("fool", XSDDatatype.XSDint); } catch (DatatypeFormatException e1) { JenaParameters.enableEagerLiteralValidation = originalFlag; - assertTrue("Delayed datatype format validation", false); + assertTrue(false, "Delayed datatype format validation"); } try { l.getValue(); @@ -1100,20 +1139,21 @@ public void testFlags() { foundException = true; } JenaParameters.enableEagerLiteralValidation = originalFlag; - assertTrue("Early datatype format exception", foundException); + assertTrue(foundException, "Early datatype format exception"); } /** * Test that equality function takes lexical distinction into account. */ + @Test public void testLexicalDistinction() { Literal l1 = m.createTypedLiteral("3.0", XSDDatatype.XSDdecimal); Literal l2 = m.createTypedLiteral("3.00", XSDDatatype.XSDdecimal); Literal l3 = m.createTypedLiteral("3.0", XSDDatatype.XSDdecimal); assertSameValueAs("lexical form does not affect value", l1, l2); assertSameValueAs("lexical form does not affect value", l3, l2); - assertTrue("lexical form affects equality", !l1.equals(l2)); - assertTrue("lexical form affects equality", l1.equals(l3)); + assertTrue(!l1.equals(l2), "lexical form affects equality"); + assertTrue(l1.equals(l3), "lexical form affects equality"); // This version will become illegal in the future and will be removed then l1 = m.createTypedLiteral("3", XSDDatatype.XSDint); @@ -1121,13 +1161,14 @@ public void testLexicalDistinction() { l3 = m.createTypedLiteral("3", XSDDatatype.XSDint); assertSameValueAs("lexical form does not affect value", l1, l2); assertSameValueAs("lexical form does not affect value", l3, l2); - assertTrue("lexical form affects equality", !l1.equals(l2)); - assertTrue("lexical form affects equality", l1.equals(l3)); + assertTrue(!l1.equals(l2), "lexical form affects equality"); + assertTrue(l1.equals(l3), "lexical form affects equality"); } /** * Test parse/unparse pairing for problem datatypes */ + @Test public void testRoundTrip() { // Prior problem cases with unparsing doTestRoundTrip("13:20:00.000", XSDDatatype.XSDtime, false); @@ -1161,17 +1202,18 @@ public void doTestValueRoundTrip(String lex, RDFDatatype dt, boolean testType) { Literal l1 = m.createTypedLiteral(lex, dt); Object o1 = l1.getValue(); Literal l2 = m.createTypedLiteral(o1); - assertTrue("value round trip", l1.sameValueAs(l2)); + assertTrue(l1.sameValueAs(l2), "value round trip"); Object o2 = l2.getValue(); - assertTrue("value round trip2", o1.equals(o2)); + assertTrue(o1.equals(o2), "value round trip2"); if ( testType ) { - assertEquals("Datatype round trip", dt, l2.getDatatype()); + assertEquals(dt, l2.getDatatype(), "Datatype round trip"); } } /** * Test ability to override an apparent DateTime to be just a date */ + @Test public void testDateOverride() { Calendar date = new GregorianCalendar(2007, 3, 4); date.setTimeZone(TimeZone.getTimeZone("GMT+0")); @@ -1186,21 +1228,21 @@ public void testDateOverride() { * Test that two objects are not semantically the same */ private void assertDiffer(String title, Literal x, Literal y) { - assertTrue(title, !x.sameValueAs(y)); + assertTrue(!x.sameValueAs(y), title); } /** * Test that two objects are semantically the same */ private void assertSameValueAs(String title, Literal x, Literal y) { - assertTrue(title, x.sameValueAs(y)); + assertTrue(x.sameValueAs(y), title); } /** * Test two doubles are equal to within 0.001 */ private void assertFloatEquals(String title, double x, double y) { - assertTrue(title, Math.abs(x - y) < 0.001); + assertTrue(Math.abs(x - y) < 0.001, title); } /** @@ -1210,7 +1252,7 @@ public void checkIllegalLiteral(String lex, RDFDatatype dtype) { try { Literal l = m.createTypedLiteral(lex, dtype); l.getValue(); - assertTrue("Failed to catch '" + lex + "' as an illegal " + dtype, false); + assertTrue(false, "Failed to catch '" + lex + "' as an illegal " + dtype); } catch (DatatypeFormatException e1) { // OK this is what we expected } diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping.java b/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping.java index 32d874b0612..23238ed71c2 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping.java @@ -21,11 +21,14 @@ package org.apache.jena.graph.compose; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.TestCase; import org.apache.jena.shared.PrefixMapping; import org.apache.jena.test.JenaTestLib; @@ -34,10 +37,7 @@ * prefixMapping to be tested. */ -public abstract class AbstractTestPrefixMapping extends TestCase { - public AbstractTestPrefixMapping(String name) { - super(name); - } +public abstract class AbstractTestPrefixMapping { /** * Subclasses implement to return a new, empty prefixMapping of their preferred @@ -52,14 +52,17 @@ public AbstractTestPrefixMapping(String name) { /** * The empty prefix is specifically allowed [for the default namespace]. */ + @Test public void testEmptyPrefix() { addGetTest("", crispURI); } + @Test public void testStrPrefix1() { addGetTest("abc", "http://example/"); } + @Test public void testStrPrefix2() { // U+1F607 - smiling face with halo String prefix = new String(Character.toChars(0x1F607)); @@ -77,6 +80,7 @@ private void addGetTest(String prefix, String uri) { /** * Test that various illegal names are trapped. */ + @Test public void testCheckNames() { PrefixMapping ns = getMapping(); for ( String bad : badNames ) { @@ -89,6 +93,7 @@ public void testCheckNames() { } } + @Test public void testNullURITrapped() { try { getMapping().setNsPrefix("xy", null); @@ -102,24 +107,25 @@ public void testNullURITrapped() { * test that a PrefixMapping maps names to URIs. The names and URIs are all fully * distinct - overlapping names/uris are dealt with in other tests. */ + @Test public void testPrefixMappingMapping() { String toast = "ftp://ftp.nowhere.not/"; JenaTestLib.assertDiffer("crisp and toast must differ", crispURI, toast); /* */ PrefixMapping ns = getMapping(); - assertEquals("crisp should be unset", null, ns.getNsPrefixURI("crisp")); - assertEquals("toast should be unset", null, ns.getNsPrefixURI("toast")); - assertEquals("butter should be unset", null, ns.getNsPrefixURI("butter")); + assertEquals(null, ns.getNsPrefixURI("crisp"), "crisp should be unset"); + assertEquals(null, ns.getNsPrefixURI("toast"), "toast should be unset"); + assertEquals(null, ns.getNsPrefixURI("butter"), "butter should be unset"); /* */ ns.setNsPrefix("crisp", crispURI); - assertEquals("crisp should be set", crispURI, ns.getNsPrefixURI("crisp")); - assertEquals("toast should still be unset", null, ns.getNsPrefixURI("toast")); - assertEquals("butter should still be unset", null, ns.getNsPrefixURI("butter")); + assertEquals(crispURI, ns.getNsPrefixURI("crisp"), "crisp should be set"); + assertEquals(null, ns.getNsPrefixURI("toast"), "toast should still be unset"); + assertEquals(null, ns.getNsPrefixURI("butter"), "butter should still be unset"); /* */ ns.setNsPrefix("toast", toast); - assertEquals("crisp should be set", crispURI, ns.getNsPrefixURI("crisp")); - assertEquals("toast should be set", toast, ns.getNsPrefixURI("toast")); - assertEquals("butter should still be unset", null, ns.getNsPrefixURI("butter")); + assertEquals(crispURI, ns.getNsPrefixURI("crisp"), "crisp should be set"); + assertEquals(toast, ns.getNsPrefixURI("toast"), "toast should be set"); + assertEquals(null, ns.getNsPrefixURI("butter"), "butter should still be unset"); } /** @@ -127,6 +133,7 @@ public void testPrefixMappingMapping() { * uriB is a prefix of uriA to try and ensure that the ordering of the map * doesn't matter. */ + @Test public void testReversePrefixMapping() { PrefixMapping ns = getMapping(); String uriA = "http://jena.hpl.hp.com/A#", uriB = "http://jena.hpl.hp.com/"; @@ -141,10 +148,11 @@ public void testReversePrefixMapping() { /** * test that we can extract a proper Map from a PrefixMapping */ + @Test public void testPrefixMappingMap() { PrefixMapping ns = getCrispyRope(); Map map = ns.getNsPrefixMap(); - assertEquals("map should have two elements", 2, map.size()); + assertEquals(2, map.size(), "map should have two elements"); assertEquals(crispURI, map.get("crisp")); assertEquals("scheme:rope/string#", map.get("rope")); } @@ -153,6 +161,7 @@ public void testPrefixMappingMap() { * test that the Map returned by getNsPrefixMap does not alias (parts of) the * secret internal map of the PrefixMapping */ + @Test public void testPrefixMappingSecret() { PrefixMapping ns = getCrispyRope(); Map map = ns.getNsPrefixMap(); @@ -190,20 +199,22 @@ private PrefixMapping getCrispyRope() { static final String[][] expansions = {{"crisp:pathPart", crispURI + "pathPart"}, {"rope:partPath", ropeURI + "partPath"}, {"crisp:path:part", crispURI + "path:part"},}; + @Test public void testExpandPrefix() { PrefixMapping ns = getMapping(); ns.setNsPrefix("crisp", crispURI); ns.setNsPrefix("rope", ropeURI); /* */ for ( String aDontChange : dontChange ) { - assertEquals("should be unchanged", aDontChange, ns.expandPrefix(aDontChange)); + assertEquals(aDontChange, ns.expandPrefix(aDontChange), "should be unchanged"); } /* */ for ( String[] expansion : expansions ) { - assertEquals("should expand correctly", expansion[1], ns.expandPrefix(expansion[0])); + assertEquals(expansion[1], ns.expandPrefix(expansion[0]), "should expand correctly"); } } + @Test public void testUseEasyPrefix() { testUseEasyPrefix("prefix mapping impl", getMapping()); testShortForm("prefix mapping impl", getMapping()); @@ -216,12 +227,13 @@ public static void testUseEasyPrefix(String title, PrefixMapping ns) { public static void testShortForm(String title, PrefixMapping ns) { ns.setNsPrefix("crisp", crispURI); ns.setNsPrefix("butter", butterURI); - assertEquals(title, "", ns.shortForm("")); - assertEquals(title, ropeURI, ns.shortForm(ropeURI)); - assertEquals(title, "crisp:tail", ns.shortForm(crispURI + "tail")); - assertEquals(title, "butter:here:we:are", ns.shortForm(butterURI + "here:we:are")); + assertEquals("", ns.shortForm(""), title); + assertEquals(ropeURI, ns.shortForm(ropeURI), title); + assertEquals("crisp:tail", ns.shortForm(crispURI + "tail"), title); + assertEquals("butter:here:we:are", ns.shortForm(butterURI + "here:we:are"), title); } + @Test public void testEasyQName() { PrefixMapping ns = getMapping(); String alphaURI = "http://seasonal.song/preamble/"; @@ -229,6 +241,7 @@ public void testEasyQName() { assertEquals("alpha:rowboat", ns.qnameFor(alphaURI + "rowboat")); } + @Test public void testNoQNameNoPrefix() { PrefixMapping ns = getMapping(); String alphaURI = "http://seasonal.song/preamble/"; @@ -236,6 +249,7 @@ public void testNoQNameNoPrefix() { assertEquals(null, ns.qnameFor("eg:rowboat")); } + @Test public void testNoQNameBadLocal() { PrefixMapping ns = getMapping(); String alphaURI = "http://seasonal.song/preamble/"; @@ -247,6 +261,7 @@ public void testNoQNameBadLocal() { * The tests implied by the email where Chris suggested adding qnameFor; * shortForm generates illegal qnames but qnameFor does not. */ + @Test public void testQnameFromEmail() { String uri = "http://some.long.uri/for/a/namespace#"; PrefixMapping ns = getMapping(); @@ -259,10 +274,11 @@ public void testQnameFromEmail() { * test that we can add the maplets from another PrefixMapping without losing our * own. */ + @Test public void testAddOtherPrefixMapping() { PrefixMapping a = getMapping(); PrefixMapping b = getMapping(); - assertFalse("must have two diffferent maps", a == b); + assertFalse(a == b, "must have two diffferent maps"); a.setNsPrefix("crisp", crispURI); a.setNsPrefix("rope", ropeURI); b.setNsPrefix("butter", butterURI); @@ -281,6 +297,7 @@ private void checkContainsMapping(PrefixMapping b) { /** * as for testAddOtherPrefixMapping, except that it's a plain Map we're adding. */ + @Test public void testAddMap() { PrefixMapping b = getMapping(); Map map = new HashMap<>(); @@ -291,6 +308,7 @@ public void testAddMap() { checkContainsMapping(b); } + @Test public void testAddDefaultMap() { PrefixMapping pm = getMapping(); PrefixMapping root = PrefixMapping.Factory.create(); @@ -306,6 +324,7 @@ public void testAddDefaultMap() { assertEquals("cootle:", pm.getNsPrefixURI("c")); } + @Test public void testSecondPrefixRetainsExistingMap() { PrefixMapping A = getMapping(); A.setNsPrefix("a", crispURI); @@ -314,6 +333,7 @@ public void testSecondPrefixRetainsExistingMap() { assertEquals(crispURI, A.getNsPrefixURI("b")); } + @Test public void testSecondPrefixReplacesReverseMap() { PrefixMapping A = getMapping(); A.setNsPrefix("a", crispURI); @@ -321,6 +341,7 @@ public void testSecondPrefixReplacesReverseMap() { assertEquals("b", A.getNsURIPrefix(crispURI)); } + @Test public void testSecondPrefixDeletedUncoversPreviousMap() { PrefixMapping A = getMapping(); A.setNsPrefix("x", crispURI); @@ -332,6 +353,7 @@ public void testSecondPrefixDeletedUncoversPreviousMap() { /** * Test that the empty prefix does not wipe an existing prefix for the same URI. */ + @Test public void testEmptyDoesNotWipeURI() { PrefixMapping pm = getMapping(); pm.setNsPrefix("frodo", ropeURI); @@ -343,6 +365,7 @@ public void testEmptyDoesNotWipeURI() { * Test that adding a new prefix mapping for U does not throw away a default * mapping for U. */ + @Test public void testSameURIKeepsDefault() { PrefixMapping A = getMapping(); A.setNsPrefix("", crispURI); @@ -350,6 +373,7 @@ public void testSameURIKeepsDefault() { assertEquals(crispURI, A.getNsPrefixURI("")); } + @Test public void testReturnsSelf() { PrefixMapping A = getMapping(); assertSame(A, A.setNsPrefix("crisp", crispURI)); @@ -358,6 +382,7 @@ public void testReturnsSelf() { assertSame(A, A.removeNsPrefix("rhubarb")); } + @Test public void testRemovePrefix() { String hURI = "http://test.remove.prefixes/prefix#"; String bURI = "http://other.test.remove.prefixes/prefix#"; @@ -369,6 +394,7 @@ public void testRemovePrefix() { assertEquals(bURI, A.getNsPrefixURI("br")); } + @Test public void testClear() { String hURI = "http://test.remove.prefixes/prefix#"; String bURI = "http://other.test.remove.prefixes/prefix#"; @@ -384,6 +410,7 @@ public void testClear() { assertEquals(null, A.getNsURIPrefix(bURI)); } + @Test public void testNoMapping() { String hURI = "http://test.prefixes/prefix#"; PrefixMapping A = getMapping(); @@ -392,6 +419,7 @@ public void testNoMapping() { assertFalse(A.hasNoMappings()); } + @Test public void testNumPrefixes() { String hURI = "http://test.prefixes/prefix#"; PrefixMapping A = getMapping(); @@ -400,6 +428,7 @@ public void testNumPrefixes() { assertEquals(1, A.numPrefixes()); } + @Test public void testEquality() { testEquals(""); testEquals("", "x=a", false); @@ -427,8 +456,8 @@ protected void testEquals(String S, String T, boolean expected, PrefixMapping A, fill(A, S); fill(B, T); String title = "usual: '" + S + "', testing: '" + T + "', should be " + (expected ? "equal" : "different"); - assertEquals(title, expected, A.samePrefixMappingAs(B)); - assertEquals(title, expected, B.samePrefixMappingAs(A)); + assertEquals(expected, A.samePrefixMappingAs(B), title); + assertEquals(expected, B.samePrefixMappingAs(A), title); } protected void fill(PrefixMapping pm, String settings) { @@ -440,10 +469,12 @@ protected void fill(PrefixMapping pm, String settings) { } // we now allow namespaces to end with non-punctuational characters + @Test public void testAllowNastyNamespace() { getMapping().setNsPrefix("abc", "def"); } + @Test public void testLock() { PrefixMapping A = getMapping(); assertSame(A, A.lock()); diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping_JU6.java b/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping_JU6.java deleted file mode 100644 index 243b1093ea0..00000000000 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/AbstractTestPrefixMapping_JU6.java +++ /dev/null @@ -1,510 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.graph.compose; - -import static org.junit.jupiter.api.Assertions.*; - -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.jena.shared.PrefixMapping; -import org.apache.jena.test.JenaTestLib; - -/** - * Test prefix mappings - subclass this test and override getMapping() to deliver the - * prefixMapping to be tested. - */ - -public abstract class AbstractTestPrefixMapping_JU6 { - - /** - * Subclasses implement to return a new, empty prefixMapping of their preferred - * kind. - */ - abstract protected PrefixMapping getMapping(); - - static final String crispURI = "http://crisp.nosuch.net/"; - static final String ropeURI = "scheme:rope/string#"; - static final String butterURI = "ftp://ftp.nowhere.at.all/cream#"; - - /** - * The empty prefix is specifically allowed [for the default namespace]. - */ - @Test - public void testEmptyPrefix() { - addGetTest("", crispURI); - } - - @Test - public void testStrPrefix1() { - addGetTest("abc", "http://example/"); - } - - @Test - public void testStrPrefix2() { - // U+1F607 - smiling face with halo - String prefix = new String(Character.toChars(0x1F607)); - addGetTest(prefix, "http://example/"); - } - - private void addGetTest(String prefix, String uri) { - PrefixMapping pmap = getMapping(); - pmap.setNsPrefix(prefix, uri); - assertEquals(uri, pmap.getNsPrefixURI(prefix)); - } - - static final String[] badNames = {"", "foo:bar", "with a space", "-argument"}; - - /** - * Test that various illegal names are trapped. - */ - @Test - public void testCheckNames() { - PrefixMapping ns = getMapping(); - for ( String bad : badNames ) { - try { - ns.setNsPrefix(bad, crispURI); - fail("'" + bad + "' is an illegal prefix and should be trapped"); - } catch (PrefixMapping.IllegalPrefixException e) { - JenaTestLib.pass(); - } - } - } - - @Test - public void testNullURITrapped() { - try { - getMapping().setNsPrefix("xy", null); - fail("should trap null URI in setNsPrefix"); - } catch (NullPointerException e) { - JenaTestLib.pass(); - } - } - - /** - * test that a PrefixMapping maps names to URIs. The names and URIs are all fully - * distinct - overlapping names/uris are dealt with in other tests. - */ - @Test - public void testPrefixMappingMapping() { - String toast = "ftp://ftp.nowhere.not/"; - JenaTestLib.assertDiffer("crisp and toast must differ", crispURI, toast); - /* */ - PrefixMapping ns = getMapping(); - assertEquals(null, ns.getNsPrefixURI("crisp"), "crisp should be unset"); - assertEquals(null, ns.getNsPrefixURI("toast"), "toast should be unset"); - assertEquals(null, ns.getNsPrefixURI("butter"), "butter should be unset"); - /* */ - ns.setNsPrefix("crisp", crispURI); - assertEquals(crispURI, ns.getNsPrefixURI("crisp"), "crisp should be set"); - assertEquals(null, ns.getNsPrefixURI("toast"), "toast should still be unset"); - assertEquals(null, ns.getNsPrefixURI("butter"), "butter should still be unset"); - /* */ - ns.setNsPrefix("toast", toast); - assertEquals(crispURI, ns.getNsPrefixURI("crisp"), "crisp should be set"); - assertEquals(toast, ns.getNsPrefixURI("toast"), "toast should be set"); - assertEquals(null, ns.getNsPrefixURI("butter"), "butter should still be unset"); - } - - /** - * Test that we can run the prefix mapping in reverse - from URIs to prefixes. - * uriB is a prefix of uriA to try and ensure that the ordering of the map - * doesn't matter. - */ - @Test - public void testReversePrefixMapping() { - PrefixMapping ns = getMapping(); - String uriA = "http://jena.hpl.hp.com/A#", uriB = "http://jena.hpl.hp.com/"; - String uriC = "http://jena.hpl.hp.com/Csharp/"; - String prefixA = "aa", prefixB = "bb"; - ns.setNsPrefix(prefixA, uriA).setNsPrefix(prefixB, uriB); - assertEquals(null, ns.getNsURIPrefix(uriC)); - assertEquals(prefixA, ns.getNsURIPrefix(uriA)); - assertEquals(prefixB, ns.getNsURIPrefix(uriB)); - } - - /** - * test that we can extract a proper Map from a PrefixMapping - */ - @Test - public void testPrefixMappingMap() { - PrefixMapping ns = getCrispyRope(); - Map map = ns.getNsPrefixMap(); - assertEquals(2, map.size(), "map should have two elements"); - assertEquals(crispURI, map.get("crisp")); - assertEquals("scheme:rope/string#", map.get("rope")); - } - - /** - * test that the Map returned by getNsPrefixMap does not alias (parts of) the - * secret internal map of the PrefixMapping - */ - @Test - public void testPrefixMappingSecret() { - PrefixMapping ns = getCrispyRope(); - Map map = ns.getNsPrefixMap(); - // The map may be unmodifiable in which case put throws - // UnsupportedOperationException - try { - map.put("crisp", "with/onions"); - map.put("sandwich", "with/cheese"); - } catch (UnsupportedOperationException ex) {} - - assertEquals(crispURI, ns.getNsPrefixURI("crisp")); - assertEquals(ropeURI, ns.getNsPrefixURI("rope")); - assertEquals(null, ns.getNsPrefixURI("sandwich")); - } - - private PrefixMapping getCrispyRope() { - PrefixMapping ns = getMapping(); - ns.setNsPrefix("crisp", crispURI); - ns.setNsPrefix("rope", ropeURI); - return ns; - } - - /** - * these are strings that should not change when they are prefix-expanded with - * crisp and rope as legal prefixes. - */ - static final String[] dontChange = {"", "http://www.somedomain.something/whatever#", "crispy:cabbage", "cris:isOnInfiniteEarths", - "rop:tangled/web", "roped:abseiling"}; - - /** - * these are the required mappings which the test cases below should satisfy: an - * array of 2-arrays, where element 0 is the string to expand and element 1 is - * the string it should expand to. - */ - static final String[][] expansions = {{"crisp:pathPart", crispURI + "pathPart"}, {"rope:partPath", ropeURI + "partPath"}, - {"crisp:path:part", crispURI + "path:part"},}; - - @Test - public void testExpandPrefix() { - PrefixMapping ns = getMapping(); - ns.setNsPrefix("crisp", crispURI); - ns.setNsPrefix("rope", ropeURI); - /* */ - for ( String aDontChange : dontChange ) { - assertEquals(aDontChange, ns.expandPrefix(aDontChange), "should be unchanged"); - } - /* */ - for ( String[] expansion : expansions ) { - assertEquals(expansion[1], ns.expandPrefix(expansion[0]), "should expand correctly"); - } - } - - @Test - public void testUseEasyPrefix() { - testUseEasyPrefix("prefix mapping impl", getMapping()); - testShortForm("prefix mapping impl", getMapping()); - } - - public static void testUseEasyPrefix(String title, PrefixMapping ns) { - testShortForm(title, ns); - } - - public static void testShortForm(String title, PrefixMapping ns) { - ns.setNsPrefix("crisp", crispURI); - ns.setNsPrefix("butter", butterURI); - assertEquals("", ns.shortForm(""), title); - assertEquals(ropeURI, ns.shortForm(ropeURI), title); - assertEquals("crisp:tail", ns.shortForm(crispURI + "tail"), title); - assertEquals("butter:here:we:are", ns.shortForm(butterURI + "here:we:are"), title); - } - - @Test - public void testEasyQName() { - PrefixMapping ns = getMapping(); - String alphaURI = "http://seasonal.song/preamble/"; - ns.setNsPrefix("alpha", alphaURI); - assertEquals("alpha:rowboat", ns.qnameFor(alphaURI + "rowboat")); - } - - @Test - public void testNoQNameNoPrefix() { - PrefixMapping ns = getMapping(); - String alphaURI = "http://seasonal.song/preamble/"; - ns.setNsPrefix("alpha", alphaURI); - assertEquals(null, ns.qnameFor("eg:rowboat")); - } - - @Test - public void testNoQNameBadLocal() { - PrefixMapping ns = getMapping(); - String alphaURI = "http://seasonal.song/preamble/"; - ns.setNsPrefix("alpha", alphaURI); - assertEquals(null, ns.qnameFor(alphaURI + "12345")); - } - - /** - * The tests implied by the email where Chris suggested adding qnameFor; - * shortForm generates illegal qnames but qnameFor does not. - */ - @Test - public void testQnameFromEmail() { - String uri = "http://some.long.uri/for/a/namespace#"; - PrefixMapping ns = getMapping(); - ns.setNsPrefix("x", uri); - assertEquals(null, ns.qnameFor(uri)); - assertEquals(null, ns.qnameFor(uri + "non/fiction")); - } - - /** - * test that we can add the maplets from another PrefixMapping without losing our - * own. - */ - @Test - public void testAddOtherPrefixMapping() { - PrefixMapping a = getMapping(); - PrefixMapping b = getMapping(); - assertFalse(a == b, "must have two diffferent maps"); - a.setNsPrefix("crisp", crispURI); - a.setNsPrefix("rope", ropeURI); - b.setNsPrefix("butter", butterURI); - assertEquals(null, b.getNsPrefixURI("crisp")); - assertEquals(null, b.getNsPrefixURI("rope")); - b.setNsPrefixes(a); - checkContainsMapping(b); - } - - private void checkContainsMapping(PrefixMapping b) { - assertEquals(crispURI, b.getNsPrefixURI("crisp")); - assertEquals(ropeURI, b.getNsPrefixURI("rope")); - assertEquals(butterURI, b.getNsPrefixURI("butter")); - } - - /** - * as for testAddOtherPrefixMapping, except that it's a plain Map we're adding. - */ - @Test - public void testAddMap() { - PrefixMapping b = getMapping(); - Map map = new HashMap<>(); - map.put("crisp", crispURI); - map.put("rope", ropeURI); - b.setNsPrefix("butter", butterURI); - b.setNsPrefixes(map); - checkContainsMapping(b); - } - - @Test - public void testAddDefaultMap() { - PrefixMapping pm = getMapping(); - PrefixMapping root = PrefixMapping.Factory.create(); - pm.setNsPrefix("a", "aPrefix:"); - pm.setNsPrefix("b", "bPrefix:"); - root.setNsPrefix("a", "pootle:"); - root.setNsPrefix("z", "bPrefix:"); - root.setNsPrefix("c", "cootle:"); - assertSame(pm, pm.withDefaultMappings(root)); - assertEquals("aPrefix:", pm.getNsPrefixURI("a")); - assertEquals(null, pm.getNsPrefixURI("z")); - assertEquals("bPrefix:", pm.getNsPrefixURI("b")); - assertEquals("cootle:", pm.getNsPrefixURI("c")); - } - - @Test - public void testSecondPrefixRetainsExistingMap() { - PrefixMapping A = getMapping(); - A.setNsPrefix("a", crispURI); - A.setNsPrefix("b", crispURI); - assertEquals(crispURI, A.getNsPrefixURI("a")); - assertEquals(crispURI, A.getNsPrefixURI("b")); - } - - @Test - public void testSecondPrefixReplacesReverseMap() { - PrefixMapping A = getMapping(); - A.setNsPrefix("a", crispURI); - A.setNsPrefix("b", crispURI); - assertEquals("b", A.getNsURIPrefix(crispURI)); - } - - @Test - public void testSecondPrefixDeletedUncoversPreviousMap() { - PrefixMapping A = getMapping(); - A.setNsPrefix("x", crispURI); - A.setNsPrefix("y", crispURI); - A.removeNsPrefix("y"); - assertEquals("x", A.getNsURIPrefix(crispURI)); - } - - /** - * Test that the empty prefix does not wipe an existing prefix for the same URI. - */ - @Test - public void testEmptyDoesNotWipeURI() { - PrefixMapping pm = getMapping(); - pm.setNsPrefix("frodo", ropeURI); - pm.setNsPrefix("", ropeURI); - assertEquals(ropeURI, pm.getNsPrefixURI("frodo")); - } - - /** - * Test that adding a new prefix mapping for U does not throw away a default - * mapping for U. - */ - @Test - public void testSameURIKeepsDefault() { - PrefixMapping A = getMapping(); - A.setNsPrefix("", crispURI); - A.setNsPrefix("crisp", crispURI); - assertEquals(crispURI, A.getNsPrefixURI("")); - } - - @Test - public void testReturnsSelf() { - PrefixMapping A = getMapping(); - assertSame(A, A.setNsPrefix("crisp", crispURI)); - assertSame(A, A.setNsPrefixes(A)); - assertSame(A, A.setNsPrefixes(new HashMap())); - assertSame(A, A.removeNsPrefix("rhubarb")); - } - - @Test - public void testRemovePrefix() { - String hURI = "http://test.remove.prefixes/prefix#"; - String bURI = "http://other.test.remove.prefixes/prefix#"; - PrefixMapping A = getMapping(); - A.setNsPrefix("hr", hURI); - A.setNsPrefix("br", bURI); - A.removeNsPrefix("hr"); - assertEquals(null, A.getNsPrefixURI("hr")); - assertEquals(bURI, A.getNsPrefixURI("br")); - } - - @Test - public void testClear() { - String hURI = "http://test.remove.prefixes/prefix#"; - String bURI = "http://other.test.remove.prefixes/prefix#"; - PrefixMapping A = getMapping(); - A.setNsPrefix("hr", hURI); - A.setNsPrefix("br", bURI); - A.clearNsPrefixMap(); - - assertEquals(null, A.getNsPrefixURI("hr")); - assertEquals(null, A.getNsPrefixURI("br")); - - assertEquals(null, A.getNsURIPrefix(hURI)); - assertEquals(null, A.getNsURIPrefix(bURI)); - } - - @Test - public void testNoMapping() { - String hURI = "http://test.prefixes/prefix#"; - PrefixMapping A = getMapping(); - assertTrue(A.hasNoMappings()); - A.setNsPrefix("hr", hURI); - assertFalse(A.hasNoMappings()); - } - - @Test - public void testNumPrefixes() { - String hURI = "http://test.prefixes/prefix#"; - PrefixMapping A = getMapping(); - assertEquals(0, A.numPrefixes()); - A.setNsPrefix("hr", hURI); - assertEquals(1, A.numPrefixes()); - } - - @Test - public void testEquality() { - testEquals(""); - testEquals("", "x=a", false); - testEquals("x=a", "", false); - testEquals("x=a"); - testEquals("x=a y=b", "y=b x=a", true); - testEquals("x=a x=b", "x=b x=a", false); - } - - protected void testEquals(String S) { - testEquals(S, S, true); - } - - protected void testEquals(String S, String T, boolean expected) { - testEqualsBase(S, T, expected); - testEqualsBase(T, S, expected); - } - - public void testEqualsBase(String S, String T, boolean expected) { - testEquals(S, T, expected, getMapping(), getMapping()); - testEquals(S, T, expected, PrefixMapping.Factory.create(), getMapping()); - } - - protected void testEquals(String S, String T, boolean expected, PrefixMapping A, PrefixMapping B) { - fill(A, S); - fill(B, T); - String title = "usual: '" + S + "', testing: '" + T + "', should be " + (expected ? "equal" : "different"); - assertEquals(expected, A.samePrefixMappingAs(B), title); - assertEquals(expected, B.samePrefixMappingAs(A), title); - } - - protected void fill(PrefixMapping pm, String settings) { - List L = JenaTestLib.listOfStrings(settings); - for ( String setting : L ) { - int eq = setting.indexOf('='); - pm.setNsPrefix(setting.substring(0, eq), setting.substring(eq + 1)); - } - } - - // we now allow namespaces to end with non-punctuational characters - @Test - public void testAllowNastyNamespace() { - getMapping().setNsPrefix("abc", "def"); - } - - @Test - public void testLock() { - PrefixMapping A = getMapping(); - assertSame(A, A.lock()); - /* */ - try { - A.setNsPrefix("crisp", crispURI); - fail("mapping should be frozen"); - } catch (PrefixMapping.JenaLockedException e) { - JenaTestLib.pass(); - } - /* */ - try { - A.setNsPrefixes(A); - fail("mapping should be frozen"); - } catch (PrefixMapping.JenaLockedException e) { - JenaTestLib.pass(); - } - /* */ - try { - A.setNsPrefixes(new HashMap()); - fail("mapping should be frozen"); - } catch (PrefixMapping.JenaLockedException e) { - JenaTestLib.pass(); - } - /* */ - try { - A.removeNsPrefix("toast"); - fail("mapping should be frozen"); - } catch (PrefixMapping.JenaLockedException e) { - JenaTestLib.pass(); - } - } -} diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDelta.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDelta.java index 8220654077d..003770df041 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDelta.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDelta.java @@ -25,12 +25,12 @@ import org.junit.jupiter.api.Test; -import org.apache.jena.graph.BaseTestGraph_JU6; +import org.apache.jena.graph.BaseTestGraph; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphTestLib; import org.apache.jena.graph.Triple; -public class TestDelta extends BaseTestGraph_JU6 { +public class TestDelta extends BaseTestGraph { private static final String DEFAULT_TRIPLES = "x R y; p S q"; diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDyadic.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDyadic.java index cd0fd3e695c..881637c30a6 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestDyadic.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestDyadic.java @@ -27,14 +27,14 @@ import java.util.StringTokenizer; -import org.apache.jena.graph.BaseTestGraph_JU6; +import org.apache.jena.graph.BaseTestGraph; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphMemFactory; import org.apache.jena.graph.Triple; import org.apache.jena.util.iterator.ExtendedIterator; import org.apache.jena.util.iterator.NiceIterator; -public abstract class TestDyadic extends BaseTestGraph_JU6 { +public abstract class TestDyadic extends BaseTestGraph { static private ExtendedIterator things(final String x) { return new NiceIterator() { diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnion.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnion.java index 27acadc03c1..3346618ceed 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnion.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestMultiUnion.java @@ -34,7 +34,7 @@ import java.util.Iterator; import java.util.List; -import org.apache.jena.graph.BaseTestGraph_JU6; +import org.apache.jena.graph.BaseTestGraph; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphTestLib; import org.apache.jena.rdf.model.Model; @@ -45,7 +45,7 @@ * Unit tests for multi-union graph. *

*/ -public class TestMultiUnion extends BaseTestGraph_JU6 +public class TestMultiUnion extends BaseTestGraph { // External signature methods diff --git a/jena-core/src/test/java/org/apache/jena/graph/compose/TestPolyadicPrefixMapping.java b/jena-core/src/test/java/org/apache/jena/graph/compose/TestPolyadicPrefixMapping.java index 3ab3187818a..7728ff72363 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/compose/TestPolyadicPrefixMapping.java +++ b/jena-core/src/test/java/org/apache/jena/graph/compose/TestPolyadicPrefixMapping.java @@ -29,7 +29,7 @@ import org.apache.jena.graph.*; import org.apache.jena.shared.PrefixMapping; -public class TestPolyadicPrefixMapping extends AbstractTestPrefixMapping_JU6 { +public class TestPolyadicPrefixMapping extends AbstractTestPrefixMapping { Graph gBase; Graph g1, g2; diff --git a/jena-core/src/test/java/org/apache/jena/memvalue/TestGraphMemModel.java b/jena-core/src/test/java/org/apache/jena/memvalue/TestGraphMemModel.java index 5297a009ace..7f8602507b2 100644 --- a/jena-core/src/test/java/org/apache/jena/memvalue/TestGraphMemModel.java +++ b/jena-core/src/test/java/org/apache/jena/memvalue/TestGraphMemModel.java @@ -48,7 +48,7 @@ * Jena5+ : Only {@link GraphMemValue} supports this. Other graph are "same term", not * "same value" and language tags are held in canonical form. */ -public class TestGraphMemModel extends BaseTestGraph_JU6 { +public class TestGraphMemModel extends BaseTestGraph { @Override public Graph getNewGraph() { diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntGraph.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntGraph.java index 7fa8c8aaba1..5c4b05b8012 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntGraph.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/TestOntGraph.java @@ -21,7 +21,7 @@ package org.apache.jena.ontology.impl; -import org.apache.jena.graph.BaseTestGraph_JU6; +import org.apache.jena.graph.BaseTestGraph; import org.apache.jena.graph.Graph; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.test.JenaTestLib; @@ -31,7 +31,7 @@ via OntModel - there doesn't appear to be an OntGraph class. */ -public class TestOntGraph extends BaseTestGraph_JU6 +public class TestOntGraph extends BaseTestGraph { static { JenaTestLib.setup(); } diff --git a/jena-core/src/test/java/org/apache/jena/graph/AbstractTestGraph.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/AbstractTestGraph.java similarity index 97% rename from jena-core/src/test/java/org/apache/jena/graph/AbstractTestGraph.java rename to jena-core/src/test/java/org/apache/jena/reasoner/test/AbstractTestGraph.java index 3fcb6600a08..934122bd6b5 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/AbstractTestGraph.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/AbstractTestGraph.java @@ -19,12 +19,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.apache.jena.graph; +package org.apache.jena.reasoner.test; import java.io.InputStream; import java.util.*; import junit.framework.TestCase; +import org.apache.jena.graph.Graph; +import org.apache.jena.graph.GraphEventManager; +import org.apache.jena.graph.GraphEvents; +import org.apache.jena.graph.GraphListener; +import org.apache.jena.graph.GraphMemFactory; +import org.apache.jena.graph.GraphTestLib; +import org.apache.jena.graph.GraphUtil; +import org.apache.jena.graph.Node; +import org.apache.jena.graph.RecordingListener; +import org.apache.jena.graph.Triple; +import org.apache.jena.graph.TransactionHandler; import org.apache.jena.junit.NodeCreateUtils; import org.apache.jena.memvalue.TrackingTripleIterator; import org.apache.jena.rdf.model.Model; @@ -37,11 +48,14 @@ import org.apache.jena.util.iterator.ExtendedIterator; /** + * A copy of {@code org.apache.jena.graph.AbstractTestGraph}, kept package-scope here so + * that {@link TestInfGraph} does not hold the JUnit 3 original in place. + *

* AbstractTestGraph provides a bunch of basic tests for something that purports to * be a Graph. The abstract method getGraph must be overridden in subclasses to * deliver a Graph of interest. */ -public abstract class AbstractTestGraph extends TestCase { +abstract class AbstractTestGraph extends TestCase { public AbstractTestGraph(String name) { super(name); } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfGraph.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfGraph.java index 4c9f8427e18..8dece4ecd51 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfGraph.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfGraph.java @@ -22,7 +22,6 @@ package org.apache.jena.reasoner.test; import junit.framework.TestSuite; -import org.apache.jena.graph.AbstractTestGraph; import org.apache.jena.graph.Graph; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.reasoner.InfGraph; diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java index 3db97c36e45..fb179f47b40 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java @@ -45,7 +45,7 @@ static public TestSuite suite() { // ** COMPLEX // Generates tests. //JU6 addTest(ts, "Enhanced", org.apache.jena.enhanced.TS3_enh.suite()); - addTest(ts, "Graph", adaptJUnit4(org.apache.jena.graph.TS3_graph.class)); +//JU6 addTest(ts, "Graph", adaptJUnit4(org.apache.jena.graph.TS3_graph.class)); //JU6 addTest(ts, "Mem", adaptJUnit4(org.apache.jena.mem.TS4_GraphMem.class)); //JU6 addTest(ts, "MemValue", adaptJUnit4(org.apache.jena.memvalue.TS3_GraphMemValue.class)); diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java index 92020ee5ff8..13a9c8132c1 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java @@ -27,6 +27,7 @@ import org.apache.jena.core_ttl.tests.TS6_TestTurtle; import org.apache.jena.datatypes.TS6_dt; +import org.apache.jena.graph.TS6_graph; import org.apache.jena.graph.compose.TS6_compose; import org.apache.jena.enhanced.TS6_enh; import org.apache.jena.irix.TS6_IRIx2; @@ -54,6 +55,8 @@ TS6_enh.class, + TS6_graph.class, + TS6_GraphMem.class, TS6_GraphMemValue.class, From f4ffbc3c0933a0a29594e3a30c78bfbac3ab1293 Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Mon, 7 Sep 2026 18:20:25 +0100 Subject: [PATCH 09/12] GH-3236: Convert jena.assembler to JUnit6 --- .../jena/assembler/AssemblerTestBase.java | 9 +-- ...{TS3_Assembler.java => TS6_Assembler.java} | 61 +++++++-------- .../jena/assembler/TestAssemblerGroup.java | 23 ++++-- .../assembler/TestAssemblerGroupTracing.java | 8 +- .../jena/assembler/TestAssemblerHelp.java | 21 +++++- .../assembler/TestAssemblerVocabulary.java | 16 ++-- .../assembler/TestBuiltinAssemblerGroup.java | 11 ++- .../jena/assembler/TestContentAssembler.java | 34 +++++++-- .../assembler/TestDefaultModelAssembler.java | 9 ++- .../TestDocumentManagerAssembler.java | 14 +++- .../jena/assembler/TestImportManager.java | 14 +++- .../jena/assembler/TestInfModelAssembler.java | 15 +++- .../assembler/TestMemoryModelAssembler.java | 9 ++- .../org/apache/jena/assembler/TestMode.java | 6 +- .../jena/assembler/TestModelAssembler.java | 10 ++- .../jena/assembler/TestModelContent.java | 15 +++- .../jena/assembler/TestModelExpansion.java | 21 +++++- .../assembler/TestOntModelAcceptance.java | 8 +- .../jena/assembler/TestOntModelAssembler.java | 74 ++++++++++--------- .../assembler/TestOntModelSpecAssembler.java | 67 +++++++++-------- .../assembler/TestPrefixMappingAssembler.java | 12 ++- .../TestReasonerFactoryAssembler.java | 21 +++++- .../apache/jena/assembler/TestRuleSet.java | 13 +++- .../jena/assembler/TestRuleSetAssembler.java | 15 +++- .../assembler/TestUnionModelAssembler.java | 13 +++- 25 files changed, 338 insertions(+), 181 deletions(-) rename jena-core/src/test/java/org/apache/jena/assembler/{TS3_Assembler.java => TS6_Assembler.java} (50%) diff --git a/jena-core/src/test/java/org/apache/jena/assembler/AssemblerTestBase.java b/jena-core/src/test/java/org/apache/jena/assembler/AssemblerTestBase.java index 20e531d19ce..a3f72f04689 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/AssemblerTestBase.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/AssemblerTestBase.java @@ -21,7 +21,8 @@ package org.apache.jena.assembler; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.*; + import org.apache.jena.assembler.assemblers.AssemblerBase; import org.apache.jena.assembler.exceptions.CannotConstructException; import org.apache.jena.rdf.model.Model; @@ -40,7 +41,7 @@ * in subclasses to control the parser that is used to construct models and the * prefixes added to the model (these features added for Eyeball). */ -public class AssemblerTestBase extends TestCase { +public class AssemblerTestBase { protected Class getAssemblerClass() { throw new BrokenException("this class must define getAssemblerClass"); @@ -89,10 +90,6 @@ public Object open(Assembler a, Resource root, Mode irrelevant) { protected static final Model schema = JA.getSchema(); - public AssemblerTestBase(String name) { - super(name); - } - protected Model model(String string) { Model result = ModelTestLib.createModel(); setRequiredPrefixes(result); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TS3_Assembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TS6_Assembler.java similarity index 50% rename from jena-core/src/test/java/org/apache/jena/assembler/TS3_Assembler.java rename to jena-core/src/test/java/org/apache/jena/assembler/TS6_Assembler.java index 174aba1e4a8..d9d270b3e3b 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TS3_Assembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TS6_Assembler.java @@ -21,39 +21,42 @@ package org.apache.jena.assembler; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.junit.platform.suite.api.BeforeSuite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; -@RunWith(Suite.class) -@Suite.SuiteClasses( { - // Convert to JUnit5 - TestMode.class, +import org.apache.jena.test.JenaTestLib; - // JUnit3 +@Suite +@SelectClasses({ + TestMode.class, TestModelExpansion.class, TestImportManager.class, TestOntModelAcceptance.class, - -// // Was "TestAssemblers" : 19 - TestRuleSet.class , - TestAssemblerHelp.class , - TestDefaultModelAssembler.class , - TestMemoryModelAssembler.class , - TestAssemblerVocabulary.class , - TestRuleSetAssembler.class , - TestInfModelAssembler.class , - TestAssemblerGroup.class , - TestAssemblerGroupTracing.class , - TestReasonerFactoryAssembler.class , - TestContentAssembler.class , - TestModelContent.class , - TestUnionModelAssembler.class , - TestPrefixMappingAssembler.class , - TestBuiltinAssemblerGroup.class , - TestModelAssembler.class , - TestDocumentManagerAssembler.class, - TestOntModelSpecAssembler.class, - TestOntModelAssembler.class + TestRuleSet.class, + TestAssemblerHelp.class, + TestDefaultModelAssembler.class, + TestMemoryModelAssembler.class, + TestAssemblerVocabulary.class, + TestRuleSetAssembler.class, + TestInfModelAssembler.class, + TestAssemblerGroup.class, + TestAssemblerGroupTracing.class, + TestReasonerFactoryAssembler.class, + TestContentAssembler.class, + TestModelContent.class, + TestUnionModelAssembler.class, + TestPrefixMappingAssembler.class, + TestBuiltinAssemblerGroup.class, + TestModelAssembler.class, + TestDocumentManagerAssembler.class, + TestOntModelSpecAssembler.class, + TestOntModelAssembler.class }) -public class TS3_Assembler {} +public class TS6_Assembler { + @BeforeSuite + public static void beforeSuite() { + JenaTestLib.setup(); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerGroup.java b/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerGroup.java index 265377cecca..c802fe20a1d 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerGroup.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerGroup.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.assembler.assemblers.AssemblerBase; import org.apache.jena.assembler.assemblers.AssemblerGroup; import org.apache.jena.assembler.assemblers.AssemblerGroup.ExpandingAssemblerGroup; @@ -36,15 +40,13 @@ import org.apache.jena.vocabulary.RDFS; public class TestAssemblerGroup extends AssemblerTestBase { - public TestAssemblerGroup(String name) { - super(name); - } @Override protected Class getAssemblerClass() { return AssemblerGroup.class; } + @Test public void testEmptyAssemblerGroup() { AssemblerGroup a = AssemblerGroup.create(); JenaTestLib.assertInstanceOf(AssemblerGroup.class, a); @@ -70,15 +72,16 @@ public static void whenRequiredByAssembler(AssemblerGroup ag) { } } + @Test public void testLoadsClasses() { AssemblerGroup a = AssemblerGroup.create(); a.implementWith(ModelTestLib.resource("T"), new MockAssembler()); Resource root = resourceInModel("x rdf:type T; _c ja:loadClass '" + TestAssemblerGroup.class.getName() + "$Trivial'"); // In case already loaded. loaded = false; - assertFalse("something has pre-loaded Trivial, so we can't test if it gets loaded", loaded); + assertFalse(loaded, "something has pre-loaded Trivial, so we can't test if it gets loaded"); assertEquals("mockmockmock", a.open(root)); - assertTrue("the assembler group did not obey the ja:loadClass directive", loaded); + assertTrue(loaded, "the assembler group did not obey the ja:loadClass directive"); } static class MockAssembler extends AssemblerBase { @@ -88,6 +91,7 @@ public Object open(Assembler a, Resource root, Mode mode) { } } + @Test public void testSingletonAssemblerGroup() { AssemblerGroup a = AssemblerGroup.create(); assertSame(a, a.implementWith(JA.InfModel, Assembler.infModel)); @@ -95,6 +99,7 @@ public void testSingletonAssemblerGroup() { checkFailsType(a, "js:DefaultModel"); } + @Test public void testMultipleAssemblerGroup() { AssemblerGroup a = AssemblerGroup.create(); assertSame(a, a.implementWith(JA.InfModel, Assembler.infModel)); @@ -104,6 +109,7 @@ public void testMultipleAssemblerGroup() { checkFailsType(a, "js:DefaultModel"); } + @Test public void testImpliedType() { AssemblerGroup a = AssemblerGroup.create(); Resource root = resourceInModel("x ja:reasoner y"); @@ -112,6 +118,7 @@ public void testImpliedType() { assertSame(expected, a.open(root)); } + @Test public void testBuiltinGroup() { AssemblerGroup g = Assembler.general(); JenaTestLib.assertInstanceOf(Model.class, g.open(resourceInModel("x rdf:type ja:DefaultModel"))); @@ -126,6 +133,7 @@ public Object open(Assembler a, Resource root, Mode mode) { } }; + @Test public void testAddingImplAddsSubclass() { final Model[] fullModel = new Model[1]; AssemblerGroup g = new AssemblerGroup.ExpandingAssemblerGroup() { @@ -149,6 +157,7 @@ public static void whenRequiredByAssembler(AssemblerGroup g) { } } + @Test public void testClassesLoadedBeforeAddingTypes() { String className = ImplementsSPOO.class.getName(); Resource root = resourceInModel("_root rdf:type ja:MemoryModel; _x ja:loadClass '" + className + "'"); @@ -166,13 +175,14 @@ protected void assertMemoryModel(Object object) { fail("expected a Model, but got a " + object.getClass()); } + @Test public void testPassesSelfIn() { final AssemblerGroup group = AssemblerGroup.create(); final Object result = new Object(); Assembler fake = new AssemblerBase() { @Override public Object open(Assembler a, Resource root, Mode irrelevant) { - assertSame("nested call should pass in assembler group:", group, a); + assertSame(group, a, "nested call should pass in assembler group:"); return result; } }; @@ -180,6 +190,7 @@ public Object open(Assembler a, Resource root, Mode irrelevant) { assertSame(result, group.open(resourceInModel("x rdf:type ja:Object"))); } + @Test public void testCopyPreservesMapping() { AssemblerGroup initial = AssemblerGroup.create().implementWith(JA.InfModel, new InfModelAssembler()); AssemblerGroup copy = initial.copy(); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerGroupTracing.java b/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerGroupTracing.java index ba2da9f15da..5e1be18965a 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerGroupTracing.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerGroupTracing.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.assembler.assemblers.*; import org.apache.jena.assembler.exceptions.AssemblerException; import org.apache.jena.rdf.model.ModelTestLib; @@ -29,10 +33,8 @@ import org.apache.jena.test.JenaTestLib; public class TestAssemblerGroupTracing extends AssemblerTestBase { - public TestAssemblerGroupTracing(String name) { - super(name); - } + @Test public void testFail() { Resource root = resourceInModel("x rdf:type A"); AssemblerGroup g = AssemblerGroup.create(); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerHelp.java b/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerHelp.java index 7641471a0f7..04870a4b8b5 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerHelp.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerHelp.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.*; import org.apache.jena.assembler.assemblers.*; @@ -31,15 +35,13 @@ import org.apache.jena.vocabulary.RDF; public class TestAssemblerHelp extends AssemblerTestBase { - public TestAssemblerHelp(String name) { - super(name); - } @Override protected Class getAssemblerClass() { throw new BrokenException("TestAssemblers does not need this method"); } + @Test public void testClosureFootprint() { Resource root = resourceInModel("x ja:reasoner y"); Statement footprint = root.getModel().createStatement(JA.This, RDF.type, JA.Expanded); @@ -48,6 +50,7 @@ public void testClosureFootprint() { assertTrue(expanded.getModel().contains(footprint)); } + @Test public void testFootprintPreventsClosure() { Resource root = resourceInModel("x ja:reasoner y; ja:this rdf:type ja:Expanded"); Model original = model("").add(root.getModel()); @@ -56,11 +59,13 @@ public void testFootprintPreventsClosure() { ModelTestLib.assertIsoModels(original, expanded.getModel()); } + @Test public void testSpecificType() { testSpecificType("ja:NamedModel", "x ja:modelName 'name'"); testSpecificType("ja:NamedModel", "x ja:modelName 'name'; x rdf:type irrelevant"); } + @Test public void testFindSpecificTypes() { testFindSpecificTypes("", "x rdf:type A", "Top"); testFindSpecificTypes("", "x rdf:type A; x rdf:type B", "Top"); @@ -78,30 +83,35 @@ private void testFindSpecificTypes(String expectedString, String model, String b assertEquals(expected, answer); } + @Test public void testFindRootByExplicitType() { Model model = model("x rdf:type ja:Object; y rdf:type Irrelevant"); Set roots = AssemblerHelp.findAssemblerRoots(model); assertEquals(ModelTestLib.resourceSet("x"), roots); } + @Test public void testFindRootByImplicitType() { Model model = model("x ja:reificationMode ja:Standard"); Set roots = AssemblerHelp.findAssemblerRoots(model); assertEquals(ModelTestLib.resourceSet("x"), roots); } + @Test public void testFindMultipleRoots() { Model model = model("x rdf:type ja:Object; y ja:reificationMode ja:Minimal"); Set roots = AssemblerHelp.findAssemblerRoots(model); assertEquals(ModelTestLib.resourceSet("y x"), roots); } + @Test public void testFindRootsWithSpecifiedType() { Model model = model("x rdf:type ja:Model; y rdf:type ja:Object"); Set roots = AssemblerHelp.findAssemblerRoots(model, JA.Model); assertEquals(ModelTestLib.resourceSet("x"), roots); } + @Test public void testThrowsIfNoRoots() { try { AssemblerHelp.singleModelRoot(model("")); @@ -111,6 +121,7 @@ public void testThrowsIfNoRoots() { } } + @Test public void testThrowsIfManyRoots() { try { AssemblerHelp.singleModelRoot(model("a rdf:type ja:Model; b rdf:type ja:Model")); @@ -120,11 +131,13 @@ public void testThrowsIfManyRoots() { } } + @Test public void testExtractsSingleRoot() { Resource it = AssemblerHelp.singleModelRoot(model("a rdf:type ja:Model")); assertEquals(ModelTestLib.resource("a"), it); } + @Test public void testSpecificTypeFails() { try { testSpecificType("xxx", "x rdf:type ja:Model; x rdf:type ja:PrefixMapping"); @@ -191,6 +204,7 @@ public Object open(Assembler a, Resource root, Mode irrelevant) { } } + @Test public void testClassAssociation() { String className = "org.apache.jena.assembler.TestAssemblerHelp$Imp"; AssemblerGroup group = AssemblerGroup.create(); @@ -204,6 +218,7 @@ public void testClassAssociation() { assertEquals(className, group.assemblerFor(ModelTestLib.resource("eh:Wossname")).getClass().getName()); } + @Test public void testClassResourceConstructor() { AssemblerGroup group = AssemblerGroup.create(); Model m = model("eh:Wossname ja:assembler 'org.apache.jena.assembler.TestAssemblerHelp$Gremlin'"); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerVocabulary.java b/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerVocabulary.java index f42cdc421f3..8c53718753d 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerVocabulary.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestAssemblerVocabulary.java @@ -21,18 +21,20 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.rdf.model.*; public class TestAssemblerVocabulary extends AssemblerTestBase { - public TestAssemblerVocabulary(String name) { - super(name); - } @Override protected Class getAssemblerClass() { return null; } + @Test public void testVocabulary() { assertEquals("http://jena.hpl.hp.com/2005/11/Assembler#", JA.getURI()); assertEquals("http://jena.hpl.hp.com/2005/11/Assembler#", JA.uri); @@ -88,6 +90,7 @@ protected void assertLocalname(String local, Resource resource) { assertEquals(JA.uri + local, resource.getURI()); } + @Test public void testObjectTypes() { assertSubclassOf(JA.Model, JA.Object); assertSubclassOf(JA.PrefixMapping, JA.Object); @@ -97,6 +100,7 @@ public void testObjectTypes() { assertSubclassOf(JA.ReasonerFactory, JA.Object); } + @Test public void testModelTypes() { assertSubclassOf(JA.MemoryModel, JA.Model); assertSubclassOf(JA.DefaultModel, JA.Model); @@ -104,16 +108,18 @@ public void testModelTypes() { assertSubclassOf(JA.OntModel, JA.InfModel); assertSubclassOf(JA.NamedModel, JA.Model); assertSubclassOf(JA.FileModel, JA.NamedModel); - // assertSubclassOf( JA.OntModelSpec, JA.ReasonerFactory ); + // assertSubclassOf(JA.OntModelSpec, JA.ReasonerFactory ); } + @Test public void testInfModelProperties() { assertDomain(JA.InfModel, JA.baseModel); assertDomain(JA.InfModel, JA.reasoner); } + @Test public void testOntModelProperties() { assertDomain(JA.OntModel, JA.ontModelSpec); - // assertRange( JA.ReasonerFactory, JA.reasonerURL ); + // assertRange(JA.ReasonerFactory, JA.reasonerURL ); } } diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestBuiltinAssemblerGroup.java b/jena-core/src/test/java/org/apache/jena/assembler/TestBuiltinAssemblerGroup.java index 80679c36bd5..2ad314ca804 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestBuiltinAssemblerGroup.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestBuiltinAssemblerGroup.java @@ -21,15 +21,16 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.assembler.assemblers.*; import org.apache.jena.rdf.model.Resource; import org.apache.jena.shared.PrefixMapping; import org.apache.jena.test.JenaTestLib; public class TestBuiltinAssemblerGroup extends AssemblerTestBase { - public TestBuiltinAssemblerGroup(String name) { - super(name); - } @Override protected Class getAssemblerClass() { @@ -37,6 +38,7 @@ protected Class getAssemblerClass() { } @SuppressWarnings("removal") + @Test public void testGeneralRegistration() { assertAssemblerClass(JA.DefaultModel, DefaultModelAssembler.class); assertAssemblerClass(JA.PrefixMapping, PrefixMappingAssembler.class); @@ -54,6 +56,7 @@ public void testGeneralRegistration() { } @SuppressWarnings("removal") + @Test public void testVariables() { JenaTestLib.assertInstanceOf(DefaultModelAssembler.class, Assembler.defaultModel); JenaTestLib.assertInstanceOf(PrefixMappingAssembler.class, Assembler.prefixMapping); @@ -68,12 +71,14 @@ public void testVariables() { JenaTestLib.assertInstanceOf(UnionModelAssembler.class, Assembler.unionModel); } + @Test public void testRecognisesAndAssemblesSinglePrefixMapping() { PrefixMapping wanted = PrefixMapping.Factory.create().setNsPrefix("P", "spoo:/"); Resource r = resourceInModel("x ja:prefix 'P'; x ja:namespace 'spoo:/'"); assertEquals(wanted, Assembler.general().open(r)); } + @Test public void testRecognisesAndAssemblesMultiplePrefixMappings() { PrefixMapping wanted = PrefixMapping.Factory.create().setNsPrefix("P", "spoo:/").setNsPrefix("Q", "flarn:/"); Resource r = resourceInModel("x ja:includes y; x ja:includes z; y ja:prefix 'P'; y ja:namespace 'spoo:/'; z ja:prefix 'Q'; z ja:namespace 'flarn:/'"); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestContentAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestContentAssembler.java index 7deb02116a7..ee0dbbfe191 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestContentAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestContentAssembler.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.assembler.assemblers.ContentAssembler; import org.apache.jena.assembler.exceptions.UnknownEncodingException; import org.apache.jena.rdf.model.*; @@ -29,25 +33,24 @@ public class TestContentAssembler extends AssemblerTestBase { protected static String Testing = "testing/assemblers"; - public TestContentAssembler(String name) { - super(name); - } - @Override protected Class getAssemblerClass() { return ContentAssembler.class; } + @Test public void testContentAssemblerType() { testDemandsMinimalType(new ContentAssembler(), JA.Content); } + @Test public void testContentVocabulary() { assertSubclassOf(JA.Content, JA.HasFileManager); assertSubclassOf(JA.ContentItem, JA.Content); - // assertSubclassOf( JA.LiteralContent, JA.Content ); + // assertSubclassOf(JA.LiteralContent, JA.Content ); } + @Test public void testContent() { Assembler a = new ContentAssembler(); Content c = (Content)a.open(resourceInModel("x rdf:type ja:Content")); @@ -57,6 +60,7 @@ public void testContent() { assertEquals(0, m.size()); } + @Test public void testMultipleLiteralsWorks() { Assembler a = new ContentAssembler(); String A = " a .".replaceAll(" ", "\\\\s"); @@ -67,6 +71,7 @@ public void testMultipleLiteralsWorks() { ModelTestLib.assertIsoModels(model("Type rdf:type rdfs:Class; A rdf:type Type"), C.fill(model(""))); } + @Test public void testN3StringContentSingleTriples() { testStringContent("_x rdf:value '17'xsd:integer", "_:x rdf:value 17 ."); testStringContent("_x rdf:value '42'xsd:integer", "_:x rdf:value 42 ."); @@ -76,10 +81,12 @@ public void testN3StringContentSingleTriples() { testStringContent("_x dc:title 'A\\sTitle'", "_:x dc:title 'A Title' ."); } + @Test public void testN3StringContentMultipleTriples() { testStringContent("x rdf:value 5; y owl:sameAs x", " rdf:value 5 . owl:sameAs ."); } + @Test public void testRDFXMLContent() { Assembler a = new ContentAssembler(); String Stuff = "".replaceAll(" ", "\\\\s"); @@ -89,6 +96,7 @@ public void testRDFXMLContent() { ModelTestLib.assertIsoModels(model("_x rdf:type owl:Class"), c.fill(model(""))); } + @Test public void testSingleExternalContent() { Assembler a = new ContentAssembler(); String source = Testing + "/schema.n3"; @@ -97,6 +105,7 @@ public void testSingleExternalContent() { ModelTestLib.assertIsoModels(FileManager.getInternal().loadModelInternal("file:" + source), c.fill(model(""))); } + @Test public void testMultipleExternalContent() { Assembler a = new ContentAssembler(); String sourceA = Testing + "/schema.n3"; @@ -109,6 +118,7 @@ public void testMultipleExternalContent() { ModelTestLib.assertIsoModels(wanted, c.fill(model(""))); } + @Test public void testIndirectContent() { Assembler a = new ContentAssembler(); Resource root = resourceInModel("x rdf:type ja:Content; x ja:content y" + "; y rdf:type ja:Content; y ja:content z" @@ -118,6 +128,7 @@ public void testIndirectContent() { ModelTestLib.assertIsoModels(wanted, c.fill(model(""))); } + @Test public void testTrapsBadEncodings() { Assembler a = new ContentAssembler(); Resource root = resourceInModel("x rdf:type ja:Content; x ja:contentEncoding 'bogus'; x ja:literalContent 'sham'"); @@ -130,6 +141,7 @@ public void testTrapsBadEncodings() { } } + @Test public void testContentTrapsBadObjects() { testContentTrapsBadObjects("ja:content", "17"); // testContentTrapsBadObjects( "ja:externalContent", "17" ); @@ -152,6 +164,7 @@ private void testContentTrapsBadObjects(String property, String value) { } } + @Test public void testMixedContent() { Assembler a = new ContentAssembler(); String source = Testing + "/schema.n3"; @@ -163,6 +176,7 @@ public void testMixedContent() { ModelTestLib.assertIsoModels(wanted, c.fill(model(""))); } + @Test public void testSingleContentQuotation() { Assembler a = new ContentAssembler(); Resource root = resourceInModel("c rdf:type ja:Content; c rdf:type ja:QuotedContent; c ja:quotedContent x; x P A; x Q B"); @@ -170,6 +184,7 @@ public void testSingleContentQuotation() { ModelTestLib.assertIsoModels(model("x P A; x Q B"), c.fill(model(""))); } + @Test public void testMultipleContentQuotation() { Assembler a = new ContentAssembler(); Resource root = resourceInModel("c rdf:type ja:Content; c rdf:type ja:QuotedContent; c ja:quotedContent x" @@ -178,6 +193,7 @@ public void testMultipleContentQuotation() { ModelTestLib.assertIsoModels(model("x P A; x Q B; y R C"), c.fill(model(""))); } + @Test public void testContentLoadsPrefixMappings() { Assembler a = new ContentAssembler(); String content = "@prefix foo: . rdf:type rdf:Property.".replaceAll(" ", "\\\\s"); @@ -200,16 +216,19 @@ protected void testStringContent(String expected, String n3) { /* -- ContentAssembler FileManager tests ---------------------------------- */ + @Test public void testContentAssemblerHasNoDefaultFileManager() { - assertNull("by default, ContentAssemblers have no FileManager", new ContentAssembler().getFileManager()); + assertNull(new ContentAssembler().getFileManager(), "by default, ContentAssemblers have no FileManager"); } + @Test public void testContentAssemblerHasSuppliedFileManager() { @SuppressWarnings("deprecation") FileManager fm = FileManager.create(); assertSame(fm, new ContentAssembler(fm).getFileManager()); } + @Test public void testUsesSuppliedFileManager() { final boolean[] used = {false}; FileManager fm = new FileManagerImpl() { @@ -224,9 +243,10 @@ public Model loadModelInternal(String filenameOrURI) { Resource root = resourceInModel("x rdf:type ja:Content; x rdf:type ja:ExternalContent; x ja:externalContent file:" + source); Content c = (Content)a.open(root); ModelTestLib.assertIsoModels(FileManager.getInternal().loadModelInternal("file:" + source), c.fill(model(""))); - assertTrue("the supplied file manager must have been used", used[0]); + assertTrue(used[0], "the supplied file manager must have been used"); } + @Test public void testContentAssemblerUsesFileManagerProperty() { Model expected = model("a P b"); String fileName = "file:spoo"; diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestDefaultModelAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestDefaultModelAssembler.java index 31a803878ce..944fc30b3a6 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestDefaultModelAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestDefaultModelAssembler.java @@ -21,25 +21,28 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.assembler.assemblers.DefaultModelAssembler; import org.apache.jena.rdf.model.Model; public class TestDefaultModelAssembler extends AssemblerTestBase { - public TestDefaultModelAssembler(String name) { - super(name); - } @Override protected Class getAssemblerClass() { return DefaultModelAssembler.class; } + @Test public void testDefaultModelAssembler() { Assembler a = Assembler.defaultModel; Model m = a.openModel(resourceInModel("x rdf:type ja:DefaultModel")); assertNotNull(m.getGraph()); } + @Test public void testDefaultModelAssemblerType() { testDemandsMinimalType(Assembler.defaultModel, JA.DefaultModel); } diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestDocumentManagerAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestDocumentManagerAssembler.java index 345a387a168..3820f720822 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestDocumentManagerAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestDocumentManagerAssembler.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.*; import org.apache.jena.assembler.assemblers.DocumentManagerAssembler; @@ -30,19 +34,18 @@ import org.apache.jena.util.FileManager; public class TestDocumentManagerAssembler extends AssemblerTestBase { - public TestDocumentManagerAssembler(String name) { - super(name); - } @Override protected Class getAssemblerClass() { return DocumentManagerAssembler.class; } + @Test public void testDocumentManagerAssemblerType() { testDemandsMinimalType(new DocumentManagerAssembler(), JA.DocumentManager); } + @Test public void testDocumentManagerVocabulary() { assertSubclassOf(JA.DocumentManager, JA.Object); assertSubclassOf(JA.DocumentManager, JA.HasFileManager); @@ -50,6 +53,7 @@ public void testDocumentManagerVocabulary() { assertDomain(JA.DocumentManager, JA.policyPath); } + @Test public void testCreatesDocumentManager() { Resource root = resourceInModel("x rdf:type ja:DocumentManager"); Assembler a = new DocumentManagerAssembler(); @@ -57,6 +61,7 @@ public void testCreatesDocumentManager() { JenaTestLib.assertInstanceOf(OntDocumentManager.class, x); } + @Test public void testUsesFileManager() { Resource root = resourceInModel("x rdf:type ja:DocumentManager; x ja:fileManager f"); Assembler a = new DocumentManagerAssembler(); @@ -68,6 +73,7 @@ public void testUsesFileManager() { assertSame(fm, ((OntDocumentManager)x).getFileManager()); } + @Test public void testSetsPolicyPath() { Resource root = resourceInModel("x rdf:type ja:DocumentManager; x ja:policyPath 'somePath'"); final List history = new ArrayList<>(); @@ -88,6 +94,7 @@ public void setMetadataSearchPath(String path, boolean replace) { assertEquals(JenaTestLib.listOfOne("somePath"), history); } + @Test public void testTrapsPolicyPathNotString() { testTrapsBadPolicyPath("aResource"); testTrapsBadPolicyPath("17"); @@ -107,6 +114,7 @@ private void testTrapsBadPolicyPath(String path) { } } + @Test public void testSetsMetadata() { // we set policyPath to avoid Ont default models // being thrown at us Resource root = resourceInModel("x rdf:type ja:DocumentManager; x ja:policyPath ''; x P a; a Q b; y R z"); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestImportManager.java b/jena-core/src/test/java/org/apache/jena/assembler/TestImportManager.java index 88cf7b7305b..83a4a8468fb 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestImportManager.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestImportManager.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.*; import org.apache.jena.graph.compose.MultiUnion; @@ -31,9 +35,6 @@ import org.apache.jena.util.FileManagerImpl; public class TestImportManager extends AssemblerTestBase { - public TestImportManager(String name) { - super(name); - } static class FixedFileManager extends FileManagerImpl { Map map = new HashMap<>(); @@ -52,6 +53,7 @@ public FixedFileManager add(String URL, Model m) { } } + @Test public void testFollowOwlImports() { final Model modelToLoad = model("this hasMarker B5"); Model m = model("x ja:reasoner y; _x owl:imports eh:/loadMe"); @@ -61,6 +63,7 @@ public void testFollowOwlImports() { ModelTestLib.assertIsoModels(modelToLoad.union(m), m2); } + @Test public void testFollowJAImports() { final Model modelToLoad = model("this hasMarker B5"); Model m = model("x ja:reasoner y; _x ja:imports eh:/loadMe"); @@ -70,6 +73,7 @@ public void testFollowJAImports() { ModelTestLib.assertIsoModels(modelToLoad.union(m), m2); } + @Test public void testImportMayBeLiteral() { final Model modelToLoad = model("this hasMarker B5"); Model m = model("x ja:reasoner y; _x ja:imports 'eh:/loadMe'"); @@ -79,6 +83,7 @@ public void testImportMayBeLiteral() { ModelTestLib.assertIsoModels(modelToLoad.union(m), m2); } + @Test public void testBadImportObjectFails() { testBadImportObjectFails("_bnode"); testBadImportObjectFails("17"); @@ -98,6 +103,7 @@ private void testBadImportObjectFails(String object) { } } + @Test public void testFollowOwlImportsDeeply() { final Model m1 = model("this hasMarker M1; _x owl:imports M2"), m2 = model("this hasMarker M2"); Model m = model("x ja:reasoner y; _x owl:imports M1"); @@ -107,6 +113,7 @@ public void testFollowOwlImportsDeeply() { ModelTestLib.assertIsoModels(m1.union(m2).union(m), result); } + @Test public void testCatchesCircularity() { final Model m1 = model("this hasMarker Mx; _x owl:imports My"), m2 = model("this hasMarker My; _x owl:imports Mx"); FileManager fm = new FixedFileManager().add("eh:/Mx", m1).add("eh:/My", m2); @@ -114,6 +121,7 @@ public void testCatchesCircularity() { ModelTestLib.assertIsoModels(m1.union(m2), result); } + @Test public void testCacheModels() { ImportManager im = new ImportManager(); Model spec = model("_x owl:imports M1"); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestInfModelAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestInfModelAssembler.java index 586686b1d91..38278a6e766 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestInfModelAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestInfModelAssembler.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.assembler.assemblers.InfModelAssembler; import org.apache.jena.assembler.exceptions.NotUniqueException; import org.apache.jena.rdf.model.*; @@ -29,34 +33,36 @@ import org.apache.jena.test.JenaTestLib; public class TestInfModelAssembler extends AssemblerTestBase { - public TestInfModelAssembler(String name) { - super(name); - } @Override protected Class getAssemblerClass() { return InfModelAssembler.class; } + @Test public void testLocationMapperAssemblerType() { testDemandsMinimalType(new InfModelAssembler(), JA.InfModel); } + @Test public void testMockReasonersDifferent() { Reasoner R = GenericRuleReasonerFactory.theInstance().create(null); assertNotSame(mockReasonerFactory(R), mockReasonerFactory(R)); } + @Test public void testInfModel() { Assembler a = Assembler.infModel; Model m = a.openModel(resourceInModel("x rdf:type ja:InfModel")); JenaTestLib.assertInstanceOf(InfModel.class, m); } + @Test public void testInfModelType() { testDemandsMinimalType(Assembler.infModel, JA.InfModel); } + @Test public void testGetsReasoner() { Reasoner R = GenericRuleReasonerFactory.theInstance().create(null); final ReasonerFactory RF = mockReasonerFactory(R); @@ -85,6 +91,7 @@ public String getURI() { }; } + @Test public void testGetsSpecifiedModel() { Model base = ModelFactory.createDefaultModel(); Resource root = resourceInModel("x rdf:type ja:InfModel; x ja:baseModel M"); @@ -93,6 +100,7 @@ public void testGetsSpecifiedModel() { assertSame(base.getGraph(), inf.getRawModel().getGraph()); } + @Test public void testDetectsMultipleBaseModels() { Model base = ModelFactory.createDefaultModel(); Resource root = resourceInModel("x rdf:type ja:InfModel; x ja:baseModel M; x ja:baseModel M2"); @@ -106,6 +114,7 @@ public void testDetectsMultipleBaseModels() { } } + @Test public void testDetectsMultipleReasoners() { Resource root = resourceInModel("x rdf:type ja:InfModel; x ja:reasoner R; x ja:reasoner R2"); Assembler mock = new FixedObjectAssembler(null); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestMemoryModelAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestMemoryModelAssembler.java index 518cb765be2..727fe9b3d5b 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestMemoryModelAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestMemoryModelAssembler.java @@ -21,23 +21,26 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.assembler.assemblers.MemoryModelAssembler; import org.apache.jena.rdf.model.Model; public class TestMemoryModelAssembler extends AssemblerTestBase { - public TestMemoryModelAssembler(String name) { - super(name); - } @Override protected Class getAssemblerClass() { return MemoryModelAssembler.class; } + @Test public void testMemoryModelAssemblerType() { testDemandsMinimalType(new MemoryModelAssembler(), JA.MemoryModel); } + @Test public void testMemoryModelAssembler() { Assembler a = new MemoryModelAssembler(); Model m = a.openModel(resourceInModel("x rdf:type ja:MemoryModel")); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestMode.java b/jena-core/src/test/java/org/apache/jena/assembler/TestMode.java index 78a18093f43..77c59f08828 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestMode.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestMode.java @@ -21,13 +21,11 @@ package org.apache.jena.assembler; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import org.apache.jena.rdf.model.Resource; import org.apache.jena.rdf.model.ResourceFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestMode { diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestModelAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestModelAssembler.java index 70c840e842d..d7e20c3f323 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestModelAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestModelAssembler.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.assembler.assemblers.ContentAssembler; import org.apache.jena.assembler.assemblers.ModelAssembler; import org.apache.jena.rdf.model.Model; @@ -37,21 +41,19 @@ protected Model openEmptyModel(Assembler a, Resource root, Mode mode) { } } - public TestModelAssembler(String name) { - super(name); - } - @Override protected Class getAssemblerClass() { return null; } + @Test public void testContent() { Resource root = resourceInModel("x rdf:type ja:DefaultModel; x ja:initialContent c; c ja:quotedContent A; A P B"); Model m = (Model)new FakeModelAssembler().open(new ContentAssembler(), root, Mode.ANY); ModelTestLib.assertIsoModels(ModelTestLib.modelWithStatements("A P B"), m); } + @Test public void testGetsPrefixMappings() { Assembler a = new FakeModelAssembler(); PrefixMapping wanted = PrefixMapping.Factory.create().setNsPrefix("my", "urn:secret:42/").setNsPrefix("your", "urn:public:17#"); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestModelContent.java b/jena-core/src/test/java/org/apache/jena/assembler/TestModelContent.java index 86cb8218d3a..7ed230eb828 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestModelContent.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestModelContent.java @@ -21,41 +21,48 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.*; import org.apache.jena.rdf.model.*; import org.apache.jena.test.JenaTestLib; public class TestModelContent extends AssemblerTestBase { - public TestModelContent(String name) { - super(name); - } @Override protected Class getAssemblerClass() { return null; } + @Test public void testMemoryModelLoadsSingleContent() { testModelLoadsSingleContent(Assembler.memoryModel, JA.MemoryModel); } + @Test public void testMemoryModelLoadsMultipleContent() { testModelLoadsMultipleContent(Assembler.memoryModel, JA.MemoryModel); } + @Test public void testDefaultModelLoadsSingleContent() { testModelLoadsSingleContent(Assembler.defaultModel, JA.DefaultModel); } + @Test public void testDefaultModelLoadsMultipleContent() { testModelLoadsMultipleContent(Assembler.defaultModel, JA.DefaultModel); } + @Test public void testInfModelLoadsContent() { testModelLoadsMultipleContent(Assembler.infModel, JA.InfModel); } + @Test public void testContentTransactionsNone() { final List history = new ArrayList<>(); final Model expected = model("_x rdf:value '17'xsd:integer"); @@ -66,6 +73,7 @@ public void testContentTransactionsNone() { } catch (RuntimeException e) {} } + @Test public void testContentTransactionsCommit() { final List history = new ArrayList<>(); final Model expected = model("_x rdf:value '17'xsd:integer"); @@ -76,6 +84,7 @@ public void testContentTransactionsCommit() { ModelTestLib.assertIsoModels(expected, m); } + @Test public void testContentTransactionsAbort() { final List history = new ArrayList<>(); final Model expected = model("_x rdf:value '17'xsd:integer"); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestModelExpansion.java b/jena-core/src/test/java/org/apache/jena/assembler/TestModelExpansion.java index de32b13fc38..7f3acbe6626 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestModelExpansion.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestModelExpansion.java @@ -21,16 +21,18 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.*; import org.apache.jena.rdf.model.*; import org.apache.jena.test.JenaTestLib; public class TestModelExpansion extends AssemblerTestBase { - public TestModelExpansion(String name) { - super(name); - } + @Test public void testAddsSubclasses() { Model base = model("a R b"); Model schema = model("x rdfs:subClassOf y; y P z"); @@ -38,6 +40,7 @@ public void testAddsSubclasses() { ModelTestLib.assertIsoModels(model("a R b; x rdfs:subClassOf y"), answer); } + @Test public void testOmitsAnonynousSubclasses() { Model base = model("a R b"); Model schema = model("x rdfs:subClassOf _y; z rdfs:subClassOf _a"); @@ -45,6 +48,7 @@ public void testOmitsAnonynousSubclasses() { ModelTestLib.assertIsoModels(model("a R b"), answer); } + @Test public void testAddsDomainTypes() { Model base = model("a R b"); Model schema = model("R rdfs:domain T"); @@ -52,6 +56,7 @@ public void testAddsDomainTypes() { ModelTestLib.assertIsoModels(model("a R b; a rdf:type T"), answer); } + @Test public void testAddsRangeTypes() { Model base = model("a R b"); Model schema = model("R rdfs:range T"); @@ -59,12 +64,14 @@ public void testAddsRangeTypes() { ModelTestLib.assertIsoModels(model("a R b; b rdf:type T"), answer); } + @Test public void testLabelsDontCrashExpansion() { Model base = ModelFactory.createRDFSModel(model("a R b; a rdfs:label 'hello'")); Model schema = ModelFactory.createRDFSModel(model("R rdfs:range T")); Model answer = ModelExpansion.withSchema(base, schema); } + @Test public void testIntersection() { testIntersection("x rdf:type T; x rdf:type U", true, "T U"); testIntersection("x rdf:type T; x rdf:type U", true, "T"); @@ -76,7 +83,7 @@ private void testIntersection(String xTyped, boolean infers, String intersection Model base = model(xTyped); Model schema = intersectionModel("I", intersectionTypes); Model answer = ModelExpansion.withSchema(base, schema); - assertEquals("should [not] infer (x rdf:type I)", infers, answer.contains(ModelTestLib.statement("x rdf:type I"))); + assertEquals(infers, answer.contains(ModelTestLib.statement("x rdf:type I")), "should [not] infer (x rdf:type I)"); } private Model intersectionModel(String inter, String types) { @@ -96,6 +103,7 @@ private String rdfList(String base, String types) { return result.toString(); } + @Test public void testAddsSupertypes() { Model base = model("a rdf:type T; T rdfs:subClassOf U"); Model schema = model("T rdfs:subClassOf V"); @@ -103,18 +111,21 @@ public void testAddsSupertypes() { ModelTestLib.assertIsoModels(model("a rdf:type T; a rdf:type U; a rdf:type V; T rdfs:subClassOf U; T rdfs:subClassOf V"), answer); } + @Test public void testSubclassClosureA() { Model m = model("A rdfs:subClassOf B; B rdfs:subClassOf C"); subClassClosure(m); ModelTestLib.assertIsoModels(model("A rdfs:subClassOf B; B rdfs:subClassOf C; A rdfs:subClassOf C"), m); } + @Test public void testSubclassClosureB() { Model m = model("A rdfs:subClassOf B; B rdfs:subClassOf C; X rdfs:subClassOf C"); subClassClosure(m); ModelTestLib.assertIsoModels(model("A rdfs:subClassOf B; B rdfs:subClassOf C; A rdfs:subClassOf C; X rdfs:subClassOf C"), m); } + @Test public void testSubclassClosureC() { Model m = model("A rdfs:subClassOf B; B rdfs:subClassOf C; X rdfs:subClassOf C; Y rdfs:subClassOf X"); subClassClosure(m); @@ -122,6 +133,7 @@ public void testSubclassClosureC() { m); } + @Test public void testSubclassClosureD() { Model m = model("A rdfs:subClassOf B; B rdfs:subClassOf C; X rdfs:subClassOf C; Y rdfs:subClassOf X; U rdfs:subClassOf A; U rdfs:subClassOf Y"); subClassClosure(m); @@ -129,6 +141,7 @@ public void testSubclassClosureD() { m); } + @Test public void testSubclassClosureE() { Model m = model("A rdfs:subClassOf B; B rdfs:subClassOf C"); subClassClosure(m); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelAcceptance.java b/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelAcceptance.java index 75dc384bdbe..52394f11dd8 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelAcceptance.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelAcceptance.java @@ -21,14 +21,15 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.ontology.*; import org.apache.jena.rdf.model.*; @SuppressWarnings("removal") public class TestOntModelAcceptance extends AssemblerTestBase { - public TestOntModelAcceptance(String name) { - super(name); - } /** * Acceptance test inherited from ontology ModelSpec tests when ModelSpec went @@ -36,6 +37,7 @@ public TestOntModelAcceptance(String name) { * some) reasoning. Probably unnecessary given the way the assembler unit test * suite works but belt-and-braces for now at least. */ + @Test public void test_ijd_01() { Model m = ModelTestLib.modelWithStatements("x ja:ontModelSpec _o" + "; _o ja:reasonerFactory _f; _o ja:ontLanguage http://www.w3.org/2002/07/owl#" diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelAssembler.java index 658219a9864..afd9a84d83f 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelAssembler.java @@ -21,10 +21,20 @@ package org.apache.jena.assembler; -import java.lang.reflect.Field; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Arrays; +import java.util.stream.Stream; + +import org.junit.jupiter.api.Named; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import org.junit.jupiter.api.Test; + import java.util.List; -import junit.framework.*; import org.apache.jena.assembler.assemblers.*; import org.apache.jena.ontology.*; import org.apache.jena.rdf.model.*; @@ -32,54 +42,42 @@ @SuppressWarnings("removal") public class TestOntModelAssembler extends AssemblerTestBase { - public TestOntModelAssembler(String name) { - super(name); - } - - public static TestSuite suite() { - TestSuite result = new TestSuite(); - result.addTestSuite(TestOntModelAssembler.class); - addParameterisedTests(result); - return result; - } @Override protected Class getAssemblerClass() { return OntModelAssembler.class; } + @Test public void testOntModelAssemblerType() { testDemandsMinimalType(new OntModelAssembler(), JA.OntModel); } - protected static void addParameterisedTests(TestSuite result) { - Field[] fields = OntModelSpec.class.getFields(); - for ( Field f : fields ) { - String name = f.getName(); - if ( f.getType() == OntModelSpec.class ) { - try { - result.addTest(createTest((OntModelSpec)f.get(null), name)); - } catch (Exception e) { - System.err.println("WARNING: failed to create test for OntModelSpec " + name); - } - } - } + /** One case per public {@code OntModelSpec} constant - was addParameterisedTests(). */ + static Stream builtinSpecs() { + return Arrays.stream(OntModelSpec.class.getFields()) + .filter(f->f.getType() == OntModelSpec.class) + .map(f->{ + try { + return Arguments.of(Named.of(f.getName(), (OntModelSpec)f.get(null)), f.getName()); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + }); } - protected static Test createTest(final OntModelSpec spec, final String name) { - return new TestOntModelAssembler(name) { - @Override - public void runBare() { - Assembler a = new OntModelAssembler(); - Model m = (Model)a.open(new FixedObjectAssembler(spec), - resourceInModel("x rdf:type ja:OntModel; x ja:ontModelSpec ja:" + name)); - JenaTestLib.assertInstanceOf(OntModel.class, m); - OntModel om = (OntModel)m; - assertSame(spec, om.getSpecification()); - } - }; + @ParameterizedTest(name = "{0}") + @MethodSource("builtinSpecs") + public void testBuiltinSpec(OntModelSpec spec, String name) { + Assembler a = new OntModelAssembler(); + Model m = (Model)a.open(new FixedObjectAssembler(spec), + resourceInModel("x rdf:type ja:OntModel; x ja:ontModelSpec ja:" + name)); + JenaTestLib.assertInstanceOf(OntModel.class, m); + OntModel om = (OntModel)m; + assertSame(spec, om.getSpecification()); } + @Test public void testAllDefaults() { Assembler a = new OntModelAssembler(); Model m = a.openModel(resourceInModel("x rdf:type ja:OntModel")); @@ -88,6 +86,7 @@ public void testAllDefaults() { assertSame(OntModelSpec.OWL_MEM_RDFS_INF, om.getSpecification()); } + @Test public void testBaseModel() { final Model baseModel = model("a P b"); Assembler a = new OntModelAssembler(); @@ -104,6 +103,7 @@ protected Model openEmptyModel(Assembler a, Resource root, Mode irrelevant) { assertSame(baseModel.getGraph(), om.getBaseModel().getGraph()); } + @Test public void testSubModels() { final Model baseModel = model("a P b"); Assembler a = new OntModelAssembler(); @@ -122,6 +122,7 @@ protected Model openEmptyModel(Assembler a, Resource root, Mode irrelevant) { assertSame(baseModel.getGraph(), subModels.get(0).getBaseModel().getGraph()); } + @Test public void testDefaultDocumentManager() { Assembler a = new OntModelAssembler(); Resource root = resourceInModel("x rdf:type ja:OntModel"); @@ -129,6 +130,7 @@ public void testDefaultDocumentManager() { assertSame(OntDocumentManager.getInstance(), om.getDocumentManager()); } + @Test public void testUsesOntModelSpec() { Assembler a = new OntModelAssembler(); Resource root = resourceInModel("x rdf:type ja:OntModel; x ja:ontModelSpec y"); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelSpecAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelSpecAssembler.java index 8dde8d41c0d..3ea95c7ef83 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelSpecAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestOntModelSpecAssembler.java @@ -21,9 +21,18 @@ package org.apache.jena.assembler; -import java.lang.reflect.Field; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Arrays; +import java.util.stream.Stream; + +import org.junit.jupiter.api.Named; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import org.junit.jupiter.api.Test; -import junit.framework.*; import org.apache.jena.assembler.assemblers.*; import org.apache.jena.assembler.exceptions.ReasonerClashException; import org.apache.jena.ontology.*; @@ -36,41 +45,33 @@ @SuppressWarnings("removal") public class TestOntModelSpecAssembler extends AssemblerTestBase { - public TestOntModelSpecAssembler(String name) { - super(name); - } @Override protected Class getAssemblerClass() { return OntModelSpecAssembler.class; } + @Test public void testOntModelSpecAssemblerType() { testDemandsMinimalType(new OntModelSpecAssembler(), JA.OntModelSpec); } - public static TestSuite suite() { - TestSuite result = new TestSuite(); - result.addTestSuite(TestOntModelSpecAssembler.class); - addParameterisedTests(result); - return result; + /** One case per public {@code OntModelSpec} constant - was addParameterisedTests(). */ + static Stream builtinSpecs() { + return Arrays.stream(OntModelSpec.class.getFields()) + .filter(f->f.getType() == OntModelSpec.class) + .map(f->{ + try { + return Arguments.of(Named.of(f.getName(), (OntModelSpec)f.get(null)), f.getName()); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + }); } - protected static void addParameterisedTests(TestSuite result) { - Field[] fields = OntModelSpec.class.getFields(); - for ( Field f : fields ) { - String name = f.getName(); - if ( f.getType() == OntModelSpec.class ) { - try { - result.addTest(createTest((OntModelSpec)f.get(null), name)); - } catch (Exception e) { - System.err.println("WARNING: failed to create test for OntModelSpec " + name); - } - } - } - } - - protected void testBuiltinSpec(OntModelSpec ontModelSpec, String specName) { + @ParameterizedTest(name = "{0}") + @MethodSource("builtinSpecs") + public void testBuiltinSpec(OntModelSpec ontModelSpec, String specName) { testBuiltinSpecAsRootName(ontModelSpec, specName); testBuiltinSpecAsLikeTarget(ontModelSpec, specName); } @@ -85,21 +86,14 @@ private void testBuiltinSpecAsRootName(OntModelSpec ontModelSpec, String specNam assertEquals(ontModelSpec, new OntModelSpecAssembler().open(root)); } - protected static Test createTest(final OntModelSpec spec, final String name) { - return new TestOntModelSpecAssembler(name) { - @Override - public void runBare() { - testBuiltinSpec(spec, name); - } - }; - } - + @Test public void testOntModelSpecVocabulary() { assertDomain(JA.OntModelSpec, JA.ontLanguage); assertDomain(JA.OntModelSpec, JA.documentManager); assertDomain(JA.OntModelSpec, JA.likeBuiltinSpec); } + @Test public void testCreateFreshDocumentManager() { Assembler a = new OntModelSpecAssembler(); Resource root = resourceInModel("x rdf:type ja:OntModelSpec; x ja:documentManager y"); @@ -109,6 +103,7 @@ public void testCreateFreshDocumentManager() { assertSame(dm, om.getDocumentManager()); } + @Test public void testUseSpecifiedReasoner() { Assembler a = new OntModelSpecAssembler(); Resource root = resourceInModel("x rdf:type ja:OntModelSpec; x ja:reasonerFactory R"); @@ -118,6 +113,7 @@ public void testUseSpecifiedReasoner() { assertSame(rf, om.getReasonerFactory()); } + @Test public void testUseSpecifiedImpliedReasoner() { testUsedSpecifiedImpliedReasoner(OWLFBRuleReasonerFactory.URI); testUsedSpecifiedImpliedReasoner(RDFSRuleReasonerFactory.URI); @@ -132,6 +128,7 @@ private void testUsedSpecifiedImpliedReasoner(String R) { assertSame(rf, om.getReasonerFactory()); } + @Test public void testDetectsClashingImpliedAndExplicitReasoners() { Assembler a = new OntModelSpecAssembler(); Resource root = resourceInModel("x rdf:type ja:OntModelSpec; x ja:reasonerURL R; x ja:reasonerFactory F"); @@ -144,6 +141,7 @@ public void testDetectsClashingImpliedAndExplicitReasoners() { } } + @Test public void testUseSpecifiedLanguage() { testSpecifiedLanguage(ProfileRegistry.OWL_DL_LANG); testSpecifiedLanguage(ProfileRegistry.OWL_LANG); @@ -158,6 +156,7 @@ private void testSpecifiedLanguage(String lang) { assertEquals(lang, om.getLanguage()); } + @Test public void testSpecifiedModelGetter() { Assembler a = new OntModelSpecAssembler(); ModelGetter getter = new ModelGetter() { diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestPrefixMappingAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestPrefixMappingAssembler.java index 8e3be099bcb..70e47175646 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestPrefixMappingAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestPrefixMappingAssembler.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.assembler.assemblers.PrefixMappingAssembler; import org.apache.jena.rdf.model.Resource; import org.apache.jena.shared.PrefixMapping; @@ -42,19 +46,18 @@ */ public class TestPrefixMappingAssembler extends AssemblerTestBase { - public TestPrefixMappingAssembler(String name) { - super(name); - } @Override protected Class getAssemblerClass() { return PrefixMappingAssembler.class; } + @Test public void testPrefixMappingAssemblerType() { testDemandsMinimalType(new PrefixMappingAssembler(), JA.PrefixMapping); } + @Test public void testConstructEmptyPrefixMapping() { Assembler a = new PrefixMappingAssembler(); Resource root = resourceInModel("pm rdf:type ja:PrefixMapping"); @@ -62,6 +65,7 @@ public void testConstructEmptyPrefixMapping() { JenaTestLib.assertInstanceOf(PrefixMapping.class, pm); } + @Test public void testSimplePrefixMapping() { PrefixMapping wanted = PrefixMapping.Factory.create().setNsPrefix("pre", "some:prefix/"); Assembler a = new PrefixMappingAssembler(); @@ -70,6 +74,7 @@ public void testSimplePrefixMapping() { assertSamePrefixMapping(wanted, pm); } + @Test public void testIncludesSingleMapping() { PrefixMapping wanted = PrefixMapping.Factory.create().setNsPrefix("pre", "some:prefix/"); Assembler a = new PrefixMappingAssembler(); @@ -79,6 +84,7 @@ public void testIncludesSingleMapping() { assertSamePrefixMapping(wanted, pm); } + @Test public void testIncludesMultipleMappings() { PrefixMapping wanted = PrefixMapping.Factory.create().setNsPrefix("p1", "some:prefix/").setNsPrefix("p2", "other:prefix/") .setNsPrefix("p3", "simple:prefix#"); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestReasonerFactoryAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestReasonerFactoryAssembler.java index 025aa88341e..c3d0925de69 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestReasonerFactoryAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestReasonerFactoryAssembler.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.ArrayList; import java.util.HashSet; @@ -39,24 +43,23 @@ public class TestReasonerFactoryAssembler extends AssemblerTestBase { private final Assembler ASSEMBLER = new ReasonerFactoryAssembler(); - public TestReasonerFactoryAssembler(String name) { - super(name); - } - @Override protected Class getAssemblerClass() { return ReasonerFactoryAssembler.class; } + @Test public void testReasonerFactoryAssemblerType() { testDemandsMinimalType(new ReasonerFactoryAssembler(), JA.ReasonerFactory); } + @Test public void testCreateReasonerFactory() { Resource root = resourceInModel("x rdf:type ja:ReasonerFactory"); JenaTestLib.assertInstanceOf(GenericRuleReasonerFactory.class, ASSEMBLER.open(root)); } + @Test public void testStandardReasonerURLs() { testReasonerURL(GenericRuleReasonerFactory.class, GenericRuleReasonerFactory.URI); testReasonerURL(TransitiveReasonerFactory.class, TransitiveReasonerFactory.URI); @@ -66,6 +69,7 @@ public void testStandardReasonerURLs() { testReasonerURL(OWLMiniReasonerFactory.class, OWLMiniReasonerFactory.URI); } + @Test public void testBadReasonerURLFails() { Resource root = resourceInModel("x rdf:type ja:ReasonerFactory; x ja:reasonerURL bad:URL"); try { @@ -101,6 +105,7 @@ public static ReasonerFactory theInstance() { } } + @Test public void testReasonerClassThrowsIfClassNotFound() { String description = "x rdf:type ja:ReasonerFactory; x ja:reasonerClass java:noSuchClass"; Resource root = resourceInModel(description); @@ -112,6 +117,7 @@ public void testReasonerClassThrowsIfClassNotFound() { } } + @Test public void testReasonerClassThrowsIfClassNotFactory() { String description = "x rdf:type ja:ReasonerFactory; x ja:reasonerClass java:java.util.ArrayList"; Resource root = resourceInModel(description); @@ -125,6 +131,7 @@ public void testReasonerClassThrowsIfClassNotFactory() { } } + @Test public void testReasonerClassUsesTheInstance() { String description = "x rdf:type ja:ReasonerFactory; x ja:reasonerClass java:"; String MockName = MockFactory.class.getName(); @@ -132,6 +139,7 @@ public void testReasonerClassUsesTheInstance() { assertEquals(MockFactory.instance, ASSEMBLER.open(root)); } + @Test public void testReasonerClassInstantiatesIfNoInstance() { String description = "x rdf:type ja:ReasonerFactory; x ja:reasonerClass java:"; String MockName = MockBase.class.getName(); @@ -140,6 +148,7 @@ public void testReasonerClassInstantiatesIfNoInstance() { assertNotSame(MockFactory.instance, ASSEMBLER.open(root)); } + @Test public void testMultipleURLsFails() { Resource root = resourceInModel("x rdf:type ja:ReasonerFactory; x ja:reasonerURL bad:URL; x ja:reasonerURL another:bad/URL"); try { @@ -151,6 +160,7 @@ public void testMultipleURLsFails() { } } + @Test public void testOnlyGenericReasonerCanHaveRules() { String url = TransitiveReasonerFactory.URI; Resource root = resourceInModel("x rdf:type ja:ReasonerFactory; x ja:rule '[->(a\\sP\\sb)]'; x ja:reasonerURL " + url); @@ -162,6 +172,7 @@ public void testOnlyGenericReasonerCanHaveRules() { } catch (CannotHaveRulesException e) {} } + @Test public void testSchema() { Model schema = model("P rdf:type owl:ObjectProperty"); Resource root = resourceInModel("x rdf:type ja:ReasonerFactory; x ja:schema S"); @@ -171,6 +182,7 @@ public void testSchema() { GraphTestLib.assertIsomorphic(schema.getGraph(), ((FBRuleReasoner)r).getBoundSchema()); } + @Test public void testSingleRules() { Resource root = resourceInModel("x rdf:type ja:ReasonerFactory; x ja:rules S"); String ruleStringA = "[rdfs2: (?x ?p ?y), (?p rdfs:domain ?c) -> (?x rdf:type ?c)]"; @@ -187,6 +199,7 @@ public Object open(Assembler a, Resource root, Mode irrelevant) { assertEquals(new HashSet<>(rules.getRules()), new HashSet<>(grr.getRules())); } + @Test public void testMultipleRules() { Resource root = resourceInModel("x rdf:type ja:ReasonerFactory; x ja:rules S; x ja:rules T"); String ruleStringA = "[rdfs2: (?x ?p ?y), (?p rdfs:domain ?c) -> (?x rdf:type ?c)]"; diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestRuleSet.java b/jena-core/src/test/java/org/apache/jena/assembler/TestRuleSet.java index 5ddea64a8cc..be291a71e82 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestRuleSet.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestRuleSet.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.*; import org.apache.jena.reasoner.rulesys.Rule; @@ -28,26 +32,26 @@ import org.apache.jena.test.JenaTestLib; public class TestRuleSet extends AssemblerTestBase { - public TestRuleSet(String name) { - super(name); - } @Override protected Class getAssemblerClass() { throw new BrokenException("TestAssemblers does not need this method"); } + @Test public void testEmpty() { assertEquals(Collections.emptyList(), RuleSet.empty.getRules()); assertEquals(RuleSet.empty, RuleSet.create(Collections. emptyList())); } + @Test public void testEmptyRuleSet() { RuleSet s = RuleSet.create(Collections. emptyList()); assertEquals(Collections.emptyList(), s.getRules()); assertNotSame(Collections.emptyList(), s.getRules()); } + @Test public void testSingleRuleSet() { Rule rule = Rule.parseRule("[(?a P b) -> (?a rdf:type T)]"); List list = JenaTestLib.listOfOne(rule); @@ -56,6 +60,7 @@ public void testSingleRuleSet() { assertNotSame(list, s.getRules()); } + @Test public void testMultipleRuleSet() { Rule A = Rule.parseRule("[(?a P b) -> (?a rdf:type T)]"); Rule B = Rule.parseRule("[(?a Q b) -> (?a rdf:type U)]"); @@ -65,12 +70,14 @@ public void testMultipleRuleSet() { assertNotSame(rules, s.getRules()); } + @Test public void testFactoryForString() { String ruleString = "[(?a P b) -> (?a rdf:type T)]"; RuleSet s = RuleSet.create(ruleString); assertEquals(Rule.parseRules(ruleString), s.getRules()); } + @Test public void testHashAndEquality() { String A = "[(?x breaks ?y) -> (?y brokenBy ?x)]"; String B = "[(?a Q b) -> (?a rdf:type U)]"; diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestRuleSetAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestRuleSetAssembler.java index 0f08877c6e0..f11608c1884 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestRuleSetAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestRuleSetAssembler.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.*; import org.apache.jena.assembler.assemblers.RuleSetAssembler; @@ -28,15 +32,13 @@ import org.apache.jena.reasoner.rulesys.Rule; public class TestRuleSetAssembler extends AssemblerTestBase { - public TestRuleSetAssembler(String name) { - super(name); - } @Override protected Class getAssemblerClass() { return RuleSetAssembler.class; } + @Test public void testRuleSetVocabulary() { assertSubclassOf(JA.RuleSet, JA.HasRules); assertDomain(JA.HasRules, JA.rule); @@ -45,16 +47,19 @@ public void testRuleSetVocabulary() { assertRange(JA.RuleSet, JA.rules); } + @Test public void testRuleSetAssemblerType() { testDemandsMinimalType(new RuleSetAssembler(), JA.RuleSet); } + @Test public void testEmptyRuleSet() { Assembler a = new RuleSetAssembler(); Resource root = resourceInModel("x rdf:type ja:RuleSet"); assertEquals(RuleSet.empty, a.open(root)); } + @Test public void testSingleRuleString() { Assembler a = new RuleSetAssembler(); String ruleString = "[(?a P ?b) -> (?a Q ?b)]"; @@ -64,6 +69,7 @@ public void testSingleRuleString() { assertEquals(expected, new HashSet<>(rules.getRules())); } + @Test public void testMultipleRuleStrings() { Assembler a = new RuleSetAssembler(); String ruleStringA = "[(?a P ?b) -> (?a Q ?b)]"; @@ -76,6 +82,7 @@ public void testMultipleRuleStrings() { assertEquals(expected, new HashSet<>(rules.getRules())); } + @Test public void testRulesFrom() { Assembler a = new RuleSetAssembler(); String rulesA = file("example.rules"); @@ -85,6 +92,7 @@ public void testRulesFrom() { assertEquals(expected, new HashSet<>(rules.getRules())); } + @Test public void testSubRules() { Assembler a = new RuleSetAssembler(); String ruleStringA = "[(?a P ?b) -> (?a Q ?b)]"; @@ -95,6 +103,7 @@ public void testSubRules() { assertEquals(expected, new HashSet<>(rules.getRules())); } + @Test public void testTrapsBadRulesObject() { testTrapsBadRuleObject("ja:rules", "'y'"); testTrapsBadRuleObject("ja:rulesFrom", "17"); diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestUnionModelAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestUnionModelAssembler.java index e86431f95cb..b7a0b544e56 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestUnionModelAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestUnionModelAssembler.java @@ -21,6 +21,10 @@ package org.apache.jena.assembler; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.*; import org.apache.jena.assembler.assemblers.*; @@ -31,19 +35,18 @@ import org.apache.jena.test.JenaTestLib; public class TestUnionModelAssembler extends AssemblerTestBase { - public TestUnionModelAssembler(String name) { - super(name); - } @Override protected Class getAssemblerClass() { return UnionModelAssembler.class; } + @Test public void testUnionModelAssemblerType() { testDemandsMinimalType(new UnionModelAssembler(), JA.UnionModel); } + @Test public void testUnionVocabulary() { assertSubclassOf(JA.UnionModel, JA.Model); assertDomain(JA.UnionModel, JA.subModel); @@ -52,6 +55,7 @@ public void testUnionVocabulary() { assertRange(JA.Model, JA.rootModel); } + @Test public void testCreatesMultiUnion() { Resource root = resourceInModel("x rdf:type ja:UnionModel"); Assembler a = new UnionModelAssembler(); @@ -88,6 +92,7 @@ public Object open(Assembler a, Resource root, Mode irrelevant) { } } + @Test public void testCreatesUnionWithSubModels() { Resource root = resourceInModel("x rdf:type ja:UnionModel; x ja:subModel A; x ja:subModel B"); Assembler a = new UnionModelAssembler(); @@ -104,6 +109,7 @@ public void testCreatesUnionWithSubModels() { checkImmutable(m); } + @Test public void testSubModelsCheckObject() { Resource root = resourceInModel("x rdf:type ja:UnionModel; x ja:subModel 'A'"); Assembler a = new UnionModelAssembler(); @@ -116,6 +122,7 @@ public void testSubModelsCheckObject() { } } + @Test public void testCreatesUnionWithBaseModel() { Resource root = resourceInModel("x rdf:type ja:UnionModel; x ja:subModel A; x ja:rootModel B"); Assembler a = new UnionModelAssembler(); From 02fc41fbd895b4bd4386c36699a1fa40f4c13354 Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Mon, 7 Sep 2026 18:35:00 +0100 Subject: [PATCH 10/12] GH-3236: Convert jena.reasoner tests to JUnit6 --- ...eReasoners.java => TS6_RuleReasoners.java} | 18 +- .../jena/reasoner/rulesys/TestRuleUtil.java | 8 +- .../rulesys/impl/TestLPBRuleCloseBug.java | 13 +- .../rulesys/impl/TestLPBRuleEngine.java | 12 +- .../rulesys/impl/TestLPBRuleEngineLeak.java | 9 +- .../rulesys/impl/TestRestartableLBRule.java | 14 +- .../rulesys/test/ConcurrencyTest.java | 22 +- .../rulesys/test/FRuleEngineIFactoryTest.java | 32 +-- .../rulesys/test/OWLConsistencyTest.java | 27 ++- .../reasoner/rulesys/test/OWLUnitTest.java | 49 +++-- .../reasoner/rulesys/test/OWLWGTester.java | 7 +- .../rulesys/test/TestBackchainer.java | 118 ++++++----- .../reasoner/rulesys/test/TestBasicLP.java | 105 +++++++--- .../reasoner/rulesys/test/TestBasics.java | 100 ++++++--- .../rulesys/test/TestComparatorBuiltins.java | 50 +++-- .../rulesys/test/TestConfigVocabulary.java | 68 ++++--- .../reasoner/rulesys/test/TestFBRules.java | 158 ++++++++------- .../test/TestGenericRuleReasonerConfig.java | 21 +- .../rulesys/test/TestGenericRules.java | 91 +++++---- .../rulesys/test/TestLPDerivation.java | 19 +- .../reasoner/rulesys/test/TestOWLMisc.java | 46 +++-- .../jena/reasoner/rulesys/test/TestRDFS9.java | 4 +- .../jena/reasoner/rulesys/test/TestRETE.java | 26 +-- .../test/TestRestrictionsDontNeedTyping.java | 29 +-- .../rulesys/test/TestRuleSystemBugs.java | 112 ++++++----- .../reasoner/rulesys/test/TestSetRules.java | 26 +-- .../rulesys/test/TestTrialOWLRules.java | 2 + .../jena/reasoner/test/AbstractTestGraph.java | 190 ++++++++++++------ .../jena/reasoner/test/ReasonerTester.java | 17 +- ...{TS3_reasoners.java => TS6_reasoners.java} | 20 +- .../jena/reasoner/test/TestInfGraph.java | 13 +- .../jena/reasoner/test/TestInfModel.java | 19 +- .../reasoner/test/TestInfPrefixMapping.java | 17 +- .../jena/reasoner/test/TestRDFSReasoners.java | 61 +++--- .../jena/reasoner/test/TestReasoners.java | 94 +++++---- .../jena/reasoner/test/TestSafeModel.java | 23 +-- .../test/TestTransitiveGraphCache.java | 97 ++++----- .../apache/jena/reasoner/test/TestUtil.java | 66 +++--- .../jena/reasoner/test/TestUtil_JU6.java | 128 ------------ .../jena/reasoner/test/WGReasonerTester.java | 13 +- .../apache/jena/test/JenaCoreTestAll_JU4.java | 6 +- .../apache/jena/test/JenaCoreTestAll_JU6.java | 8 + 42 files changed, 1042 insertions(+), 916 deletions(-) rename jena-core/src/test/java/org/apache/jena/reasoner/rulesys/{TS3_RuleReasoners.java => TS6_RuleReasoners.java} (84%) mode change 100755 => 100644 rename jena-core/src/test/java/org/apache/jena/reasoner/test/{TS3_reasoners.java => TS6_reasoners.java} (75%) delete mode 100644 jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil_JU6.java diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TS3_RuleReasoners.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TS6_RuleReasoners.java old mode 100755 new mode 100644 similarity index 84% rename from jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TS3_RuleReasoners.java rename to jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TS6_RuleReasoners.java index cebcdc5e006..6087f50d539 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TS3_RuleReasoners.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TS6_RuleReasoners.java @@ -21,17 +21,19 @@ package org.apache.jena.reasoner.rulesys; +import org.junit.platform.suite.api.BeforeSuite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; import org.apache.jena.reasoner.rulesys.impl.TestLPBRuleCloseBug; import org.apache.jena.reasoner.rulesys.impl.TestLPBRuleEngine; import org.apache.jena.reasoner.rulesys.impl.TestLPBRuleEngineLeak; import org.apache.jena.reasoner.rulesys.impl.TestRestartableLBRule; import org.apache.jena.reasoner.rulesys.test.*; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.apache.jena.test.JenaTestLib; -@RunWith(Suite.class) -@Suite.SuiteClasses({ +@Suite +@SelectClasses({ TestConfigVocabulary.class, TestGenericRuleReasonerConfig.class, TestBasics.class, @@ -59,4 +61,10 @@ ConcurrencyTest.class, TestRestrictionsDontNeedTyping.class }) -public class TS3_RuleReasoners {} + +public class TS6_RuleReasoners { + @BeforeSuite + public static void beforeSuite() { + JenaTestLib.setup(); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TestRuleUtil.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TestRuleUtil.java index 03c1f9a396e..c374970a637 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TestRuleUtil.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TestRuleUtil.java @@ -21,7 +21,7 @@ package org.apache.jena.reasoner.rulesys; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import java.math.BigDecimal; import java.math.BigInteger; @@ -30,7 +30,7 @@ import org.apache.jena.graph.Node; import org.apache.jena.graph.NodeFactory; import org.apache.jena.reasoner.rulesys.test.TestComparatorBuiltins; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests more of comparison in org.apache.jena.reasoner.rulesys.Util/ @@ -73,10 +73,10 @@ private void compare(String lex1, XSDDatatype dt1, String lex2, XSDDatatype dt2, private void compare(Number num1, Number num2, int outcome) { int z1 = Util.compareNumbers(num1, num2); - assertEquals("compare(num1,num2)", outcome, z1); + assertEquals(outcome, z1, "compare(num1,num2)"); // reverse int z2 = Util.compareNumbers(num2, num1); - assertEquals("compare(num2,num1)", outcome, -1 * z2); + assertEquals(outcome, -1 * z2, "compare(num2,num1)"); } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleCloseBug.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleCloseBug.java index 6527af1e15c..35da2223e59 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleCloseBug.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleCloseBug.java @@ -21,6 +21,10 @@ package org.apache.jena.reasoner.rulesys.impl; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; @@ -37,11 +41,8 @@ import org.apache.jena.reasoner.rulesys.Rule; import org.apache.jena.util.iterator.ExtendedIterator; import org.apache.jena.vocabulary.RDF; -import org.junit.Test; - -import junit.framework.TestCase; -public class TestLPBRuleCloseBug extends TestCase { +public class TestLPBRuleCloseBug { /** * Test case for JENA-2184. */ @@ -67,7 +68,7 @@ public void testCloseOfTabledIterator() { Node clsCLASS = NodeFactory.createURI("urn:ic:CLASS"); ExtendedIterator sInfIter = infGraph.find(x1, RDF.Nodes.type, clsSUB); - assertTrue( sInfIter.hasNext() ); + assertTrue(sInfIter.hasNext() ); // Closing without having read from the iterator // Forces a close of LPInterpreter instances including on behind the tabled goal for the find @@ -76,7 +77,7 @@ public void testCloseOfTabledIterator() { // This query depends on the above tabled goal which was not complete before the close() ExtendedIterator cInfIter = infGraph.find(x1, RDF.Nodes.type, clsCLASS); boolean foundClass = cInfIter.hasNext(); - assertTrue( foundClass ); + assertTrue(foundClass ); } } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleEngine.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleEngine.java index e5bdf011a22..9b56628cb3d 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleEngine.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleEngine.java @@ -21,12 +21,14 @@ package org.apache.jena.reasoner.rulesys.impl; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.lang.reflect.Field; import java.util.List; -import org.junit.Test; -import junit.framework.TestCase; import org.apache.jena.graph.*; import org.apache.jena.reasoner.rulesys.FBRuleInfGraph; import org.apache.jena.reasoner.rulesys.FBRuleReasoner; @@ -35,7 +37,7 @@ import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDFS; -public class TestLPBRuleEngine extends TestCase { +public class TestLPBRuleEngine { protected Node a = NodeFactory.createURI("a"); protected Node p = NodeFactory.createURI("p"); protected Node C1 = NodeFactory.createURI("C1"); @@ -112,7 +114,7 @@ public void testTabledGoalsLeak() throws Exception { ExtendedIterator it = infgraph.find(a, ty, C1); it.close(); // how many were cached - in current configuration this will be zero because we retract the cache entry, in other settings might be one completed goal - assertTrue( engine.tabledGoals.size() <= 1 ); + assertTrue(engine.tabledGoals.size() <= 1 ); // and no leaks of activeInterpreters assertEquals(0, engine.activeInterpreters.size()); @@ -121,7 +123,7 @@ public void testTabledGoalsLeak() throws Exception { it.close(); // if it was a cache hit, no change here: - assertTrue( engine.tabledGoals.size() <= 1 ); + assertTrue(engine.tabledGoals.size() <= 1 ); assertEquals(0, engine.activeInterpreters.size()); //the cached generator should not have any consumingCP left diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleEngineLeak.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleEngineLeak.java index 17f820839a4..bf7426b3ea6 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleEngineLeak.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestLPBRuleEngineLeak.java @@ -21,12 +21,14 @@ package org.apache.jena.reasoner.rulesys.impl; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.lang.reflect.Field; import java.util.List; -import org.junit.Test; -import junit.framework.TestCase; import org.apache.jena.graph.*; import org.apache.jena.reasoner.rulesys.FBRuleInfGraph; import org.apache.jena.reasoner.rulesys.FBRuleReasoner; @@ -35,7 +37,7 @@ import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDFS; -public class TestLPBRuleEngineLeak extends TestCase { +public class TestLPBRuleEngineLeak { protected Node a = NodeFactory.createURI("a"); protected Node b = NodeFactory.createURI("b"); protected Node nohit = NodeFactory.createURI("nohit"); @@ -85,7 +87,6 @@ public void testNotLeakingActiveInterpreters() throws Exception { it2.close(); assertEquals(0, engine.activeInterpreters.size()); - // OK, let's ask for something that is in the graph ExtendedIterator it3 = infgraph.find(a, ty, C1); diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestRestartableLBRule.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestRestartableLBRule.java index fec09d2fa13..991b4d94a3a 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestRestartableLBRule.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/impl/TestRestartableLBRule.java @@ -21,11 +21,13 @@ package org.apache.jena.reasoner.rulesys.impl; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.Iterator; -import org.junit.Test; -import junit.framework.TestCase; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphMemFactory; import org.apache.jena.graph.TransactionHandler; @@ -40,7 +42,7 @@ import org.apache.jena.util.iterator.WrappedIterator; import org.apache.jena.vocabulary.RDF; -public class TestRestartableLBRule extends TestCase { +public class TestRestartableLBRule { private static Graph createGraphForTest() { return GraphMemFactory.createDefaultGraph(); @@ -66,9 +68,9 @@ public void testCrossTransactionQueryBug() { InfModel infmodel = ModelFactory.createInfModel(reasoner, data); - assertTrue( queryN(infmodel, Person, 10) ); - assertTrue( queryN(infmodel, Politician, 1000) ); - assertTrue( queryN(infmodel, Person, 1000) ); + assertTrue(queryN(infmodel, Person, 10) ); + assertTrue(queryN(infmodel, Politician, 1000) ); + assertTrue(queryN(infmodel, Person, 1000) ); } private boolean queryN(Model model, Resource c, int n) { diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/ConcurrencyTest.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/ConcurrencyTest.java index 571594fcbc2..540dba0cc8a 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/ConcurrencyTest.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/ConcurrencyTest.java @@ -21,6 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; import java.lang.management.ThreadMXBean; @@ -38,16 +42,13 @@ import org.apache.jena.shared.Lock; import org.apache.jena.util.PrintUtil; import org.apache.jena.util.iterator.ExtendedIterator; -import org.junit.Assert; -import junit.framework.TestCase; -import junit.framework.TestSuite; /** * Test for deadlock and concurrency problems in rule engines. * *

Test inspired by suggestions from Timm Linder

*/ -public class ConcurrencyTest extends TestCase { +public class ConcurrencyTest { // For routine jena tests we do minimal exercise here, otherwise too slow // If problems crop up then switch to full tests @@ -68,17 +69,11 @@ public class ConcurrencyTest extends TestCase { /** * Boilerplate for junit */ - public ConcurrencyTest( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite( ConcurrencyTest.class ); - } @SuppressWarnings("removal") private void runConcurrencyTest(Creator modelCreator, String runId) throws InterruptedException { @@ -87,7 +82,7 @@ private void runConcurrencyTest(Creator modelCreator, String runId) th doTestConcurrency(modelCreator.create()); } } catch (JenaException e ) { - assertTrue(e.getMessage(), false); + assertTrue(false, e.getMessage()); } } @@ -181,13 +176,14 @@ public void run() { System.err.println(); } } - Assert.assertTrue("Deadlock detected!", false); + assertTrue(false, "Deadlock detected!"); /* end deadlock block */ - assertTrue("Failed to terminate execution", false); + assertTrue(false, "Failed to terminate execution"); } } @SuppressWarnings("removal") + @Test public void testWithOWLMemMicroRuleInfModel() throws InterruptedException { runConcurrencyTest( ()->ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF), "OWL_MEM_MICRO_RULE_INF"); diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/FRuleEngineIFactoryTest.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/FRuleEngineIFactoryTest.java index e298f4f223c..1c5c14b5d92 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/FRuleEngineIFactoryTest.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/FRuleEngineIFactoryTest.java @@ -21,10 +21,13 @@ package org.apache.jena.reasoner.rulesys.test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + import java.util.Iterator; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.graph.*; import org.apache.jena.reasoner.Derivation; import org.apache.jena.reasoner.Reasoner; @@ -40,53 +43,50 @@ import org.apache.jena.shared.PrefixMapping; import org.apache.jena.util.iterator.ExtendedIterator; - -public class FRuleEngineIFactoryTest extends TestCase { +public class FRuleEngineIFactoryTest { /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite( FRuleEngineIFactoryTest.class ); - } - - @Override + @AfterEach public void tearDown() { FRuleEngineIFactory.setInstance(new FRuleEngineIFactory()); } + @Test public void testItShouldBeASingleton() { FRuleEngineIFactory instance = FRuleEngineIFactory.getInstance(); - assertNotNull("A default instance must be created", instance); + assertNotNull(instance, "A default instance must be created"); - assertSame("The same instance should have be returned", - instance, FRuleEngineIFactory.getInstance()); + assertSame(instance, FRuleEngineIFactory.getInstance(), "The same instance should have be returned"); } + @Test public void testItShouldLetYouReplaceTheSingletonInstance() { MyFRuleEngineIFactory anotherFactory = new MyFRuleEngineIFactory(); FRuleEngineIFactory.setInstance(anotherFactory); - assertSame("The instance should have been replaced", - anotherFactory, FRuleEngineIFactory.getInstance()); + assertSame(anotherFactory, FRuleEngineIFactory.getInstance(), "The instance should have been replaced"); } + @Test public void testItShouldInstantiateAFRuleEngineIfUseRETEisFalse() { ForwardRuleInfGraphI infGraph = new DummyForwardRuleInfGraph(); FRuleEngineI engine = FRuleEngineIFactory.getInstance().createFRuleEngineI(infGraph, null, false); - assertSame("A FRuleEngine should have been instantiated", FRuleEngine.class, engine.getClass()); + assertSame(FRuleEngine.class, engine.getClass(), "A FRuleEngine should have been instantiated"); } + @Test public void testItShouldInstantiateAReteEngineIfUseRETEisTrue() { ForwardRuleInfGraphI infGraph = new DummyForwardRuleInfGraph(); FRuleEngineI engine = FRuleEngineIFactory.getInstance().createFRuleEngineI(infGraph, null, true); - assertSame("A RETEEngine should have been instantiated", RETEEngine.class, engine.getClass()); + assertSame(RETEEngine.class, engine.getClass(), "A RETEEngine should have been instantiated"); } private static final class MyFRuleEngineIFactory extends FRuleEngineIFactory { diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLConsistencyTest.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLConsistencyTest.java index 664633b74d4..a0282376aa9 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLConsistencyTest.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLConsistencyTest.java @@ -21,9 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; +import static org.junit.jupiter.api.Assertions.*; + import java.util.Iterator; -import junit.framework.TestCase; import org.apache.jena.rdf.model.InfModel; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; @@ -37,7 +38,12 @@ * Utility for checking OWL validation results. */ -public class OWLConsistencyTest extends TestCase { +public class OWLConsistencyTest { + + /** Name used when this test is reported. */ + private String name = "OWLConsistencyTest"; + + public String getName() { return name; } /** The base directory for finding the datafiles */ public static final String BASE_DIR = "file:testing/reasoners/owl/"; @@ -83,7 +89,7 @@ public class OWLConsistencyTest extends TestCase { */ public OWLConsistencyTest(String tbox, String abox, int expected, Object culprit) { - super(abox); + this.name = abox; this.tbox = tbox; this.abox = abox; this.expected = expected; @@ -95,7 +101,7 @@ public OWLConsistencyTest(String tbox, String abox, int expected, */ public OWLConsistencyTest(OWLConsistencyTest base, String reasonerName, ReasonerFactory rf) { - super(reasonerName + ":" + base.abox); + this.name = reasonerName + ":" + base.abox; this.tbox = base.tbox; this.abox = base.abox; this.expected = base.expected; @@ -124,20 +130,19 @@ public ValidityReport testResults() { return im.validate(); } - @Override public void runTest() { ValidityReport report = testResults(); switch (expected) { case INCONSISTENT: - assertTrue("expected inconsistent", !report.isValid()); + assertTrue(!report.isValid(), "expected inconsistent"); break; case WARNINGS: - assertTrue("expected just warnings but reports not valid", report - .isValid()); - assertFalse("expected warnings but reports clean", report.isClean()); + assertTrue(report + .isValid(), "expected just warnings but reports not valid"); + assertFalse(report.isClean(), "expected warnings but reports clean"); break; case CLEAN: - assertTrue("expected clean", report.isClean()); + assertTrue(report.isClean(), "expected clean"); } if (culprit != null) { boolean foundit = false; @@ -150,7 +155,7 @@ public void runTest() { } } if (!foundit) { - assertTrue("Expcted to find a culprint " + culprit, false); + assertTrue(false, "Expcted to find a culprint " + culprit); } } } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLUnitTest.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLUnitTest.java index 6d8542087b8..3a87890ca08 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLUnitTest.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLUnitTest.java @@ -21,10 +21,13 @@ package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; import org.apache.jena.rdf.model.ResourceFactory; import org.apache.jena.reasoner.*; @@ -33,7 +36,7 @@ /** * Version of the OWL unit tests used during development of the mini ruleset. */ -public class OWLUnitTest extends TestCase { +public class OWLUnitTest { // -------------- statics defining the whole test suite --------------------- @@ -192,18 +195,29 @@ public class OWLUnitTest extends TestCase { /** * Boilerplate for junit */ - public OWLUnitTest( String manifest, String rName, ReasonerFactory rf) { - super( rName + ":" + manifest ); - this.manifest = manifest; - this.reasonerFactory = rf; + /** JUnit needs a no-arg constructor for the class holding the @TestFactory. */ + public OWLUnitTest() {} + + private String name = "OWLUnitTest"; + + public String getName() { return name; } + + /** JUnit 5 requires a single constructor, so cases are built through this. */ + private static OWLUnitTest make(String manifest, String rName, ReasonerFactory rf) { + OWLUnitTest t = new OWLUnitTest(); + t.name = rName + ":" + manifest; + t.manifest = manifest; + t.reasonerFactory = rf; + return t; } /** - * Boilerplate for junit. - * This is its own test suite + * One dynamic test per (reasoner, test definition) pair that the definition + * declares itself applicable to. This was a hand-built {@code TestSuite}. */ - public static TestSuite suite() { - TestSuite suite = new TestSuite(); + @TestFactory + public Stream owlTests() { + List suite = new ArrayList<>(); for (int i = 0; i < reasonerFactories.length; i++) { String rName = reasonerNames[i]; ReasonerFactory rf = reasonerFactories[i]; @@ -213,24 +227,25 @@ public static TestSuite suite() { { if ( test.spec instanceof String ) { - suite.addTest( new OWLUnitTest( (String) test.spec, rName, rf ) ); + OWLUnitTest t = make((String)test.spec, rName, rf); + suite.add(DynamicTest.dynamicTest(t.getName(), ()->t.runTest())); } else if ( test.spec instanceof OWLConsistencyTest ) { OWLConsistencyTest oct = (OWLConsistencyTest) test.spec; - suite.addTest( new OWLConsistencyTest( oct, rName, rf ) ); + OWLConsistencyTest t = new OWLConsistencyTest( oct, rName, rf ); + suite.add(DynamicTest.dynamicTest(t.getName(), ()->t.runTest())); } } } } - return suite; + return suite.stream(); } /** * The test runner */ - @Override - protected void runTest() throws IOException { + public void runTest() throws IOException { // System.out.println(" - " + manifest + " using " + reasonerFactory.getURI()); OWLWGTester tester = new OWLWGTester(reasonerFactory, this, null); tester.runTests(manifest, false, false); diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLWGTester.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLWGTester.java index 0cc15e9682a..c3957765792 100755 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLWGTester.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLWGTester.java @@ -38,7 +38,6 @@ import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.ReasonerVocabulary; import org.junit.Assert; -import junit.framework.TestCase; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -89,7 +88,7 @@ public class OWLWGTester { protected Resource configuration; /** The test case which has invoke this test */ - protected TestCase testcase; + protected Object testcase; /** The processing time used since testcase creation */ protected static long timeCost = 0; @@ -112,10 +111,10 @@ public class OWLWGTester { /** * Constructor * @param reasonerF the factory for the reasoner to be tested - * @param testcase the JUnit test case which is requesting this test + * @param testcase non-null if the caller wants a failed test to assert * @param configuration optional configuration information */ - public OWLWGTester(ReasonerFactory reasonerF, TestCase testcase, Resource configuration) { + public OWLWGTester(ReasonerFactory reasonerF, Object testcase, Resource configuration) { this.reasonerF = reasonerF; this.testcase = testcase; this.configuration = configuration; diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBackchainer.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBackchainer.java index d135ab6bb28..d892e7e7823 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBackchainer.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBackchainer.java @@ -21,8 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphMemFactory; import org.apache.jena.graph.Node; @@ -53,7 +55,7 @@ * That has now been obsoleted at this is now used to double check the * LP engine, though the bulk of such tests are really done by TestBasicLP. */ -public class TestBackchainer extends TestCase { +public class TestBackchainer { // Maximum size of binding environment needed in the tests private static final int MAX_VARS = 10; @@ -92,20 +94,11 @@ public class TestBackchainer extends TestCase { /** * Boilerplate for junit */ - public TestBackchainer( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite( TestBackchainer.class ); -// TestSuite suite = new TestSuite(); -// suite.addTest(new TestBackchainer( "testRDFSProblemsb" )); -// return suite; - } private static Graph createGraphForTest() { return GraphMemFactory.createDefaultGraph(); @@ -128,19 +121,17 @@ public Reasoner createReasoner(List rules) { /** * Test parser modes to support backarrow notation are working */ + @Test public void testParse() { List rules = Rule.parseRules(testRules1); - assertEquals("BRule parsing", - "[ (?x ?q ?y) <- (?p rdfs:subPropertyOf ?q) (?x ?p ?y) ]", - rules.get(0).toString()); - assertEquals("BRule parsing", - "[ (?a rdfs:subPropertyOf ?c) <- (?a rdfs:subPropertyOf ?b) (?b rdfs:subPropertyOf ?c) ]", - rules.get(1).toString()); + assertEquals("[ (?x ?q ?y) <- (?p rdfs:subPropertyOf ?q) (?x ?p ?y) ]", rules.get(0).toString(), "BRule parsing"); + assertEquals("[ (?a rdfs:subPropertyOf ?c) <- (?a rdfs:subPropertyOf ?b) (?b rdfs:subPropertyOf ?c) ]", rules.get(1).toString(), "BRule parsing"); } /** * Test goal/head unify operation. */ + @Test public void testUnify() { Node_RuleVariable xg = new Node_RuleVariable("?x", 0); Node_RuleVariable yg = new Node_RuleVariable("?y", 1); @@ -244,6 +235,7 @@ private void doTestUnify(TriplePattern goal, TriplePattern head, boolean succeed * Check that a reasoner over an empty rule set accesses * the raw data successfully. */ + @Test public void testListData() { Graph data = createGraphForTest(); for ( Triple dataElt : dataElts ) @@ -256,7 +248,7 @@ public void testListData() { // Case of schema and data but no rule axioms Reasoner reasoner = createReasoner(new ArrayList()); InfGraph infgraph = reasoner.bindSchema(schema).bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, null, null), new Object[] { Triple.create(p, sP, q), @@ -268,7 +260,7 @@ public void testListData() { List rules = Rule.parseRules("-> (d p d)."); reasoner = createReasoner(rules); infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, null, null), new Object[] { Triple.create(p, sP, q), @@ -278,7 +270,7 @@ public void testListData() { // Case of data and rule axioms and schema infgraph = reasoner.bindSchema(schema).bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, null, null), new Object[] { Triple.create(p, sP, q), @@ -292,6 +284,7 @@ public void testListData() { /** * Test basic rule operations - simple AND rule */ + @Test public void testBaseRules1() { List rules = Rule.parseRules("[r1: (?a r ?c) <- (?a p ?b),(?b p ?c)]"); Graph data = createGraphForTest(); @@ -300,7 +293,7 @@ public void testBaseRules1() { data.add(Triple.create(b, p, d)); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, r, null), new Object[] { Triple.create(a, r, c), @@ -311,6 +304,7 @@ public void testBaseRules1() { /** * Test basic rule operations - simple OR rule */ + @Test public void testBaseRules2() { List rules = Rule.parseRules( "[r1: (?a r ?b) <- (?a p ?b)]" + @@ -324,7 +318,7 @@ public void testBaseRules2() { data.add(Triple.create(b, s, d)); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, r, null), new Object[] { Triple.create(a, r, b), @@ -336,6 +330,7 @@ public void testBaseRules2() { /** * Test basic rule operations - simple OR rule with chaining */ + @Test public void testBaseRules2b() { List rules = Rule.parseRules( "[r1: (?a r ?b) <- (?a p ?b)]" + @@ -350,7 +345,7 @@ public void testBaseRules2b() { data.add(Triple.create(b, s, d)); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, r, null), new Object[] { Triple.create(a, r, b), @@ -362,6 +357,7 @@ public void testBaseRules2b() { /** * Test basic rule operations - simple AND rule check with tabling. */ + @Test public void testBaseRules3() { List rules = Rule.parseRules("[rule: (?a rdfs:subPropertyOf ?c) <- (?a rdfs:subPropertyOf ?b),(?b rdfs:subPropertyOf ?c)]"); Reasoner reasoner = createReasoner(rules); @@ -372,7 +368,7 @@ public void testBaseRules3() { data.add(Triple.create(s, sP, t) ); data.add(Triple.create(a, p, b) ); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, RDFS.subPropertyOf.asNode(), null), new Object[] { Triple.create(p, sP, q), @@ -387,6 +383,7 @@ public void testBaseRules3() { /** * Test basic rule operations - simple AND rule check with tabling. */ + @Test public void testBaseRules3b() { List rules = Rule.parseRules("[rule: (?a rdfs:subPropertyOf ?c) <- (?a rdfs:subPropertyOf ?b),(?b rdfs:subPropertyOf ?c)]"); Reasoner reasoner = createReasoner(rules); @@ -396,7 +393,7 @@ public void testBaseRules3b() { data.add(Triple.create(r, sP, t) ); data.add(Triple.create(q, sP, s) ); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, RDFS.subPropertyOf.asNode(), null), new Object[] { Triple.create(p, sP, q), @@ -414,6 +411,7 @@ public void testBaseRules3b() { /** * Test basic rule operations - simple AND/OR with tabling. */ + @Test public void testBaseRules4() { Graph data = createGraphForTest(); data.add(Triple.create(a, r, b)); @@ -426,7 +424,7 @@ public void testBaseRules4() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, p, null), new Object[] { Triple.create(a, p, b), @@ -438,6 +436,7 @@ public void testBaseRules4() { /** * Test basic rule operations - simple AND/OR with tabling. */ + @Test public void testBaseRulesXSB1() { Graph data = createGraphForTest(); data.add(Triple.create(p, c, q)); @@ -452,7 +451,7 @@ public void testBaseRulesXSB1() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(p, a, null), new Object[] { Triple.create(p, a, q), @@ -463,6 +462,7 @@ public void testBaseRulesXSB1() { /** * Test basic functor usage. */ + @Test public void testFunctors1() { Graph data = createGraphForTest(); data.add(Triple.create(a, p, b)); @@ -473,7 +473,7 @@ public void testFunctors1() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, s, null), new Object[] { Triple.create(a, s, b) @@ -483,6 +483,7 @@ public void testFunctors1() { /** * Test basic functor usage. */ + @Test public void testFunctors2() { Graph data = createGraphForTest(); data.add(Triple.create(a, p, b)); @@ -496,7 +497,7 @@ public void testFunctors2() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, s, null), new Object[] { Triple.create(a, s, b), @@ -507,6 +508,7 @@ public void testFunctors2() { /** * Test basic functor usage. */ + @Test public void testFunctors3() { Graph data = createGraphForTest(); data.add(Triple.create(a, s, b)); @@ -518,7 +520,7 @@ public void testFunctors3() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, r, null), new Object[] { Triple.create(a, r, c) @@ -528,6 +530,7 @@ public void testFunctors3() { /** * Test basic builtin usage. */ + @Test public void testBuiltin1() { Graph data = createGraphForTest(); List rules = Rule.parseRules( @@ -537,7 +540,7 @@ public void testBuiltin1() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, r, null), new Object[] { Triple.create(a, r, Util.makeIntNode(5)) @@ -547,6 +550,7 @@ public void testBuiltin1() { /** * Test basic builtin usage. */ + @Test public void testBuiltin2() { Graph data = createGraphForTest(); data.add(Triple.create(a, p, b)); @@ -557,12 +561,12 @@ public void testBuiltin2() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, r, null), new Object[] { Triple.create(a, r, b) } ); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, r, null), new Object[] { Triple.create(a, r, c) @@ -572,6 +576,7 @@ public void testBuiltin2() { /** * Test basic builtin usage. */ + @Test public void testBuiltin3() { Graph data = createGraphForTest(); List rules = Rule.parseRules( @@ -579,7 +584,7 @@ public void testBuiltin3() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, null, null), new Object[] { Triple.create(a, p, b) @@ -589,6 +594,7 @@ public void testBuiltin3() { /** * Test basic ground head patterns. */ + @Test public void testGroundHead() { Graph data = createGraphForTest(); data.add(Triple.create(a, r, b)); @@ -597,7 +603,7 @@ public void testGroundHead() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, null, null), new Object[] { Triple.create(a, p, b), @@ -628,6 +634,7 @@ public void testGroundHead() { /** * Test rebind operation */ + @Test public void testRebind() { List rules = Rule.parseRules("[r1: (?a r ?c) <- (?a p ?b),(?b p ?c)]"); Graph data = createGraphForTest(); @@ -636,7 +643,7 @@ public void testRebind() { data.add(Triple.create(b, p, d)); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, r, null), new Object[] { Triple.create(a, r, c), @@ -646,7 +653,7 @@ public void testRebind() { ndata.add(Triple.create(a, p, d)); ndata.add(Triple.create(d, p, b)); infgraph.rebind(ndata); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, r, null), new Object[] { Triple.create(a, r, b) @@ -657,6 +664,7 @@ public void testRebind() { /** * Test troublesome rdfs rules */ + @Test public void testRDFSProblemsb() { Graph data = createGraphForTest(); data.add(Triple.create(C1, sC, C2)); @@ -670,7 +678,7 @@ public void testRDFSProblemsb() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, sC, null), new Object[] { Triple.create(C1, sC, C2), @@ -685,6 +693,7 @@ public void testRDFSProblemsb() { /** * Test troublesome rdfs rules */ + @Test public void testRDFSProblems() { Graph data = createGraphForTest(); data.add(Triple.create(p, sP, q)); @@ -701,14 +710,14 @@ public void testRDFSProblems() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, ty, null), new Object[] { Triple.create(a, ty, C1), Triple.create(a, ty, C2), Triple.create(a, ty, C3) } ); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(C1, sC, a), new Object[] { } ); @@ -717,6 +726,7 @@ public void testRDFSProblems() { /** * Test complex rule head unification */ + @Test public void testHeadUnify() { Graph data = createGraphForTest(); data.add(Triple.create(c, q, d)); @@ -726,7 +736,7 @@ public void testHeadUnify() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(c, r, null), new Object[] { } ); data.add(Triple.create(c, q, a)); @@ -736,7 +746,7 @@ public void testHeadUnify() { ); reasoner = createReasoner(rules); infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(c, r, null), new Object[] { Triple.create(c, r, a) @@ -754,7 +764,7 @@ public void testHeadUnify() { ); reasoner = createReasoner(rules); infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(c, r, null), new Object[] { Triple.create(c, r, b) @@ -766,7 +776,7 @@ public void testHeadUnify() { ); reasoner = createReasoner(rules); infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(c, r, null), new Object[] { Triple.create(c, r, a) @@ -776,6 +786,7 @@ public void testHeadUnify() { /** * Test restriction example */ + @Test public void testRestriction1() { Graph data = createGraphForTest(); data.add(Triple.create(a, ty, r)); @@ -791,18 +802,18 @@ public void testRestriction1() { ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(b, ty, c), new Object[] { Triple.create(b, ty, c) } ); } - /** * Test restriction example. The rules are more than the minimum required * to solve the query and they interact to given run away seaches if there * is a problem. */ + @Test public void testRestriction2() { Graph data = createGraphForTest(); data.add(Triple.create(a, ty, OWL.Thing.asNode())); @@ -834,11 +845,11 @@ public void testRestriction2() { "" ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, ty, C1), new Object[] { Triple.create(a, ty, C1) } ); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, ty, c), new Object[] { Triple.create(a, ty, c) } ); @@ -847,6 +858,7 @@ public void testRestriction2() { /** * Test restriction example */ + @Test public void testRestriction3() { Graph data = createGraphForTest(); data.add(Triple.create(a, ty, r)); @@ -866,7 +878,7 @@ public void testRestriction3() { "" ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, ty, c), new Object[] { } ); } @@ -874,6 +886,7 @@ public void testRestriction3() { /** * Test close and halt operation. */ + @Test public void testClose() { Graph data = createGraphForTest(); data.add(Triple.create(p, sP, q)); @@ -898,7 +911,7 @@ public void testClose() { assertEquals(result.getPredicate(), ty); it.close(); // Make sure if we start again we get the full listing. - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, ty, null), new Object[] { Triple.create(a, ty, C1), @@ -910,6 +923,7 @@ public void testClose() { /** * Test problematic rdfs case */ + @Test public void testBug1() { Graph data = createGraphForTest(); Node p = NodeFactory.createURI("http://www.hpl.hp.com/semweb/2003/eg#p"); @@ -919,7 +933,7 @@ public void testBug1() { List rules = Rule.parseRules(Util.loadRuleParserFromResourceFile("testing/reasoners/bugs/rdfs-error1.brules")); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(b, ty, C1), new Object[] { Triple.create(b, ty, C1) diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasicLP.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasicLP.java index efa74723735..282743dad8e 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasicLP.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasicLP.java @@ -21,8 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphMemFactory; import org.apache.jena.graph.Node; @@ -53,7 +55,7 @@ * To be moved to a test directory once the code is working. *

*/ -public class TestBasicLP extends TestCase { +public class TestBasicLP { // Useful constants Node p = NodeFactory.createURI("p"); @@ -81,21 +83,11 @@ public class TestBasicLP extends TestCase { /** * Boilerplate for junit */ - public TestBasicLP( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { -// return new TestSuite( TestBasicLP.class ); - - TestSuite suite = new TestSuite(); - suite.addTest(new TestBasicLP( "testCME" )); - return suite; - } private static Graph createGraphForTest() { return GraphMemFactory.createDefaultGraph(); @@ -134,6 +126,7 @@ public InfGraph makeInfGraph(List rules, Graph data, Node[] tabled) { /** * Test basic rule operations - lookup, no matching rules */ + @Test public void testBaseRules1() { doBasicTest("[r1: (?x r c) <- (?x p b)]", Triple.create(Node.ANY, p, b), @@ -145,6 +138,7 @@ public void testBaseRules1() { /** * Test basic rule operations - simple chain rule */ + @Test public void testBaseRules2() { doBasicTest("[r1: (?x r c) <- (?x p b)]", Triple.create(Node.ANY, r, c), @@ -156,6 +150,7 @@ public void testBaseRules2() { /** * Test basic rule operations - chain rule with head unification */ + @Test public void testBaseRules3() { doBasicTest("[r1: (?x r ?x) <- (?x p b)]", Triple.create(Node.ANY, r, a), @@ -167,6 +162,7 @@ public void testBaseRules3() { /** * Test basic rule operations - rule with head unification, non-temp var */ + @Test public void testBaseRules4() { doBasicTest("[r1: (?x r ?x) <- (?y p b), (?x p b)]", Triple.create(Node.ANY, r, a), @@ -178,6 +174,7 @@ public void testBaseRules4() { /** * Test basic rule operations - simple cascade */ + @Test public void testBaseRules5() { doBasicTest("[r1: (?x q ?y) <- (?x r ?y)(?y s ?x)]" + "[r2: (?x r ?y) <- (?x p ?y)]" + @@ -191,6 +188,7 @@ public void testBaseRules5() { /** * Test basic rule operations - chain rule which will fail at head time */ + @Test public void testBaseRules6() { doBasicTest("[r1: (?x r ?x) <- (?x p b)]", Triple.create(a, r, b), @@ -201,6 +199,7 @@ public void testBaseRules6() { /** * Test basic rule operations - chain rule which will fail in search */ + @Test public void testBaseRules7() { doBasicTest("[r1: (?x r ?y) <- (?x p c)]", Triple.create(a, r, b), @@ -211,6 +210,7 @@ public void testBaseRules7() { /** * Test basic rule operations - simple chain */ + @Test public void testBaseRules8() { doBasicTest("[r1: (?x q ?y) <- (?x r ?y)]" + "[r2: (?x r ?y) <- (?x p ?y)]", @@ -223,6 +223,7 @@ public void testBaseRules8() { /** * Test basic rule operations - simple chain */ + @Test public void testBaseRules9() { doBasicTest("[r1: (?x q ?y) <- (?x r ?y)]" + "[r2: (?x r ?y) <- (?y p ?x)]", @@ -235,6 +236,7 @@ public void testBaseRules9() { /** * Test backtracking - simple triple query. */ + @Test public void testBacktrack1() { doTest("[r1: (?x r ?y) <- (?x p ?y)]", new Triple[] { @@ -253,6 +255,7 @@ public void testBacktrack1() { /** * Test backtracking - chain to simple triple query. */ + @Test public void testBacktrack2() { doTest("[r1: (?x r ?y) <- (?x p ?y)]", new Triple[] { @@ -271,6 +274,7 @@ public void testBacktrack2() { /** * Test backtracking - simple choice point */ + @Test public void testBacktrack3() { doTest("[r1: (?x r C1) <- (?x p b)]" + "[r2: (?x r C2) <- (?x p b)]" + @@ -289,6 +293,7 @@ public void testBacktrack3() { /** * Test backtracking - nested choice point */ + @Test public void testBacktrack4() { doTest("[r1: (?x r C1) <- (?x p b)]" + "[r2: (?x r C2) <- (?x p b)]" + @@ -311,6 +316,7 @@ public void testBacktrack4() { /** * Test backtracking - nested choice point with multiple triple matches */ + @Test public void testBacktrack5() { doTest("[r1: (?x r C3) <- (C1 p ?x)]" + "[r2: (?x r C2) <- (C2 p ?x)]" + @@ -334,6 +340,7 @@ public void testBacktrack5() { * Test backtracking - nested choice point with multiple triple matches, and * checking temp v. permanent variable usage */ + @Test public void testBacktrack6() { doTest("[r1: (?x r C1) <- (?x p a)]" + "[r2: (?x r C2) <- (?x p b)]" + @@ -356,6 +363,7 @@ public void testBacktrack6() { /** * Test backtracking - nested choice point with simple triple matches */ + @Test public void testBacktrack7() { doTest( "[r1: (?x r C1) <- (?x p b)]" + "[r2: (?x r C2) <- (?x p b)]" + @@ -382,6 +390,7 @@ public void testBacktrack7() { * Test backtracking - nested choice point with simple triple matches, * permanent vars but used just once in body */ + @Test public void testBacktrack8() { doTest( "[r1: (?x r C1) <- (?x p b)]" + "[r2: (?x r C2) <- (?x p b)]" + @@ -408,6 +417,7 @@ public void testBacktrack8() { /** * Test backtracking - multiple triple matches */ + @Test public void testBacktrack9() { doTest("[r1: (?x s ?y) <- (?x r ?y) (?x q ?y)]", new Triple[] { @@ -429,6 +439,7 @@ public void testBacktrack9() { /** * Test backtracking - multiple triple matches */ + @Test public void testBacktrack10() { doTest("[r1: (?x s ?y) <- (?x r ?y) (?x q ?z), equal(?y, ?z)(?x, p, ?y)]" + "[(a p D1) <- ]" + @@ -452,6 +463,7 @@ public void testBacktrack10() { /** * Test clause order is right */ + @Test public void testClauseOrder() { List rules = Rule.parseRules( "[r1: (?x r C1) <- (?x p b)]" + @@ -469,6 +481,7 @@ public void testClauseOrder() { /** * Test axioms work. */ + @Test public void testAxioms() { doTest("[a1: -> (a r C1) ]" + "[a2: -> (a r C2) ]" + @@ -487,6 +500,7 @@ public void testAxioms() { /** * Test nested invocation of rules with permanent vars */ + @Test public void testNestedPvars() { doTest("[r1: (?x r ?y) <- (?x p ?z) (?z q ?y)]" + "[r1: (?y t ?x) <- (?x p ?z) (?z q ?y)]" + @@ -509,6 +523,7 @@ public void testNestedPvars() { /** * Test simple invocation of a builtin */ + @Test public void testBuiltin1() { doTest("[r1: (?x r ?y) <- (?x p ?v), sum(?v 2 ?y)]", new Triple[] { @@ -522,10 +537,10 @@ public void testBuiltin1() { } ); } - /** * Test simple invocation of a builtin */ + @Test public void testBuiltin2() { doTest("[r1: (?x r C1) <- (?x p ?v), lessThan(?v 3)]", new Triple[] { @@ -544,6 +559,7 @@ public void testBuiltin2() { * Test wildcard predicate usage - simple triple search. * Rules look odd because we have to hack around the recursive loops. */ + @Test public void testWildPredicate1() { doTest("[r1: (b r ?y) <- (a ?y ?v)]", new Triple[] { @@ -562,6 +578,7 @@ public void testWildPredicate1() { * Test wildcard predicate usage - combind triple search and multiclause matching. * Rules look odd because we have to hack around the recursive loops. */ + @Test public void testWildPredicate2() { doTest("[r1: (a r ?y) <- (b ?y ?v)]" + "[r2: (?x q ?y) <- (?x p ?y)]" + @@ -593,6 +610,7 @@ public void testWildPredicate2() { * Test wildcard predicate usage - combined triple search and multiclause matching. * Rules look odd because we have to hack around the recursive loops. */ + @Test public void testWildPredicate3() { String rules = "[r1: (a r ?y) <- (b ?y ?v)]" + "[r2: (?x q ?y) <- (?x p ?y)]" + @@ -633,6 +651,7 @@ public void testWildPredicate3() { /** * Test wildcard predicate usage - wildcard in head as well */ + @Test public void testWildPredicate4() { doTest("[r1: (a ?p ?x) <- (b ?p ?x)]", new Triple[] { @@ -652,6 +671,7 @@ public void testWildPredicate4() { /** * Test functor usage. */ + @Test public void testFunctors1() { String ruleSrc = "[r1: (?x s ?y) <- (?x p foo(?z, ?y))] "; Triple[] triples = @@ -673,6 +693,7 @@ public void testFunctors1() { /** * Test functor usage. */ + @Test public void testFunctors2() { String ruleSrc = "[r1: (?x r foo(?y,?z)) <- (?x p ?y), (?x q ?z)]" + "[r2: (?x s ?y) <- (?x r foo(?z, ?y))] "; @@ -696,6 +717,7 @@ public void testFunctors2() { /** * Test functor usage. */ + @Test public void testFunctors3() { String ruleSrc = "[r1: (?x r foo(p,?y)) <- (?x p ?y)]" + "[r2: (?x r foo(q,?y)) <- (?x q ?y)]" + @@ -721,6 +743,7 @@ public void testFunctors3() { /** * Test tabled predicates. Simple chain call case. */ + @Test public void testTabled1() { doTest("[r1: (?a q ?b) <- (?a p ?b)]" + "[r2: (?x r ?y) <- (?x q ?y)]", @@ -739,6 +762,7 @@ public void testTabled1() { /** * Test tabled predicates. Simple transitive closure case. */ + @Test public void testTabled2() { doTest("[r1: (?a p ?c) <- (?a p ?b)(?b p ?c)]", new Node[] { p }, @@ -760,6 +784,7 @@ public void testTabled2() { /** * Test tabled predicates. Simple transitive closure over normal predicates */ + @Test public void testTabled3() { doTest("[r1: (?x p ?z) <- (?x p ?y), (?y p ?z)]" + "[r2: (?x p ?z) <- (?x e ?z), (?z q ?z)]", @@ -783,6 +808,7 @@ public void testTabled3() { /** * Test tabled predicates. Co-routining example. */ + @Test public void testTabled4() { doTest("[r1: (?x a ?y) <- (?x c ?y)]" + "[r2: (?x a ?y) <- (?x b ?z), (?z c ?y)]" + @@ -805,6 +831,7 @@ public void testTabled4() { /** * Test tabled predicates. Simple transitive closure case. */ + @Test public void testTabled5() { doTest("[r1: (?a p ?c) <- (?a p ?b)(?b p ?c)]" + "[r2: (?a r ?b) <- (?a q ?b)]", @@ -828,6 +855,7 @@ public void testTabled5() { * Test tabled predicates. Simple transitive closure case, tabling set * by rule base. */ + @Test public void testTabled6() { doTest("[-> table(p)] [r1: (?a p ?c) <- (?a p ?b)(?b p ?c)]", new Triple[] { @@ -848,6 +876,7 @@ public void testTabled6() { /** * Test tabled calls with aliased local vars in the call. */ + @Test public void testTabled7() { doTest("[r1: (?a q ?b) <- (?a p ?b)]" + "[r2: (?a q ?a) <- (?a s ?a)]" + @@ -871,6 +900,7 @@ public void testTabled7() { /** * Test RDFS example. */ + @Test public void testRDFS1() { doTest( "[ (?a rdf:type C1) <- (?a rdf:type C2) ]" + @@ -895,6 +925,7 @@ public void testRDFS1() { /** * Test RDFS example - branched version */ + @Test public void testRDFS2() { doTest( "[ (?a rdf:type C1) <- (?a rdf:type C2) ]" + @@ -920,6 +951,7 @@ public void testRDFS2() { * A problem from the original backchainer tests - interaction * of tabling and functor expansion. */ + @Test public void testProblem1() { doTest( "[r1: (a q f(?x,?y)) <- (a s ?x), (a t ?y)]" + @@ -940,6 +972,7 @@ public void testProblem1() { /** * A problem from the original backchainer tests - tabled closure operation. */ + @Test public void testProblem2() { String ruleSrc = "[rdfs8: (?a rdfs:subClassOf ?c) <- (?a rdfs:subClassOf ?b), (?b rdfs:subClassOf ?c)]" + @@ -967,6 +1000,7 @@ public void testProblem2() { /** * A problem from the original backchainer tests - bound/unbound primitives */ + @Test public void testProblem3() { String rules = "[r1: (?x r ?y ) <- bound(?x), (?x p ?y) ]" + "[r2: (?x r ?y) <- unbound(?x), (?x q ?y)]"; @@ -993,6 +1027,7 @@ public void testProblem3() { /** * A problem from the original backchainer tests - head unification test */ + @Test public void testProblem4() { String rules = "[r1: (c r ?x) <- (?x p ?x)]" + "[r2: (?x p ?y) <- (a q ?x), (b q ?y)]"; @@ -1014,6 +1049,7 @@ public void testProblem4() { /** * A problem from the original backchainer tests - RDFS example which threw an NPE */ + @Test public void testProblem5() { String ruleSrc = "[rdfs8: (?a rdfs:subClassOf ?c) <- (?a rdfs:subClassOf ?b), (?b rdfs:subClassOf ?c)]" + @@ -1041,6 +1077,7 @@ public void testProblem5() { /** * A problem from the original backchainer tests - RDFS example which threw an NPE */ + @Test public void testProblem6() { String ruleSrc = "[rdfs9: (?a rdf:type ?y) <- (?x rdfs:subClassOf ?y), (?a rdf:type ?x)]" + @@ -1066,6 +1103,7 @@ public void testProblem6() { * A problem from the original backchainer tests - incorrect additional deduction. * Was due to interpeter setup failing to clone input variables. */ + @Test public void testProblem7() { String ruleSrc = "[rdfs8: (?a rdfs:subClassOf ?c) <- (?a rdfs:subClassOf ?b), (?b rdfs:subClassOf ?c)]" + @@ -1093,7 +1131,7 @@ public void testProblem7() { assertEquals(result.getPredicate(), ty); it.close(); // Make sure if we start again we get the full listing. - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, ty, null), new Object[] { Triple.create(a, ty, C1), @@ -1106,6 +1144,7 @@ public void testProblem7() { * A problem from the original backchainer tests - RDFS example which failed. * Was due to unsupported multi-head statement. */ + @Test public void testProblem8() { String ruleSrc = "[rdfs9: (?a rdf:type ?y) <- bound(?y) (?x rdfs:subClassOf ?y) (?a rdf:type ?x)]" + @@ -1133,6 +1172,7 @@ public void testProblem8() { /** * Test derivation machinery */ + @Test public void testRuleDerivations() { String rules = "[testRule1: (C2, p, ?a) <- (C1 p ?a)]" + "[testRule2: (C2, q, ?a) <- (C1 q ?a)]" + @@ -1145,7 +1185,7 @@ public void testRuleDerivations() { InfGraph infgraph = makeInfGraph(ruleList, data, new Node[]{p, q}); infgraph.setDerivationLogging(true); - TestUtil.assertIteratorValues(this, infgraph.find(a, null, null), + TestUtil.assertIteratorValues( infgraph.find(a, null, null), new Triple[] { Triple.create(a, p, C3) }); @@ -1159,11 +1199,14 @@ public void testRuleDerivations() { } out.flush(); - String testString = TestUtil.normalizeWhiteSpace("Rule testRule3 concluded (a p C3) <-\n" + - " Rule testRule1 concluded (C2 p C3) <-\n" + - " Fact (C1 p C3)\r\n" + - " Rule testRule2 concluded (C2 q C3) <-\n" + - " Fact (C1 q C3)\r\n"); + // PrintUtil.print renders a URI node with no matching prefix as . This + // expectation predates that and had gone stale unnoticed: the class was not + // reached by the JUnit 3 suite, so these tests had not been running. + String testString = TestUtil.normalizeWhiteSpace("Rule testRule3 concluded (

) <-\n" + + " Rule testRule1 concluded (

) <-\n" + + " Fact (

)\r\n" + + " Rule testRule2 concluded ( ) <-\n" + + " Fact ( )\r\n"); assertEquals(testString, TestUtil.normalizeWhiteSpace(outString.getBuffer().toString())); } @@ -1171,6 +1214,7 @@ public void testRuleDerivations() { * A suspect problem, originally derived from the OWL rules - risk of unbound variables escaping. * Not managed to isolate or reproduce the problem yet. */ + @Test public void testProblem9() { String ruleSrc = "[test: (?x owl:sameAs ?x) <- (?x rdf:type owl:Thing) ]" + @@ -1199,6 +1243,7 @@ public void testProblem9() { /** * Test 3-arg builtins such as arithmetic. */ + @Test public void testArithBuiltins() { doBuiltinTest( "[(a,r,0) <- (a,p,?x), (a,q,?y), lessThan(?x,?y)]" + @@ -1236,6 +1281,7 @@ public void testArithBuiltins() { /** * Test the temporary list builtins */ + @Test public void testListBuiltins() { String ruleSrc = "[(a r ?n) <- (a p ?l), listLength(?l, ?n)]" + "[(a s ?e) <- (a p ?l), listEntry(?l, 1, ?e)]"; @@ -1243,12 +1289,12 @@ public void testListBuiltins() { Graph data = createGraphForTest(); data.add(Triple.create(a, p, Util.makeList(new Node[]{C1,C2,C3},data))); InfGraph infgraph = makeInfGraph(rules, data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(Triple.create(a, r, Node.ANY)), new Triple[] { Triple.create(a, r, Util.makeIntNode(3)) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(Triple.create(a, s, Node.ANY)), new Triple[] { Triple.create(a, s, C2) @@ -1268,7 +1314,7 @@ public void testListBuiltins() { data.add(Triple.create(a, r, Util.makeList( new Node[]{C3, C1, Util.makeLongNode(2)}, data) )); infgraph = makeInfGraph(rules, data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(Triple.create(a, s, Node.ANY)), new Triple[] { Triple.create(a, s, b), @@ -1286,7 +1332,7 @@ public void testListBuiltins() { data.add(Triple.create(a, q, Util.makeLongNode(3))); data.add(Triple.create(a, q, C2)); infgraph = makeInfGraph(rules, data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(Triple.create(b, Node.ANY, Node.ANY)), new Triple[] { Triple.create(b, r, C1), @@ -1299,6 +1345,7 @@ public void testListBuiltins() { * Test that we detect concurrent modification of LP graphs with * non-closed iterators. */ + @Test public void testCME() { String ruleSrc = "(?a p 1) <- (?a p 0). (?a p 2) <- (?a p 0)."; List rules = Rule.parseRules(ruleSrc); @@ -1307,7 +1354,7 @@ public void testCME() { InfGraph infgraph = makeInfGraph(rules, data); // Check the base case works - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(Triple.create(a, p, Node.ANY)), new Triple[] { Triple.create(a, p, Util.makeIntNode(0)), @@ -1327,7 +1374,7 @@ public void testCME() { } finally { i.close(); } - assertTrue("Expect CME on unclosed iterators", ok); + assertTrue(ok, "Expect CME on unclosed iterators"); } /** @@ -1345,7 +1392,7 @@ private void doTest(String ruleSrc, Triple[] triples, Triple query, Object[] res data.add( triple ); } InfGraph infgraph = makeInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(query), results); + TestUtil.assertIteratorValues( infgraph.find(query), results); } /** @@ -1364,7 +1411,7 @@ private void doTest(String ruleSrc, Node[] tabled, Triple[] triples, Triple quer data.add( triple ); } InfGraph infgraph = makeInfGraph(rules, data, tabled); - TestUtil.assertIteratorValues(this, infgraph.find(query), results); + TestUtil.assertIteratorValues( infgraph.find(query), results); } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasics.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasics.java index f010d6c35c0..b0117ff9dc1 100755 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasics.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasics.java @@ -21,8 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.datatypes.RDFDatatype; import org.apache.jena.datatypes.TypeMapper; import org.apache.jena.graph.Graph; @@ -68,7 +70,7 @@ /** * Unit tests for simple infrastructure pieces of the rule systems. */ -public class TestBasics extends TestCase { +public class TestBasics { // Maximum size of binding environment needed in the tests private static final int MAX_VARS = 10; @@ -85,21 +87,14 @@ public class TestBasics extends TestCase { Node n5 = NodeFactory.createURI("n5"); Node res = NodeFactory.createURI("res"); - /** * Boilerplate for junit */ - public TestBasics( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite( TestBasics.class ); - } private static Graph createGraphForTest() { return GraphMemFactory.createDefaultGraph(); @@ -108,10 +103,12 @@ private static Graph createGraphForTest() { /** * Test the internal rule parser */ + @Test public void testRuleParserBad01() { execTestBad("(foo(?A) eg:p ?B) <- (?a, eg:p, ?B)."); } + @Test public void testRuleParserBad02() { execTestBad("(foo(?A) eg:p ?B) -> (?a, eg:p, ?B)."); } @@ -123,17 +120,20 @@ private static void execTestBad(String ruleStr) { } catch (Rule.ParserException e) { foundError = true; } - assertTrue("Failed to find illegal rule: " + ruleStr, foundError); + assertTrue(foundError, "Failed to find illegal rule: " + ruleStr); } + @Test public void testParser01() { execTest("(?a rdf:type ?_) -> (?a rdf:type ?b).", "[ (?a rdf:type ?_) -> (?a rdf:type ?b) ]"); } + @Test public void testParser02() { execTest("(?a rdf:type ?_), (?a rdf:type ?_) -> (?a rdf:type ?b).", "[ (?a rdf:type ?_) (?a rdf:type ?_) -> (?a rdf:type ?b) ]"); } + @Test public void testParser03() { // Register so that parsing the string form works. RDFDatatype dt = FunctorDatatype.theFunctorDatatype; @@ -144,55 +144,68 @@ public void testParser03() { TypeMapper.getInstance().unregisterDatatype(dt); } + @Test public void testParser04() { execTest("(?a rdf:type ?_) -> addOne(?a).", "[ (?a rdf:type ?_) -> addOne(?a) ]"); } + @Test public void testParser05() { execTest("(?a rdf:type ?_) -> [(?a rdf:type ?_) -> addOne(?a)].", "[ (?a rdf:type ?_) -> [ (?a rdf:type ?_) -> addOne(?a) ] ]"); } + @Test public void testParser06() { execTest("(?a rdf:type ?_) -> (?a rdf:type '42').", "[ (?a rdf:type ?_) -> (?a rdf:type '42') ]"); } + @Test public void testParser07() { execTest("(?a rdf:type ?_) -> (?a rdf:type 4.2).", "[ (?a rdf:type ?_) -> (?a rdf:type '4.2'^^http://www.w3.org/2001/XMLSchema#float) ]"); } + @Test public void testParser08() { execTest("(?a rdf:type ?_) -> (?a rdf:type ' fool that,I(am)').", "[ (?a rdf:type ?_) -> (?a rdf:type ' fool that,I(am)') ]"); } + @Test public void testParser09() { execTest("[rule1: (?a rdf:type ?_) -> (?a rdf:type a)]", "[ rule1: (?a rdf:type ?_) -> (?a rdf:type ) ]"); } + @Test public void testParser10() { execTest("-> print(' ').", "[ -> print(' ') ]"); } + @Test public void testParser11() { execTest("-> print(' literal with embedded \\' characters ').", "[ -> print(' literal with embedded \\' characters ') ]"); } + @Test public void testParser12() { execTest("-> print(\" literal characters \").", "[ -> print(' literal characters ') ]"); } + @Test public void testParser13() { execTest("-> print(42). ", "[ -> print('42'^^http://www.w3.org/2001/XMLSchema#int) ]"); } + @Test public void testParser14() { execTest("-> print('42'^^xsd:byte). ", "[ -> print('42'^^http://www.w3.org/2001/XMLSchema#byte) ]"); } + @Test public void testParser15() { execTest("-> print('42'^^http://www.w3.org/2001/XMLSchema#int). ", "[ -> print('42'^^http://www.w3.org/2001/XMLSchema#int) ]"); } + @Test public void testParser16() { PrintUtil.registerPrefix("foobar", "http://foobar#"); try { @@ -202,63 +215,78 @@ public void testParser16() { } } + @Test public void testParser17() { execTest("-> print(). ", "[ -> print() ]"); } + @Test public void testParser18() { execTest("-> print(\"(\").", "[ -> print('(') ]"); } + @Test public void testParser19() { execTest("-> print(\",\").", "[ -> print(',') ]"); } + @Test public void testParser20() { execTest("-> print(',').", "[ -> print(',') ]"); } + @Test public void testParser21() { // Leading quote! execTest("-> print(\"\\\"\").", "[ -> print('\"') ]"); } + @Test public void testParser22() { execTest("-> print('\"').", "[ -> print('\"') ]"); } + @Test public void testParser23() { execTest("-> print(\"'\").", "[ -> print('\\'') ]"); } + @Test public void testParser24() { execTest("-> print('\\'').", "[ -> print('\\'') ]"); } + @Test public void testParser25() { execTest("-> print('(').", "[ -> print('(') ]"); } + @Test public void testParser26() { execTest("-> print(')').", "[ -> print(')') ]"); } + @Test public void testParser27() { execTest("-> print(']').", "[ -> print(']') ]"); } + @Test public void testParser28() { execTest("-> print('[').", "[ -> print('[') ]"); } + @Test public void testParser29() { execTest("-> print(123).", "[ -> print('123'^^http://www.w3.org/2001/XMLSchema#int) ]"); } + @Test public void testParser30() { execTest("-> print(123, 'AB' 'CD').", "[ -> print('123'^^http://www.w3.org/2001/XMLSchema#int 'AB' 'CD') ]"); } + @Test public void testParser31() { execTest("-> print(123) print('AB') print('CD').", "[ -> print('123'^^http://www.w3.org/2001/XMLSchema#int) print('AB') print('CD') ]"); } @@ -282,6 +310,7 @@ private static void execTest(String ruleStr, String expected) { /** * Test rule equality operations. */ + @Test public void testRuleEquality() { Rule r1 = Rule.parseRule("(?a p ?b) -> (?a q ?b)."); Rule r2 = Rule.parseRule("(?a p ?b) -> (?b q ?a)."); @@ -292,9 +321,9 @@ public void testRuleEquality() { Rule r5 = Rule.parseRule("(?a p ?b), addOne(?b) -> (?a q ?b)."); Rule r6 = Rule.parseRule("(?a p ?b), addOne(p) -> (?a q ?b)."); assertTrue(! r1.equals(r2)); - assertTrue( r1.equals(r1b)); + assertTrue( r1.equals(r1b)); assertTrue(! r1.equals(r3)); - assertTrue( r3.equals(r3b)); + assertTrue( r3.equals(r3b)); assertTrue(! r3.equals(r4)); assertTrue(! r3.equals(r5)); assertTrue(! r3.equals(r6)); @@ -303,6 +332,7 @@ public void testRuleEquality() { /** * Test the BindingEnvironment machinery */ + @Test public void testBindingEnvironment() { BindingStack env = new BindingStack(); env.reset(MAX_VARS); @@ -335,7 +365,7 @@ public void testBindingEnvironment() { assertEquals(n3, env.getEnvironment()[1]); try { env.unwind(); - assertTrue("Failed to catch end of stack", false); + assertTrue(false, "Failed to catch end of stack"); } catch (IndexOutOfBoundsException e) { } } @@ -343,6 +373,7 @@ public void testBindingEnvironment() { /** * Test simple single clause binding */ + @Test public void testClauseMaching() { BindingStack env = new BindingStack(); env.reset(MAX_VARS); @@ -390,6 +421,7 @@ public void testClauseMaching() { /** * Minimal rule tester to check basic pattern match */ + @Test public void testRuleMatcher() { String rules = "[r1: (?a p ?b), (?b q ?c) -> (?a, q, ?c)]" + "[r2: (?a p ?b), (?b p ?c) -> (?a, p, ?c)]" + @@ -403,7 +435,7 @@ public void testRuleMatcher() { infgraph.add(Triple.create(n2, q, n3)); infgraph.add(Triple.create(n4, p, n4)); - TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), + TestUtil.assertIteratorValues( infgraph.find(null, null, null), new Triple[] { Triple.create(n1, p, n2), Triple.create(n2, p, n3), @@ -418,6 +450,7 @@ public void testRuleMatcher() { /** * Test derivation machinery */ + @Test public void testRuleDerivations() { String rules = "[testRule1: (n1 p ?a) -> (n2, p, ?a)]" + "[testRule2: (n1 q ?a) -> (n2, q, ?a)]" + @@ -430,7 +463,7 @@ public void testRuleDerivations() { infgraph.add(Triple.create(n1, q, n4)); infgraph.add(Triple.create(n1, q, n3)); - TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), + TestUtil.assertIteratorValues( infgraph.find(null, null, null), new Triple[] { Triple.create(n1, p, n3), Triple.create(n2, p, n3), @@ -458,10 +491,10 @@ public void testRuleDerivations() { assertEquals(testString, TestUtil.normalizeWhiteSpace(outString.getBuffer().toString())); } - /** * Test axiom handling machinery */ + @Test public void testAxiomHandling() { String rules = "[testRule1: (n1 p ?a) -> (n2, p, ?a)]" + "[testRule2: (n1 q ?a) -> (n2, q, ?a)]" + @@ -470,7 +503,7 @@ public void testAxiomHandling() { List ruleList = Rule.parseRules(rules); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(createGraphForTest()); - TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), + TestUtil.assertIteratorValues( infgraph.find(null, null, null), new Triple[] { Triple.create(n1, p, n3), Triple.create(n2, p, n3), @@ -479,7 +512,7 @@ public void testAxiomHandling() { infgraph.add(Triple.create(n1, q, n4)); infgraph.add(Triple.create(n1, q, n3)); - TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), + TestUtil.assertIteratorValues( infgraph.find(null, null, null), new Triple[] { Triple.create(n1, p, n3), Triple.create(n2, p, n3), @@ -495,6 +528,7 @@ public void testAxiomHandling() { /** * Test schema partial binding machinery */ + @Test public void testSchemaBinding() { String rules = "[testRule1: (n1 p ?a) -> (n2, p, ?a)]" + "[testRule2: (n1 q ?a) -> (n2, q, ?a)]" + @@ -510,7 +544,7 @@ public void testSchemaBinding() { Reasoner boundReasoner = reasoner.bindSchema(schema); InfGraph infgraph = boundReasoner.bind(data); - TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), + TestUtil.assertIteratorValues( infgraph.find(null, null, null), new Triple[] { Triple.create(n1, p, n3), Triple.create(n2, p, n3), @@ -525,6 +559,7 @@ public void testSchemaBinding() { /** * Test functor handling */ + @Test public void testEmbeddedFunctors() { String rules = "(?C owl:onProperty ?P), (?C owl:allValuesFrom ?D) -> (?C rb:restriction all(?P, ?D))." + "(?C rb:restriction all(eg:p, eg:D)) -> (?C rb:restriction 'allOK')." + @@ -563,6 +598,7 @@ public void testEmbeddedFunctors() { /** * The the minimal machinery for supporting builtins */ + @Test public void testBuiltins() { String rules = //"[testRule1: (n1 ?p ?a) -> print('rule1test', ?p, ?a)]" + "[r1: (n1 p ?x), addOne(?x, ?y) -> (n1 q ?y)]" + @@ -573,12 +609,12 @@ public void testBuiltins() { List ruleList = Rule.parseRules(rules); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(createGraphForTest()); - TestUtil.assertIteratorValues(this, infgraph.find(n1, q, null), + TestUtil.assertIteratorValues( infgraph.find(n1, q, null), new Triple[] { Triple.create(n1, q, Util.makeIntNode(2)), Triple.create(n1, q, Util.makeIntNode(5)) }); - TestUtil.assertIteratorValues(this, infgraph.find(n2, q, null), + TestUtil.assertIteratorValues( infgraph.find(n2, q, null), new Triple[] { Triple.create(n2, q, Util.makeIntNode(1)) }); @@ -588,6 +624,7 @@ public void testBuiltins() { /** * The the "remove" builtin */ + @Test public void testRemoveBuiltin() { String rules = "[rule1: (?x p ?y), (?x q ?y) -> remove(0)]" + @@ -599,7 +636,7 @@ public void testRemoveBuiltin() { infgraph.add(Triple.create(n1, p, Util.makeIntNode(2))); infgraph.add(Triple.create(n1, q, Util.makeIntNode(2))); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), + TestUtil.assertIteratorValues( infgraph.find(n1, null, null), new Triple[] { Triple.create(n1, p, Util.makeIntNode(1)), Triple.create(n1, q, Util.makeIntNode(2)) @@ -610,6 +647,7 @@ public void testRemoveBuiltin() { /** * The the "drop" builtin */ + @Test public void testDropBuiltin() { String rules = "[rule1: (?x p ?y) -> drop(0)]" + @@ -621,7 +659,7 @@ public void testDropBuiltin() { infgraph.add(Triple.create(n1, p, Util.makeIntNode(2))); infgraph.add(Triple.create(n1, q, Util.makeIntNode(2))); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), + TestUtil.assertIteratorValues( infgraph.find(n1, null, null), new Triple[] { Triple.create(n1, q, Util.makeIntNode(2)) }); @@ -631,13 +669,14 @@ public void testDropBuiltin() { /** * Test the rebind operation. */ + @Test public void testRebind() { String rules = "[rule1: (?x p ?y) -> (?x q ?y)]"; List ruleList = Rule.parseRules(rules); Graph data = createGraphForTest(); data.add(Triple.create(n1, p, n2)); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(data); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), + TestUtil.assertIteratorValues( infgraph.find(n1, null, null), new Triple[] { Triple.create(n1, p, n2), Triple.create(n1, q, n2) @@ -645,7 +684,7 @@ public void testRebind() { Graph ndata = createGraphForTest(); ndata.add(Triple.create(n1, p, n3)); infgraph.rebind(ndata); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), + TestUtil.assertIteratorValues( infgraph.find(n1, null, null), new Triple[] { Triple.create(n1, p, n3), Triple.create(n1, q, n3) @@ -655,6 +694,7 @@ public void testRebind() { /** * Test size bug, used to blow up if size was called before any queries. */ + @Test public void testSize() { String rules = "[rule1: (?x p ?y) -> (?x q ?y)]"; List ruleList = Rule.parseRules(rules); @@ -667,30 +707,32 @@ public void testSize() { /** * Check validity report implementation, there had been a stupid bug here. */ + @Test public void testValidityReport() { StandardValidityReport report = new StandardValidityReport(); report.add(false, "dummy", "dummy1"); report.add(false, "dummy", "dummy3"); assertTrue(report.isValid()); report.add(true, "dummy", "dummy2"); - assertTrue( ! report.isValid()); + assertTrue(! report.isValid()); report = new StandardValidityReport(); report.add(false, "dummy", "dummy1"); report.add(true, "dummy", "dummy2"); report.add(false, "dummy", "dummy3"); - assertTrue( ! report.isValid()); + assertTrue(! report.isValid()); report = new StandardValidityReport(); report.add(new ValidityReport.Report(false, "dummy", "dummy1")); report.add(new ValidityReport.Report(true, "dummy", "dummy2")); report.add(new ValidityReport.Report(false, "dummy", "dummy3")); - assertTrue( ! report.isValid()); + assertTrue(! report.isValid()); } /** * Test the list conversion utility that is used in some of the builtins. */ + @Test public void testConvertList() { Graph data = createGraphForTest(); Node first = RDF.Nodes.first; diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestComparatorBuiltins.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestComparatorBuiltins.java index 38c862b0b67..989d6dd67d7 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestComparatorBuiltins.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestComparatorBuiltins.java @@ -21,8 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.datatypes.RDFDatatype; import org.apache.jena.datatypes.xsd.XSDDatatype; import org.apache.jena.graph.Node; @@ -37,16 +39,11 @@ /** * Test cases for comparison operators, especially as applies to time values */ -public class TestComparatorBuiltins extends TestCase { - - public TestComparatorBuiltins(String name) { - super(name); - } +public class TestComparatorBuiltins { - public static TestSuite suite() { - return new TestSuite( TestComparatorBuiltins.class ); - } + + @Test public void testComparatorNumbers() { doTestComparator("1", "2", XSDDatatype.XSDint); doTestComparator("1.0", "1.1", XSDDatatype.XSDfloat); @@ -62,6 +59,7 @@ public void testComparatorNumbers() { NodeFactory.createLiteralDT("2", XSDDatatype.XSDlong) ); } + @Test public void testComparatorTime() { doTestComparator("2000-03-04T20:00:00Z", "2000-03-05T20:00:00Z", XSDDatatype.XSDdateTime); doTestComparator("2000-03-04T20:00:00Z", "2000-03-04T21:00:00Z", XSDDatatype.XSDdateTime); @@ -90,27 +88,27 @@ public void doTestBuiltins(String lLow, String lHigh, RDFDatatype type) { } public void doTestBuiltins(Node nLow, Node nHigh) { - assertTrue( call(new Equal(), nLow, nLow) ); - assertFalse( call(new Equal(), nLow, nHigh) ); + assertTrue(call(new Equal(), nLow, nLow) ); + assertFalse(call(new Equal(), nLow, nHigh) ); - assertFalse( call(new NotEqual(), nLow, nLow) ); - assertTrue( call(new NotEqual(), nLow, nHigh) ); + assertFalse(call(new NotEqual(), nLow, nLow) ); + assertTrue(call(new NotEqual(), nLow, nHigh) ); - assertTrue( call(new LE(), nLow, nHigh) ); - assertFalse( call(new LE(), nHigh, nLow) ); - assertTrue( call(new LE(), nLow, nLow) ); + assertTrue(call(new LE(), nLow, nHigh) ); + assertFalse(call(new LE(), nHigh, nLow) ); + assertTrue(call(new LE(), nLow, nLow) ); - assertTrue( call(new LessThan(), nLow, nHigh) ); - assertFalse( call(new LessThan(), nHigh, nLow) ); - assertFalse( call(new LessThan(), nLow, nLow) ); + assertTrue(call(new LessThan(), nLow, nHigh) ); + assertFalse(call(new LessThan(), nHigh, nLow) ); + assertFalse(call(new LessThan(), nLow, nLow) ); - assertFalse( call(new GE(), nLow, nHigh) ); - assertTrue( call(new GE(), nHigh, nLow) ); - assertTrue( call(new GE(), nLow, nLow) ); + assertFalse(call(new GE(), nLow, nHigh) ); + assertTrue(call(new GE(), nHigh, nLow) ); + assertTrue(call(new GE(), nLow, nLow) ); - assertFalse( call(new GreaterThan(), nLow, nHigh) ); - assertTrue( call(new GreaterThan(), nHigh, nLow) ); - assertFalse( call(new GreaterThan(), nLow, nLow) ); + assertFalse(call(new GreaterThan(), nLow, nHigh) ); + assertTrue(call(new GreaterThan(), nHigh, nLow) ); + assertFalse(call(new GreaterThan(), nLow, nLow) ); } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestConfigVocabulary.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestConfigVocabulary.java index 644f7f107d4..52da95bf201 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestConfigVocabulary.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestConfigVocabulary.java @@ -21,7 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.rdf.model.Property; import org.apache.jena.rdf.model.Resource; import org.apache.jena.reasoner.ReasonerRegistry; @@ -32,60 +35,61 @@ /** Tests for configuration vocabulary added as part of ModelSpec removal */ -public class TestConfigVocabulary extends TestCase - { - public TestConfigVocabulary( String name ) - { super( name ); } +public class TestConfigVocabulary { + @Test public void testExistingVocabulary() { - assertIsProperty( "name", ReasonerVocabulary.nameP ); - assertIsProperty( "description", ReasonerVocabulary.descriptionP ); - assertIsProperty( "version", ReasonerVocabulary.versionP ); - assertIsProperty( "supports", ReasonerVocabulary.supportsP ); - assertIsProperty( "configurationProperty", ReasonerVocabulary.configurationP ); - assertIsProperty( "individualAsThing", ReasonerVocabulary.individualAsThingP ); + assertIsProperty("name", ReasonerVocabulary.nameP ); + assertIsProperty("description", ReasonerVocabulary.descriptionP ); + assertIsProperty("version", ReasonerVocabulary.versionP ); + assertIsProperty("supports", ReasonerVocabulary.supportsP ); + assertIsProperty("configurationProperty", ReasonerVocabulary.configurationP ); + assertIsProperty("individualAsThing", ReasonerVocabulary.individualAsThingP ); } + @Test public void testPropVocavulary() { - assertIsPropProperty( "derivationLogging", ReasonerVocabulary.PROPderivationLogging ); - assertIsPropProperty( "traceOn", ReasonerVocabulary.PROPtraceOn ); - assertIsPropProperty( "ruleMode", ReasonerVocabulary.PROPruleMode ); - assertIsPropProperty( "enableOWLTranslation", ReasonerVocabulary.PROPenableOWLTranslation ); - assertIsPropProperty( "enableTGCCaching", ReasonerVocabulary.PROPenableTGCCaching ); - assertIsPropProperty( "enableCMPScan", ReasonerVocabulary.PROPenableCMPScan ); - assertIsPropProperty( "setRDFSLevel", ReasonerVocabulary.PROPsetRDFSLevel ); - assertIsPropProperty( "enableFunctorFiltering", ReasonerVocabulary.PROPenableFunctorFiltering ); + assertIsPropProperty("derivationLogging", ReasonerVocabulary.PROPderivationLogging ); + assertIsPropProperty("traceOn", ReasonerVocabulary.PROPtraceOn ); + assertIsPropProperty("ruleMode", ReasonerVocabulary.PROPruleMode ); + assertIsPropProperty("enableOWLTranslation", ReasonerVocabulary.PROPenableOWLTranslation ); + assertIsPropProperty("enableTGCCaching", ReasonerVocabulary.PROPenableTGCCaching ); + assertIsPropProperty("enableCMPScan", ReasonerVocabulary.PROPenableCMPScan ); + assertIsPropProperty("setRDFSLevel", ReasonerVocabulary.PROPsetRDFSLevel ); + assertIsPropProperty("enableFunctorFiltering", ReasonerVocabulary.PROPenableFunctorFiltering ); } + @Test public void testDirectVocabulary() { - assertIsDirectProperty( RDFS.subClassOf, ReasonerVocabulary.directSubClassOf ); - assertIsDirectProperty( RDFS.subPropertyOf, ReasonerVocabulary.directSubPropertyOf ); - assertIsDirectProperty( RDF.type, ReasonerVocabulary.directRDFType ); + assertIsDirectProperty(RDFS.subClassOf, ReasonerVocabulary.directSubClassOf ); + assertIsDirectProperty(RDFS.subPropertyOf, ReasonerVocabulary.directSubPropertyOf ); + assertIsDirectProperty(RDF.type, ReasonerVocabulary.directRDFType ); } + @Test public void testRuleSetVocabulary() { - assertIsProperty( "ruleSet", ReasonerVocabulary.ruleSet ); - assertIsProperty( "ruleSetURL", ReasonerVocabulary.ruleSetURL ); - assertIsProperty( "hasRule", ReasonerVocabulary.hasRule ); - assertIsProperty( "schemaURL", ReasonerVocabulary.schemaURL ); + assertIsProperty("ruleSet", ReasonerVocabulary.ruleSet ); + assertIsProperty("ruleSetURL", ReasonerVocabulary.ruleSetURL ); + assertIsProperty("hasRule", ReasonerVocabulary.hasRule ); + assertIsProperty("schemaURL", ReasonerVocabulary.schemaURL ); } - private void assertIsDirectProperty( Resource r, Property p ) + private void assertIsDirectProperty(Resource r, Property p ) { - assertEquals( ReasonerRegistry.makeDirect( r.getURI() ), p.getURI() ); + assertEquals(ReasonerRegistry.makeDirect( r.getURI() ), p.getURI() ); } - private void assertIsProperty( String name, Property p ) + private void assertIsProperty(String name, Property p ) { - assertEquals( ReasonerVocabulary.getJenaReasonerNS() + name, p.getURI() ); + assertEquals(ReasonerVocabulary.getJenaReasonerNS() + name, p.getURI() ); } - private void assertIsPropProperty( String name, Property p ) + private void assertIsPropProperty(String name, Property p ) { - assertEquals( ReasonerVocabulary.PropURI + "#" + name, p.getURI() ); + assertEquals(ReasonerVocabulary.PropURI + "#" + name, p.getURI() ); } } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestFBRules.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestFBRules.java index 1d736dd96f8..6aa27a63787 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestFBRules.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestFBRules.java @@ -21,8 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.datatypes.xsd.XSDDatatype; import org.apache.jena.datatypes.xsd.XSDDateTime; import org.apache.jena.graph.Graph; @@ -70,7 +72,7 @@ /** * Test suite for the hybrid forward/backward rule system. */ -public class TestFBRules extends TestCase { +public class TestFBRules { protected static Logger logger = LoggerFactory.getLogger(TestFBRules.class); @@ -104,20 +106,11 @@ public class TestFBRules extends TestCase { /** * Boilerplate for junit */ - public TestFBRules( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite( TestFBRules.class ); -// TestSuite suite = new TestSuite(); -// suite.addTest(new TestFBRules( "testNumericFunctors" )); -// return suite; - } private static Graph createGraphForTest() { return GraphMemFactory.createDefaultGraph(); @@ -141,7 +134,6 @@ public InfGraph createInfGraph(String rules, Graph data) { return createReasoner( Rule.parseRules(rules) ).bind(data); } - /** * Assemble a test infGraph from a rule source and empty data */ @@ -152,16 +144,18 @@ public InfGraph createInfGraph(String rules) { /** * Check parser extension for f/b distinction. */ + @Test public void testParser() { String rf = "(?a rdf:type ?t) -> (?t rdf:type rdfs:Class)."; String rb = "(?t rdf:type rdfs:Class) <- (?a rdf:type ?t)."; - assertTrue( ! Rule.parseRule(rf).isBackward() ); - assertTrue( Rule.parseRule(rb).isBackward() ); + assertTrue(! Rule.parseRule(rf).isBackward() ); + assertTrue( Rule.parseRule(rb).isBackward() ); } /** * Minimal rule tester to check basic pattern match, forward style. */ + @Test public void testRuleMatcher() { String rules = "[r1: (?a p ?b), (?b q ?c) -> (?a, q, ?c)]" + "[r2: (?a p ?b), (?b p ?c) -> (?a, p, ?c)]" + @@ -174,7 +168,7 @@ public void testRuleMatcher() { infgraph.add(Triple.create(n2, q, n3)); infgraph.add(Triple.create(n4, p, n4)); - TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), + TestUtil.assertIteratorValues( infgraph.find(null, null, null), new Triple[] { Triple.create(n1, p, n2), Triple.create(n2, p, n3), @@ -189,6 +183,7 @@ public void testRuleMatcher() { /** * Test functor handling */ + @Test public void testEmbeddedFunctors() { String rules = "(?C owl:onProperty ?P), (?C owl:allValuesFrom ?D) -> (?C rb:restriction all(?P, ?D))." + "(?C rb:restriction all(eg:p, eg:D)) -> (?C rb:restriction 'allOK')." + @@ -222,6 +217,7 @@ public void testEmbeddedFunctors() { /** * The the minimal machinery for supporting builtins */ + @Test public void testBuiltins() { String rules = //"[testRule1: (n1 ?p ?a) -> print('rule1test', ?p, ?a)]" + "[r1: (n1 p ?x), addOne(?x, ?y) -> (n1 q ?y)]" + @@ -231,12 +227,12 @@ public void testBuiltins() { ""; InfGraph infgraph = createInfGraph(rules); - TestUtil.assertIteratorValues(this, infgraph.find(n1, q, null), + TestUtil.assertIteratorValues( infgraph.find(n1, q, null), new Triple[] { Triple.create(n1, q, Util.makeIntNode(2)), Triple.create(n1, q, Util.makeIntNode(5)) }); - TestUtil.assertIteratorValues(this, infgraph.find(n2, q, null), + TestUtil.assertIteratorValues( infgraph.find(n2, q, null), new Triple[] { Triple.create(n2, q, Util.makeIntNode(1)) }); @@ -246,6 +242,7 @@ public void testBuiltins() { /** * Test schmea partial binding machinery, forward subset. */ + @Test public void testSchemaBinding() { String rules = "[testRule1: (n1 p ?a) -> (n2, p, ?a)]" + "[testRule2: (n1 q ?a) -> (n2, q, ?a)]" + @@ -262,7 +259,7 @@ public void testSchemaBinding() { Reasoner boundReasoner = reasoner.bindSchema(schema); InfGraph infgraph = boundReasoner.bind(data); - TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), + TestUtil.assertIteratorValues( infgraph.find(null, null, null), new Triple[] { Triple.create(n1, p, n3), Triple.create(n2, p, n3), @@ -278,6 +275,7 @@ public void testSchemaBinding() { /** * The the "remove" builtin */ + @Test public void testRemoveBuiltin() { String rules = "[rule1: (?x p ?y), (?x q ?y) -> remove(0)]" + @@ -288,7 +286,7 @@ public void testRemoveBuiltin() { infgraph.add(Triple.create(n1, p, Util.makeIntNode(2))); infgraph.add(Triple.create(n1, q, Util.makeIntNode(2))); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), + TestUtil.assertIteratorValues( infgraph.find(n1, null, null), new Triple[] { Triple.create(n1, p, Util.makeIntNode(1)), Triple.create(n1, q, Util.makeIntNode(2)) @@ -299,12 +297,13 @@ public void testRemoveBuiltin() { /** * Test the rebind operation. */ + @Test public void testRebind() { String rules = "[rule1: (?x p ?y) -> (?x q ?y)]"; Graph data = createGraphForTest(); data.add(Triple.create(n1, p, n2)); InfGraph infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), + TestUtil.assertIteratorValues( infgraph.find(n1, null, null), new Triple[] { Triple.create(n1, p, n2), Triple.create(n1, q, n2) @@ -312,19 +311,19 @@ public void testRebind() { Graph ndata = createGraphForTest(); ndata.add(Triple.create(n1, p, n3)); infgraph.rebind(ndata); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), + TestUtil.assertIteratorValues( infgraph.find(n1, null, null), new Triple[] { Triple.create(n1, p, n3), Triple.create(n1, q, n3) }); } - /** * Test that reset does actually clear out all the data. * We use the RDFS configuration because uses both TGC, forward and backward * rules and so is a good check. */ + @Test public void testRebind2() { String NS = "http://jena.hpl.hp.com/test#"; Model base = ModelFactory.createDefaultModel(); @@ -343,6 +342,7 @@ public void testRebind2() { /** * Test rebindAll reconsults a changed ruleset */ + @Test public void testRebindAll() { String NS = "http://jena.hpl.hp.com/example#"; List rules1 = Rule.parseRules( "(?x http://jena.hpl.hp.com/example#p ?y) -> (?x http://jena.hpl.hp.com/example#q ?y)." ); @@ -360,22 +360,23 @@ public void testRebindAll() { GenericRuleReasoner reasoner = new GenericRuleReasoner(rules1); InfModel infModel = ModelFactory.createInfModel(reasoner, m); reasoner.addRules(rules2); - TestUtil.assertIteratorValues(this, infModel.listStatements(a, null, (RDFNode)null), + TestUtil.assertIteratorValues( infModel.listStatements(a, null, (RDFNode)null), new Object[] {s1, s2}); ((FBRuleInfGraph)infModel.getGraph()).rebindAll(); - TestUtil.assertIteratorValues(this, infModel.listStatements(a, null, (RDFNode)null), + TestUtil.assertIteratorValues( infModel.listStatements(a, null, (RDFNode)null), new Object[] {s1, s2, s3}); } /** * Test the close operation. */ + @Test public void testClose() { String rules = "[rule1: (?x p ?y) -> (?x q ?y)]"; Graph data = createGraphForTest(); data.add(Triple.create(n1, p, n2)); InfGraph infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), + TestUtil.assertIteratorValues( infgraph.find(n1, null, null), new Triple[] { Triple.create(n1, p, n2), Triple.create(n1, q, n2) @@ -387,12 +388,13 @@ public void testClose() { } catch (ClosedException e) { foundException = true; } - assertTrue("Close detected", foundException); + assertTrue(foundException, "Close detected"); } /** * Test example pure backchaining rules */ + @Test public void testBackchain1() { Graph data = createGraphForTest(); data.add(Triple.create(p, sP, q)); @@ -407,14 +409,14 @@ public void testBackchain1() { "[rdfs3: (?y rdf:type ?c) <- (?x ?p ?y), (?p rdfs:range ?c)]" + "[rdfs7: (?a rdfs:subClassOf ?a) <- (?a rdf:type rdfs:Class)]"; InfGraph infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, ty, null), new Object[] { Triple.create(a, ty, C1), Triple.create(a, ty, C2), Triple.create(a, ty, C3) } ); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(C1, sC, a), new Object[] { } ); @@ -423,6 +425,7 @@ public void testBackchain1() { /** * Test complex rule head unification */ + @Test public void testBackchain2() { Graph data = createGraphForTest(); data.add(Triple.create(c, q, d)); @@ -430,7 +433,7 @@ public void testBackchain2() { "[r1: (c r ?x) <- (?x p f(?x b))]" + "[r2: (?y p f(a ?y)) <- (c q ?y)]"; InfGraph infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(c, r, null), new Object[] { } ); data.add(Triple.create(c, q, a)); @@ -438,7 +441,7 @@ public void testBackchain2() { "[r1: (c r ?x) <- (?x p f(?x a))]" + "[r2: (?y p f(a ?y)) <- (c q ?y)]"; infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(c, r, null), new Object[] { Triple.create(c, r, a) @@ -454,7 +457,7 @@ public void testBackchain2() { "[r1: (c r ?x) <- (?x p ?x)]" + "[r2: (?x p ?y) <- (a q ?x), (b q ?y)]"; infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(c, r, null), new Object[] { Triple.create(c, r, b) @@ -464,7 +467,7 @@ public void testBackchain2() { "[r1: (c r ?x) <- (?x p ?x)]" + "[r2: (a p ?x) <- (a q ?x)]"; infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(c, r, null), new Object[] { Triple.create(c, r, a) @@ -474,6 +477,7 @@ public void testBackchain2() { /** * Test restriction example */ + @Test public void testBackchain3() { Graph data = createGraphForTest(); data.add(Triple.create(a, ty, r)); @@ -488,7 +492,7 @@ public void testBackchain3() { "[rs2: (?X rdf:type all(?P,?C)) <- (?D owl:equivalentClass all(?P,?C)), (?X rdf:type ?D)]" + "[rp4: (?Y rdf:type ?C) <- (?X rdf:type all(?P, ?C)), (?X ?P ?Y)]"; InfGraph infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(b, ty, c), new Object[] { Triple.create(b, ty, c) } ); @@ -497,6 +501,7 @@ public void testBackchain3() { /** * Test example hybrid rule. */ + @Test public void testHybrid1() { Graph data = createGraphForTest(); data.add(Triple.create(a, p, b)); @@ -504,7 +509,7 @@ public void testHybrid1() { String rules = "[r1: (?p rdf:type s) -> [r1b: (?x ?p ?y) <- (?y ?p ?x)]]"; InfGraph infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, p, null), new Object[] { Triple.create(a, p, b), Triple.create(b, p, a) @@ -514,6 +519,7 @@ public void testHybrid1() { /** * Test example hybrid rule. */ + @Test public void testHybrid2() { Graph data = createGraphForTest(); data.add(Triple.create(a, r, b)); @@ -526,8 +532,8 @@ public void testHybrid2() { FBRuleInfGraph infgraph = (FBRuleInfGraph) createInfGraph(rules, data); infgraph.setDerivationLogging(true); infgraph.prepare(); - assertTrue("Forward rule count", infgraph.getNRulesFired() == 3); - TestUtil.assertIteratorValues(this, + assertTrue(infgraph.getNRulesFired() == 3, "Forward rule count"); + TestUtil.assertIteratorValues( infgraph.find(null, p, null), new Object[] { Triple.create(a, p, a), Triple.create(a, p, b), @@ -542,13 +548,14 @@ public void testHybrid2() { assertTrue(di.hasNext()); RuleDerivation d = (RuleDerivation)di.next(); assertTrue(d.getRule().getName().equals("r1b")); - TestUtil.assertIteratorValues(this, d.getMatches().iterator(), new Object[] { Triple.create(a, p, b) }); + TestUtil.assertIteratorValues( d.getMatches().iterator(), new Object[] { Triple.create(a, p, b) }); assertTrue(! di.hasNext()); } /** * Test example hybrid rules for rdfs. */ + @Test public void testHybridRDFS() { Graph data = createGraphForTest(); data.add(Triple.create(a, p, b)); @@ -564,7 +571,7 @@ public void testHybridRDFS() { "[rdfs9: (?x rdfs:subClassOf ?y) -> [ (?a rdf:type ?y) <- (?a rdf:type ?x)] ]"; InfGraph infgraph = createInfGraph(rules, data); // ((FBRuleInfGraph)infgraph).setTraceOn(true); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(b, ty, null), new Object[] { Triple.create(b, ty, C1) } ); @@ -573,6 +580,7 @@ public void testHybridRDFS() { /** * Test example hybrid rules for rdfs. */ + @Test public void testHybridRDFS2() { Graph data = createGraphForTest(); data.add(Triple.create(a, p, b)); @@ -583,7 +591,7 @@ public void testHybridRDFS2() { "[rdfs6: (?p rdfs:subPropertyOf ?q) -> [ (?a ?q ?b) <- (?a ?p ?b)] ]"; InfGraph infgraph = createInfGraph(rules, data); // ((FBRuleInfGraph)infgraph).setTraceOn(true); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(b, ty, C1), new Object[] { Triple.create(b, ty, C1) } ); @@ -592,6 +600,7 @@ public void testHybridRDFS2() { /** * Test access to makeInstance machinery from a Brule. */ + @Test public void testMakeInstance() { Graph data = createGraphForTest(); data.add(Triple.create(a, ty, C1)); @@ -611,6 +620,7 @@ public void testMakeInstance() { /** * Test access to makeInstance machinery from a Brule. */ + @Test public void testMakeInstances() { Graph data = createGraphForTest(); data.add(Triple.create(a, ty, C1)); @@ -627,6 +637,7 @@ public void testMakeInstances() { /** * Test case for makeInstance which failed during development. */ + @Test public void testMakeInstanceBug() { Graph data = createGraphForTest(); data.add(Triple.create(a, ty, r)); @@ -648,6 +659,7 @@ public void testMakeInstanceBug() { /** * Test numeric functors */ + @Test public void testNumericFunctors() { String rules = "[r1: (?x p f(a, ?x)) -> (?x q f(?x)) ]" + @@ -661,7 +673,7 @@ public void testNumericFunctors() { a, NodeFactory.createLiteralDT( "0", XSDDatatype.XSDnonNegativeInteger ) } ))); InfGraph infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(null, s, null), + TestUtil.assertIteratorValues( infgraph.find(null, s, null), new Triple[] { Triple.create(n2, s, res), Triple.create(n3, s, res), @@ -671,6 +683,7 @@ public void testNumericFunctors() { /** * Test the builtins themselves */ + @Test public void testBuiltins2() { // Numeric comparisions Node lt = NodeFactory.createURI("lt"); @@ -693,19 +706,19 @@ public void testBuiltins2() { data.add(Triple.create(n3, q, Util.makeIntNode(3)) ); InfGraph infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, n2), + TestUtil.assertIteratorValues( infgraph.find(n1, null, n2), new Triple[] { Triple.create(n1, eq, n2), Triple.create(n1, le, n2), Triple.create(n1, ge, n2), }); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, n3), + TestUtil.assertIteratorValues( infgraph.find(n1, null, n3), new Triple[] { Triple.create(n1, ne, n3), Triple.create(n1, lt, n3), Triple.create(n1, le, n3), }); - TestUtil.assertIteratorValues(this, infgraph.find(n3, null, n1), + TestUtil.assertIteratorValues( infgraph.find(n3, null, n1), new Triple[] { Triple.create(n3, ne, n1), Triple.create(n3, gt, n1), @@ -719,13 +732,13 @@ public void testBuiltins2() { data.add(Triple.create(n3, q, Util.makeDoubleNode(2.3)) ); infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, n2), + TestUtil.assertIteratorValues( infgraph.find(n1, null, n2), new Triple[] { Triple.create(n1, ne, n2), Triple.create(n1, le, n2), Triple.create(n1, lt, n2), }); - TestUtil.assertIteratorValues(this, infgraph.find(n2, null, n3), + TestUtil.assertIteratorValues( infgraph.find(n2, null, n3), new Triple[] { Triple.create(n2, ne, n3), Triple.create(n2, le, n3), @@ -740,25 +753,25 @@ public void testBuiltins2() { data.add(Triple.create(n3, q, NodeFactory.createLiteralDT("2002-03-04T20:00:00Z", XSDDatatype.XSDdateTime))); infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, n2), + TestUtil.assertIteratorValues( infgraph.find(n1, null, n2), new Triple[] { Triple.create(n1, ne, n2), Triple.create(n1, le, n2), Triple.create(n1, lt, n2), }); - TestUtil.assertIteratorValues(this, infgraph.find(n2, null, n3), + TestUtil.assertIteratorValues( infgraph.find(n2, null, n3), new Triple[] { Triple.create(n2, ne, n3), Triple.create(n2, le, n3), Triple.create(n2, lt, n3), }); - TestUtil.assertIteratorValues(this, infgraph.find(n2, null, n1), + TestUtil.assertIteratorValues( infgraph.find(n2, null, n1), new Triple[] { Triple.create(n2, ne, n1), Triple.create(n2, ge, n1), Triple.create(n2, gt, n1), }); - TestUtil.assertIteratorValues(this, infgraph.find(n3, null, n2), + TestUtil.assertIteratorValues( infgraph.find(n3, null, n2), new Triple[] { Triple.create(n3, ne, n2), Triple.create(n3, ge, n2), @@ -791,7 +804,7 @@ public void testBuiltins2() { data.add(Triple.create(n1, q, Util.makeIntNode(5)) ); infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), + TestUtil.assertIteratorValues( infgraph.find(n1, null, null), new Triple[] { Triple.create(n1, p, Util.makeIntNode(3)), Triple.create(n1, q, Util.makeIntNode(5)), @@ -816,17 +829,17 @@ public void testBuiltins2() { data.add(Triple.create(n3, p, NodeFactory.createBlankNode())); infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(n1, s, null), + TestUtil.assertIteratorValues( infgraph.find(n1, s, null), new Triple[] { Triple.create(n1, s, NodeFactory.createLiteralString("literal")), Triple.create(n1, s, NodeFactory.createLiteralString("notBNode")), }); - TestUtil.assertIteratorValues(this, infgraph.find(n2, s, null), + TestUtil.assertIteratorValues( infgraph.find(n2, s, null), new Triple[] { Triple.create(n2, s, NodeFactory.createLiteralString("notLiteral")), Triple.create(n2, s, NodeFactory.createLiteralString("notBNode")), }); - TestUtil.assertIteratorValues(this, infgraph.find(n3, s, null), + TestUtil.assertIteratorValues( infgraph.find(n3, s, null), new Triple[] { Triple.create(n3, s, NodeFactory.createLiteralString("notLiteral")), Triple.create(n3, s, NodeFactory.createLiteralString("bNode")), @@ -849,7 +862,7 @@ public void testBuiltins2() { data.add(Triple.create(n5, p, NodeFactory.createLiteralDT("-1", XSDDatatype.XSDnonNegativeInteger)) ); infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(null, s, null), + TestUtil.assertIteratorValues( infgraph.find(null, s, null), new Triple[] { Triple.create(n1, s, NodeFactory.createLiteralString("isLiteral")), Triple.create(n1, s, NodeFactory.createLiteralString("isXSDInt")), @@ -880,7 +893,7 @@ public void testBuiltins2() { data.add(Triple.create(n1, p, Util.makeIntNode(3)) ); data.add(Triple.create(n1, p, n2) ); infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(n1, s, null), + TestUtil.assertIteratorValues( infgraph.find(n1, s, null), new Triple[] { Triple.create(n1, s, Util.makeIntNode(2)), }); @@ -891,7 +904,7 @@ public void testBuiltins2() { data = createGraphForTest(); data.add(Triple.create(n1, p, Util.makeList(new Node[]{b, c, d}, data) )); infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(null, q, null), + TestUtil.assertIteratorValues( infgraph.find(null, q, null), new Triple[] { Triple.create(b, q, C1), Triple.create(c, q, C1), @@ -905,6 +918,7 @@ public void testBuiltins2() { /** * Check string manipulation builtins, new at 2.5. */ + @Test public void testStringBuiltins() { String rules = "[r1: (?x p ?y) strConcat(?y, rdf:type, 'foo', ?z) -> (?x q ?z) ] \n" + @@ -914,7 +928,7 @@ public void testStringBuiltins() { data.add(Triple.create(n1, p, NodeFactory.createLiteralString("test")) ); InfGraph infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(null, q, null), + TestUtil.assertIteratorValues( infgraph.find(null, q, null), new Triple[] { Triple.create(n1, q, NodeFactory.createLiteralString("testhttp://www.w3.org/1999/02/22-rdf-syntax-ns#typefoo")), Triple.create(n1, q, NodeFactory.createLiteralString("")), @@ -929,11 +943,11 @@ public void testStringBuiltins() { data.add(Triple.create(n1, p, NodeFactory.createLiteralString("foo bar foo")) ); data.add(Triple.create(n2, p, NodeFactory.createLiteralString("foo bar baz")) ); infgraph = createInfGraph(rules, data); - TestUtil.assertIteratorValues(this, infgraph.find(null, q, null), + TestUtil.assertIteratorValues( infgraph.find(null, q, null), new Triple[] { Triple.create(n1, q, NodeFactory.createLiteralString("ok")), }); - TestUtil.assertIteratorValues(this, infgraph.find(null, r, null), + TestUtil.assertIteratorValues( infgraph.find(null, r, null), new Triple[] { Triple.create(n1, r, NodeFactory.createLiteralString("bar")), }); @@ -942,6 +956,7 @@ public void testStringBuiltins() { /** * Test regex handling of null groups */ + @Test public void testRegexNulls() { String rules = "[r2: (?x p ?y) regex(?y, '((Boys)|(Girls))(.*)', ?m1, ?m2, ?m3, ?m4) -> (?x q ?m2) (?x r ?m3) (?x s ?m4) ] \n" + @@ -950,7 +965,7 @@ public void testRegexNulls() { data.add(Triple.create(n1, p, NodeFactory.createLiteralString("Girls44")) ); InfGraph infgraph = createInfGraph(rules, data); infgraph.prepare(); - TestUtil.assertIteratorValues(this, infgraph.getDeductionsGraph().find(null, null, null), + TestUtil.assertIteratorValues( infgraph.getDeductionsGraph().find(null, null, null), new Triple[] { Triple.create(n1, q, NodeFactory.createLiteralString("")), Triple.create(n1, r, NodeFactory.createLiteralString("Girls")), @@ -962,6 +977,7 @@ public void testRegexNulls() { * More extensive check of arithmetic which checks that binding to an * expected answer also works */ + @Test public void testArithmetic() { doTestArithmetic("sum", 3, 5, 8); doTestArithmetic("difference", 5, 3, 2); @@ -985,8 +1001,8 @@ private void doTestArithmetic(String op, int arg1, int arg2, int expected) { data.add(Triple.create(n1, r, Util.makeIntNode(expected)) ); data.add(Triple.create(n1, t, Util.makeIntNode(expected+1)) ); InfGraph infgraph = createInfGraph(rules, data); - assertTrue( infgraph.contains(n1, s, Util.makeIntNode(expected))); - assertFalse( infgraph.contains(n1, u, Node.ANY) ); + assertTrue(infgraph.contains(n1, s, Util.makeIntNode(expected))); + assertFalse(infgraph.contains(n1, u, Node.ANY) ); } /** @@ -998,7 +1014,7 @@ private Node getValue(Graph g, Node s, Node p) { assertTrue(i.hasNext()); Node result = i.next().getObject(); if (i.hasNext()) { - assertTrue("multiple values not expected", false); + assertTrue(false, "multiple values not expected"); i.close(); } return result; @@ -1008,6 +1024,7 @@ private Node getValue(Graph g, Node s, Node p) { * Investigate a suspicious case in the OWL ruleset, is the backchainer * returning duplicate values? */ + @Test public void testDuplicatesEC4() { boolean prior = JenaParameters.enableFilteringOfHiddenInfNodes; try { @@ -1042,23 +1059,24 @@ public void testDuplicatesEC4() { /** * Test skolem constant generation */ + @Test public void testSkolem() { - assertEquals( getSkolem(a, Util.makeIntNode(42)), + assertEquals(getSkolem(a, Util.makeIntNode(42)), getSkolem(a, Util.makeIntNode(42)) ); - assertNotSame( getSkolem(a, Util.makeIntNode(42)), + assertNotSame(getSkolem(a, Util.makeIntNode(42)), getSkolem(b, Util.makeIntNode(42)) ); - assertNotSame( getSkolem(a, Util.makeIntNode(42)), + assertNotSame(getSkolem(a, Util.makeIntNode(42)), getSkolem(a, Util.makeIntNode(43)) ); - assertNotSame( getSkolem(a, NodeFactory.createLiteralString("foo")), + assertNotSame(getSkolem(a, NodeFactory.createLiteralString("foo")), getSkolem(a, NodeFactory.createLiteralLang("foo", "en")) ); - assertEquals( getSkolem(NodeFactory.createLiteralString("foo")), + assertEquals(getSkolem(NodeFactory.createLiteralString("foo")), getSkolem(NodeFactory.createLiteralString("foo"))); - assertNotSame( getSkolem(NodeFactory.createLiteralString("foo")), + assertNotSame(getSkolem(NodeFactory.createLiteralString("foo")), getSkolem(NodeFactory.createLiteralString("bar"))); } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRuleReasonerConfig.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRuleReasonerConfig.java index 16311f368b4..585456ce895 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRuleReasonerConfig.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRuleReasonerConfig.java @@ -21,6 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import static org.apache.jena.reasoner.rulesys.Rule.parseRule; import java.util.ArrayList; @@ -39,15 +43,12 @@ import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.ReasonerVocabulary; - /** Your eyes will bleed with the number of backslashes required in the substitute strings. */ public class TestGenericRuleReasonerConfig extends AssemblerTestBase { - public TestGenericRuleReasonerConfig( String name ) - { super( name ); } @Override protected Model setRequiredPrefixes( Model x ) @@ -56,6 +57,7 @@ protected Model setRequiredPrefixes( Model x ) return super.setRequiredPrefixes( x ); } + @Test public void testLoadsSingleRuleSetViaURL() { // testLoadsSingleRuleViaURL( "jms" ); @@ -68,9 +70,10 @@ private void testLoadsSingleRuleViaURL( String ns ) Resource r = resourceInModel( "x :ruleSetURL ".replaceAll( "", ns ).replaceAll( "", where ) ); List rules = Rule.rulesFromURL( where ); GenericRuleReasoner grr = new GenericRuleReasoner( null, r ); - assertEquals( rules, grr.getRules() ); + assertEquals(rules, grr.getRules() ); } + @Test public void testLoadsSingleRuleFromString() { // testLoadsSingleRuleFromString( "jms" ); @@ -83,9 +86,10 @@ private void testLoadsSingleRuleFromString( String ns ) List rules = Rule.parseRules( rule ); Resource r = resourceInModel( "x :hasRule ''".replaceAll( "", ns ).replaceAll( "", rule.replaceAll( " ", "\\\\\\\\s" ) ) ); GenericRuleReasoner grr = new GenericRuleReasoner( null, r ); - assertEquals( rules, grr.getRules() ); + assertEquals(rules, grr.getRules() ); } + @Test public void testLoadsSingleRuleViaRuleSetStringString() { // testLoadsRulesViaRuleSetStrings( "jms" ); @@ -104,9 +108,10 @@ private void testLoadsRulesViaRuleSetStrings( String ns ) ; Resource r = resourceInModel( modelString ); GenericRuleReasoner grr = new GenericRuleReasoner( null, r ); - assertEquals( rules, new HashSet<>( grr.getRules() ) ); + assertEquals(rules, new HashSet<>( grr.getRules() ) ); } + @Test public void testLoadsMultipleRuleSetsViaRuleSetNode() { // testLoadsMultipleRuleSetsViaRuleSetNode( "jms" ); @@ -119,7 +124,7 @@ private void testLoadsMultipleRuleSetsViaRuleSetNode( String ns ) String whereB = "file:testing/modelspecs/extra.rules"; Resource r = resourceInModel( "x :ruleSet _a; _a :ruleSetURL ; _a :ruleSetURL ".replaceAll( "", ns ).replaceAll( "", whereA ).replaceAll( "", whereB ) ); GenericRuleReasoner grr = new GenericRuleReasoner( null, r ); - assertEquals( rulesFromTwoPlaces( whereA, whereB ), new HashSet<>( grr.getRules() ) ); + assertEquals(rulesFromTwoPlaces( whereA, whereB ), new HashSet<>( grr.getRules() ) ); } private Set rulesFromTwoStrings( String ruleA, String ruleB ) @@ -137,6 +142,7 @@ private Set rulesFromTwoPlaces( String whereA, String whereB ) return rules; } + @Test public void testRuleLoadingWithOverridenBuiltins() { List savedNode=new ArrayList<>(); Builtin b= new BaseBuiltin() { @@ -155,7 +161,6 @@ public void headAction(Node[] args, int length, RuleContext context) { savedNode.add(getArg(0,args,context)); } - }; BuiltinRegistry r=new OverrideBuiltinRegistry(BuiltinRegistry.theRegistry); r.register(b); diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRules.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRules.java index 55877c4c91e..824d5add6e5 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRules.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRules.java @@ -21,8 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.*; @@ -41,13 +43,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * Test the packaging of all the reasoners into the GenericRuleReasoner. * The other tests check out this engine. These tests just need to touch * enough to validate the packaging. */ -public class TestGenericRules extends TestCase { +public class TestGenericRules { protected static Logger logger = LoggerFactory.getLogger(TestFBRules.class); @@ -77,20 +78,11 @@ public class TestGenericRules extends TestCase { /** * Boilerplate for junit */ - public TestGenericRules( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite( TestGenericRules.class ); -// TestSuite suite = new TestSuite(); -// suite.addTest(new TestGenericRules( "testFunctorLooping" )); -// return suite; - } private static Graph createGraphForTest() { return GraphMemFactory.createDefaultGraph(); @@ -99,6 +91,7 @@ private static Graph createGraphForTest() { /** * Minimal rule tester to check basic pattern match, forward style. */ + @Test public void testForward() { Graph test = createGraphForTest(); test.add(Triple.create(a, p, b)); @@ -110,16 +103,17 @@ public void testForward() { // Check data bind version InfGraph infgraph = reasoner.bind(test); - TestUtil.assertIteratorValues(this, infgraph.find(null, p, null), ans); + TestUtil.assertIteratorValues( infgraph.find(null, p, null), ans); // Check schema bind version infgraph = reasoner.bindSchema(test).bind(createGraphForTest()); - TestUtil.assertIteratorValues(this, infgraph.find(null, p, null), ans); + TestUtil.assertIteratorValues( infgraph.find(null, p, null), ans); } /** * Minimal rule tester to check basic pattern match, backward style. */ + @Test public void testBackward() { Graph test = createGraphForTest(); test.add(Triple.create(a, p, b)); @@ -131,16 +125,17 @@ public void testBackward() { // Check data bind version InfGraph infgraph = reasoner.bind(test); - TestUtil.assertIteratorValues(this, infgraph.find(null, p, null), ans); + TestUtil.assertIteratorValues( infgraph.find(null, p, null), ans); // Check schema bind version infgraph = reasoner.bindSchema(test).bind(createGraphForTest()); - TestUtil.assertIteratorValues(this, infgraph.find(null, p, null), ans); + TestUtil.assertIteratorValues( infgraph.find(null, p, null), ans); } /** * Test example hybrid rule. */ + @Test public void testHybrid() { Graph data = createGraphForTest(); data.add(Triple.create(a, r, b)); @@ -158,7 +153,7 @@ public void testHybrid() { InfGraph infgraph = reasoner.bind(data); infgraph.setDerivationLogging(true); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, p, null), new Object[] { Triple.create(a, p, a), Triple.create(a, p, b), @@ -173,13 +168,14 @@ public void testHybrid() { // d.printTrace(out, true); // out.close(); assertTrue(d.getRule().getName().equals("r1b")); - TestUtil.assertIteratorValues(this, d.getMatches().iterator(), new Object[] { Triple.create(a, p, b) }); + TestUtil.assertIteratorValues( d.getMatches().iterator(), new Object[] { Triple.create(a, p, b) }); assertTrue(! di.hasNext()); } /** * Test early detection of illegal backward rules. */ + @Test public void testBRuleErrorHandling() { Graph data = createGraphForTest(); List rules = Rule.parseRules( @@ -195,12 +191,13 @@ public void testBRuleErrorHandling() { } catch (ReasonerException e) { foundException = true; } - assertTrue("Catching use of multi-headed brules", foundException); + assertTrue(foundException, "Catching use of multi-headed brules"); } /** * Test example parameter setting */ + @Test public void testParameters() { Graph data = createGraphForTest(); data.add(Triple.create(a, r, b)); @@ -214,7 +211,7 @@ public void testParameters() { GenericRuleReasoner reasoner = (GenericRuleReasoner)GenericRuleReasonerFactory.theInstance().create(configuration); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, p, null), new Object[] { Triple.create(a, p, a), Triple.create(a, p, b), @@ -226,14 +223,14 @@ public void testParameters() { assertTrue(di.hasNext()); RuleDerivation d = (RuleDerivation)di.next(); assertTrue(d.getRule().getName().equals("r1b")); - TestUtil.assertIteratorValues(this, d.getMatches().iterator(), new Object[] { Triple.create(a, p, b) }); + TestUtil.assertIteratorValues( d.getMatches().iterator(), new Object[] { Triple.create(a, p, b) }); assertTrue(! di.hasNext()); // Check retrieval of configuration Model m2 = ModelFactory.createDefaultModel(); Resource newConfig = m2.createResource(); reasoner.addDescription(m2, newConfig); - TestUtil.assertIteratorValues(this, newConfig.listProperties(), new Statement[] { + TestUtil.assertIteratorValues( newConfig.listProperties(), new Statement[] { m2.createStatement(newConfig, ReasonerVocabulary.PROPderivationLogging, "true"), m2.createStatement(newConfig, ReasonerVocabulary.PROPruleMode, "hybrid"), m2.createStatement(newConfig, ReasonerVocabulary.PROPruleSet, "testing/reasoners/genericRuleTest.rules") @@ -243,7 +240,7 @@ public void testParameters() { reasoner.setParameter(ReasonerVocabulary.PROPderivationLogging, "false"); newConfig = m2.createResource(); reasoner.addDescription(m2, newConfig); - TestUtil.assertIteratorValues(this, newConfig.listProperties(), new Statement[] { + TestUtil.assertIteratorValues( newConfig.listProperties(), new Statement[] { m2.createStatement(newConfig, ReasonerVocabulary.PROPderivationLogging, "false"), m2.createStatement(newConfig, ReasonerVocabulary.PROPruleMode, "hybrid"), m2.createStatement(newConfig, ReasonerVocabulary.PROPruleSet, "testing/reasoners/genericRuleTest.rules") @@ -261,7 +258,7 @@ public void testParameters() { Node an = NodeFactory.createURI(PrintUtil.egNS + "a"); Node C = NodeFactory.createURI(PrintUtil.egNS + "C"); Node D = NodeFactory.createURI(PrintUtil.egNS + "D"); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, null, null), new Object[] { Triple.create(an, RDF.Nodes.type, C), Triple.create(an, RDF.Nodes.type, D), @@ -278,13 +275,14 @@ public void testParameters() { Resource Cc = im.createResource(PrintUtil.egNS + "C"); im.add(Ac, RDFS.subClassOf, Bc); im.add(Bc, RDFS.subClassOf, Cc); - assertTrue("TGC enabled correctly", im.contains(Ac, RDFS.subClassOf, Cc)); + assertTrue(im.contains(Ac, RDFS.subClassOf, Cc), "TGC enabled correctly"); } /** * Check that the use of typed literals in the configuration also works */ + @Test public void testTypedConfigParameters() { Model m = ModelFactory.createDefaultModel(); Resource configuration= m.createResource(GenericRuleReasonerFactory.URI); @@ -297,12 +295,13 @@ public void testTypedConfigParameters() { Resource Cc = im.createResource(PrintUtil.egNS + "C"); im.add(Ac, RDFS.subClassOf, Bc); im.add(Bc, RDFS.subClassOf, Cc); - assertTrue("TGC enabled correctly", im.contains(Ac, RDFS.subClassOf, Cc)); + assertTrue(im.contains(Ac, RDFS.subClassOf, Cc), "TGC enabled correctly"); } /** * Test control of functor filtering */ + @Test public void testHybridFunctorFilter() { Graph data = createGraphForTest(); data.add(Triple.create(a, r, b)); @@ -313,13 +312,13 @@ public void testHybridFunctorFilter() { reasoner.setMode(GenericRuleReasoner.HYBRID); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, q, null), new Object[] { } ); reasoner.setFunctorFiltering(false); infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, q, null), new Object[] { Triple.create(a, q, Functor.makeFunctorNode("func", new Node[]{b, s})) } ); @@ -328,6 +327,7 @@ public void testHybridFunctorFilter() { /** * Test that functor filtering is honored in backward mode. */ + @Test public void testBackwardFunctorFilter() { Graph data = createGraphForTest(); data.add(Triple.create(a, r, b)); @@ -339,14 +339,14 @@ public void testBackwardFunctorFilter() { // Default: functors are filtered out InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, q, null), new Object[] { } ); // With filtering disabled: functor triples should be visible reasoner.setFunctorFiltering(false); infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(null, q, null), new Object[] { Triple.create(a, q, Functor.makeFunctorNode("func", new Node[]{b, s})) } ); @@ -356,6 +356,7 @@ public void testBackwardFunctorFilter() { * Test recursive rules involving functors * May lock up in there is a bug. */ + @Test public void testFunctorLooping() { doTestFunctorLooping(GenericRuleReasoner.FORWARD_RETE); doTestFunctorLooping(GenericRuleReasoner.HYBRID); @@ -376,12 +377,13 @@ public void doTestFunctorLooping(RuleMode mode) { InfGraph infgraph = reasoner.bind(data); // The p should have been asserted but is invisible - assertFalse( infgraph.contains(Node.ANY, p, Node.ANY) ); + assertFalse(infgraph.contains(Node.ANY, p, Node.ANY) ); } /** * Test the @prefix and @include extensions to the rule parser */ + @Test public void testExtendedRuleParser() { List rules = Rule.rulesFromURL("file:testing/reasoners/ruleParserTest1.rules"); GenericRuleReasoner reasoner = new GenericRuleReasoner(rules); @@ -398,22 +400,23 @@ public void testExtendedRuleParser() { Property p = m.getProperty(NS2 + "p"); Property a = m.getProperty(NS3 + "a"); Resource foo = m.getResource(NS1 + "foo"); - assertTrue("@prefix test", m.contains(A, p, foo)); + assertTrue(m.contains(A, p, foo), "@prefix test"); // Check RDFS rule inclusion - assertTrue("@include RDFS test", m.contains(A, RDFS.subClassOf, C)); - assertTrue("@include test", m.contains(a,a,a)); + assertTrue(m.contains(A, RDFS.subClassOf, C), "@include RDFS test"); + assertTrue(m.contains(a,a,a), "@include test"); } /** * Test that @include supports fileManger redirections */ + @Test public void testIncludeRedirect() { - assertFalse( checkIncludeFound("file:testing/reasoners/importTest.rules") ); + assertFalse(checkIncludeFound("file:testing/reasoners/importTest.rules") ); LocationMapper lm = FileManager.getInternal().getLocationMapper(); lm.addAltEntry("file:testing/reasoners/includeAlt.rules", "file:testing/reasoners/include.rules"); - assertTrue( checkIncludeFound("file:testing/reasoners/importTest.rules") ); + assertTrue(checkIncludeFound("file:testing/reasoners/importTest.rules") ); lm.removeAltEntry("file:testing/reasoners/includeAlt.rules"); } @@ -439,6 +442,7 @@ private boolean checkIncludeFound(String ruleSrc) { /** * Test add/remove support */ + @Test public void testAddRemove() { doTestAddRemove(false); doTestAddRemove(true); @@ -468,7 +472,7 @@ public void doTestAddRemove(boolean useTGC) { reasoner.setTransitiveClosureCaching(useTGC); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, ty, null), new Object[] { Triple.create(a, ty, C1), Triple.create(a, ty, C2), @@ -477,7 +481,7 @@ public void doTestAddRemove(boolean useTGC) { logger.debug("Checkpoint 1"); infgraph.delete(Triple.create(C1, sC, C2)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, ty, null), new Object[] { Triple.create(a, ty, C1) } ); @@ -485,18 +489,18 @@ public void doTestAddRemove(boolean useTGC) { logger.debug("Checkpoint 2"); infgraph.add(Triple.create(C1, sC, C3)); infgraph.add(Triple.create(b, p, C2)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, ty, null), new Object[] { Triple.create(a, ty, C1), Triple.create(a, ty, C3) } ); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(b, ty, null), new Object[] { Triple.create(b, ty, C2), Triple.create(b, ty, C3) } ); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( data.find(null, null, null), new Object[] { Triple.create(a, p, C1), Triple.create(b, p, C2), @@ -508,6 +512,7 @@ public void doTestAddRemove(boolean useTGC) { /** * Resolve a bug using remove in rules themselves. */ + @Test public void testAddRemove2() { Graph data = createGraphForTest(); data.add(Triple.create(a, p, Util.makeIntNode(0))); @@ -526,7 +531,7 @@ public void testAddRemove2() { reasoner.setMode(GenericRuleReasoner.FORWARD_RETE); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, p, null), new Object[] { Triple.create(a, p, Util.makeIntNode(2)) } ); diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestLPDerivation.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestLPDerivation.java index d9cc508123b..25e34364be6 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestLPDerivation.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestLPDerivation.java @@ -21,12 +21,14 @@ package org.apache.jena.reasoner.rulesys.test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.Arrays; import java.util.Iterator; import java.util.List; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.graph.*; import org.apache.jena.reasoner.Derivation; import org.apache.jena.reasoner.InfGraph; @@ -40,22 +42,16 @@ * Test the derivation tracing of the LP system. */ -public class TestLPDerivation extends TestCase { +public class TestLPDerivation { /** * Boilerplate for junit */ - public TestLPDerivation( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite( TestLPDerivation.class ); - } private static Graph createGraphForTest() { return GraphMemFactory.createDefaultGraph(); @@ -128,6 +124,7 @@ private void doTest(String ruleSrc, Node[] tabled, Triple[] triples, Triple quer /** * Test simple rule derivation. */ + @Test public void testBasic() { doTest( "(?x p ?y) <- (?x q ?y).", new Node[]{}, // Rules + tabling @@ -145,6 +142,7 @@ public void testBasic() { /** * Test simple rule derivation from pair */ + @Test public void testBasic2() { doTest( "(?x p ?y) <- (?x q ?y). (?x p ?y) <- (?x r ?y).", @@ -163,6 +161,7 @@ public void testBasic2() { /** * Test composite derivation. */ + @Test public void testComposite() { doTest( "(?x p ?y) <- (?x q ?y) (?x r ?y).", new Node[]{}, // Rules + tabling @@ -182,6 +181,7 @@ public void testComposite() { /** * Test Chain derivation. */ + @Test public void testChain() { doTest( "(?x s ?y) <- (?x r ?y). (?x p ?y) <- (?x q ?y) (?x s ?y). ", @@ -202,6 +202,7 @@ public void testChain() { /** * Test tabled chaining */ + @Test public void testTabled() { doTest( "(?x p ?z) <- (?x p ?y) (?y p ?z).", diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestOWLMisc.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestOWLMisc.java index 37e5d5c7b05..95947659a78 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestOWLMisc.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestOWLMisc.java @@ -21,8 +21,11 @@ package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import org.apache.jena.datatypes.RDFDatatype; import org.apache.jena.datatypes.xsd.XSDDatatype; import org.apache.jena.graph.Triple; @@ -53,24 +56,17 @@ * have arisen from bug reports or user questions. */ @SuppressWarnings("removal") -public class TestOWLMisc extends TestCase { +public class TestOWLMisc { /** * Boilerplate for junit */ - public TestOWLMisc( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite( TestOWLMisc.class ); - } - - @Override + @BeforeEach public void setUp() { // ensure the ont doc manager is in a consistent state OntDocumentManager.getInstance().reset( true ); @@ -79,6 +75,7 @@ public void setUp() { /** * Test sameAs/differentFrom interaction */ + @Test public void testSameAsDifferentFrom() { doTestSameAsDifferentFrom(OntModelSpec.OWL_MEM_MINI_RULE_INF); doTestSameAsDifferentFrom(OntModelSpec.OWL_MEM_RULE_INF); @@ -96,8 +93,8 @@ public void doTestSameAsDifferentFrom(OntModelSpec os) { Resource l4 = inf.getResource(NS + "limited4"); Resource l2 = inf.getResource(NS + "limited2"); Resource l3 = inf.getResource(NS + "limited3"); - assertTrue( inf.contains(l4, OWL.differentFrom, l2) ); - assertTrue( inf.contains(l4, OWL.differentFrom, l3) ); + assertTrue(inf.contains(l4, OWL.differentFrom, l2) ); + assertTrue(inf.contains(l4, OWL.differentFrom, l3) ); } private void doTestDatatypeRangeValidation(RDFDatatype over12Type, OntModelSpec spec) { @@ -124,6 +121,7 @@ private void doTestDatatypeRangeValidation(RDFDatatype over12Type, OntModelSpec /** * Test reported problem with OWL property axioms. */ + @Test public void testOWLPropertyAxioms() { Model data = ModelFactory.createDefaultModel(); Resource fp = data.createResource("urn:example:test/fp"); @@ -135,19 +133,20 @@ public void testOWLPropertyAxioms() { data.add(tp, RDF.type, OWL.TransitiveProperty); data.add(sp, RDF.type, OWL.SymmetricProperty); InfModel infmodel = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), data); - assertTrue("property class axioms", infmodel.contains(fp, RDF.type, RDF.Property)); - assertTrue("property class axioms", infmodel.contains(ifp, RDF.type, RDF.Property)); - assertTrue("property class axioms", infmodel.contains(tp, RDF.type, RDF.Property)); - assertTrue("property class axioms", infmodel.contains(sp, RDF.type, RDF.Property)); - assertTrue("property class axioms", infmodel.contains(ifp, RDF.type, OWL.ObjectProperty)); - assertTrue("property class axioms", infmodel.contains(tp, RDF.type, OWL.ObjectProperty)); - assertTrue("property class axioms", infmodel.contains(sp, RDF.type, OWL.ObjectProperty)); + assertTrue(infmodel.contains(fp, RDF.type, RDF.Property), "property class axioms"); + assertTrue(infmodel.contains(ifp, RDF.type, RDF.Property), "property class axioms"); + assertTrue(infmodel.contains(tp, RDF.type, RDF.Property), "property class axioms"); + assertTrue(infmodel.contains(sp, RDF.type, RDF.Property), "property class axioms"); + assertTrue(infmodel.contains(ifp, RDF.type, OWL.ObjectProperty), "property class axioms"); + assertTrue(infmodel.contains(tp, RDF.type, OWL.ObjectProperty), "property class axioms"); + assertTrue(infmodel.contains(sp, RDF.type, OWL.ObjectProperty), "property class axioms"); } /** * Test problems with inferring equivalence of some simple class definitions, * reported by Jeffrey Hau. */ + @Test public void testEquivalentClass1() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/equivalentClassTest.owl"); @@ -155,7 +154,7 @@ public void testEquivalentClass1() { String NAMESPACE = "urn:foo:abc#"; Resource A = test.getResource(NAMESPACE + "A"); Resource B = test.getResource(NAMESPACE + "B"); - assertTrue("hasValue equiv deduction", test.contains(A, OWL.equivalentClass, B)); + assertTrue(test.contains(A, OWL.equivalentClass, B), "hasValue equiv deduction"); } /** @@ -194,6 +193,7 @@ public void hiddenTestOWLLoop() { /** * Test bug with leaking variables which results in an incorrect "range = Nothing" deduction. */ + @Test public void testRangeBug() { Model model = FileManager.getInternal().loadModelInternal("file:testing/reasoners/bugs/rangeBug.owl"); // Model m = ModelFactory.createDefaultModel(); @@ -209,6 +209,7 @@ public void testRangeBug() { /** * Test change of RDF specs to allow plain literals w/o lang and XSD string to be the same. */ + @Test public void testLiteralBug() { Model model = FileManager.getInternal().loadModelInternal("file:testing/reasoners/bugs/dtValidation.owl"); // Model m = ModelFactory.createDefaultModel(); @@ -222,6 +223,7 @@ public void testLiteralBug() { * Report of problems with cardinality v. maxCardinality usage in classification, * from Hugh Winkler. */ + @Test public void testCardinality1() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/cardFPTest.owl"); @@ -229,7 +231,7 @@ public void testCardinality1() { String NAMESPACE = "urn:foo:abc#"; Resource aDocument = test.getResource(NAMESPACE + "aDocument"); Resource documentType = test.getResource(NAMESPACE + "Document"); - assertTrue("Cardinality-based classification", test.contains(aDocument, RDF.type, documentType)); + assertTrue(test.contains(aDocument, RDF.type, documentType), "Cardinality-based classification"); } public static final String NS = "http://jena.hpl.hp.com/example#"; diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFS9.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFS9.java index 157fc2a88b0..762a6d58280 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFS9.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFS9.java @@ -82,7 +82,7 @@ public void testRDFSInheritance() { Graph data = createGraphForTest(); data.add(Triple.create(a, p, b)); InfGraph igraph = ReasonerRegistry.getRDFSReasoner().bind(new Union(tdata, data)); - TestUtil.assertIteratorValues(this, igraph.find(a, ty, null), + TestUtil.assertIteratorValues( igraph.find(a, ty, null), new Object[] { Triple.create(a, ty, D), Triple.create(a, ty, RDFS.Resource.asNode()), @@ -99,7 +99,7 @@ public void testRDFSInheritance() { } assertTrue(ok); igraph = ReasonerRegistry.getRDFSReasoner().bindSchema(tdata).bind(data); - TestUtil.assertIteratorValues(this, igraph.find(a, ty, null), + TestUtil.assertIteratorValues( igraph.find(a, ty, null), new Object[] { Triple.create(a, ty, D), Triple.create(a, ty, RDFS.Resource.asNode()), diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRETE.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRETE.java index 7dc73db9da0..95a45c15f51 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRETE.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRETE.java @@ -21,17 +21,19 @@ package org.apache.jena.reasoner.rulesys.test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.*; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.graph.*; import org.apache.jena.reasoner.*; import org.apache.jena.reasoner.rulesys.*; import org.apache.jena.reasoner.rulesys.impl.*; import org.apache.jena.reasoner.test.TestUtil; -public class TestRETE extends TestCase { +public class TestRETE { // Useful constants Node_RuleVariable x = new Node_RuleVariable("x", 0); @@ -55,20 +57,11 @@ public class TestRETE extends TestCase { /** * Boilerplate for junit */ - public TestRETE( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite( TestRETE.class ); -// TestSuite suite = new TestSuite(); -// suite.addTest(new TestRETE( "foo" )); -// return suite; - } private static Graph createGraphForTest() { return GraphMemFactory.createDefaultGraph(); @@ -77,6 +70,7 @@ private static Graph createGraphForTest() { /** * Test clause compiler and clause filter implementation. */ + @Test public void testClauseFilter() { doTestClauseFilter( new TriplePattern(a, p, x), Triple.create(a, p, b), new Node[]{b, null, null}); @@ -171,6 +165,7 @@ public RETENode clone(Map netCopy, RETERuleContext context) /** * Minimal rule tester to check basic pattern match. */ + @Test public void testRuleMatcher() { doRuleTest( "[r1: (?a p ?b), (?b q ?c) -> (?a, q, ?c)]" + "[r2: (?a p ?b), (?b p ?c) -> (?a, p, ?c)]" + @@ -246,13 +241,14 @@ private void doRuleTest(String rules, Triple[] adds, Triple[] expected) { engine.addTriple( add, true ); } engine.runAll(); - TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), expected); + TestUtil.assertIteratorValues( infgraph.find(null, null, null), expected); } /** * Check that the rulestate cloning keeps two descendent graphs independent. * */ + @Test public void testRuleClone() { String rules = "[testRule1: (a p ?x) (b p ?x) -> (n1 p ?x) ]" + "[testRule2: (?x q ?y) -> (?x p ?y)]"; @@ -273,7 +269,7 @@ public void testRuleClone() { InfGraph infgraph1 = boundReasoner.bind(data1); InfGraph infgraph2 = boundReasoner.bind(data2); - TestUtil.assertIteratorValues(this, infgraph1.find(null, p, null), + TestUtil.assertIteratorValues( infgraph1.find(null, p, null), new Triple[] { Triple.create(a, p, c), Triple.create(a, p, d), @@ -281,7 +277,7 @@ public void testRuleClone() { Triple.create(n1, p, c) }); - TestUtil.assertIteratorValues(this, infgraph2.find(null, p, null), + TestUtil.assertIteratorValues( infgraph2.find(null, p, null), new Triple[] { Triple.create(a, p, c), Triple.create(a, p, d), diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRestrictionsDontNeedTyping.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRestrictionsDontNeedTyping.java index 9e2fbbf5db6..a0d90c8ded7 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRestrictionsDontNeedTyping.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRestrictionsDontNeedTyping.java @@ -21,8 +21,10 @@ package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModelSpec; import org.apache.jena.rdf.model.Model; @@ -38,24 +40,19 @@ explicit type (ie we're not caught in a forward rule -> backward rule layering problem). */ @SuppressWarnings("removal") -public class TestRestrictionsDontNeedTyping extends TestCase - { - - public static TestSuite suite() { - return new TestSuite( TestRestrictionsDontNeedTyping.class ); - } +public class TestRestrictionsDontNeedTyping { static final Property ANY = null; - public TestRestrictionsDontNeedTyping( String name ) - { super( name ); } - + @Test public void testAllValuesFromFullRules() { testAllValuesFrom( OntModelSpec.OWL_MEM_RULE_INF ); } + @Test public void testAllValuesFromMiniRules() { testAllValuesFrom( OntModelSpec.OWL_MEM_MINI_RULE_INF ); } + @Test public void testAllValuesFromMicroRules() { /* micro doesn't support this anyway */ @@ -66,15 +63,18 @@ private void testAllValuesFrom( OntModelSpec owlSpec ) { Model m = model( "V owl:equivalentClass _R; _R owl:onProperty P; _R owl:allValuesFrom T; X rdf:type V; X P t" ); OntModel ont = ModelFactory.createOntologyModel( owlSpec, m ); - assertTrue( ont.contains( ModelTestLib.resource( "t" ), RDF.type, ModelTestLib.resource( "T" ) ) ); + assertTrue(ont.contains( ModelTestLib.resource( "t" ), RDF.type, ModelTestLib.resource( "T" ) ) ); } + @Test public void testSomeValuesFromMiniRules() { testSomeValuesFrom( OntModelSpec.OWL_MEM_MINI_RULE_INF ); } + @Test public void testSomeValuesFromMicroRules() { testSomeValuesFrom( OntModelSpec.OWL_MEM_MICRO_RULE_INF ); } + @Test public void testSomeValuesFromFullRules() { testSomeValuesFrom( OntModelSpec.OWL_MEM_RULE_INF ); } @@ -82,9 +82,10 @@ private void testSomeValuesFrom( OntModelSpec owlSpec ) { Model m = model( "V owl:equivalentClass _R; _R owl:onProperty P; _R owl:someValuesFrom T; X P t; t rdf:type T" ); OntModel ont = ModelFactory.createOntologyModel( owlSpec, m ); - assertTrue( ont.contains( ModelTestLib.resource( "X" ), RDF.type, ModelTestLib.resource( "V" ) ) ); + assertTrue(ont.contains( ModelTestLib.resource( "X" ), RDF.type, ModelTestLib.resource( "V" ) ) ); } + @Test public void testCardinalityFullRules() { testCardinality( OntModelSpec.OWL_MEM_RULE_INF ); } @@ -98,7 +99,7 @@ private void testCardinality( OntModelSpec owlSpec ) { Model m = model( "V owl:equivalentClass _R; _R rdf:type owl:Restriction; _R owl:onProperty P; _R owl:cardinality 1; X rdf:type V" ); OntModel ont = ModelFactory.createOntologyModel( owlSpec, m ); - assertEquals( 1, ont.listStatements( ModelTestLib.resource( "X" ), ModelTestLib.property( "P" ), ANY ).toList().size() ); + assertEquals(1, ont.listStatements( ModelTestLib.resource( "X" ), ModelTestLib.property( "P" ), ANY ).toList().size() ); } Model model( String statements ) diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRuleSystemBugs.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRuleSystemBugs.java index c6a8483d662..d7acc8bf92d 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRuleSystemBugs.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRuleSystemBugs.java @@ -21,8 +21,11 @@ package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.Node; import org.apache.jena.graph.NodeFactory; import org.apache.jena.graph.Triple; @@ -85,32 +88,21 @@ import java.util.List; import java.util.Set; - /** * Unit tests for reported bugs in the rule system. */ @SuppressWarnings("removal") -public class TestRuleSystemBugs extends TestCase { +public class TestRuleSystemBugs { /** * Boilerplate for junit */ - public TestRuleSystemBugs( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite( TestRuleSystemBugs.class ); -// TestSuite suite = new TestSuite(); -// suite.addTest(new TestBugs( "testLayeredValidation" )); -// return suite; - } - - @Override + @BeforeEach public void setUp() { // ensure the ont doc manager is in a consistent state OntDocumentManager.getInstance().reset( true ); @@ -120,6 +112,7 @@ public void setUp() { * Report of NPE during processing on an ontology with a faulty intersection list, * from Hugh Winkler. */ + @Test public void testIntersectionNPE() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/bad-intersection.owl"); @@ -131,13 +124,14 @@ public void testIntersectionNPE() { } catch (ReasonerException e) { foundBadList = true; } - assertTrue("Correctly detected the illegal list", foundBadList); + assertTrue(foundBadList, "Correctly detected the illegal list"); } /** * Report of functor literals leaking out of inference graphs and raising CCE * in iterators. */ + @Test public void testFunctorCCE() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/cceTest.owl"); @@ -216,6 +210,7 @@ private boolean anyInstancesOfNothing(Model model) { /** * Test for a reported bug in delete */ + @Test public void testDeleteBug() { Model modelo = ModelFactory.createDefaultModel(); modelo.read("file:testing/reasoners/bugs/deleteBug.owl"); @@ -231,6 +226,7 @@ public void testDeleteBug() { /** * Test bug caused by caching of deductions models. */ + @Test public void testDeteleBug2() { Model m = ModelFactory.createDefaultModel(); String NS = PrintUtil.egNS; @@ -252,13 +248,14 @@ public void testDeteleBug2() { /** * Test that prototype nodes are now hidden */ + @Test public void testHide() { String NS = "http://jena.hpl.hp.com/bugs#"; OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null); OntClass c = m.createClass(NS + "C"); OntResource i = m.createIndividual(c); Iterator res = m.listStatements(null, RDF.type, c); - TestUtil.assertIteratorValues(this, res, new Statement[] { + TestUtil.assertIteratorValues( res, new Statement[] { m.createStatement(i, RDF.type, c) }); } @@ -266,6 +263,7 @@ public void testHide() { /** * Also want to have hidden rb:xsdRange */ + @Test public void testHideXSDRange() { OntModelSpec[] specs = new OntModelSpec[] { OntModelSpec.OWL_MEM_RULE_INF, @@ -280,7 +278,7 @@ public void testHideXSDRange() { while (i.hasNext()) { Resource r = i.next(); if (r.getURI() != null && r.getURI().startsWith(ReasonerVocabulary.RBNamespace)) { - assertTrue("Rubrik internal property leaked out: " + r + "(" + os + ")", false); + assertTrue(false, "Rubrik internal property leaked out: " + r + "(" + os + ")"); } } } @@ -289,6 +287,7 @@ public void testHideXSDRange() { /** * Test problem with bindSchema not interacting properly with validation. */ + @Test public void testBindSchemaValidate() { Reasoner reasoner = ReasonerRegistry.getOWLReasoner(); Model schema = FileManager.getInternal().loadModelInternal("file:testing/reasoners/bugs/sbug.owl"); @@ -297,7 +296,7 @@ public void testBindSchemaValidate() { // Union version InfModel infu = ModelFactory.createInfModel(reasoner, data.union(schema)); ValidityReport validity = infu.validate(); - assertTrue( ! validity.isValid()); + assertTrue(! validity.isValid()); // debug print // for (Iterator i = validity.getReports(); i.hasNext(); ) { // System.out.println(" - " + i.next()); @@ -306,12 +305,13 @@ public void testBindSchemaValidate() { // bindSchema version InfModel inf = ModelFactory.createInfModel(reasoner.bindSchema(schema), data); validity = inf.validate(); - assertTrue( ! validity.isValid()); + assertTrue(! validity.isValid()); } /** * Delete bug in generic rule reasoner. */ + @Test public void testGenericDeleteBug() { Model data = ModelFactory.createDefaultModel(); String NS = "urn:example:test:"; @@ -334,6 +334,7 @@ public void testGenericDeleteBug() { /** * RETE incremental processing bug. */ + @Test public void testRETEInc() { String rule = "(?x ?p ?y) -> (?p rdf:type rdf:Property) ."; Reasoner r = new GenericRuleReasoner(Rule.parseRules(rule)); @@ -354,6 +355,7 @@ public void testRETEInc() { /** * RETE incremental processing bug. */ + @Test public void testRETEDec() { String rule = "(?x ?p ?y) -> (?p rdf:type rdf:Property) ."; Reasoner r = new GenericRuleReasoner(Rule.parseRules(rule)); @@ -375,10 +377,10 @@ private void assertIsProperty(Model m, Property prop) { assertTrue(m.contains(prop, RDF.type, RDF.Property)); } - /** * Bug that exposed prototypes of owl:Thing despite hiding being switched on. */ + @Test public void testHideOnOWLThing() { Reasoner r = ReasonerRegistry.getOWLReasoner(); Model data = ModelFactory.createDefaultModel(); @@ -423,6 +425,7 @@ public void xxtest_oh_01() { } /** Problem with bindSchema and validation rules */ + @Test public void test_der_validation() { Model abox = FileManager.getInternal().loadModelInternal("file:testing/reasoners/owl/nondetbug.rdf"); List rules = FBRuleReasoner.loadRules("testing/reasoners/owl/nondetbug.rules"); @@ -430,7 +433,7 @@ public void test_der_validation() { // r.setTraceOn(true); for (int i = 0; i < 10; i++) { InfModel im = ModelFactory.createInfModel(r, abox); - assertTrue("failed on count " + i, im.contains(null, ReasonerVocabulary.RB_VALIDATION_REPORT, (RDFNode)null)); + assertTrue(im.contains(null, ReasonerVocabulary.RB_VALIDATION_REPORT, (RDFNode)null), "failed on count " + i); } } @@ -486,12 +489,13 @@ private void test_oh_01scan( OntModelSpec s, String prompt, Resource[] expected } } - assertEquals( "Some expected results were not seen", 0, mask ); + assertEquals(0, mask, "Some expected results were not seen"); } /** * Bug report from David A Bigwood */ + @Test public void test_domainInf() { // create an OntModel OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null ); @@ -505,16 +509,16 @@ public void test_domainInf() { UnionClass uc = m.createUnionClass(null, null); // add an operand uc.addOperand( c1 ); - assertEquals( "Size should be 1", 1, uc.getOperands().size() ); - assertTrue( "uc should have c1 as union member", uc.getOperands().contains( c1 ) ); + assertEquals(1, uc.getOperands().size(), "Size should be 1"); + assertTrue(uc.getOperands().contains( c1 ), "uc should have c1 as union member"); // add another operand uc.addOperand( c2 ); - assertEquals( "Size should be 2", 2, uc.getOperands().size() ); - TestUtil.assertIteratorValues(this, uc.listOperands(), new Object[] { c1, c2 } ); + assertEquals(2, uc.getOperands().size(), "Size should be 2"); + TestUtil.assertIteratorValues( uc.listOperands(), new Object[] { c1, c2 } ); // add a third operand uc.addOperand( c3 ); - assertEquals( "Size should be 3", 3, uc.getOperands().size() ); - TestUtil.assertIteratorValues(this, uc.listOperands(), new Object[] { c1, c2, c3} ); + assertEquals(3, uc.getOperands().size(), "Size should be 3"); + TestUtil.assertIteratorValues( uc.listOperands(), new Object[] { c1, c2, c3} ); // add union class as domain of a property p1.addDomain(uc); } @@ -522,6 +526,7 @@ public void test_domainInf() { /** * Bug report on bad conflict resolution between two non-monotonic rules. */ + @Test public void testNonmonotonicCR() { String ruleSrc = "(eg:IndA eg:scoreA ?score), sum(?score 40 ?total), noValue(eg:IndA eg:flag_1 'true') -> drop(0), (eg:IndA eg:scoreA ?total), (eg:IndA eg:flag_1 'true')." + "(eg:IndA eg:scoreA ?score), sum(?score 33 ?total), noValue(eg:IndA eg:flag_2 'true') -> drop(0), (eg:IndA eg:scoreA ?total), (eg:IndA eg:flag_2 'true')."; @@ -534,12 +539,13 @@ public void testNonmonotonicCR() { GenericRuleReasoner reasoner = new GenericRuleReasoner(rules); InfModel inf = ModelFactory.createInfModel(reasoner, data); Iterator values = inf.listObjectsOfProperty(i, scoreA); - TestUtil.assertIteratorValues(this, values, new Object[] { data.createTypedLiteral(173)}); + TestUtil.assertIteratorValues( values, new Object[] { data.createTypedLiteral(173)}); } /** * Bug report - intersection processing does not work incrementally. */ + @Test public void testIncrementalIU() { OntModel ontmodel = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MINI_RULE_INF ); @@ -564,13 +570,14 @@ public void testIncrementalIU() { // Works with rebind, bug is that it doesn't work without rebind // ontmodel.rebind(); - TestUtil.assertIteratorValues(this, classI.listInstances(), subind); - TestUtil.assertIteratorValues(this, classU.listInstances(), ind); + TestUtil.assertIteratorValues( classI.listInstances(), subind); + TestUtil.assertIteratorValues( classU.listInstances(), ind); } /** * Fact rules with non-empty bodyies failed to fire. */ + @Test public void testFactRules() { Model facts = ModelFactory.createDefaultModel(); String NS = PrintUtil.egNS; @@ -591,6 +598,7 @@ public void testFactRules() { * Test chainging rules from axioms which broke while trying to * fix about test case. */ + @Test public void testFactChainRules() { Model facts = ModelFactory.createDefaultModel(); String NS = PrintUtil.egNS; @@ -606,7 +614,7 @@ public void testFactChainRules() { reasoner.setTransitiveClosureCaching(true); InfModel inf = ModelFactory.createInfModel(reasoner, facts); Property egRange = inf.createProperty(NS + "range"); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( inf.listStatements(null, egRange, (RDFNode)null), new Object[] {inf.createStatement(mother, egRange, female)} ); } @@ -614,6 +622,7 @@ public void testFactChainRules() { /** * test remove operator in case with empty data. */ + @Test public void testEmptyRemove() { List rules = Rule.parseRules( "-> (eg:i eg:prop eg:foo) ." + @@ -623,13 +632,14 @@ public void testEmptyRemove() { InfModel im = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel()); Resource i = im.createResource(PrintUtil.egNS + "i"); Property guard = im.createProperty(PrintUtil.egNS + "guard"); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( im.listStatements(), new Object[] {im.createStatement(i, guard, "done")}); } /** * test duplicate removal when using pure backward rules */ + @Test public void testBackwardDupRemoval() { String NS = PrintUtil.egNS; Model base = ModelFactory.createDefaultModel(); @@ -651,6 +661,7 @@ public void testBackwardDupRemoval() { /** * Test closure of grounded choice points */ + @Test public void testGroundClosure() { Flag myFlag = new Flag(); BuiltinRegistry.theRegistry.register(myFlag); @@ -668,13 +679,14 @@ public void testGroundClosure() { m.add(a, p, a); GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules)); InfModel infModel = ModelFactory.createInfModel(reasoner, m); - assertTrue( infModel.contains(a, q, b) ); - assertTrue( ! myFlag.fired ); + assertTrue(infModel.contains(a, q, b) ); + assertTrue(! myFlag.fired ); } /** * Test closure of grounded choice points */ + @Test public void testGroundClosure2() { Flag myFlag = new Flag(); BuiltinRegistry.theRegistry.register(myFlag); @@ -687,12 +699,13 @@ public void testGroundClosure2() { Resource Paul = inf.getResource(NS + "Paul"); Property parent = inf.getProperty(NS + "parent"); assertTrue ( inf.contains(Paul, parent, Phil) ); - assertTrue( ! myFlag.fired ); + assertTrue(! myFlag.fired ); } /** * Test case for a reported CME bug in the transitive reasoner */ + @Test public void testCMEInTrans() { OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_TRANS_INF); @@ -702,6 +715,7 @@ public void testCMEInTrans() { /** * Test case for reported problem in detecting cardinality violations */ + @Test public void testIndCardValidation() { final String NS = "http://dummy#"; @@ -742,6 +756,7 @@ public void testIndCardValidation() { /** * Listeners on deductions graph should be preserved across rebind operations */ + @Test public void testDeductionListener() { final String NS = PrintUtil.egNS; @@ -794,6 +809,7 @@ public void addedStatement( Statement s ) { /** * Problems with getDeductionsModel not rerunning prepare at OntModel level */ + @Test public void testOntModelGetDeductions() { List rules = Rule.parseRules( "(?x rdfs:subClassOf ?y) (?i rdf:type ?x) -> (?i rdf:type ?y)." ); GenericRuleReasoner reasoner = new GenericRuleReasoner(rules); @@ -808,7 +824,7 @@ public void testOntModelGetDeductions() { Model deductions = om.getDeductionsModel(); i.removeRDFType(A); deductions = om.getDeductionsModel(); - assertFalse("Deductions model updating correctly", deductions.contains(i, RDF.type, B)); + assertFalse(deductions.contains(i, RDF.type, B), "Deductions model updating correctly"); } /** @@ -829,16 +845,17 @@ public boolean bodyCall(Node[] args, int length, RuleContext context) { /** * Check ability to report literals as well as resources as culprits */ + @Test public void testLiteralsInErrorReports() { RDFNode culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 42). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?X)."); - assertEquals( culprit, ResourceFactory.createTypedLiteral( Integer.valueOf(42) )); + assertEquals(culprit, ResourceFactory.createTypedLiteral( Integer.valueOf(42) )); culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 'foo'). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?X)."); - assertEquals( culprit, ResourceFactory.createPlainLiteral("foo")); + assertEquals(culprit, ResourceFactory.createPlainLiteral("foo")); BuiltinRegistry.theRegistry.register( new SomeTriple() ); culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 42). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?Y), someTriple(?X)."); - assertTrue( culprit.isLiteral() ); + assertTrue(culprit.isLiteral() ); Object val = ((Literal)culprit).getValue(); - assertTrue( val instanceof Triple); + assertTrue(val instanceof Triple); } private RDFNode doTestLiteralsInErrorReports(String rules) { @@ -847,7 +864,7 @@ private RDFNode doTestLiteralsInErrorReports(String rules) { ValidityReport validity = im.validate(); assertTrue (! validity.isValid()); ValidityReport.Report report = (validity.getReports().next()); - assertTrue( report.getExtension() instanceof RDFNode); + assertTrue(report.getExtension() instanceof RDFNode); return (RDFNode)report.getExtension(); } @@ -877,6 +894,7 @@ public boolean bodyCall(Node[] args, int length, RuleContext context) { * Arguably this should be moved to ../test/TestRDFSReasoners but that requires more * fiddling with manifest files and declarative test specifications */ + @Test public void testRDFSSimple() { doTestRDFSSimple(ReasonerVocabulary.RDFS_DEFAULT); doTestRDFSSimple(ReasonerVocabulary.RDFS_SIMPLE); @@ -891,14 +909,14 @@ private void doTestRDFSSimple(String level) { Reasoner reasoner = RDFSRuleReasonerFactory.theInstance().create(null); reasoner.setParameter(ReasonerVocabulary.PROPsetRDFSLevel, level); InfModel im = ModelFactory.createInfModel(reasoner, model); - assertTrue( im.contains(prop, RDFS.subPropertyOf, prop) ); + assertTrue(im.contains(prop, RDFS.subPropertyOf, prop) ); } - /** * Layering one reasoner on another leads to exposed functors which * used to trip up validation */ + @Test public void testLayeredValidation() { Model ont = FileManager.getInternal().loadModelInternal("testing/reasoners/bugs/layeredValidation.owl"); InfModel infModel = @@ -921,19 +939,19 @@ public void testLayeredValidation() { * Potential problem in handling of maxCardinality(0) assertions in the * presence of disjointness. */ + @Test public void testMaxCard2() { doTestmaxCard2(OntModelSpec.OWL_MEM_MINI_RULE_INF); doTestmaxCard2(OntModelSpec.OWL_MEM_RULE_INF); } - private void doTestmaxCard2(OntModelSpec spec) { String NS = "http://jena.hpl.hp.com/eg#"; Model base = FileManager.getInternal().loadModelInternal("testing/reasoners/bugs/terrorism.owl"); OntModel model = ModelFactory.createOntologyModel(spec, base); OntClass event = model.getOntClass(NS + "Event"); List subclasses = event.listSubClasses().toList(); - assertFalse( subclasses.contains( OWL.Nothing ) ); + assertFalse(subclasses.contains( OWL.Nothing ) ); assertEquals(3, subclasses.size()); } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestSetRules.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestSetRules.java index 1eb2930c8e1..236874958e8 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestSetRules.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestSetRules.java @@ -21,10 +21,12 @@ package org.apache.jena.reasoner.rulesys.test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.*; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.rdf.model.*; import org.apache.jena.reasoner.*; import org.apache.jena.reasoner.rulesys.*; @@ -33,25 +35,19 @@ /** TestSetRules - tests to bring setRules into existence on RuleReasonerFactory. */ -public class TestSetRules extends TestCase - { - - public TestSetRules( String name ) - { super( name ); } - - public static TestSuite suite() - { return new TestSuite( TestSetRules.class ); } +public class TestSetRules { static final List rules = Rule.parseRules( "[name: (?s owl:foo ?p) -> (?s ?p ?a)]" ); + @Test public void testRuleReasonerWrapper() { MockFactory mock = new MockFactory(); ReasonerFactory wrapped = wrap( mock ); - assertEquals( MockFactory.capabilities, wrapped.getCapabilities() ); - assertEquals( MockFactory.uri, wrapped.getURI() ); - assertEquals( MockFactory.reasoner, wrapped.create( null ) ); - assertEquals( Arrays.asList( new Object[] {"capabilities", "uri", "create"} ), mock.done ); + assertEquals(MockFactory.capabilities, wrapped.getCapabilities() ); + assertEquals(MockFactory.uri, wrapped.getURI() ); + assertEquals(MockFactory.reasoner, wrapped.create( null ) ); + assertEquals(Arrays.asList( new Object[] {"capabilities", "uri", "create"} ), mock.done ); } private static class MockFactory implements ReasonerFactory @@ -62,7 +58,7 @@ private static class MockFactory implements ReasonerFactory static final Reasoner reasoner = new GenericRuleReasoner( rules ); public void addRules( List rules ) - { assertEquals( TestSetRules.rules, rules ); + { assertEquals(TestSetRules.rules, rules ); done.add( "addRules" ); } @Override diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestTrialOWLRules.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestTrialOWLRules.java index c062976e6f7..8bf0452b281 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestTrialOWLRules.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestTrialOWLRules.java @@ -21,6 +21,8 @@ package org.apache.jena.reasoner.rulesys.test; +import junit.framework.TestCase; + import junit.framework.*; import java.io.IOException; diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/AbstractTestGraph.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/AbstractTestGraph.java index 934122bd6b5..3b85951d141 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/AbstractTestGraph.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/AbstractTestGraph.java @@ -21,10 +21,6 @@ package org.apache.jena.reasoner.test; -import java.io.InputStream; -import java.util.*; - -import junit.framework.TestCase; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphEventManager; import org.apache.jena.graph.GraphEvents; @@ -34,8 +30,17 @@ import org.apache.jena.graph.GraphUtil; import org.apache.jena.graph.Node; import org.apache.jena.graph.RecordingListener; -import org.apache.jena.graph.Triple; import org.apache.jena.graph.TransactionHandler; +import org.apache.jena.graph.Triple; + +import static org.junit.jupiter.api.Assertions.*; + +import java.io.InputStream; +import java.util.*; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import org.apache.jena.junit.NodeCreateUtils; import org.apache.jena.memvalue.TrackingTripleIterator; import org.apache.jena.rdf.model.Model; @@ -48,17 +53,10 @@ import org.apache.jena.util.iterator.ExtendedIterator; /** - * A copy of {@code org.apache.jena.graph.AbstractTestGraph}, kept package-scope here so - * that {@link TestInfGraph} does not hold the JUnit 3 original in place. - *

- * AbstractTestGraph provides a bunch of basic tests for something that purports to - * be a Graph. The abstract method getGraph must be overridden in subclasses to - * deliver a Graph of interest. + * A copy of {@code org.apache.jena.graph.AbstractTestGraph}, kept package-scope here so that + * {@link TestInfGraph} does not depend on the graph test package. */ -abstract class AbstractTestGraph extends TestCase { - public AbstractTestGraph(String name) { - super(name); - } +abstract class AbstractTestGraph { /** * Returns a Graph to take part in the test. Must be overridden in a subclass. @@ -71,13 +69,15 @@ public Graph getGraphWith(String facts) { return g; } + @Test public void testCloseSetsIsClosed() { Graph g = getNewGraph(); - assertFalse("unclosed Graph shouild not be isClosed()", g.isClosed()); + Assertions.assertFalse(g.isClosed(), "unclosed Graph should not be isClosed()"); g.close(); - assertTrue("closed Graph should be isClosed()", g.isClosed()); + Assertions.assertTrue(g.isClosed(), "closed Graph should be isClosed()"); } + @Test public void testFindAndContains() { Graph g = getNewGraph(); Node r = NodeCreateUtils.create("r"), s = NodeCreateUtils.create("s"), p = NodeCreateUtils.create("P"); @@ -86,6 +86,7 @@ public void testFindAndContains() { assertEquals(1, g.find(r, p, Node.ANY).toList().size()); } + @Test public void testRepeatedSubjectDoesNotConceal() { Graph g = getGraphWith("s P o; s Q r"); assertTrue(g.contains(GraphTestLib.triple("s P o"))); @@ -96,6 +97,7 @@ public void testRepeatedSubjectDoesNotConceal() { assertTrue(g.contains(GraphTestLib.triple("?? Q ??"))); } + @Test public void testFindByFluidTriple() { Graph g = getGraphWith("x y z "); Set expect = GraphTestLib.tripleSet("x y z"); @@ -104,6 +106,7 @@ public void testFindByFluidTriple() { assertEquals(expect, g.find(GraphTestLib.triple("x y ??")).toSet()); } + @Test public void testContainsConcrete() { Graph g = getGraphWith("s P o; _x _R _y; x S 0"); assertTrue(g.contains(GraphTestLib.triple("s P o"))); @@ -117,6 +120,7 @@ public void testContainsConcrete() { assertFalse(g.contains(GraphTestLib.triple("x S 1"))); } + @Test public void testContainsFluid() { Graph g = getGraphWith("x R y; a P b"); assertTrue(g.contains(GraphTestLib.triple("?? R y"))); @@ -135,6 +139,7 @@ public void testContainsFluid() { assertFalse(g.contains(GraphTestLib.triple("a S ??"))); } + @Test public void testMatchLanguagedLiteralCaseInsensitive() { Graph m = GraphTestLib.graphWith("a p 'chat'en"); Node chaten = GraphTestLib.node("'chat'en"), chatEN = GraphTestLib.node("'chat'EN"); @@ -147,6 +152,7 @@ public void testMatchLanguagedLiteralCaseInsensitive() { assertEquals(1, m.find(Node.ANY, Node.ANY, chatEN).toList().size()); } + @Test public void testMatchBothLanguagedLiteralsCaseInsensitive() { Graph m = GraphTestLib.graphWith("a p 'chat'en; a p 'chat'EN"); Node chaten = GraphTestLib.node("'chat'en"), chatEN = GraphTestLib.node("'chat'EN"); @@ -163,9 +169,10 @@ public void testMatchBothLanguagedLiteralsCaseInsensitive() { /** * test isEmpty - moved from the QueryHandler code. */ + @Test public void testIsEmpty() { Graph g = getNewGraph(); - if ( canBeEmpty(g) ) { + if (canBeEmpty(g)) { assertTrue(g.isEmpty()); g.add(NodeCreateUtils.createTriple("S P O")); assertFalse(g.isEmpty()); @@ -180,6 +187,7 @@ public void testIsEmpty() { } } + @Test public void testAGraph() { String title = this.getClass().getName(); Graph g = getNewGraph(); @@ -187,19 +195,19 @@ public void testAGraph() { GraphTestLib.graphAdd(g, "x R y; p S q; a T b"); /* */ GraphTestLib.assertContainsAll(title + ": simple graph", g, "x R y; p S q; a T b"); - assertEquals(title + ": size", baseSize + 3, g.size()); + Assertions.assertEquals(baseSize + 3, g.size(), title + ": size"); GraphTestLib.graphAdd(g, "spindizzies lift cities; Diracs communicate instantaneously"); - assertEquals(title + ": size after adding", baseSize + 5, g.size()); + Assertions.assertEquals(baseSize + 5, g.size(), title + ": size after adding"); g.delete(GraphTestLib.triple("x R y")); g.delete(GraphTestLib.triple("a T b")); - assertEquals(title + ": size after deleting", baseSize + 3, g.size()); + Assertions.assertEquals(baseSize + 3, g.size(), title + ": size after deleting"); GraphTestLib.assertContainsAll(title + ": modified simple graph", g, "p S q; spindizzies lift cities; Diracs communicate instantaneously"); GraphTestLib.assertOmitsAll(title + ": modified simple graph", g, "x R y; a T b"); /* */ ClosableIterator it = g.find(Node.ANY, GraphTestLib.node("lift"), Node.ANY); - assertTrue(title + ": finds some triple(s)", it.hasNext()); - assertEquals(title + ": finds a 'lift' triple", GraphTestLib.triple("spindizzies lift cities"), it.next()); - assertFalse(title + ": finds exactly one triple", it.hasNext()); + Assertions.assertTrue(it.hasNext(), title + ": finds some triple(s)"); + Assertions.assertEquals(GraphTestLib.triple("spindizzies lift cities"), it.next(), title + ": finds a 'lift' triple"); + Assertions.assertFalse(it.hasNext(), title + ": finds exactly one triple"); it.close(); } @@ -207,25 +215,32 @@ public void testAGraph() { * Test that Graphs have transaction support methods, and that if they fail on * some g they fail because they do not support the operation. */ + @Test public void testHasTransactions() { Graph g = getNewGraph(); TransactionHandler th = g.getTransactionHandler(); th.transactionsSupported(); try { th.begin(); - } catch (UnsupportedOperationException x) {} + } catch (UnsupportedOperationException x) { + } try { th.abort(); - } catch (UnsupportedOperationException x) {} + } catch (UnsupportedOperationException x) { + } try { th.begin(); th.commit(); - } catch (UnsupportedOperationException x) {} + } catch (UnsupportedOperationException x) { + } try { - th.execute(() -> {}); - } catch (UnsupportedOperationException x) {} + th.execute(() -> { + }); + } catch (UnsupportedOperationException x) { + } } + @Test public void testExecuteInTransactionCatchesThrowable() { Graph g = getNewGraph(); TransactionHandler th = g.getTransactionHandler(); @@ -233,9 +248,11 @@ public void testExecuteInTransactionCatchesThrowable() { th.executeAlways(() -> { throw new Error(); }); - } catch (JenaException x) {} + } catch (JenaException x) { + } } + @Test public void testCalculateInTransactionCatchesThrowable() { Graph g = getNewGraph(); TransactionHandler th = g.getTransactionHandler(); @@ -243,7 +260,8 @@ public void testCalculateInTransactionCatchesThrowable() { th.calculateAlways(() -> { throw new Error(); }); - } catch (JenaException x) {} + } catch (JenaException x) { + } } static final Triple[] tripleArray = GraphTestLib.tripleArray("S P O; A R B; X Q Y"); @@ -254,6 +272,7 @@ public void testCalculateInTransactionCatchesThrowable() { static final Set tripleSet = CollectionFactory.createHashedSet(Arrays.asList(setTriples)); + @Test public void testBulkUpdate() { Graph g = getNewGraph(); Graph items = GraphTestLib.graphWith("pigs might fly; dead can dance"); @@ -297,9 +316,10 @@ public void testBulkUpdate() { GraphTestLib.testOmits(g, items); /* */ GraphUtil.delete(g, tripleList); - assertEquals("graph has original size", initialSize, g.size()); + Assertions.assertEquals(initialSize, g.size(), "graph has original size"); } + @Test public void testAddWithReificationPreamble() { Graph g = getNewGraph(); xSPO(g); @@ -319,6 +339,7 @@ protected void xSPO(Graph g) { ReifierStd.reifyAs(g, NodeCreateUtils.create("x"), NodeCreateUtils.createTriple("S P O")); } + @Test public void testRemove() { testRemove("?? ?? ??", "?? ?? ??"); testRemove("S ?? ??", "S ?? ??"); @@ -339,7 +360,7 @@ public void testRemove(String findRemove, String findCheck) { it.next(); it.remove(); it.close(); - assertEquals("remove with " + findRemove + ":", 0, g.size()); + Assertions.assertEquals(0, g.size(), "remove with " + findRemove + ":"); assertFalse(g.contains(NodeCreateUtils.createTriple(findCheck))); } catch (UnsupportedOperationException e) { // No iterator remove. @@ -347,6 +368,7 @@ public void testRemove(String findRemove, String findCheck) { } } + @Test public void testFind() { Graph g = getNewGraph(); GraphTestLib.graphAdd(g, "S P O"); @@ -358,6 +380,7 @@ protected boolean canBeEmpty(Graph g) { return g.isEmpty(); } + @Test public void testEventRegister() { Graph g = getNewGraph(); GraphEventManager gem = g.getEventManager(); @@ -367,6 +390,7 @@ public void testEventRegister() { /** * Test that we can safely unregister a listener that isn't registered. */ + @Test public void testEventUnregister() { getNewGraph().getEventManager().unregister(L); } @@ -386,18 +410,21 @@ protected Graph getAndRegister(GraphListener gl) { return g; } + @Test public void testAddTriple() { Graph g = getAndRegister(L); g.add(SPO); - L.assertHas(new Object[]{"add", g, SPO}); + L.assertHas(new Object[] {"add", g, SPO}); } + @Test public void testDeleteTriple() { Graph g = getAndRegister(L); g.delete(SPO); - L.assertHas(new Object[]{"delete", g, SPO}); + L.assertHas(new Object[] {"delete", g, SPO}); } + @Test public void testListSubjects() { Set emptySubjects = listSubjects(getGraphWith("")); Graph g = getGraphWith("x P y; y Q z"); @@ -410,6 +437,7 @@ protected Set listSubjects(Graph g) { return GraphUtil.listSubjects(g, Node.ANY, Node.ANY).toSet(); } + @Test public void testListPredicates() { Set emptyPredicates = listPredicates(getGraphWith("")); Graph g = getGraphWith("x P y; y Q z"); @@ -422,6 +450,7 @@ protected Set listPredicates(Graph g) { return GraphUtil.listPredicates(g, Node.ANY, Node.ANY).toSet(); } + @Test public void testListObjects() { Set emptyObjects = listObjects(getGraphWith("")); Graph g = getGraphWith("x P y; y Q z"); @@ -448,23 +477,25 @@ private Set remove(Set A, Set B) { * Ensure that triples removed by calling .remove() on the iterator returned by a * find() will generate deletion notifications. */ + @Test public void testEventDeleteByFind() { Graph g = getAndRegister(L); Triple toRemove = GraphTestLib.triple("remove this triple"); g.add(toRemove); try { ExtendedIterator rtr = g.find(toRemove); - assertTrue("ensure a(t least) one triple", rtr.hasNext()); + Assertions.assertTrue(rtr.hasNext(), "ensure at least one triple"); rtr.next(); rtr.remove(); rtr.close(); - L.assertHas(new Object[]{"add", g, toRemove, "delete", g, toRemove}); + L.assertHas(new Object[] {"add", g, toRemove, "delete", g, toRemove}); } catch (UnsupportedOperationException ex) { // No iterator remove } } + @Test public void testTwoListeners() { RecordingListener L1 = new RecordingListener(); RecordingListener L2 = new RecordingListener(); @@ -472,86 +503,97 @@ public void testTwoListeners() { GraphEventManager gem = g.getEventManager(); gem.register(L1).register(L2); g.add(SPO); - L2.assertHas(new Object[]{"add", g, SPO}); - L1.assertHas(new Object[]{"add", g, SPO}); + L2.assertHas(new Object[] {"add", g, SPO}); + L1.assertHas(new Object[] {"add", g, SPO}); } + @Test public void testUnregisterWorks() { Graph g = getNewGraph(); GraphEventManager gem = g.getEventManager(); gem.register(L).unregister(L); g.add(SPO); - L.assertHas(new Object[]{}); + L.assertHas(new Object[] {}); } + @Test public void testRegisterTwice() { Graph g = getAndRegister(L); g.getEventManager().register(L); g.add(SPO); - L.assertHas(new Object[]{"add", g, SPO, "add", g, SPO}); + L.assertHas(new Object[] {"add", g, SPO, "add", g, SPO}); } + @Test public void testUnregisterOnce() { Graph g = getAndRegister(L); g.getEventManager().register(L).unregister(L); g.delete(SPO); - L.assertHas(new Object[]{"delete", g, SPO}); + L.assertHas(new Object[] {"delete", g, SPO}); } + @Test public void testBulkAddArrayEvent() { Graph g = getAndRegister(L); Triple[] triples = GraphTestLib.tripleArray("x R y; a P b"); GraphUtil.add(g, triples); - L.assertHas(new Object[]{"add[]", g, triples}); + L.assertHas(new Object[] {"add[]", g, triples}); } + @Test public void testBulkAddList() { Graph g = getAndRegister(L); List elems = Arrays.asList(GraphTestLib.tripleArray("bells ring loudly; pigs might fly")); GraphUtil.add(g, elems); - L.assertHas(new Object[]{"addList", g, elems}); + L.assertHas(new Object[] {"addList", g, elems}); } + @Test public void testBulkDeleteArray() { Graph g = getAndRegister(L); Triple[] triples = GraphTestLib.tripleArray("x R y; a P b"); GraphUtil.delete(g, triples); - L.assertHas(new Object[]{"delete[]", g, triples}); + L.assertHas(new Object[] {"delete[]", g, triples}); } + @Test public void testBulkDeleteList() { Graph g = getAndRegister(L); List elems = Arrays.asList(GraphTestLib.tripleArray("bells ring loudly; pigs might fly")); GraphUtil.delete(g, elems); - L.assertHas(new Object[]{"deleteList", g, elems}); + L.assertHas(new Object[] {"deleteList", g, elems}); } + @Test public void testBulkAddIterator() { Graph g = getAndRegister(L); Triple[] triples = GraphTestLib.tripleArray("I wrote this; you read that; I wrote this"); GraphUtil.add(g, asIterator(triples)); - L.assertHas(new Object[]{"addIterator", g, Arrays.asList(triples)}); + L.assertHas(new Object[] {"addIterator", g, Arrays.asList(triples)}); } + @Test public void testBulkDeleteIterator() { Graph g = getAndRegister(L); Triple[] triples = GraphTestLib.tripleArray("I wrote this; you read that; I wrote this"); GraphUtil.delete(g, asIterator(triples)); - L.assertHas(new Object[]{"deleteIterator", g, Arrays.asList(triples)}); + L.assertHas(new Object[] {"deleteIterator", g, Arrays.asList(triples)}); } public Iterator asIterator(Triple[] triples) { return Arrays.asList(triples).iterator(); } + @Test public void testBulkAddGraph() { Graph g = getAndRegister(L); Graph triples = GraphTestLib.graphWith("this type graph; I type slowly"); GraphUtil.addInto(g, triples); - L.assertHas(new Object[]{"addGraph", g, triples}); + L.assertHas(new Object[] {"addGraph", g, triples}); GraphTestLib.testContains(g, triples); } + @Test public void testBulkAddGraph1() { Graph g1 = GraphTestLib.graphWith("pigs might fly; dead can dance"); Graph g2 = GraphTestLib.graphWith("this type graph"); @@ -559,6 +601,7 @@ public void testBulkAddGraph1() { GraphTestLib.testContains(g1, g2); } + @Test public void testBulkAddGraph2() { Graph g1 = GraphTestLib.graphWith("this type graph"); Graph g2 = GraphTestLib.graphWith("pigs might fly; dead can dance"); @@ -566,14 +609,16 @@ public void testBulkAddGraph2() { GraphTestLib.testContains(g1, g2); } + @Test public void testBulkDeleteGraph() { Graph g = getAndRegister(L); Graph triples = GraphTestLib.graphWith("this type graph; I type slowly"); GraphUtil.deleteFrom(g, triples); - L.assertHas(new Object[]{"deleteGraph", g, triples}); + L.assertHas(new Object[] {"deleteGraph", g, triples}); GraphTestLib.testOmits(g, triples); } + @Test public void testBulkDeleteGraph1() { Graph g1 = GraphTestLib.graphWith("pigs might fly; dead can dance"); Graph g2 = GraphTestLib.graphWith("pigs might fly"); @@ -581,6 +626,7 @@ public void testBulkDeleteGraph1() { GraphTestLib.testOmits(g1, g2); } + @Test public void testBulkDeleteGraph2() { Graph g1 = GraphTestLib.graphWith("pigs might fly"); Graph g2 = GraphTestLib.graphWith("pigs might fly; dead can dance"); @@ -588,25 +634,28 @@ public void testBulkDeleteGraph2() { GraphTestLib.testOmits(g1, g2); } + @Test public void testGeneralEvent() { Graph g = getAndRegister(L); - Object value = new int[]{}; + Object value = new int[] {}; g.getEventManager().notifyEvent(g, value); - L.assertHas(new Object[]{"someEvent", g, value}); + L.assertHas(new Object[] {"someEvent", g, value}); } + @Test public void testRemoveAllEvent() { Graph g = getAndRegister(L); g.clear(); - L.assertHas(new Object[]{"someEvent", g, GraphEvents.removeAll}); + L.assertHas(new Object[] {"someEvent", g, GraphEvents.removeAll}); } + @Test public void testRemoveSomeEvent() { Graph g = getAndRegister(L); Node S = GraphTestLib.node("S"), P = GraphTestLib.node("??"), O = GraphTestLib.node("??"); g.remove(S, P, O); Object event = GraphEvents.remove(S, P, O); - L.assertHas(new Object[]{"someEvent", g, event}); + L.assertHas(new Object[] {"someEvent", g, event}); } /** @@ -614,6 +663,7 @@ public void testRemoveSomeEvent() { * 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 = getNewGraph(); GraphTestLib.graphAdd(g, "a P b; _c _Q _d; a 11 12"); @@ -636,6 +686,7 @@ private boolean containsNode(Graph g, Node node) { return GraphUtil.containsNode(g, node); } + @Test public void testSubjectsFor() { // First get the answer from the empty graph (not empty for an inf graph) Graph b = getGraphWith(""); @@ -651,7 +702,7 @@ public void testSubjectsFor() { testSubjects(g, B, GraphTestLib.node("Q"), GraphTestLib.node("z")); } - protected void testSubjects(Graph g, Collection exclude, Node p, Node o, Node...expected) { + protected void testSubjects(Graph g, Collection exclude, Node p, Node o, Node... expected) { List R = GraphUtil.listSubjects(g, p, o).toList(); R.removeAll(exclude); assertSameUnordered(R, exclude, expected); @@ -674,6 +725,7 @@ private void assertSameUnordered(List x1, Collection exclude, Node[] } + @Test public void testListSubjectsNoRemove() { Graph g = getGraphWith("a P b; b Q c; c R a"); Iterator it = GraphUtil.listSubjects(g, Node.ANY, Node.ANY); @@ -686,6 +738,7 @@ public void testListSubjectsNoRemove() { } } + @Test public void testObjectsFor() { // First get the answer from the empty graph (not empty for an inf graph) Graph b = getGraphWith(""); @@ -700,11 +753,12 @@ public void testObjectsFor() { testObjects(g, B, GraphTestLib.node("z"), GraphTestLib.node("Q")); } - protected void testObjects(Graph g, Collection exclude, Node s, Node p, Node...expected) { + protected void testObjects(Graph g, Collection exclude, Node s, Node p, Node... expected) { List 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 = getGraphWith(""); @@ -720,11 +774,12 @@ public void testPredicatesFor() { testPredicates(g, B, GraphTestLib.node("z"), GraphTestLib.node("y")); } - protected void testPredicates(Graph g, Collection exclude, Node s, Node o, Node...expected) { + protected void testPredicates(Graph g, Collection exclude, Node s, Node o, Node... expected) { List X = GraphUtil.listPredicates(g, s, o).toList(); assertSameUnordered(X, exclude, expected); } + @Test public void testListObjectsNoRemove() { Graph g = getGraphWith("a P b; b Q c; c R a"); Iterator it = GraphUtil.listObjects(g, Node.ANY, Node.ANY); @@ -737,6 +792,7 @@ public void testListObjectsNoRemove() { } } + @Test public void testListPredicatesNoRemove() { Graph g = getGraphWith("a P b; b Q c; c R a"); Iterator it = GraphUtil.listPredicates(g, Node.ANY, Node.ANY); @@ -749,6 +805,7 @@ public void testListPredicatesNoRemove() { } } + @Test public void testRemoveAll() { testRemoveAll(""); testRemoveAll("a R b"); @@ -792,17 +849,18 @@ public void remove() { * */ protected String[][] cases = {{"x R y", "x R y", ""}, {"x R y; a P b", "x R y", "a P b"}, {"x R y; a P b", "?? R y", "a P b"}, - {"x R y; a P b", "x R ??", "a P b"}, {"x R y; a P b", "x ?? y", "a P b"}, {"x R y; a P b", "?? ?? ??", ""}, - {"x R y; a P b; c P d", "?? P ??", "x R y"}, {"x R y; a P b; x S y", "x ?? ??", "a P b"},}; + {"x R y; a P b", "x R ??", "a P b"}, {"x R y; a P b", "x ?? y", "a P b"}, {"x R y; a P b", "?? ?? ??", ""}, + {"x R y; a P b; c P d", "?? P ??", "x R y"}, {"x R y; a P b; x S y", "x ?? ??", "a P b"},}; /** * Test that remove(s, p, o) works, in the presence of inferencing graphs that * mean emptyness isn't available. This is why we go round the houses and test * that expected ~= initialContent + addedStuff - removed - initialContent. */ + @Test public void testRemoveSPO() { - for ( String[] aCase : cases ) { - for ( int j = 0 ; j < 3 ; j += 1 ) { + for (String[] aCase : cases) { + for (int j = 0; j < 3; j += 1) { Graph content = getNewGraph(); Graph baseContent = copy(content); GraphTestLib.graphAdd(content, aCase[0]); @@ -816,13 +874,14 @@ public void testRemoveSPO() { } /** testIsomorphism from file data */ + @Test public void testIsomorphismFile() { testIsomorphismXMLFile(1, true); testIsomorphismXMLFile(2, true); testIsomorphismXMLFile(3, true); -// testIsomorphismXMLFile(4,true); -- Uses daml:collection + // testIsomorphismXMLFile(4,true); -- Uses daml:collection testIsomorphismXMLFile(5, false); -// testIsomorphismXMLFile(6,false); -- Uses daml:collection + // testIsomorphismXMLFile(6,false); -- Uses daml:collection testIsomorphismNTripleFile(7, true); testIsomorphismNTripleFile(8, false); @@ -854,13 +913,13 @@ private void testIsomorphismFile(int n, String lang, String suffix, boolean resu m2.read(getInputStream(n, 2, suffix), "http://www.example.org/", lang); boolean rslt = g1.isIsomorphicWith(g2) == result; - if ( !rslt ) { + if (!rslt) { System.out.println("g1:"); m1.write(System.out, "N-TRIPLE"); System.out.println("g2:"); m2.write(System.out, "N-TRIPLE"); } - assertTrue("Isomorphism test failed", rslt); + Assertions.assertTrue(rslt, "Isomorphism test failed"); } protected void add(Graph toUpdate, Graph toAdd) { @@ -883,4 +942,5 @@ protected Graph getClosed() { result.close(); return result; } + } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/ReasonerTester.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/ReasonerTester.java index 27b71035c9d..339f0efcbec 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/ReasonerTester.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/ReasonerTester.java @@ -28,7 +28,6 @@ import java.nio.charset.StandardCharsets; import java.util.*; -import junit.framework.TestCase; import org.apache.jena.graph.GraphMemFactory; import org.apache.jena.graph.Graph; import org.apache.jena.graph.Node; @@ -191,13 +190,13 @@ public static Node nodeToPattern(Node n) { /** * 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 testcase non-null if the caller wants a failed test to assert * @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, Object testcase, Resource configuration) throws IOException { for ( String test : listTests() ) { if ( !runTest( test, reasonerF, testcase, configuration ) ) @@ -211,12 +210,12 @@ public boolean runTests(ReasonerFactory reasonerF, TestCase testcase, Resource c /** * 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 + * @param testcase non-null if the caller wants a failed test to assert * @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, Object testcase) throws IOException { for ( String test : listTests() ) { if ( !runTest( test, reasoner, testcase ) ) @@ -244,13 +243,13 @@ public List listTests() { * 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 testcase non-null if the caller wants a failed test to assert * @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, Object testcase, Resource configuration) throws IOException { Reasoner reasoner = reasonerF.create(configuration); return runTest(uri, reasoner, testcase); } @@ -259,12 +258,12 @@ public boolean runTest(String uri, ReasonerFactory reasonerF, TestCase testcase, * 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 + * @param testcase non-null if the caller wants a failed test to assert * @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, Object testcase) throws IOException { // Find the specification for the named test Resource test = testManifest.getResource(uri); if (!test.hasProperty(RDF.type, testClass)) { diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TS3_reasoners.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TS6_reasoners.java similarity index 75% rename from jena-core/src/test/java/org/apache/jena/reasoner/test/TS3_reasoners.java rename to jena-core/src/test/java/org/apache/jena/reasoner/test/TS6_reasoners.java index 02db325046b..2e479c12a4a 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TS3_reasoners.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TS6_reasoners.java @@ -21,18 +21,26 @@ package org.apache.jena.reasoner.test; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.junit.platform.suite.api.BeforeSuite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; -@RunWith(Suite.class) -@Suite.SuiteClasses({ +import org.apache.jena.test.JenaTestLib; + +@Suite +@SelectClasses({ TestTransitiveGraphCache.class, TestReasoners.class, TestRDFSReasoners.class, TestInfPrefixMapping.class, TestInfGraph.class, TestInfModel.class, - TestSafeModel.class, + TestSafeModel.class }) -public class TS3_reasoners {} +public class TS6_reasoners { + @BeforeSuite + public static void beforeSuite() { + JenaTestLib.setup(); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfGraph.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfGraph.java index 8dece4ecd51..ea06e23c3f2 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfGraph.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfGraph.java @@ -21,7 +21,10 @@ package org.apache.jena.reasoner.test; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.Graph; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.reasoner.InfGraph; @@ -34,11 +37,6 @@ parametrised with the InfGraph being tested (hence getInfGraph). public class TestInfGraph extends AbstractTestGraph { - public TestInfGraph( String name ) - { super( name ); } - - public static TestSuite suite() - { return new TestSuite( TestInfGraph.class ); } @SuppressWarnings("removal") private InfGraph getInfGraph() @@ -50,9 +48,10 @@ private InfGraph getInfGraph() public Graph getNewGraph() { return getInfGraph(); } + @Test public void testInfGraph() { InfGraph ig = getInfGraph(); - assertSame( ig.getPrefixMapping(), ig.getRawGraph().getPrefixMapping() ); + assertSame(ig.getPrefixMapping(), ig.getRawGraph().getPrefixMapping() ); } } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfModel.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfModel.java index 5e2c26dd463..c9febee7f0f 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfModel.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfModel.java @@ -21,8 +21,10 @@ package org.apache.jena.reasoner.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.OntModelSpec; import org.apache.jena.rdf.model.*; @@ -35,26 +37,21 @@ * particular reasoner. */ -public class TestInfModel extends TestCase { +public class TestInfModel { /** * Boilerplate for junit */ - public TestInfModel( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite(TestInfModel.class); - } /** * Check interface extensions which had an earlier bug with null handling */ @SuppressWarnings("removal") + @Test public void testListWithPosits() { String NS = PrintUtil.egNS; Model data = ModelFactory.createDefaultModel(); @@ -65,7 +62,7 @@ public void testListWithPosits() { Model premise = ModelFactory.createDefaultModel(); premise.add(c1, RDFS.subClassOf, c2); InfModel im = ModelFactory.createInfModel(ReasonerRegistry.getRDFSReasoner(), data); - TestUtil.assertIteratorValues(this, im.listStatements(c1, RDFS.subClassOf, null, premise), + TestUtil.assertIteratorValues( im.listStatements(c1, RDFS.subClassOf, null, premise), new Object[] { data.createStatement(c1, RDFS.subClassOf, c2), data.createStatement(c1, RDFS.subClassOf, c3), @@ -73,7 +70,7 @@ public void testListWithPosits() { }); OntModel om = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF, data); - TestUtil.assertIteratorValues(this, om.listStatements(c1, RDFS.subClassOf, null, premise), + TestUtil.assertIteratorValues( om.listStatements(c1, RDFS.subClassOf, null, premise), new Object[] { data.createStatement(c1, RDFS.subClassOf, c2), data.createStatement(c1, RDFS.subClassOf, c3), diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfPrefixMapping.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfPrefixMapping.java index 38a887f2675..a895f9d8344 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfPrefixMapping.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfPrefixMapping.java @@ -21,8 +21,10 @@ package org.apache.jena.reasoner.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.reasoner.InfGraph; @@ -31,13 +33,7 @@ the Jena-provided base. Needs to be made into an abstract test and parametrised with the InfGraph being tested (hence getInfGraph). */ -public class TestInfPrefixMapping extends TestCase - { - public TestInfPrefixMapping( String name ) - { super( name ); } - - public static TestSuite suite() - { return new TestSuite( TestInfPrefixMapping.class ); } +public class TestInfPrefixMapping { @SuppressWarnings("removal") private InfGraph getInfGraph() @@ -45,9 +41,10 @@ private InfGraph getInfGraph() return (InfGraph) ModelFactory.createOntologyModel().getGraph(); } + @Test public void testInfGraph() { InfGraph ig = getInfGraph(); - assertSame( ig.getPrefixMapping(), ig.getRawGraph().getPrefixMapping() ); + assertSame(ig.getPrefixMapping(), ig.getRawGraph().getPrefixMapping() ); } } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java index e986a56c95a..8263150c6d4 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java @@ -21,6 +21,8 @@ package org.apache.jena.reasoner.test; +import static org.junit.jupiter.api.Assertions.*; + import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; @@ -28,8 +30,13 @@ import java.nio.charset.StandardCharsets; import java.util.Iterator; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; + import org.apache.jena.rdf.model.*; import org.apache.jena.reasoner.InfGraph; import org.apache.jena.reasoner.Reasoner; @@ -46,25 +53,21 @@ /** * Test the set of admissable RDFS reasoners. */ -public class TestRDFSReasoners extends TestCase { +public class TestRDFSReasoners { /** Base URI for the test names */ public static final String NAMESPACE = "http://www.hpl.hp.com/semweb/2003/query_tester/"; protected static Logger logger = LoggerFactory.getLogger(TestReasoners.class); - /** - * Boilerplate for junit - */ - public TestRDFSReasoners(String name) { - super(name); - } /** - * Boilerplate for junit. This is its own test suite + * The RDFS reasoner tests, one dynamic test per manifest entry. This was a + * hand-built {@code TestSuite} of {@code TestCase} subclasses. */ - public static TestSuite suite() { - TestSuite suite = new TestSuite(); + @TestFactory + public Stream rdfsReasonerTests() { + List suite = new ArrayList<>(); try { // FB reasoner doesn't support validation so the full set of wg tests are // commented out @@ -80,7 +83,7 @@ public static TestSuite suite() { constructRDFWGtests(suite, RDFSRuleReasonerFactory.theInstance(), null); constructQuerytests(suite, "rdfs/manifest-standard.rdf", RDFSRuleReasonerFactory.theInstance(), config); - suite.addTest(new TestRDFSMisc(RDFSRuleReasonerFactory.theInstance(), null)); + suite.add(DynamicTest.dynamicTest("TestRDFSMisc", ()->new TestRDFSMisc(RDFSRuleReasonerFactory.theInstance(), null).runTest())); Resource configFull = ReasonerTestLib.newResource().addProperty(ReasonerVocabulary.PROPsetRDFSLevel, ReasonerVocabulary.RDFS_FULL); @@ -108,47 +111,47 @@ public static TestSuite suite() { // failed to even built the test harness logger.error("Failed to construct RDFS test harness", e); } - return suite; + return suite.stream(); } /** * Build a single named query test */ - private static void constructSingleQuerytests(TestSuite suite, String manifest, String test, ReasonerFactory rf, + private static void constructSingleQuerytests(List suite, String manifest, String test, ReasonerFactory rf, Resource config) throws IOException { ReasonerTester tester = new ReasonerTester(manifest); Reasoner r = rf.create(config); - suite.addTest(new TestReasonerFromManifest(tester, test, r)); + suite.add(DynamicTest.dynamicTest(test, ()->new TestReasonerFromManifest(tester, test, r).runTest())); } /** * Build the query tests for the given reasoner. */ - private static void constructQuerytests(TestSuite suite, String manifest, ReasonerFactory rf, Resource config) throws IOException { + private static void constructQuerytests(List suite, String manifest, ReasonerFactory rf, Resource config) throws IOException { ReasonerTester tester = new ReasonerTester(manifest); Reasoner r = rf.create(config); for ( String test : tester.listTests() ) { - suite.addTest(new TestReasonerFromManifest(tester, test, r)); + suite.add(DynamicTest.dynamicTest(test, ()->new TestReasonerFromManifest(tester, test, r).runTest())); } } /** * Build the working group tests for the given reasoner. */ - private static void constructRDFWGtests(TestSuite suite, ReasonerFactory rf, Resource config) throws IOException { + private static void constructRDFWGtests(List suite, ReasonerFactory rf, Resource config) throws IOException { WGReasonerTester tester = new WGReasonerTester("Manifest.rdf"); for ( String test : tester.listTests() ) { - suite.addTest(new TestReasonerWG(tester, test, rf, config)); + suite.add(DynamicTest.dynamicTest(test, ()->new TestReasonerWG(tester, test, rf, config).runTest())); } } /** * Build the query tests for the given reasoner. */ - public static void constructQuerytests(TestSuite suite, String manifest, Reasoner reasoner) throws IOException { + public static void constructQuerytests(List suite, String manifest, Reasoner reasoner) throws IOException { ReasonerTester tester = new ReasonerTester(manifest); for ( String test : tester.listTests() ) { - suite.addTest(new TestReasonerFromManifest(tester, test, reasoner)); + suite.add(DynamicTest.dynamicTest(test, ()->new TestReasonerFromManifest(tester, test, reasoner).runTest())); } } @@ -156,7 +159,7 @@ public static void constructQuerytests(TestSuite suite, String manifest, Reasone * Inner class defining a test framework for invoking a single locally defined * query-over-inference test. */ - static class TestReasonerFromManifest extends TestCase { + static class TestReasonerFromManifest { /** The tester which already has the test manifest loaded */ ReasonerTester tester; @@ -169,7 +172,6 @@ static class TestReasonerFromManifest extends TestCase { /** Constructor */ TestReasonerFromManifest(ReasonerTester tester, String test, Reasoner reasoner) { - super(test); this.tester = tester; this.test = test; this.reasoner = reasoner; @@ -178,7 +180,6 @@ static class TestReasonerFromManifest extends TestCase { /** * The test runner */ - @Override public void runTest() throws IOException { tester.runTest(test, reasoner, this); } @@ -189,7 +190,7 @@ public void runTest() throws IOException { * Inner class defining a test framework for invoking a single RDFCore working * group test. */ - static class TestReasonerWG extends TestCase { + static class TestReasonerWG { /** The tester which already has the test manifest loaded */ WGReasonerTester tester; @@ -205,7 +206,6 @@ static class TestReasonerWG extends TestCase { /** Constructor */ TestReasonerWG(WGReasonerTester tester, String test, ReasonerFactory reasonerFactory, Resource config) { - super(test); this.tester = tester; this.test = test; this.reasonerFactory = reasonerFactory; @@ -215,7 +215,6 @@ static class TestReasonerWG extends TestCase { /** * The test runner */ - @Override public void runTest() throws IOException { tester.runTest(test, reasonerFactory, this, config); } @@ -226,7 +225,7 @@ public void runTest() throws IOException { * Inner class defining the misc extra tests needed to check out a candidate RDFS * reasoner. */ - static class TestRDFSMisc extends TestCase { + static class TestRDFSMisc { /** The factory for the reasoner type under test */ ReasonerFactory reasonerFactory; @@ -236,7 +235,6 @@ static class TestRDFSMisc extends TestCase { /** Constructor */ TestRDFSMisc(ReasonerFactory reasonerFactory, Resource config) { - super("TestRDFSMisc"); this.reasonerFactory = reasonerFactory; this.config = config; } @@ -244,7 +242,6 @@ static class TestRDFSMisc extends TestCase { /** * The test runner */ - @Override public void runTest() throws IOException { ReasonerTester tester = new ReasonerTester("rdfs/manifest.rdf"); // Test effect of switching off property scan - should break container @@ -257,7 +254,7 @@ public void runTest() throws IOException { } } configuration.addProperty(ReasonerVocabulary.PROPenableCMPScan, "false"); - assertTrue("scanproperties off", !tester.runTest(NAMESPACE + "rdfs/test17", reasonerFactory, null, configuration)); + assertTrue(!tester.runTest(NAMESPACE + "rdfs/test17", reasonerFactory, null, configuration), "scanproperties off"); // Check capabilities description Reasoner r = reasonerFactory.create(null); diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestReasoners.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestReasoners.java index 47f694375bb..287247ba247 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestReasoners.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestReasoners.java @@ -21,13 +21,15 @@ package org.apache.jena.reasoner.test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Set; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.graph.*; import org.apache.jena.ontology.OntClass; import org.apache.jena.ontology.OntModel; @@ -50,22 +52,15 @@ * Test cases for transitive reasoner (includes some early RDFS reasoner checks) */ @SuppressWarnings("removal") -public class TestReasoners extends TestCase { +public class TestReasoners { /** * Boilerplate for junit */ - public TestReasoners( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - JenaTestLib.setup(); - return new TestSuite(TestReasoners.class); - } private static Graph createGraphForTest() { return GraphMemFactory.createDefaultGraph(); @@ -78,15 +73,17 @@ public static void beforeSuite() { /** * 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(tester.runTests(rf, this, null), "transitive reasoner tests"); } /** * Test rebind operation for the transitive reasoner */ + @Test public void testTransitiveRebind() { Graph data = createGraphForTest(); Node C1 = NodeFactory.createURI("C1"); @@ -99,7 +96,7 @@ public void testTransitiveRebind() { assertTrue(reasoner.supportsProperty(RDFS.subClassOf)); assertTrue(! reasoner.supportsProperty(RDFS.domain)); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(C1, null, null), new Object[] { Triple.create(C1, RDFS.subClassOf.asNode(), C1), @@ -117,13 +114,13 @@ public void testTransitiveRebind() { Node c = NodeFactory.createURI("c"); infgraph.add(Triple.create(a, RDFS.subClassOf.asNode(), b)); infgraph.add(Triple.create(b, RDFS.subClassOf.asNode(), c)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(b, RDFS.subClassOf.asNode(), null), new Object[] { Triple.create(b, RDFS.subClassOf.asNode(), c), Triple.create(b, RDFS.subClassOf.asNode(), b) } ); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(a, RDFS.subClassOf.asNode(), null), new Object[] { Triple.create(a, RDFS.subClassOf.asNode(), a), @@ -135,13 +132,13 @@ public void testTransitiveRebind() { Node r = NodeFactory.createURI("r"); infgraph.add(Triple.create(p, RDFS.subPropertyOf.asNode(), q)); infgraph.add(Triple.create(q, RDFS.subPropertyOf.asNode(), r)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(q, RDFS.subPropertyOf.asNode(), null), new Object[] { Triple.create(q, RDFS.subPropertyOf.asNode(), q), Triple.create(q, RDFS.subPropertyOf.asNode(), r) } ); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(p, RDFS.subPropertyOf.asNode(), null), new Object[] { Triple.create(p, RDFS.subPropertyOf.asNode(), p), @@ -153,6 +150,7 @@ public void testTransitiveRebind() { /** * Test delete operation for Transtive reasoner. */ + @Test public void testTransitiveRemove() { Graph data = createGraphForTest(); Node a = NodeFactory.createURI("a"); @@ -168,7 +166,7 @@ public void testTransitiveRemove() { data.add( Triple.create(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( infgraph.find(a, RDFS.subClassOf.asNode(), null), new Object[] { Triple.create(a, closedP, a), Triple.create(a, closedP, b), @@ -177,14 +175,14 @@ public void testTransitiveRemove() { Triple.create(a, closedP, d), Triple.create(a, closedP, e) }); - TestUtil.assertIteratorValues(this, infgraph.find(b, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues( infgraph.find(b, RDFS.subClassOf.asNode(), null), new Object[] { Triple.create(b, closedP, b), Triple.create(b, closedP, d), Triple.create(b, closedP, e) }); infgraph.delete(Triple.create(b, closedP, d)); - TestUtil.assertIteratorValues(this, infgraph.find(a, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues( infgraph.find(a, RDFS.subClassOf.asNode(), null), new Object[] { Triple.create(a, closedP, a), Triple.create(a, closedP, b), @@ -193,21 +191,21 @@ public void testTransitiveRemove() { Triple.create(a, closedP, d), Triple.create(a, closedP, e) }); - TestUtil.assertIteratorValues(this, infgraph.find(b, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues( infgraph.find(b, RDFS.subClassOf.asNode(), null), new Object[] { Triple.create(b, closedP, b), }); infgraph.delete(Triple.create(a, closedP, c)); - TestUtil.assertIteratorValues(this, infgraph.find(a, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues( infgraph.find(a, RDFS.subClassOf.asNode(), null), new Object[] { Triple.create(a, closedP, a), Triple.create(a, closedP, b) }); - TestUtil.assertIteratorValues(this, infgraph.find(b, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues( infgraph.find(b, RDFS.subClassOf.asNode(), null), new Object[] { Triple.create(b, closedP, b) }); - TestUtil.assertIteratorValues(this, data.find(null, RDFS.subClassOf.asNode(), null), + TestUtil.assertIteratorValues( data.find(null, RDFS.subClassOf.asNode(), null), new Object[] { Triple.create(a, closedP, b), Triple.create(c, closedP, d), @@ -218,6 +216,7 @@ public void testTransitiveRemove() { /** * Test metalevel add/remove subproperty operations for transitive reasoner. */ + @Test public void testTransitiveMetaLevel() { doTestMetaLevel(TransitiveReasonerFactory.theInstance()); } @@ -225,6 +224,7 @@ public void testTransitiveMetaLevel() { /** * Test metalevel add/remove subproperty operations for rdsf reasoner. */ + @Test public void testRDFSMetaLevel() { doTestMetaLevel(RDFSRuleReasonerFactory.theInstance()); } @@ -245,22 +245,22 @@ public void doTestMetaLevel(ReasonerFactory rf) { data.add( Triple.create(c1, p, c2)); Reasoner reasoner = rf.create(null); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues( infgraph.find(c1, sC, null), new Object[] { }); infgraph.add(Triple.create(p, q, sC)); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues( infgraph.find(c1, sC, null), new Object[] { }); infgraph.add(Triple.create(q, sP, sP)); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues( infgraph.find(c1, sC, null), new Object[] { Triple.create(c1, sC, c1), Triple.create(c1, sC, c2), Triple.create(c1, sC, c3) }); infgraph.delete(Triple.create(p, q, sC)); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues( infgraph.find(c1, sC, null), new Object[] { }); } @@ -268,6 +268,7 @@ public void doTestMetaLevel(ReasonerFactory rf) { /** * Check a complex graph's transitive reduction. */ + @Test public void testTransitiveReduction() { Model test = FileManager.getInternal().loadModelInternal("testing/reasoners/bugs/subpropertyModel.n3"); Property dp = test.getProperty(TransitiveReasoner.directSubPropertyOf.getURI()); @@ -296,7 +297,7 @@ public void doTestTransitiveReduction(Model model, Property dp) { Resource d2 = (Resource)directLinks.get(m); if (im.contains(d1, dp, d2) && ! base.equals(d1) && !base.equals(d2)) { - assertTrue("Triangle discovered in transitive reduction", false); + assertTrue(false, "Triangle discovered in transitive reduction"); } } } @@ -311,6 +312,7 @@ public void doTestTransitiveReduction(Model model, Property dp) { * 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"); @@ -324,7 +326,7 @@ public void testTransitiveSpecReuse() { StmtIterator si = om2.listStatements(); boolean ok = ! si.hasNext(); si.close(); - assertTrue("Transitive reasoner state leak", ok); + assertTrue(ok, "Transitive reasoner state leak"); } /** @@ -333,6 +335,7 @@ public void testTransitiveSpecReuse() { * 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()); @@ -347,13 +350,14 @@ public void testTransitiveBindReuse() { StmtIterator si = om2.listStatements(); boolean ok = ! si.hasNext(); si.close(); - assertTrue("Transitive reasoner state leak", ok); + assertTrue(ok, "Transitive reasoner state leak"); } /** * Test that two transitive engines are independent. * See JENA-1260 */ + @Test public void testTransitiveEngineSeparation() throws InterruptedException { String NS = "http://example.com/test#"; @@ -365,20 +369,21 @@ public void testTransitiveEngineSeparation() throws InterruptedException { InfModel simple = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel()); simple.add(s, sp, p); - assertFalse( simple.contains(s, RDFS.subPropertyOf, p) ); + assertFalse(simple.contains(s, RDFS.subPropertyOf, p) ); InfModel withSP = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel()); withSP.add(sp, RDFS.subPropertyOf, RDFS.subPropertyOf); withSP.add(s, sp, p); - assertTrue( withSP.contains(s, RDFS.subPropertyOf, p) ); + assertTrue(withSP.contains(s, RDFS.subPropertyOf, p) ); simple.add(q, sp, p); - assertFalse( simple.contains(q, RDFS.subPropertyOf, p) ); + assertFalse(simple.contains(q, RDFS.subPropertyOf, p) ); } /** * Test rebind operation for the RDFS reasoner */ + @Test public void testRDFSRebind() { Graph data = createGraphForTest(); Node C1 = NodeFactory.createURI("C1"); @@ -389,7 +394,7 @@ public void testRDFSRebind() { data.add( Triple.create(C2, RDFS.subClassOf.asNode(), C3) ); Reasoner reasoner = RDFSRuleReasonerFactory.theInstance().create(null); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(C1, RDFS.subClassOf.asNode(), null), new Object[] { Triple.create(C1, RDFS.subClassOf.asNode(), C1), @@ -400,7 +405,7 @@ public void testRDFSRebind() { data2.add( Triple.create(C1, RDFS.subClassOf.asNode(), C2) ); data2.add( Triple.create(C2, RDFS.subClassOf.asNode(), C4) ); infgraph.rebind(data2); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( infgraph.find(C1, RDFS.subClassOf.asNode(), null), new Object[] { Triple.create(C1, RDFS.subClassOf.asNode(), C1), @@ -414,6 +419,7 @@ public void testRDFSRebind() { * 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; @@ -425,32 +431,34 @@ public void testRDFSRemove() { p.addProperty(RDFS.domain, D); i.addProperty(p, c); i.addProperty(p, d); - TestUtil.assertIteratorValues(this, i.listProperties(), new Object[] { + TestUtil.assertIteratorValues( 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( i.listProperties(), new Object[] { }); } /** * Cycle bug in transitive reasoner */ + @Test public void testTransitiveCycleBug() { Model m = FileManager.getInternal().loadModelInternal( "file:testing/reasoners/bugs/unbroken.n3" ); OntModel om = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM_TRANS_INF, m ); OntClass rootClass = om.getOntClass( RDFS.Resource.getURI() ); Resource c = m.getResource("c"); Set direct = rootClass.listSubClasses( true ).toSet(); - assertFalse( direct.contains( c ) ); + assertFalse(direct.contains( c ) ); } /** * Test the ModelFactory interface */ + @Test public void testModelFactoryRDFS() { Model data = ModelFactory.createDefaultModel(); Property p = data.createProperty("urn:example:p"); @@ -461,7 +469,7 @@ public void testModelFactoryRDFS() { .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( i, new Object[] { data.createStatement(b, RDF.type, RDFS.Resource ), data.createStatement(b, RDF.type, C ) }); @@ -471,6 +479,7 @@ public void testModelFactoryRDFS() { /** * Run test on findWithPremies for Transitive reasoner. */ + @Test public void testTransitiveFindWithPremises() { doTestFindWithPremises(TransitiveReasonerFactory.theInstance()); } @@ -478,6 +487,7 @@ public void testTransitiveFindWithPremises() { /** * Run test on findWithPremies for RDFS reasoner. */ + @Test public void testRDFSFindWithPremises() { doTestFindWithPremises(RDFSRuleReasonerFactory.theInstance()); } @@ -497,16 +507,16 @@ public void doTestFindWithPremises(ReasonerFactory rf) { premise.add( Triple.create(c1, sC, c2)); Reasoner reasoner = rf.create(null); InfGraph infgraph = reasoner.bind(data); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues( infgraph.find(c1, sC, null), new Object[] { }); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null, premise), + TestUtil.assertIteratorValues( infgraph.find(c1, sC, null, premise), new Object[] { Triple.create(c1, sC, c2), Triple.create(c1, sC, c3), Triple.create(c1, sC, c1) }); - TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), + TestUtil.assertIteratorValues( infgraph.find(c1, sC, null), new Object[] { }); diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestSafeModel.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestSafeModel.java index f546bdba0cc..42d2b724e33 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestSafeModel.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestSafeModel.java @@ -21,11 +21,13 @@ package org.apache.jena.reasoner.test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import java.util.List; import static org.apache.jena.util.PrintUtil.egNS; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.jena.graph.Graph; import org.apache.jena.graph.Node; import org.apache.jena.graph.Triple; @@ -39,27 +41,22 @@ * against literals in the subject position. By default getDeductionsModel in those * cases will return a SafeModel */ -public class TestSafeModel extends TestCase { +public class TestSafeModel { /** * Boilerplate for junit */ - public TestSafeModel( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite - */ - public static TestSuite suite() { - return new TestSuite(TestSafeModel.class); - } + */ /** * Create a generalized model via inference and check it is * safe but unwrappable */ + @Test public void testBasics() { Model base = ModelFactory.createDefaultModel(); Resource r = base.createResource(egNS + "r"); @@ -72,17 +69,17 @@ public void testBasics() { List rules = Rule.parseRules("(?r eg:p ?v) -> (?v eg:q ?r)."); GenericRuleReasoner reasoner = new GenericRuleReasoner(rules); InfModel inf = ModelFactory.createInfModel(reasoner, base); - TestUtil.assertIteratorValues(this, inf.listStatements(), new Statement[]{asserted}); + TestUtil.assertIteratorValues( inf.listStatements(), new Statement[]{asserted}); Model deductions = inf.getDeductionsModel(); - TestUtil.assertIteratorValues(this, deductions.listStatements(), new Statement[]{}); + TestUtil.assertIteratorValues( deductions.listStatements(), new Statement[]{}); Graph safeGraph = deductions.getGraph(); assertTrue(safeGraph instanceof SafeGraph); Graph rawGraph = ((SafeGraph)safeGraph).getRawGraph(); Triple deduction = Triple.create(l.asNode(), q.asNode(), r.asNode()); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( rawGraph.find(Node.ANY, Node.ANY, Node.ANY), new Triple[]{deduction}); } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestTransitiveGraphCache.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestTransitiveGraphCache.java index eb3de317e12..cfb026d552c 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestTransitiveGraphCache.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestTransitiveGraphCache.java @@ -21,8 +21,10 @@ package org.apache.jena.reasoner.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + import org.apache.jena.graph.Node; import org.apache.jena.graph.NodeFactory; import org.apache.jena.graph.Triple; @@ -34,7 +36,7 @@ * off the main unit test paths. */ -public class TestTransitiveGraphCache extends TestCase { +public class TestTransitiveGraphCache { /** The cache under test */ TransitiveGraphCache cache; @@ -55,25 +57,17 @@ public class TestTransitiveGraphCache extends TestCase { /** * Boilerplate for junit */ - public TestTransitiveGraphCache( String name ) { - super( name ); - } /** * Boilerplate for junit. * This is its own test suite */ - public static TestSuite suite() { - return new TestSuite( TestTransitiveGraphCache.class ); -// TestSuite suite = new TestSuite(); -// suite.addTest( new TestTransitiveGraphCache("testEquivalencesSimple")); -// return suite; - } /** * Test the basic functioning a Transitive closure cache. * Caches the graph but not the final closure. */ + @Test public void testBasicCache() { initCache(); cache.setCaching(false); @@ -84,6 +78,7 @@ public void testBasicCache() { * Test the basic functioning a Transitive closure cache. * Caches the graph and any requested closures */ + @Test public void testCachingCache() { initCache(); cache.setCaching(true); @@ -93,6 +88,7 @@ public void testCachingCache() { /** * Test the clone operation */ + @Test public void testCloning() { initCache(); TransitiveGraphCache clone = cache.deepCopy(); @@ -131,13 +127,13 @@ private void initCache() { public void doBasicTest(TransitiveGraphCache cache) { // Test forward property patterns - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(a, directP, null)), new Object[] { Triple.create(a, closedP, a), Triple.create(a, closedP, b) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(a, closedP, null)), new Object[] { Triple.create(a, closedP, a), @@ -147,21 +143,21 @@ public void doBasicTest(TransitiveGraphCache cache) { Triple.create(a, closedP, f), Triple.create(a, closedP, g) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(a, closedP, g)), new Object[] { Triple.create(a, closedP, g), }); // Test backward patterns - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(null, directP, f)), new Object[] { Triple.create(e, closedP, f), Triple.create(f, closedP, f), Triple.create(c, closedP, f) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(null, closedP, f)), new Object[] { Triple.create(f, closedP, f), @@ -173,7 +169,7 @@ public void doBasicTest(TransitiveGraphCache cache) { }); // List all cases - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(null, directP, null)), new Object[] { Triple.create(a, closedP, a), @@ -191,7 +187,7 @@ public void doBasicTest(TransitiveGraphCache cache) { Triple.create(f, closedP, g), Triple.create(g, closedP, g) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(null, closedP, null)), new Object[] { Triple.create(a, closedP, a), @@ -225,28 +221,28 @@ public void doBasicTest(TransitiveGraphCache cache) { // Add a look in the graph and check the loop from each starting position cache.addRelation(Triple.create(g, closedP, e)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(e, directP, null)), new Object[] { Triple.create(e, closedP, e), Triple.create(e, closedP, f), Triple.create(e, closedP, g) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(f, directP, null)), new Object[] { Triple.create(f, closedP, f), Triple.create(f, closedP, g), Triple.create(f, closedP, e) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(g, directP, null)), new Object[] { Triple.create(g, closedP, g), Triple.create(g, closedP, e), Triple.create(g, closedP, f) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(null, directP, e)), new Object[] { Triple.create(e, closedP, e), @@ -255,7 +251,7 @@ public void doBasicTest(TransitiveGraphCache cache) { Triple.create(c, closedP, e), Triple.create(g, closedP, e) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(null, directP, f)), new Object[] { Triple.create(f, closedP, f), @@ -264,7 +260,7 @@ public void doBasicTest(TransitiveGraphCache cache) { Triple.create(c, closedP, f), Triple.create(e, closedP, f) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(null, directP, g)), new Object[] { Triple.create(g, closedP, g), @@ -273,21 +269,21 @@ public void doBasicTest(TransitiveGraphCache cache) { Triple.create(c, closedP, g), Triple.create(f, closedP, g) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(g, closedP, null)), new Object[] { Triple.create(g, closedP, g), Triple.create(g, closedP, e), Triple.create(g, closedP, f) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(e, closedP, null)), new Object[] { Triple.create(e, closedP, g), Triple.create(e, closedP, e), Triple.create(e, closedP, f) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(f, closedP, null)), new Object[] { Triple.create(f, closedP, g), @@ -310,13 +306,14 @@ public void doBasicTest(TransitiveGraphCache cache) { * Test a a case where an earlier version had a bug due to removing * a link which was required rather than redundant. */ + @Test public void testBug1() { TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP); cache.addRelation(Triple.create(a, closedP, b)); cache.addRelation(Triple.create(c, closedP, a)); cache.addRelation(Triple.create(c, closedP, b)); cache.addRelation(Triple.create(a, closedP, c)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(a, directP, null)), new Object[] { Triple.create(a, closedP, a), @@ -332,12 +329,13 @@ public void testBug1() { * form a linear chain, with all closed links provided. But inserted * in a particular order. */ + @Test public void testBug2() { TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP); cache.addRelation(Triple.create(a, closedP, b)); cache.addRelation(Triple.create(a, closedP, c)); cache.addRelation(Triple.create(b, closedP, c)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(a, directP, null)), new Object[] { Triple.create(a, closedP, a), @@ -349,6 +347,7 @@ public void testBug2() { /** * Test the removeRelation functionality. */ + @Test public void testRemove() { TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP); cache.addRelation(Triple.create(a, closedP, b)); @@ -356,7 +355,7 @@ public void testRemove() { cache.addRelation(Triple.create(b, closedP, d)); cache.addRelation(Triple.create(c, closedP, d)); cache.addRelation(Triple.create(d, closedP, e)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(a, closedP, null)), new Object[] { Triple.create(a, closedP, a), @@ -366,7 +365,7 @@ public void testRemove() { Triple.create(a, closedP, d), Triple.create(a, closedP, e) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(b, closedP, null)), new Object[] { Triple.create(b, closedP, b), @@ -374,7 +373,7 @@ public void testRemove() { Triple.create(b, closedP, e) }); cache.removeRelation(Triple.create(b, closedP, d)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(a, closedP, null)), new Object[] { Triple.create(a, closedP, a), @@ -384,19 +383,19 @@ public void testRemove() { Triple.create(a, closedP, d), Triple.create(a, closedP, e) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(b, closedP, null)), new Object[] { Triple.create(b, closedP, b), }); cache.removeRelation(Triple.create(a, closedP, c)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(a, closedP, null)), new Object[] { Triple.create(a, closedP, a), Triple.create(a, closedP, b) }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(b, closedP, null)), new Object[] { Triple.create(b, closedP, b), @@ -406,13 +405,14 @@ public void testRemove() { /** * Test direct link case with adverse ordering. */ + @Test public void testDirect() { TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP); cache.addRelation(Triple.create(a, closedP, b)); cache.addRelation(Triple.create(c, closedP, d)); cache.addRelation(Triple.create(a, closedP, d)); cache.addRelation(Triple.create(b, closedP, c)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(a, directP, null)), new Object[] { Triple.create(a, closedP, a), @@ -423,13 +423,14 @@ public void testDirect() { /** * Test cycle detection. */ + @Test public void testCycle() { TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP); cache.addRelation(Triple.create(a, closedP, b)); cache.addRelation(Triple.create(b, closedP, c)); cache.addRelation(Triple.create(a, closedP, c)); cache.addRelation(Triple.create(c, closedP, b)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(a, directP, null)), new Object[] { Triple.create(a, closedP, a), @@ -441,6 +442,7 @@ public void testCycle() { /** * A ring of three cycle */ + @Test public void testCycle2() { TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP); cache.addRelation(Triple.create(a, closedP, b)); @@ -452,7 +454,7 @@ public void testCycle2() { cache.addRelation(Triple.create(d, closedP, e)); cache.addRelation(Triple.create(c, closedP, e)); cache.addRelation(Triple.create(c, closedP, b)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(c, directP, null)), new Object[] { Triple.create(c, closedP, e), @@ -461,7 +463,7 @@ public void testCycle2() { Triple.create(c, closedP, d), Triple.create(c, closedP, c), }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(null, directP, c)), new Object[] { Triple.create(a, closedP, c), @@ -470,7 +472,7 @@ public void testCycle2() { Triple.create(f, closedP, c), Triple.create(c, closedP, c), }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(f, closedP, null)), new Object[] { Triple.create(f, closedP, f), @@ -485,6 +487,7 @@ public void testCycle2() { /** * Two ring-of-three cycles joined at two points */ + @Test public void testCycle3() { TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP); cache.addRelation(Triple.create(a, closedP, b)); @@ -495,7 +498,7 @@ public void testCycle3() { cache.addRelation(Triple.create(f, closedP, d)); cache.addRelation(Triple.create(b, closedP, d)); cache.addRelation(Triple.create(f, closedP, c)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(a, directP, null)), new Object[] { Triple.create(a, closedP, a), @@ -505,7 +508,7 @@ public void testCycle3() { Triple.create(a, closedP, e), Triple.create(a, closedP, f), }); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(null, directP, a)), new Object[] { Triple.create(a, closedP, a), @@ -520,11 +523,12 @@ public void testCycle3() { /** * Test simple equivalences case */ + @Test public void testEquivalencesSimple() { TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP); cache.addRelation(Triple.create(a, closedP, b)); cache.addRelation(Triple.create(b, closedP, a)); - TestUtil.assertIteratorValues(this, + TestUtil.assertIteratorValues( cache.find(new TriplePattern(null, closedP, null)), new Object[] { Triple.create(a, closedP, b), @@ -532,12 +536,13 @@ public void testEquivalencesSimple() { Triple.create(b, closedP, b), Triple.create(a, closedP, a), }); - TestUtil.assertIteratorLength( cache.find(new TriplePattern(null, closedP, null)), 4); + TestUtil.assertIteratorLength(cache.find(new TriplePattern(null, closedP, null)), 4); } /** * Test equivalences case */ + @Test public void testEquivalences() { TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP); cache.addRelation(Triple.create(a, closedP, b)); @@ -549,7 +554,7 @@ public void testEquivalences() { cache.addRelation(Triple.create(b, closedP, d)); cache.addRelation(Triple.create(d, closedP, b)); - assertTrue("Test eq", cache.contains(new TriplePattern(a, closedP, d))); + assertTrue(cache.contains(new TriplePattern(a, closedP, d)), "Test eq"); } } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil.java index c8e381ec2e4..0eba8d84b0f 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil.java @@ -21,59 +21,62 @@ package org.apache.jena.reasoner.test; +import static org.junit.jupiter.api.Assertions.*; + import java.util.Iterator; -import org.apache.jena.rdf.model.Resource; -import org.apache.jena.rdf.model.Statement; -import org.junit.Assert; -import junit.framework.TestCase; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.Statement; + /** * Collection of utilities to assist with unit testing. + *

+ * JUnit6 counterpart of the {@code assertIterator*} methods of {@link TestUtil}. + * The {@code junit.framework.TestCase} argument of the originals has been + * dropped: it served only to label failure messages and to name the logger, + * both of which JUnit6 reports for itself. */ public class TestUtil { - + + private static final Logger LOG = LoggerFactory.getLogger( TestUtil.class ); + /** * Helper method to test an iterator against a list of objects - order independent - * @param testCase The JUnit test case that is invoking this helper * @param it The iterator to test * @param vals The expected values of the iterator */ - public static void assertIteratorValues(TestCase testCase, Iterator it, Object[] vals) { - assertIteratorValues( testCase, it, vals, 0 ); + public static void assertIteratorValues(Iterator it, Object[] vals) { + assertIteratorValues( it, vals, 0 ); } - + /** * Helper method to test an iterator against a list of objects - order independent, and - * can optionally check the count of anonymous resources. This allows us to test a - * iterator of resource values which includes both URI nodes and bNodes. - * @param testCase The JUnit test case that is invoking this helper + * can optionally check the count of anonymous resources. This allows us to test a + * iterator of resource values which includes both URI nodes and bNodes. * @param it The iterator to test * @param vals The expected values of the iterator * @param countAnon If non zero, count the number of anonymous resources returned by it, * and don't check these resources against the expected vals. */ - public static void assertIteratorValues(TestCase testCase, Iterator it, Object[] vals, int countAnon ) { - Logger logger = LoggerFactory.getLogger( testCase.getClass() ); - + public static void assertIteratorValues(Iterator it, Object[] vals, int countAnon ) { boolean[] found = new boolean[vals.length]; int anonFound = 0; - + for (int i = 0; i < vals.length; i++) found[i] = false; - - + while (it.hasNext()) { Object n = it.next(); boolean gotit = false; - + // do bNodes separately if (countAnon > 0 && isAnonValue( n )) { anonFound++; continue; } - + for (int i = 0; i < vals.length; i++) { if (n.equals(vals[i])) { gotit = true; @@ -81,24 +84,22 @@ public static void assertIteratorValues(TestCase testCase, Iterator it, Objec } } if (!gotit) { - logger.debug( testCase.getName() + " found unexpected iterator value: " + n); + LOG.debug( "found unexpected iterator value: " + n); } - Assert.assertTrue( testCase.getName() + " found unexpected iterator value: " + n, gotit); + assertTrue( gotit, "found unexpected iterator value: " + n); } - + // check that no expected values were unfound for (int i = 0; i < vals.length; i++) { if (!found[i]) { -// for (int j = 0; j < vals.length; j += 1) System.err.println( "#" + j + ": " + vals[j] ); - logger.debug( testCase.getName() + " failed to find expected iterator value: " + vals[i]); + LOG.debug( "failed to find expected iterator value: " + vals[i]); } - Assert.assertTrue(testCase.getName() + " failed to find expected iterator value: " + vals[i], found[i]); + assertTrue( found[i], "failed to find expected iterator value: " + vals[i]); } - + // check we got the right no. of anons - Assert.assertEquals( testCase.getName() + " iterator test did not find the right number of anon. nodes", countAnon, anonFound ); + assertEquals( countAnon, anonFound, "iterator test did not find the right number of anon. nodes" ); } - /** * Replace all blocks of white space by a single space character, just @@ -124,7 +125,7 @@ public static String normalizeWhiteSpace(String src) { } return result.toString(); } - + /** * Check the length of an iterator. */ @@ -134,10 +135,9 @@ public static void assertIteratorLength(Iterator it, int expectedLength) { it.next(); length++; } - Assert.assertEquals(expectedLength, length); + assertEquals(expectedLength, length); } - - + /** * For the purposes of counting, a value is anonymous if (a) it is an anonymous resource, * or (b) it is a statement with a bNode subject or (c) it is a statement with a bNode diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil_JU6.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil_JU6.java deleted file mode 100644 index db3b6a35cfd..00000000000 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil_JU6.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.reasoner.test; - -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Iterator; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.jena.rdf.model.Resource; -import org.apache.jena.rdf.model.Statement; - -/** - * Collection of utilities to assist with unit testing. - *

- * JUnit6 counterpart of the {@code assertIterator*} methods of {@link TestUtil}. - * The {@code junit.framework.TestCase} argument of the originals has been - * dropped: it served only to label failure messages and to name the logger, - * both of which JUnit6 reports for itself. - */ -public class TestUtil_JU6 { - - private static final Logger LOG = LoggerFactory.getLogger( TestUtil_JU6.class ); - - /** - * Helper method to test an iterator against a list of objects - order independent - * @param it The iterator to test - * @param vals The expected values of the iterator - */ - public static void assertIteratorValues(Iterator it, Object[] vals) { - assertIteratorValues( it, vals, 0 ); - } - - /** - * Helper method to test an iterator against a list of objects - order independent, and - * can optionally check the count of anonymous resources. This allows us to test a - * iterator of resource values which includes both URI nodes and bNodes. - * @param it The iterator to test - * @param vals The expected values of the iterator - * @param countAnon If non zero, count the number of anonymous resources returned by it, - * and don't check these resources against the expected vals. - */ - public static void assertIteratorValues(Iterator it, Object[] vals, int countAnon ) { - boolean[] found = new boolean[vals.length]; - int anonFound = 0; - - for (int i = 0; i < vals.length; i++) found[i] = false; - - while (it.hasNext()) { - Object n = it.next(); - boolean gotit = false; - - // do bNodes separately - if (countAnon > 0 && isAnonValue( n )) { - anonFound++; - continue; - } - - for (int i = 0; i < vals.length; i++) { - if (n.equals(vals[i])) { - gotit = true; - found[i] = true; - } - } - if (!gotit) { - LOG.debug( "found unexpected iterator value: " + n); - } - assertTrue( gotit, "found unexpected iterator value: " + n); - } - - // check that no expected values were unfound - for (int i = 0; i < vals.length; i++) { - if (!found[i]) { - LOG.debug( "failed to find expected iterator value: " + vals[i]); - } - assertTrue( found[i], "failed to find expected iterator value: " + vals[i]); - } - - // check we got the right no. of anons - assertEquals( countAnon, anonFound, "iterator test did not find the right number of anon. nodes" ); - } - - /** - * Check the length of an iterator. - */ - public static void assertIteratorLength(Iterator it, int expectedLength) { - int length = 0; - while (it.hasNext()) { - it.next(); - length++; - } - assertEquals(expectedLength, length); - } - - /** - * For the purposes of counting, a value is anonymous if (a) it is an anonymous resource, - * or (b) it is a statement with a bNode subject or (c) it is a statement with a bNode - * object. This is because we cannot check bNode identity against fixed expected data values. - * @param n A value - * @return True if n is anonymous - */ - protected static boolean isAnonValue( Object n ) { - return ((n instanceof Resource) && ((Resource) n).isAnon()) || - ((n instanceof Statement) && ((Statement) n).getSubject().isAnon()) || - ((n instanceof Statement) && isAnonValue( ((Statement) n).getObject() )); - } -} diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/WGReasonerTester.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/WGReasonerTester.java index 68865e693ef..6751b2e07dd 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/WGReasonerTester.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/WGReasonerTester.java @@ -32,7 +32,6 @@ import org.junit.Assert; -import junit.framework.TestCase; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphMemFactory; import org.apache.jena.rdf.model.*; @@ -208,13 +207,13 @@ private Graph loadTestFile(Resource test, Property predicate) throws IOException /** * 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 testcase non-null if the caller wants a failed test to assert * @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, Object testcase, Resource configuration) throws IOException { for ( String test : listTests() ) { if ( !runTest( test, reasonerF, testcase, configuration ) ) @@ -253,13 +252,13 @@ public Resource getTypeOfLastTest() { * 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 testcase non-null if the caller wants a failed test to assert * @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, Object testcase, Resource configuration) throws IOException { return runTestDetailedResponse(uri,reasonerF,testcase,configuration) != FAIL; } static final public int FAIL = -1; @@ -271,7 +270,7 @@ public boolean runTest(String uri, ReasonerFactory reasonerF, TestCase testcase, * 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 testcase non-null if the caller wants a failed test to assert * @param configuration optional configuration information * @return true if the test passes * @throws IOException if one of the test files can't be found @@ -279,7 +278,7 @@ public boolean runTest(String uri, ReasonerFactory reasonerF, TestCase testcase, */ - public int runTestDetailedResponse(String uri, ReasonerFactory reasonerF, TestCase testcase, Resource configuration) throws IOException { + public int runTestDetailedResponse(String uri, ReasonerFactory reasonerF, Object testcase, Resource configuration) throws IOException { // Find the specification for the named test Resource test = testManifest.getResource(uri); diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java index fb179f47b40..85d53ee94cd 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java @@ -62,7 +62,7 @@ static public TestSuite suite() { //JU6 addTest(ts, "Util", adaptJUnit4(org.apache.jena.util.TS4_coreutil.class)); //JU6 addTest(ts, "Jena iterator", adaptJUnit4(org.apache.jena.util.iterator.test.TS3_coreiter.class)); - addTest(ts, "Assembler", adaptJUnit4(org.apache.jena.assembler.TS3_Assembler.class)); +//JU6 addTest(ts, "Assembler", adaptJUnit4(org.apache.jena.assembler.TS3_Assembler.class)); //JU6 addTest(ts, "Vocabularies", adaptJUnit4(org.apache.jena.vocabulary.TS3_Vocabularies.class)); //JU6 addTest(ts, "Shared", adaptJUnit4(org.apache.jena.shared.TS_SharedPackage.class)); @@ -70,8 +70,8 @@ static public TestSuite suite() { // ** COMPLEX //JU6 addTest(ts, "Composed graphs", org.apache.jena.graph.compose.TS3_compose.suite() ); - addTest(ts, "Reasoners", adaptJUnit4(org.apache.jena.reasoner.test.TS3_reasoners.class)); - addTest(ts, "RuleReasoners", adaptJUnit4(org.apache.jena.reasoner.rulesys.TS3_RuleReasoners.class)); +//JU6 addTest(ts, "Reasoners", adaptJUnit4(org.apache.jena.reasoner.test.TS3_reasoners.class)); +//JU6 addTest(ts, "RuleReasoners", adaptJUnit4(org.apache.jena.reasoner.rulesys.TS3_RuleReasoners.class)); //JU6 addTest(ts, "Ontology ModelMaker", adaptJUnit4(org.apache.jena.ontology.makers.TS3_ModelMakers.class)); //JU6 addTest(ts, "Ontology", adaptJUnit4(org.apache.jena.ontology.impl.TS3_ont.class)); diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java index 13a9c8132c1..3fc600cc5e7 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU6.java @@ -25,6 +25,7 @@ import org.junit.platform.suite.api.SelectClasses; import org.junit.platform.suite.api.Suite; +import org.apache.jena.assembler.TS6_Assembler; import org.apache.jena.core_ttl.tests.TS6_TestTurtle; import org.apache.jena.datatypes.TS6_dt; import org.apache.jena.graph.TS6_graph; @@ -38,6 +39,8 @@ import org.apache.jena.ontology.makers.TS6_ModelMakers; import org.apache.jena.rdf.model.TS6_Model; import org.apache.jena.rdfxml.xmloutput.TS6_xmloutput; +import org.apache.jena.reasoner.rulesys.TS6_RuleReasoners; +import org.apache.jena.reasoner.test.TS6_reasoners; import org.apache.jena.shared.TS6_SharedPackage; import org.apache.jena.util.TS6_coreutil; import org.apache.jena.util.iterator.TS6_coreiter; @@ -72,6 +75,11 @@ TS6_compose.class, + TS6_Assembler.class, + + TS6_reasoners.class, + TS6_RuleReasoners.class, + TS6_ModelMakers.class, TS6_ont.class, From 7c63850147a96e149e542a89c1ae8c842fc90c9c Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Mon, 7 Sep 2026 20:52:00 +0100 Subject: [PATCH 11/12] GH-3236: Remove more JUnit3 --- jena-core/pom.xml | 3 +- .../jena/assembler/MockTransactionModel.java | 4 +- .../jena/assembler/TestModelAssembler.java | 2 - .../assembler/TestPrefixMappingAssembler.java | 2 - .../org/apache/jena/graph/GraphTestLib.java | 20 +- .../apache/jena/graph/RecordingListener.java | 8 +- .../apache/jena/graph/TestGraphListener.java | 2 +- .../jena/junit/AbstractRecordingListener.java | 14 +- .../org/apache/jena/junit/GraphHelper.java | 18 +- .../org/apache/jena/junit/TestUtils4.java | 13 +- .../jena/ontology/impl/OntTestBase.java | 8 - .../jena/ontology/impl/OntTestUtil.java | 6 - .../apache/jena/rdf/model/ModelTestLib.java | 8 +- .../rdf/model/RecordingModelListener.java | 10 +- .../jena/rdf/model/helpers/ModelHelper.java | 17 +- .../model/helpers/RecordingModelListener.java | 10 +- ...TS3_xmlinput1.java => TS3_rdfxml_arp.java} | 10 +- .../rdfxml/xmloutput/BaseTestXMLOutput.java | 3 +- .../reasoner/rulesys/TS6_RuleReasoners.java | 8 +- .../reasoner/rulesys/test/OWLWGTester.java | 4 +- .../reasoner/rulesys/test/TestBasicLP.java | 3 - .../reasoner/rulesys/test/TestLPRDFS.java | 67 ++---- .../rulesys/test/TestOWLConsistency.java | 86 +++---- .../jena/reasoner/rulesys/test/TestRDFS9.java | 42 ++-- .../reasoner/rulesys/test/TestRDFSRules.java | 73 +++--- .../reasoner/rulesys/test/TestRuleLoader.java | 25 +- .../rulesys/test/TestTrialOWLRules.java | 226 ------------------ .../jena/reasoner/test/ReasonerTester.java | 4 +- .../jena/reasoner/test/TestCurrentRDFWG.java | 159 ------------ .../jena/reasoner/test/TestInfModel.java | 2 - .../jena/reasoner/test/TestRDFSReasoners.java | 3 +- .../apache/jena/reasoner/test/TestUtil.java | 7 +- .../jena/reasoner/test/WGReasonerTester.java | 4 +- .../apache/jena/test/JenaCoreTestAll_JU3.java | 46 ++++ .../apache/jena/test/JenaCoreTestAll_JU4.java | 103 -------- .../org/apache/jena/test/JenaTestLib.java | 4 +- .../jena/util/iterator/TestAndThen.java | 10 +- .../jena/util/iterator/TestAsCollection.java | 2 +- .../jena/util/iterator/TestFilters.java | 2 +- .../util/iterator/TestWrappedIterator.java | 2 +- .../apache/jena/vocabulary/VocabTestLib.java | 2 +- 41 files changed, 259 insertions(+), 783 deletions(-) rename jena-core/src/test/java/org/apache/jena/rdfxml/arp1tests/{TS3_xmlinput1.java => TS3_rdfxml_arp.java} (88%) mode change 100755 => 100644 jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFSRules.java delete mode 100644 jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestTrialOWLRules.java delete mode 100644 jena-core/src/test/java/org/apache/jena/reasoner/test/TestCurrentRDFWG.java create mode 100644 jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU3.java delete mode 100644 jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java diff --git a/jena-core/pom.xml b/jena-core/pom.xml index 9f3e3e69e3d..5e325527990 100644 --- a/jena-core/pom.xml +++ b/jena-core/pom.xml @@ -75,6 +75,7 @@ test + org.junit.vintage junit-vintage-engine @@ -149,7 +150,7 @@ -XX:+EnableDynamicAgentLoading -Xshare:off org/apache/jena/test/JenaCoreTestAll_JU6.java - org/apache/jena/test/JenaCoreTestAll_JU4.java + org/apache/jena/test/JenaCoreTestAll_JU3.java diff --git a/jena-core/src/test/java/org/apache/jena/assembler/MockTransactionModel.java b/jena-core/src/test/java/org/apache/jena/assembler/MockTransactionModel.java index c65f8a17c51..f68886d0ce7 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/MockTransactionModel.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/MockTransactionModel.java @@ -28,7 +28,7 @@ import org.apache.jena.rdf.model.*; import org.apache.jena.rdf.model.impl.ModelCom; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * A model assembler that creates a model with controllable supporting of @@ -55,7 +55,7 @@ protected Model openEmptyModel(Assembler a, Resource root, Mode irrelevant) { @Override public Model begin() { history.add("begin"); - Assert.assertTrue(isEmpty()); + assertTrue(isEmpty()); return this; } diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestModelAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestModelAssembler.java index d7e20c3f323..0461db21d94 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestModelAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestModelAssembler.java @@ -21,8 +21,6 @@ package org.apache.jena.assembler; -import static org.junit.jupiter.api.Assertions.*; - import org.junit.jupiter.api.Test; import org.apache.jena.assembler.assemblers.ContentAssembler; diff --git a/jena-core/src/test/java/org/apache/jena/assembler/TestPrefixMappingAssembler.java b/jena-core/src/test/java/org/apache/jena/assembler/TestPrefixMappingAssembler.java index 70e47175646..eb6418ad0bb 100644 --- a/jena-core/src/test/java/org/apache/jena/assembler/TestPrefixMappingAssembler.java +++ b/jena-core/src/test/java/org/apache/jena/assembler/TestPrefixMappingAssembler.java @@ -21,8 +21,6 @@ package org.apache.jena.assembler; -import static org.junit.jupiter.api.Assertions.*; - import org.junit.jupiter.api.Test; import org.apache.jena.assembler.assemblers.PrefixMappingAssembler; diff --git a/jena-core/src/test/java/org/apache/jena/graph/GraphTestLib.java b/jena-core/src/test/java/org/apache/jena/graph/GraphTestLib.java index b8f5c125678..b9556fad210 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/GraphTestLib.java +++ b/jena-core/src/test/java/org/apache/jena/graph/GraphTestLib.java @@ -21,6 +21,11 @@ package org.apache.jena.graph; +import static org.apache.jena.test.JenaTestLib.getConstructor; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.FileNotFoundException; import java.lang.reflect.Constructor; import java.net.URISyntaxException; @@ -34,9 +39,6 @@ import org.apache.jena.util.CollectionFactory; import org.apache.jena.util.iterator.ExtendedIterator; -import static junit.framework.TestCase.*; -import static org.apache.jena.test.JenaTestLib.getConstructor; - public class GraphTestLib { /** @@ -263,7 +265,7 @@ public static void assertIsomorphic(Graph expected, Graph got) { * containing name. */ public static void assertContains(String name, String s, Graph g) { - assertTrue(name + " must contain " + s, g.contains(triple(s))); + assertTrue(g.contains(triple(s)), name + " must contain " + s); } /** @@ -283,7 +285,7 @@ public static void assertContainsAll(String name, Graph g, String s) { name. */ public static void assertOmits(String name, Graph g, String s) { - assertFalse(name + " must not contain " + s, g.contains(triple(s))); + assertFalse(g.contains(triple(s)), name + " must not contain " + s); } /** @@ -310,7 +312,7 @@ public static boolean contains(Graph g, String fact) { */ public static void testContains(Graph g, Triple[] triples) { for ( Triple triple : triples ) { - assertTrue("contains " + triple, g.contains(triple)); + assertTrue(g.contains(triple), "contains " + triple); } } @@ -344,7 +346,7 @@ public static void testContains(Graph g, Graph other) { */ public static void testOmits(Graph g, Triple[] triples) { for ( Triple triple : triples ) { - assertFalse("", g.contains(triple)); + assertFalse(g.contains(triple)); } } @@ -354,7 +356,7 @@ public static void testOmits(Graph g, Triple[] triples) { */ public static void testOmits(Graph g, List triples) { for ( Triple triple : triples ) { - assertFalse("", g.contains(triple)); + assertFalse(g.contains(triple)); } } @@ -363,7 +365,7 @@ public static void testOmits(Graph g, List triples) { */ public static void testOmits(Graph g, Iterator it) { while (it.hasNext()) - assertFalse("", g.contains(it.next())); + assertFalse(g.contains(it.next())); } /** diff --git a/jena-core/src/test/java/org/apache/jena/graph/RecordingListener.java b/jena-core/src/test/java/org/apache/jena/graph/RecordingListener.java index f6d89191674..a2bee05c614 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/RecordingListener.java +++ b/jena-core/src/test/java/org/apache/jena/graph/RecordingListener.java @@ -26,7 +26,7 @@ import java.util.Iterator; import java.util.List; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.fail; import org.apache.jena.atlas.iterator.Iter; @@ -125,7 +125,7 @@ public boolean has(Object[] things) { public void assertHas(List things) { if ( has(things) == false ) - Assert.fail("expected " + things + " but got " + history); + fail("expected " + things + " but got " + history); } public void assertHas(Object[] things) { @@ -135,12 +135,12 @@ public void assertHas(Object[] things) { public void assertHasStart(Object[] start) { List L = Arrays.asList(start); if ( hasStart(L) == false ) - Assert.fail("expected " + L + " at the beginning of " + history); + fail("expected " + L + " at the beginning of " + history); } public void assertHasEnd(Object[] end) { List L = Arrays.asList(end); if ( hasEnd(L) == false ) - Assert.fail("expected " + L + " at the end of " + history); + fail("expected " + L + " at the end of " + history); } } diff --git a/jena-core/src/test/java/org/apache/jena/graph/TestGraphListener.java b/jena-core/src/test/java/org/apache/jena/graph/TestGraphListener.java index a8988195dc7..34626128194 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/TestGraphListener.java +++ b/jena-core/src/test/java/org/apache/jena/graph/TestGraphListener.java @@ -41,7 +41,7 @@ public class TestGraphListener extends BaseTestGraph { /** * The implementation used for the listener's copy of the graph. Extending - * MetaTestGraph_JU6 would inherit its argument source as well as this one, running + * MetaTestGraph would inherit its argument source as well as this one, running * every test once per implementation on top of these. */ @Parameter diff --git a/jena-core/src/test/java/org/apache/jena/junit/AbstractRecordingListener.java b/jena-core/src/test/java/org/apache/jena/junit/AbstractRecordingListener.java index ce69217c780..5485f5a6183 100644 --- a/jena-core/src/test/java/org/apache/jena/junit/AbstractRecordingListener.java +++ b/jena-core/src/test/java/org/apache/jena/junit/AbstractRecordingListener.java @@ -27,7 +27,7 @@ import java.util.Iterator; import java.util.List; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.fail; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.Statement; @@ -103,14 +103,14 @@ public final boolean has(Object... things) { public final void assertHas(Object... things) { if (has(things) == false) { int idx = differ(things); - Assert.fail("expected " + Arrays.asList(things) + " but got " + fail("expected " + Arrays.asList(things) + " but got " + history + " differ at position " + idx); } } public final void assertEmpty() { if (history.size() > 0) { - Assert.fail("Should be no history but got " + history); + fail("Should be no history but got " + history); } } @@ -135,25 +135,25 @@ public final boolean hasEnd(List L) { public final void assertHas(List things) { if (has(things) == false) - Assert.fail("expected " + things + " but got " + history); + fail("expected " + things + " but got " + history); } public final void assertContains(Object... things) { if (contains(things) == false) - Assert.fail(String.format("expected %s but got %s", + fail(String.format("expected %s but got %s", Arrays.asList(things), history)); } public final void assertHasStart(Object... start) { List L = Arrays.asList(start); if (hasStart(L) == false) - Assert.fail("expected " + L + " at the beginning of " + history); + fail("expected " + L + " at the beginning of " + history); } public final void assertHasEnd(Object... end) { List L = Arrays.asList(end); if (hasEnd(L) == false) - Assert.fail("expected " + L + " at the end of " + history); + fail("expected " + L + " at the end of " + history); } public final void clear() { diff --git a/jena-core/src/test/java/org/apache/jena/junit/GraphHelper.java b/jena-core/src/test/java/org/apache/jena/junit/GraphHelper.java index 388a06ecb39..8008bff734e 100644 --- a/jena-core/src/test/java/org/apache/jena/junit/GraphHelper.java +++ b/jena-core/src/test/java/org/apache/jena/junit/GraphHelper.java @@ -24,9 +24,9 @@ /** * Foo set of static test helpers. Generally included as a static. */ -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.lang.reflect.Constructor; import java.util.*; @@ -316,7 +316,7 @@ public static void assertIsomorphic(Graph expected, Graph got) { * message containing name. */ public static void assertContains(String name, String s, Graph g) { - assertTrue(name + " must contain " + s, g.contains(triple(s))); + assertTrue(g.contains(triple(s)), name + " must contain " + s); } /** @@ -336,7 +336,7 @@ public static void assertContainsAll(String name, Graph g, String s) { name. */ public static void assertOmits(String name, Graph g, String s) { - assertFalse(name + " must not contain " + s, g.contains(triple(s))); + assertFalse(g.contains(triple(s)), name + " must not contain " + s); } /** @@ -363,7 +363,7 @@ public static boolean contains(Graph g, String fact) { */ public static void testContains(Graph g, Triple[] triples) { for (int i = 0; i < triples.length; i += 1) - assertTrue("contains " + triples[i], g.contains(triples[i])); + assertTrue(g.contains(triples[i]), "contains " + triples[i]); } /** @@ -395,7 +395,7 @@ public static void testContains(Graph g, Graph other) { */ public static void testOmits(Graph g, Triple[] triples) { for (int i = 0; i < triples.length; i += 1) - assertFalse("", g.contains(triples[i])); + assertFalse(g.contains(triples[i])); } /** @@ -404,7 +404,7 @@ public static void testOmits(Graph g, Triple[] triples) { */ public static void testOmits(Graph g, List triples) { for (int i = 0; i < triples.size(); i += 1) - assertFalse("", g.contains(triples.get(i))); + assertFalse(g.contains(triples.get(i))); } /** @@ -413,7 +413,7 @@ public static void testOmits(Graph g, List triples) { */ public static void testOmits(Graph g, Iterator it) { while (it.hasNext()) - assertFalse("", g.contains(it.next())); + assertFalse(g.contains(it.next())); } /** diff --git a/jena-core/src/test/java/org/apache/jena/junit/TestUtils4.java b/jena-core/src/test/java/org/apache/jena/junit/TestUtils4.java index 05c4f4f30a1..4e54ae8df25 100644 --- a/jena-core/src/test/java/org/apache/jena/junit/TestUtils4.java +++ b/jena-core/src/test/java/org/apache/jena/junit/TestUtils4.java @@ -23,12 +23,11 @@ import org.slf4j.LoggerFactory; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Basis for Jena test cases which provides assertFalse and assertDiffer. * Often the logic of the names is clearer than using a negation. - * JUnit4. */ public class TestUtils4 { // do not instantiate, do not subclass. @@ -104,9 +103,9 @@ public static void assertEquivalent(Object o1, Object o2) { * @param o2 */ public static void assertEquivalent(String msg, Object o1, Object o2) { - assertEquals(msg, o1, o2); - assertEquals(msg, o2, o1); - assertEquals(msg, o1.hashCode(), o2.hashCode()); + assertEquals(o1, o2, msg); + assertEquals(o2, o1, msg); + assertEquals(o1.hashCode(), o2.hashCode(), msg); } /** @@ -116,8 +115,8 @@ public static void assertEquivalent(String msg, Object o1, Object o2) { * @param o2 */ public static void assertNotEquivalent(String msg, Object o1, Object o2) { - assertNotEquals(msg, o1, o2); - assertNotEquals(msg, o2, o1); + assertNotEquals(o1, o2, msg); + assertNotEquals(o2, o1, msg); } // FIXME this is to be removed when testing is complete diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestBase.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestBase.java index 98c7f5b3ad2..b4ba3f373c7 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestBase.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestBase.java @@ -37,14 +37,6 @@ *

* Generic test case for ontology unit testing. *

- *

- * JUnit6 counterpart of {@link OntTestBase}. The JUnit3 original was a - * {@code TestSuite} that built one {@code TestCase} per entry of - * {@link #getTests}; here the same array becomes one {@link DynamicTest} per - * entry, so the test count is unchanged. {@code OntTestCase} keeps the - * constructor and {@code ontTest} contract of the original, so sub-classes - * carry over unaltered. - *

*/ @SuppressWarnings("removal") public abstract class OntTestBase diff --git a/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestUtil.java b/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestUtil.java index 999de2ae119..baf8f2d903a 100644 --- a/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestUtil.java +++ b/jena-core/src/test/java/org/apache/jena/ontology/impl/OntTestUtil.java @@ -33,12 +33,6 @@ /** * Collection of utilities to assist with unit testing. - *

- * The {@code assertIterator*} methods are derived from - * {@link org.apache.jena.reasoner.test.TestUtil} so that this package can be - * migrated to JUnit6 independently. The {@code junit.framework.TestCase} - * argument of the originals has been dropped: it served only to label failure - * messages and to name the logger, both of which JUnit6 reports for itself. */ class OntTestUtil { diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/ModelTestLib.java b/jena-core/src/test/java/org/apache/jena/rdf/model/ModelTestLib.java index 6c3e7648cb4..f3da4463312 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/ModelTestLib.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/ModelTestLib.java @@ -21,9 +21,9 @@ package org.apache.jena.rdf.model; -import java.util.*; +import static org.junit.jupiter.api.Assertions.fail; -import org.junit.Assert; +import java.util.*; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphTestLib; @@ -56,13 +56,11 @@ public static void assertIsoModels(final Model wanted, final Model got) { * @param title a String appearing at the beginning of the failure message * @param wanted the model value that is expected * @param got the model value to check - * @exception junit.framework.AssertionFailedError if the models are not - * isomorphic */ public static void assertIsoModels(final String title, final Model wanted, final Model got) { if ( wanted.isIsomorphicWith(got) == false ) { final Map map = CollectionFactory.createHashedMap(); - Assert.fail(title + ": expected " + GraphTestLib.nice(wanted.getGraph(), map) + "\n but had " + fail(title + ": expected " + GraphTestLib.nice(wanted.getGraph(), map) + "\n but had " + GraphTestLib.nice(got.getGraph(), map)); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/RecordingModelListener.java b/jena-core/src/test/java/org/apache/jena/rdf/model/RecordingModelListener.java index c56bbcc0b9f..0b2b4ae341a 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/RecordingModelListener.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/RecordingModelListener.java @@ -25,7 +25,7 @@ import java.util.Arrays; import java.util.List; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.fail; import org.apache.jena.atlas.iterator.Iter; @@ -104,7 +104,7 @@ public boolean has(Object[] things) { public void assertHas(Object[] things) { if ( has(things) == false ) - Assert.fail("expected " + Arrays.asList(things) + " but got " + history); + fail("expected " + Arrays.asList(things) + " but got " + history); } public boolean has(List things) { @@ -121,19 +121,19 @@ public boolean hasEnd(List L) { public void assertHas(List things) { if ( has(things) == false ) - Assert.fail("expected " + things + " but got " + history); + fail("expected " + things + " but got " + history); } public void assertHasStart(Object[] start) { List L = Arrays.asList(start); if ( hasStart(L) == false ) - Assert.fail("expected " + L + " at the beginning of " + history); + fail("expected " + L + " at the beginning of " + history); } public void assertHasEnd(Object[] end) { List L = Arrays.asList(end); if ( hasEnd(L) == false ) - Assert.fail("expected " + L + " at the end of " + history); + fail("expected " + L + " at the end of " + history); } public void clear() { diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java b/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java index c64a71b9f04..00a1d73d422 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/ModelHelper.java @@ -21,10 +21,9 @@ package org.apache.jena.rdf.model.helpers; -import java.util.*; +import static org.junit.jupiter.api.Assertions.fail; -import junit.framework.TestCase; -import org.junit.Ignore; +import java.util.*; import org.apache.jena.graph.GraphTestLib; import org.apache.jena.graph.Node; @@ -36,18 +35,9 @@ /** provides useful functionality for testing models, eg building small models from strings, testing equality, etc. - - Currently this class extends TestCase. - - TODO: Refactoring should remove the TestCase dependency in future. - */ -@Ignore // ignore this class as a test case. -public class ModelHelper extends TestCase +public class ModelHelper { - private ModelHelper(String name) - { super(name); } - protected static Model aModel; static { @@ -175,7 +165,6 @@ public static Model modelAdd( Model m, String facts ) @param title a String appearing at the beginning of the failure message @param wanted the model value that is expected @param got the model value to check - @exception junit.framework.AssertionFailedError the models are not isomorphic */ public static void assertIsoModels( String title, Model wanted, Model got ) { diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/RecordingModelListener.java b/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/RecordingModelListener.java index b5f9a34e425..ef36b54dccb 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/RecordingModelListener.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/helpers/RecordingModelListener.java @@ -26,7 +26,7 @@ import java.util.Collection; import java.util.List; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.fail; import org.apache.jena.atlas.iterator.Iter; import org.apache.jena.rdf.model.Model; @@ -74,7 +74,7 @@ public void assertHas( final List things ) { if (has(things) == false) { - Assert.fail("expected " + things + " but got " + history); + fail("expected " + things + " but got " + history); } } @@ -82,7 +82,7 @@ public void assertHas( final Object[] things ) { if (has(things) == false) { - Assert.fail("expected " + Arrays.asList(things) + " but got " + fail("expected " + Arrays.asList(things) + " but got " + history); } } @@ -92,7 +92,7 @@ public void assertHasEnd( final Object[] end ) final List L = Arrays.asList(end); if (hasEnd(L) == false) { - Assert.fail("expected " + L + " at the end of " + history); + fail("expected " + L + " at the end of " + history); } } @@ -101,7 +101,7 @@ public void assertHasStart( final Object[] start ) final List L = Arrays.asList(start); if (hasStart(L) == false) { - Assert.fail("expected " + L + " at the beginning of " + history); + fail("expected " + L + " at the beginning of " + history); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdfxml/arp1tests/TS3_xmlinput1.java b/jena-core/src/test/java/org/apache/jena/rdfxml/arp1tests/TS3_rdfxml_arp.java similarity index 88% rename from jena-core/src/test/java/org/apache/jena/rdfxml/arp1tests/TS3_xmlinput1.java rename to jena-core/src/test/java/org/apache/jena/rdfxml/arp1tests/TS3_rdfxml_arp.java index ecb14d51ddd..3c4cd10e6aa 100644 --- a/jena-core/src/test/java/org/apache/jena/rdfxml/arp1tests/TS3_xmlinput1.java +++ b/jena-core/src/test/java/org/apache/jena/rdfxml/arp1tests/TS3_rdfxml_arp.java @@ -22,13 +22,17 @@ package org.apache.jena.rdfxml.arp1tests; import junit.framework.TestSuite; +import org.apache.jena.test.JenaTestLib; + +public class TS3_rdfxml_arp extends TestSuite { + + static { JenaTestLib.setup(); } -public class TS3_xmlinput1 extends TestSuite { static public TestSuite suite() { - return new TS3_xmlinput1(); + return new TS3_rdfxml_arp(); } - private TS3_xmlinput1() { + private TS3_rdfxml_arp() { super("RDF/XML Input ARP1"); addTest(TestURIs.suite()); addTest(TestSuiteWG_RDFXML.suite()); diff --git a/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/BaseTestXMLOutput.java b/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/BaseTestXMLOutput.java index 99d71e4a05e..104ab60504b 100644 --- a/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/BaseTestXMLOutput.java +++ b/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/BaseTestXMLOutput.java @@ -217,5 +217,4 @@ protected void checkZ(String filename, String encoding, String regexPresent, Str assertEquals(errorExpected, errorsFound, "Errors (not) detected."); } - - } +} diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TS6_RuleReasoners.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TS6_RuleReasoners.java index 6087f50d539..01e34d6b912 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TS6_RuleReasoners.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/TS6_RuleReasoners.java @@ -59,7 +59,13 @@ TestLPBRuleCloseBug.class, ConcurrencyTest.class, - TestRestrictionsDontNeedTyping.class + TestRestrictionsDontNeedTyping.class, + + TestLPRDFS.class, + TestOWLConsistency.class, + TestRuleLoader.class, + TestRDFSRules.class, + TestRDFS9.class }) public class TS6_RuleReasoners { diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLWGTester.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLWGTester.java index c3957765792..7a5db4920c7 100755 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLWGTester.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/OWLWGTester.java @@ -37,7 +37,7 @@ import org.apache.jena.util.FileManager; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.ReasonerVocabulary; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -225,7 +225,7 @@ public boolean runTest(Resource test, boolean log, boolean stats) throws IOExcep // Signal the results if (testcase != null) { - Assert.assertTrue("Test: " + test + "\n" + reasonerF.getURI() + "\n" + description, correct); + assertTrue(correct, "Test: " + test + "\n" + reasonerF.getURI() + "\n" + description); } return correct; } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasicLP.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasicLP.java index 282743dad8e..1b1bd46fc33 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasicLP.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBasicLP.java @@ -1199,9 +1199,6 @@ public void testRuleDerivations() { } out.flush(); - // PrintUtil.print renders a URI node with no matching prefix as . This - // expectation predates that and had gone stale unnoticed: the class was not - // reached by the JUnit 3 suite, so these tests had not been running. String testString = TestUtil.normalizeWhiteSpace("Rule testRule3 concluded (

) <-\n" + " Rule testRule1 concluded (

) <-\n" + " Fact (

)\r\n" + diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestLPRDFS.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestLPRDFS.java index c8d7f465ffc..d54c7b7bc2c 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestLPRDFS.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestLPRDFS.java @@ -19,24 +19,23 @@ * SPDX-License-Identifier: Apache-2.0 */ + package org.apache.jena.reasoner.rulesys.test; import java.io.IOException; +import java.util.List; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.jena.reasoner.*; -import org.apache.jena.reasoner.rulesys.*; -import org.apache.jena.reasoner.test.ReasonerTester; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.junit.jupiter.api.Test; -import java.util.*; +import org.apache.jena.reasoner.Reasoner; +import org.apache.jena.reasoner.rulesys.FBRuleReasoner; +import org.apache.jena.reasoner.rulesys.Rule; +import org.apache.jena.reasoner.test.ReasonerTester; /** * Test an FB hybrid using the emerging LP engine on the basic RDFS tests. */ -public class TestLPRDFS extends TestCase { +public class TestLPRDFS { /** The location of the OWL rule definitions on the class path */ public static final String RULE_FILE = "etc/rdfs-fb-lp-expt.rules"; @@ -44,105 +43,92 @@ public class TestLPRDFS extends TestCase { /** The parsed rules */ protected static List ruleSet; - /** The tester utility */ - protected ReasonerTester tester; - - static Logger logger = LoggerFactory.getLogger(TestLPRDFS.class); - - /** - * Boilerplate for junit - */ - public TestLPRDFS( String name ) { - super( name ); - } - - /** - * Boilerplate for junit. - * This is its own test suite - */ - public static TestSuite suite() { - return new TestSuite(TestLPRDFS.class); -// TestSuite suite = new TestSuite(); -// try { -// TestRDFSReasoners.constructQuerytests( -// suite, -// "rdfs/manifest-nodirect-noresource.rdf", -// makeReasoner()); -// } catch (IOException e) { -// // failed to even built the test harness -// logger.error("Failed to construct RDFS test harness", e); -// } -// return suite; - } - + @Test public void test1() throws IOException { doTest("test1"); } + @Test public void test2() throws IOException { doTest("test2"); } + @Test public void test3() throws IOException { doTest("test3"); } + @Test public void test4() throws IOException { doTest("test4"); } + @Test public void test5() throws IOException { doTest("test5"); } + @Test public void test6() throws IOException { doTest("test6"); } + @Test public void test7() throws IOException { doTest("test7"); } + @Test public void test8() throws IOException { doTest("test8"); } + @Test public void test9() throws IOException { doTest("test9"); } + @Test public void test10() throws IOException { doTest("test10"); } + @Test public void test11() throws IOException { doTest("test11"); } + @Test public void test12() throws IOException { doTest("test12"); } + @Test public void test13() throws IOException { doTest("test13"); } + @Test public void test14() throws IOException { doTest("test14"); } + @Test public void test15() throws IOException { doTest("test15"); } + @Test public void test16() throws IOException { doTest("test16"); } + @Test public void test18() throws IOException { doTest("test18"); } + @Test public void test20() throws IOException { doTest("test20"); } @@ -171,5 +157,4 @@ public static List loadRules() { if (ruleSet == null) ruleSet = FBRuleReasoner.loadRules( RULE_FILE ); return ruleSet; } - } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestOWLConsistency.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestOWLConsistency.java index fe182547f79..8f8f1c2674d 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestOWLConsistency.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestOWLConsistency.java @@ -19,46 +19,32 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.apache.jena.reasoner.rulesys.test; +package org.apache.jena.reasoner.rulesys.test; -//import java.util.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.jena.rdf.model.*; -import org.apache.jena.reasoner.*; +import org.apache.jena.rdf.model.InfModel; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.reasoner.Reasoner; +import org.apache.jena.reasoner.ReasonerRegistry; +import org.apache.jena.reasoner.ValidityReport; import org.apache.jena.util.FileManager; /** * Test the preliminary OWL validation rules. */ -public class TestOWLConsistency extends TestCase { - +public class TestOWLConsistency { + /** The tbox/ontology file to test against sample data */ public static final String testTbox = "file:testing/reasoners/owl/tbox.owl"; - + /** A cached copy of the bound reasoner */ public static Reasoner reasonerCache; - - /** - * Boilerplate for junit - */ - public TestOWLConsistency( String name ) { - super( name ); - } - - /** - * Boilerplate for junit. - * This is its own test suite - */ - public static TestSuite suite() { - return new TestSuite( TestOWLConsistency.class ); -// TestSuite suite = new TestSuite(); -// suite.addTest(new TestOWLConsistency( "testInconsistent5" )); -// return suite; - } /** * Create, or retrieve from cache, an OWL reasoner already bound @@ -71,75 +57,71 @@ public Reasoner makeReasoner() { } return reasonerCache; } - + /** * Should be consistent. */ + @Test public void testConsistent() { assertTrue(doTestOn("file:testing/reasoners/owl/consistentData.rdf")); } - + /** * Should find problem due to overlap of disjoint classes. */ + @Test public void testInconsistent1() { - assertTrue( ! doTestOn("file:testing/reasoners/owl/inconsistent1.rdf")); + assertFalse(doTestOn("file:testing/reasoners/owl/inconsistent1.rdf")); } - + /** * Should find problem due to type violations */ + @Test public void testInconsistent2() { - assertTrue( ! doTestOn("file:testing/reasoners/owl/inconsistent2.rdf")); + assertFalse(doTestOn("file:testing/reasoners/owl/inconsistent2.rdf")); } - + /** * Should find problem due to count violations */ + @Test public void testInconsistent3() { - assertTrue( ! doTestOn("file:testing/reasoners/owl/inconsistent3.rdf")); + assertFalse(doTestOn("file:testing/reasoners/owl/inconsistent3.rdf")); } - + /** * Should find distinct values for a functional property */ + @Test public void testInconsistent4() { - assertTrue( ! doTestOn("file:testing/reasoners/owl/inconsistent4.rdf")); + assertFalse(doTestOn("file:testing/reasoners/owl/inconsistent4.rdf")); } - + /** * Should find type clash due to allValuesFrom rdfs:Literal */ + @Test public void testInconsistent5() { - assertTrue( ! doTestOn("file:testing/reasoners/owl/inconsistent5.rdf")); + assertFalse(doTestOn("file:testing/reasoners/owl/inconsistent5.rdf")); } - + /** * Should find distinct literal values for a functional property * via an indirect sameAs */ + @Test public void testInconsistent7() { - assertTrue( ! doTestOn("file:testing/reasoners/owl/inconsistent7.rdf")); + assertFalse(doTestOn("file:testing/reasoners/owl/inconsistent7.rdf")); } - + /** * Run a single consistency test on the given data file. */ private boolean doTestOn(String dataFile) { -// System.out.println("Test: " + dataFile); Model data = FileManager.getInternal().loadModelInternal(dataFile); InfModel infmodel = ModelFactory.createInfModel(makeReasoner(), data); ValidityReport reportList = infmodel.validate(); - /* Debug only - if (reportList.isValid()) { - System.out.println("No reported problems"); - } else { - for (Iterator i = reportList.getReports(); i.hasNext(); ) { - ValidityReport.Report report = (ValidityReport.Report)i.next(); - System.out.println("- " + report); - } - } - */ return reportList.isValid(); } } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFS9.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFS9.java index 762a6d58280..0a78a4c7d72 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFS9.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFS9.java @@ -19,51 +19,45 @@ * SPDX-License-Identifier: Apache-2.0 */ + package org.apache.jena.reasoner.rulesys.test; -import java.util.*; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Iterator; + +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.jena.graph.*; +import org.apache.jena.graph.Graph; +import org.apache.jena.graph.GraphMemFactory; +import org.apache.jena.graph.Node; +import org.apache.jena.graph.NodeFactory; +import org.apache.jena.graph.Triple; import org.apache.jena.graph.compose.Union; -import org.apache.jena.reasoner.*; +import org.apache.jena.reasoner.InfGraph; +import org.apache.jena.reasoner.ReasonerRegistry; import org.apache.jena.reasoner.test.TestUtil; -import org.apache.jena.vocabulary.*; +import org.apache.jena.vocabulary.RDF; +import org.apache.jena.vocabulary.RDFS; /** * Test harness used in debugging some issues with execution * of modified versions of rule rdfs9. */ -public class TestRDFS9 extends TestCase { - - /** - * Boilerplate for junit - */ - public TestRDFS9( String name ) { - super( name ); - } - - /** - * Boilerplate for junit. - * This is its own test suite - */ - public static TestSuite suite() { - return new TestSuite(TestRDFS9.class); - } +public class TestRDFS9 { - private static Graph createGraphForTest() { + private static Graph createGraphForTest() { return GraphMemFactory.createDefaultGraph(); } /** * Test a type inheritance example. */ + @Test public void testRDFSInheritance() { Node C1 = NodeFactory.createURI("C1"); Node C2 = NodeFactory.createURI("C2"); Node C3 = NodeFactory.createURI("C3"); - Node C4 = NodeFactory.createURI("C4"); Node D = NodeFactory.createURI("D"); Node a = NodeFactory.createURI("a"); Node b = NodeFactory.createURI("b"); diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFSRules.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFSRules.java old mode 100755 new mode 100644 index 5fb60d78529..1b1abba0ef6 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFSRules.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRDFSRules.java @@ -19,10 +19,19 @@ * SPDX-License-Identifier: Apache-2.0 */ + package org.apache.jena.reasoner.rulesys.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.util.Iterator; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Resource; @@ -36,87 +45,68 @@ import org.apache.jena.vocabulary.OWL; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDFS; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.Iterator; /** Test suite to test the production rule version of the RDFS implementation. *

The tests themselves have been replaced by an updated version * of the top level TestRDFSReasoners but this file is maintained for now since * the top level timing test can sometimes be useful.

*/ -public class TestRDFSRules extends TestCase { +public class TestRDFSRules { /** Base URI for the test names */ public static final String NAMESPACE = "http://www.hpl.hp.com/semweb/2003/query_tester/"; - + protected static Logger logger = LoggerFactory.getLogger(TestRDFSRules.class); - - /** - * Boilerplate for junit - */ - public TestRDFSRules( String name ) { - super( name ); - } - - /** - * Boilerplate for junit. - * This is its own test suite - */ - public static TestSuite suite() { - return new TestSuite(TestRDFSRules.class); -// TestSuite suite = new TestSuite(); -// suite.addTest(new TestRDFSRules( "hiddenTestRDFSReasonerDebug" )); -// return suite; - } /** * Test a single RDFS case. + * Not run as part of the suite - the name does not start "test". */ public void hiddenTestRDFSReasonerDebug() throws IOException { ReasonerTester tester = new ReasonerTester("rdfs/manifest-nodirect-noresource.rdf"); ReasonerFactory rf = RDFSRuleReasonerFactory.theInstance(); - - assertTrue("RDFS hybrid-tgc reasoner test", tester.runTest("http://www.hpl.hp.com/semweb/2003/query_tester/rdfs/test11", rf, this, null)); + + assertTrue(tester.runTest("http://www.hpl.hp.com/semweb/2003/query_tester/rdfs/test11", rf, this, null), + "RDFS hybrid-tgc reasoner test"); } /** * Test the basic functioning of the hybrid RDFS rule reasoner */ + @Test public void testRDFSFBReasoner() throws IOException { ReasonerTester tester = new ReasonerTester("rdfs/manifest-nodirect-noresource.rdf"); ReasonerFactory rf = RDFSFBRuleReasonerFactory.theInstance(); - assertTrue("RDFS hybrid reasoner tests", tester.runTests(rf, this, null)); + assertTrue(tester.runTests(rf, this, null), "RDFS hybrid reasoner tests"); } /** * Test the basic functioning of the hybrid RDFS rule reasoner with TGC cache */ + @Test public void testRDFSExptReasoner() throws IOException { ReasonerTester tester = new ReasonerTester("rdfs/manifest-nodirect-noresource.rdf"); ReasonerFactory rf = RDFSRuleReasonerFactory.theInstance(); - assertTrue("RDFS experimental (hybrid+tgc) reasoner tests", tester.runTests(rf, this, null)); + assertTrue(tester.runTests(rf, this, null), "RDFS experimental (hybrid+tgc) reasoner tests"); } /** * Test the capabilities description. */ + @Test public void testRDFSDescription() { ReasonerFactory rf = RDFSFBRuleReasonerFactory.theInstance(); Reasoner r = rf.create(null); - assertTrue(r.supportsProperty(RDFS.subClassOf)); - assertTrue(r.supportsProperty(RDFS.domain)); - assertTrue( ! r.supportsProperty(OWL.allValuesFrom)); + assertTrue(r.supportsProperty(RDFS.subClassOf)); + assertTrue(r.supportsProperty(RDFS.domain)); + assertFalse(r.supportsProperty(OWL.allValuesFrom)); } - + /** * Time a trial list of results from an inf graph. */ private static void doTiming(Reasoner r, Model tbox, Model data, String name, int loop) { Resource C1 = ResourceFactory.createResource("http://www.hpl.hp.com/semweb/2003/eg#C1"); - Resource C2 = ResourceFactory.createResource("http://www.hpl.hp.com/semweb/2003/eg#C2"); - + long t1 = System.currentTimeMillis(); int count = 0; for (int lp = 0; lp < loop; lp++) { @@ -129,12 +119,5 @@ private static void doTiming(Reasoner r, Model tbox, Model data, String name, in long time = time10/10; long timeFraction = time10 - (time*10); System.out.println(name + ": " + count +" results in " + time + "." + timeFraction +"ms"); -// t1 = System.currentTimeMillis(); -// for (int j = 0; j < 10; j++) { -// count = 0; -// for (Iterator i = m.listStatements(null, RDF.type, C1); i.hasNext(); i.next()) count++; -// } -// t2 = System.currentTimeMillis(); -// System.out.println(name + ": " + count + " results in " + (t2-t1)/10 +"ms"); - } + } } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRuleLoader.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRuleLoader.java index 8d8c0f3d9d6..05d607cf3bd 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRuleLoader.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestRuleLoader.java @@ -19,24 +19,27 @@ * SPDX-License-Identifier: Apache-2.0 */ + package org.apache.jena.reasoner.rulesys.test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.List; + +import org.junit.jupiter.api.Test; + import org.apache.jena.reasoner.rulesys.BuiltinRegistry; import org.apache.jena.reasoner.rulesys.MapBuiltinRegistry; import org.apache.jena.reasoner.rulesys.Rule; import org.apache.jena.reasoner.rulesys.builtins.BaseBuiltin; import org.apache.jena.shared.RulesetNotFoundException; import org.apache.jena.shared.WrappedIOException; -import org.junit.Test; - -import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; /** * Tests for the rule loader */ -public class TestRuleLoader { +public class TestRuleLoader { private static BuiltinRegistry createBuiltinRegistry() { BuiltinRegistry br = new MapBuiltinRegistry(); @@ -49,9 +52,10 @@ public String getName() { return br; } - @Test(expected=RulesetNotFoundException.class) + @Test public void load_from_file_uri_non_existent() { - Rule.rulesFromURL("file:///no-such-file.txt"); + assertThrows(RulesetNotFoundException.class, + () -> Rule.rulesFromURL("file:///no-such-file.txt")); } @Test @@ -61,9 +65,10 @@ public void load_from_file_with_include_uri_non_existent() { assertEquals("file:testing/reasoners/includeAlt.rules", e.getURI()); } - @Test(expected=WrappedIOException.class) + @Test public void load_from_file_bad_encoding() { - Rule.rulesFromURL("testing/reasoners/bugs/bad-encoding.rules"); + assertThrows(WrappedIOException.class, + () -> Rule.rulesFromURL("testing/reasoners/bugs/bad-encoding.rules")); } /** diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestTrialOWLRules.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestTrialOWLRules.java deleted file mode 100644 index 8bf0452b281..00000000000 --- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestTrialOWLRules.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.reasoner.rulesys.test; - -import junit.framework.TestCase; - -import junit.framework.*; - -import java.io.IOException; - -import org.apache.jena.rdf.model.*; -import org.apache.jena.reasoner.*; -import org.apache.jena.reasoner.rulesys.*; -import org.apache.jena.util.FileManager; -import org.apache.jena.vocabulary.RDF; -import org.apache.jena.vocabulary.ReasonerVocabulary; - -/** - * Test suite to test experimental versions of the OWL reasoner, not - * included in the main regression test suite. - */ -public class TestTrialOWLRules extends TestCase { - - /** The name of the manifest file to test */ - protected String manifest; - - /** Flag to control whether tracing and logging enabled */ - protected static boolean enableTracing = false; - - /** Flag to control whether to print performance stats as we go */ - protected static boolean printStats = true; - - /** Configuration spec for the reasoner under test */ - protected static Resource configuration; - - static { - Model m = ModelFactory.createDefaultModel(); - configuration = m.createResource(GenericRuleReasonerFactory.URI); - configuration.addProperty(ReasonerVocabulary.PROPruleMode, "hybrid"); - configuration.addProperty(ReasonerVocabulary.PROPruleSet, "etc/owl-fb-test.rules"); - configuration.addProperty(ReasonerVocabulary.PROPenableOWLTranslation, "true" ); - } - - /** - * Boilerplate for junit - */ - public TestTrialOWLRules( String manifest ) { - super( manifest ); - this.manifest = manifest; - } - - /** - * Boilerplate for junit. - * This is its own test suite - */ - public static TestSuite suite() { - TestSuite suite = new TestSuite(); - - // Basic property and equivalence tests - suite.addTest(new TestTrialOWLRules("SymmetricProperty/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("FunctionalProperty/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("FunctionalProperty/Manifest002.rdf")); - suite.addTest(new TestTrialOWLRules("FunctionalProperty/Manifest003.rdf")); - suite.addTest(new TestTrialOWLRules("InverseFunctionalProperty/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("InverseFunctionalProperty/Manifest002.rdf")); - suite.addTest(new TestTrialOWLRules("InverseFunctionalProperty/Manifest003.rdf")); - suite.addTest(new TestTrialOWLRules("rdf-charmod-uris/Manifest.rdf")); - suite.addTest(new TestTrialOWLRules("I5.5/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("I5.5/Manifest002.rdf")); - suite.addTest(new TestTrialOWLRules("I5.5/Manifest003.rdf")); - suite.addTest(new TestTrialOWLRules("I5.5/Manifest004.rdf")); - suite.addTest(new TestTrialOWLRules("inverseOf/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("TransitiveProperty/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("equivalentClass/Manifest001.rdf")); // bx - long - suite.addTest(new TestTrialOWLRules("equivalentClass/Manifest002.rdf")); // bx - long but terminates - suite.addTest(new TestTrialOWLRules("equivalentClass/Manifest003.rdf")); // bx - long but terminates - suite.addTest(new TestTrialOWLRules("equivalentClass/Manifest005.rdf")); // bx - timeout - suite.addTest(new TestTrialOWLRules("equivalentProperty/Manifest001.rdf")); // bx - long but terminates - suite.addTest(new TestTrialOWLRules("equivalentProperty/Manifest002.rdf")); // bx - long but terminates - suite.addTest(new TestTrialOWLRules("equivalentProperty/Manifest003.rdf")); - suite.addTest(new TestTrialOWLRules("I4.6/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("I4.6/Manifest002.rdf")); - suite.addTest(new TestTrialOWLRules("I5.1/Manifest001.rdf")); // bx - v. long but terminates - suite.addTest(new TestTrialOWLRules("I5.24/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("I5.24/Manifest002-mod.rdf")); - suite.addTest(new TestTrialOWLRules("equivalentProperty/Manifest006.rdf")); - suite.addTest(new TestTrialOWLRules("intersectionOf/Manifest001.rdf")); // bx - takes a long time - - // Disjointness tests - suite.addTest(new TestTrialOWLRules("differentFrom/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("disjointWith/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("disjointWith/Manifest002.rdf")); - suite.addTest(new TestTrialOWLRules("AllDifferent/Manifest001.rdf")); // bx gets lost - - // Restriction tests - suite.addTest(new TestTrialOWLRules("allValuesFrom/Manifest001.rdf")); // bx - long but terminates - suite.addTest(new TestTrialOWLRules("allValuesFrom/Manifest002.rdf")); // bx - slow - suite.addTest(new TestTrialOWLRules("someValuesFrom/Manifest002.rdf")); // bx - slow - suite.addTest(new TestTrialOWLRules("maxCardinality/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("maxCardinality/Manifest002.rdf")); - suite.addTest(new TestTrialOWLRules("FunctionalProperty/Manifest005-mod.rdf")); - suite.addTest(new TestTrialOWLRules("I5.24/Manifest004-mod.rdf")); // bx - long - suite.addTest(new TestTrialOWLRules("localtests/Manifest001.rdf")); // bx - long but terminates - suite.addTest(new TestTrialOWLRules("localtests/Manifest002.rdf")); // bx - long but terminates - suite.addTest(new TestTrialOWLRules("cardinality/Manifest001-mod.rdf")); // bx gets lost - suite.addTest(new TestTrialOWLRules("cardinality/Manifest002-mod.rdf")); // bx gets lost - suite.addTest(new TestTrialOWLRules("cardinality/Manifest003-mod.rdf")); // bx gets lost - suite.addTest(new TestTrialOWLRules("cardinality/Manifest004-mod.rdf")); // bx gets lost - suite.addTest(new TestTrialOWLRules("I5.24/Manifest003-mod.rdf")); - suite.addTest(new TestTrialOWLRules("cardinality/Manifest005-mod.rdf")); // bx gets lost - suite.addTest(new TestTrialOWLRules("cardinality/Manifest006-mod.rdf")); // bx gets lost - suite.addTest(new TestTrialOWLRules("equivalentClass/Manifest004.rdf")); // bx - timeout - - // Needs prototype creation rule -// suite.addTest(new TestTrialOWLRules("someValuesFrom/Manifest001.rdf")); // bx needs creation rule - - // Duplications of tests included earlier -// suite.addTest(new TestTrialOWLRules("differentFrom/Manifest002.rdf")); // Duplication of AllDifferent#1 -// suite.addTest(new TestTrialOWLRules("distinctMembers/Manifest001.rdf")); // Duplication of AllDifferent#1 - - // Consistency tests - not yet implemented by tester -// suite.addTest(new TestTrialOWLRules("I5.3/Manifest005.rdf")); -// suite.addTest(new TestTrialOWLRules("I5.3/Manifest006.rdf")); -// suite.addTest(new TestTrialOWLRules("I5.3/Manifest007.rdf")); -// suite.addTest(new TestTrialOWLRules("I5.3/Manifest008.rdf")); -// suite.addTest(new TestTrialOWLRules("I5.3/Manifest009.rdf")); -// suite.addTest(new TestTrialOWLRules("Nothing/Manifest001.rdf")); -// suite.addTest(new TestTrialOWLRules("miscellaneous/Manifest001.rdf")); -// suite.addTest(new TestTrialOWLRules("miscellaneous/Manifest002.rdf")); - - // Non-feature tests -// suite.addTest(new TestTrialOWLRules("I3.2/Manifest001.rdf")); -// suite.addTest(new TestTrialOWLRules("I3.2/Manifest002.rdf")); -// suite.addTest(new TestTrialOWLRules("I3.2/Manifest003.rdf")); -// suite.addTest(new TestTrialOWLRules("I3.4/Manifest001.rdf")); -// suite.addTest(new TestTrialOWLRules("I4.1/Manifest001.rdf")); - - // Outside (f)lite set - hasValue, oneOf, complementOf, unionOf - /* - suite.addTest(new TestTrialOWLRules("unionOf/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("unionOf/Manifest002.rdf")); - suite.addTest(new TestTrialOWLRules("oneOf/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("oneOf/Manifest002.rdf")); - suite.addTest(new TestTrialOWLRules("oneOf/Manifest003.rdf")); - suite.addTest(new TestTrialOWLRules("oneOf/Manifest004.rdf")); - suite.addTest(new TestTrialOWLRules("complementOf/Manifest001.rdf")); - suite.addTest(new TestTrialOWLRules("FunctionalProperty/Manifest004.rdf")); - suite.addTest(new TestTrialOWLRules("InverseFunctionalProperty/Manifest004.rdf")); - suite.addTest(new TestTrialOWLRules("equivalentClass/Manifest007.rdf")); - suite.addTest(new TestTrialOWLRules("equivalentClass/Manifest006.rdf")); - suite.addTest(new TestTrialOWLRules("equivalentProperty/Manifest004.rdf")); - suite.addTest(new TestTrialOWLRules("equivalentProperty/Manifest005.rdf")); - suite.addTest(new TestTrialOWLRules("Nothing/Manifest002.rdf")); - */ - - return suite; - } - - /** - * The test runner - */ - @Override - protected void runTest() throws IOException { - OWLWGTester tester = new OWLWGTester(GenericRuleReasonerFactory.theInstance(), this, configuration); -// OWLWGTester tester = new OWLWGTester(OWLExptRuleReasonerFactory.theInstance(), this, null); - tester.runTests(manifest, enableTracing, printStats); - } - - /** - * Boiler plate code for loading up and exploring a specific test case - * for use during debugging. - */ - public static void main(String[] args) { - Model premises = FileManager.getInternal().loadModelInternal("file:testing/wg/someValuesFrom/premises001.rdf"); - Reasoner reasoner = GenericRuleReasonerFactory.theInstance().create(configuration); - InfModel conclusions = ModelFactory.createInfModel(reasoner, premises); - - System.out.println("Premises = "); - for (StmtIterator i = premises.listStatements(); i.hasNext(); ) { - System.out.println(" - " + i.next()); - } - - Resource i = conclusions.getResource("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#i"); - Property p = conclusions.getProperty("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#p"); - Resource c = conclusions.getResource("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#c"); - Resource r = conclusions.getResource("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#r"); - Resource v = (Resource)i.getRequiredProperty(p).getObject(); - System.out.println("Value of i.p = " + v); - System.out.println("Types of v are: "); - for (StmtIterator it2 = conclusions.listStatements(v, RDF.type, (RDFNode)null); it2.hasNext(); ) { - System.out.println(" - " + it2.next()); - } -// System.out.println("Things of type r are: "); -// for (Iterator it = conclusions.listStatements(null, RDF.type, r); it.hasNext(); ) { -// System.out.println(" - " + it.next()); -// } -// System.out.println("Types of i are: "); -// for (Iterator it = conclusions.listStatements(i, RDF.type, (RDFNode)null); it.hasNext(); ) { -// System.out.println(" - " + it.next()); -// } -// System.out.println("Things of type r are: "); -// for (Iterator it = conclusions.listStatements(null, RDF.type, r); it.hasNext(); ) { -// System.out.println(" - " + it.next()); -// } - - } -} diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/ReasonerTester.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/ReasonerTester.java index 339f0efcbec..918cae9fcc4 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/ReasonerTester.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/ReasonerTester.java @@ -42,7 +42,7 @@ import org.apache.jena.reasoner.rulesys.Node_RuleVariable; import org.apache.jena.shared.JenaException; import org.apache.jena.vocabulary.RDF; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -322,7 +322,7 @@ public boolean runTest(String uri, Reasoner reasoner, Object testcase) throws IO */ // ... end of debugging hack if (testcase != null) { - Assert.assertTrue(description, correct); + assertTrue(correct, description); } return correct; } diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestCurrentRDFWG.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestCurrentRDFWG.java deleted file mode 100644 index 10292774296..00000000000 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestCurrentRDFWG.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.reasoner.test; - -import java.io.IOException; - -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.rdf.model.Resource; -import org.apache.jena.reasoner.ReasonerFactory; -import org.apache.jena.reasoner.rulesys.RDFSRuleReasonerFactory; -import org.apache.jena.shared.impl.JenaParameters; -import org.apache.jena.vocabulary.OWLResults; -import org.apache.jena.vocabulary.RDFS; -import org.apache.jena.vocabulary.ReasonerVocabulary; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Test the default RDFS reasoner against the current set of working group tests - */ -public class TestCurrentRDFWG extends TestCase { - - /** Location of the test file directory */ - public static final String TEST_DIR = "testing/wg20031010/"; -// public static final String TEST_DIR = "testing/wg/"; - - /** The base URI for the results file */ - public static String BASE_RESULTS_URI = "http://jena.apache.org/data/rdf-results.rdf"; - - /** The model describing the results of the run */ - Model testResults; - - /** The resource which acts as a description for the Jena instance being tested */ - Resource jena; - - protected static Logger logger = LoggerFactory.getLogger(TestCurrentRDFWG.class); - - /** - * Boilerplate for junit - */ - public TestCurrentRDFWG( String name ) { - super( name ); - } - - /** - * Initialize the result model. - */ - public void initResults() { - testResults = ModelFactory.createDefaultModel(); - jena = testResults.createResource(BASE_RESULTS_URI + "#jena2"); - jena.addProperty(RDFS.label, "Jena2"); - testResults.setNsPrefix("results", OWLResults.NS); - } - - /** - * Boilerplate for junit. - * This is its own test suite - */ - public static TestSuite suite() { - TestSuite suite = new TestSuite(); - try { - Resource config = ReasonerTestLib.newResource() - .addProperty(ReasonerVocabulary.PROPsetRDFSLevel, "full"); - constructRDFWGtests(suite, RDFSRuleReasonerFactory.theInstance(), config); - - } catch (IOException e) { - // failed to even built the test harness - logger.error("Failed to construct RDF WG test harness", e); - } - return suite; - } - - /** - * Build the working group tests for the given reasoner. - */ - private static void constructRDFWGtests(TestSuite suite, ReasonerFactory rf, Resource config) throws IOException { - JenaParameters.enableWhitespaceCheckingOfTypedLiterals = true; - WGReasonerTester tester = new WGReasonerTester("Manifest.rdf", TEST_DIR); - for ( String test : tester.listTests() ) - { - suite.addTest( new TestReasonerWG( tester, test, rf, config ) ); - } - } - - /** - * Inner class defining a test framework for invoking a single - * RDFCore working group test. - */ - static class TestReasonerWG extends TestCase { - - /** The tester which already has the test manifest loaded */ - WGReasonerTester tester; - - /** The name of the specific test to run */ - String test; - - /** The factory for the reasoner type under test */ - ReasonerFactory reasonerFactory; - - /** An optional configuration model */ - Resource config; - - /** Constructor */ - TestReasonerWG(WGReasonerTester tester, String test, - ReasonerFactory reasonerFactory, Resource config) { - super(test); - this.tester = tester; - this.test = test; - this.reasonerFactory = reasonerFactory; - this.config = config; - } - - /** - * The test runner - */ - @Override - public void runTest() throws IOException { - boolean success = tester.runTest(test, reasonerFactory, this, config); -// Resource resultType = null; -// if (test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest) -// || test.hasProperty(RDF.type, OWLTest.ConsistencyTest)) { -// resultType = success ? OWLResults.PassingRun : OWLResults.FailingRun; -// } else { -// resultType = success ? OWLResults.PassingRun : OWLResults.IncompleteRun; -// } -// // log to the rdf result format -// Resource result = testResults.createResource() -// .addProperty(RDF.type, OWLResults.TestRun) -// .addProperty(RDF.type, resultType) -// .addProperty(OWLResults.test, test) -// .addProperty(OWLResults.system, jena2); - - } - - } - -} diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfModel.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfModel.java index c9febee7f0f..a7086bda2ff 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfModel.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestInfModel.java @@ -21,8 +21,6 @@ package org.apache.jena.reasoner.test; -import static org.junit.jupiter.api.Assertions.*; - import org.junit.jupiter.api.Test; import org.apache.jena.ontology.OntModel; diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java index 8263150c6d4..6088bf79f08 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestRDFSReasoners.java @@ -62,8 +62,7 @@ public class TestRDFSReasoners { /** - * The RDFS reasoner tests, one dynamic test per manifest entry. This was a - * hand-built {@code TestSuite} of {@code TestCase} subclasses. + * The RDFS reasoner tests, one dynamic test per manifest entry. */ @TestFactory public Stream rdfsReasonerTests() { diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil.java index 0eba8d84b0f..4c8d5f55584 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/TestUtil.java @@ -33,11 +33,6 @@ /** * Collection of utilities to assist with unit testing. - *

- * JUnit6 counterpart of the {@code assertIterator*} methods of {@link TestUtil}. - * The {@code junit.framework.TestCase} argument of the originals has been - * dropped: it served only to label failure messages and to name the logger, - * both of which JUnit6 reports for itself. */ public class TestUtil { @@ -104,7 +99,7 @@ public static void assertIteratorValues(Iterator it, Object[] vals, int count /** * Replace all blocks of white space by a single space character, just * used for creating test cases. - * + * * @param src the original string * @return normalized version of src */ diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/test/WGReasonerTester.java b/jena-core/src/test/java/org/apache/jena/reasoner/test/WGReasonerTester.java index 6751b2e07dd..5ceda3b1203 100644 --- a/jena-core/src/test/java/org/apache/jena/reasoner/test/WGReasonerTester.java +++ b/jena-core/src/test/java/org/apache/jena/reasoner/test/WGReasonerTester.java @@ -30,7 +30,7 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Assert; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.jena.graph.Graph; import org.apache.jena.graph.GraphMemFactory; @@ -385,7 +385,7 @@ public int runTestDetailedResponse(String uri, ReasonerFactory reasonerF, Object // System.out.println("**** expected"); // conclusions.write(System.out, "TTL"); // } - Assert.assertTrue("Test: " + test + "\n" + description, correct); + assertTrue(correct, "Test: " + test + "\n" + description); } return correct?goodResult:FAIL; } diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU3.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU3.java new file mode 100644 index 00000000000..074b7aed6de --- /dev/null +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU3.java @@ -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 + * + * https://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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.apache.jena.test; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Jena core test suite. JUnit3 remaining + */ +public class JenaCoreTestAll_JU3 extends TestCase { + + static public TestSuite suite() { + JenaTestLib.setup(); + + TestSuite ts = new TestSuite(); + ts.setName("Jena Core [legacy]"); + addTest(ts, "XML Input [ARP1]", org.apache.jena.rdfxml.arp1tests.TS3_rdfxml_arp.suite()); + return ts; + } + + private static void addTest(TestSuite ts, String name, TestSuite tc) { + if ( name != null ) + tc.setName(name); + ts.addTest(tc); + } +} diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java deleted file mode 100644 index 85d53ee94cd..00000000000 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU4.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.test; - -import junit.framework.JUnit4TestAdapter; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Jena core test suite. - * Tests using JUnit 4, and JUnit3 wrapped as JUnit4. - */ -public class JenaCoreTestAll_JU4 extends TestCase { - - static public TestSuite suite() { - JenaTestLib.setup(); - - TestSuite ts = new TestSuite(); - ts.setName("Jena Core [legacy]"); - -//JU6 addTest(ts, "IRIx", adaptJUnit4(org.apache.jena.irix.TS_IRIx.class)); -//JU6 addTest(ts, "LangTagX", adaptJUnit4(org.apache.jena.langtagx.TS4_LangTagX.class)); -//JU6 addTest(ts, "Datatypes", adaptJUnit4(org.apache.jena.datatypes.TS4_dt.class)); - - // ** COMPLEX - // Generates tests. -//JU6 addTest(ts, "Enhanced", org.apache.jena.enhanced.TS3_enh.suite()); -//JU6 addTest(ts, "Graph", adaptJUnit4(org.apache.jena.graph.TS3_graph.class)); - -//JU6 addTest(ts, "Mem", adaptJUnit4(org.apache.jena.mem.TS4_GraphMem.class)); -//JU6 addTest(ts, "MemValue", adaptJUnit4(org.apache.jena.memvalue.TS3_GraphMemValue.class)); - - // ** COMPLEX -//JU6 addTest(ts, "Model1", org.apache.jena.rdf.model.TS3_Model1.suite()); - // ** COMPLEX -//JU6 addTest(ts, "Default Model", org.apache.jena.rdf.model.TestDefaultModel.suite()); - - // Test suite building - addTest(ts, "XML Input [ARP1]", org.apache.jena.rdfxml.arp1tests.TS3_xmlinput1.suite()); -//JU6 addTest(ts, "XML Output", org.apache.jena.rdfxml.xmloutput.TS3_xmloutput.suite()); - -//JU6 addTest(ts, "Util", adaptJUnit4(org.apache.jena.util.TS4_coreutil.class)); -//JU6 addTest(ts, "Jena iterator", adaptJUnit4(org.apache.jena.util.iterator.test.TS3_coreiter.class)); - -//JU6 addTest(ts, "Assembler", adaptJUnit4(org.apache.jena.assembler.TS3_Assembler.class)); - -//JU6 addTest(ts, "Vocabularies", adaptJUnit4(org.apache.jena.vocabulary.TS3_Vocabularies.class)); -//JU6 addTest(ts, "Shared", adaptJUnit4(org.apache.jena.shared.TS_SharedPackage.class)); - - // ** COMPLEX -//JU6 addTest(ts, "Composed graphs", org.apache.jena.graph.compose.TS3_compose.suite() ); - -//JU6 addTest(ts, "Reasoners", adaptJUnit4(org.apache.jena.reasoner.test.TS3_reasoners.class)); -//JU6 addTest(ts, "RuleReasoners", adaptJUnit4(org.apache.jena.reasoner.rulesys.TS3_RuleReasoners.class)); - -//JU6 addTest(ts, "Ontology ModelMaker", adaptJUnit4(org.apache.jena.ontology.makers.TS3_ModelMakers.class)); -//JU6 addTest(ts, "Ontology", adaptJUnit4(org.apache.jena.ontology.impl.TS3_ont.class)); - - // Local TTL parser for tests - not fully compliant. -//JU6 addTest(ts, "Turtle", adaptJUnit4(org.apache.jena.ttl_test.test_turtle.TS_TestTurtle.class)); - // ** Generated tests -//JU6 addTest(ts, "Turtle:Manifest", org.apache.jena.ttl_test.test_turtle.TurtleTestSuiteManifest.suite()); - return ts; - } - - // JUnit4 in a JUnit3 test runner. - private static Test adaptJUnit4(Class testClass) { - return new JUnit4TestAdapter(testClass); - } - - private static void addTest(TestSuite ts, String name, TestSuite tc) { - if ( name != null ) - tc.setName(name); - ts.addTest(tc); - } - - private static void addTest(TestSuite ts, String name, Test test) { - // Extra level but does name the test suite. - TestSuite ts2 = new TestSuite(name); - ts2.addTest(test); - ts.addTest(ts2); - } -} diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaTestLib.java b/jena-core/src/test/java/org/apache/jena/test/JenaTestLib.java index 7d07723ca11..91611bc3fc4 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaTestLib.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaTestLib.java @@ -21,6 +21,8 @@ package org.apache.jena.test; +import static org.junit.jupiter.api.Assertions.fail; + import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -33,8 +35,6 @@ import org.apache.jena.util.iterator.ExtendedIterator; import org.apache.jena.util.iterator.WrappedIterator; -import static junit.framework.TestCase.*; - public class JenaTestLib { /** diff --git a/jena-core/src/test/java/org/apache/jena/util/iterator/TestAndThen.java b/jena-core/src/test/java/org/apache/jena/util/iterator/TestAndThen.java index 4671add7a4a..8c2f104b231 100644 --- a/jena-core/src/test/java/org/apache/jena/util/iterator/TestAndThen.java +++ b/jena-core/src/test/java/org/apache/jena/util/iterator/TestAndThen.java @@ -21,9 +21,9 @@ package org.apache.jena.util.iterator; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertSame; -import static junit.framework.TestCase.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; @@ -63,8 +63,8 @@ public void testClosingConcatenationClosesRemainingIterators() { ExtendedIterator cat = L.andThen(M).andThen(R); cat.next(); cat.close(); - assertTrue("middle iterator should have been closed", M.isClosed()); - assertTrue("final iterator should have been closed", R.isClosed()); + assertTrue(M.isClosed(), "middle iterator should have been closed"); + assertTrue(R.isClosed(), "final iterator should have been closed"); } @Test diff --git a/jena-core/src/test/java/org/apache/jena/util/iterator/TestAsCollection.java b/jena-core/src/test/java/org/apache/jena/util/iterator/TestAsCollection.java index 1787cc27c70..24c24ca72f9 100644 --- a/jena-core/src/test/java/org/apache/jena/util/iterator/TestAsCollection.java +++ b/jena-core/src/test/java/org/apache/jena/util/iterator/TestAsCollection.java @@ -21,7 +21,7 @@ package org.apache.jena.util.iterator; -import static junit.framework.TestCase.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; import java.util.Set; diff --git a/jena-core/src/test/java/org/apache/jena/util/iterator/TestFilters.java b/jena-core/src/test/java/org/apache/jena/util/iterator/TestFilters.java index df26cdf6c0d..7d4e1388f07 100644 --- a/jena-core/src/test/java/org/apache/jena/util/iterator/TestFilters.java +++ b/jena-core/src/test/java/org/apache/jena/util/iterator/TestFilters.java @@ -21,7 +21,7 @@ package org.apache.jena.util.iterator; -import static junit.framework.TestCase.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Iterator; import java.util.function.Predicate; diff --git a/jena-core/src/test/java/org/apache/jena/util/iterator/TestWrappedIterator.java b/jena-core/src/test/java/org/apache/jena/util/iterator/TestWrappedIterator.java index 247819a1206..9c0a393126c 100644 --- a/jena-core/src/test/java/org/apache/jena/util/iterator/TestWrappedIterator.java +++ b/jena-core/src/test/java/org/apache/jena/util/iterator/TestWrappedIterator.java @@ -21,7 +21,7 @@ package org.apache.jena.util.iterator; -import static junit.framework.TestCase.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/jena-core/src/test/java/org/apache/jena/vocabulary/VocabTestLib.java b/jena-core/src/test/java/org/apache/jena/vocabulary/VocabTestLib.java index 04e719dfd7b..51812361043 100644 --- a/jena-core/src/test/java/org/apache/jena/vocabulary/VocabTestLib.java +++ b/jena-core/src/test/java/org/apache/jena/vocabulary/VocabTestLib.java @@ -24,7 +24,7 @@ import org.apache.jena.rdf.model.Property; import org.apache.jena.rdf.model.Resource; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class VocabTestLib { From 542e2071f8bc39d0fd3b95805350477474b51e24 Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Tue, 8 Sep 2026 08:47:24 +0100 Subject: [PATCH 12/12] GH-3236: Restore running TestXMLAbbrev; remove duplicate TestXMLFeatures_XML_Abbrev --- .../jena/rdfxml/xmloutput/TS6_xmloutput.java | 2 +- .../jena/rdfxml/xmloutput/TestXMLAbbrev.java | 59 ++++++++++++------- .../TestXMLFeatures_CoreNTriples.java | 35 ----------- .../apache/jena/test/JenaCoreTestAll_JU3.java | 14 ++++- 4 files changed, 52 insertions(+), 58 deletions(-) delete mode 100644 jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLFeatures_CoreNTriples.java diff --git a/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TS6_xmloutput.java b/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TS6_xmloutput.java index 1202b2b8816..4541dab4621 100644 --- a/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TS6_xmloutput.java +++ b/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TS6_xmloutput.java @@ -31,9 +31,9 @@ @Suite @SelectClasses({ TestPrettyWriter.class, + TestXMLAbbrev.class, TestXMLFeatures_XML_Basic.class, TestXMLFeatures_XML_Abbrev.class, - TestXMLFeatures_XML_Abbrev.class, TestWriterURIExceptions.class, TestEntityOutput.class, TestLiteralEncoding.class, diff --git a/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLAbbrev.java b/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLAbbrev.java index a38b21adb56..927cda0c521 100644 --- a/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLAbbrev.java +++ b/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLAbbrev.java @@ -23,6 +23,10 @@ import java.io.IOException; +import org.junit.jupiter.api.Test; + +import org.apache.jena.test.JenaTestLib; + public class TestXMLAbbrev extends BaseTestXMLOutput { @Override @@ -30,6 +34,9 @@ protected String getLang() { return "RDF/XML-ABBREV"; } + static { JenaTestLib.setup(); } + + @Test public void testNoPropAttr() throws IOException { checkY(BaseTestXMLFeatures.file1, @@ -39,24 +46,27 @@ public void testNoPropAttr() throws IOException ); } + @Test public void testNoRdfCollection() throws IOException { checkY("testing/abbreviated/collection.rdf", - null, - "[\"']Collection[\"']", - Change.blockRules( "parseTypeCollectionPropertyElt" ) + null, + "[\"']Collection[\"']", + Change.blockRules( "parseTypeCollectionPropertyElt" ) ); } + @Test public void testNoLi() throws IOException { checkY("testing/abbreviated/container.rdf", - null, - "rdf:li", - Change.blockRules( "section-List-Expand" ) + null, + "rdf:li", + Change.blockRules( "section-List-Expand" ) ); } + @Test public void testNoID() throws IOException { checkB("testing/abbreviated/container.rdf", @@ -66,6 +76,7 @@ public void testNoID() throws IOException ); } + @Test public void testNoID2() throws IOException { checkB("testing/abbreviated/container.rdf", @@ -75,6 +86,7 @@ public void testNoID2() throws IOException ); } + @Test public void testNoID3() throws IOException { // Minimal version of testNoID2 checkB("testing/abbreviated/rdf-id.rdf", @@ -84,6 +96,7 @@ public void testNoID3() throws IOException { ); } + @Test public void testNoResource() throws IOException { checkB("testing/abbreviated/container.rdf", @@ -93,24 +106,27 @@ public void testNoResource() throws IOException ); } + @Test public void testPropAttrs() throws IOException { checkY("testing/abbreviated/namespaces.rdf", - ":prop0 *=", - null, - Change.blockRules( "" ) + ":prop0 *=", + null, + Change.blockRules( "" ) ); } + @Test public void testNoPropAttrs() throws IOException { checkY("testing/abbreviated/namespaces.rdf", - null, - ":prop0 *=", - Change.none() + null, + ":prop0 *=", + Change.none() ); } + @Test public void testNoReification() throws IOException { // System.err.println("WARNING: reification output tests suppressed."); @@ -122,22 +138,23 @@ public void code(RDFWriter w){} },base); /* */ checkZ(filename, - null, - "rdf:subject", - null, - false, - Change.blockRules( "section-Reification" ), - base + null, + "rdf:subject", + null, + false, + Change.blockRules( "section-Reification" ), + base ); } + @Test public void testNoCookUp() throws IOException { checkY("testing/abbreviated/cookup.rdf", - null, - "(j\\.fixup|j\\.cook\\.up)", - Change.blockRules( "" ) + null, + "(j\\.fixup|j\\.cook\\.up)", + Change.blockRules( "" ) ); } } diff --git a/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLFeatures_CoreNTriples.java b/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLFeatures_CoreNTriples.java deleted file mode 100644 index 9b6a820afc9..00000000000 --- a/jena-core/src/test/java/org/apache/jena/rdfxml/xmloutput/TestXMLFeatures_CoreNTriples.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 - * - * https://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. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.apache.jena.rdfxml.xmloutput; - -/** Test with the core/test N-triples writer */ -public class TestXMLFeatures_CoreNTriples extends BaseTestXMLFeatures { - - public TestXMLFeatures_CoreNTriples() { - super(); - } - - @Override - protected String getLang() { - return "N-TRIPLES"; - } -} diff --git a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU3.java b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU3.java index 074b7aed6de..f1f2daf0c6f 100644 --- a/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU3.java +++ b/jena-core/src/test/java/org/apache/jena/test/JenaCoreTestAll_JU3.java @@ -25,7 +25,7 @@ import junit.framework.TestSuite; /** - * Jena core test suite. JUnit3 remaining + * Jena core test suite. Any JUnit3 remaining. */ public class JenaCoreTestAll_JU3 extends TestCase { @@ -43,4 +43,16 @@ private static void addTest(TestSuite ts, String name, TestSuite tc) { tc.setName(name); ts.addTest(tc); } + +// // JUnit4 in a JUnit3 test runner. +// private static Test adaptJUnit4(Class testClass) { +// return new JUnit4TestAdapter(testClass); +// } +// +// private static void addTest(TestSuite ts, String name, Test test) { +// // Adds an extra level but does name the test suite. +// TestSuite ts2 = new TestSuite(name); +// ts2.addTest(test); +// ts.addTest(ts2); +// } }