You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2021/07/13 11:07:36 UTC

[sis] branch geoapi-4.0 updated (351dbc1 -> 2f900ed)

This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git.


    from 351dbc1  Make canvas more robust to missing CRS information.
     new d7d208e  Fix broken tests.
     new 2f900ed  Downgrade from JUnit 5 to JUnit 4. The mix of JUnit 4 and 5 seems to cause some tests to be ignored. Full migration to JUnit 5 will be done later: https://issues.apache.org/jira/browse/SIS-457

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../factory/IdentifiedObjectFinder.java            | 24 +++++++++++--
 .../operation/builder/LinearizerTest.java          |  3 +-
 .../transform/ProjectiveTransformTest.java         | 39 +++++++++++++++++-----
 .../transform/TransformResultComparator.java       |  4 +--
 ide-project/NetBeans/build.xml                     |  1 +
 pom.xml                                            | 23 ++-----------
 storage/sis-sqlstore/pom.xml                       | 20 -----------
 .../apache/sis/internal/sql/feature/EWKBTest.java  | 36 ++++++++++++++++----
 .../internal/sql/feature/PostGISMappingTest.java   |  5 ++-
 9 files changed, 89 insertions(+), 66 deletions(-)

[sis] 01/02: Fix broken tests.

Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit d7d208e507963b4c03d48c5a0e2077fac1e7fc8e
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Jul 13 12:53:47 2021 +0200

    Fix broken tests.
---
 .../factory/IdentifiedObjectFinder.java            | 24 +++++++++++--
 .../operation/builder/LinearizerTest.java          |  3 +-
 .../transform/ProjectiveTransformTest.java         | 39 +++++++++++++++++-----
 .../transform/TransformResultComparator.java       |  4 +--
 4 files changed, 55 insertions(+), 15 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java
index 8858a50..a56ff63 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/IdentifiedObjectFinder.java
@@ -162,6 +162,12 @@ public class IdentifiedObjectFinder {
     boolean ignoreIdentifiers;
 
     /**
+     * {@code true} if the result can be restricted to a singleton.
+     * This is set by {@link #findSingleton(IdentifiedObject)} only.
+     */
+    private boolean wantSingleton;
+
+    /**
      * Creates a finder using the specified factory.
      *
      * <div class="note"><b>Design note:</b>
@@ -299,15 +305,23 @@ public class IdentifiedObjectFinder {
         ArgumentChecks.ensureNonNull("object", object);
         Set<IdentifiedObject> result = getFromCache(object);
         if (result == null) {
-            final AuthorityFactoryProxy<?> previous = proxy;
+            final boolean previousIgnoreAxes = ignoreAxes;
+            final AuthorityFactoryProxy<?> previousProxy = proxy;
             proxy = AuthorityFactoryProxy.getInstance(object.getClass());
             try {
-                if (!ignoreIdentifiers) {
+                /*
+                 * If user wants to ignore axes, we need to return all matches. We can not use the identifier
+                 * because it would reduce the set to a single element. Having all elements is necessary when
+                 * `CoordinateOperationRegistry` searches for a coordinate operation between a pair of CRS.
+                 * The only exception to this rule is when this method is invoked from `findSingleton(…)`.
+                 */
+                if (!ignoreIdentifiers && (!previousIgnoreAxes || wantSingleton)) {
                     /*
                      * First check if one of the identifiers can be used to find directly an identified object.
                      * Verify that the object that we found is actually equal to given one; we do not blindly
                      * trust the identifiers in the user object.
                      */
+                    ignoreAxes = false;
                     IdentifiedObject candidate = createFromIdentifiers(object);
                     if (candidate != null) {
                         return Collections.singleton(candidate);    // Not worth to cache.
@@ -331,7 +345,8 @@ public class IdentifiedObjectFinder {
                 }
                 result = createFromCodes(object);
             } finally {
-                proxy = previous;
+                proxy      = previousProxy;
+                ignoreAxes = previousIgnoreAxes;
             }
             result = cache(object, result);     // Costly operation (even if the result is empty) worth to cache.
         }
@@ -363,6 +378,7 @@ public class IdentifiedObjectFinder {
         IdentifiedObject result = null;
         boolean sameAxisOrder = false;
         boolean ambiguous = false;
+        wantSingleton = true;
         try {
             for (final IdentifiedObject candidate : find(object)) {
                 final boolean so = !ignoreAxes || Utilities.deepEquals(candidate, object, COMPARISON_MODE);
@@ -377,6 +393,8 @@ public class IdentifiedObjectFinder {
             }
         } catch (BackingStoreException e) {
             throw e.unwrapOrRethrow(FactoryException.class);
+        } finally {
+            wantSingleton = false;
         }
         return (sameAxisOrder || !ambiguous) ? result : null;
     }
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LinearizerTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LinearizerTest.java
index d3db170..9bb6553 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LinearizerTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LinearizerTest.java
@@ -24,6 +24,7 @@ import org.apache.sis.referencing.operation.transform.LinearTransform;
 import org.apache.sis.referencing.operation.HardCodedConversions;
 import org.apache.sis.geometry.Envelope2D;
 import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
@@ -38,7 +39,7 @@ import static org.junit.Assert.*;
  * @module
  */
 @DependsOn(LocalizationGridBuilderTest.class)
-public final strictfp class LinearizerTest {
+public final strictfp class LinearizerTest extends TestCase {
     /**
      * Tests {@link LinearTransformBuilder#approximate(MathTransform, Envelope)} on a transform created by
      * {@link LocalizationGridBuilder}. We verify that the {@link Linearizer#approximate(MathTransform,
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
index 45d13a5..32f2ee0 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.referencing.operation.transform;
 
+import org.opengis.util.FactoryException;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransform1D;
@@ -84,8 +85,8 @@ public strictfp class ProjectiveTransformTest extends AffineTransformTest {
                 MathTransform tr = pt.optimize();
                 if (tr != pt) {
                     /*
-                     * Opportunistically tests ScaledTransform together with ProjectiveTransform.
-                     * We takes ScaledTransform as a reference implementation since it is simpler.
+                     * Opportunistically tests `ScaleTransform` together with `ProjectiveTransform`.
+                     * We take `ScaleTransform` as a reference implementation because it is simpler.
                      */
                     tr = new TransformResultComparator(tr, pt, STRICT);
                 }
@@ -94,6 +95,18 @@ public strictfp class ProjectiveTransformTest extends AffineTransformTest {
         });
     }
 
+    /**
+     * Returns the transform without {@link TransformResultComparator} wrapper.
+     * The transform is the one computed by {@link ProjectiveTransform#optimize()}.
+     */
+    private MathTransform getOptimizedTransform() {
+        MathTransform tr = transform;
+        if (tr instanceof TransformResultComparator) {
+            tr = ((TransformResultComparator) tr).reference;
+        }
+        return tr;
+    }
+
     /*
      * Inherit all the tests from GeoAPI:
      *    - testIdentity1D()
@@ -113,12 +126,13 @@ public strictfp class ProjectiveTransformTest extends AffineTransformTest {
      * Tests {@link ProjectiveTransform#optimize()}. In particular this method verifies that a non-square matrix
      * that looks like diagonal is not confused with a real diagonal matrix.
      *
+     * @throws FactoryException if the transform can not be created.
      * @throws TransformException if a coordinate conversion failed.
      *
      * @since 0.7
      */
     @Test
-    public void testOptimize() throws TransformException {
+    public void testOptimize() throws FactoryException, TransformException {
         matrix = Matrices.create(5, 4, new double[] {
             2, 0, 0, 0,
             0, 3, 0, 0,
@@ -126,15 +140,15 @@ public strictfp class ProjectiveTransformTest extends AffineTransformTest {
             0, 0, 0, 5,
             0, 0, 0, 1
         });
-        transform = new ProjectiveTransform(matrix).optimize();
+        transform = mtFactory.createAffineTransform(matrix);
         assertInstanceOf("Non-diagonal matrix shall not be handled by ScaleTransform.", ProjectiveTransform.class, transform);
         verifyConsistency(1, 2, 3,   -3, -2, -1);
         /*
          * Remove the "problematic" row. The new transform should now be optimizable.
          */
         matrix = ((MatrixSIS) matrix).removeRows(3, 4);
-        transform = new ProjectiveTransform(matrix).optimize();
-        assertInstanceOf("Diagonal matrix should be handled by a specialized class.", ScaleTransform.class, transform);
+        transform = mtFactory.createAffineTransform(matrix);
+        assertInstanceOf("Diagonal matrix should be handled by a specialized class.", ScaleTransform.class, getOptimizedTransform());
         verifyConsistency(1, 2, 3,   -3, -2, -1);
     }
 
@@ -142,14 +156,15 @@ public strictfp class ProjectiveTransformTest extends AffineTransformTest {
      * Tests {@link ProjectiveTransform#optimize()} when the matrix defines a constant value.
      * Older SIS versions wrongly optimized this case as a translation.
      *
+     * @throws FactoryException if the transform can not be created.
      * @throws TransformException if a coordinate conversion failed.
      *
      * @since 1.1
      */
     @Test
-    public void testOptimizeConstant() throws TransformException {
+    public void testOptimizeConstant() throws FactoryException, TransformException {
         matrix = new Matrix2(0, 10, 0, 1);
-        transform = new ProjectiveTransform(matrix).optimize();
+        transform = mtFactory.createAffineTransform(matrix);
         Assert.assertMatrixEquals("Transform shall use the given matrix unmodified.",
                 matrix, ((LinearTransform) transform).getMatrix(), STRICT);
         verifyConsistency(1, 2, 3,   -3, -2, -1);
@@ -173,6 +188,12 @@ public strictfp class ProjectiveTransformTest extends AffineTransformTest {
      */
     @After
     public final void ensureImplementRightInterface() {
+        /*
+         * `TransformResultComparator.tested` is the `ProjectiveTransform` before call to `optimize()`.
+         * This is okay because `ProjectiveTransform.optimize()` is not expected to take in account all
+         * possible types, so the test would fail if checking its result. More complete optimizations
+         * are tested in the `LinearTransformTest` subclass.
+         */
         if (transform instanceof TransformResultComparator) {
             transform = ((TransformResultComparator) transform).tested;
         }
@@ -180,7 +201,7 @@ public strictfp class ProjectiveTransformTest extends AffineTransformTest {
          * Below is a copy of MathTransformTestCase.validate(), with minor modifications
          * due to the fact that this class does not extend MathTransformTestCase.
          */
-        assertNotNull("The 'transform' field shall be assigned a value.", transform);
+        assertNotNull("The `transform` field shall be assigned a value.", transform);
         Validators.validate(transform);
         final int dimension = transform.getSourceDimensions();
         if (transform.getTargetDimensions() == dimension && !skipInterfaceCheckForDimension(dimension)) {
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformResultComparator.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformResultComparator.java
index 569f16c..ca59ed4 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformResultComparator.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformResultComparator.java
@@ -31,7 +31,7 @@ import static org.opengis.test.Assert.*;
  * Compares the results of two {@link MathTransform} implementations.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 1.1
  * @since   0.7
  * @module
  */
@@ -39,7 +39,7 @@ final strictfp class TransformResultComparator implements MathTransform {
     /**
      * The transform to be used as the reference.
      */
-    private final MathTransform reference;
+    final MathTransform reference;
 
     /**
      * The transform to be compared with the {@link #reference} one.

[sis] 02/02: Downgrade from JUnit 5 to JUnit 4. The mix of JUnit 4 and 5 seems to cause some tests to be ignored. Full migration to JUnit 5 will be done later: https://issues.apache.org/jira/browse/SIS-457

Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 2f900edbfc41fb90fcb3c40952529faeafd5b085
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Jul 13 12:56:07 2021 +0200

    Downgrade from JUnit 5 to JUnit 4. The mix of JUnit 4 and 5 seems to cause some tests to be ignored.
    Full migration to JUnit 5 will be done later: https://issues.apache.org/jira/browse/SIS-457
---
 ide-project/NetBeans/build.xml                     |  1 +
 pom.xml                                            | 23 ++------------
 storage/sis-sqlstore/pom.xml                       | 20 ------------
 .../apache/sis/internal/sql/feature/EWKBTest.java  | 36 +++++++++++++++++-----
 .../internal/sql/feature/PostGISMappingTest.java   |  5 ++-
 5 files changed, 34 insertions(+), 51 deletions(-)

diff --git a/ide-project/NetBeans/build.xml b/ide-project/NetBeans/build.xml
index d17f099..cfc5e9b 100644
--- a/ide-project/NetBeans/build.xml
+++ b/ide-project/NetBeans/build.xml
@@ -291,6 +291,7 @@
       </fileset>
       <fileset dir="${project.root}/storage/sis-sqlstore/src/test/resources">
         <include name="**/*.sql"/>
+        <include name="**/*.csv"/>
       </fileset>
       <fileset dir="${project.root}/storage/sis-earth-observation/src/test/resources">
         <include name="**/*.txt"/>
diff --git a/pom.xml b/pom.xml
index 61cd1bd..cbe0974 100644
--- a/pom.xml
+++ b/pom.xml
@@ -432,12 +432,6 @@
         <artifactId>geoapi-conformance</artifactId>
         <version>${geoapi.version}</version>
         <scope>test</scope>
-        <exclusions>            <!-- TODO: remove this exclusion after migration to JUnit 5. -->
-          <exclusion>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-          </exclusion>
-        </exclusions>
       </dependency>
 
       <!-- Libraries (language, XML, network) -->
@@ -535,22 +529,9 @@
            Dependencies to be inherited by all modules.
        =========================================================== -->
   <dependencies>
-    <!--
-      Unit test declaration. Embed aggregator dependency + retrocompatibility artifact ('vintage').
-      The later won't be needed anymore once all JUnit tests have been upgraded to new JUnit version.
-      TODO: remove <version>5.5.2</version> after complete migration to JUnit 5 (dependency version
-      will be inherited from GeoAPI).
-    -->
     <dependency>
-      <groupId>org.junit.jupiter</groupId>
-      <artifactId>junit-jupiter</artifactId>
-      <version>5.8.0-M1</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.junit.vintage</groupId>
-      <artifactId>junit-vintage-engine</artifactId>
-      <version>5.8.0-M1</version>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>   <!-- To be removed after https://issues.apache.org/jira/browse/SIS-469 is done. -->
diff --git a/storage/sis-sqlstore/pom.xml b/storage/sis-sqlstore/pom.xml
index 86d7cc4..17ccd49 100644
--- a/storage/sis-sqlstore/pom.xml
+++ b/storage/sis-sqlstore/pom.xml
@@ -92,26 +92,6 @@
           </archive>
         </configuration>
       </plugin>
-
-
-      <!-- Execute individual tests instead of test suites, to allow JUnit 5 use. -->
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <version>3.0.0-M4</version>
-        <configuration>
-          <includes>
-            <include>**/*Test.java</include>
-          </includes>
-          <systemProperties>
-            <property>
-              <name>derby.stream.error.file</name>
-              <value>${project.build.directory}/derby.log</value>
-            </property>
-          </systemProperties>
-        </configuration>
-      </plugin>
-
     </plugins>
   </build>
 
diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/EWKBTest.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/EWKBTest.java
index 9653e34..d4ff045 100644
--- a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/EWKBTest.java
+++ b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/EWKBTest.java
@@ -1,6 +1,9 @@
 package org.apache.sis.internal.sql.feature;
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
 
 import org.opengis.referencing.crs.GeographicCRS;
 
@@ -9,22 +12,18 @@ import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.setup.GeometryLibrary;
 import org.apache.sis.test.TestCase;
 
-import org.junit.Assert;
 import org.junit.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.CsvFileSource;
+import static org.junit.Assert.*;
 
 
 public class EWKBTest extends TestCase {
 
     public static final Geometries<?> GF = Geometries.implementation(GeometryLibrary.JTS);
 
-    @ParameterizedTest
-    @CsvFileSource(resources = "hexa_ewkb_4326.csv", numLinesToSkip = 1, delimiter = '\t')
     public void decodeHexadecimal(String wkt, String hexEWKB) throws Exception {
         final GeographicCRS expectedCrs = CommonCRS.defaultGeographic();
         final EWKBReader reader = new EWKBReader(GF).forCrs(expectedCrs);
-        Assert.assertEquals("WKT and hexadecimal EWKB representation don't match",
+        assertEquals("WKT and hexadecimal EWKB representation don't match",
                 GF.parseWKT(wkt).implementation(), reader.readHexa(hexEWKB));
     }
 
@@ -46,6 +45,29 @@ public class EWKBTest extends TestCase {
         point.position(0);
 
         final Object read = new EWKBReader(GeometryLibrary.JTS).read(point);
-        Assert.assertEquals(GF.createPoint(42.2, 43.3), read);
+        assertEquals(GF.createPoint(42.2, 43.3), read);
+    }
+
+    /**
+     * Temporary test for simulating JUnit 5 execution of {@link #decodeHexadecimal(String, String)}
+     * as a parameterized test. To be removed after migration to JUnit 5.
+     *
+     * @throws Exception if test file can not be decoded.
+     */
+    @Test
+    public void testDecodeHexadecimal() throws Exception {
+        try (final BufferedReader in = new BufferedReader(new InputStreamReader(
+                EWKBTest.class.getResourceAsStream("hexa_ewkb_4326.csv"), StandardCharsets.UTF_8)))
+        {
+            String line;
+            int numLinesToSkip = 1;
+            while ((line = in.readLine()) != null) {
+                if (!(line = line.trim()).isEmpty() && line.charAt(0) != '#' && --numLinesToSkip < 0) {
+                    final String[] columns = line.split("\t");
+                    assertEquals(2, columns.length);
+                    decodeHexadecimal(columns[0], columns[1]);
+                }
+            }
+        }
     }
 }
diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/PostGISMappingTest.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/PostGISMappingTest.java
index 9b78aca..15a412c 100644
--- a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/PostGISMappingTest.java
+++ b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/PostGISMappingTest.java
@@ -1,10 +1,9 @@
 package org.apache.sis.internal.sql.feature;
 
-import org.junit.jupiter.api.Test;
+import org.junit.Test;
 
 import static org.apache.sis.internal.sql.feature.PostGISMapping.verifyVersion;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.Assert.*;
 
 public class PostGISMappingTest {