Search in sources :

Example 1 with DataQuality

use of org.opengis.metadata.quality.DataQuality in project sis by apache.

the class SingletonAttributeTest method testQuality.

/**
 * Tests {@link SingletonAttribute#quality()}.
 */
@Test
@DependsOnMethod("testValue")
@SuppressWarnings("unchecked")
public void testQuality() {
    final AbstractAttribute<Integer> attribute = population();
    DataQuality quality = attribute.quality();
    assertEquals("scope.level", ScopeCode.ATTRIBUTE, quality.getScope().getLevel());
    assertDomainConsistencyEquals("population", "Missing value for “population” property.", (DomainConsistency) getSingleton(quality.getReports()));
    /*
         * Intentionally store a value of the wrong type, and test again.
         */
    ((AbstractAttribute) attribute).setValue(4.5f);
    quality = attribute.quality();
    assertEquals("scope.level", ScopeCode.ATTRIBUTE, quality.getScope().getLevel());
    assertDomainConsistencyEquals("population", "Expected an instance of ‘Integer’ for the “population” property, but got an instance of ‘Float’.", (DomainConsistency) getSingleton(quality.getReports()));
}
Also used : DataQuality(org.opengis.metadata.quality.DataQuality) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with DataQuality

use of org.opengis.metadata.quality.DataQuality in project sis by apache.

the class FeatureTestCase method testCustomAttribute.

/**
 * Tests the possibility to plugin custom attributes via {@code AbstractFeature.setProperty(Property)}.
 */
@Test
@DependsOnMethod({ "testSimpleValues", "testSimpleProperties" })
public void testCustomAttribute() {
    feature = createFeature(DefaultFeatureTypeTest.city());
    final AbstractAttribute<String> wrong = SingletonAttributeTest.parliament();
    final CustomAttribute<String> city = new CustomAttribute<>(Features.cast((DefaultAttributeType<?>) feature.getType().getProperty("city"), String.class));
    feature.setProperty(city);
    setAttributeValue("city", "Utopia", "Atlantide");
    try {
        feature.setProperty(wrong);
        fail("Shall not be allowed to set a property of the wrong type.");
    } catch (IllegalArgumentException e) {
        final String message = e.getMessage();
        assertTrue(message, message.contains("parliament"));
        assertTrue(message, message.contains("City"));
    }
    if (assertSameProperty("city", city, true)) {
        /*
             * The quality report is expected to contains a custom element.
             */
        int numOccurrences = 0;
        final DataQuality quality = verifyQualityReports("population");
        for (final Element report : quality.getReports()) {
            final String identifier = report.getMeasureIdentification().toString();
            if (identifier.equals("city")) {
                numOccurrences++;
                final Result result = TestUtilities.getSingleton(report.getResults());
                assertInstanceOf("result", QuantitativeResult.class, result);
                assertEquals("quality.report.result.errorStatistic", CustomAttribute.ADDITIONAL_QUALITY_INFO, String.valueOf(((QuantitativeResult) result).getErrorStatistic()));
            }
        }
        assertEquals("Number of reports.", 1, numOccurrences);
    }
}
Also used : QuantitativeResult(org.opengis.metadata.quality.QuantitativeResult) DataQuality(org.opengis.metadata.quality.DataQuality) Element(org.opengis.metadata.quality.Element) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Result(org.opengis.metadata.quality.Result) QuantitativeResult(org.opengis.metadata.quality.QuantitativeResult) ConformanceResult(org.opengis.metadata.quality.ConformanceResult) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 3 with DataQuality

use of org.opengis.metadata.quality.DataQuality in project sis by apache.

the class FeatureTestCase method verifyQualityReports.

/**
 * Asserts that {@link AbstractFeature#quality()} reports no anomaly, or only anomalies for the given properties.
 *
 * @param  anomalousProperties  the property for which we expect a report.
 * @return the data quality report.
 */
private DataQuality verifyQualityReports(final String... anomalousProperties) {
    int anomalyIndex = 0;
    final DataQuality quality = feature.quality();
    for (final Element report : quality.getReports()) {
        for (final Result result : report.getResults()) {
            if (result instanceof ConformanceResult && !((ConformanceResult) result).pass()) {
                assertTrue("Too many reports", anomalyIndex < anomalousProperties.length);
                final String propertyName = anomalousProperties[anomalyIndex];
                final String identifier = report.getMeasureIdentification().toString();
                final String explanation = ((ConformanceResult) result).getExplanation().toString();
                assertEquals("quality.report.measureIdentification", propertyName, identifier);
                assertTrue("quality.report.result.explanation", explanation.contains(propertyName));
                anomalyIndex++;
            }
        }
    }
    assertEquals("Number of reports.", anomalousProperties.length, anomalyIndex);
    return quality;
}
Also used : DataQuality(org.opengis.metadata.quality.DataQuality) Element(org.opengis.metadata.quality.Element) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Result(org.opengis.metadata.quality.Result) QuantitativeResult(org.opengis.metadata.quality.QuantitativeResult) ConformanceResult(org.opengis.metadata.quality.ConformanceResult) ConformanceResult(org.opengis.metadata.quality.ConformanceResult)

Example 4 with DataQuality

use of org.opengis.metadata.quality.DataQuality in project sis by apache.

the class Validator method validate.

/**
 * Implementation of {@link AbstractFeature#quality()}, also shared by {@link Features} static method.
 *
 * @param type     the type of the {@code feature} argument, provided explicitely for protecting from user overriding.
 * @param feature  the feature to validate.
 */
void validate(final FeatureType type, final AbstractFeature feature) {
    for (final AbstractIdentifiedType pt : type.getProperties(true)) {
        final Object property = feature.getProperty(pt.getName().toString());
        final DataQuality pq;
        if (property instanceof AbstractAttribute<?>) {
            pq = ((AbstractAttribute<?>) property).quality();
        } else if (property instanceof AbstractAssociation) {
            pq = ((AbstractAssociation) property).quality();
        } else if (property instanceof AbstractAttribute<?>) {
            validate(((AbstractAttribute<?>) property).getType(), ((AbstractAttribute<?>) property).getValues());
            continue;
        } else if (property instanceof AbstractAssociation) {
            validate(((AbstractAssociation) property).getRole(), ((AbstractAssociation) property).getValues());
            continue;
        } else {
            continue;
        }
        if (pq != null) {
            // Should not be null, but let be safe.
            quality.getReports().addAll(pq.getReports());
        }
    }
}
Also used : DataQuality(org.opengis.metadata.quality.DataQuality) DefaultDataQuality(org.apache.sis.metadata.iso.quality.DefaultDataQuality)

Aggregations

DataQuality (org.opengis.metadata.quality.DataQuality)4 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)2 Test (org.junit.Test)2 ConformanceResult (org.opengis.metadata.quality.ConformanceResult)2 Element (org.opengis.metadata.quality.Element)2 QuantitativeResult (org.opengis.metadata.quality.QuantitativeResult)2 Result (org.opengis.metadata.quality.Result)2 DefaultDataQuality (org.apache.sis.metadata.iso.quality.DefaultDataQuality)1