From 4de4207d42dc670a85e6ca426c064da05b239225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Fri, 12 Jan 2024 18:54:40 +0100 Subject: [PATCH] GH-4592 allows users to see variables that are used in compliance tests --- .../manifest/SPARQL10QueryComplianceTest.java | 35 +- .../manifest/SPARQL11QueryComplianceTest.java | 4 +- .../SPARQL11SyntaxComplianceTest.java | 1 - .../SPARQL11UpdateComplianceTest.java | 3 +- .../manifest/SPARQL12QueryComplianceTest.java | 4 +- .../sparql/manifest/SPARQLComplianceTest.java | 1 - .../manifest/SPARQLQueryComplianceTest.java | 319 +++++++++--------- .../manifest/SPARQLSyntaxComplianceTest.java | 3 +- 8 files changed, 191 insertions(+), 179 deletions(-) diff --git a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL10QueryComplianceTest.java b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL10QueryComplianceTest.java index 065a5c8b02c..80bf656d768 100644 --- a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL10QueryComplianceTest.java +++ b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL10QueryComplianceTest.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.rdf4j.testsuite.query.parser.sparql.manifest; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -21,28 +20,26 @@ * A test suite that runs the W3C Approved SPARQL 1.0 query tests. * * @author Jeen Broekstra - * * @see sparql docs test */ public abstract class SPARQL10QueryComplianceTest extends SPARQLQueryComplianceTest { - private final List defaultIgnoredTests = new ArrayList<>(); - { - // incompatible with SPARQL 1.1 - syntax for decimals was modified - defaultIgnoredTests.add("Basic - Term 6"); - // incompatible with SPARQL 1.1 - syntax for decimals was modified - defaultIgnoredTests.add("Basic - Term 7"); - // Test is incorrect: assumes timezoned date is comparable with non-timezoned - defaultIgnoredTests.add("date-2"); - // Incompatible with SPARQL 1.1 - string-typed literals and plain literals are - // identical - defaultIgnoredTests.add("Strings: Distinct"); - // Incompatible with SPARQL 1.1 - string-typed literals and plain literals are - // identical - defaultIgnoredTests.add("All: Distinct"); - // Incompatible with SPARQL 1.1 - string-typed literals and plain literals are - // identical - defaultIgnoredTests.add("SELECT REDUCED ?x with strings"); + private static final String[] defaultIgnoredTests = { + // incompatible with SPARQL 1.1 - syntax for decimals was modified + "Basic - Term 6", + // incompatible with SPARQL 1.1 - syntax for decimals was modified + "Basic - Term 7", + // Test is incorrect: assumes timezoned date is comparable with non-timezoned + "date-2", + // Incompatible with SPARQL 1.1 - string-typed literals and plain literals are + // identical + "Strings: Distinct", + // Incompatible with SPARQL 1.1 - string-typed literals and plain literals are + // identical + "All: Distinct", + // Incompatible with SPARQL 1.1 - string-typed literals and plain literals are + // identical + "SELECT REDUCED ?x with strings" }; public SPARQL10QueryComplianceTest() { diff --git a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11QueryComplianceTest.java b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11QueryComplianceTest.java index d8281fdd503..a1190eab436 100644 --- a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11QueryComplianceTest.java +++ b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11QueryComplianceTest.java @@ -20,15 +20,15 @@ * A test suite that runs the W3C Approved SPARQL 1.1 query tests. * * @author Jeen Broekstra - * * @see sparql docs tests */ public abstract class SPARQL11QueryComplianceTest extends SPARQLQueryComplianceTest { public SPARQL11QueryComplianceTest() { super(List.of("service")); - for (String ig : defaultIgnoredTests) + for (String ig : defaultIgnoredTests) { addIgnoredTest(ig); + } } private static final String[] defaultIgnoredTests = { diff --git a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11SyntaxComplianceTest.java b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11SyntaxComplianceTest.java index 721753ed157..2e2c58314e3 100644 --- a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11SyntaxComplianceTest.java +++ b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11SyntaxComplianceTest.java @@ -17,7 +17,6 @@ * A test suite that runs the W3C Approved SPARQL 1.1 Syntax tests. * * @author Jeen Broekstra - * * @see sparql docs tests */ diff --git a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11UpdateComplianceTest.java b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11UpdateComplianceTest.java index dfdb2c20523..d767f4c465d 100644 --- a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11UpdateComplianceTest.java +++ b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL11UpdateComplianceTest.java @@ -383,8 +383,9 @@ public SPARQLUpdateTestManifest(String filename) { DynamicSPARQL11UpdateComplianceTest ds11ut = new DynamicSPARQL11UpdateComplianceTest( displayName, testURI.stringValue(), testName, requestFile.stringValue(), defaultGraphURI, inputNamedGraphs, resultDefaultGraphURI, resultNamedGraphs); - if (!shouldIgnoredTest(testName)) + if (!shouldIgnoredTest(testName)) { tests.add(DynamicTest.dynamicTest(displayName, ds11ut::test)); + } } } } diff --git a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL12QueryComplianceTest.java b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL12QueryComplianceTest.java index e8cf944dd46..958f9aab5d2 100644 --- a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL12QueryComplianceTest.java +++ b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQL12QueryComplianceTest.java @@ -20,7 +20,6 @@ * A test suite that runs the SPARQL 1.2 community group's query tests. * * @author Jeen Broekstra - * * @see sparql 1.2 */ public abstract class SPARQL12QueryComplianceTest extends SPARQLQueryComplianceTest { @@ -31,8 +30,9 @@ public abstract class SPARQL12QueryComplianceTest extends SPARQLQueryComplianceT public SPARQL12QueryComplianceTest() { super(excludedSubdirs); - for (String ig : defaultIgnoredTests) + for (String ig : defaultIgnoredTests) { addIgnoredTest(ig); + } } @TestFactory diff --git a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLComplianceTest.java b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLComplianceTest.java index 22c13b13d27..623198cd1c9 100644 --- a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLComplianceTest.java +++ b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLComplianceTest.java @@ -41,7 +41,6 @@ * Base functionality for SPARQL compliance test suites using a W3C-style Manifest. * * @author Jeen Broekstra - * */ public abstract class SPARQLComplianceTest { diff --git a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLQueryComplianceTest.java b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLQueryComplianceTest.java index d13deef7a8e..d5b6345f980 100644 --- a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLQueryComplianceTest.java +++ b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLQueryComplianceTest.java @@ -88,7 +88,20 @@ public SPARQLQueryComplianceTest(List excludedSubdirs) { private static final Logger logger = LoggerFactory.getLogger(SPARQLQueryComplianceTest.class); + protected abstract Repository newRepository() throws Exception; + + private Repository createRepository() throws Exception { + Repository repo = newRepository(); + try (RepositoryConnection con = repo.getConnection()) { + con.clear(); + con.clearNamespaces(); + } + return repo; + } + /** + * This can be overridden in order to read one or more of the test parameters. + * * @param displayName * @param testURI * @param name @@ -96,7 +109,159 @@ public SPARQLQueryComplianceTest(List excludedSubdirs) { * @param resultFileURL * @param dataset * @param ordered + * @param laxCardinality + * @return */ + protected void testParameterListener(String displayName, String testURI, String name, String queryFileURL, + String resultFileURL, Dataset dataset, boolean ordered, boolean laxCardinality) { + // no-op + } + + @TestFactory + public abstract Collection tests(); + + public Collection getTestData(String manifestResource) { + return getTestData(manifestResource, true); + } + + public Collection getTestData(String manifestResource, boolean approvedOnly) { + List tests = new ArrayList<>(); + + Deque manifests = new ArrayDeque<>(); + manifests.add(this.getClass().getClassLoader().getResource(manifestResource).toExternalForm()); + while (!manifests.isEmpty()) { + String pop = manifests.pop(); + SPARQLQueryTestManifest manifest = new SPARQLQueryTestManifest(pop, excludedSubdirs, approvedOnly); + tests.addAll(manifest.tests); + manifests.addAll(manifest.subManifests); + } + + return tests; + } + + protected class SPARQLQueryTestManifest { + private final List tests = new ArrayList<>(); + private final List subManifests = new ArrayList<>(); + + public SPARQLQueryTestManifest(String filename, List excludedSubdirs) { + this(filename, excludedSubdirs, true); + } + + public SPARQLQueryTestManifest(String filename, List excludedSubdirs, boolean approvedOnly) { + SailRepository sailRepository = new SailRepository(new MemoryStore()); + try (SailRepositoryConnection connection = sailRepository.getConnection()) { + connection.add(new URL(filename), filename, RDFFormat.TURTLE); + } catch (IOException e) { + throw new RuntimeException(e); + } + + try (SailRepositoryConnection connection = sailRepository.getConnection()) { + + String manifestQuery = " PREFIX qt: " + + "PREFIX mf: " + + "SELECT DISTINCT ?manifestFile " + + "WHERE { [] mf:include [ rdf:rest*/rdf:first ?manifestFile ] . } "; + + try (TupleQueryResult manifestResults = connection + .prepareTupleQuery(QueryLanguage.SPARQL, manifestQuery, filename) + .evaluate()) { + for (BindingSet bindingSet : manifestResults) { + String subManifestFile = bindingSet.getValue("manifestFile").stringValue(); + if (SPARQLQueryComplianceTest.includeSubManifest(subManifestFile, excludedSubdirs)) { + getSubManifests().add(subManifestFile); + } + } + } + + StringBuilder query = new StringBuilder(512); + query.append(" PREFIX mf: \n"); + query.append(" PREFIX dawgt: \n"); + query.append(" PREFIX qt: \n"); + query.append(" PREFIX sd: \n"); + query.append(" PREFIX ent: \n"); + query.append( + " SELECT DISTINCT ?testURI ?testName ?resultFile ?action ?queryFile ?defaultGraph ?ordered ?laxCardinality \n"); + query.append(" WHERE { [] rdf:first ?testURI . \n"); + if (approvedOnly) { + query.append(" ?testURI dawgt:approval dawgt:Approved . \n"); + } + query.append(" ?testURI mf:name ?testName; \n"); + query.append(" mf:result ?resultFile . \n"); + query.append(" OPTIONAL { ?testURI mf:checkOrder ?ordered } \n"); + query.append(" OPTIONAL { ?testURI mf:requires ?requirement } \n"); + query.append(" ?testURI mf:action ?action. \n"); + query.append(" ?action qt:query ?queryFile . \n"); + query.append(" OPTIONAL { ?action qt:data ?defaultGraph } \n"); + query.append(" OPTIONAL { ?action sd:entailmentRegime ?regime } \n"); + query.append(" OPTIONAL { ?testURI mf:resultCardinality ?laxCardinality, mf:LaxCardinality } \n"); + // skip tests involving CSV result files, these are not query tests + query.append(" FILTER(!STRENDS(STR(?resultFile), \"csv\")) \n"); + // skip tests involving entailment regimes + query.append(" FILTER(!BOUND(?regime)) \n"); + // skip test involving basic federation, these are tested separately. + query.append(" FILTER (!BOUND(?requirement) || (?requirement != mf:BasicFederation)) \n"); + query.append(" }\n"); + + try (TupleQueryResult result = connection.prepareTupleQuery(query.toString()).evaluate()) { + + query.setLength(0); + query.append(" PREFIX qt: \n"); + query.append(" SELECT ?graph \n"); + query.append(" WHERE { ?action qt:graphData ?graph } \n"); + TupleQuery namedGraphsQuery = connection.prepareTupleQuery(query.toString()); + + for (BindingSet bs : result) { + // FIXME I'm sure there's a neater way to do this + String testName = bs.getValue("testName").stringValue(); + String displayName = filename.substring(0, filename.lastIndexOf('/')); + displayName = displayName.substring(displayName.lastIndexOf('/') + 1, displayName.length()) + + ": " + testName; + + IRI defaultGraphURI = (IRI) bs.getValue("defaultGraph"); + Value action = bs.getValue("action"); + Value ordered = bs.getValue("ordered"); + + SimpleDataset dataset = null; + + // Query named graphs + namedGraphsQuery.setBinding("action", action); + try (TupleQueryResult namedGraphs = namedGraphsQuery.evaluate()) { + if (defaultGraphURI != null || namedGraphs.hasNext()) { + dataset = new SimpleDataset(); + if (defaultGraphURI != null) { + dataset.addDefaultGraph(defaultGraphURI); + } + while (namedGraphs.hasNext()) { + BindingSet graphBindings = namedGraphs.next(); + IRI namedGraphURI = (IRI) graphBindings.getValue("graph"); + dataset.addNamedGraph(namedGraphURI); + } + } + } + + DynamicSPARQLQueryComplianceTest ds11ut = new DynamicSPARQLQueryComplianceTest(displayName, + bs.getValue("testURI").stringValue(), testName, bs.getValue("queryFile").stringValue(), + bs.getValue("resultFile").stringValue(), dataset, + Literals.getBooleanValue(ordered, false), bs.hasBinding("laxCardinality")); + + if (!shouldIgnoredTest(testName)) { + tests.add(DynamicTest.dynamicTest(displayName, ds11ut::test)); + } + } + } + } + + } + + /** + * @return the subManifests + */ + public List getSubManifests() { + return subManifests; + } + + } + public class DynamicSPARQLQueryComplianceTest extends DynamicSparqlComplianceTest { private final String queryFileURL; @@ -158,6 +323,8 @@ private boolean readExpectedBooleanQueryResult() throws Exception { @Override public void setUp() throws Exception { + testParameterListener(getDisplayName(), getTestURI(), getName(), queryFileURL, resultFileURL, dataset, + ordered, laxCardinality); dataRepository = createRepository(); if (dataset != null) { try { @@ -380,156 +547,4 @@ private void compareTupleQueryResults(TupleQueryResult queryResult, TupleQueryRe } } - protected abstract Repository newRepository() throws Exception; - - private Repository createRepository() throws Exception { - Repository repo = newRepository(); - try (RepositoryConnection con = repo.getConnection()) { - con.clear(); - con.clearNamespaces(); - } - return repo; - } - - protected class SPARQLQueryTestManifest { - private final List tests = new ArrayList<>(); - private final List subManifests = new ArrayList<>(); - - public SPARQLQueryTestManifest(String filename, List excludedSubdirs) { - this(filename, excludedSubdirs, true); - } - - public SPARQLQueryTestManifest(String filename, List excludedSubdirs, boolean approvedOnly) { - SailRepository sailRepository = new SailRepository(new MemoryStore()); - try (SailRepositoryConnection connection = sailRepository.getConnection()) { - connection.add(new URL(filename), filename, RDFFormat.TURTLE); - } catch (IOException e) { - throw new RuntimeException(e); - } - - try (SailRepositoryConnection connection = sailRepository.getConnection()) { - - String manifestQuery = " PREFIX qt: " - + "PREFIX mf: " - + "SELECT DISTINCT ?manifestFile " - + "WHERE { [] mf:include [ rdf:rest*/rdf:first ?manifestFile ] . } "; - - try (TupleQueryResult manifestResults = connection - .prepareTupleQuery(QueryLanguage.SPARQL, manifestQuery, filename) - .evaluate()) { - for (BindingSet bindingSet : manifestResults) { - String subManifestFile = bindingSet.getValue("manifestFile").stringValue(); - if (SPARQLQueryComplianceTest.includeSubManifest(subManifestFile, excludedSubdirs)) { - getSubManifests().add(subManifestFile); - } - } - } - - StringBuilder query = new StringBuilder(512); - query.append(" PREFIX mf: \n"); - query.append(" PREFIX dawgt: \n"); - query.append(" PREFIX qt: \n"); - query.append(" PREFIX sd: \n"); - query.append(" PREFIX ent: \n"); - query.append( - " SELECT DISTINCT ?testURI ?testName ?resultFile ?action ?queryFile ?defaultGraph ?ordered ?laxCardinality \n"); - query.append(" WHERE { [] rdf:first ?testURI . \n"); - if (approvedOnly) { - query.append(" ?testURI dawgt:approval dawgt:Approved . \n"); - } - query.append(" ?testURI mf:name ?testName; \n"); - query.append(" mf:result ?resultFile . \n"); - query.append(" OPTIONAL { ?testURI mf:checkOrder ?ordered } \n"); - query.append(" OPTIONAL { ?testURI mf:requires ?requirement } \n"); - query.append(" ?testURI mf:action ?action. \n"); - query.append(" ?action qt:query ?queryFile . \n"); - query.append(" OPTIONAL { ?action qt:data ?defaultGraph } \n"); - query.append(" OPTIONAL { ?action sd:entailmentRegime ?regime } \n"); - query.append(" OPTIONAL { ?testURI mf:resultCardinality ?laxCardinality, mf:LaxCardinality } \n"); - // skip tests involving CSV result files, these are not query tests - query.append(" FILTER(!STRENDS(STR(?resultFile), \"csv\")) \n"); - // skip tests involving entailment regimes - query.append(" FILTER(!BOUND(?regime)) \n"); - // skip test involving basic federation, these are tested separately. - query.append(" FILTER (!BOUND(?requirement) || (?requirement != mf:BasicFederation)) \n"); - query.append(" }\n"); - - try (TupleQueryResult result = connection.prepareTupleQuery(query.toString()).evaluate()) { - - query.setLength(0); - query.append(" PREFIX qt: \n"); - query.append(" SELECT ?graph \n"); - query.append(" WHERE { ?action qt:graphData ?graph } \n"); - TupleQuery namedGraphsQuery = connection.prepareTupleQuery(query.toString()); - - for (BindingSet bs : result) { - // FIXME I'm sure there's a neater way to do this - String testName = bs.getValue("testName").stringValue(); - String displayName = filename.substring(0, filename.lastIndexOf('/')); - displayName = displayName.substring(displayName.lastIndexOf('/') + 1, displayName.length()) - + ": " + testName; - - IRI defaultGraphURI = (IRI) bs.getValue("defaultGraph"); - Value action = bs.getValue("action"); - Value ordered = bs.getValue("ordered"); - - SimpleDataset dataset = null; - - // Query named graphs - namedGraphsQuery.setBinding("action", action); - try (TupleQueryResult namedGraphs = namedGraphsQuery.evaluate()) { - if (defaultGraphURI != null || namedGraphs.hasNext()) { - dataset = new SimpleDataset(); - if (defaultGraphURI != null) { - dataset.addDefaultGraph(defaultGraphURI); - } - while (namedGraphs.hasNext()) { - BindingSet graphBindings = namedGraphs.next(); - IRI namedGraphURI = (IRI) graphBindings.getValue("graph"); - dataset.addNamedGraph(namedGraphURI); - } - } - } - DynamicSPARQLQueryComplianceTest ds11ut = new DynamicSPARQLQueryComplianceTest(displayName, - bs.getValue("testURI").stringValue(), testName, bs.getValue("queryFile").stringValue(), - bs.getValue("resultFile").stringValue(), dataset, - Literals.getBooleanValue(ordered, false), bs.hasBinding("laxCardinality")); - if (!shouldIgnoredTest(testName)) - tests.add(DynamicTest.dynamicTest(displayName, ds11ut::test)); - } - } - } - - } - - /** - * @return the subManifests - */ - public List getSubManifests() { - return subManifests; - } - - } - - @TestFactory - public abstract Collection tests(); - - public Collection getTestData(String manifestResource) { - return getTestData(manifestResource, true); - } - - public Collection getTestData(String manifestResource, boolean approvedOnly) { - List tests = new ArrayList<>(); - - Deque manifests = new ArrayDeque<>(); - manifests.add(this.getClass().getClassLoader().getResource(manifestResource).toExternalForm()); - while (!manifests.isEmpty()) { - String pop = manifests.pop(); - SPARQLQueryTestManifest manifest = new SPARQLQueryTestManifest(pop, excludedSubdirs, approvedOnly); - tests.addAll(manifest.tests); - manifests.addAll(manifest.subManifests); - } - - return tests; - } } diff --git a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLSyntaxComplianceTest.java b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLSyntaxComplianceTest.java index dfa91721dff..4fde7632403 100644 --- a/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLSyntaxComplianceTest.java +++ b/testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/query/parser/sparql/manifest/SPARQLSyntaxComplianceTest.java @@ -233,8 +233,9 @@ public SPARQLSyntaxManifest(String filename) { DynamicSPARQLSyntaxComplianceTest ds11ut = new DynamicSPARQLSyntaxComplianceTest(displayName, testURI.stringValue(), testName, action.stringValue(), positiveTest); - if (!shouldIgnoredTest(testName)) + if (!shouldIgnoredTest(testName)) { tests.add(DynamicTest.dynamicTest(displayName, ds11ut::test)); + } } }