Skip to content

Commit e9d9c40

Browse files
committed
GH-5112 add test cases
1 parent 20fb23f commit e9d9c40

66 files changed

Lines changed: 1900 additions & 2 deletions

File tree

Some content is hidden

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

core/sail/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/AbstractShaclTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
package org.eclipse.rdf4j.sail.shacl;
1313

14+
import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT;
1415
import static org.junit.jupiter.params.provider.Arguments.arguments;
1516

1617
import java.io.File;
@@ -83,6 +84,7 @@
8384
import org.junit.jupiter.api.AfterEach;
8485
import org.junit.jupiter.api.Assertions;
8586
import org.junit.jupiter.api.BeforeAll;
87+
import org.junit.jupiter.api.parallel.Execution;
8688
import org.junit.jupiter.api.parallel.Isolated;
8789
import org.junit.jupiter.params.provider.Arguments;
8890
import org.slf4j.Logger;
@@ -311,7 +313,7 @@ static void afterAll() throws IllegalAccessException {
311313
}
312314

313315
@AfterEach
314-
void tearDown() {
316+
void afterEach() {
315317
fullLogging = false;
316318
}
317319

@@ -594,6 +596,12 @@ void referenceImplementationTestCaseValidation(TestCase testCase) {
594596
return;
595597
}
596598

599+
// the TopBraid SHACL API doesn't agree with other implementations on how multiple paths to the same target
600+
// should work
601+
if (testCase.testCasePath.startsWith("test-cases/nodeKind/simpleCompress/")) {
602+
return;
603+
}
604+
597605
printTestCase(testCase);
598606

599607
Dataset shaclDataset = DatasetFactory.create();
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Eclipse RDF4J contributors.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Distribution License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/org/documents/edl-v10.php.
8+
*
9+
* SPDX-License-Identifier: BSD-3-Clause
10+
*******************************************************************************/
11+
12+
package org.eclipse.rdf4j.sail.shacl;
13+
14+
import org.eclipse.rdf4j.common.transaction.IsolationLevel;
15+
import org.eclipse.rdf4j.repository.sail.SailRepository;
16+
import org.eclipse.rdf4j.sail.Sail;
17+
import org.eclipse.rdf4j.sail.shacl.ast.Shape;
18+
import org.junit.jupiter.api.AfterEach;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.params.ParameterizedTest;
21+
import org.junit.jupiter.params.provider.MethodSource;
22+
23+
/**
24+
* @author Håvard Ottestad
25+
*/
26+
public class ShaclTestWithoutSparqlValidationTest extends AbstractShaclTest {
27+
28+
@Override
29+
SailRepository getShaclSail(TestCase testCase) {
30+
SailRepository sail = super.getShaclSail(testCase);
31+
ShaclSail shaclSail = (ShaclSail) sail.getSail();
32+
shaclSail.sparqlValidation = false;
33+
return sail;
34+
}
35+
36+
@ParameterizedTest
37+
@MethodSource("testsToRunWithIsolationLevel")
38+
public void test(TestCase testCase, IsolationLevel isolationLevel) {
39+
runWithAutomaticLogging(() -> runTestCase(testCase, isolationLevel, false));
40+
}
41+
42+
@ParameterizedTest
43+
@MethodSource("testCases")
44+
public void testSingleTransaction(TestCase testCase) {
45+
runWithAutomaticLogging(() -> runTestCaseSingleTransaction(testCase));
46+
}
47+
48+
@ParameterizedTest
49+
@MethodSource("testsToRunWithIsolationLevel")
50+
public void testRevalidation(TestCase testCase, IsolationLevel isolationLevel) {
51+
runWithAutomaticLogging(() -> runTestCaseRevalidate(testCase, isolationLevel));
52+
}
53+
54+
@ParameterizedTest
55+
@MethodSource("testsToRunWithIsolationLevel")
56+
public void testNonEmpty(TestCase testCase, IsolationLevel isolationLevel) {
57+
runWithAutomaticLogging(() -> runTestCase(testCase, isolationLevel, true));
58+
}
59+
60+
@ParameterizedTest
61+
@MethodSource("testCases")
62+
public void testParsing(TestCase testCase) {
63+
runWithAutomaticLogging(() -> runParsingTest(testCase));
64+
}
65+
66+
@ParameterizedTest
67+
@MethodSource("testCases")
68+
public void testReferenceImplementation(TestCase testCase) {
69+
runWithAutomaticLogging(() -> referenceImplementationTestCaseValidation(testCase));
70+
}
71+
72+
@ParameterizedTest
73+
@MethodSource("testCases")
74+
public void testShaclValidator(TestCase testCase) {
75+
runWithAutomaticLogging(() -> runWithShaclValidator(testCase));
76+
}
77+
78+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
PREFIX ex: <http://example.com/ns#>
2+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
3+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
4+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
5+
PREFIX sh: <http://www.w3.org/ns/shacl#>
6+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
7+
8+
INSERT DATA {
9+
ex:validPerson1 a ex:AnyTarget, ex:Person, ex:SecondTarget ;
10+
ex:knows1 [ ex:knows2 [ ex:knows3 [ ex:knows4 ex:peter ]]].
11+
12+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@prefix ex: <http://example.com/ns#> .
2+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
3+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
4+
@prefix sh: <http://www.w3.org/ns/shacl#> .
5+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
6+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
7+
@prefix rsx: <http://rdf4j.org/shacl-extensions#> .
8+
@prefix rdf4j: <http://rdf4j.org/schema/rdf4j#> .
9+
10+
[] a sh:ValidationReport;
11+
rdf4j:truncated false;
12+
sh:conforms false;
13+
sh:result [ a sh:ValidationResult;
14+
rsx:shapesGraph rdf4j:SHACLShapeGraph;
15+
sh:focusNode ex:validPerson1;
16+
sh:resultPath _:867c9670a0c541e184b71a3107a202a6598;
17+
sh:resultSeverity sh:Violation;
18+
sh:sourceConstraintComponent sh:ClassConstraintComponent;
19+
sh:sourceShape [ a sh:PropertyShape;
20+
sh:class ex:Person;
21+
sh:path _:867c9670a0c541e184b71a3107a202a6598
22+
];
23+
sh:value ex:peter
24+
] .
25+
26+
_:867c9670a0c541e184b71a3107a202a6598 rdf:first ex:knows1;
27+
rdf:rest (ex:knows2 ex:knows3 ex:knows4) .

core/sail/shacl/src/test/resources/test-cases/class/complexPath/shacl.trig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
rdf4j:SHACLShapeGraph {
1010
ex:PersonShape a sh:NodeShape;
11-
sh:targetClass ex:Person, ex:SecondTarget;
11+
sh:targetClass ex:Person, ex:SecondTarget, ex:AnyTarget;
1212
sh:property [
1313
sh:path (ex:knows1 ex:knows2 ex:knows3 ex:knows4);
1414
sh:class ex:Person
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
PREFIX ex: <http://example.com/ns#>
2+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
3+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
4+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
5+
PREFIX sh: <http://www.w3.org/ns/shacl#>
6+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
7+
8+
INSERT DATA {
9+
ex:validPerson1 a ex:Person ;
10+
ex:knows1 [ex:knows2 [ex:knows3 [ex:knows4 ex:p1]]].
11+
12+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@prefix ex: <http://example.com/ns#> .
2+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
3+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
4+
@prefix sh: <http://www.w3.org/ns/shacl#> .
5+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
6+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
7+
@prefix rsx: <http://rdf4j.org/shacl-extensions#> .
8+
@prefix rdf4j: <http://rdf4j.org/schema/rdf4j#> .
9+
10+
[] a sh:ValidationReport;
11+
rdf4j:truncated false;
12+
sh:conforms false;
13+
sh:result [ a sh:ValidationResult;
14+
rsx:dataGraph rdf4j:nil;
15+
rsx:shapesGraph rdf4j:nil;
16+
sh:focusNode [];
17+
sh:resultPath ex:knows2;
18+
sh:resultSeverity sh:Violation;
19+
sh:sourceConstraintComponent sh:NodeConstraintComponent;
20+
sh:sourceShape [ a sh:PropertyShape;
21+
sh:node [ a sh:NodeShape;
22+
sh:property [ a sh:PropertyShape;
23+
sh:path ex:knows3;
24+
sh:property [ a sh:PropertyShape;
25+
sh:datatype xsd:float;
26+
sh:path ex:knows4
27+
]
28+
]
29+
];
30+
sh:path ex:knows2
31+
];
32+
sh:value []
33+
] .
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
PREFIX ex: <http://example.com/ns#>
2+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
3+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
4+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
5+
PREFIX sh: <http://www.w3.org/ns/shacl#>
6+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
7+
8+
INSERT DATA {
9+
ex:validPerson1 a ex:Person ;
10+
ex:knows1 ex:p1.
11+
12+
ex:p1 ex:knows2 ex:p2.
13+
ex:p2 ex:knows3 ex:p3.
14+
ex:p3 ex:knows4 ex:p4.
15+
16+
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@prefix ex: <http://example.com/ns#> .
2+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
3+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
4+
@prefix sh: <http://www.w3.org/ns/shacl#> .
5+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
6+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
7+
@prefix rsx: <http://rdf4j.org/shacl-extensions#> .
8+
@prefix rdf4j: <http://rdf4j.org/schema/rdf4j#> .
9+
10+
[] a sh:ValidationReport;
11+
rdf4j:truncated false;
12+
sh:conforms false;
13+
sh:result [ a sh:ValidationResult;
14+
rsx:dataGraph rdf4j:nil;
15+
rsx:shapesGraph rdf4j:nil;
16+
sh:focusNode ex:p1;
17+
sh:resultPath ex:knows2;
18+
sh:resultSeverity sh:Violation;
19+
sh:sourceConstraintComponent sh:NodeConstraintComponent;
20+
sh:sourceShape [ a sh:PropertyShape;
21+
sh:node [ a sh:NodeShape;
22+
sh:property [ a sh:PropertyShape;
23+
sh:path ex:knows3;
24+
sh:property [ a sh:PropertyShape;
25+
sh:datatype xsd:float;
26+
sh:path ex:knows4
27+
]
28+
]
29+
];
30+
sh:path ex:knows2
31+
];
32+
sh:value ex:p2
33+
] .
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
PREFIX ex: <http://example.com/ns#>
2+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
3+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
4+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
5+
PREFIX sh: <http://www.w3.org/ns/shacl#>
6+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
7+
8+
INSERT DATA {
9+
ex:validPerson1 a ex:Person ;
10+
ex:knows1 ex:p1, ex:p1_1.
11+
12+
ex:p1 ex:knows2 ex:p2.
13+
ex:p1_1 ex:knows2 ex:p2.
14+
15+
ex:p2 ex:knows3 ex:p3.
16+
ex:p3 ex:knows4 ex:p4.
17+
18+
}

0 commit comments

Comments
 (0)