Search in sources :

Example 1 with ValidationProblemSeverity

use of io.apicurio.datamodels.core.models.ValidationProblemSeverity in project apicurio-data-models by Apicurio.

the class ValidationTestRunner method runChild.

/**
 * @see org.junit.runners.ParentRunner#runChild(java.lang.Object, org.junit.runner.notification.RunNotifier)
 */
@Override
protected void runChild(ValidationTestCase child, RunNotifier notifier) {
    Description description = this.describeChild(child);
    Statement statement = new Statement() {

        @Override
        public void evaluate() throws Throwable {
            String testCP = "fixtures/validation/" + child.getTest();
            URL testUrl = Thread.currentThread().getContextClassLoader().getResource(testCP);
            Assert.assertNotNull("Could not load test resource: " + testCP, testUrl);
            // Read the test source
            String original = loadResource(testUrl);
            Assert.assertNotNull(original);
            // Parse into a Json object
            Object originalParsed = mapper.readTree(original);
            // Parse into a data model
            Document doc = Library.readDocument(originalParsed);
            // Validate the document
            IValidationSeverityRegistry severityRegistry = null;
            if (child.getSeverity() != null) {
                final ValidationProblemSeverity severity = ValidationProblemSeverity.valueOf(child.getSeverity());
                severityRegistry = new IValidationSeverityRegistry() {

                    @Override
                    public ValidationProblemSeverity lookupSeverity(ValidationRuleMetaData rule) {
                        return severity;
                    }
                };
            }
            List<ValidationProblem> problems = Library.validateDocument(doc, severityRegistry, Collections.emptyList()).get();
            // Now compare with expected
            String actual = formatProblems(problems);
            String expectedCP = testCP + ".expected";
            URL expectedUrl = Thread.currentThread().getContextClassLoader().getResource(expectedCP);
            Assert.assertNotNull("Could not load test resource: " + expectedCP, expectedUrl);
            String expected = loadResource(expectedUrl);
            Assert.assertEquals(normalize(expected), normalize(actual));
        }
    };
    runLeaf(statement, description, notifier);
}
Also used : Description(org.junit.runner.Description) Statement(org.junit.runners.model.Statement) ValidationProblem(io.apicurio.datamodels.core.models.ValidationProblem) Document(io.apicurio.datamodels.core.models.Document) URL(java.net.URL) ValidationProblemSeverity(io.apicurio.datamodels.core.models.ValidationProblemSeverity)

Example 2 with ValidationProblemSeverity

use of io.apicurio.datamodels.core.models.ValidationProblemSeverity in project apicurio-data-models by Apicurio.

the class ValidationVisitor method report.

/**
 * @see io.apicurio.datamodels.core.validation.IValidationProblemReporter#report(io.apicurio.datamodels.core.validation.ValidationRuleMetaData, io.apicurio.datamodels.core.models.Node, java.lang.String, java.lang.String)
 */
@Override
public void report(ValidationRuleMetaData ruleInfo, Node node, String property, String message) {
    ValidationProblemSeverity severity = this.severityRegistry.lookupSeverity(ruleInfo);
    if (severity == ValidationProblemSeverity.ignore) {
        return;
    }
    NodePath path = NodePathUtil.createNodePath(node);
    ValidationProblem problem = node.addValidationProblem(ruleInfo.code, path, property, message, severity);
    // Include in the list of problems tracked by the validator.
    this.problems.add(problem);
}
Also used : ValidationProblem(io.apicurio.datamodels.core.models.ValidationProblem) ValidationProblemSeverity(io.apicurio.datamodels.core.models.ValidationProblemSeverity) NodePath(io.apicurio.datamodels.core.models.NodePath)

Aggregations

ValidationProblem (io.apicurio.datamodels.core.models.ValidationProblem)2 ValidationProblemSeverity (io.apicurio.datamodels.core.models.ValidationProblemSeverity)2 Document (io.apicurio.datamodels.core.models.Document)1 NodePath (io.apicurio.datamodels.core.models.NodePath)1 URL (java.net.URL)1 Description (org.junit.runner.Description)1 Statement (org.junit.runners.model.Statement)1