sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1725985 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/factory/ test/java/org/apache/sis/referencing/datum/ test/java/org/apache/sis/referencing/factory/ test/java/org/apache/sis/test/suite/
Date Thu, 21 Jan 2016 15:27:17 GMT
Author: desruisseaux
Date: Thu Jan 21 15:27:17 2016
New Revision: 1725985

URL: http://svn.apache.org/viewvc?rev=1725985&view=rev
Log:
Add tests for MultiAuthoritiesFactory.createFoo("AUTHORITY:CODE").

Added:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryMock.java
  (with props)
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryIdentifier.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/PrimeMeridianMock.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryIdentifier.java?rev=1725985&r1=1725984&r2=1725985&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryIdentifier.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/AuthorityFactoryIdentifier.java
[UTF-8] Thu Jan 21 15:27:17 2016
@@ -215,20 +215,6 @@ final class AuthorityFactoryIdentifier {
     }
 
     /**
-     * Returns the authority.
-     */
-    String getAuthority() {
-        return authority;
-    }
-
-    /**
-     * Returns {@code true} if this identifier is for a specific dataset version.
-     */
-    boolean hasVersion() {
-        return version != null;
-    }
-
-    /**
      * Ensures that the authority and version use shared {@link String} instances. This method
is invoked only when
      * we have determined that this {@code AuthorityFactoryIdentifier} instance will be used
as a key in a hash map.
      */
@@ -263,6 +249,31 @@ final class AuthorityFactoryIdentifier {
     }
 
     /**
+     * Returns {@code true} if the given identifier is for the same authority than this identifier.
+     */
+    boolean isSameAuthority(final AuthorityFactoryIdentifier other) {
+        return authority.equals(other.authority);
+    }
+
+    /**
+     * Returns the authority with the version, if any.
+     */
+    CharSequence getAuthority() {
+        CharSequence name = authority;
+        if (hasVersion()) {
+            name = Vocabulary.formatInternational(Vocabulary.Keys.Version_2, name, version);
+        }
+        return name;
+    }
+
+    /**
+     * Returns {@code true} if this identifier is for a specific dataset version.
+     */
+    boolean hasVersion() {
+        return version != null;
+    }
+
+    /**
      * Logs a message reporting a conflict between the factory identified by this {@code
AuthorityFactoryIdentifier}
      * and another factory, if this instance has not already logged a warning. This method
assumes that it is invoked
      * by the {@code MultiAuthoritiesFactory.getAuthorityFactory(…)} method.
@@ -272,12 +283,8 @@ final class AuthorityFactoryIdentifier {
     void logConflictWarning(final AuthorityFactory used) {
         if (!hasLoggedWarning) {
             hasLoggedWarning = true;
-            CharSequence name = authority;
-            if (version != null) {
-                name = Vocabulary.formatInternational(Vocabulary.Keys.Version_2, name, version);
-            }
             final LogRecord record = Messages.getResources(null).getLogRecord(Level.WARNING,
-                    Messages.Keys.IgnoredServiceProvider_3, TYPES[type], name, Classes.getClass(used));
+                    Messages.Keys.IgnoredServiceProvider_3, TYPES[type], getAuthority(),
Classes.getClass(used));
             record.setLoggerName(Loggers.CRS_FACTORY);
             // MultiAuthoritiesFactory.getAuthorityFactory(…) is the nearest public API.
             Logging.log(MultiAuthoritiesFactory.class, "getAuthorityFactory", record);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java?rev=1725985&r1=1725984&r2=1725985&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/CommonAuthorityFactory.java
[UTF-8] Thu Jan 21 15:27:17 2016
@@ -236,7 +236,7 @@ public class CommonAuthorityFactory exte
     /**
      * The parameter separator for codes in the {@code "AUTO(2)"} namespace.
      */
-    private static final char SEPARATOR = ',';
+    static final char SEPARATOR = ',';
 
     /**
      * The codes known to this factory, associated with their CRS type. This is set to an
empty map

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java?rev=1725985&r1=1725984&r2=1725985&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
[UTF-8] Thu Jan 21 15:27:17 2016
@@ -124,8 +124,10 @@ public class MultiAuthoritiesFactory ext
 
     /**
      * A bit masks identifying which providers have given us all their factories.
+     * The value {@code (1 << type)} is set when {@code MultiAuthoritiesFactory}
+     * has iterated until the end of {@code providers[type].iterator()}.
      */
-    private final AtomicInteger iterationCompleted;
+    private final AtomicInteger isIterationCompleted;
 
     /**
      * The code spaces of all factories given to the constructor, created when first requested.
@@ -186,7 +188,7 @@ public class MultiAuthoritiesFactory ext
         }
         providers = ArraysExt.resize(p, length);
         factories = new ConcurrentHashMap<>();
-        iterationCompleted = new AtomicInteger(nullMask);
+        isIterationCompleted = new AtomicInteger(nullMask);
     }
 
     /**
@@ -315,7 +317,7 @@ public class MultiAuthoritiesFactory ext
          * a previous call to this getAuthorityFactory(…) method, we will continue the
search after skipping already
          * cached instances.
          */
-        int doneMask = iterationCompleted.get();
+        int doneMask = isIterationCompleted.get();
         final int type = request.type;
         if ((doneMask & (1 << type)) == 0) {
             if (type >= 0 && type < providers.length) {
@@ -337,7 +339,7 @@ public class MultiAuthoritiesFactory ext
                              * We have no choice when ignoring the version number causes
a conflict, or
                              * when the user asked for a specific version.
                              */
-                            if (factory != cached || (request.hasVersion() && request.getAuthority().equals(unversioned.getAuthority())))
{
+                            if (factory != cached || (request.hasVersion() && request.isSameAuthority(unversioned)))
{
                                 final AuthorityFactoryIdentifier versioned = unversioned.versionOf(factory.getAuthority());
                                 if (versioned != unversioned) {
                                     /*
@@ -401,11 +403,11 @@ public class MultiAuthoritiesFactory ext
              * Note that the mask values may also be modified in other threads for other
providers, so we
              * need to atomically verify that the current value has not been modified before
to set it.
              */
-            while (!iterationCompleted.compareAndSet(doneMask, doneMask | (1 << type)))
{
-                doneMask = iterationCompleted.get();
+            while (!isIterationCompleted.compareAndSet(doneMask, doneMask | (1 << type)))
{
+                doneMask = isIterationCompleted.get();
             }
         }
-        final String authority = request.getAuthority();
+        final String authority = request.getAuthority().toString();
         throw new NoSuchAuthorityFactoryException(Errors.format(Errors.Keys.UnknownAuthority_1,
authority), authority);
     }
 
@@ -418,17 +420,20 @@ public class MultiAuthoritiesFactory ext
      * @return The object from one of the authority factory specified at construction time.
      * @throws FactoryException If an error occurred while creating the object.
      */
-    private <T> T create(final AuthorityFactoryProxy<T> proxy, final String code)
throws FactoryException {
+    private <T> T create(final AuthorityFactoryProxy<T> proxy, String code) throws
FactoryException {
         ArgumentChecks.ensureNonNull("code", code);
-        final String authority, version;
+        final String authority;
+        String version;
         final DefinitionURI uri = DefinitionURI.parse(code);
         if (uri != null) {
             authority = uri.authority;
-            version = uri.version;
+            version   = uri.version;
+            code      = uri.code;
         } else {
             /*
-             * Usages of CharSequences.skipLeadingWhitespaces(…) and skipTrailingWhitespaces(…)
-             * below will work even if code.indexOf(…) returned -1.
+             * Separate the authority from the rest of the code. The authority is mandatory;
if missing,
+             * an exception will be thrown. Note that the CharSequences.skipLeading/TrailingWhitespaces(…)
+             * methods are robust to negative index, so the code will work even if code.indexOf(…)
returned -1.
              */
             int afterAuthority = code.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR);
             int end = CharSequences.skipTrailingWhitespaces(code, 0, afterAuthority);
@@ -437,19 +442,41 @@ public class MultiAuthoritiesFactory ext
                 throw new NoSuchAuthorityFactoryException(Errors.format(Errors.Keys.MissingAuthority_1,
code), null);
             }
             authority = code.substring(start, end);
+            version = null;
+            /*
+             * Separate the version from the rest of the code. The version is optional. The
code may have no room
+             * for version (e.g. "EPSG:4326"), or specify an empty version (e.g. "EPSG::4326").
If the version is
+             * equals to an empty string or to the "0" string, it will be considered as no
version. Usage of 0 as
+             * a pseudo-version is a practice commonly found in other softwares.
+             */
             int afterVersion = code.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR, ++afterAuthority);
             start = CharSequences.skipLeadingWhitespaces(code, afterAuthority, afterVersion);
             end = CharSequences.skipTrailingWhitespaces(code, start, afterVersion);
             if (start < end) {
-                version = code.substring(start, end);
-                afterVersion++;
-            } else {
-                version = null;
-                afterVersion = afterAuthority;
+                if (end - start != 1 || code.charAt(start) != '0') {
+                    version = code.substring(start, end);
+                }
             }
+            /*
+             * Separate the code from the authority and the version.
+             */
+            afterVersion = Math.max(afterAuthority, afterVersion + 1);
+            end   = CharSequences.skipTrailingWhitespaces(code, afterVersion, code.length());
+            start = CharSequences.skipLeadingWhitespaces(code, afterVersion, end);
+            code  = code.substring(start, end);
+        }
+        /*
+         * At this point we have the code without the authority and version parts.
+         * Push back the authority part if the factory may need it. For now we do that only
if the code has
+         * parameters, since interpretation of the unit parameter in "AUTO(2):42001,unit,longitude,latitude"
+         * depends on whether the authority is "AUTO" or "AUTO2". This works for now, but
we may need a more
+         * rigorous approach in a future SIS version.
+         */
+        if (code.indexOf(CommonAuthorityFactory.SEPARATOR) >= 0) {
+            code = authority + DefaultNameSpace.DEFAULT_SEPARATOR + code;
         }
-        return proxy.createFromAPI(getAuthorityFactory(
-                AuthorityFactoryIdentifier.create(proxy.factoryType, authority, version)),
code);
+        return proxy.createFromAPI(
+                getAuthorityFactory(AuthorityFactoryIdentifier.create(proxy.factoryType,
authority, version)), code);
     }
 
     /**
@@ -1069,12 +1096,12 @@ public class MultiAuthoritiesFactory ext
     }
 
     /**
-     * Sets {@link #iterationCompleted} to {@code iterationCompleted & mask}.
+     * Sets {@link #isIterationCompleted} to {@code iterationCompleted & mask}.
      * This is used by {@link #reload()} for clearing bits.
      */
     private void applyAndMask(final int mask) {
         int value;
-        do value = iterationCompleted.get();
-        while (!iterationCompleted.compareAndSet(value, value & mask));
+        do value = isIterationCompleted.get();
+        while (!isIterationCompleted.compareAndSet(value, value & mask));
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java?rev=1725985&r1=1725984&r2=1725985&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java
[UTF-8] Thu Jan 21 15:27:17 2016
@@ -30,7 +30,6 @@ import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
-import static org.apache.sis.referencing.datum.GeodeticDatumMock.WGS84;
 
 
 /**
@@ -52,7 +51,7 @@ public final strictfp class BursaWolfPar
      * Area of validity is the World.
      */
     static BursaWolfParameters createWGS72_to_WGS84() {
-        final BursaWolfParameters bursaWolf = new BursaWolfParameters(WGS84, Extents.WORLD);
+        final BursaWolfParameters bursaWolf = new BursaWolfParameters(GeodeticDatumMock.WGS84,
Extents.WORLD);
         bursaWolf.tZ = 4.5;
         bursaWolf.rZ = 0.554;
         bursaWolf.dS = 0.219;
@@ -67,7 +66,7 @@ public final strictfp class BursaWolfPar
      * Area of validity is the North Sea: 5.05°W to 11.13°E in longitude and 51.04°N to
62.0°N in latitude.
      */
     static BursaWolfParameters createED87_to_WGS84() {
-        final BursaWolfParameters bursaWolf = new BursaWolfParameters(WGS84, new DefaultExtent("Europe
- North Sea",
+        final BursaWolfParameters bursaWolf = new BursaWolfParameters(GeodeticDatumMock.WGS84,
new DefaultExtent("Europe - North Sea",
                 new DefaultGeographicBoundingBox(-5.05, 11.13, 51.04, 62.0), null, null));
         bursaWolf.tX =  -82.981;
         bursaWolf.tY =  -99.719;
@@ -88,7 +87,7 @@ public final strictfp class BursaWolfPar
      * This transformation uses only translation parameters.
      */
     static BursaWolfParameters createNTF_to_WGS84() {
-        final BursaWolfParameters bursaWolf = new BursaWolfParameters(WGS84, Extents.WORLD);
+        final BursaWolfParameters bursaWolf = new BursaWolfParameters(GeodeticDatumMock.WGS84,
Extents.WORLD);
         bursaWolf.tX = -168;
         bursaWolf.tY =  -60;
         bursaWolf.tZ =  320;

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java?rev=1725985&r1=1725984&r2=1725985&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java
[UTF-8] Thu Jan 21 15:27:17 2016
@@ -37,7 +37,6 @@ import org.apache.sis.test.TestStep;
 import org.junit.Test;
 
 import static org.apache.sis.test.MetadataAssert.*;
-import static org.apache.sis.referencing.datum.GeodeticDatumMock.*;
 import static org.apache.sis.referencing.GeodeticObjectVerifier.*;
 
 
@@ -105,7 +104,7 @@ public final strictfp class DefaultGeode
      */
     @Test
     public void testIsHeuristicMatchForName() {
-        final DefaultGeodeticDatum datum = new DefaultGeodeticDatum(WGS84);
+        final DefaultGeodeticDatum datum = new DefaultGeodeticDatum(GeodeticDatumMock.WGS84);
         assertFalse(datum.isHeuristicMatchForName("WGS72"));
         assertTrue (datum.isHeuristicMatchForName("WGS84"));
         assertTrue (datum.isHeuristicMatchForName("WGS 84"));
@@ -136,28 +135,29 @@ public final strictfp class DefaultGeode
          * Build the datum using WGS 72 ellipsoid (so at least one of the BursaWolfParameters
is real).
          */
         final DefaultGeodeticDatum datum = new DefaultGeodeticDatum(properties,
-                WGS72.getEllipsoid(), WGS72.getPrimeMeridian());
+                GeodeticDatumMock.WGS72.getEllipsoid(),
+                GeodeticDatumMock.WGS72.getPrimeMeridian());
         /*
          * Search for BursaWolfParameters around the North Sea area.
          */
         final DefaultGeographicBoundingBox areaOfInterest = new DefaultGeographicBoundingBox(-2,
8, 55, 60);
         final DefaultExtent extent = new DefaultExtent("Around the North Sea", areaOfInterest,
null, null);
-        Matrix matrix = datum.getPositionVectorTransformation(NAD83, extent);
+        Matrix matrix = datum.getPositionVectorTransformation(GeodeticDatumMock.NAD83, extent);
         assertNull("No BursaWolfParameters for NAD83", matrix);
-        matrix = datum.getPositionVectorTransformation(WGS84, extent);
+        matrix = datum.getPositionVectorTransformation(GeodeticDatumMock.WGS84, extent);
         assertNotNull("BursaWolfParameters for WGS84", matrix);
         checkTransformationSignature(local, matrix, 0);
         /*
          * Expand the area of interest to something greater than North Sea, and test again.
          */
         areaOfInterest.setWestBoundLongitude(-8);
-        matrix = datum.getPositionVectorTransformation(WGS84, extent);
+        matrix = datum.getPositionVectorTransformation(GeodeticDatumMock.WGS84, extent);
         assertNotNull("BursaWolfParameters for WGS84", matrix);
         checkTransformationSignature(global, matrix, 0);
         /*
          * Search in the reverse direction.
          */
-        final DefaultGeodeticDatum targetDatum = new DefaultGeodeticDatum(WGS84);
+        final DefaultGeodeticDatum targetDatum = new DefaultGeodeticDatum(GeodeticDatumMock.WGS84);
         matrix = targetDatum.getPositionVectorTransformation(datum, extent);
         global.invert(); // Expected result is the inverse.
         checkTransformationSignature(global, matrix, 1E-6);
@@ -182,7 +182,7 @@ public final strictfp class DefaultGeode
      */
     @Test
     public void testToWKT() {
-        final DefaultGeodeticDatum datum = new DefaultGeodeticDatum(WGS84);
+        final DefaultGeodeticDatum datum = new DefaultGeodeticDatum(GeodeticDatumMock.WGS84);
         assertWktEquals(Convention.WKT2,
                 "DATUM[“WGS84”,\n" +
                 "  ELLIPSOID[“WGS84”, 6378137.0, 298.257223563, LENGTHUNIT[“metre”,
1]]]",
@@ -222,7 +222,7 @@ public final strictfp class DefaultGeode
                 "    </gml:Ellipsoid>\n" +
                 "  </gml:ellipsoid>\n" +
                 "</gml:GeodeticDatum>",
-                marshal(new DefaultGeodeticDatum(WGS84)), "xmlns:*");
+                marshal(new DefaultGeodeticDatum(GeodeticDatumMock.WGS84)), "xmlns:*");
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java?rev=1725985&r1=1725984&r2=1725985&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
[UTF-8] Thu Jan 21 15:27:17 2016
@@ -36,7 +36,6 @@ import org.junit.Test;
 import static java.util.Collections.singletonMap;
 import static org.apache.sis.test.MetadataAssert.*;
 import static org.apache.sis.referencing.GeodeticObjectVerifier.*;
-import static org.apache.sis.referencing.datum.PrimeMeridianMock.GREENWICH;
 
 
 /**
@@ -59,7 +58,7 @@ public final strictfp class DefaultPrime
      */
     @Test
     public void testToWKT() {
-        final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(GREENWICH);
+        final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(PrimeMeridianMock.GREENWICH);
         assertIsGreenwich(pm);
         assertWktEquals(Convention.WKT2, "PRIMEM[“Greenwich”, 0.0, ANGLEUNIT[“degree”,
0.017453292519943295]]", pm);
         assertWktEquals(Convention.WKT2_SIMPLIFIED, "PrimeMeridian[“Greenwich”, 0.0]",
pm);
@@ -123,7 +122,7 @@ public final strictfp class DefaultPrime
      */
     @Test
     public void testMarshall() throws JAXBException {
-        final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(GREENWICH);
+        final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(PrimeMeridianMock.GREENWICH);
         assertXmlEquals(getGreenwichXml(Namespaces.GML), marshal(pm), "xmlns:*");
     }
 
@@ -135,7 +134,7 @@ public final strictfp class DefaultPrime
     @Test
     @DependsOnMethod("testMarshall")
     public void testMarshallGML31() throws JAXBException {
-        final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(GREENWICH);
+        final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(PrimeMeridianMock.GREENWICH);
         final MarshallerPool pool = getMarshallerPool();
         final Marshaller marshaller = pool.acquireMarshaller();
         marshaller.setProperty(XML.GML_VERSION, LegacyNamespaces.VERSION_3_0);

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/PrimeMeridianMock.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/PrimeMeridianMock.java?rev=1725985&r1=1725984&r2=1725985&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/PrimeMeridianMock.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/PrimeMeridianMock.java
[UTF-8] Thu Jan 21 15:27:17 2016
@@ -32,7 +32,7 @@ import org.apache.sis.test.mock.Identifi
  * @module
  */
 @SuppressWarnings("serial")
-public final strictfp class PrimeMeridianMock extends IdentifiedObjectMock implements PrimeMeridian
{
+final strictfp class PrimeMeridianMock extends IdentifiedObjectMock implements PrimeMeridian
{
     /**
      * A mock for the Greenwich prime meridian.
      */

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java?rev=1725985&r1=1725984&r2=1725985&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/TimeDependentBWPTest.java
[UTF-8] Thu Jan 21 15:27:17 2016
@@ -28,7 +28,6 @@ import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
 import static org.apache.sis.test.TestUtilities.date;
-import static org.apache.sis.referencing.datum.GeodeticDatumMock.WGS84;
 import static org.apache.sis.internal.referencing.Formulas.JULIAN_YEAR_LENGTH;
 
 
@@ -48,7 +47,7 @@ public final strictfp class TimeDependen
      * For the purpose of this test, the target datum does not matter anyway.
      */
     private static TimeDependentBWP create() {
-        final TimeDependentBWP p = new TimeDependentBWP(WGS84, null, date("1994-01-01 00:00:00"));
+        final TimeDependentBWP p = new TimeDependentBWP(GeodeticDatumMock.WGS84, null, date("1994-01-01
00:00:00"));
         p.tX = -0.08468;    p.dtX = +1.42;
         p.tY = -0.01942;    p.dtY = +1.34;
         p.tZ = +0.03201;    p.dtZ = +0.90;

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryMock.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryMock.java?rev=1725985&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryMock.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryMock.java
[UTF-8] Thu Jan 21 15:27:17 2016
@@ -0,0 +1,132 @@
+/*
+ * 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.referencing.factory;
+
+import java.util.Set;
+import java.util.LinkedHashSet;
+import org.opengis.util.FactoryException;
+import org.opengis.metadata.citation.Citation;
+import org.opengis.referencing.IdentifiedObject;
+import org.opengis.referencing.NoSuchAuthorityCodeException;
+import org.opengis.referencing.crs.CRSAuthorityFactory;
+import org.opengis.referencing.crs.GeocentricCRS;
+import org.opengis.referencing.crs.GeographicCRS;
+import org.opengis.referencing.crs.VerticalCRS;
+import org.opengis.referencing.datum.DatumAuthorityFactory;
+import org.opengis.referencing.datum.GeodeticDatum;
+import org.opengis.referencing.datum.PrimeMeridian;
+import org.opengis.referencing.datum.VerticalDatum;
+import org.opengis.util.InternationalString;
+import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.internal.simple.SimpleCitation;
+import org.apache.sis.referencing.datum.HardCodedDatum;
+import org.apache.sis.referencing.crs.HardCodedCRS;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * A pseudo-authority factory with hard-coded objects.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+public final strictfp class AuthorityFactoryMock extends GeodeticAuthorityFactory
+        implements CRSAuthorityFactory, DatumAuthorityFactory
+{
+    /**
+     * The authority.
+     */
+    private final Citation authority;
+
+    /**
+     * Creates a new factory for the given authority.
+     *
+     * @param authority The title of the authority to declare.
+     * @param version   The version, or {@code null} if none.
+     */
+    @SuppressWarnings("serial")
+    public AuthorityFactoryMock(final String authority, final String version) {
+        this.authority = new SimpleCitation(authority) {
+            @Override public InternationalString getEdition() {
+                return (version != null) ? new SimpleInternationalString(version) : null;
+            }
+        };
+    }
+
+    /**
+     * Returns the authority built from the title given at construction time.
+     */
+    @Override
+    public Citation getAuthority() {
+        return authority;
+    }
+
+    /**
+     * Add the string representations of the given values into the {@code codes} set.
+     * This is a helper method for {@link #getAuthorityCodes(Class)}.
+     * Not an efficient approach but okay for testing purpose.
+     */
+    private static void add(final Set<String> codes, final int... values) {
+        for (final int value : values) {
+            final String s = Integer.toString(value);
+            assertTrue(s, codes.add(s));
+        }
+    }
+
+    /**
+     * Returns the authority codes for the given type.
+     */
+    @Override
+    public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type)
{
+        final Set<String> codes = new LinkedHashSet<>();
+        if (type.isAssignableFrom(GeocentricCRS.class)) add(codes, 4979);
+        if (type.isAssignableFrom(GeographicCRS.class)) add(codes, 84, 4326);
+        if (type.isAssignableFrom(PrimeMeridian.class)) add(codes, 8901, 8903, 8914);
+        if (type.isAssignableFrom(GeodeticDatum.class)) add(codes, 6326, 6322, 6807, 6301,
6612, 6047);
+        if (type.isAssignableFrom(VerticalDatum.class)) add(codes, 5100);
+        if (type.isAssignableFrom(VerticalCRS.class))   add(codes, 5714, 9905);
+        return codes;
+    }
+
+    /**
+     * Returns the geodetic object for the given code.
+     */
+    @Override
+    public IdentifiedObject createObject(final String code) throws FactoryException {
+        switch (Integer.parseInt(trimNamespace(code))) {
+            case   84: return HardCodedCRS.WGS84;
+            case 4326: return HardCodedCRS.WGS84_φλ;
+            case 4979: return HardCodedCRS.GEOCENTRIC;
+            case 5714: return HardCodedCRS.GRAVITY_RELATED_HEIGHT;
+            case 9905: return HardCodedCRS.DEPTH;
+            case 8901: return HardCodedDatum.GREENWICH;
+            case 8903: return HardCodedDatum.PARIS;
+            case 8914: return HardCodedDatum.PARIS_RGS;
+            case 6326: return HardCodedDatum.WGS84;
+            case 6322: return HardCodedDatum.WGS72;
+            case 6807: return HardCodedDatum.NTF;
+            case 6301: return HardCodedDatum.TOKYO;
+            case 6612: return HardCodedDatum.JGD2000;
+            case 6047: return HardCodedDatum.SPHERE;
+            case 5100: return HardCodedDatum.MEAN_SEA_LEVEL;
+            default: throw new NoSuchAuthorityCodeException(code, authority.getTitle().toString(),
code);
+        }
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/AuthorityFactoryMock.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java?rev=1725985&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java
[UTF-8] Thu Jan 21 15:27:17 2016
@@ -0,0 +1,217 @@
+/*
+ * 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.referencing.factory;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Set;
+import org.opengis.referencing.IdentifiedObject;
+import org.opengis.referencing.crs.CRSAuthorityFactory;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.crs.GeocentricCRS;
+import org.opengis.referencing.crs.GeodeticCRS;
+import org.opengis.referencing.crs.GeographicCRS;
+import org.opengis.referencing.crs.VerticalCRS;
+import org.opengis.referencing.datum.Datum;
+import org.opengis.referencing.datum.DatumAuthorityFactory;
+import org.opengis.referencing.datum.GeodeticDatum;
+import org.opengis.referencing.datum.PrimeMeridian;
+import org.opengis.referencing.datum.VerticalDatum;
+import org.opengis.util.FactoryException;
+import org.apache.sis.internal.system.Loggers;
+import org.apache.sis.referencing.crs.HardCodedCRS;
+import org.apache.sis.referencing.datum.HardCodedDatum;
+import org.apache.sis.util.logging.Logging;
+import org.apache.sis.test.LoggingWatcher;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests {@link MultiAuthoritiesFactory}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+@DependsOn(AuthorityFactoryProxyTest.class)
+public final strictfp class MultiAuthoritiesFactoryTest extends TestCase {
+    /**
+     * A JUnit {@linkplain Rule rule} for listening to log events. This field is public because
JUnit requires
+     * us to do so, but should be considered as an implementation details (it should have
been a private field).
+     */
+    @Rule
+    public final LoggingWatcher listener = new Listener();
+
+    /**
+     * Implementation of the {@link MultiAuthoritiesFactoryTest#listener} rule.
+     */
+    private static final class Listener extends LoggingWatcher {
+        /** Expected keywords in the log message. */
+        String[] expectedKeywords;
+
+        /** Creates a new log listener. */
+        Listener() {super(Logging.getLogger(Loggers.CRS_FACTORY));}
+
+        /** Verifies the log message. */
+        @Override protected void verifyMessage(final String message) {
+            assertTrue(message, message.contains("CRSAuthorityFactory"));
+            assertTrue(message, message.contains("AuthorityFactoryMock"));
+            for (final String keyword : expectedKeywords) {
+                assertTrue(message, message.contains(keyword));
+            }
+        }
+    }
+
+    /**
+     * Tests consistency of the mock factory used by other tests in this class.
+     *
+     * @throws FactoryException if no object was found for a code.
+     */
+    @Test
+    public void testAuthorityFactoryMock() throws FactoryException {
+        final AuthorityFactoryMock factory = new AuthorityFactoryMock("MOCK", null);
+        final Class<?>[] types = {
+            GeocentricCRS.class,
+            GeographicCRS.class,
+            GeodeticDatum.class,
+            VerticalDatum.class,
+            VerticalCRS.class,
+            GeodeticCRS.class,
+            PrimeMeridian.class,
+            Datum.class,
+            CoordinateReferenceSystem.class,
+            IdentifiedObject.class
+        };
+        for (final Class<?> type : types) {
+            for (final String code : factory.getAuthorityCodes(type.asSubclass(IdentifiedObject.class)))
{
+                assertInstanceOf(code, type, factory.createObject(code));
+            }
+        }
+    }
+
+    /**
+     * Tests {@link MultiAuthoritiesFactory#getCodeSpaces()}.
+     */
+    @Test
+    public void testGetCodeSpaces() {
+        final AuthorityFactoryMock mock1 = new AuthorityFactoryMock("MOCK1", "2.3");
+        final AuthorityFactoryMock mock2 = new AuthorityFactoryMock("MOCK2", null);
+        final AuthorityFactoryMock mock3 = new AuthorityFactoryMock("MOCK3", null);
+        final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(
+                Arrays.asList(mock1, mock2), null,
+                Arrays.asList(mock1, mock3), null);
+        assertSetEquals(Arrays.asList("MOCK1", "MOCK2", "MOCK3"), factory.getCodeSpaces());
+    }
+
+    /**
+     * Tests {@link MultiAuthoritiesFactory#getAuthorityFactory(Class, String, String)}.
+     *
+     * @throws NoSuchAuthorityFactoryException if an authority is not recognized.
+     */
+    @Test
+    public void testGetAuthorityFactory() throws NoSuchAuthorityFactoryException {
+        final AuthorityFactoryMock mock1 = new AuthorityFactoryMock("MOCK1", null);
+        final AuthorityFactoryMock mock2 = new AuthorityFactoryMock("MOCK2", "1.2");
+        final AuthorityFactoryMock mock3 = new AuthorityFactoryMock("MOCK1", "2.3");
+        final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(
+                Arrays.asList(mock1, mock2, mock3), null,
+                Arrays.asList(mock1, mock3), null);
+
+        assertSame("MOCK2", mock2, factory.getAuthorityFactory(  CRSAuthorityFactory.class,
"mock2", null));
+        assertSame("MOCK1", mock1, factory.getAuthorityFactory(  CRSAuthorityFactory.class,
"mock1", null));
+        assertSame("MOCK2", mock2, factory.getAuthorityFactory(  CRSAuthorityFactory.class,
"mock2", "1.2"));
+        assertSame("MOCK3", mock3, factory.getAuthorityFactory(  CRSAuthorityFactory.class,
"mock1", "2.3"));
+        assertSame("MOCK3", mock3, factory.getAuthorityFactory(DatumAuthorityFactory.class,
"mock1", "2.3"));
+        assertSame("MOCK1", mock1, factory.getAuthorityFactory(DatumAuthorityFactory.class,
"mock1", null));
+        try {
+            factory.getAuthorityFactory(DatumAuthorityFactory.class, "mock2", null);
+            fail("Should not have found a 'mock2' factory for datum objects.");
+        } catch (NoSuchAuthorityFactoryException e) {
+            final String message = e.getMessage();
+            assertTrue(message, message.contains("MOCK2"));
+        }
+        try {
+            factory.getAuthorityFactory(CRSAuthorityFactory.class, "mock1", "9.9");
+            fail("Should not have found a 'mock1' factory for the 9.9 version.");
+        } catch (NoSuchAuthorityFactoryException e) {
+            final String message = e.getMessage();
+            assertTrue(message, message.contains("MOCK1"));
+            assertTrue(message, message.contains("9.9"));
+        }
+    }
+
+    /**
+     * Tests {@link MultiAuthoritiesFactory#getAuthorityFactory(Class, String, String)}
+     * with a conflict in the factory namespace.
+     *
+     * @throws NoSuchAuthorityFactoryException if an authority is not recognized.
+     */
+    @Test
+    @DependsOnMethod("testGetAuthorityFactory")
+    public void testConflict() throws NoSuchAuthorityFactoryException {
+        final AuthorityFactoryMock mock1 = new AuthorityFactoryMock("MOCK1", "2.3");
+        final AuthorityFactoryMock mock2 = new AuthorityFactoryMock("MOCK1", "2.3");
+        final AuthorityFactoryMock mock3 = new AuthorityFactoryMock("MOCK3", "1.2");
+        final AuthorityFactoryMock mock4 = new AuthorityFactoryMock("MOCK3", null);
+        final AuthorityFactoryMock mock5 = new AuthorityFactoryMock("MOCK5", null);
+        final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(
+                Arrays.asList(mock1, mock2, mock3, mock4, mock5), null, null, null);
+
+        assertSame("MOCK1", mock1, factory.getAuthorityFactory(CRSAuthorityFactory.class,
"mock1", null));
+        assertSame("MOCK1", mock1, factory.getAuthorityFactory(CRSAuthorityFactory.class,
"mock1", "2.3"));
+
+        listener.maximumLogCount = 1;
+        ((Listener) listener).expectedKeywords = new String[] {"MOCK1", "2.3"};
+        assertSame("MOCK3", mock3, factory.getAuthorityFactory(CRSAuthorityFactory.class,
"mock3", null));
+        assertEquals("Expected a warning about the extraneous MOCK1 factory.", 0, listener.maximumLogCount);
+
+        listener.maximumLogCount = 1;
+        ((Listener) listener).expectedKeywords = new String[] {"MOCK3"};
+        assertSame("MOCK5", mock5, factory.getAuthorityFactory(CRSAuthorityFactory.class,
"mock5", null));
+        assertEquals("Expected a warning about the extraneous MOCK3 factory.", 0, listener.maximumLogCount);
+
+        // Ask again the same factories. No logging should be emitted now, because we already
logged.
+        assertSame("MOCK3", mock3, factory.getAuthorityFactory(CRSAuthorityFactory.class,
"mock3", null));
+        assertSame("MOCK5", mock5, factory.getAuthorityFactory(CRSAuthorityFactory.class,
"mock5", null));
+    }
+
+    /**
+     * Tests {@code MultiAuthoritiesFactory.createFoo(String)} from codes in the {@code "AUTHORITY:CODE"}
form.
+     * Tests also {@code "AUTHORITY:VERSION:CODE"}.
+     *
+     * @throws FactoryException if an authority or a code is not recognized.
+     */
+    @Test
+    public void testCreateFromSimpleCodes() throws FactoryException {
+        final Set<AuthorityFactoryMock> mock = Collections.singleton(new AuthorityFactoryMock("MOCK",
"2.3"));
+        final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(mock, null, mock,
null);
+
+        assertSame("Straight",      HardCodedCRS  .WGS84_φλ,  factory.createGeographicCRS("MOCK:4326"));
+        assertSame("With spaces",   HardCodedCRS  .WGS84,     factory.createGeographicCRS("
 mock :  84 "));
+        assertSame("With version",  HardCodedDatum.WGS84,     factory.createGeodeticDatum("mock:2.3:6326"));
+        assertSame("Empty version", HardCodedDatum.GREENWICH, factory.createPrimeMeridian("
MoCk :: 8901"));
+        assertSame("With spaces",   HardCodedCRS  .DEPTH,     factory.createVerticalCRS 
(" MoCk : : 9905"));
+        assertSame("Version 0",     HardCodedDatum.SPHERE,    factory.createGeodeticDatum("MOCK:
0:6047"));
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1725985&r1=1725984&r2=1725985&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Thu Jan 21 15:27:17 2016
@@ -179,6 +179,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.factory.CommonAuthorityFactoryTest.class,
     org.apache.sis.referencing.factory.AuthorityFactoryProxyTest.class,
     org.apache.sis.referencing.factory.IdentifiedObjectFinderTest.class,
+    org.apache.sis.referencing.factory.MultiAuthoritiesFactoryTest.class,
     org.apache.sis.referencing.factory.GIGS2001.class,
     org.apache.sis.referencing.factory.GIGS2002.class,
     org.apache.sis.referencing.factory.GIGS2003.class,




Mime
View raw message