This repository has been archived by the owner on Feb 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eclipse-rdf4j/rdf4j#1374 log unsupported shacl features with test
Signed-off-by: Håvard Ottestad <[email protected]>
- Loading branch information
1 parent
87e5b23
commit a707a52
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
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
73 changes: 73 additions & 0 deletions
73
shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/UnknownShapesTest.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,73 @@ | ||
package org.eclipse.rdf4j.sail.shacl; | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.classic.spi.LoggingEvent; | ||
import ch.qos.logback.core.Appender; | ||
import ch.qos.logback.core.AppenderBase; | ||
import ch.qos.logback.core.Context; | ||
import ch.qos.logback.core.LogbackException; | ||
import ch.qos.logback.core.filter.Filter; | ||
import ch.qos.logback.core.spi.FilterReply; | ||
import ch.qos.logback.core.status.Status; | ||
import org.eclipse.rdf4j.model.vocabulary.RDF; | ||
import org.eclipse.rdf4j.model.vocabulary.RDFS; | ||
import org.eclipse.rdf4j.repository.sail.SailRepository; | ||
import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; | ||
import org.junit.Test; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class UnknownShapesTest { | ||
|
||
@Test | ||
public void testPropertyShapes() throws IOException { | ||
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory | ||
.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); | ||
|
||
MyAppender newAppender = new MyAppender(); | ||
root.addAppender(newAppender); | ||
|
||
SailRepository shaclRepository = Utils.getInitializedShaclRepository("unknownProperties.ttl", false); | ||
|
||
try (SailRepositoryConnection connection = shaclRepository.getConnection()) { | ||
connection.begin(); | ||
connection.add(RDF.TYPE, RDF.TYPE, RDFS.RESOURCE); | ||
connection.commit(); | ||
} | ||
|
||
Set<String> relevantLog = newAppender.logged.stream() | ||
.filter(m -> m.startsWith("Unsupported SHACL feature")) | ||
.collect(Collectors.toSet()); | ||
|
||
Set<String> expected = new HashSet<>(Arrays.asList( | ||
"Unsupported SHACL feature detected sh:unknownTarget in statement (http://example.com/ns#PersonShape, http://www.w3.org/ns/shacl#unknownTarget, http://www.w3.org/2000/01/rdf-schema#Class) [null]", | ||
"Unsupported SHACL feature detected sh:unknownShaclProperty in statement (http://example.com/ns#PersonPropertyShape, http://www.w3.org/ns/shacl#unknownShaclProperty, \"1\"^^<http://www.w3.org/2001/XMLSchema#integer>) [null]")); | ||
|
||
assertEquals(expected, relevantLog); | ||
|
||
} | ||
|
||
class MyAppender extends AppenderBase<ILoggingEvent> { | ||
|
||
List<String> logged = new ArrayList<>(); | ||
|
||
@Override | ||
public synchronized void doAppend(ILoggingEvent eventObject) { | ||
logged.add(eventObject.getFormattedMessage()); | ||
} | ||
|
||
@Override | ||
protected void append(ILoggingEvent iLoggingEvent) { | ||
|
||
} | ||
} | ||
} |
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,20 @@ | ||
@base <http://example.com/ns> . | ||
@prefix ex: <http://example.com/ns#> . | ||
@prefix owl: <http://www.w3.org/2002/07/owl#> . | ||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | ||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
@prefix foaf: <http://xmlns.com/foaf/0.1/>. | ||
|
||
ex:PersonShape | ||
a sh:NodeShape ; | ||
sh:targetClass rdfs:Resource ; | ||
sh:unknownTarget rdfs:Class ; | ||
rdfs:label "label" ; | ||
rdfs:subClassOf ex:HumanShape ; | ||
sh:property ex:PersonPropertyShape . | ||
|
||
ex:PersonPropertyShape | ||
sh:path rdfs:label ; | ||
sh:unknownShaclProperty 1 . |