|
12 | 12 |
|
13 | 13 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
14 | 14 |
|
| 15 | +import java.io.IOException; |
15 | 16 | import java.io.StringReader;
|
| 17 | +import java.util.List; |
| 18 | +import java.util.stream.Collectors; |
16 | 19 |
|
17 | 20 | import org.eclipse.rdf4j.common.transaction.IsolationLevels;
|
18 | 21 | import org.eclipse.rdf4j.http.client.shacl.RemoteShaclValidationException;
|
19 | 22 | import org.eclipse.rdf4j.http.protocol.Protocol;
|
| 23 | +import org.eclipse.rdf4j.model.BNode; |
| 24 | +import org.eclipse.rdf4j.model.Model; |
20 | 25 | import org.eclipse.rdf4j.model.Resource;
|
| 26 | +import org.eclipse.rdf4j.model.Statement; |
| 27 | +import org.eclipse.rdf4j.model.Value; |
21 | 28 | import org.eclipse.rdf4j.model.ValueFactory;
|
22 | 29 | import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
|
| 30 | +import org.eclipse.rdf4j.model.util.Values; |
23 | 31 | import org.eclipse.rdf4j.model.vocabulary.RDF;
|
24 | 32 | import org.eclipse.rdf4j.model.vocabulary.RDF4J;
|
25 | 33 | import org.eclipse.rdf4j.model.vocabulary.RDFS;
|
| 34 | +import org.eclipse.rdf4j.model.vocabulary.SHACL; |
26 | 35 | import org.eclipse.rdf4j.repository.Repository;
|
27 | 36 | import org.eclipse.rdf4j.repository.RepositoryConnection;
|
28 | 37 | import org.eclipse.rdf4j.repository.RepositoryException;
|
29 | 38 | import org.eclipse.rdf4j.repository.http.HTTPRepository;
|
30 | 39 | import org.eclipse.rdf4j.rio.RDFFormat;
|
31 | 40 | import org.eclipse.rdf4j.sail.shacl.ShaclSail;
|
32 | 41 | import org.junit.jupiter.api.AfterAll;
|
| 42 | +import org.junit.jupiter.api.Assertions; |
33 | 43 | import org.junit.jupiter.api.BeforeAll;
|
34 | 44 | import org.junit.jupiter.api.BeforeEach;
|
35 | 45 | import org.junit.jupiter.api.Test;
|
@@ -67,11 +77,12 @@ public static void stopServer() throws Exception {
|
67 | 77 | "ex:PersonShape\n" +
|
68 | 78 | "\ta sh:NodeShape ;\n" +
|
69 | 79 | "\tsh:targetClass rdfs:Resource ;\n" +
|
70 |
| - "\tsh:property ex:PersonShapeProperty .\n" + |
| 80 | + "\tsh:property _:bnode .\n" + |
71 | 81 | "\n" +
|
72 | 82 | "\n" +
|
73 |
| - "ex:PersonShapeProperty\n" + |
| 83 | + "_:bnode\n" + |
74 | 84 | " sh:path rdfs:label ;\n" +
|
| 85 | + " rdfs:label \"abc\" ;\n" + |
75 | 86 | " sh:minCount 1 .";
|
76 | 87 |
|
77 | 88 | @BeforeEach
|
@@ -231,4 +242,54 @@ public void testValidationDisabledSnapshotSerializableValidation() throws Throwa
|
231 | 242 |
|
232 | 243 | }
|
233 | 244 |
|
| 245 | + @Test |
| 246 | + public void testBlankNodeIdsPreserved() throws IOException { |
| 247 | + |
| 248 | + Repository repository = new HTTPRepository( |
| 249 | + Protocol.getRepositoryLocation(TestServer.SERVER_URL, TestServer.TEST_SHACL_REPO_ID)); |
| 250 | + |
| 251 | + try (RepositoryConnection connection = repository.getConnection()) { |
| 252 | + connection.begin(); |
| 253 | + connection.add(new StringReader(shacl), "", RDFFormat.TURTLE, RDF4J.SHACL_SHAPE_GRAPH); |
| 254 | + connection.commit(); |
| 255 | + } |
| 256 | + |
| 257 | + try (RepositoryConnection connection = repository.getConnection()) { |
| 258 | + connection.begin(); |
| 259 | + connection.add(RDFS.RESOURCE, RDF.TYPE, RDFS.RESOURCE); |
| 260 | + connection.commit(); |
| 261 | + } catch (RepositoryException repositoryException) { |
| 262 | + |
| 263 | + Model validationReport = ((RemoteShaclValidationException) repositoryException.getCause()) |
| 264 | + .validationReportAsModel(); |
| 265 | + |
| 266 | + BNode shapeBnode = (BNode) validationReport |
| 267 | + .filter(null, SHACL.SOURCE_SHAPE, null) |
| 268 | + .objects() |
| 269 | + .stream() |
| 270 | + .findAny() |
| 271 | + .orElseThrow(); |
| 272 | + |
| 273 | + try (RepositoryConnection connection = repository.getConnection()) { |
| 274 | + List<Statement> collect = connection |
| 275 | + .getStatements(shapeBnode, null, null, RDF4J.SHACL_SHAPE_GRAPH) |
| 276 | + .stream() |
| 277 | + .collect(Collectors.toList()); |
| 278 | + |
| 279 | + Assertions.assertEquals(3, collect.size()); |
| 280 | + |
| 281 | + Value rdfsLabel = collect |
| 282 | + .stream() |
| 283 | + .filter(s -> s.getPredicate().equals(RDFS.LABEL)) |
| 284 | + .map(Statement::getObject) |
| 285 | + .findAny() |
| 286 | + .orElseThrow(); |
| 287 | + |
| 288 | + Assertions.assertEquals(Values.literal("abc"), rdfsLabel); |
| 289 | + |
| 290 | + } |
| 291 | + } |
| 292 | + |
| 293 | + } |
| 294 | + |
234 | 295 | }
|
0 commit comments