sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1719093 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/factory/ test/java/org/apache/sis/referencing/factory/ test/java/org/apache/sis/test/suite/
Date Thu, 10 Dec 2015 15:15:38 GMT
Author: desruisseaux
Date: Thu Dec 10 15:15:38 2015
New Revision: 1719093

URL: http://svn.apache.org/viewvc?rev=1719093&view=rev
Log:
Add tests for IdentifiedObjectFinder.

Added:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/IdentifiedObjectFinderTest.java
  (with props)
Modified:
    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/IdentifiedObjectFinder.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.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/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=1719093&r1=1719092&r2=1719093&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 Dec 10 15:15:38 2015
@@ -83,9 +83,10 @@ public class CommonAuthorityFactory exte
     private static final String PREFIX = "CRS";
 
     /**
-     * Authority codes known to this factory, in the order they are declared in the WMS 1.3
specification.
+     * Authority codes known to this factory.
+     * We are better to declare first the codes that are most likely to be requested.
      */
-    private static final String[] CODES = {"1", "84", "83", "27", "88"};
+    private static final String[] CODES = {"84", "83", "27", "88", "1"};
 
     /**
      * The set of codes known to this factory. Created when first needed.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java?rev=1719093&r1=1719092&r2=1719093&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java
[UTF-8] Thu Dec 10 15:15:38 2015
@@ -304,20 +304,18 @@ public class IdentifiedObjectFinder {
     final IdentifiedObject createFromIdentifiers(final IdentifiedObject object) throws FactoryException
{
         final Citation authority = getAuthority();
         for (final Identifier id : object.getIdentifiers()) {
-            if (!Citations.identifierMatches(authority, id.getAuthority())) {
-                // The identifier is not for this authority. Looks the other ones.
-                continue;
-            }
-            final String code = IdentifiedObjects.toString(id);
-            final IdentifiedObject candidate;
-            try {
-                candidate = create(code);
-            } catch (NoSuchAuthorityCodeException e) {
-                // The identifier was not recognized. No problem, let's go on.
-                continue;
-            }
-            if (Utilities.deepEquals(candidate, object, COMPARISON_MODE)) {
-                return candidate;
+            if (Citations.identifierMatches(authority, id.getAuthority())) {
+                final String code = IdentifiedObjects.toString(id);
+                final IdentifiedObject candidate;
+                try {
+                    candidate = create(code);
+                } catch (NoSuchAuthorityCodeException e) {
+                    // The identifier was not recognized. No problem, let's go on.
+                    continue;
+                }
+                if (Utilities.deepEquals(candidate, object, COMPARISON_MODE)) {
+                    return candidate;
+                }
             }
         }
         return null;

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java?rev=1719093&r1=1719092&r2=1719093&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java
[UTF-8] Thu Dec 10 15:15:38 2015
@@ -27,6 +27,7 @@ import org.apache.sis.io.wkt.Convention;
 
 // Test imports
 import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
@@ -41,6 +42,7 @@ import static org.apache.sis.test.Metada
  * @version 0.7
  * @module
  */
+@DependsOn(org.apache.sis.referencing.CommonCRSTest.class)
 public final strictfp class CommonAuthorityFactoryTest extends TestCase {
     /**
      * The factory to test.

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/IdentifiedObjectFinderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/IdentifiedObjectFinderTest.java?rev=1719093&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/IdentifiedObjectFinderTest.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/IdentifiedObjectFinderTest.java
[UTF-8] Thu Dec 10 15:15:38 2015
@@ -0,0 +1,128 @@
+/*
+ * 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.Collections;
+import org.opengis.util.NameFactory;
+import org.opengis.util.FactoryException;
+import org.opengis.referencing.IdentifiedObject;
+import org.opengis.referencing.crs.CRSAuthorityFactory;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.crs.GeographicCRS;
+import org.apache.sis.internal.system.DefaultFactories;
+import org.apache.sis.referencing.crs.DefaultGeographicCRS;
+
+// Test imports
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests {@link IdentifiedObjectFinder}.
+ * This test uses {@link CommonAuthorityFactory} as a simple factory implementation.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+@DependsOn({CommonAuthorityFactoryTest.class, AuthorityFactoryProxyTest.class})
+public final strictfp class IdentifiedObjectFinderTest extends TestCase {
+    /**
+     * The factory to use for the test.
+     */
+    private GeodeticAuthorityFactory factory;
+
+    /**
+     * Initializes the factory to test.
+     */
+    public IdentifiedObjectFinderTest() {
+        factory = new CommonAuthorityFactory(DefaultFactories.forBuildin(NameFactory.class));
+    }
+
+    /**
+     * Tests the {@link IdentifiedObjectFinder#find(IdentifiedObject)} method.
+     *
+     * @throws FactoryException if the creation of a CRS failed.
+     */
+    @Test
+    public void testFind() throws FactoryException {
+        final GeographicCRS CRS84 = factory.createGeographicCRS("CRS:84");
+        final IdentifiedObjectFinder finder = factory.createIdentifiedObjectFinder(CoordinateReferenceSystem.class);
+        assertTrue("Newly created finder should default to full scan.", finder.isFullScanAllowed());
+
+        finder.setFullScanAllowed(false);
+        assertSame("Should find without the need for scan, since we can use the CRS:84 identifier.",
+                   CRS84, finder.find(CRS84));
+
+        finder.setFullScanAllowed(true);
+        assertSame("Allowing scanning should not make any difference for this CRS84 instance.",
+                   CRS84, finder.find(CRS84));
+        /*
+         * Same test than above, using a CRS without identifier.
+         * The intend is to force a full scan.
+         */
+        final CoordinateReferenceSystem search = new DefaultGeographicCRS(
+                Collections.singletonMap(DefaultGeographicCRS.NAME_KEY, CRS84.getName()),
+                CRS84.getDatum(), CRS84.getCoordinateSystem());
+        assertEqualsIgnoreMetadata(CRS84, search);              // Required condition for
next test.
+
+        finder.setFullScanAllowed(false);
+        assertNull("Should not find WGS84 without a full scan, since it does not contains
the CRS:84 identifier.",
+                   finder.find(search));
+
+        finder.setFullScanAllowed(true);
+        assertSame("A full scan should allow us to find WGS84, since it is equals ignoring
metadata to CRS:84.",
+                   CRS84, finder.find(search));
+
+        assertEquals("CRS:84", finder.findIdentifier(search));
+    }
+
+    /**
+     * Tests the {@link IdentifiedObjectFinder#find(IdentifiedObject)} method through the
finder provided by
+     * {@link ConcurrentAuthorityFactory}. The objects found are expected to be cached.
+     *
+     * @throws FactoryException if the creation of a CRS failed.
+     */
+    @Test
+    @DependsOnMethod("testFind")
+    public void testFindOnCachedInstance() throws FactoryException {
+        factory = new Cached(factory);
+        testFind();
+    }
+
+    /**
+     * An authority factory to be used by {@link IdentifiedObjectFinderTest#testFindOnCachedInstance()}.
+     */
+    private static final strictfp class Cached extends ConcurrentAuthorityFactory implements
CRSAuthorityFactory {
+        private final GeodeticAuthorityFactory factory;
+
+        public Cached(final GeodeticAuthorityFactory factory) {
+            super(factory.nameFactory);
+            this.factory = factory;
+        }
+
+        @Override
+        protected GeodeticAuthorityFactory createBackingStore() {
+            return factory;
+        }
+    }
+}

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

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/IdentifiedObjectFinderTest.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=1719093&r1=1719092&r2=1719093&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 Dec 10 15:15:38 2015
@@ -165,6 +165,9 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.crs.DefaultCompoundCRSTest.class,
     org.apache.sis.referencing.crs.HardCodedCRSTest.class,
 
+    org.apache.sis.referencing.StandardDefinitionsTest.class,
+    org.apache.sis.referencing.CommonCRSTest.class,
+    org.apache.sis.referencing.CRSTest.class,
     org.apache.sis.referencing.factory.GIGS3002.class,
     org.apache.sis.referencing.factory.GIGS3003.class,
     org.apache.sis.referencing.factory.GIGS3004.class,
@@ -172,9 +175,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.factory.GeodeticObjectFactoryTest.class,
     org.apache.sis.referencing.factory.CommonAuthorityFactoryTest.class,
     org.apache.sis.referencing.factory.AuthorityFactoryProxyTest.class,
-    org.apache.sis.referencing.StandardDefinitionsTest.class,
-    org.apache.sis.referencing.CommonCRSTest.class,
-    org.apache.sis.referencing.CRSTest.class,
+    org.apache.sis.referencing.factory.IdentifiedObjectFinderTest.class,
 
     org.apache.sis.io.wkt.MathTransformParserTest.class,
     org.apache.sis.io.wkt.GeodeticObjectParserTest.class,



Mime
View raw message