sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1566470 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/metadata/iso/ sis-referencing/src/main/java/org/apache/sis/parameter/ sis-referencing/src/main/java/org/apache/sis/referencing/ sis-referencing/src/test/java/o...
Date Sun, 09 Feb 2014 23:23:02 GMT
Author: desruisseaux
Date: Sun Feb  9 23:23:01 2014
New Revision: 1566470

URL: http://svn.apache.org/r1566470
Log:
Ported more tests.

Added:
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java   (with props)
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java?rev=1566470&r1=1566469&r2=1566470&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java [UTF-8] Sun Feb  9 23:23:01 2014
@@ -299,11 +299,16 @@ public class ImmutableIdentifier extends
      *   </tr>
      * </table>
      *
+     * {@section Localization}
      * {@code "remarks"} is a localizable attributes which may have a language and country
      * code suffix. For example the {@code "remarks_fr"} property stands for remarks in
      * {@linkplain Locale#FRENCH French} and the {@code "remarks_fr_CA"} property stands
      * for remarks in {@linkplain Locale#CANADA_FRENCH French Canadian}.
      *
+     * <p>The {@code "locale"} property applies only to exception messages, if any.
+     * After successful construction, {@code ImmutableIdentifier} instances do not keep the locale
+     * since localizations are deferred to the {@link InternationalString#toString(Locale)} method.</p>
+     *
      * @param  properties The properties to be given to this identifier.
      * @throws InvalidParameterValueException if a property has an invalid value.
      * @throws IllegalArgumentException if a property is invalid for some other reason.

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java?rev=1566470&r1=1566469&r2=1566470&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java [UTF-8] Sun Feb  9 23:23:01 2014
@@ -19,7 +19,7 @@ package org.apache.sis.parameter;
 import java.util.Arrays;
 import java.util.Set;
 import java.util.Map;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import javax.measure.unit.Unit;
 
 import org.opengis.util.CodeList;
@@ -180,7 +180,7 @@ public class DefaultParameterDescriptor<
             }
         }
         if (validValues != null) {
-            final Set<T> valids = new HashSet<>(hashMapCapacity(validValues.length));
+            final Set<T> valids = new LinkedHashSet<>(hashMapCapacity(validValues.length));
             for (T value : validValues) {
                 value = Numerics.cached(value);
                 ensureCanCast("validValues", valueClass, value);
@@ -190,9 +190,11 @@ public class DefaultParameterDescriptor<
         } else {
             this.validValues = null;
         }
-        final Verifier error = Verifier.ensureValidValue(valueClass, this.validValues, minimum, maximum, defaultValue);
-        if (error != null) {
-            throw new IllegalArgumentException(error.message(properties, super.getName().getCode(), defaultValue));
+        if (defaultValue != null) {
+            final Verifier error = Verifier.ensureValidValue(valueClass, this.validValues, minimum, maximum, defaultValue);
+            if (error != null) {
+                throw new IllegalArgumentException(error.message(properties, super.getName().getCode(), defaultValue));
+            }
         }
     }
 

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java?rev=1566470&r1=1566469&r2=1566470&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java [UTF-8] Sun Feb  9 23:23:01 2014
@@ -323,7 +323,7 @@ public class DefaultParameterValue<T> ex
     private UnitConverter getConverterTo(final Unit<?> unit) {
         final Unit<?> source = getUnit();
         if (source == null) {
-            throw Verifier.unitlessParameter(descriptor);
+            throw new IllegalStateException(Errors.format(Errors.Keys.UnitlessParameter_1, Verifier.getName(descriptor)));
         }
         ensureNonNull("unit", unit);
         final short expectedID = Verifier.getUnitMessageID(source);
@@ -467,12 +467,19 @@ public class DefaultParameterValue<T> ex
     }
 
     /**
-     * Sets the parameter value as an object. The object type is typically a {@link Double}, {@link Integer},
-     * {@link Boolean}, {@link String}, {@link URI}, {@code double[]} or {@code int[]}.
+     * Sets the parameter value as an object. The object type is typically (but not limited to) {@link Double},
+     * {@link Integer}, {@link Boolean}, {@link String}, {@link URI}, {@code double[]} or {@code int[]}.
+     * If the given value is {@code null}, then there is a choice:
+     *
+     * <ul>
+     *   <li>If this parameter is mandatory, then the value is set to the
+     *       {@linkplain DefaultParameterDescriptor#getDefaultValue() default value}.</li>
+     *   <li>If this parameter is optional, then the value is set to {@code null} as requested.</li>
+     * </ul>
      *
-     * <p>The default implementation delegates to {@link #setValue(Object, Unit)}.</p>
+     * The default implementation delegates to {@link #setValue(Object, Unit)}.
      *
-     * @param  value The parameter value, or {@code null} to restore the default value.
+     * @param  value The parameter value, or {@code null}.
      * @throws InvalidParameterValueException if the type of {@code value} is inappropriate for this parameter,
      *         or if the value is illegal for some other reason (for example the value is numeric and out of range).
      *
@@ -532,9 +539,11 @@ public class DefaultParameterValue<T> ex
 
     /**
      * Wraps the given value in a type compatible with the expected value class, if possible.
+     *
+     * @throws IllegalArgumentException If the given value can not be converted to the given type.
      */
     @SuppressWarnings("unchecked")
-    private static Number wrap(final double value, final Class<?> valueClass) {
+    private static Number wrap(final double value, final Class<?> valueClass) throws IllegalArgumentException {
         if (Number.class.isAssignableFrom(valueClass)) {
             return Numbers.wrap(value, (Class<? extends Number>) valueClass);
         } else {
@@ -558,9 +567,13 @@ public class DefaultParameterValue<T> ex
      */
     @Override
     public void setValue(final double value) throws InvalidParameterValueException {
-        // Use 'unit' instead than 'getUnit()' despite class Javadoc claims because units are not expected
-        // to be involved in this method. We just want the current unit setting to be unchanged.
-        setValue(wrap(value, ((ParameterDescriptor<?>) descriptor).getValueClass()), unit);
+        try {
+            // Use 'unit' instead than 'getUnit()' despite class Javadoc claims because units are not expected
+            // to be involved in this method. We just want the current unit setting to be unchanged.
+            setValue(wrap(value, ((ParameterDescriptor<?>) descriptor).getValueClass()), unit);
+        } catch (IllegalArgumentException e) {
+            throw new InvalidParameterValueException(e.getLocalizedMessage(), Verifier.getName(descriptor), value);
+        }
     }
 
     /**
@@ -579,7 +592,11 @@ public class DefaultParameterValue<T> ex
      */
     @Override
     public void setValue(final double value, final Unit<?> unit) throws InvalidParameterValueException {
-        setValue(wrap(value, ((ParameterDescriptor<?>) descriptor).getValueClass()), unit);
+        try {
+            setValue(wrap(value, ((ParameterDescriptor<?>) descriptor).getValueClass()), unit);
+        } catch (IllegalArgumentException e) {
+            throw new InvalidParameterValueException(e.getLocalizedMessage(), Verifier.getName(descriptor), value);
+        }
     }
 
     /**
@@ -599,11 +616,19 @@ public class DefaultParameterValue<T> ex
 
     /**
      * Sets the parameter value and its associated unit.
+     * If the given value is {@code null}, then there is a choice:
+     * <ul>
+     *   <li>If this parameter is mandatory, then the value is set to the
+     *       {@linkplain DefaultParameterDescriptor#getDefaultValue() default value}.</li>
+     *   <li>If this parameter is optional, then the value is set to {@code null} as requested.</li>
+     * </ul>
+     *
+     * {@section Implementation note for subclasses}
      * This method is invoked by all setter methods in this class, thus providing a single point that
      * subclasses can override if they want to perform more processing on the value before its storage,
      * or to be notified about value changes.
      *
-     * @param  value The parameter value, or {@code null} to restore the default value.
+     * @param  value The parameter value, or {@code null}.
      * @param  unit  The unit associated to the new parameter value, or {@code null}.
      * @throws InvalidParameterValueException if the type of {@code value} is inappropriate for this parameter,
      *         or if the value is illegal for some other reason (for example the value is numeric and out of range).

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java?rev=1566470&r1=1566469&r2=1566470&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java [UTF-8] Sun Feb  9 23:23:01 2014
@@ -94,12 +94,6 @@ final class Verifier {
     static <T> T ensureValidValue(final ParameterDescriptor<T> descriptor, final Object value, final Unit<?> unit)
             throws InvalidParameterValueException
     {
-        if (value == null) {
-            if (descriptor.getMinimumOccurs() != 0) {
-                return descriptor.getDefaultValue();
-            }
-            return null;
-        }
         final Class<T> type = descriptor.getValueClass();
         /*
          * Before to verify if the given value is inside the bounds, we need to convert the value
@@ -109,20 +103,21 @@ final class Verifier {
         if (unit != null) {
             final Unit<?> def = descriptor.getUnit();
             if (def == null) {
-                throw unitlessParameter(descriptor);
+                final String name = getName(descriptor);
+                throw new InvalidParameterValueException(Errors.format(Errors.Keys.UnitlessParameter_1, name), name, unit);
             }
             if (!unit.equals(def)) {
                 final short expectedID = getUnitMessageID(def);
                 if (getUnitMessageID(unit) != expectedID) {
                     throw new IllegalArgumentException(Errors.format(expectedID, unit));
                 }
-                final UnitConverter converter;
-                try {
-                    converter = unit.getConverterToAny(def);
-                } catch (ConversionException e) {
-                    throw new IllegalArgumentException(Errors.format(Errors.Keys.IncompatibleUnits_2, unit, def), e);
-                }
-                if (Number.class.isAssignableFrom(type)) {
+                if (value != null && Number.class.isAssignableFrom(type)) {
+                    final UnitConverter converter;
+                    try {
+                        converter = unit.getConverterToAny(def);
+                    } catch (ConversionException e) {
+                        throw new IllegalArgumentException(Errors.format(Errors.Keys.IncompatibleUnits_2, unit, def), e);
+                    }
                     Number n = (Number) value; // Given value.
                     n = converter.convert(n.doubleValue()); // Value in units that we can compare.
                     try {
@@ -133,13 +128,16 @@ final class Verifier {
                 }
             }
         }
-        final Comparable<T> minimum = descriptor.getMinimumValue();
-        final Comparable<T> maximum = descriptor.getMaximumValue();
-        final Verifier error = ensureValidValue(descriptor.getValueClass(),
-                    descriptor.getValidValues(), minimum, maximum, convertedValue);
-        if (error != null) {
-            final String name = getName(descriptor);
-            throw new InvalidParameterValueException(error.message(null, name, value), name, value);
+        if (convertedValue != null) {
+            final Comparable<T> minimum = descriptor.getMinimumValue();
+            final Comparable<T> maximum = descriptor.getMaximumValue();
+            final Verifier error = ensureValidValue(type, descriptor.getValidValues(), minimum, maximum, convertedValue);
+            if (error != null) {
+                final String name = getName(descriptor);
+                throw new InvalidParameterValueException(error.message(null, name, value), name, value);
+            }
+        } else if (descriptor.getMinimumOccurs() != 0) {
+            return descriptor.getDefaultValue();
         }
         /*
          * Passed every tests - the value is valid.
@@ -168,8 +166,8 @@ final class Verifier {
         {
             return new Verifier(Errors.Keys.ValueOutOfRange_4, true, null, minimum, maximum, convertedValue);
         }
-        if (validValues!=null && !validValues.contains(convertedValue)) {
-            return new Verifier(Errors.Keys.IllegalArgumentValue_2, true, null, convertedValue);
+        if (validValues != null && !validValues.contains(convertedValue)) {
+            return new Verifier(Errors.Keys.IllegalParameterValue_2, true, null, convertedValue);
         }
         return null;
     }
@@ -190,13 +188,6 @@ final class Verifier {
     }
 
     /**
-     * Returns an exception initialized with a "Unitless parameter" error message for the specified descriptor.
-     */
-    static IllegalStateException unitlessParameter(final GeneralParameterDescriptor descriptor) {
-        return new IllegalStateException(Errors.format(Errors.Keys.UnitlessParameter_1, getName(descriptor)));
-    }
-
-    /**
      * Convenience method returning the name of the specified descriptor.
      * This method is used mostly for output to be read by human, not for processing.
      * Consequently, we may consider to returns a localized name in a future version.

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1566470&r1=1566469&r2=1566470&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] Sun Feb  9 23:23:01 2014
@@ -209,8 +209,12 @@ public class AbstractIdentifiedObject ex
     /**
      * Constructs an object from the given properties. Keys are strings from the table below.
      * The map given in argument shall contain an entry at least for the
-     * {@value org.opengis.referencing.IdentifiedObject#NAME_KEY} key.
+     * {@value org.opengis.referencing.IdentifiedObject#NAME_KEY} or
+     * {@value org.opengis.referencing.ReferenceIdentifier#CODE_KEY} key.
      * Other properties listed in the table below are optional.
+     * In particular, {@code "authority"}, {@code "code"}, {@code "codespace"} and {@code "version"}
+     * are convenience properties for building a name, and are ignored if the {@code "name"} property
+     * is already a {@link ReferenceIdentifier} object instead than a {@link String}.
      *
      * <table class="sis">
      *   <tr>
@@ -265,12 +269,14 @@ public class AbstractIdentifiedObject ex
      *   </tr>
      * </table>
      *
-     * Additionally, all localizable attributes like {@code "remarks"} may have a language and country code suffix.
+     * {@section Localization}
+     * All localizable attributes like {@code "remarks"} may have a language and country code suffix.
      * For example the {@code "remarks_fr"} property stands for remarks in {@linkplain Locale#FRENCH French} and
      * the {@code "remarks_fr_CA"} property stands for remarks in {@linkplain Locale#CANADA_FRENCH French Canadian}.
      *
-     * <p>Note that the {@code "authority"} and {@code "version"} properties are ignored if the {@code "name"}
-     * property is already a {@link ReferenceIdentifier} object instead than a {@link String}.</p>
+     * <p>The {@code "locale"} property applies only to exception messages, if any.
+     * After successful construction, {@code AbstractIdentifiedObject} instances do not keep the locale
+     * since localizations are deferred to the {@link InternationalString#toString(Locale)} method.</p>
      *
      * @param  properties The properties to be given to this identified object.
      * @throws IllegalArgumentException if a property has an invalid value.

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java?rev=1566470&r1=1566469&r2=1566470&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java [UTF-8] Sun Feb  9 23:23:01 2014
@@ -56,7 +56,31 @@ public final strictfp class DefaultParam
     private static final double EPS = 1E-10;
 
     /**
-     * Constructs a descriptor for a mandatory parameter in a range of integer values.
+     * Creates the map of properties to be given to {@link DefaultParameterDescriptor} constructor.
+     *
+     * @param  name The parameter name.
+     * @return The properties to be given to descriptor constructor.
+     */
+    private static Map<String,Object> properties(final String name) {
+        final Map<String,Object> properties = new HashMap<>(4);
+        assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY, name));
+        assertNull(properties.put(DefaultParameterDescriptor.LOCALE_KEY, Locale.US));
+        return properties;
+    }
+
+    /**
+     * Creates a descriptor for an optional parameter without default value, minimum or maximum value.
+     *
+     * @param  name The parameter name.
+     * @param  type The type of values.
+     * @return The parameter descriptor.
+     */
+    static <T> DefaultParameterDescriptor<T> createSimpleOptional(final String name, final Class<T> type) {
+        return new DefaultParameterDescriptor<>(properties(name), type, null, null, null, null, null, false);
+    }
+
+    /**
+     * Creates a descriptor for a mandatory parameter in a range of integer values.
      *
      * @param  name         The parameter name.
      * @param  defaultValue The default value for the parameter.
@@ -64,19 +88,16 @@ public final strictfp class DefaultParam
      * @param  maximum      The maximum parameter value.
      * @return The parameter descriptor for the given range of values.
      */
-    private static DefaultParameterDescriptor<Integer> create(final String name,
+    static DefaultParameterDescriptor<Integer> create(final String name,
             final int defaultValue, final int minimum, final int maximum)
     {
-        final Map<String,Object> properties = new HashMap<>(4);
-        assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY, name));
-        assertNull(properties.put(DefaultParameterDescriptor.LOCALE_KEY, Locale.US));
-        return new DefaultParameterDescriptor<>(properties,
+        return new DefaultParameterDescriptor<>(properties(name),
                  Integer.class, null, Integer.valueOf(defaultValue),
                  Integer.valueOf(minimum), Integer.valueOf(maximum), null, true);
     }
 
     /**
-     * Constructs a descriptor for a mandatory parameter in a range of floating point values.
+     * Creates a descriptor for a mandatory parameter in a range of floating point values.
      *
      * @param  name         The parameter name.
      * @param  defaultValue The default value for the parameter, or {@link Double#NaN} if none.
@@ -85,23 +106,53 @@ public final strictfp class DefaultParam
      * @param  unit         The unit for default, minimum and maximum values.
      * @return The parameter descriptor for the given range of values.
      */
-    private static DefaultParameterDescriptor<Double> create(final String name,
+    static DefaultParameterDescriptor<Double> create(final String name,
             final double defaultValue, final double minimum, final double maximum, final Unit<?> unit)
     {
-        final Map<String,Object> properties = new HashMap<>(4);
-        assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY, name));
-        assertNull(properties.put(DefaultParameterDescriptor.LOCALE_KEY, Locale.US));
-        return new DefaultParameterDescriptor<>(properties, Double.class, null,
+        return new DefaultParameterDescriptor<>(properties(name), Double.class, null,
                 Double.isNaN(defaultValue)          ? null : Double.valueOf(defaultValue),
                 minimum == Double.NEGATIVE_INFINITY ? null : Double.valueOf(minimum),
                 maximum == Double.POSITIVE_INFINITY ? null : Double.valueOf(maximum), unit, true);
     }
 
     /**
+     * Creates a descriptor for a parameter restricted to a set of valid values.
+     * This is typically (but not necessarily) a code list parameter.
+     *
+     * @param  name         The parameter name.
+     * @param  type         The type of values.
+     * @param  validValues  The valid values.
+     * @param  defaultValue The default value for the parameter.
+     * @return The parameter descriptor for the given range of values.
+     */
+    static <T> DefaultParameterDescriptor<T> create(final String name, final Class<T> type,
+            final T[] validValues, final T defaultValue)
+    {
+        return new DefaultParameterDescriptor<>(properties(name), type, validValues, defaultValue, null, null, null, true);
+    }
+
+    /**
+     * Tests the creation of a simple descriptor for an optional parameter without minimum or maximum value.
+     */
+    @Test
+    public void testOptionalInteger() {
+        final ParameterDescriptor<Integer> descriptor = createSimpleOptional("Simple param", Integer.class);
+        assertEquals("name",      "Simple param", descriptor.getName().getCode());
+        assertEquals("valueClass", Integer.class, descriptor.getValueClass());
+        assertNull  ("validValues",               descriptor.getValidValues());
+        assertNull  ("defaultValue",              descriptor.getDefaultValue());
+        assertNull  ("minimumValue",              descriptor.getMinimumValue());
+        assertNull  ("maximumValue",              descriptor.getMaximumValue());
+        assertEquals("minimumOccurs", 0,          descriptor.getMinimumOccurs());
+        assertEquals("maximumOccurs", 1,          descriptor.getMaximumOccurs());
+    }
+
+    /**
      * Tests {@code DefaultParameterDescriptor} constructor
      * with valid and invalid minimum and maximum values.
      */
     @Test
+    @DependsOnMethod("testOptionalInteger")
     public void testRangeValidation() {
         try {
             create("Test range", 12, 20, 4);
@@ -110,7 +161,9 @@ public final strictfp class DefaultParam
             assertEquals("Range [20 … 4] is not valid.", exception.getMessage());
         }
         final ParameterDescriptor<Integer> descriptor = create("Test range", 12, 4, 20);
-        assertEquals("name", "Test range", descriptor.getName().getCode());
+        assertEquals("name",          "Test range",        descriptor.getName().getCode());
+        assertEquals("valueClass",    Integer.class,       descriptor.getValueClass());
+        assertNull  ("validValues",                        descriptor.getValidValues());
         assertEquals("defaultValue",  Integer.valueOf(12), descriptor.getDefaultValue());
         assertEquals("minimumValue",  Integer.valueOf( 4), descriptor.getMinimumValue());
         assertEquals("maximumValue",  Integer.valueOf(20), descriptor.getMaximumValue());
@@ -138,15 +191,15 @@ public final strictfp class DefaultParam
      */
     @Test
     public void testDoubleType() {
-        final ParameterDescriptor<Double> descriptor = create("Test", 12, 4, 20, METRE);
-        assertEquals("name",         "Test",             descriptor.getName().getCode());
+        final ParameterDescriptor<Double> descriptor = create("Length measure", 12, 4, 20, METRE);
+        assertEquals("name",         "Length measure",   descriptor.getName().getCode());
         assertEquals("unit",         METRE,              descriptor.getUnit());
         assertEquals("class",        Double.class,       descriptor.getValueClass());
         assertEquals("defaultValue", Double.valueOf(12), descriptor.getDefaultValue());
         assertEquals("minimum",      Double.valueOf( 4), descriptor.getMinimumValue());
         assertEquals("maximum",      Double.valueOf(20), descriptor.getMaximumValue());
         validate(descriptor);
-        assertEquals("DefaultParameterDescriptor[\"Test\", mandatory, class=Double, " +
+        assertEquals("DefaultParameterDescriptor[\"Length measure\", mandatory, class=Double, " +
                 "valid=[4.0 … 20.0], default=12.0, unit=m]", descriptor.toString());
 
         testDoubleValue(new DefaultParameterValue<>(descriptor));
@@ -175,13 +228,13 @@ public final strictfp class DefaultParam
             parameter.setValue(3.0);
             fail("setValue(< min)");
         } catch (InvalidParameterValueException exception) {
-            assertEquals("Test", exception.getParameterName());
+            assertEquals("Length measure", exception.getParameterName());
         }
         try {
             parameter.setValue("12");
             fail("setValue(Sring)");
         } catch (InvalidParameterValueException exception) {
-            assertEquals("Test", exception.getParameterName());
+            assertEquals("Length measure", exception.getParameterName());
         }
         for (int i=400; i<=2000; i+=100) {
             parameter.setValue(i, CENTIMETRE);
@@ -190,4 +243,58 @@ public final strictfp class DefaultParam
             assertEquals("value", i/100,             parameter.doubleValue(METRE), EPS);
         }
     }
+
+    /**
+     * Verifies that we can not assign unit of measurements to non-numerical values.
+     */
+    @Test
+    public void testStringType() {
+        final ParameterDescriptor<String> descriptor = new DefaultParameterDescriptor<>(
+                properties("String param"), String.class, null, "ABC", "AAA", "BBB", null, false);
+        assertEquals("name", "String param",     descriptor.getName().getCode());
+        assertEquals("valueClass", String.class, descriptor.getValueClass());
+        assertNull  ("validValues",              descriptor.getValidValues());
+        assertEquals("defaultValue",  "ABC",     descriptor.getDefaultValue());
+        assertEquals("minimumValue",  "AAA",     descriptor.getMinimumValue());
+        assertEquals("maximumValue",  "BBB",     descriptor.getMaximumValue());
+        assertEquals("minimumOccurs", 0,         descriptor.getMinimumOccurs());
+        assertEquals("maximumOccurs", 1,         descriptor.getMaximumOccurs());
+        /*
+         * Same construction than above, except that we specify a unit of measurement.
+         * This operation shall be invalid for non-numerical types.
+         */
+        try {
+            new DefaultParameterDescriptor<>(properties("Invalid param"),
+                     String.class, null, "ABC", "AAA", "BBB", METRE, false);
+        } catch (IllegalArgumentException e) {
+            assertEquals("Unit of measurement “m” is not valid for “Invalid param” values.", e.getMessage());
+        }
+    }
+
+    /**
+     * Tests a descriptor for a parameter restricted to some values.
+     * This is typically (but not necessarily) a code list parameter.
+     */
+    @Test
+    public void testEnumeration() {
+        final String[] enumeration = {"Apple", "Orange", "りんご"};
+        final ParameterDescriptor<String> descriptor = create(
+                "Enumeration param", String.class, enumeration, "Apple");
+        assertEquals     ("name", "Enumeration param", descriptor.getName().getCode());
+        assertEquals     ("valueClass", String.class,  descriptor.getValueClass());
+        assertArrayEquals("validValues", enumeration,  descriptor.getValidValues().toArray());
+        assertEquals     ("defaultValue",  "Apple",    descriptor.getDefaultValue());
+        assertNull       ("minimumValue",              descriptor.getMinimumValue());
+        assertNull       ("maximumValue",              descriptor.getMaximumValue());
+        assertEquals     ("minimumOccurs", 1,          descriptor.getMinimumOccurs());
+        assertEquals     ("maximumOccurs", 1,          descriptor.getMaximumOccurs());
+        /*
+         * Invalid operation: element not in the list of valid elements.
+         */
+        try {
+            create("Enumeration param", String.class, enumeration, "Pear");
+        } catch (IllegalArgumentException e) {
+            assertEquals("Parameter “Enumeration param” can not take the “Pear” value.", e.getMessage());
+        }
+    }
 }

Added: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java?rev=1566470&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java (added)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java [UTF-8] Sun Feb  9 23:23:01 2014
@@ -0,0 +1,472 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.parameter;
+
+import javax.measure.unit.SI;
+import javax.measure.unit.NonSI;
+import javax.measure.unit.Unit;
+import org.opengis.referencing.cs.AxisDirection;
+import org.opengis.referencing.datum.VerticalDatumType;
+import org.opengis.parameter.ParameterValue;
+import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.parameter.InvalidParameterTypeException;
+import org.opengis.parameter.InvalidParameterValueException;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static java.lang.StrictMath.*;
+import static org.apache.sis.test.Assert.*;
+import static org.opengis.test.Validators.*;
+
+
+/**
+ * Tests the {@link DefaultParameterValue} class.
+ *
+ * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @since   0.4 (derived from geotk-2.1)
+ * @version 0.4
+ * @module
+ */
+@DependsOn(DefaultParameterDescriptorTest.class)
+public final strictfp class DefaultParameterValueTest extends TestCase {
+    /**
+     * Strict tolerance factor for floating point comparisons. In the particular
+     * case of this test suite, we can afford to be strict since we will perform
+     * arithmetic only on integer values.
+     */
+    private static final double STRICT = 0.0;
+
+    /**
+     * Small tolerance factor for floating point comparisons resulting from some calculation.
+     */
+    private static final double EPS = 1E-10;
+
+    /**
+     * Constructs an optional parameter initialized to the given value.
+     * The descriptor has no default value, no minimum and no maximum.
+     *
+     * @param  name  The parameter name.
+     * @param  value The parameter value.
+     * @return A new parameter instance for the given name and value.
+     */
+    private static DefaultParameterValue<Integer> createOptional(final String name, final int value) {
+        final DefaultParameterValue<Integer> parameter = new DefaultParameterValue<>(
+                DefaultParameterDescriptorTest.createSimpleOptional(name, Integer.class));
+        parameter.setValue(value, null);
+        return parameter;
+    }
+
+    /**
+     * Constructs a mandatory parameter initialize to the given value and unit.
+     *
+     * @param name  The parameter name.
+     * @param value The parameter value.
+     * @param unit  The unit for the parameter value.
+     * @return A new parameter instance for the given name and value.
+     */
+    private static DefaultParameterValue<Double> create(final String name, final double value, final Unit<?> unit) {
+        final ParameterDescriptor<Double> descriptor = DefaultParameterDescriptorTest.create(
+                name, Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, unit);
+        final DefaultParameterValue<Double> parameter = new DefaultParameterValue<>(descriptor);
+        parameter.setValue(value, unit);
+        return parameter;
+    }
+
+    /**
+     * Tests a parameter for an integer value.
+     * First this method verifies the properties of the newly created instance, then attempts some
+     * invalid operations on it. We test that the invalid operations throw the expected exceptions.
+     */
+    @Test
+    public void testIntegerType() {
+        final ParameterValue<Integer> parameter = createOptional("Integer param", 14);
+        final ParameterDescriptor<Integer> descriptor = parameter.getDescriptor();
+        validate(parameter);
+
+        assertEquals("name",        "Integer param",     descriptor.getName().getCode());
+        assertEquals("type",        Integer.class,       descriptor.getValueClass());
+        assertNull  ("defaultUnit",                      descriptor.getUnit());
+        assertNull  ("unit",                             parameter .getUnit());
+        assertNull  ("defaultValue",                     descriptor.getDefaultValue());
+        assertEquals("value",       Integer.valueOf(14), parameter .getValue());
+        assertEquals("intValue",    14,                  parameter .intValue());
+        assertEquals("doubleValue", 14,                  parameter .doubleValue(), STRICT);
+        assertNull  ("minimum",                          descriptor.getMinimumValue());
+        assertNull  ("maximum",                          descriptor.getMaximumValue());
+        assertNull  ("validValues",                      descriptor.getValidValues());
+        /*
+         * Invalid operation: this parameter does not have unit of measurement.
+         */
+        try {
+            parameter.doubleValue(SI.METRE);
+            fail("doubleValue(METRE)");
+        } catch (IllegalStateException exception) {
+            final String message = exception.getMessage();
+            assertTrue(message, message.contains("Integer param"));
+        }
+        /*
+         * Invalid operation: this parameter is an integer, not a string.
+         * While we could convert the integer to a string, in the context
+         * of map projection parameters this is usually an error.
+         */
+        try {
+            parameter.stringValue();
+            fail("stringValue()");
+        } catch (InvalidParameterTypeException exception) {
+            final String message = exception.getMessage();
+            assertTrue(message, message.contains("Integer"));
+            assertEquals("Integer param", exception.getParameterName());
+        }
+        /*
+         * Set values. In the case of null value, since this parameter is optional
+         * the value should stay null (not substituted by the default value).
+         */
+        parameter.setValue(-15);
+        assertEquals(Integer.valueOf(-15), parameter.getValue());
+        parameter.setValue(null);
+        assertNull(parameter.getValue());
+        validate(parameter);
+    }
+
+    /**
+     * Creates a parameter bounded by some range of integer numbers, and tests values
+     * inside and outside that range. Tests also the usage of values of the wrong type.
+     */
+    @Test
+    @DependsOnMethod("testIntegerType")
+    public void testBoundedInteger() {
+        final DefaultParameterValue<Integer> parameter = new DefaultParameterValue<>(
+                DefaultParameterDescriptorTest.create("Bounded param", 15, -30, +40));
+        assertEquals(Integer.class, parameter.getDescriptor().getValueClass());
+        assertEquals(      "value", Integer.valueOf(15), parameter.getValue());
+        assertEquals(   "intValue", 15, parameter.intValue());
+        assertEquals("doubleValue", 15, parameter.doubleValue(), STRICT);
+        validate(parameter);
+        /*
+         * Set a value inside the range of valid values.
+         */
+        parameter.setValue(12);
+        assertEquals(      "value", Integer.valueOf(12), parameter.getValue());
+        assertEquals(   "intValue", 12, parameter.intValue());
+        assertEquals("doubleValue", 12, parameter.doubleValue(), STRICT);
+        validate(parameter);
+        /*
+         * Invalid operations: attempt to set values out of range.
+         */
+        try {
+            parameter.setValue(50);
+            fail("setValue(> max)");
+        } catch (InvalidParameterValueException exception) {
+            final String message = exception.getMessage();
+            assertTrue(message, message.contains("Bounded param"));
+            assertEquals("Bounded param", exception.getParameterName());
+        }
+        try {
+            parameter.setValue(-40);
+            fail("setValue(< min)");
+        } catch (InvalidParameterValueException exception) {
+            final String message = exception.getMessage();
+            assertTrue(message, message.contains("Bounded param"));
+            assertEquals("Bounded param", exception.getParameterName());
+        }
+        /*
+         * Invalid operation: attempt to set a floating point value.
+         */
+        try {
+            parameter.setValue(10.5);
+            fail("setValue(double)");
+        } catch (InvalidParameterValueException exception) {
+            final String message = exception.getMessage();
+            assertTrue(message, message.contains("Integer"));
+            assertEquals("Bounded param", exception.getParameterName());
+        }
+        /*
+         * Try again to set a floating point value, but this time
+         * the value can be converted to an integer.
+         */
+        parameter.setValue(10.0);
+        assertEquals(      "value", Integer.valueOf(10), parameter.getValue());
+        assertEquals(   "intValue", 10, parameter.intValue());
+        assertEquals("doubleValue", 10, parameter.doubleValue(), STRICT);
+        validate(parameter);
+        /*
+         * Invalid operation: set the same value than above, but with a unit of measurement.
+         * This shall be an invalid operation since we created a unitless parameter.
+         */
+        try {
+            parameter.setValue(10.0, SI.METRE);
+            fail("setValue(double,Unit)");
+        } catch (InvalidParameterValueException exception) {
+            final String message = exception.getMessage();
+            assertTrue(message, message.contains("Bounded param"));
+            assertEquals("Bounded param", exception.getParameterName());
+        }
+    }
+
+    /**
+     * Tests a parameter for a floating point value with a unit of measurement.
+     */
+    @Test
+    public void testDoubleType() {
+        final DefaultParameterValue<Double> parameter = create("Numerical param", 3, SI.METRE);
+        final ParameterDescriptor<Double> descriptor = parameter.getDescriptor();
+        validate(parameter);
+
+        assertEquals("name",        "Numerical param", descriptor.getName().getCode());
+        assertEquals("defaultUnit", SI.METRE,          descriptor.getUnit());
+        assertEquals("unit",        SI.METRE,          parameter .getUnit());
+        assertNull  ("defaultValue",                   descriptor.getDefaultValue());
+        assertEquals("value",       Double.valueOf(3), parameter .getValue());
+        assertEquals("intValue",      3,               parameter .intValue());
+        assertEquals("doubleValue",   3,               parameter .doubleValue(), STRICT);
+        assertEquals("doubleValue", 300,               parameter .doubleValue(SI.CENTIMETRE), STRICT);
+        assertNull  ("minimum",                        descriptor.getMinimumValue());
+        assertNull  ("maximum",                        descriptor.getMaximumValue());
+        assertNull  ("validValues",                    descriptor.getValidValues());
+        /*
+         * Invalid operation: this parameter is a real number, not a string.
+         * While we could convert the number to a string, in the context of
+         * map projection parameters this is usually an error.
+         */
+        try {
+            parameter.stringValue();
+            fail("stringValue()");
+        } catch (InvalidParameterTypeException exception) {
+            final String message = exception.getMessage();
+            assertTrue(message, message.contains("Double"));
+            assertEquals("Numerical param", exception.getParameterName());
+        }
+        /*
+         * Sets a value in centimetres.
+         */
+        parameter.setValue(400, SI.CENTIMETRE);
+        assertEquals("unit",        SI.CENTIMETRE, parameter.getUnit());
+        assertEquals("doubleValue", 400, parameter.doubleValue(),              STRICT);
+        assertEquals("doubleValue", 400, parameter.doubleValue(SI.CENTIMETRE), STRICT);
+        assertEquals("doubleValue",   4, parameter.doubleValue(SI.METRE),      STRICT);
+        validate(parameter);
+    }
+
+    /**
+     * Creates a parameter bounded by some range of floating point numbers, and tests values
+     * inside and outside that range. Tests also the usage of values of the wrong type.
+     */
+    @Test
+    @DependsOnMethod("testDoubleType")
+    public void testBoundedDouble() {
+        final DefaultParameterValue<Double> parameter = new DefaultParameterValue<>(
+                DefaultParameterDescriptorTest.create("Bounded param", 15.0, -30.0, +40.0, null));
+        assertEquals(Double.class, parameter.getDescriptor().getValueClass());
+        assertEquals(      "value", Double.valueOf(15), parameter.getValue());
+        assertEquals(   "intValue", 15, parameter.intValue());
+        assertEquals("doubleValue", 15, parameter.doubleValue(), STRICT);
+        validate(parameter);
+
+        parameter.setValue(12.0);
+        assertEquals(      "value", Double.valueOf(12), parameter.getValue());
+        assertEquals(   "intValue", 12, parameter.intValue());
+        assertEquals("doubleValue", 12, parameter.doubleValue(), STRICT);
+        validate(parameter);
+
+        try {
+            parameter.setValue(50.0);
+            fail("setValue(> max)");
+        } catch (InvalidParameterValueException exception) {
+            // This is the expected exception.
+            assertEquals("Bounded param", exception.getParameterName());
+        }
+        try {
+            parameter.setValue(-40.0);
+            fail("setValue(< min)");
+        } catch (InvalidParameterValueException exception) {
+            // This is the expected exception.
+            assertEquals("Bounded param", exception.getParameterName());
+        }
+        try {
+            parameter.setValue("12");
+            fail("setValue(String)");
+        } catch (InvalidParameterValueException exception) {
+            final String message = exception.getMessage();
+            assertTrue(message, message.contains("Bounded param"));
+            assertEquals("Bounded param", exception.getParameterName());
+        }
+    }
+
+    /**
+     * Tests a parameter for a code list.
+     */
+    @Test
+    public void testCodeList() {
+        final AxisDirection[] directions = {
+            AxisDirection.NORTH,
+            AxisDirection.SOUTH,
+            AxisDirection.DISPLAY_LEFT,
+            AxisDirection.PAST
+        };
+        final ParameterDescriptor<AxisDirection> descriptor = DefaultParameterDescriptorTest.create(
+                "Direction", AxisDirection.class, directions, AxisDirection.NORTH);
+        final DefaultParameterValue<AxisDirection> parameter = new DefaultParameterValue<>(descriptor);
+        validate(parameter);
+
+        assertEquals     ("name",         "Direction",         descriptor.getName().getCode());
+        assertEquals     ("defaultValue", AxisDirection.NORTH, descriptor.getDefaultValue());
+        assertEquals     ("value",        AxisDirection.NORTH, parameter .getValue());
+        assertNull       ("defaultUnit",                       descriptor.getUnit());
+        assertNull       ("unit",                              parameter .getUnit());
+        assertNull       ("minimum",                           descriptor.getMinimumValue());
+        assertNull       ("maximum",                           descriptor.getMaximumValue());
+        assertArrayEquals("validValues", directions,           descriptor.getValidValues().toArray());
+        /*
+         * Invalid operation: attempt to get the value as a 'double' is not allowed.
+         */
+        try {
+            parameter.doubleValue();
+            fail("doubleValue shall not be allowed on AxisDirection");
+        } catch (InvalidParameterTypeException exception) {
+            final String message = exception.getMessage();
+            assertTrue(message, message.contains("AxisDirection"));
+            assertEquals("Direction", exception.getParameterName());
+        }
+        /*
+         * Set a valid value.
+         */
+        parameter.setValue(AxisDirection.PAST);
+        assertEquals("value", AxisDirection.PAST, parameter.getValue());
+        /*
+         * Invalid operation: set a value of valid type but not in the list of valid values.
+         */
+        try {
+            parameter.setValue(AxisDirection.GEOCENTRIC_X);
+            fail("setValue(AxisDirection.UP)");
+        } catch (InvalidParameterValueException exception) {
+            final String message = exception.getMessage();
+            assertTrue(message, message.contains("Direction"));
+            assertTrue(message, message.contains("Geocentric X"));
+            assertEquals("Direction", exception.getParameterName());
+        }
+        /*
+         * Invalid operation: attempt to set a value of wrong type.
+         */
+        try {
+            parameter.setValue(VerticalDatumType.BAROMETRIC);
+            fail("setValue(VerticalDatumType)");
+        } catch (InvalidParameterValueException exception) {
+            final String message = exception.getMessage();
+            assertTrue(message, message.contains("Direction"));
+            assertTrue(message, message.contains("VerticalDatumType"));
+            assertTrue(message, message.contains("AxisDirection"));
+            assertEquals("Direction", exception.getParameterName());
+        }
+    }
+
+    /**
+     * Tests the creation of many parameters for integer and floating point values.
+     * Some on those values are cached (e.g. 0, 90, 360) because frequently used.
+     * It should be transparent to the user.
+     * Test also unit conversions (degrees to radians in this case).
+     *
+     * @todo Tests parallel instantiation on JDK8.
+     */
+    @Test
+    @DependsOnMethod({"testBoundedInteger", "testBoundedDouble"})
+    public void testMany() {
+        DefaultParameterValue<? extends Number> p;
+        ParameterDescriptor<? extends Number> d;
+        for (int i=-500; i<=500; i++) {
+            p = createOptional("Unitlesss integer value", i);
+            d = p.getDescriptor();
+            validate(p);
+
+            assertNotNull("Expected a descriptor.",       d);
+            assertNull   ("Expected no default value.",   d.getDefaultValue());
+            assertNull   ("Expected no minimal value.",   d.getMinimumValue());
+            assertNull   ("Expected no maximal value.",   d.getMaximumValue());
+            assertNull   ("Expected no enumeration.",     d.getValidValues());
+            assertEquals ("Expected integer type.",       Integer.class, d.getValueClass());
+            assertTrue   ("Expected integer type.",       p.getValue() instanceof Integer);
+            assertNull   ("Expected unitless parameter.", p.getUnit());
+            assertEquals ("Expected integer value", i,    p.intValue());
+            assertEquals ("Expected integer value", i,    p.doubleValue(), STRICT);
+
+            p = create("Unitlesss double value", i, null);
+            d = p.getDescriptor();
+            validate(p);
+
+            assertNotNull("Expected a descriptor.",       d);
+            assertNull   ("Expected no default value.",   d.getDefaultValue());
+            assertNull   ("Expected no minimal value.",   d.getMinimumValue());
+            assertNull   ("Expected no maximal value.",   d.getMaximumValue());
+            assertNull   ("Expected no enumeration.",     d.getValidValues());
+            assertEquals ("Expected double type.",        Double.class, d.getValueClass());
+            assertTrue   ("Expected double type.",        p.getValue() instanceof Double);
+            assertNull   ("Expected unitless parameter.", p.getUnit());
+            assertEquals ("Expected integer value", i,    p.intValue());
+            assertEquals ("Expected integer value", i,    p.doubleValue(), STRICT);
+
+            p = create("Dimensionless double value", i, Unit.ONE);
+            d = p.getDescriptor();
+            validate(p);
+
+            assertNotNull("Expected a descriptor.",       d);
+            assertNull   ("Expected no default value.",   d.getDefaultValue());
+            assertNull   ("Expected no minimal value.",   d.getMinimumValue());
+            assertNull   ("Expected no maximal value.",   d.getMaximumValue());
+            assertNull   ("Expected no enumeration.",     d.getValidValues());
+            assertEquals ("Expected double type.",        Double.class, d.getValueClass());
+            assertTrue   ("Expected double type.",        p.getValue() instanceof Double);
+            assertEquals ("Expected dimensionless.",      Unit.ONE, p.getUnit());
+            assertEquals ("Expected integer value", i,    p.intValue());
+            assertEquals ("Expected integer value", i,    p.doubleValue(), STRICT);
+
+            p = create("Angular double value", i, NonSI.DEGREE_ANGLE);
+            d = p.getDescriptor();
+            validate(p);
+
+            assertNotNull("Expected a descriptor.",       d);
+            assertNull   ("Expected no default value.",   d.getDefaultValue());
+            assertNull   ("Expected no minimal value.",   d.getMinimumValue());
+            assertNull   ("Expected no maximal value.",   d.getMaximumValue());
+            assertNull   ("Expected no enumeration.",     d.getValidValues());
+            assertEquals ("Expected double type.",        Double.class, d.getValueClass());
+            assertTrue   ("Expected double type.",        p.getValue() instanceof Double);
+            assertEquals ("Expected angular unit.",       NonSI.DEGREE_ANGLE, p.getUnit());
+            assertEquals ("Expected integer value", i,    p.intValue());
+            assertEquals ("Expected integer value", i,    p.doubleValue(), STRICT);
+            assertEquals ("Expected unit conversion.", toRadians(i), p.doubleValue(SI.RADIAN), EPS);
+        }
+    }
+
+    /**
+     * Tests clone.
+     */
+    @Test
+    public void testClone() {
+        final DefaultParameterValue<Double> parameter = create("Clone test", 3, SI.METRE);
+        assertEquals("equals(clone)", parameter, parameter.clone());
+    }
+
+    /**
+     * Tests serialization.
+     */
+    @Test
+    public void testSerialization() {
+        final DefaultParameterValue<Double> parameter = create("Serialization test", 3, SI.METRE);
+        assertNotSame(parameter, assertSerializedEquals(parameter));
+    }
+}

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java?rev=1566470&r1=1566469&r2=1566470&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java [UTF-8] Sun Feb  9 23:23:01 2014
@@ -119,6 +119,9 @@ public final strictfp class AbstractIden
         } catch (IllegalArgumentException e) {
             assertEquals("Missing value for “code” property.", e.getMessage());
         }
+        // "code" with String value is accepted as well.
+        assertNull(properties.put("code", "Test"));
+        assertEquals("Test", new AbstractIdentifiedObject(properties).getName().getCode());
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1566470&r1=1566469&r2=1566470&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java [UTF-8] Sun Feb  9 23:23:01 2014
@@ -51,6 +51,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.AbstractIdentifiedObjectTest.class,
     org.apache.sis.referencing.AbstractReferenceSystemTest.class,
     org.apache.sis.parameter.DefaultParameterDescriptorTest.class,
+    org.apache.sis.parameter.DefaultParameterValueTest.class,
     org.apache.sis.referencing.datum.BursaWolfParametersTest.class,
     org.apache.sis.referencing.datum.TimeDependentBWPTest.class,
     org.apache.sis.referencing.datum.DefaultEllipsoidTest.class,

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1566470&r1=1566469&r2=1566470&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] Sun Feb  9 23:23:01 2014
@@ -272,7 +272,7 @@ public final class Errors extends Indexe
         public static final short IllegalOrdinateRange_3 = 39;
 
         /**
-         * Parameter ‘{0}’ can’t be of type ‘{1}’.
+         * Parameter “{0}” can not be of type ‘{1}’.
          */
         public static final short IllegalParameterType_2 = 143;
 
@@ -283,6 +283,11 @@ public final class Errors extends Indexe
         public static final short IllegalParameterValueClass_3 = 138;
 
         /**
+         * Parameter “{0}” can not take the “{1}” value.
+         */
+        public static final short IllegalParameterValue_2 = 144;
+
+        /**
          * Property “{0}” does not accept instances of ‘{1}’.
          */
         public static final short IllegalPropertyClass_2 = 40;

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1566470&r1=1566469&r2=1566470&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] Sun Feb  9 23:23:01 2014
@@ -64,7 +64,8 @@ IllegalMemberType_2               = Memb
 IllegalOperationForValueClass_1   = This operation can not be applied to values of class \u2018{0}\u2019.
 IllegalOptionValue_2              = Option \u2018{0}\u2019 can not take the \u201c{1}\u201d value.
 IllegalOrdinateRange_3            = The [{0} \u2026 {1}] range of ordinate values is not valid for the \u201c{2}\u201d axis.
-IllegalParameterType_2            = Parameter \u2018{0}\u2019 can\u2019t be of type \u2018{1}\u2019.
+IllegalParameterType_2            = Parameter \u201c{0}\u201d can not be of type \u2018{1}\u2019.
+IllegalParameterValue_2           = Parameter \u201c{0}\u201d can not take the \u201c{1}\u201d value.
 IllegalParameterValueClass_3      = Parameter \u201c{0}\u201d does not accept values of \u2018{2}\u2019 type. Expected an instance of \u2018{1}\u2019 or derived type.
 IllegalPropertyClass_2            = Property \u201c{0}\u201d does not accept instances of \u2018{1}\u2019.
 IllegalRange_2                    = Range [{0} \u2026 {1}] is not valid.

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1566470&r1=1566469&r2=1566470&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] Sun Feb  9 23:23:01 2014
@@ -54,7 +54,8 @@ IllegalMemberType_2               = Le m
 IllegalOperationForValueClass_1   = Cette op\u00e9ration ne peut pas s\u2019appliquer aux valeurs de classe \u2018{0}\u2019.
 IllegalOptionValue_2              = L\u2019option \u2018{0}\u2019 n\u2019accepte pas la valeur \u00ab\u202f{1}\u202f\u00bb.
 IllegalOrdinateRange_3            = La plage de valeurs de coordonn\u00e9es [{0} \u2026 {1}] n\u2019est pas valide pour l\u2019axe \u00ab\u202f{2}\u202f\u00bb.
-IllegalParameterType_2            = Le param\u00e8tre \u2018{0}\u2019 ne peut pas \u00eatre du type \u2018{1}\u2019.
+IllegalParameterType_2            = Le param\u00e8tre \u00ab\u202f{0}\u202f\u00bb ne peut pas \u00eatre du type \u2018{1}\u2019.
+IllegalParameterValue_2           = Le param\u00e8tre \u00ab\u202f{0}\u202f\u00bb n\u2019accepte pas la valeur \u00ab\u202f{1}\u202f\u00bb.
 IllegalParameterValueClass_3      = Le param\u00e8tre \u00ab\u202f{0}\u202f\u00bb n\u2019accepte pas les valeurs de type \u2018{2}\u2019. Une instance de \u2018{1}\u2019 ou d\u2019un type d\u00e9riv\u00e9 \u00e9tait attendue.
 IllegalPropertyClass_2            = La propri\u00e9t\u00e9 \u00ab\u202f{0}\u202f\u00bb n\u2019accepte pas les valeurs de type \u2018{1}\u2019.
 IllegalRange_2                    = La plage [{0} \u2026 {1}] n\u2019est pas valide.



Mime
View raw message