Skip to content

Commit fc83894

Browse files
committed
Port all tests to Junit 5.
1 parent 3212bfa commit fc83894

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1389
-1388
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Changed
1111
- Require Java 11+
12+
- Port all tests to Junit 5
1213

1314
### Fixed
1415
- Dropped dependency on Guava

README.md

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,6 @@ which contain the necessary credentials to access the Web API.
155155
An example can be found in the test cases
156156
[src/test/resources/web-of-things](src/test/resources/web-of-things).
157157

158-
#### Accessing Oracle Database
159-
160-
You need to add the Oracle JDBC driver manually to the class path
161-
if you want to access an Oracle Database.
162-
The required driver is `ojdbc8`.
163-
164-
- Download `ojdbc8.jar` from [Oracle](https://www.oracle.com/database/technologies/jdbc-ucp-122-downloads.html).
165-
- Execute the RMLMapper via
166-
167-
```
168-
java -cp 'rmlmapper.jar:ojdbc8-12.2.0.1.jar' be.ugent.rml.cli.Main -m rules.rml.ttl
169-
```
170-
171-
The options do the following:
172-
173-
- `-cp 'rmlmapper.jar:ojdbc8-12.2.0.1.jar'`: Put the jar of the RMLMapper and JDBC driver in the classpath.
174-
- `be.ugent.rml.cli.Main`: `be.ugent.rml.cli.Main` is the entry point of the RMLMapper.
175-
- `-m rules.rml.ttl`: Use the RML rules in the file `rules.rml`.ttl.
176-
The exact same options as the ones mentioned earlier are supported.
177-
178158
### Library
179159

180160
An example of how you can use the RMLMapper as an external library can be found
@@ -199,9 +179,10 @@ The RMLMapper is executed in the `/data` folder in the Docker container.
199179

200180
### Including functions
201181

202-
There are two ways to include (new) functions within the RML Mapper
182+
There are three ways to include (new) functions within the RML Mapper
203183
* dynamic loading: you add links to java files or jar files, and those files are loaded dynamically at runtime
204184
* preloading: you register functionality via code, and you need to rebuild the mapper to use that functionality
185+
* add as dependency
205186

206187
Registration of functions is done using a Turtle file, which you can find in `src/main/resources/functions.ttl`
207188

@@ -253,6 +234,14 @@ This overrides the dynamic loading.
253234
An example of how you can use Preload a custom function can be found
254235
at [./src/test/java/be/ugent/rml/readme/ReadmeFunctionTest.java](https://github.com/RMLio/rmlmapper-java/blob/master/src/test/java/be/ugent/rml/readme/ReadmeFunctionTest.java)
255236

237+
#### Adding as dependency
238+
239+
This is most interesting if you use RMLMapper as a library in your own project.
240+
Just add the dependency to the function library you want to use in your project.
241+
242+
You can also add a function library as a Maven dependency in `pom.xml` or RMLMapper.
243+
You'll have to rebuild RMLMapper to use it.
244+
256245
### Generating metadata
257246

258247
Conform to how it is described in the scientific paper [1],

pom.xml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
<properties>
3737
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38-
<junit.version>5.8.2</junit.version>
38+
<junit.version>5.8.2</junit.version> <!-- testcontainers can't handle > 5.8 yet -->
3939
<maven.compiler.source>10</maven.compiler.source>
4040
<maven.compiler.target>10</maven.compiler.target>
4141
<jackson.version>2.14.0</jackson.version>
@@ -272,6 +272,10 @@
272272
<groupId>org.apache.jena</groupId>
273273
<artifactId>*</artifactId>
274274
</exclusion>
275+
<exclusion>
276+
<groupId>junit</groupId>
277+
<artifactId>*</artifactId>
278+
</exclusion>
275279
</exclusions>
276280
</dependency>
277281
<dependency>
@@ -342,13 +346,8 @@
342346
<version>1.0-1</version>
343347
<scope>test</scope>
344348
</dependency>
349+
345350
<!--< testcontainer dependencies > -->
346-
<dependency>
347-
<groupId>org.testcontainers</groupId> <!-- for running tests with dockerized databases -->
348-
<artifactId>testcontainers</artifactId>
349-
<version>${testcontainers.version}</version>
350-
<scope>test</scope>
351-
</dependency>
352351
<dependency>
353352
<groupId>org.testcontainers</groupId>
354353
<artifactId>postgresql</artifactId>
@@ -373,7 +372,20 @@
373372
<version>${testcontainers.version}</version>
374373
<scope>test</scope>
375374
</dependency>
375+
<dependency>
376+
<groupId>org.testcontainers</groupId>
377+
<artifactId>jdbc</artifactId>
378+
<version>${testcontainers.version}</version>
379+
<scope>test</scope>
380+
</dependency>
381+
<dependency>
382+
<groupId>org.testcontainers</groupId>
383+
<artifactId>junit-jupiter</artifactId>
384+
<version>${testcontainers.version}</version>
385+
<scope>test</scope>
386+
</dependency>
376387
<!-- < testcontainer dependencies /> -->
388+
377389
<!-- For easy parsing and execution of SQL files -->
378390
<dependency>
379391
<groupId>org.mybatis</groupId>

src/test/java/be/ugent/rml/Arguments_Test.java renamed to src/test/java/be/ugent/rml/ArgumentsTest.java

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package be.ugent.rml;
22

33
import be.ugent.rml.cli.Main;
4-
import org.junit.Test;
4+
import org.junit.jupiter.api.Test;
55
import org.rdfhdt.hdt.hdt.HDT;
66
import org.rdfhdt.hdt.hdt.HDTManager;
77
import org.rdfhdt.hdt.triples.IteratorTripleID;
@@ -16,11 +16,9 @@
1616
import static org.hamcrest.CoreMatchers.containsString;
1717
import static org.hamcrest.CoreMatchers.not;
1818
import static org.hamcrest.MatcherAssert.assertThat;
19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertThrows;
21-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.*;
2220

23-
public class Arguments_Test extends TestCore {
21+
public class ArgumentsTest extends TestCore {
2422

2523
@Test
2624
public void withConfigFile() throws Exception {
@@ -31,9 +29,8 @@ public void withConfigFile() throws Exception {
3129
false
3230
);
3331

34-
File outputFile = null;
3532
try {
36-
outputFile = Utils.getFile("./generated_output.nq");
33+
File outputFile = Utils.getFile("./generated_output.nq");
3734
assertTrue(outputFile.delete());
3835
} catch (Exception e) {
3936
e.printStackTrace();
@@ -91,10 +88,8 @@ public void withoutConfigFileWindowsSlashes() throws Exception {
9188
}
9289

9390
@Test
94-
public void nonexistingMappingFile() throws Exception {
95-
assertThrows(IllegalArgumentException.class, () -> {
96-
Main.run("-m ./argument-config-file-test-cases/I_DONT_EXIST.ttl -o ./generated_output.nq".split(" "));
97-
});
91+
public void nonexistingMappingFile() {
92+
assertThrows(IllegalArgumentException.class, () -> Main.run("-m ./argument-config-file-test-cases/I_DONT_EXIST.ttl -o ./generated_output.nq".split(" ")));
9893
}
9994

10095
@Test
@@ -119,9 +114,8 @@ public void mappingFileAndRawMappingString() throws Exception {
119114
false
120115
);
121116

122-
File outputFile = null;
123117
try {
124-
outputFile = Utils.getFile("./generated_output.nq");
118+
File outputFile = Utils.getFile("./generated_output.nq");
125119
assertTrue(outputFile.delete());
126120
} catch (Exception e) {
127121
e.printStackTrace();
@@ -139,9 +133,8 @@ public void multipleMappingFiles() throws Exception {
139133
false
140134
);
141135

142-
File outputFile = null;
143136
try {
144-
outputFile = Utils.getFile("./generated_output.nq");
137+
File outputFile = Utils.getFile("./generated_output.nq");
145138
assertTrue(outputFile.delete());
146139
} catch (Exception e) {
147140
e.printStackTrace();
@@ -174,9 +167,9 @@ public void testStdOut() throws Exception {
174167
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); // reset to original System.out
175168
}
176169

177-
assertThat(stdout.toString(StandardCharsets.UTF_8.name()), containsString("<http://example.com/10> <http://xmlns.com/foaf/0.1/name> \"Venus\\\"\"."));
178-
assertThat(stdout.toString(StandardCharsets.UTF_8.name()), containsString("<http://example.com/10> <http://example.com/id> \"10\"."));
179-
assertThat(stdout.toString(StandardCharsets.UTF_8.name()), containsString("<http://example.com/10> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person>."));
170+
assertThat(stdout.toString(StandardCharsets.UTF_8), containsString("<http://example.com/10> <http://xmlns.com/foaf/0.1/name> \"Venus\\\"\"."));
171+
assertThat(stdout.toString(StandardCharsets.UTF_8), containsString("<http://example.com/10> <http://example.com/id> \"10\"."));
172+
assertThat(stdout.toString(StandardCharsets.UTF_8), containsString("<http://example.com/10> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person>."));
180173
}
181174

182175

@@ -190,7 +183,7 @@ public void testVerboseWithoutCustomFunctionFile() throws Exception {
190183
} finally {
191184
System.setErr(new PrintStream(new FileOutputStream(FileDescriptor.err))); // reset to original System.err
192185
}
193-
assertThat(stdout.toString(StandardCharsets.UTF_8.name()), not(containsString("Using custom path to functions.ttl file: ")));
186+
assertThat(stdout.toString(StandardCharsets.UTF_8), not(containsString("Using custom path to functions.ttl file: ")));
194187
}
195188

196189
@Test
@@ -202,7 +195,7 @@ public void testWithCustomFunctionFile() throws Exception {
202195
} finally {
203196
System.setErr(new PrintStream(new FileOutputStream(FileDescriptor.err))); // reset to original System.err
204197
}
205-
assertThat(stdout.toString(StandardCharsets.UTF_8.name()), not(containsString("Using custom path to functions.ttl file: ")));
198+
assertThat(stdout.toString(StandardCharsets.UTF_8), not(containsString("Using custom path to functions.ttl file: ")));
206199
}
207200

208201
@Test
@@ -219,9 +212,8 @@ public void testWithCustomFunctionFileInternalFunctionsStillWork() throws Except
219212
false
220213
);
221214

222-
File outputFile = null;
223215
try {
224-
outputFile = Utils.getFile(actualOutPath);
216+
File outputFile = Utils.getFile(actualOutPath);
225217
assertTrue(outputFile.delete());
226218
} catch (Exception e) {
227219
e.printStackTrace();
@@ -244,7 +236,7 @@ public void testWithCustomFunctionFileVerboseFunctionLogging() throws Exception
244236
actualOutPath,
245237
false
246238
);
247-
assertThat(stdout.toString(StandardCharsets.UTF_8.name()), containsString("Loading function descriptions"));
239+
assertThat(stdout.toString(StandardCharsets.UTF_8), containsString("Loading function descriptions"));
248240

249241
try {
250242
File outputFile = Utils.getFile(actualOutPath);
@@ -275,7 +267,7 @@ public void outputTurtle() throws Exception {
275267

276268
try {
277269
byte[] encoded = Files.readAllBytes(Paths.get(actualTrigPath));
278-
String content = new String(encoded, "utf-8");
270+
String content = new String(encoded, StandardCharsets.UTF_8);
279271

280272
assertTrue(content.contains("@prefix foaf: <http://xmlns.com/foaf/0.1/> ."));
281273
} catch (IOException e) {
@@ -380,7 +372,7 @@ public void outputHDT() throws Exception {
380372
TripleID tripleID1 = iteratorTripleID1.next();
381373
TripleID tripleID2 = iteratorTripleID2.next();
382374

383-
assertTrue(tripleID1.equals(tripleID2));
375+
assertEquals(tripleID1, tripleID2);
384376
}
385377
} finally {
386378
assertTrue((new File(actualHDTPath)).delete());
@@ -491,9 +483,8 @@ public void pipeAndMapping() throws Exception {
491483
}
492484

493485
@Test
494-
public void wrongOutPutFile() throws Exception{
495-
assertThrows(IllegalArgumentException.class, () -> {
496-
Main.run("-m ./argument-config-file-test-cases/mapping.ttl -o ./wrong/file/output/generated_output.nq".split(" "));
497-
});
486+
public void wrongOutPutFile() {
487+
assertThrows(IllegalArgumentException.class, () ->
488+
Main.run("-m ./argument-config-file-test-cases/mapping.ttl -o ./wrong/file/output/generated_output.nq".split(" ")));
498489
}
499490
}

src/test/java/be/ugent/rml/Arguments_Test_MySQL.java renamed to src/test/java/be/ugent/rml/ArgumentsTestMySQLTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
package be.ugent.rml;
22

33
import be.ugent.rml.cli.Main;
4-
import org.junit.BeforeClass;
5-
import org.junit.Test;
4+
import org.junit.jupiter.api.BeforeAll;
5+
import org.junit.jupiter.api.Test;
6+
import org.junit.jupiter.api.TestInstance;
67
import org.slf4j.LoggerFactory;
78

89
import java.io.File;
910

10-
import static org.junit.Assert.assertTrue;
11+
import static org.junit.jupiter.api.Assertions.assertTrue;
1112

12-
public class Arguments_Test_MySQL extends MySQLTestCore {
1313

14-
@BeforeClass
14+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
15+
public class ArgumentsTestMySQLTest extends MySQLTestCore {
16+
17+
@BeforeAll
1518
public static void beforeClass() {
16-
logger = LoggerFactory.getLogger(Arguments_Test_MySQL.class);
19+
logger = LoggerFactory.getLogger(ArgumentsTestMySQLTest.class);
1720
}
1821

1922
@Test
@@ -26,7 +29,7 @@ public void executeR2RML() throws Exception {
2629

2730
prepareDatabase(resourcePath, "root", "");
2831

29-
Main.run(("-m " + mappingFilePath + " -o " + actualPath + " --r2rml-jdbcDSN " + dbURL + " --r2rml-username root -v").split(" "), cwd);
32+
Main.run(("-m " + mappingFilePath + " -o " + actualPath + " --r2rml-jdbcDSN " + getDbURL() + " --r2rml-username root -v").split(" "), cwd);
3033
compareFiles(
3134
expectedPath,
3235
actualPath,

src/test/java/be/ugent/rml/Custom_RML_FnO_Mapper_CSV_Test.java renamed to src/test/java/be/ugent/rml/CustomRMLFnOMapperCSVTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package be.ugent.rml;
22

3-
import org.junit.Ignore;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.Disabled;
4+
import org.junit.jupiter.api.Test;
55

66
import java.lang.reflect.InvocationTargetException;
77

88
import static org.junit.jupiter.api.Assertions.assertThrows;
99

1010

11-
public class Custom_RML_FnO_Mapper_CSV_Test extends TestFunctionCore {
11+
public class CustomRMLFnOMapperCSVTest extends TestFunctionCore {
1212
@Test
1313
public void evaluate_0000_CSV() throws Exception {
1414
doPreloadMapping("./rml-fno-test-cases/RMLFNOTC0000-CSV/mapping.ttl", "./rml-fno-test-cases/RMLFNOTC0000-CSV/output.ttl");
@@ -50,8 +50,8 @@ public void evaluate_0006_CSV() throws Exception {
5050
}
5151

5252
@Test
53-
public void evaluate_0007_CSV() throws Exception {
54-
assertThrows(InvocationTargetException.class, () -> {doPreloadMapping("./rml-fno-test-cases/RMLFNOTC0007-CSV/mapping.ttl", "./rml-fno-test-cases/RMLFNOTC0007-CSV/output.ttl");});
53+
public void evaluate_0007_CSV() {
54+
assertThrows(InvocationTargetException.class, () -> doPreloadMapping("./rml-fno-test-cases/RMLFNOTC0007-CSV/mapping.ttl", "./rml-fno-test-cases/RMLFNOTC0007-CSV/output.ttl"));
5555
}
5656

5757
@Test
@@ -60,19 +60,19 @@ public void evaluate_0008_CSV() throws Exception {
6060
}
6161

6262
@Test
63-
@Ignore
63+
@Disabled
6464
public void evaluate_0009_CSV() throws Exception {
6565
doPreloadMapping("./rml-fno-test-cases/RMLFNOTC0009-CSV/mapping.ttl", "./rml-fno-test-cases/RMLFNOTC0009-CSV/output.ttl");
6666
}
6767

6868
@Test
69-
@Ignore
69+
@Disabled
7070
public void evaluate_0010_CSV() throws Exception {
7171
doPreloadMapping("./rml-fno-test-cases/RMLFNOTC0010-CSV/mapping.ttl", "./rml-fno-test-cases/RMLFNOTC0010-CSV/output.ttl");
7272
}
7373

7474
@Test
75-
@Ignore
75+
@Disabled
7676
public void evaluate_0011_CSV() throws Exception {
7777
doPreloadMapping("./rml-fno-test-cases/RMLFNOTC0011-CSV/mapping.ttl", "./rml-fno-test-cases/RMLFNOTC0011-CSV/output.ttl");
7878
}
@@ -88,25 +88,25 @@ public void evaluate_0013_CSV() throws Exception {
8888
}
8989

9090
@Test
91-
@Ignore
91+
@Disabled
9292
public void evaluate_0014_CSV() throws Exception {
9393
doPreloadMapping("./rml-fno-test-cases/RMLFNOTC0014-CSV/mapping.ttl", "./rml-fno-test-cases/RMLFNOTC0014-CSV/output.ttl");
9494
}
9595

9696
@Test
97-
@Ignore
97+
@Disabled
9898
public void evaluate_0015_CSV() throws Exception {
9999
doPreloadMapping("./rml-fno-test-cases/RMLFNOTC0015-CSV/mapping.ttl", "./rml-fno-test-cases/RMLFNOTC0015-CSV/output.ttl");
100100
}
101101

102102
@Test
103-
@Ignore
103+
@Disabled
104104
public void evaluate_0016_CSV() throws Exception {
105105
doPreloadMapping("./rml-fno-test-cases/RMLFNOTC0016-CSV/mapping.ttl", "./rml-fno-test-cases/RMLFNOTC0016-CSV/output.nq");
106106
}
107107

108108
@Test
109-
@Ignore
109+
@Disabled
110110
public void evaluate_0017_CSV() throws Exception {
111111
doPreloadMapping("./rml-fno-test-cases/RMLFNOTC0017-CSV/mapping.ttl", "./rml-fno-test-cases/RMLFNOTC0017-CSV/output.ttl");
112112
}

src/test/java/be/ugent/rml/Custom_RML_FnO_Mapper_JSON_Test.java renamed to src/test/java/be/ugent/rml/CustomRMLFnOMapperJSONTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package be.ugent.rml;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44

5-
public class Custom_RML_FnO_Mapper_JSON_Test extends TestFunctionCore {
5+
public class CustomRMLFnOMapperJSONTest extends TestFunctionCore {
66
@Test
77
public void evaluate_0020_JSON() throws Exception {
88
doPreloadMapping("./rml-fno-test-cases/RMLFNOTC0020-JSON/mapping.ttl", "./rml-fno-test-cases/RMLFNOTC0020-JSON/output.ttl");

0 commit comments

Comments
 (0)