Skip to content

Commit

Permalink
Run the tests for the prefixes separately.
Browse files Browse the repository at this point in the history
  • Loading branch information
JervenBolleman committed May 17, 2024
1 parent 465f4f8 commit f450d11
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.NodeIterator;
import org.apache.jena.riot.RDFDataMgr;
import org.eclipse.rdf4j.model.vocabulary.SHACL;

public class CreateTestWithJenaMethods {

Expand All @@ -25,7 +26,7 @@ static void testQueryValid(Path p, String projectPrefixes) {
Model model = RDFDataMgr.loadModel(p.toUri().toString());
assertFalse(model.isEmpty());
Stream.of("ask", "select", "concat", "describe")
.map(s -> model.listObjectsOfProperty(model.createProperty("http://www.w3.org/ns/shacl#", s)))
.map(s -> model.listObjectsOfProperty(model.createProperty(SHACL.NAMESPACE, s)))
.map(NodeIterator::toList).flatMap(List::stream).forEach(n -> {
assertNotNull(n);
Literal ql = n.asLiteral();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.impl.LinkedHashModel;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.model.vocabulary.SHACL;
import org.eclipse.rdf4j.query.MalformedQueryException;
import org.eclipse.rdf4j.query.parser.QueryParser;
import org.eclipse.rdf4j.query.parser.sparql.SPARQLParserFactory;
Expand All @@ -41,7 +42,7 @@ static void testQueryValid(Path p, String projectPrefixes) {
QueryParser parser = new SPARQLParserFactory().getParser();
Stream.of("ask", "select", "concat", "describe")
.map(s -> model.getStatements(null,
SimpleValueFactory.getInstance().createIRI("http://www.w3.org/ns/shacl#", s), null))
SimpleValueFactory.getInstance().createIRI(SHACL.NAMESPACE, s), null))
.map(Iterable::iterator).forEach(i -> {
while (i.hasNext()) {
Value obj = i.next().getObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public Stream<DynamicTest> testAllWithRDF4j() throws URISyntaxException, IOExcep
projectPrefixes) -> () -> CreateTestWithRDF4jMethods.testQueryValid(p, projectPrefixes);
return testAll(tester);
}

@TestFactory
public Stream<DynamicTest> testPrefixDeclarations() throws URISyntaxException, IOException {
URL baseDir = getClass().getResource("/");
Path basePath = Paths.get(baseDir.toURI());
return Files.walk(basePath, 5).filter(this::isTurtleAndPrefixFile).flatMap(this::testPrefixes);
}

private Stream<DynamicTest> testAll(BiFunction<Path, String, Executable> tester)
throws URISyntaxException, IOException {
Expand All @@ -58,9 +65,8 @@ private Stream<DynamicTest> testAll(BiFunction<Path, String, Executable> tester)
String commonPrefixes = extractPrefixes(Paths.get(getClass().getResource("/prefixes.ttl").toURI()));
return Files.list(basePath).flatMap(path -> {
try {
Stream<DynamicTest> testForEachExample = Files.walk(path, 5).filter(this::isTurtleButNotPrefixFile)
return Files.walk(path, 5).filter(this::isTurtleButNotPrefixFile)
.map(p -> createTest(tester, path, extractProjectPrefixes(commonPrefixes, path), p));
return Stream.concat(testPrefixes(path), testForEachExample);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -83,8 +89,7 @@ String extractProjectPrefixes(String commonPrefixes, Path path) {
return projectPrefixes;
}

private Stream<DynamicTest> testPrefixes(Path path) {
Path prefixes = Paths.get(path.toString(), "prefixes.ttl");
private Stream<DynamicTest> testPrefixes(Path prefixes) {
if (Files.exists(prefixes)) {
return Stream
.of(DynamicTest.dynamicTest(prefixes.getParent().getFileName().toString() + ":prefixes.ttl", () -> {
Expand All @@ -108,7 +113,7 @@ private String extractPrefixes(Path prefixes) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution next = rs.next();
prefixesSB.append(next.getLiteral("s").getValue());
prefixesSB.append(next.getLiteral("s").getValue()).append('\n');
}
rs.close();
qe.close();
Expand All @@ -119,4 +124,9 @@ private boolean isTurtleButNotPrefixFile(Path p) {
return Files.exists(p) && p.toUri().getPath().endsWith(".ttl") && !p.toUri().getPath().endsWith("prefixes.ttl")
&& Files.isRegularFile(p);
}

private boolean isTurtleAndPrefixFile(Path p) {
return Files.exists(p) && p.toUri().getPath().endsWith("prefixes.ttl")
&& Files.isRegularFile(p);
}
}

0 comments on commit f450d11

Please sign in to comment.