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);
}
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);
}
Aggregations