Skip to content

Commit 5813329

Browse files
GH-4592 Replace a Junit4 Suite with v5 DynamicTest
Also replaces a static so more tests should be runnable in parallel in the future. Signed-off-by: Jerven Bolleman <jerven.bolleman@sib.swiss>
1 parent ee2bf24 commit 5813329

24 files changed

Lines changed: 838 additions & 866 deletions

compliance/sparql/src/test/java/org/eclipse/rdf4j/sail/lmdb/LmdbSPARQLComplianceTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,19 @@
1515
import org.eclipse.rdf4j.repository.sail.config.SailRepositoryFactory;
1616
import org.eclipse.rdf4j.sail.lmdb.config.LmdbStoreFactory;
1717
import org.eclipse.rdf4j.testsuite.sparql.RepositorySPARQLComplianceTestSuite;
18-
import org.junit.AfterClass;
19-
import org.junit.BeforeClass;
2018

2119
/**
2220
* Test additional SPARQL functionality on LMDB store.
2321
*/
2422
public class LmdbSPARQLComplianceTest extends RepositorySPARQLComplianceTestSuite {
2523

26-
@BeforeClass
27-
public static void setUpFactory() throws Exception {
28-
setRepositoryFactory(new SailRepositoryFactory() {
24+
public LmdbSPARQLComplianceTest() {
25+
super(new SailRepositoryFactory() {
2926
@Override
3027
public RepositoryImplConfig getConfig() {
3128

3229
return new SailRepositoryConfig(new LmdbStoreFactory().getConfig());
3330
}
3431
});
3532
}
36-
37-
@AfterClass
38-
public static void tearDownFactory() throws Exception {
39-
setRepositoryFactory(null);
40-
}
4133
}

compliance/sparql/src/test/java/org/eclipse/rdf4j/sail/memory/MemorySPARQLComplianceTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,18 @@
1515
import org.eclipse.rdf4j.repository.sail.config.SailRepositoryFactory;
1616
import org.eclipse.rdf4j.sail.memory.config.MemoryStoreFactory;
1717
import org.eclipse.rdf4j.testsuite.sparql.RepositorySPARQLComplianceTestSuite;
18-
import org.junit.AfterClass;
19-
import org.junit.BeforeClass;
2018

2119
/**
2220
* @author jeen
2321
*/
2422
public class MemorySPARQLComplianceTest extends RepositorySPARQLComplianceTestSuite {
2523

26-
@BeforeClass
27-
public static void setUpFactory() throws Exception {
28-
setRepositoryFactory(new SailRepositoryFactory() {
24+
public MemorySPARQLComplianceTest() {
25+
super(new SailRepositoryFactory() {
2926
@Override
3027
public RepositoryImplConfig getConfig() {
3128
return new SailRepositoryConfig(new MemoryStoreFactory().getConfig());
3229
}
3330
});
3431
}
35-
36-
@AfterClass
37-
public static void tearDownFactory() throws Exception {
38-
setRepositoryFactory(null);
39-
}
4032
}

compliance/sparql/src/test/java/org/eclipse/rdf4j/sail/nativerdf/NativeSPARQLComplianceTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,19 @@
1515
import org.eclipse.rdf4j.repository.sail.config.SailRepositoryFactory;
1616
import org.eclipse.rdf4j.sail.nativerdf.config.NativeStoreFactory;
1717
import org.eclipse.rdf4j.testsuite.sparql.RepositorySPARQLComplianceTestSuite;
18-
import org.junit.AfterClass;
19-
import org.junit.BeforeClass;
2018

2119
/**
2220
* @author jeen
2321
*/
2422
public class NativeSPARQLComplianceTest extends RepositorySPARQLComplianceTestSuite {
2523

26-
@BeforeClass
27-
public static void setUpFactory() throws Exception {
28-
setRepositoryFactory(new SailRepositoryFactory() {
24+
public NativeSPARQLComplianceTest() {
25+
super(new SailRepositoryFactory() {
2926
@Override
3027
public RepositoryImplConfig getConfig() {
3128

3229
return new SailRepositoryConfig(new NativeStoreFactory().getConfig());
3330
}
3431
});
3532
}
36-
37-
@AfterClass
38-
public static void tearDownFactory() throws Exception {
39-
setRepositoryFactory(null);
40-
}
4133
}

eclipse-settings/codetemplates.xml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<templates>
3-
<template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/*******************************************************************************
4-
* Copyright (c) ${year} Eclipse RDF4J contributors.
5-
*
6-
* All rights reserved. This program and the accompanying materials
7-
* are made available under the terms of the Eclipse Distribution License v1.0
8-
* which accompanies this distribution, and is available at
9-
* http://www.eclipse.org/org/documents/edl-v10.php
10-
*
11-
* SPDX-License-Identifier: BSD-3-Clause
12-
*******************************************************************************/
13-
</template>
3+
<template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/******************************************************************************* * Copyright (c) ${year} Eclipse RDF4J contributors. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Distribution License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/org/documents/edl-v10.php * * SPDX-License-Identifier: BSD-3-Clause *******************************************************************************/</template>
144
</templates>

testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/sparql/AbstractComplianceTest.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
import org.eclipse.rdf4j.rio.RDFParseException;
4747
import org.eclipse.rdf4j.rio.Rio;
4848
import org.eclipse.rdf4j.testsuite.sparql.vocabulary.EX;
49-
import org.junit.After;
50-
import org.junit.Before;
49+
import org.junit.jupiter.api.DynamicTest;
50+
import org.junit.jupiter.api.function.Executable;
5151
import org.slf4j.Logger;
5252
import org.slf4j.LoggerFactory;
5353

@@ -58,20 +58,31 @@
5858
*/
5959
public abstract class AbstractComplianceTest {
6060

61+
protected DynamicTest makeTest(String name, Executable x) {
62+
return DynamicTest.dynamicTest(name, () -> {
63+
setUp();
64+
x.execute();
65+
tearDown();
66+
});
67+
}
68+
6169
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
6270

63-
protected Repository repo;
71+
protected final Repository repo;
6472
protected RepositoryConnection conn;
6573

66-
@Before
67-
public void setUp() throws Exception {
68-
repo = RepositorySPARQLComplianceTestSuite.getEmptyInitializedRepository(this.getClass());
74+
public AbstractComplianceTest(Repository repo) {
75+
this.repo = repo;
76+
}
77+
78+
public void setUp() {
79+
repo.init();
6980
conn = new RepositoryConnectionWrapper(repo.getConnection());
7081
}
7182

72-
@After
7383
public void tearDown() {
7484
try {
85+
conn.clear();
7586
conn.close();
7687
} finally {
7788
repo.shutDown();

testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/sparql/RepositorySPARQLComplianceTestSuite.java

Lines changed: 107 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212

1313
import java.io.File;
1414
import java.io.IOException;
15-
import java.nio.file.Files;
15+
import java.util.stream.Stream;
1616

1717
import org.eclipse.rdf4j.common.annotation.Experimental;
1818
import org.eclipse.rdf4j.common.exception.RDF4JException;
19-
import org.eclipse.rdf4j.common.io.FileUtil;
2019
import org.eclipse.rdf4j.repository.Repository;
2120
import org.eclipse.rdf4j.repository.RepositoryConnection;
2221
import org.eclipse.rdf4j.repository.config.RepositoryFactory;
@@ -38,77 +37,134 @@
3837
import org.eclipse.rdf4j.testsuite.sparql.tests.SubselectTest;
3938
import org.eclipse.rdf4j.testsuite.sparql.tests.UnionTest;
4039
import org.eclipse.rdf4j.testsuite.sparql.tests.ValuesTest;
41-
import org.junit.AfterClass;
42-
import org.junit.BeforeClass;
43-
import org.junit.runner.RunWith;
44-
import org.junit.runners.Suite;
45-
import org.junit.runners.Suite.SuiteClasses;
40+
import org.junit.jupiter.api.AfterAll;
41+
import org.junit.jupiter.api.BeforeAll;
42+
import org.junit.jupiter.api.DynamicTest;
43+
import org.junit.jupiter.api.TestFactory;
44+
import org.junit.jupiter.api.io.TempDir;
4645

4746
/**
4847
* A suite of custom compliance tests on SPARQL query functionality for RDF4J Repositories.
4948
* <p>
5049
* To use this test suite, extend the abstract suite class, making sure that the correct {@link RepositoryFactory} gets
51-
* set on initialization, and torn down after. For example, to run the suite against an RDF4J Memory Store:
52-
*
53-
* <pre>
54-
* <code>
55-
* &#64;BeforeClass
56-
public static void setUpFactory() throws Exception {
57-
setRepositoryFactory(new SailRepositoryFactory() {
58-
&#64;Override
59-
public RepositoryImplConfig getConfig() {
60-
return new SailRepositoryConfig(new MemoryStoreFactory().getConfig());
61-
}
62-
});
63-
}
64-
65-
&#64;AfterClass
66-
public static void tearDownFactory() throws Exception {
67-
setRepositoryFactory(null);
68-
}
69-
* </code>
70-
* </pre>
50+
* set on construction,
7151
*
7252
* @author Jeen Broekstra
73-
* @implNote currently implemented as an abstract JUnit-4 suite. This suite is marked Experimental as we may want to
74-
* make further improvements to its setup (including migrating to JUnit 5 when its suite support matures) in
75-
* future minor releases.
7653
*/
77-
@RunWith(Suite.class)
78-
@SuiteClasses({ AggregateTest.class, ArbitraryLengthPathTest.class, BasicTest.class, BindTest.class,
79-
BuiltinFunctionTest.class, ConstructTest.class, DefaultGraphTest.class, DescribeTest.class, GroupByTest.class,
80-
InTest.class, OptionalTest.class, PropertyPathTest.class, SubselectTest.class, UnionTest.class,
81-
ValuesTest.class, OrderByTest.class, ExistsTest.class, MinusTest.class })
8254
@Experimental
8355
public abstract class RepositorySPARQLComplianceTestSuite {
84-
@BeforeClass
56+
57+
@TestFactory
58+
Stream<DynamicTest> aggregate() throws RDF4JException, IOException {
59+
return new AggregateTest(getEmptyInitializedRepository()).tests();
60+
}
61+
62+
@TestFactory
63+
Stream<DynamicTest> arbitraryLengthPath() throws RDF4JException, IOException {
64+
return new ArbitraryLengthPathTest(getEmptyInitializedRepository()).tests();
65+
}
66+
67+
@TestFactory
68+
Stream<DynamicTest> basic() throws RDF4JException, IOException {
69+
return new BasicTest(getEmptyInitializedRepository()).tests();
70+
}
71+
72+
@TestFactory
73+
Stream<DynamicTest> bind() throws RDF4JException, IOException {
74+
return new BindTest(getEmptyInitializedRepository()).tests();
75+
}
76+
77+
@TestFactory
78+
Stream<DynamicTest> builtinFunction() throws RDF4JException, IOException {
79+
return new BuiltinFunctionTest(getEmptyInitializedRepository()).tests();
80+
}
81+
82+
@TestFactory
83+
Stream<DynamicTest> construct() throws RDF4JException, IOException {
84+
return new ConstructTest(getEmptyInitializedRepository()).tests();
85+
}
86+
87+
@TestFactory
88+
Stream<DynamicTest> defaultGraph() throws RDF4JException, IOException {
89+
return new DefaultGraphTest(getEmptyInitializedRepository()).tests();
90+
}
91+
92+
@TestFactory
93+
Stream<DynamicTest> describe() throws RDF4JException, IOException {
94+
return new DescribeTest(getEmptyInitializedRepository()).tests();
95+
}
96+
97+
@TestFactory
98+
Stream<DynamicTest> groupBy() throws RDF4JException, IOException {
99+
return new GroupByTest(getEmptyInitializedRepository()).tests();
100+
}
101+
102+
@TestFactory
103+
Stream<DynamicTest> in() throws RDF4JException, IOException {
104+
return new InTest(getEmptyInitializedRepository()).tests();
105+
}
106+
107+
@TestFactory
108+
Stream<DynamicTest> optional() throws RDF4JException, IOException {
109+
return new OptionalTest(getEmptyInitializedRepository()).tests();
110+
}
111+
112+
@TestFactory
113+
Stream<DynamicTest> propertyPath() throws RDF4JException, IOException {
114+
return new PropertyPathTest(getEmptyInitializedRepository()).tests();
115+
}
116+
117+
@TestFactory
118+
Stream<DynamicTest> subselect() throws RDF4JException, IOException {
119+
return new SubselectTest(getEmptyInitializedRepository()).tests();
120+
}
121+
122+
@TestFactory
123+
Stream<DynamicTest> union() throws RDF4JException, IOException {
124+
return new UnionTest(getEmptyInitializedRepository()).tests();
125+
}
126+
127+
@TestFactory
128+
Stream<DynamicTest> values() throws RDF4JException, IOException {
129+
return new ValuesTest(getEmptyInitializedRepository()).tests();
130+
}
131+
132+
@TestFactory
133+
Stream<DynamicTest> orderBy() throws RDF4JException, IOException {
134+
return new OrderByTest(getEmptyInitializedRepository()).tests();
135+
}
136+
137+
@TestFactory
138+
Stream<DynamicTest> exists() throws RDF4JException, IOException {
139+
return new ExistsTest(getEmptyInitializedRepository()).tests();
140+
}
141+
142+
@TestFactory
143+
Stream<DynamicTest> minus() throws RDF4JException, IOException {
144+
return new MinusTest(getEmptyInitializedRepository()).tests();
145+
}
146+
147+
@BeforeAll
85148
public static void setUpClass() {
86149
System.setProperty("org.eclipse.rdf4j.repository.debug", "true");
87150
}
88151

89-
@AfterClass
152+
@AfterAll
90153
public static void tearDownClass() {
91154
System.setProperty("org.eclipse.rdf4j.repository.debug", "false");
92155
}
93156

94-
private static RepositoryFactory factory;
157+
@TempDir
158+
private File dataDir;
95159

96-
private static File dataDir;
160+
protected final RepositoryFactory factory;
97161

98-
public static void setRepositoryFactory(RepositoryFactory factory) throws IOException {
99-
if (dataDir != null && dataDir.isDirectory()) {
100-
FileUtil.deleteDir(dataDir);
101-
dataDir = null;
102-
}
103-
RepositorySPARQLComplianceTestSuite.factory = factory;
162+
public RepositorySPARQLComplianceTestSuite(RepositoryFactory factory) {
163+
super();
164+
this.factory = factory;
104165
}
105166

106-
public static Repository getEmptyInitializedRepository(Class<?> caller) throws RDF4JException, IOException {
107-
if (dataDir != null && dataDir.isDirectory()) {
108-
FileUtil.deleteDir(dataDir);
109-
dataDir = null;
110-
}
111-
dataDir = Files.createTempDirectory(caller.getSimpleName()).toFile();
167+
public Repository getEmptyInitializedRepository() throws RDF4JException, IOException {
112168
Repository repository = factory.getRepository(factory.getConfig());
113169
repository.setDataDir(dataDir);
114170
try (RepositoryConnection con = repository.getConnection()) {

0 commit comments

Comments
 (0)