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 2022/12/07 17:36:35 UTC
[sis] 01/03: Fix test failure when running tests on PostgreSQL without EPSG dataset.
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 f51c5514629837509983e71111d98a12e276b28c
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Dec 7 14:05:10 2022 +0100
Fix test failure when running tests on PostgreSQL without EPSG dataset.
---
.../report/CoordinateOperationMethods.java | 4 ++--
.../internal/sql/feature/GeometryGetterTest.java | 19 ++++++++++++++-----
.../sis/internal/sql/postgis/PostgresTest.java | 21 ++++++++++++++++-----
3 files changed, 32 insertions(+), 12 deletions(-)
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java
index ac5e31516f..22313e785d 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java
@@ -68,7 +68,7 @@ import org.opengis.metadata.Identifier;
* first, no HTML characters to escape in non-EPSG identifiers, etc.).</p>
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.3
* @since 0.6
* @module
*/
@@ -556,7 +556,7 @@ public strictfp class CoordinateOperationMethods extends HTMLGenerator {
if (id == null) {
id = method.getName().getCode();
}
- return id.replace(" ", "_");
+ return id.replace(" ", "_").replace("(", "").replace(")", "");
}
/**
diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/GeometryGetterTest.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/GeometryGetterTest.java
index 95ccb22d9b..3657071482 100644
--- a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/GeometryGetterTest.java
+++ b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/GeometryGetterTest.java
@@ -22,6 +22,7 @@ import java.sql.Statement;
import java.sql.ResultSet;
import org.opengis.util.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.apache.sis.internal.feature.Geometries;
import org.apache.sis.internal.feature.GeometryWrapper;
import org.apache.sis.internal.feature.GeometryWithCRS;
@@ -43,7 +44,7 @@ import static org.junit.Assert.*;
*
* @author Alexis Manin (Geomatys)
* @author Martin Desruisseaux (Geomatys)
- * @version 1.2
+ * @version 1.3
* @since 1.1
* @module
*/
@@ -144,8 +145,10 @@ public strictfp final class GeometryGetterTest extends TestCase {
final Geometry geometry = (Geometry) reader.getValue(fromSridToCRS, results, 2);
final GeometryWrapper<?> expected = GF.parseWKT(wkt);
assertEquals("WKT and WKB parsings gave different results.", expected.implementation(), geometry);
- assertSame("SRID", getExpectedCRS(results.getInt(3)),
- GF.castOrWrap(geometry).getCoordinateReferenceSystem());
+ final CoordinateReferenceSystem expectedCRS = getExpectedCRS(results.getInt(3));
+ if (expectedCRS != null) {
+ assertSame("SRID", expectedCRS, GF.castOrWrap(geometry).getCoordinateReferenceSystem());
+ }
}
}
}
@@ -157,14 +160,20 @@ public strictfp final class GeometryGetterTest extends TestCase {
* used for the test. Other databases may have different mapping.
*
* @param srid the SRID for which to get the CRS.
- * @return the CRS for the given SRID.
+ * @return the CRS for the given SRID, or {@code null} if not available.
* @throws FactoryException if an error occurred while fetching the CRS.
*/
public static CoordinateReferenceSystem getExpectedCRS(final int srid) throws FactoryException {
+ final String code;
switch (srid) {
- case 3395: return CRS.forCode("EPSG:3395");
+ case 3395: code = "EPSG:3395"; break;
case 4326: return CommonCRS.WGS84.normalizedGeographic();
default: throw new AssertionError(srid);
}
+ try {
+ return CRS.forCode(code);
+ } catch (NoSuchAuthorityCodeException ignore) {
+ return null; // No EPSG database available.
+ }
}
}
diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/postgis/PostgresTest.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/postgis/PostgresTest.java
index abcf98d4f1..0c86f82300 100644
--- a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/postgis/PostgresTest.java
+++ b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/postgis/PostgresTest.java
@@ -26,6 +26,8 @@ import java.lang.reflect.Method;
import java.util.stream.Stream;
import org.opengis.geometry.Envelope;
import org.opengis.util.FactoryException;
+import org.opengis.referencing.crs.ProjectedCRS;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.apache.sis.setup.OptionKey;
import org.apache.sis.setup.GeometryLibrary;
import org.apache.sis.storage.FeatureSet;
@@ -39,7 +41,6 @@ import org.apache.sis.internal.storage.io.ChannelDataInput;
import org.apache.sis.internal.sql.feature.BinaryEncoding;
import org.apache.sis.internal.sql.feature.GeometryGetterTest;
import org.apache.sis.internal.feature.jts.JTS;
-import org.apache.sis.referencing.CRS;
import org.apache.sis.referencing.CommonCRS;
import org.apache.sis.referencing.crs.HardCodedCRS;
import org.apache.sis.test.sql.TestDatabase;
@@ -55,7 +56,7 @@ import org.opengis.feature.Feature;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Geometry;
-import static org.junit.Assert.*;
+import static org.opengis.test.Assert.*;
/**
@@ -63,7 +64,7 @@ import static org.junit.Assert.*;
*
* @author Alexis Manin (Geomatys)
* @author Martin Desruisseaux (Geomatys)
- * @version 1.2
+ * @version 1.3
* @since 1.1
* @module
*/
@@ -128,7 +129,12 @@ public final strictfp class PostgresTest extends TestCase {
*/
private static void testInfoStatements(final ExtendedInfo info) throws Exception {
assertEquals("findSRID", 4326, info.findSRID(HardCodedCRS.WGS84));
- assertSame("fetchCRS", CRS.forCode("EPSG:3395"), info.fetchCRS(3395));
+ final CoordinateReferenceSystem expected = GeometryGetterTest.getExpectedCRS(3395);
+ final CoordinateReferenceSystem actual = info.fetchCRS(3395);
+ assertInstanceOf("findSRID", ProjectedCRS.class, actual);
+ if (expected != null) {
+ assertSame("fetchCRS", expected, actual);
+ }
}
/**
@@ -192,7 +198,12 @@ public final strictfp class PostgresTest extends TestCase {
default: throw new AssertionError(filename);
}
try {
- assertEquals(GeometryGetterTest.getExpectedCRS(geomSRID), JTS.getCoordinateReferenceSystem(geometry));
+ final CoordinateReferenceSystem expected = GeometryGetterTest.getExpectedCRS(geomSRID);
+ final CoordinateReferenceSystem actual = JTS.getCoordinateReferenceSystem(geometry);
+ assertNotNull(actual);
+ if (expected != null) {
+ assertEquals(expected, actual);
+ }
} catch (FactoryException e) {
throw new AssertionError(e);
}