sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1700843 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/jaxb/referencing/ main/java/org/apache/sis/parameter/ main/java/org/apache/sis/referencing/operation/ test/java/org/apache/sis/internal/jaxb/refere...
Date Wed, 02 Sep 2015 15:37:40 GMT
Author: desruisseaux
Date: Wed Sep  2 15:37:39 2015
New Revision: 1700843

URL: http://svn.apache.org/r1700843
Log:
Add test for <gml:Conversion> unmarshalling.

Added:
    sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/operation/
    sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/operation/Conversion.xml
  (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Parameters.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java?rev=1700843&r1=1700842&r2=1700843&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java
[UTF-8] Wed Sep  2 15:37:39 2015
@@ -17,12 +17,17 @@
 package org.apache.sis.internal.jaxb.referencing;
 
 import java.util.Map;
+import java.util.Collection;
 import java.util.Collections;
 import javax.xml.bind.annotation.XmlElement;
+import javax.measure.unit.Unit;
 import org.opengis.util.FactoryException;
 import org.opengis.metadata.Identifier;
 import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.parameter.GeneralParameterDescriptor;
+import org.opengis.parameter.ParameterValue;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.CoordinateOperationFactory;
@@ -30,6 +35,8 @@ import org.apache.sis.internal.jaxb.Cont
 import org.apache.sis.internal.jaxb.gco.PropertyType;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.referencing.provider.MapProjection;
+import org.apache.sis.parameter.DefaultParameterValue;
+import org.apache.sis.parameter.DefaultParameterValueGroup;
 import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
 import org.apache.sis.referencing.operation.DefaultOperationMethod;
 import org.apache.sis.referencing.IdentifiedObjects;
@@ -186,4 +193,50 @@ public final class CC_OperationMethod ex
         }
         return new DefaultParameterDescriptorGroup(properties, 1, 1, descriptors);
     }
+
+    /**
+     * Stores the given {@code parameters} into the given {@code addTo} collection.
+     * This method copies only the <em>references</em> if possible. However is
some
+     * cases the values may need to be copied in new parameter instances.
+     *
+     * <div class="note"><b>Note:</b>
+     * this code is defined in this {@code CC_OperationMethod} class instead than in the
+     * {@link DefaultOperationMethod} class in the hope to reduce the amount of code processed
+     * by the JVM in the common case where JAXB (un)marshalling is not needed.</div>
+     *
+     * @param parameters   The parameters to add to the {@code addTo} collection.
+     * @param addTo        Where to store the {@code parameters}.
+     * @param replacements The replacements to apply in the {@code GeneralParameterValue}
instances.
+     */
+    public static void store(final GeneralParameterValue[] parameters,
+                             final Collection<GeneralParameterValue> addTo,
+                             final Map<GeneralParameterDescriptor,GeneralParameterDescriptor>
replacements)
+    {
+        for (GeneralParameterValue p : parameters) {
+            final GeneralParameterDescriptor replacement = replacements.get(p.getDescriptor());
+            if (replacement != null) {
+                if (p instanceof ParameterValue<?>) {
+                    final ParameterValue<?> source = (ParameterValue<?>) p;
+                    final ParameterValue<?> target = new DefaultParameterValue<>((ParameterDescriptor<?>)
replacement);
+                    final Object value = source.getValue();
+                    final Unit<?> unit = source.getUnit();
+                    if (unit == null) {
+                        target.setValue(value);
+                    } else if (value instanceof double[]) {
+                        target.setValue((double[]) value, unit);
+                    } else {
+                        target.setValue(((Number) value).doubleValue(), unit);
+                    }
+                    p = target;
+                } else if (p instanceof ParameterValueGroup) {
+                    final ParameterValueGroup source = (ParameterValueGroup) p;
+                    final ParameterValueGroup target = new DefaultParameterValueGroup((ParameterDescriptorGroup)
replacement);
+                    final Collection<GeneralParameterValue> values = source.values();
+                    store(values.toArray(new GeneralParameterValue[values.size()]), target.values(),
replacements);
+                    p = target;
+                }
+            }
+            addTo.add(p);
+        }
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java?rev=1700843&r1=1700842&r2=1700843&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
[UTF-8] Wed Sep  2 15:37:39 2015
@@ -526,16 +526,10 @@ public class DefaultParameterValueGroup
      * {@link org.apache.sis.internal.jaxb.referencing.CC_GeneralOperationParameter} for
logging purpose.</p>
      */
     private void setValues(final GeneralParameterValue[] parameters) {
-        final GeneralParameterDescriptor[] fromValues = new GeneralParameterDescriptor[parameters.length];
-        for (int i=0; i<parameters.length; i++) {
-            fromValues[i] = parameters[i].getDescriptor();
-        }
         ParameterValueList addTo = values;
         if (addTo == null) {
             // Should never happen, unless the XML document is invalid and does not have
a 'group' element.
             addTo = new ParameterValueList(new DefaultParameterDescriptorGroup());
-        } else {
-            addTo.clear();  // Because references to parameter descriptors have changed.
         }
         /*
          * Merge the descriptors declared in the <gml:group> element with the descriptors
given in each
@@ -543,8 +537,9 @@ public class DefaultParameterValueGroup
          * because this is the type declared in the JAXBContext and in adapters.
          */
         final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements
= new IdentityHashMap<>(4);
-        ((DefaultParameterDescriptorGroup) addTo.descriptor).merge(fromValues, replacements);
-        addAll(parameters, replacements, addTo);
+        ((DefaultParameterDescriptorGroup) addTo.descriptor).merge(getDescriptors(parameters),
replacements);
+        addTo.clear();  // Because references to parameter descriptors have changed.
+        setValues(parameters, replacements, addTo);
     }
 
     /**
@@ -556,7 +551,7 @@ public class DefaultParameterValueGroup
      * @param addTo        Where to store the new values.
      */
     @SuppressWarnings({"unchecked", "AssignmentToCollectionOrArrayFieldFromParameter"})
-    private void addAll(GeneralParameterValue[] parameters,
+    private void setValues(GeneralParameterValue[] parameters,
             final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements,
             final ParameterValueList addTo)
     {
@@ -569,7 +564,7 @@ public class DefaultParameterValueGroup
                 if (p instanceof DefaultParameterValue<?>) {
                     ((DefaultParameterValue<?>) p).setDescriptor((ParameterDescriptor)
replacement);
                 } else if (p instanceof DefaultParameterValueGroup) {
-                    ((DefaultParameterValueGroup) p).addAll(null, replacements,
+                    ((DefaultParameterValueGroup) p).setValues(null, replacements,
                             new ParameterValueList((ParameterDescriptorGroup) replacement));
                 }
             }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Parameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Parameters.java?rev=1700843&r1=1700842&r2=1700843&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Parameters.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/Parameters.java
[UTF-8] Wed Sep  2 15:37:39 2015
@@ -217,6 +217,35 @@ public abstract class Parameters impleme
     }
 
     /**
+     * Returns the descriptors of the given parameters, in the same order.
+     * Special cases:
+     *
+     * <ul>
+     *   <li>If the given array is {@code null}, then this method returns {@code null}.
+     *   <li>If an element of the given array is {@code null}, then the corresponding
+     *       element of the returned array is also {@code null}.</li>
+     * </ul>
+     *
+     * @param  parameters The parameter values from which to get the descriptors, or {@code
null}.
+     * @return The descriptors of the given parameter values, or {@code null} if the {@code
parameters} argument was null.
+     *
+     * @since 0.6
+     */
+    public static GeneralParameterDescriptor[] getDescriptors(final GeneralParameterValue...
parameters) {
+        if (parameters == null) {
+            return null;
+        }
+        final GeneralParameterDescriptor[] descriptors = new GeneralParameterDescriptor[parameters.length];
+        for (int i=0; i<parameters.length; i++) {
+            final GeneralParameterValue p = parameters[i];
+            if (p != null) {
+                descriptors[i] = p.getDescriptor();
+            }
+        }
+        return descriptors;
+    }
+
+    /**
      * Gets the parameter name as an instance of {@code MemberName}.
      * This method performs the following checks:
      *

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java?rev=1700843&r1=1700842&r2=1700843&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] Wed Sep  2 15:37:39 2015
@@ -18,24 +18,27 @@ package org.apache.sis.referencing.opera
 
 import java.util.Map;
 import java.util.List;
-import java.util.Arrays;
+import java.util.IdentityHashMap;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.ParameterDescriptorGroup;
+import org.opengis.parameter.GeneralParameterDescriptor;
 import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.SingleOperation;
 import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.apache.sis.parameter.Parameters;
 import org.apache.sis.parameter.Parameterized;
 import org.apache.sis.parameter.DefaultParameterValueGroup;
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
 import org.apache.sis.referencing.operation.transform.PassThroughTransform;
+import org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroup;
 import org.apache.sis.internal.jaxb.referencing.CC_OperationMethod;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.internal.metadata.ReferencingServices;
@@ -450,12 +453,38 @@ class AbstractSingleOperation extends Ab
         if (ReferencingUtilities.canSetProperty(DefaultOperationMethod.class,
                 "setParameters", "parameterValue", parameters != null))
         {
-            ParameterDescriptorGroup descriptor = method.getParameters();
-            parameters = new DefaultParameterValueGroup(descriptor);
-            parameters.values().addAll(Arrays.asList(values));
-            if (method instanceof DefaultOperationMethod) {
-                ((DefaultOperationMethod) method).setParameters(parameters.getDescriptor());
+            /*
+             * The descriptors in the <gml:method> element do not know the class of
parameter value
+             * (String, Integer, Double, double[], etc.) because this information is not
part of GML.
+             * But this information is available to descriptors in the <gml:parameterValue>
elements
+             * because Apache SIS infers the type from the actual parameter value. The 'merge'
method
+             * below puts those information together.
+             */
+            final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements
= new IdentityHashMap<>(4);
+            final GeneralParameterDescriptor[] merged = CC_OperationParameterGroup.merge(
+                    method.getParameters().descriptors(),
+                    Parameters.getDescriptors(values),
+                    replacements);
+            /*
+             * Sometime Apache SIS recognizes the OperationMethod as one of its build-in
methods and use the
+             * build-in parameters. In such cases the unmarshalled ParameterDescriptorGroup
can be used as-in.
+             * But if the above 'merge' method has changed any parameter descriptor, then
we will need to create
+             * a new ParameterDescriptorGroup with the new descriptors.
+             */
+            for (int i=0; i<merged.length; i++) {
+                if (merged[i] != values[i].getDescriptor()) {
+                    ((DefaultOperationMethod) method).updateDescriptors(merged);
+                    break;
+                }
             }
+            /*
+             * Sometime the descriptors associated to ParameterValues need to be updated,
for example because
+             * the descriptors in OperationMethod contain more information (remarks, etc.).
Those updates, if
+             * needed, are applied on-the-fly by the copy operation below, using the information
provided by
+             * the 'replacements' map.
+             */
+            parameters = new DefaultParameterValueGroup(method.getParameters());
+            CC_OperationMethod.store(values, parameters.values(), replacements);
         }
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java?rev=1700843&r1=1700842&r2=1700843&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultOperationMethod.java
[UTF-8] Wed Sep  2 15:37:39 2015
@@ -825,10 +825,10 @@ public class DefaultOperationMethod exte
 
     /**
      * Invoked by {@link AbstractSingleOperation} for completing the parameter descriptor.
-     *
-     * @see #getParameters()
      */
-    final void setParameters(final ParameterDescriptorGroup descriptor) {
-        parameters = descriptor;
+    final void updateDescriptors(final GeneralParameterDescriptor[] descriptors) {
+        final ParameterDescriptorGroup previous = parameters;
+        parameters = new DefaultParameterDescriptorGroup(IdentifiedObjects.getProperties(previous),
+                previous.getMinimumOccurs(), previous.getMaximumOccurs(), descriptors);
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java?rev=1700843&r1=1700842&r2=1700843&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
[UTF-8] Wed Sep  2 15:37:39 2015
@@ -200,26 +200,43 @@ public final strictfp class CC_Operation
 
         assertSame("name", group.getName(), group.getName());
         assertEquals("descriptors.size", 2, descriptors.size());
-        verifyMethodParameter((DefaultParameterDescriptor<?>) descriptors.get(0), (DefaultParameterDescriptor<?>)
Mercator1SP.LATITUDE_OF_ORIGIN, REMARK);
-        verifyMethodParameter((DefaultParameterDescriptor<?>) descriptors.get(1), (DefaultParameterDescriptor<?>)
Mercator1SP.LONGITUDE_OF_ORIGIN, null);
+        verifyMethodParameter(Mercator1SP.LATITUDE_OF_ORIGIN, REMARK, (ParameterDescriptor<?>)
descriptors.get(0));
+        verifyMethodParameter(Mercator1SP.LONGITUDE_OF_ORIGIN,  null, (ParameterDescriptor<?>)
descriptors.get(1));
     }
 
     /**
      * Verifies the properties of an operation method parameter.
+     *
+     * @param expected A parameter descriptor containing the expected properties (except
remarks).
+     * @param actual   The parameter descriptor to verify.
      */
-    private static void verifyMethodParameter(final DefaultParameterDescriptor<?> actual,
-                                              final DefaultParameterDescriptor<?> expected,
-                                              final String remarks)
+    public static void verifyMethodParameter(final ParameterDescriptor<?> expected,
+                                             final ParameterDescriptor<?> actual)
     {
-        assertSame  ("name",          expected.getName(),         actual.getName());
-        assertSame  ("description",   expected.getDescription(),  actual.getDescription());
+        assertEquals("name",          expected.getName(),         actual.getName());
+        assertEquals("description",   expected.getDescription(),  actual.getDescription());
         assertEquals("valueClass",    expected.getValueClass(),   actual.getValueClass());
-        assertSame  ("valueDomain",   expected.getValueDomain(),  actual.getValueDomain());
         assertEquals("validValues",   expected.getValidValues(),  actual.getValidValues());
-        assertSame  ("defaultValue",  expected.getDefaultValue(), actual.getDefaultValue());
-        assertSame  ("unit",          expected.getUnit(),         actual.getUnit());
+        assertEquals("unit",          expected.getUnit(),         actual.getUnit());
         assertEquals("minimumOccurs", DEFAULT_OCCURRENCE,         actual.getMinimumOccurs());
         assertEquals("maximumOccurs", DEFAULT_OCCURRENCE,         actual.getMaximumOccurs());
+    }
+
+    /**
+     * Same verification than {@link #verifyMethodParameter(ParameterDescriptor, ParameterDescriptor)},
but stricter.
+     *
+     * @param expected A parameter descriptor containing the expected properties (except
remarks).
+     * @param remarks  The expected remarks, or {@code null} for fetching this information
from {@code expected}.
+     * @param actual   The parameter descriptor to verify.
+     */
+    private static void verifyMethodParameter(final ParameterDescriptor<?> expected,
+            final String remarks, final ParameterDescriptor<?> actual)
+    {
+        verifyMethodParameter(expected, actual);
+        assertSame("name",         expected.getName(),         actual.getName());
+        assertSame("minimumValue", expected.getMinimumValue(), actual.getMinimumValue());
+        assertSame("maximumValue", expected.getMaximumValue(), actual.getMaximumValue());
+        assertSame("defaultValue", expected.getDefaultValue(), actual.getDefaultValue());
         if (remarks != null) {
             assertEquals("remarks", remarks, actual.getRemarks().toString());
         } else {

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java?rev=1700843&r1=1700842&r2=1700843&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/OperationMarshallingTest.java
[UTF-8] Wed Sep  2 15:37:39 2015
@@ -21,18 +21,24 @@ import java.util.HashMap;
 import java.util.Iterator;
 import javax.xml.bind.JAXBException;
 import javax.measure.unit.NonSI;
+import org.opengis.metadata.extent.GeographicBoundingBox;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.parameter.GeneralParameterDescriptor;
+import org.opengis.referencing.operation.OperationMethod;
 import org.apache.sis.parameter.ParameterBuilder;
+import org.apache.sis.internal.referencing.provider.Mercator1SP;
+import org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.XML;
 import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.XMLTestCase;
 import org.junit.Test;
 
-import static org.apache.sis.test.ReferencingAssert.*;
 import static org.apache.sis.metadata.iso.citation.Citations.EPSG;
+import static org.apache.sis.test.TestUtilities.getSingleton;
+import static org.apache.sis.test.ReferencingAssert.*;
 
 
 /**
@@ -45,6 +51,7 @@ import static org.apache.sis.metadata.is
  */
 @DependsOn({
     DefaultOperationMethodTest.class,
+    CC_OperationParameterGroupTest.class,
     org.apache.sis.parameter.ParameterMarshallingTest.class
 })
 public final strictfp class OperationMarshallingTest extends XMLTestCase {
@@ -75,24 +82,24 @@ public final strictfp class OperationMar
     @Test
     public void testOperationMethod() throws JAXBException {
         final String xml = XML.marshal(createMercatorMethod());
-        assertXmlEquals("<gml:OperationMethod xmlns:gml=\"" + Namespaces.GML + "\">\n"
-                      + "  <gml:name>Mercator (1SP)</gml:name>\n"
-                      + "  <gml:formula>See EPSG guide.</gml:formula>\n"
-                      + "  <gml:sourceDimensions>2</gml:sourceDimensions>\n"
-                      + "  <gml:targetDimensions>2</gml:targetDimensions>\n"
-                      + "  <gml:parameter>\n"
-                      + "    <gml:OperationParameter gml:id=\"epsg-parameter-8801\">\n"
-                      + "      <gml:identifier codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8801</gml:identifier>\n"
-                      + "      <gml:name codeSpace=\"EPSG\">Latitude of natural origin</gml:name>\n"
-                      + "    </gml:OperationParameter>\n"
-                      + "  </gml:parameter>\n"
-                      + "  <gml:parameter>\n"
-                      + "    <gml:OperationParameter gml:id=\"epsg-parameter-8802\">\n"
-                      + "      <gml:identifier codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8802</gml:identifier>\n"
-                      + "      <gml:name codeSpace=\"EPSG\">Longitude of natural origin</gml:name>\n"
-                      + "    </gml:OperationParameter>\n"
-                      + "  </gml:parameter>\n"
-                      + "</gml:OperationMethod>", xml, "xmlns:*");
+        assertXmlEquals("<gml:OperationMethod xmlns:gml=\"" + Namespaces.GML + "\">\n"
+
+                        "  <gml:name>Mercator (1SP)</gml:name>\n" +
+                        "  <gml:formula>See EPSG guide.</gml:formula>\n" +
+                        "  <gml:sourceDimensions>2</gml:sourceDimensions>\n"
+
+                        "  <gml:targetDimensions>2</gml:targetDimensions>\n"
+
+                        "  <gml:parameter>\n" +
+                        "    <gml:OperationParameter gml:id=\"epsg-parameter-8801\">\n"
+
+                        "      <gml:identifier codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8801</gml:identifier>\n"
+
+                        "      <gml:name codeSpace=\"EPSG\">Latitude of natural origin</gml:name>\n"
+
+                        "    </gml:OperationParameter>\n" +
+                        "  </gml:parameter>\n" +
+                        "  <gml:parameter>\n" +
+                        "    <gml:OperationParameter gml:id=\"epsg-parameter-8802\">\n"
+
+                        "      <gml:identifier codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8802</gml:identifier>\n"
+
+                        "      <gml:name codeSpace=\"EPSG\">Longitude of natural origin</gml:name>\n"
+
+                        "    </gml:OperationParameter>\n" +
+                        "  </gml:parameter>\n" +
+                        "</gml:OperationMethod>", xml, "xmlns:*");
 
         verifyMethod((DefaultOperationMethod) XML.unmarshal(xml));
     }
@@ -100,7 +107,7 @@ public final strictfp class OperationMar
     /**
      * Verifies the unmarshalled parameter descriptors.
      */
-    private static void verifyMethod(final DefaultOperationMethod method) {
+    private static void verifyMethod(final OperationMethod method) {
         assertIdentifierEquals("name", null, null, null, "Mercator (1SP)", method.getName());
         assertEquals("formula", "See EPSG guide.", method.getFormula().getFormula().toString());
         assertEquals("sourceDimensions", Integer.valueOf(2), method.getSourceDimensions());
@@ -108,21 +115,31 @@ public final strictfp class OperationMar
         final ParameterDescriptorGroup parameters = method.getParameters();
         assertEquals("parameters.name", "Mercator (1SP)", parameters.getName().getCode());
         final Iterator<GeneralParameterDescriptor> it = parameters.descriptors().iterator();
-        verifyIncompleteDescriptor("Latitude of natural origin",  it.next());
-        verifyIncompleteDescriptor("Longitude of natural origin", it.next());
+        CC_OperationParameterGroupTest.verifyMethodParameter(Mercator1SP.LATITUDE_OF_ORIGIN,
 (ParameterDescriptor<?>) it.next());
+        CC_OperationParameterGroupTest.verifyMethodParameter(Mercator1SP.LONGITUDE_OF_ORIGIN,
(ParameterDescriptor<?>) it.next());
         assertFalse("Unexpected parameter.", it.hasNext());
     }
 
     /**
-     * Verifies that the given parameter descriptor has the expected EPSG name. This method
does not
-     * verify that {@link ParameterDescriptor#getValueClass()} returns {@code Double.class},
because
-     * this information is not known to {@code OperationMethod}.
+     * Tests unmarshalling of a conversion.
      *
-     * @param name       The expected EPSG name.
-     * @param descriptor The parameter descriptor to verify.
+     * @throws JAXBException if an error occurred during marshalling or unmarshalling.
      */
-    private static void verifyIncompleteDescriptor(final String name, final GeneralParameterDescriptor
descriptor) {
-        assertIdentifierEquals("name", "##unrestricted", "EPSG", null, name, descriptor.getName());
-        assertEquals("maximumOccurs", 1, descriptor.getMaximumOccurs());
+    @Test
+    @DependsOnMethod("testOperationMethod")
+    public void testConversionUnmarshalling() throws JAXBException {
+        final DefaultConversion c = unmarshalFile(DefaultConversion.class, "Conversion.xml");
+        assertEquals("name", "World Mercator", c.getName().getCode());
+        assertEquals("identifier", "3395", getSingleton(c.getIdentifiers()).getCode());
+        assertEquals("scope", "Very small scale mapping.", String.valueOf(c.getScope()));
+
+        final GeographicBoundingBox e = (GeographicBoundingBox) getSingleton(c.getDomainOfValidity().getGeographicElements());
+        assertEquals("eastBoundLongitude", +180, e.getEastBoundLongitude(), STRICT);
+        assertEquals("westBoundLongitude", -180, e.getWestBoundLongitude(), STRICT);
+        assertEquals("northBoundLatitude",   84, e.getNorthBoundLatitude(), STRICT);
+        assertEquals("southBoundLatitude",  -80, e.getSouthBoundLatitude(), STRICT);
+
+        // The most difficult part.
+        verifyMethod(c.getMethod());
     }
 }

Added: sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/operation/Conversion.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/operation/Conversion.xml?rev=1700843&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/operation/Conversion.xml
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/operation/Conversion.xml
Wed Sep  2 15:37:39 2015
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<gml:Conversion xsi:schemaLocation = "http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/datums.xsd"
+                xmlns:gml          = "http://www.opengis.net/gml/3.2"
+                xmlns:gmd          = "http://www.isotc211.org/2005/gmd"
+                xmlns:gco          = "http://www.isotc211.org/2005/gco"
+                xmlns:xsi          = "http://www.w3.org/2001/XMLSchema-instance"
+                xmlns:xlink        = "http://www.w3.org/1999/xlink"
+                gml:id             = "WorldMercator">
+
+  <gml:identifier codeSpace="test">3395</gml:identifier>  <!-- Not the real
EPSG::3395 -->
+  <gml:name>World Mercator</gml:name>
+  <gml:domainOfValidity>
+    <gmd:EX_Extent>
+      <gmd:geographicElement>
+        <gmd:EX_GeographicBoundingBox>
+          <gmd:westBoundLongitude><gco:Decimal>-180</gco:Decimal></gmd:westBoundLongitude>
+          <gmd:eastBoundLongitude><gco:Decimal>+180</gco:Decimal></gmd:eastBoundLongitude>
+          <gmd:southBoundLatitude><gco:Decimal> -80</gco:Decimal></gmd:southBoundLatitude>
+          <gmd:northBoundLatitude><gco:Decimal> +84</gco:Decimal></gmd:northBoundLatitude>
+        </gmd:EX_GeographicBoundingBox>
+      </gmd:geographicElement>
+    </gmd:EX_Extent>
+  </gml:domainOfValidity>
+  <gml:scope>Very small scale mapping.</gml:scope>
+  <gml:coordinateOperationAccuracy>
+    <gmd:DQ_RelativeInternalPositionalAccuracy>
+      <gmd:result>
+        <gmd:DQ_QuantitativeResult>
+          <gmd:valueUnit>
+            <gml:BaseUnit gml:id="m">
+              <gml:identifier codeSpace="IOGP">urn:ogc:def:uom:EPSG::9001</gml:identifier>
+              <gml:name>metre</gml:name>
+              <gml:quantityType>length</gml:quantityType>
+              <gml:unitsSystem xlink:href="http://www.bipm.fr/en/si"/>
+            </gml:BaseUnit>
+          </gmd:valueUnit>
+          <gmd:value>
+            <gco:Record>
+              <gco:Decimal>0</gco:Decimal>
+            </gco:Record>
+          </gmd:value>
+        </gmd:DQ_QuantitativeResult>
+      </gmd:result>
+    </gmd:DQ_RelativeInternalPositionalAccuracy>
+  </gml:coordinateOperationAccuracy>
+  <gml:method>
+    <gml:OperationMethod gml:id="Mercator">
+      <gml:identifier codeSpace="test">19883</gml:identifier>  <!-- Not the
real EPSG::19883 -->
+      <gml:name>Mercator (1SP)</gml:name>
+      <gml:formula>See EPSG guide.</gml:formula>
+      <gml:sourceDimensions>2</gml:sourceDimensions>
+      <gml:targetDimensions>2</gml:targetDimensions>
+      <gml:parameter>
+        <gml:OperationParameter gml:id="epsg-parameter-8801">
+          <gml:identifier codeSpace="IOGP">urn:ogc:def:parameter:EPSG::8801</gml:identifier>
+          <gml:name codeSpace="EPSG">Latitude of natural origin</gml:name>
+        </gml:OperationParameter>
+      </gml:parameter>
+      <gml:parameter>
+        <gml:OperationParameter gml:id="epsg-parameter-8802">
+          <gml:identifier codeSpace="IOGP">urn:ogc:def:parameter:EPSG::8802</gml:identifier>
+          <gml:name codeSpace="EPSG">Longitude of natural origin</gml:name>
+        </gml:OperationParameter>
+      </gml:parameter>
+
+      <!-- There is more parameters in a Mercator projection,
+           but two are enough for (un)marshaling test purpose. -->
+
+    </gml:OperationMethod>
+  </gml:method>
+  <gml:parameterValue>
+    <gml:ParameterValue>
+      <gml:value uom="urn:ogc:def:uom:EPSG::9102">0</gml:value>
+
+      <!-- All descriptors below this point are duplication of the descriptors already
defined above.
+           For now we do not yet use the XML references, but this is something that we will
need to
+           support in a future SIS version. See https://issues.apache.org/jira/browse/SIS-173
issue.
+           In the meantime, we have to change the gml:id attribute values used below for
avoiding
+           collisions with the gml:id attribute used in above descriptors. -->
+
+      <gml:operationParameter>
+        <gml:OperationParameter gml:id="LatitudeOfNaturalOrigin">
+          <gml:identifier codeSpace="IOGP">urn:ogc:def:parameter:EPSG::8801</gml:identifier>
+          <gml:name codeSpace="EPSG">Latitude of natural origin</gml:name>
+          <gml:remarks>This parameter is shown for completeness, but should never have
a value different than 0 for this projection.</gml:remarks>
+        </gml:OperationParameter>
+      </gml:operationParameter>
+    </gml:ParameterValue>
+  </gml:parameterValue>
+  <gml:parameterValue>
+    <gml:ParameterValue>
+      <gml:value uom="urn:ogc:def:uom:EPSG::9102">0</gml:value>
+      <gml:operationParameter>
+        <gml:OperationParameter gml:id="LongitudeOfNaturalOrigin">
+          <gml:identifier codeSpace="IOGP">urn:ogc:def:parameter:EPSG::8802</gml:identifier>
+          <gml:name codeSpace="EPSG">Longitude of natural origin</gml:name>
+        </gml:OperationParameter>
+      </gml:operationParameter>
+    </gml:ParameterValue>
+  </gml:parameterValue>
+
+  <!-- There is more parameters in a Mercator projection,
+       but two are enough for (un)marshaling test purpose. -->
+
+</gml:Conversion>

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/operation/Conversion.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/operation/Conversion.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message