Search in sources :

Example 11 with ValidationReport

use of org.apache.jena.shacl.ValidationReport in project jena by apache.

the class QualifiedValueShape method conforms.

private static boolean conforms(ValidationContext vCxt, Shape shape, Node v) {
    ValidationContext vCxt2 = ValidationContext.create(vCxt);
    ValidationProc.execValidateShape(vCxt2, vCxt.getDataGraph(), shape, v);
    ValidationReport report = vCxt2.generateReport();
    return report.conforms();
}
Also used : ValidationReport(org.apache.jena.shacl.ValidationReport) ValidationContext(org.apache.jena.shacl.engine.ValidationContext)

Example 12 with ValidationReport

use of org.apache.jena.shacl.ValidationReport in project jena by apache.

the class ShaclTest method shaclTest.

public static void shaclTest(ShaclTestItem test) {
    Graph shapesGraph = RDFDataMgr.loadGraph(test.getShapesGraph().getURI());
    try {
        Graph dataGraph;
        if (test.getShapesGraph().getURI().equals(test.getDataGraph().getURI()))
            dataGraph = shapesGraph;
        else
            dataGraph = RDFDataMgr.loadGraph(test.getDataGraph().getURI());
        boolean generalFailure = test.isGeneralFailure();
        if (generalFailure) {
            try {
                ValidationReport testReport = validate(ShaclValidator.get(), shapesGraph, dataGraph);
                if (testReport.conforms())
                    fail("Expect a test failure: " + test.origin());
            } catch (RuntimeException ex) {
            // Ignore.
            }
        }
        // Fails on unimplemented.
        ValidationReport vReportExpected = ValidationReport.fromGraph(test.getResult().getModel().getGraph());
        ValidationReport vReportGot;
        try {
            vReportGot = validate(ShaclValidator.get(), shapesGraph, dataGraph);
        } catch (Throwable th) {
            System.out.println("** Test : " + test.origin());
            throw th;
        }
        boolean b1 = VR.compare(vReportGot, vReportExpected);
        if (!b1) {
            // expected report != actual report
            System.out.println("<< Test : " + test.origin());
            Shapes shapes = Shapes.parse(shapesGraph);
            ShLib.printShapes(shapes);
            System.out.println("++++ Expected:");
            ShLib.printReport(vReportExpected);
            System.out.println("++++ Got");
            ShLib.printReport(vReportGot);
            System.out.println("-----");
        }
        Model modelGot = VR.strip(vReportGot.getResource().getModel());
        Model modelExpected = VR.strip(vReportExpected.getResource().getModel());
        boolean b2 = modelGot.isIsomorphicWith(modelExpected);
        if (!b2) {
            // expected model != actual model
            System.out.println("**** Expected");
            RDFDataMgr.write(System.out, modelExpected, Lang.TTL);
            System.out.println("**** Got");
            RDFDataMgr.write(System.out, modelGot, Lang.TTL);
            System.out.println(">> Test : " + test.origin());
            System.out.println("-----");
        }
        assertTrue("Reports differ : " + test.origin(), b1);
        assertTrue("Report models differ", b2);
    } catch (RuntimeException ex) {
        // ShLib.printShapes(shapeList);
        throw ex;
    }
}
Also used : Graph(org.apache.jena.graph.Graph) ValidationReport(org.apache.jena.shacl.ValidationReport) Model(org.apache.jena.rdf.model.Model) Shapes(org.apache.jena.shacl.Shapes)

Example 13 with ValidationReport

use of org.apache.jena.shacl.ValidationReport in project jena by apache.

the class VR method check.

public static void check(ValidationReport report) {
    // Internal test.
    // Also entries->model->entries but bnode, order issues.
    Model m = report.getResource().getModel();
    ValidationReport report2 = ValidationReport.fromModel(m);
    Model m2 = report2.getResource().getModel();
    boolean b = m.isIsomorphicWith(m2);
    if (!b) {
        System.err.println("****");
        RDFDataMgr.write(System.err, m, Lang.TTL);
        System.err.println("++++ Round trip");
        RDFDataMgr.write(System.err, m2, Lang.TTL);
        System.err.println("----");
    }
}
Also used : ValidationReport(org.apache.jena.shacl.ValidationReport)

Example 14 with ValidationReport

use of org.apache.jena.shacl.ValidationReport in project jena by apache.

the class TestValidationReport method testRoundTripReport.

// @Test public void rtReport_2() {
// // two entries
// }
private void testRoundTripReport(String message, ValidationReport report1) {
    Resource r = report1.getResource();
    ValidationReport report2 = ValidationReport.fromModel(r.getModel());
    boolean b = VR.compare(report1, report2);
    if (!b) {
        System.out.println("****");
        ShLib.printReport(report1);
        System.out.println("----");
        ShLib.printReport(report2);
        System.out.flush();
    }
    assertTrue("Reports differ: " + message, b);
}
Also used : ValidationReport(org.apache.jena.shacl.ValidationReport) Resource(org.apache.jena.rdf.model.Resource)

Example 15 with ValidationReport

use of org.apache.jena.shacl.ValidationReport in project jena by apache.

the class TestValidationReport method rtReport_1.

// Round trip :: ValidationReport -> RDF -> ValidationReport
@Test
public void rtReport_1() {
    ValidationReport report = ValidationReport.reportConformsTrue();
    testRoundTripReport("conforms", report);
}
Also used : ValidationReport(org.apache.jena.shacl.ValidationReport) Test(org.junit.Test)

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