|
10 | 10 | *******************************************************************************/ |
11 | 11 | package org.eclipse.rdf4j.sail.shacl; |
12 | 12 |
|
| 13 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
13 | 14 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
14 | 15 | import static org.junit.jupiter.api.Assertions.assertThrows; |
15 | 16 |
|
16 | 17 | import java.net.URL; |
17 | 18 | import java.util.Objects; |
18 | 19 | import java.util.Set; |
19 | 20 |
|
| 21 | +import org.eclipse.rdf4j.common.transaction.IsolationLevels; |
| 22 | +import org.eclipse.rdf4j.model.Resource; |
| 23 | +import org.eclipse.rdf4j.model.util.Values; |
20 | 24 | import org.eclipse.rdf4j.model.vocabulary.RDF4J; |
| 25 | +import org.eclipse.rdf4j.model.vocabulary.RDFS; |
21 | 26 | import org.eclipse.rdf4j.repository.RepositoryException; |
22 | 27 | import org.eclipse.rdf4j.repository.sail.SailRepository; |
23 | 28 | import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; |
24 | 29 | import org.eclipse.rdf4j.rio.RDFFormat; |
| 30 | +import org.eclipse.rdf4j.sail.memory.MemoryStore; |
25 | 31 | import org.eclipse.rdf4j.sail.shacl.ast.ShaclShapeParsingException; |
26 | 32 | import org.junit.jupiter.api.Test; |
27 | 33 |
|
28 | 34 | class DeepRecursionValidationTest { |
29 | 35 |
|
| 36 | + @Test |
| 37 | + void recursiveShapesCanBeRemovedAfterFailedValidation() throws Exception { |
| 38 | + ShaclSail shaclSail = new ShaclSail(new MemoryStore()); |
| 39 | + shaclSail.setShapesGraphs(Set.of(RDF4J.SHACL_SHAPE_GRAPH)); |
| 40 | + SailRepository shaclRepository = new SailRepository(shaclSail); |
| 41 | + shaclRepository.init(); |
| 42 | + |
| 43 | + URL shapes = Objects.requireNonNull( |
| 44 | + getClass().getClassLoader().getResource("recursion/deep/shacl.trig")); |
| 45 | + |
| 46 | + try (SailRepositoryConnection connection = shaclRepository.getConnection()) { |
| 47 | + connection.begin(IsolationLevels.NONE, ShaclSail.TransactionSettings.ValidationApproach.Disabled); |
| 48 | + connection.add(shapes, shapes.toString(), RDFFormat.TRIG, RDF4J.SHACL_SHAPE_GRAPH); |
| 49 | + connection.commit(); |
| 50 | + } |
| 51 | + |
| 52 | + try (SailRepositoryConnection connection = shaclRepository.getConnection()) { |
| 53 | + connection.begin(); |
| 54 | + connection.add(RDF4J.SHACL_SHAPE_GRAPH, RDF4J.SHACL_SHAPE_GRAPH, RDF4J.SHACL_SHAPE_GRAPH); |
| 55 | + |
| 56 | + assertThrows(ShaclShapeParsingException.class, connection::commit); |
| 57 | + connection.rollback(); |
| 58 | + } |
| 59 | + |
| 60 | + try (SailRepositoryConnection connection = shaclRepository.getConnection()) { |
| 61 | + connection.begin(); |
| 62 | + connection.clear(RDF4J.SHACL_SHAPE_GRAPH); |
| 63 | + connection.commit(); |
| 64 | + |
| 65 | + assertFalse(connection.hasStatement(null, null, null, false, RDF4J.SHACL_SHAPE_GRAPH)); |
| 66 | + } finally { |
| 67 | + shaclRepository.shutDown(); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + void recursiveShapesCanBeRemovedAfterFailedValidation2() throws Exception { |
| 73 | + ShaclSail shaclSail = new ShaclSail(new MemoryStore()); |
| 74 | + shaclSail.setShapesGraphs(Set.of(RDF4J.NIL)); |
| 75 | + |
| 76 | + SailRepository shaclRepository = new SailRepository(shaclSail); |
| 77 | + shaclRepository.init(); |
| 78 | + |
| 79 | + URL shapes = Objects.requireNonNull( |
| 80 | + getClass().getClassLoader().getResource("recursion/deep/shacl.trig")); |
| 81 | + |
| 82 | + try (SailRepositoryConnection connection = shaclRepository.getConnection()) { |
| 83 | + connection.begin(IsolationLevels.NONE, ShaclSail.TransactionSettings.ValidationApproach.Disabled); |
| 84 | + connection.add(shapes, shapes.toString(), RDFFormat.TRIG); |
| 85 | + connection.commit(); |
| 86 | + } |
| 87 | + |
| 88 | + try (SailRepositoryConnection connection = shaclRepository.getConnection()) { |
| 89 | + connection.begin(); |
| 90 | + connection.add(Values.bnode(), RDFS.LABEL, Values.literal("This will fail")); |
| 91 | + |
| 92 | + assertThrows(ShaclShapeParsingException.class, connection::commit); |
| 93 | + connection.rollback(); |
| 94 | + } |
| 95 | + |
| 96 | + try (SailRepositoryConnection connection = shaclRepository.getConnection()) { |
| 97 | + connection.begin(); |
| 98 | + connection.clear(new Resource[1]); |
| 99 | + connection.commit(); |
| 100 | + |
| 101 | + assertFalse(connection.hasStatement(null, null, null, false)); |
| 102 | + } finally { |
| 103 | + shaclRepository.shutDown(); |
| 104 | + } |
| 105 | + } |
| 106 | + |
30 | 107 | @Test |
31 | 108 | void deepRecursionAcrossAllConstraintTypesValidates() throws Exception { |
32 | 109 | SailRepository shaclRepository = Utils.getInitializedShaclRepository( |
|
0 commit comments