|
12 | 12 |
|
13 | 13 | import java.io.File; |
14 | 14 | import java.io.IOException; |
15 | | -import java.nio.file.Files; |
| 15 | +import java.util.stream.Stream; |
16 | 16 |
|
17 | 17 | import org.eclipse.rdf4j.common.annotation.Experimental; |
18 | 18 | import org.eclipse.rdf4j.common.exception.RDF4JException; |
19 | | -import org.eclipse.rdf4j.common.io.FileUtil; |
20 | 19 | import org.eclipse.rdf4j.repository.Repository; |
21 | 20 | import org.eclipse.rdf4j.repository.RepositoryConnection; |
22 | 21 | import org.eclipse.rdf4j.repository.config.RepositoryFactory; |
|
38 | 37 | import org.eclipse.rdf4j.testsuite.sparql.tests.SubselectTest; |
39 | 38 | import org.eclipse.rdf4j.testsuite.sparql.tests.UnionTest; |
40 | 39 | 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; |
46 | 45 |
|
47 | 46 | /** |
48 | 47 | * A suite of custom compliance tests on SPARQL query functionality for RDF4J Repositories. |
49 | 48 | * <p> |
50 | 49 | * 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 | | - * @BeforeClass |
56 | | - public static void setUpFactory() throws Exception { |
57 | | - setRepositoryFactory(new SailRepositoryFactory() { |
58 | | - @Override |
59 | | - public RepositoryImplConfig getConfig() { |
60 | | - return new SailRepositoryConfig(new MemoryStoreFactory().getConfig()); |
61 | | - } |
62 | | - }); |
63 | | - } |
64 | | -
|
65 | | - @AfterClass |
66 | | - public static void tearDownFactory() throws Exception { |
67 | | - setRepositoryFactory(null); |
68 | | - } |
69 | | - * </code> |
70 | | - * </pre> |
| 50 | + * set on construction, |
71 | 51 | * |
72 | 52 | * @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. |
76 | 53 | */ |
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 }) |
82 | 54 | @Experimental |
83 | 55 | 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 |
85 | 148 | public static void setUpClass() { |
86 | 149 | System.setProperty("org.eclipse.rdf4j.repository.debug", "true"); |
87 | 150 | } |
88 | 151 |
|
89 | | - @AfterClass |
| 152 | + @AfterAll |
90 | 153 | public static void tearDownClass() { |
91 | 154 | System.setProperty("org.eclipse.rdf4j.repository.debug", "false"); |
92 | 155 | } |
93 | 156 |
|
94 | | - private static RepositoryFactory factory; |
| 157 | + @TempDir |
| 158 | + private File dataDir; |
95 | 159 |
|
96 | | - private static File dataDir; |
| 160 | + protected final RepositoryFactory factory; |
97 | 161 |
|
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; |
104 | 165 | } |
105 | 166 |
|
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 { |
112 | 168 | Repository repository = factory.getRepository(factory.getConfig()); |
113 | 169 | repository.setDataDir(dataDir); |
114 | 170 | try (RepositoryConnection con = repository.getConnection()) { |
|
0 commit comments