use of ddf.catalog.validation.violation.ValidationViolation in project ddf by codice.
the class TestDuplicationValidator method testValidateMetacardWithValidationErrorAndWarning.
@Test
public void testValidateMetacardWithValidationErrorAndWarning() {
String[] checksumAttribute = { Metacard.CHECKSUM };
String[] idAttribute = { Metacard.ID };
validator.setWarnOnDuplicateAttributes(checksumAttribute);
validator.setErrorOnDuplicateAttributes(idAttribute);
Optional<MetacardValidationReport> report = validator.validateMetacard(testMetacard);
assertThat(report.isPresent(), is(true));
assertThat(report.get().getMetacardValidationViolations(), hasSize(2));
Map<ValidationViolation.Severity, ValidationViolation> violations = report.get().getMetacardValidationViolations().stream().collect(Collectors.toMap(ValidationViolation::getSeverity, Function.identity()));
ValidationViolation warnViolation = violations.get(ValidationViolation.Severity.WARNING);
ValidationViolation errorViolation = violations.get(ValidationViolation.Severity.ERROR);
assertThat(warnViolation.getAttributes(), is(new HashSet<>(Arrays.asList(checksumAttribute))));
assertThat(warnViolation.getMessage(), containsString(Metacard.CHECKSUM));
assertThat(errorViolation.getAttributes(), is(new HashSet<>(Arrays.asList(idAttribute))));
assertThat(errorViolation.getMessage(), containsString(Metacard.ID));
}
Aggregations