sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1594363 - in /sis/branches/JDK8/core/sis-feature: ./ src/main/java/org/apache/sis/feature/ src/test/java/org/apache/sis/feature/
Date Tue, 13 May 2014 20:10:40 GMT
Author: desruisseaux
Date: Tue May 13 20:10:40 2014
New Revision: 1594363

URL: http://svn.apache.org/r1594363
Log:
'validate()' method now return a DataQuality report instead than throwing an exception when
a property does not met the constraints.

Modified:
    sis/branches/JDK8/core/sis-feature/pom.xml
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttribute.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeature.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Property.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/PropertySingleton.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Validator.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAttributeTest.java

Modified: sis/branches/JDK8/core/sis-feature/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/pom.xml?rev=1594363&r1=1594362&r2=1594363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/pom.xml (original)
+++ sis/branches/JDK8/core/sis-feature/pom.xml Tue May 13 20:10:40 2014
@@ -95,6 +95,20 @@ Representations of geographic features.
       <version>${project.version}</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.sis.core</groupId>
+      <artifactId>sis-metadata</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sis.core</groupId>
+      <artifactId>sis-referencing</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opengis</groupId>
+      <artifactId>geoapi-pending</artifactId>
+    </dependency>
+    <dependency>
       <groupId>com.esri.geometry</groupId>
       <artifactId>esri-geometry-api</artifactId>
     </dependency>

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java?rev=1594363&r1=1594362&r2=1594363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java
[UTF-8] Tue May 13 20:10:40 2014
@@ -17,6 +17,7 @@
 package org.apache.sis.feature;
 
 import java.io.Serializable;
+import org.opengis.metadata.quality.DataQuality;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
@@ -109,7 +110,8 @@ public class DefaultAssociation extends 
      *
      * {@section Validation}
      * The amount of validation performed by this method is implementation dependent.
-     * The current {@code DefaultAssociation} implementation performs only very cheap validations.
+     * Usually, only the most basic constraints are verified. This is so for performance
reasons
+     * and also because some rules may be temporarily broken while constructing a feature.
      * A more exhaustive verification can be performed by invoking the {@link #validate()}
method.
      *
      * @param  value The new value, or {@code null}.
@@ -130,15 +132,27 @@ public class DefaultAssociation extends 
     }
 
     /**
-     * Ensures that the current association value complies with the constraints defined by
the association role.
-     * This method can be invoked explicitly on a single association, or may be invoked implicitly
by a call to
-     * {@link DefaultFeature#validate()}.
+     * Verifies if the current association value mets the constraints defined by the association
role.
+     * This method returns {@linkplain org.apache.sis.metadata.iso.quality.DefaultDataQuality#getReports()
+     * reports} for all constraint violations found, if any.
+     * See {@link DefaultAttribute#validate()} for an example.
+     *
+     * <p>This association is valid if this method does not report any
+     * {@linkplain org.apache.sis.metadata.iso.quality.DefaultConformanceResult conformance
result} having a
+     * {@linkplain org.apache.sis.metadata.iso.quality.DefaultConformanceResult#pass() pass}
value of {@code false}.</p>
+     *
+     * @return Reports on all constraint violations found.
      *
      * @see DefaultFeature#validate()
      */
-    @Override
-    public void validate() {
-        Validator.ensureValidValue(role, value);
+    /*
+     * API NOTE: this method is final for now because if we allowed users to override it,
users would
+     * expect their method to be invoked by DefaultFeature.validate(). But this is not yet
the case.
+     */
+    public final DataQuality validate() {
+        final Validator v = new Validator(null);
+        v.validate(role, value);
+        return v.quality;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttribute.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttribute.java?rev=1594363&r1=1594362&r2=1594363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttribute.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttribute.java
[UTF-8] Tue May 13 20:10:40 2014
@@ -17,6 +17,8 @@
 package org.apache.sis.feature;
 
 import java.io.Serializable;
+import org.opengis.metadata.quality.DataQuality;
+import org.opengis.metadata.maintenance.ScopeCode;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.ArgumentChecks;
@@ -114,6 +116,12 @@ public class DefaultAttribute<T> extends
     /**
      * Sets the attribute value.
      *
+     * {@section Validation}
+     * The amount of validation performed by this method is implementation dependent.
+     * Usually, only the most basic constraints are verified. This is so for performance
reasons
+     * and also because some rules may be temporarily broken while constructing a feature.
+     * A more exhaustive verification can be performed by invoking the {@link #validate()}
method.
+     *
      * @param value The new value.
      *
      * @see DefaultFeature#setPropertyValue(String, Object)
@@ -123,15 +131,44 @@ public class DefaultAttribute<T> extends
     }
 
     /**
-     * Ensures that the current attribute value complies with the constraints defined by
the attribute type.
-     * This method can be invoked explicitly on a single attribute, or may be invoked implicitly
by a call to
-     * {@link DefaultFeature#validate()}.
+     * Verifies if the current attribute value mets the constraints defined by the attribute
type.
+     * This method returns {@linkplain org.apache.sis.metadata.iso.quality.DefaultDataQuality#getReports()
+     * reports} for all constraint violations found, if any.
+     *
+     * <div class="note"><b>Example:</b> given an attribute named “population”
with [1 … 1] cardinality,
+     * if no value has been assigned to that attribute, then this {@code validate()} method
will return
+     * the following data quality report:
+     *
+     * {@preformat text
+     *   Data quality
+     *     ├─Scope
+     *     │   └─Level…………………………………………………
Attribute
+     *     └─Report
+     *         ├─Measure identification
+     *         │   └─Code…………………………………………
population
+     *         ├─Evaluation method type…… Direct internal
+     *         └─Result
+     *             ├─Explanation……………………… Missing value for
“population” property.
+     *             └─Pass………………………………………… false
+     * }
+     * </div>
+     *
+     * This attribute is valid if this method does not report any
+     * {@linkplain org.apache.sis.metadata.iso.quality.DefaultConformanceResult conformance
result} having a
+     * {@linkplain org.apache.sis.metadata.iso.quality.DefaultConformanceResult#pass() pass}
value of {@code false}.
+     *
+     * @return Reports on all constraint violations found.
      *
      * @see DefaultFeature#validate()
      */
-    @Override
-    public void validate() {
-        Validator.ensureValidValue(type, value);
+    /*
+     * API NOTE: this method is final for now because if we allowed users to override it,
users would
+     * expect their method to be invoked by DefaultFeature.validate(). But this is not yet
the case.
+     */
+    public final DataQuality validate() {
+        final Validator v = new Validator(ScopeCode.ATTRIBUTE);
+        v.validate(type, value);
+        return v.quality;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeature.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeature.java?rev=1594363&r1=1594362&r2=1594363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeature.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeature.java
[UTF-8] Tue May 13 20:10:40 2014
@@ -20,6 +20,8 @@ import java.util.Map;
 import java.util.HashMap;
 import java.util.ConcurrentModificationException;
 import java.io.Serializable;
+import org.opengis.metadata.quality.DataQuality;
+import org.opengis.metadata.maintenance.ScopeCode;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
@@ -220,13 +222,14 @@ public class DefaultFeature implements S
      *
      * {@section Validation}
      * The amount of validation performed by this method is implementation dependent.
-     * The current {@code DefaultFeature} implementation performs only minimal validations.
+     * Usually, only the most basic constraints are verified. This is so for performance
reasons
+     * and also because some rules may be temporarily broken while constructing a feature.
      * A more exhaustive verification can be performed by invoking the {@link #validate()}
method.
      *
      * @param  name  The attribute name.
      * @param  value The new value for the given attribute (may be {@code null}).
-     * @throws IllegalArgumentException If the given argument is not an attribute name of
this feature.
      * @throws ClassCastException If the value is not assignable to the expected value class.
+     * @throws IllegalArgumentException If the given value can not be assigned for an other
reason.
      *
      * @see DefaultAttribute#setValue(Object)
      */
@@ -307,21 +310,47 @@ public class DefaultFeature implements S
     }
 
     /**
-     * Ensures that all current properties comply with the constraints defined by the feature
type.
-     * This method will implicitly invokes {@link DefaultAttribute#validate()} for all attributes.
+     * Verifies if all current properties met the constraints defined by the feature type.
+     * This method returns {@linkplain org.apache.sis.metadata.iso.quality.DefaultDataQuality#getReports()
+     * reports} for all constraint violations found, if any.
+     *
+     * <div class="note"><b>Example:</b> given a feature with an attribute
named “population”.
+     * If this attribute is mandatory ([1 … 1] cardinality) but no value has been assigned
to it,
+     * then this {@code validate()} method will return the following data quality report:
+     *
+     * {@preformat text
+     *   Data quality
+     *     ├─Scope
+     *     │   └─Level…………………………………………………
Feature
+     *     └─Report
+     *         ├─Measure identification
+     *         │   └─Code…………………………………………
population
+     *         ├─Evaluation method type…… Direct internal
+     *         └─Result
+     *             ├─Explanation……………………… Missing value for
“population” property.
+     *             └─Pass………………………………………… false
+     * }
+     * </div>
+     *
+     * This feature is valid if this method does not report any
+     * {@linkplain org.apache.sis.metadata.iso.quality.DefaultConformanceResult conformance
result} having a
+     * {@linkplain org.apache.sis.metadata.iso.quality.DefaultConformanceResult#pass() pass}
value of {@code false}.
+     *
+     * @return Reports on all constraint violations found.
      *
      * @see DefaultAttribute#validate()
      * @see DefaultAssociation#validate()
      */
-    public void validate() {
+    /*
+     * API NOTE: this method is final for now because if we allowed users to override it,
users would
+     * expect their method to be invoked by DefaultAssociation.validate(). But this is not
yet the case.
+     */
+    public final DataQuality validate() {
+        final Validator v = new Validator(ScopeCode.FEATURE);
         for (final Map.Entry<String, Object> entry : properties.entrySet()) {
-            final Object value = entry.getValue();
-            if (value instanceof Property) {
-                ((Property) value).validate();
-            } else {
-                Validator.ensureValid(getPropertyType(entry.getKey()), value);
-            }
+            v.validateAny(getPropertyType(entry.getKey()), entry.getValue());
         }
+        return v.quality;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Property.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Property.java?rev=1594363&r1=1594362&r2=1594363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Property.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Property.java
[UTF-8] Tue May 13 20:10:40 2014
@@ -30,5 +30,4 @@ package org.apache.sis.feature;
  * @module
  */
 abstract class Property {
-    public abstract void validate();
 }

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/PropertySingleton.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/PropertySingleton.java?rev=1594363&r1=1594362&r2=1594363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/PropertySingleton.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/PropertySingleton.java
[UTF-8] Tue May 13 20:10:40 2014
@@ -118,7 +118,7 @@ final class PropertySingleton extends Ab
     @Override
     public DefaultAttribute<?> set(final int index, final DefaultAttribute<?>
element) {
         ensureNonNull("element", element);
-        Validator.ensureValidType(type, element);
+        ensureValidType(element);
         if (index == 0) {
             modCount++;
             final Object previous = properties.put(key, element);
@@ -133,12 +133,22 @@ final class PropertySingleton extends Ab
     }
 
     /**
+     * Ensures that the give element is an instance of the expected type.
+     * The caller shall ensure that the element is non-null before to invoke this method.
+     */
+    private void ensureValidType(final DefaultAttribute<?> element) {
+        if (element.getType() != type) {
+            throw new IllegalArgumentException(Errors.format(Errors.Keys.MismatchedPropertyType_1,
type.getName()));
+        }
+    }
+
+    /**
      * Sets the attribute associated to the key, if no instance existed prior this method
call.
      */
     @Override
     public void add(final int index, final DefaultAttribute<?> element) {
         ensureNonNull("element", element);
-        Validator.ensureValidType(type, element);
+        ensureValidType(element);
         if (index == 0) {
             if (properties.putIfAbsent(key, element) == null) {
                 modCount++;

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Validator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Validator.java?rev=1594363&r1=1594362&r2=1594363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Validator.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Validator.java
[UTF-8] Tue May 13 20:10:40 2014
@@ -16,6 +16,16 @@
  */
 package org.apache.sis.feature;
 
+import org.opengis.util.GenericName;
+import org.opengis.util.InternationalString;
+import org.opengis.metadata.Identifier;
+import org.opengis.metadata.maintenance.ScopeCode;
+import org.opengis.metadata.quality.EvaluationMethodType;
+import org.apache.sis.metadata.iso.quality.DefaultDataQuality;
+import org.apache.sis.metadata.iso.quality.DefaultDomainConsistency;
+import org.apache.sis.metadata.iso.quality.DefaultConformanceResult;
+import org.apache.sis.metadata.iso.quality.DefaultScope;
+import org.apache.sis.referencing.NamedIdentifier;
 import org.apache.sis.util.resources.Errors;
 
 
@@ -29,63 +39,99 @@ import org.apache.sis.util.resources.Err
  */
 final class Validator {
     /**
-     * Do not allow (for now) instantiation of this class.
+     * The data quality report.
      */
-    private Validator() {
-    }
+    final DefaultDataQuality quality;
 
     /**
-     * Ensures that the give element is an instance of the expected type.
-     * The caller shall ensure that the element is non-null before to invoke this method.
+     * Creates a new validator.
+     *
+     * @param feature {@code FEATURE} if the object to validate is a feature,
+     *        or {@code ATTRIBUTE} for an attribute, or {@code null} otherwise.
      */
-    static void ensureValidType(final AbstractIdentifiedType type, final DefaultAttribute<?>
element) {
-        if (element.getType() != type) {
-            throw new IllegalArgumentException(Errors.format(Errors.Keys.MismatchedPropertyType_1,
type.getName()));
+    Validator(final ScopeCode scope) {
+        quality = new DefaultDataQuality();
+        if (scope != null) {
+            quality.setScope(new DefaultScope(scope));
         }
     }
 
     /**
-     * Ensures that the given value is valid for the given attribute type.
-     * This method delegates to one of the {@code ensureValidValue(…)} methods depending
of the value type.
+     * Adds a report for a constraint violation.
+     *
+     * @param type        Description of the property for which a constraint violation has
been found.
+     * @param explanation Explanation of the constraint violation.
+     */
+    void addViolationReport(final AbstractIdentifiedType type, final InternationalString
explanation) {
+        final DefaultDomainConsistency report = new DefaultDomainConsistency();
+        final GenericName name = type.getName();
+        report.setMeasureIdentification(name instanceof Identifier ? (Identifier) name :
new NamedIdentifier(name));
+        report.setMeasureDescription(type.getDescription());
+        report.setEvaluationMethodType(EvaluationMethodType.DIRECT_INTERNAL);
+        report.getResults().add(new DefaultConformanceResult(null, explanation, false));
+        quality.getReports().add(report);
+    }
+
+    /**
+     * Verifies if the given value is valid for the given attribute type.
+     * This method delegates to one of the {@code validate(…)} methods depending of the
value type.
      */
-    static void ensureValid(final PropertyType type, final Object value) {
+    void validateAny(final PropertyType type, final Object value) {
         if (type instanceof DefaultAttributeType<?>) {
-            ensureValidValue((DefaultAttributeType<?>) type, value);
+            validate((DefaultAttributeType<?>) type, value);
         }
         if (type instanceof DefaultAssociationRole) {
-            ensureValidValue((DefaultAssociationRole) type, (DefaultFeature) value);
+            validate((DefaultAssociationRole) type, (DefaultFeature) value);
         }
     }
 
     /**
-     * Ensures that the given value is valid for the given attribute type.
+     * Verifies if the given value is valid for the given attribute type.
      */
-    static void ensureValidValue(final DefaultAttributeType<?> type, final Object value)
{
-        if (value == null) {
-            return;
+    void validate(final DefaultAttributeType<?> type, final Object value) {
+        if (value != null) {
+            /*
+             * In theory, the following check is unnecessary since the type was constrained
by the Attribute.setValue(T)
+             * method signature. However in practice the call to Attribute.setValue(…)
is sometime done after type erasure,
+             * so we are better to check.
+             */
+            if (!type.getValueClass().isInstance(value)) {
+                addViolationReport(type, Errors.formatInternational(
+                        Errors.Keys.IllegalPropertyClass_2, type.getName(), value.getClass()));
+            }
         }
-        /*
-         * In theory, the following check is unnecessary since the type was constrained by
the Attribute.setValue(T)
-         * method signature. However in practice the call to Attribute.setValue(…) is sometime
done after type erasure,
-         * so we are better to check.
-         */
-        if (!type.getValueClass().isInstance(value)) {
-            throw new IllegalStateException(
-                    Errors.format(Errors.Keys.IllegalPropertyClass_2, type.getName(), value.getClass()));
+        verifyCardinality(type, type.getMinimumOccurs(), type.getMaximumOccurs(), value);
+    }
+
+    /**
+     * Verifies if the given value is valid for the given association role.
+     */
+    void validate(final DefaultAssociationRole role, final DefaultFeature value) {
+        if (value != null) {
+            final DefaultFeatureType type = value.getType();
+            if (!role.getValueType().isAssignableFrom(type)) {
+                addViolationReport(role, Errors.formatInternational(
+                        Errors.Keys.IllegalPropertyClass_2, role.getName(), type.getName()));
+            }
         }
+        verifyCardinality(role, role.getMinimumOccurs(), role.getMaximumOccurs(), value);
     }
 
     /**
-     * Ensures that the given value is valid for the given association role.
+     * Verifies if the given value mets the cardinality constraint.
      */
-    static void ensureValidValue(final DefaultAssociationRole role, final DefaultFeature
value) {
+    private void verifyCardinality(final AbstractIdentifiedType type,
+            final int minimumOccurs, final int maximumOccurs, final Object value)
+    {
         if (value == null) {
-            return;
-        }
-        final DefaultFeatureType type = value.getType();
-        if (!role.getValueType().isAssignableFrom(type)) {
-            throw new IllegalStateException(
-                    Errors.format(Errors.Keys.IllegalPropertyClass_2, role.getName(), type.getName()));
+            if (minimumOccurs != 0) {
+                addViolationReport(type, Errors.formatInternational(
+                        Errors.Keys.MissingValueForProperty_1, type.getName()));
+            }
+        } else {
+            if (maximumOccurs == 0) {
+                // TODO
+            }
         }
     }
 }

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAttributeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAttributeTest.java?rev=1594363&r1=1594362&r2=1594363&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAttributeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAttributeTest.java
[UTF-8] Tue May 13 20:10:40 2014
@@ -16,13 +16,19 @@
  */
 package org.apache.sis.feature;
 
+import java.util.Locale;
 import java.util.HashMap;
+import org.opengis.metadata.quality.DataQuality;
+import org.opengis.metadata.quality.DomainConsistency;
+import org.opengis.metadata.quality.ConformanceResult;
+import org.opengis.metadata.maintenance.ScopeCode;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
+import static org.apache.sis.test.TestUtilities.getSingleton;
 
 
 /**
@@ -65,6 +71,44 @@ public final strictfp class DefaultAttri
     }
 
     /**
+     * Tests {@link DefaultAttribute#validate()}.
+     */
+    @Test
+    @DependsOnMethod("testValue")
+    @SuppressWarnings("unchecked")
+    public void testValidate() {
+        final DefaultAttribute<Integer> attribute = population();
+        DataQuality quality = attribute.validate();
+        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.
+         */
+        ((DefaultAttribute) attribute).setValue(4.5f);
+        quality = attribute.validate();
+        assertEquals("scope.level", ScopeCode.ATTRIBUTE, quality.getScope().getLevel());
+        assertDomainConsistencyEquals("population", "Property “population” does not accept
instances of ‘Float’.",
+                (DomainConsistency) getSingleton(quality.getReports()));
+    }
+
+    /**
+     * Verifies that the given element reports a validation failure with the given explanation.
+     *
+     * @param propertyName The name of the property that failed validation.
+     * @param explanation  The expected explanation.
+     * @param consistency  The report element to test.
+     */
+    private static void assertDomainConsistencyEquals(final String propertyName, final String
explanation,
+            final DomainConsistency consistency)
+    {
+        assertEquals("report.measureIdentification", propertyName, consistency.getMeasureIdentification().getCode());
+        final ConformanceResult result = (ConformanceResult) getSingleton(consistency.getResults());
+        assertFalse ("report.result.pass", result.pass());
+        assertEquals("report.result.explanation", explanation, result.getExplanation().toString(Locale.US));
+    }
+
+    /**
      * Tests attribute comparison.
      */
     @Test



Mime
View raw message