sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1552228 - in /sis/branches/JDK7/core/sis-referencing/src: main/java/org/apache/sis/referencing/datum/ test/java/org/apache/sis/referencing/datum/ test/resources/org/apache/sis/referencing/datum/
Date Thu, 19 Dec 2013 05:01:45 GMT
Author: desruisseaux
Date: Thu Dec 19 05:01:45 2013
New Revision: 1552228

URL: http://svn.apache.org/r1552228
Log:
Added tests.

Added:
    sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Clarke
1880.xml   (with props)
Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DatumTestCase.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Greenwich.xml
    sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1552228&r1=1552227&r2=1552228&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] Thu Dec 19 05:01:45 2013
@@ -349,12 +349,10 @@ public class DefaultEllipsoid extends Ab
      * been defined, it is now possible to calculate the value of the missing parameter
      * using the values of those that are set.
      *
-     * <p>This method is invoked by JAXB only.</p>
-     *
      * @see #setSemiMajorAxisMeasure(Measure)
      * @see #setSecondDefiningParameter(SecondDefiningParameter)
      */
-    private void afterUnmarshal(Object target, Object parent) {
+    private void afterUnmarshal() {
         if (ivfDefinitive) {
             if (semiMinorAxis == 0) {
                 semiMinorAxis = semiMajorAxis * (1 - 1/inverseFlattening);
@@ -412,9 +410,12 @@ public class DefaultEllipsoid extends Ab
             warnDuplicated("semiMajorAxis");
         } else {
             final Unit<Length> uom = unit; // In case semi-minor were defined before
semi-major.
-            semiMajorAxis = measure.value;
+            ensureStrictlyPositive("semiMajorAxis", semiMajorAxis = measure.value);
             unit = measure.getUnit(Length.class);
             harmonizeAxisUnits(uom);
+            if ((ivfDefinitive ? inverseFlattening : semiMinorAxis) != 0) {
+                afterUnmarshal();
+            }
         }
     }
 
@@ -513,30 +514,37 @@ public class DefaultEllipsoid extends Ab
         }
         final Measure measure = second.measure;
         if (measure != null) {
-            double value = measure.value;
-            if (second.isIvfDefinitive()) {
-                if (inverseFlattening == 0) {
-                    inverseFlattening = value;
-                    ivfDefinitive = true;
-                    return;
+            final boolean isIvfDefinitive = second.isIvfDefinitive();
+            if ((isIvfDefinitive ? inverseFlattening : semiMinorAxis) != 0) {
+                warnDuplicated("secondDefiningParameter");
+            } else {
+                ivfDefinitive = isIvfDefinitive;
+                double value = measure.value;
+                if (isIvfDefinitive) {
+                    if (value == 0) {
+                        value = Double.POSITIVE_INFINITY;
+                    }
+                    ensureStrictlyPositive("inverseFlattening", inverseFlattening = value);
+                } else if (semiMinorAxis == 0) {
+                    ensureStrictlyPositive("semiMinorAxis", semiMinorAxis = value);
+                    if (unit == null) {
+                        unit = measure.getUnit(Length.class);
+                    } else {
+                        harmonizeAxisUnits(measure.unit);
+                    }
                 }
-            } else if (semiMinorAxis == 0) {
-                semiMinorAxis = value;
-                ivfDefinitive = false;
-                if (unit == null) {
-                    unit = measure.getUnit(Length.class);
-                } else {
-                    harmonizeAxisUnits(measure.unit);
+                if (semiMajorAxis != 0) {
+                    afterUnmarshal();
                 }
-                return;
             }
-            warnDuplicated("secondDefiningParameter");
         }
     }
 
     /**
      * Ensures that the semi-minor axis uses the same unit than the semi-major one.
+     * The {@link #unit} field shall be set to the semi-major axis unit before this method
call.
      *
+     * @param  uom The semi-minor axis unit.
      * @throws ConversionException If semi-major and semi-minor axes use inconsistent units
      *         and we can not convert from one to the other.
      */

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DatumTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DatumTestCase.java?rev=1552228&r1=1552227&r2=1552228&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DatumTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DatumTestCase.java
[UTF-8] Thu Dec 19 05:01:45 2013
@@ -24,7 +24,7 @@ import org.opengis.referencing.datum.Pri
 import org.apache.sis.xml.MarshallerPool;
 import org.apache.sis.test.XMLTestCase;
 
-import static org.opengis.test.Assert.*;
+import static org.apache.sis.test.Assert.*;
 
 
 /**
@@ -61,6 +61,18 @@ abstract strictfp class DatumTestCase ex
     }
 
     /**
+     * Marshals the given object and ensure that the result is equals to the content of the
given file,
+     * ignoring namespace declarations.
+     *
+     * @param  filename The name of the XML file.
+     * @param  object The object to marshal.
+     * @throws JAXBException If an error occurred during marshalling.
+     */
+    final void assertMarshalEqualsFile(final String filename, final Object object) throws
JAXBException {
+        assertXmlEquals(getResource(filename), marshal(object), "xlmns:*", "xsi:schemaLocation");
+    }
+
+    /**
      * Unmarshalls the given test file.
      *
      * @param  type The expected object type.

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java?rev=1552228&r1=1552227&r2=1552228&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
[UTF-8] Thu Dec 19 05:01:45 2013
@@ -17,6 +17,8 @@
 package org.apache.sis.referencing.datum;
 
 import java.util.Random;
+import javax.xml.bind.JAXBException;
+import javax.measure.unit.NonSI;
 import org.apache.sis.measure.Latitude;
 import org.apache.sis.measure.Longitude;
 import org.apache.sis.referencing.IdentifiedObjects;
@@ -157,4 +159,21 @@ public final strictfp class DefaultEllip
         final DefaultEllipsoid e = new DefaultEllipsoid(GeodeticDatumMock.WGS84.getEllipsoid());
         assertWktEquals(e, "SPHEROID[“WGS84”, 6378137.0, 298.257223563]");
     }
+
+    /**
+     * Tests unmarshalling and marshalling.
+     *
+     * @throws JAXBException If an error occurred during (un)marshalling.
+     */
+    @Test
+    public void testXML() throws JAXBException {
+        final DefaultEllipsoid ellipsoid = unmarshall(DefaultEllipsoid.class, "Clarke 1880.xml");
+        assertEquals("name", "Clarke 1880 (international foot)", ellipsoid.getName().getCode());
+        assertEquals("remarks", "Definition in feet assumed to be international foot.", ellipsoid.getRemarks().toString());
+        assertFalse ("isIvfDefinitive",                       ellipsoid.isIvfDefinitive());
+        assertEquals("semiMajorAxis",     20926202,           ellipsoid.getSemiMajorAxis(),
0);
+        assertEquals("semiMinorAxis",     20854895,           ellipsoid.getSemiMinorAxis(),
0);
+        assertEquals("inverseFlattening", 293.46630765562986, ellipsoid.getInverseFlattening(),
1E-12);
+        assertEquals("axisUnit",          NonSI.FOOT,         ellipsoid.getAxisUnit());
+    }
 }

Added: sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Clarke
1880.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Clarke%201880.xml?rev=1552228&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Clarke
1880.xml (added)
+++ sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Clarke
1880.xml [UTF-8] Thu Dec 19 05:01:45 2013
@@ -0,0 +1,36 @@
+<?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:Ellipsoid
+    xmlns:gml = "http://www.opengis.net/gml/3.2"
+    xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation = "http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/datums.xsd"
+    gml:id = "epsg-ellipsoid-7055">
+
+  <gml:identifier codeSpace="OGP">urn:ogc:def:ellipsoid:EPSG::7055</gml:identifier>
+  <gml:name>Clarke 1880 (international foot)</gml:name>
+  <gml:remarks>Definition in feet assumed to be international foot.</gml:remarks>
+  <gml:semiMajorAxis uom="urn:ogc:def:uom:EPSG::9002">20926202</gml:semiMajorAxis>
+  <gml:secondDefiningParameter>
+    <gml:SecondDefiningParameter>
+      <gml:semiMinorAxis uom="urn:ogc:def:uom:EPSG::9002">20854895</gml:semiMinorAxis>
+    </gml:SecondDefiningParameter>
+  </gml:secondDefiningParameter>
+</gml:Ellipsoid>

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Clarke
1880.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Clarke
1880.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Greenwich.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Greenwich.xml?rev=1552228&r1=1552227&r2=1552228&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Greenwich.xml
(original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Greenwich.xml
Thu Dec 19 05:01:45 2013
@@ -21,7 +21,8 @@
 <gml:PrimeMeridian
     xmlns:gml = "http://www.opengis.net/gml/3.2"
     xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation = "http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/datums.xsd">
+    xsi:schemaLocation = "http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/datums.xsd"
+    gml:id = "epsg-meridian-8901">
 
   <gml:identifier codeSpace="OGP">urn:ogc:def:meridian:EPSG::8901</gml:identifier>
   <gml:name>Greenwich</gml:name>

Modified: sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml?rev=1552228&r1=1552227&r2=1552228&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml
(original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Paris.xml
Thu Dec 19 05:01:45 2013
@@ -21,10 +21,11 @@
 <gml:PrimeMeridian
     xmlns:gml = "http://www.opengis.net/gml/3.2"
     xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation = "http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/datums.xsd">
+    xsi:schemaLocation = "http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/datums.xsd"
+    gml:id = "epsg-meridian-8903">
 
   <gml:identifier codeSpace="OGP">urn:ogc:def:meridian:EPSG::8903</gml:identifier>
   <gml:name>Paris</gml:name>
-  <gml:greenwichLongitude uom="urn:ogc:def:uom:EPSG::9105">2.5969213</gml:greenwichLongitude>
   <gml:remarks>Equivalent to 2°20′14.025″.</gml:remarks>
+  <gml:greenwichLongitude uom="urn:ogc:def:uom:EPSG::9105">2.5969213</gml:greenwichLongitude>
 </gml:PrimeMeridian>



Mime
View raw message