@@ -1780,7 +1780,7 @@ void testSparqlTargetWithGenericConstraint() {
1780
1780
}
1781
1781
1782
1782
@ Test
1783
- void testSparqlTargetWithSparqlConstraint () {
1783
+ void testSparqlTargetWithShapeSparqlConstraint () {
1784
1784
final Model shapesModel = model ( """
1785
1785
@prefix sh: <http://www.w3.org/ns/shacl#> .
1786
1786
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@@ -1845,6 +1845,71 @@ void testSparqlTargetWithSparqlConstraint() {
1845
1845
assertThat ( finding ).isInstanceOf ( SparqlConstraintViolation .class );
1846
1846
}
1847
1847
1848
+ @ Test
1849
+ void testSparqlTargetWithPropertySparqlConstraint () {
1850
+ final Model shapesModel = model ( """
1851
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
1852
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
1853
+ @prefix : <http://example.com#> .
1854
+
1855
+ :prefixDeclarations
1856
+ sh:declare [
1857
+ sh:prefix "" ;
1858
+ sh:namespace "http://example.com#"^^xsd:anyURI ;
1859
+ ] .
1860
+
1861
+ :MyShape
1862
+ a sh:NodeShape ;
1863
+ sh:target [
1864
+ a sh:SPARQLTarget ;
1865
+ sh:prefixes :prefixDeclarations ;
1866
+ sh:select ""\"
1867
+ select $this
1868
+ where {
1869
+ $this a :TestClass .
1870
+ }
1871
+ ""\"
1872
+ ] ;
1873
+ sh:name "Test shape" ;
1874
+ sh:description "Test shape description" ;
1875
+ sh:property [
1876
+ sh:path :testProperty ;
1877
+ sh:datatype xsd:string ;
1878
+ sh:sparql [
1879
+ a sh:SPARQLConstraint ;
1880
+ sh:message "Required property 'testProperty' does not exist on {$this}." ;
1881
+ sh:prefixes :prefixDeclarations ;
1882
+ sh:select ""\"
1883
+ select $this ?code
1884
+ where {
1885
+ $this a :TestClass .
1886
+ filter ( not exists { $this :testProperty [] } ) .
1887
+ bind( "ERR_CUSTOM" as ?code )
1888
+ }
1889
+ ""\"
1890
+ ] ;
1891
+ ] .
1892
+ """ );
1893
+
1894
+ // important detail: ':testProperty' is missing on ':Foo', the SPARQLConstraint must run anyway
1895
+ final Model dataModel = model ( """
1896
+ @prefix : <http://example.com#> .
1897
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
1898
+ :Foo a :TestClass.
1899
+
1900
+ :Bar a :TestClass ;
1901
+ :testProperty "secret valid value" .
1902
+ """ );
1903
+
1904
+ final ShaclValidator validator = new ShaclValidator ( shapesModel );
1905
+ final Resource element = dataModel .createResource ( namespace + "Foo" );
1906
+ final List <Violation > violations = validator .validateElement ( element );
1907
+
1908
+ assertThat ( violations .size () ).isEqualTo ( 1 );
1909
+ final Violation finding = violations .get ( 0 );
1910
+ assertThat ( finding ).isInstanceOf ( SparqlConstraintViolation .class );
1911
+ }
1912
+
1848
1913
@ Test
1849
1914
void testMultiElementValidation () {
1850
1915
final Model shapesModel = model ( """
0 commit comments