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