-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
817 additions
and
96 deletions.
There are no files selected for viewing
430 changes: 346 additions & 84 deletions
430
core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/ShaclProperties.java
Large diffs are not rendered by default.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
...sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/ShaclShapeParsingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Eclipse RDF4J contributors. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
******************************************************************************/ | ||
|
||
package org.eclipse.rdf4j.sail.shacl.ast; | ||
|
||
import org.eclipse.rdf4j.common.exception.RDF4JException; | ||
import org.eclipse.rdf4j.model.Resource; | ||
|
||
/** | ||
* An exception indicating that something went wrong when parsing a shape. The id field contains the subject of the | ||
* shape statements. | ||
*/ | ||
public class ShaclShapeParsingException extends RDF4JException { | ||
|
||
Resource id; | ||
|
||
public ShaclShapeParsingException(String msg, Resource id) { | ||
super(msg + " - Caused by shape with id: " + resourceToString(id)); | ||
this.id = id; | ||
} | ||
|
||
public ShaclShapeParsingException(String msg, Throwable t, Resource id) { | ||
super(msg + " - Caused by shape with id: " + resourceToString(id), t); | ||
this.id = id; | ||
} | ||
|
||
public ShaclShapeParsingException(Throwable t, Resource id) { | ||
super(t.getMessage() + " - Caused by shape with id: " + resourceToString(id), t); | ||
this.id = id; | ||
} | ||
|
||
public Resource getId() { | ||
return id; | ||
} | ||
|
||
private static String resourceToString(Resource id) { | ||
assert id != null; | ||
if (id == null) { | ||
return "null"; | ||
} | ||
if (id.isIRI()) { | ||
return "<" + id.stringValue() + ">"; | ||
} | ||
if (id.isBNode()) { | ||
return id.toString(); | ||
} | ||
if (id.isTriple()) { | ||
return "TRIPLE " + id; | ||
} | ||
return id.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
...sail/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/ast/ShaclPropertiesCastingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Eclipse RDF4J contributors. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
******************************************************************************/ | ||
|
||
package org.eclipse.rdf4j.sail.shacl.ast; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.eclipse.rdf4j.model.*; | ||
import org.eclipse.rdf4j.model.util.Values; | ||
import org.eclipse.rdf4j.sail.shacl.wrapper.shape.ShapeSource; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class ShaclPropertiesCastingTest { | ||
|
||
public static final Literal DUMMY_VALUE = Values.literal("dummy value"); | ||
public static final IRI IRI = Values.iri("http://example.org/iri"); | ||
@Mock | ||
private Statement statement; | ||
|
||
@Mock | ||
private ShapeSource shapeSource; | ||
|
||
@InjectMocks | ||
private ShaclProperties shaclProperties; | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideArgumentsForTest") | ||
public void testConstructor(IRI predicate, Value value, String exceptedMessage) { | ||
String exceptedMessageWithPredicate = String.format(exceptedMessage, predicate); | ||
|
||
when(shapeSource.getAllStatements(any(Resource.class))).thenReturn(Stream.of(statement)); | ||
when(statement.getPredicate()).thenReturn(predicate); | ||
when(statement.getObject()).thenReturn(value); | ||
|
||
ShaclShapeParsingException exception = assertThrows(ShaclShapeParsingException.class, | ||
() -> new ShaclProperties(Values.iri("http://example.org/shape1"), shapeSource) | ||
); | ||
|
||
assertEquals(exceptedMessageWithPredicate, exception.getMessage()); | ||
|
||
} | ||
|
||
private static Stream<Arguments> provideArgumentsForTest() { | ||
return Stream.of( | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#or"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#xone"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#and"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#not"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#property"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#node"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#message"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#severity"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have an IRI as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#languageIn"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#nodeKind"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#datatype"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have an IRI as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#minCount"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#maxCount"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#minLength"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#maxLength"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#minExclusive"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#maxExclusive"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#minInclusive"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#maxInclusive"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#pattern"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#class"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have an IRI as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#targetNode"), Values.bnode("bnode1"), | ||
"Expected predicate <%s> to have a Literal or an IRI as object, but found BNode for _:bnode1 - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#targetClass"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#targetSubjectsOf"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have an IRI as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#targetObjectsOf"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have an IRI as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#deactivated"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#uniqueLang"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#closed"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#ignoredProperties"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#flags"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#path"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#in"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#equals"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have an IRI as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#disjoint"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have an IRI as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#lessThan"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have an IRI as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#lessThanOrEquals"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have an IRI as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#target"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#qualifiedValueShape"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#qualifiedValueShapesDisjoint"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#qualifiedMinCount"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#qualifiedMaxCount"), IRI, | ||
"Expected predicate <%s> to have a Literal as object, but found IRI for http://example.org/iri - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://datashapes.org/dash#hasValueIn"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://rdf4j.org/shacl-extensions#targetShape"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>"), | ||
Arguments.of(Values.iri("http://www.w3.org/ns/shacl#sparql"), DUMMY_VALUE, | ||
"Expected predicate <%s> to have a Resource as object, but found Literal for \"dummy value\" - Caused by shape with id: <http://example.org/shape1>") | ||
); | ||
} | ||
} |
Oops, something went wrong.