Search in sources :

Example 1 with Element

use of org.opengis.metadata.quality.Element 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 2 with Element

use of org.opengis.metadata.quality.Element 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)

Aggregations

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