Search in sources :

Example 6 with ValidationViolation

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));
}
Also used : MetacardValidationReport(ddf.catalog.validation.report.MetacardValidationReport) ValidationViolation(ddf.catalog.validation.violation.ValidationViolation) Matchers.anyString(org.mockito.Matchers.anyString) StringContains.containsString(org.hamcrest.core.StringContains.containsString) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ValidationViolation (ddf.catalog.validation.violation.ValidationViolation)6 HashSet (java.util.HashSet)5 Attribute (ddf.catalog.data.Attribute)3 MetacardValidationReport (ddf.catalog.validation.report.MetacardValidationReport)3 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)2 Metacard (ddf.catalog.data.Metacard)2 FederationException (ddf.catalog.federation.FederationException)2 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)2 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)2 AttributeValidator (ddf.catalog.validation.AttributeValidator)2 ReportingMetacardValidator (ddf.catalog.validation.ReportingMetacardValidator)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Preconditions (com.google.common.base.Preconditions)1 CatalogFramework (ddf.catalog.CatalogFramework)1 MetacardType (ddf.catalog.data.MetacardType)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1