sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1596588 - in /sis/branches/JDK8/core/sis-feature/src: main/java/org/apache/sis/feature/DefaultFeatureType.java main/java/org/apache/sis/feature/SparseFeature.java test/java/org/apache/sis/feature/FeatureTestCase.java
Date Wed, 21 May 2014 14:44:44 GMT
Author: desruisseaux
Date: Wed May 21 14:44:43 2014
New Revision: 1596588

URL: http://svn.apache.org/r1596588
Log:
Additional test and bug fix in the evaluation of Feature quality.

Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java?rev=1596588&r1=1596587&r2=1596588&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] Wed May 21 14:44:43 2014
@@ -246,7 +246,7 @@ public class DefaultFeatureType extends 
     private void computeTransientFields() {
         final int capacity = Containers.hashMapCapacity(properties.size());
         byName       = new LinkedHashMap<>(capacity);
-        indices      = new HashMap<>(capacity);
+        indices      = new LinkedHashMap<>(capacity);
         assignableTo = new HashSet<>(4);
         assignableTo.add(getName());
         scanPropertiesFrom(this);

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java?rev=1596588&r1=1596587&r2=1596588&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java
[UTF-8] Wed May 21 14:44:43 2014
@@ -226,8 +226,8 @@ final class SparseFeature extends Abstra
     public DataQuality quality() {
         if (valuesKind == VALUES) {
             final Validator v = new Validator(ScopeCode.FEATURE);
-            for (final Map.Entry<String, Object> entry : properties.entrySet()) {
-                v.validateAny(getPropertyType(entry.getKey()), entry.getValue());
+            for (final String name : super.getType().indices().keySet()) {
+                v.validateAny(getPropertyType(name), properties.get(name));
             }
             return v.quality;
         }

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java?rev=1596588&r1=1596587&r2=1596588&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
[UTF-8] Wed May 21 14:44:43 2014
@@ -133,8 +133,16 @@ abstract strictfp class FeatureTestCase 
             assertTrue(message, message.contains("Integer"));
         }
         assertEquals("Property shall not have been modified.", "Atlantide", getAttributeValue("city"));
+        /*
+         * Before we set the population attribute, the feature should be considered invalid.
+         * After we set it, the feature should be valid since all mandatory attributes are
set.
+         */
+        assertQualityReports("population", "population");
         setAttributeValue("population", null, 1000);
-        assertValid();
+        assertQualityReports(null, null);
+        /*
+         * Opportunist tests using the existing instance.
+         */
         testSerialization();
         try {
             testClone("population", 1000, 1500);
@@ -170,7 +178,6 @@ abstract strictfp class FeatureTestCase 
          * in order to test the conversion of existing values to property instances.
          */
         getValuesFromProperty = true;
-        setAttributeValue("isGlobal", null, Boolean.TRUE);
         final SimpleInternationalString region = new SimpleInternationalString("State of
New York");
         setAttributeValue("region", null, region);
         /*
@@ -186,7 +193,16 @@ abstract strictfp class FeatureTestCase 
             assertTrue(message, message.contains("String"));
         }
         assertSame("region", region, getAttributeValue("region"));
-        assertValid();
+        /*
+         * Before we set the 'isGlobal' attribute, the feature should be considered invalid.
+         * After we set it, the feature should be valid since all mandatory attributes are
set.
+         */
+        assertQualityReports("isGlobal", "isGlobal");
+        setAttributeValue("isGlobal", null, Boolean.TRUE);
+        assertQualityReports(null, null);
+        /*
+         * Opportunist tests using the existing instance.
+         */
         testSerialization();
         try {
             testClone("population", 8405837, 8405838); // A birth...
@@ -196,15 +212,26 @@ abstract strictfp class FeatureTestCase 
     }
 
     /**
-     * Asserts that {@link AbstractFeature#quality()} reports no anomaly.
+     * Asserts that {@link AbstractFeature#quality()} reports no anomaly, or only an anomaly
for the given property.
+     *
+     * @param property The property for which we expect a report, or {@code null} if none.
+     * @param keyword  A keyword which is expected to exists in the explanation.
      */
-    private void assertValid() {
+    private void assertQualityReports(final String property, final String keyword) {
+        int numOccurrences = 0;
         for (final Element report : feature.quality().getReports()) {
             for (final Result result : report.getResults()) {
                 assertInstanceOf("result", ConformanceResult.class, result);
-                assertTrue("result.pass", ((ConformanceResult) result).pass());
+                if (!((ConformanceResult) result).pass()) {
+                    final String identifier  = report.getMeasureIdentification().toString();
+                    final String explanation = ((ConformanceResult) result).getExplanation().toString();
+                    assertEquals("quality.report.measureIdentification", property, identifier);
+                    assertTrue("quality.report.result.explanation", explanation.contains(keyword));
+                    numOccurrences++;
+                }
             }
         }
+        assertEquals("Number of reports.", property == null ? 0 : 1, numOccurrences);
     }
 
     /**



Mime
View raw message