Search in sources :

Example 21 with ValidationReport

use of org.apache.jena.shacl.ValidationReport in project webofneeds by researchstudio-sat.

the class ShaclCheckTest method validateAgainstShapes.

public void validateAgainstShapes(Shapes shapes, Graph graph, Resource resourceOfGraph) {
    ValidationReport shaclReport = ShaclSystem.get().validate(shapes, new Union(shapes.getGraph(), graph));
    if (!shaclReport.conforms()) {
        ShLib.printReport(shaclReport);
        System.out.println();
        RDFDataMgr.write(System.out, shaclReport.getModel(), Lang.TTL);
    }
    Assert.isTrue(shaclReport.conforms(), String.format("%s: graph does not conform to shapes", resourceOfGraph.getFilename()));
}
Also used : ValidationReport(org.apache.jena.shacl.ValidationReport) Union(org.apache.jena.graph.compose.Union)

Example 22 with ValidationReport

use of org.apache.jena.shacl.ValidationReport in project webofneeds by researchstudio-sat.

the class AuthShapeTest method assertConformityOfAuthorizations.

private void assertConformityOfAuthorizations(Shapes shapes, Resource authGraph) {
    logger.debug("checking {}", authGraph.getFilename());
    Model data = ModelFactory.createDefaultModel();
    try {
        RDFDataMgr.read(data, authGraph.getInputStream(), Lang.TTL);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Graph g = data.getGraph();
    long start = CPUUtils.getCpuTime();
    ValidationReport report = ShaclValidator.get().validate(shapes, new Union(g, shapes.getGraph()));
    long duration = CPUUtils.getCpuTime() - start;
    logger.debug("validation took {} millis ", (double) duration / 1000000d);
    if (!report.conforms()) {
        printNonconformingReport(report);
    }
    Assert.assertTrue(report.conforms());
}
Also used : Graph(org.apache.jena.graph.Graph) ValidationReport(org.apache.jena.shacl.ValidationReport) Model(org.apache.jena.rdf.model.Model) IOException(java.io.IOException) Union(org.apache.jena.graph.compose.Union)

Example 23 with ValidationReport

use of org.apache.jena.shacl.ValidationReport in project webofneeds by researchstudio-sat.

the class AuthShapeTest method assertConformityOfOperationRequests.

private void assertConformityOfOperationRequests(Shapes shapes, Resource authGraph) {
    logger.debug("checking {}", authGraph.getFilename());
    Model data = ModelFactory.createDefaultModel();
    try {
        RDFDataMgr.read(data, authGraph.getInputStream(), Lang.TTL);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Graph g = data.getGraph();
    long start = CPUUtils.getCpuTime();
    ValidationReport report = ShaclValidator.get().validate(shapes, g);
    long duration = CPUUtils.getCpuTime() - start;
    logger.debug("validation took {} millis ", (double) duration / 1000000d);
    if (!report.conforms()) {
        printNonconformingReport(report);
    }
    Assert.assertTrue(report.conforms());
}
Also used : Graph(org.apache.jena.graph.Graph) ValidationReport(org.apache.jena.shacl.ValidationReport) Model(org.apache.jena.rdf.model.Model) IOException(java.io.IOException)

Example 24 with ValidationReport

use of org.apache.jena.shacl.ValidationReport in project webofneeds by researchstudio-sat.

the class GrantedOperationsTest method validateTestData.

public void validateTestData(Shapes shapes, Graph graph, boolean failTest, String testCaseIdentifier) {
    ValidationReport shaclReport = ShaclSystem.get().validate(shapes, new Union(shapes.getGraph(), graph));
    if (failTest) {
        if (!shaclReport.conforms()) {
            ShLib.printReport(shaclReport);
            System.out.println();
            RDFDataMgr.write(System.out, shaclReport.getModel(), Lang.TTL);
        }
        Assert.assertTrue(String.format("%s: test data invalid", testCaseIdentifier), shaclReport.conforms());
    } else {
        if (!shaclReport.conforms()) {
            logger.info("failed SHACL validation: {}", testCaseIdentifier);
        }
    }
}
Also used : ValidationReport(org.apache.jena.shacl.ValidationReport) Union(org.apache.jena.graph.compose.Union)

Aggregations

ValidationReport (org.apache.jena.shacl.ValidationReport)24 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)9 Test (org.junit.Test)9 Graph (org.apache.jena.graph.Graph)7 Union (org.apache.jena.graph.compose.Union)5 Model (org.apache.jena.rdf.model.Model)3 Shapes (org.apache.jena.shacl.Shapes)3 IOException (java.io.IOException)2 Node (org.apache.jena.graph.Node)2 Resource (org.apache.jena.rdf.model.Resource)2 ValidationContext (org.apache.jena.shacl.engine.ValidationContext)2 MediaType (org.apache.jena.atlas.web.MediaType)1 FusekiServer (org.apache.jena.fuseki.main.FusekiServer)1 Operation (org.apache.jena.fuseki.server.Operation)1 Lang (org.apache.jena.riot.Lang)1 Shape (org.apache.jena.shacl.parser.Shape)1 ResettableErrorHandler (won.shacl2java.validation.ResettableErrorHandler)1