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 d438a0d1b60f5d185c2b0297ac2a84cc53c44e59 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Dec 6 18:50:47 2022 +0100 Fix JUnit test failures when the tests are run without EPSG database. --- .../org/apache/sis/console/CRSCommandTest.java | 14 ++++++----- .../sis/internal/simple/CitationConstant.java | 12 ++++++++-- .../java/org/apache/sis/xml/NilObjectHandler.java | 7 +++--- .../sis/referencing/GeodeticObjectVerifier.java | 6 ++--- .../factory/CommonAuthorityFactoryTest.java | 27 ++++++++++++++-------- pom.xml | 2 +- 6 files changed, 43 insertions(+), 25 deletions(-) diff --git a/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java b/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java index afc92ed5ce..63b572a08c 100644 --- a/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java +++ b/application/sis-console/src/test/java/org/apache/sis/console/CRSCommandTest.java @@ -29,7 +29,7 @@ import static org.junit.Assert.*; * Tests the {@link CRSCommand} sub-command. * * @author Martin Desruisseaux (Geomatys) - * @version 1.0 + * @version 1.3 * @since 0.8 * @module */ @@ -46,18 +46,20 @@ public final strictfp class CRSCommandTest extends TestCase { * Creates a new test. */ public CRSCommandTest() { - WGS84 = - "\\QGeodeticCRS[\"WGS 84\",\n" + + final String name = "\"WGS\\E\\s?(?:19)?\\Q84\""; // Accept "WGS 84" or "WGS 1984". + WGS84 = "(?m)\\Q" + // Multilines. + "GeodeticCRS[" + name + ",\n" + " Datum[\"World Geodetic System 1984\",\n" + - " Ellipsoid[\"WGS 84\", 6378137.0, 298.257223563]],\n" + + " Ellipsoid[" + name + ", 6378137.0, 298.257223563]],\n" + " CS[ellipsoidal, 2],\n" + " Axis[\"Latitude (B)\", north],\n" + " Axis[\"Longitude (L)\", east],\n" + " Unit[\"degree\", 0.017453292519943295],\n" + - " Scope[\"Horizontal component of 3D system.\\E.*\\Q\"],\n" + // EPSG geodetic dataset provides more details here. + "\\E(?: Scope\\[\".+\"\\],\n)?\\Q" + // Ignore SCOPE[…] if present. " Area[\"\\E.*\\Q\"],\n" + // Language may vary because of SIS localization. " BBox[-90.00, -180.00, 90.00, 180.00],\n" + - " Id[\"EPSG\", 4326,\\E.*\\Q URI[\"urn:ogc:def:crs:EPSG:\\E.*\\Q:4326\"]]]\n\\E"; // Version number of EPSG dataset may vary. + " Id[\"EPSG\", 4326,\\E.*\\Q URI[\"urn:ogc:def:crs:EPSG:\\E.*\\Q:4326\"]]" + // Version number of EPSG dataset may vary. + "\\E(?:,\n Remark\\[\".+\"\\])?\\]\n"; // Ignore trailing REMARK[…] if present. /* * Insert the native line separator in the expected string. We modify the expected string * instead of modifying the `test.outputBuffer` result because we want to verify that the diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/simple/CitationConstant.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/simple/CitationConstant.java index 34095c93f9..ee0d2641f5 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/internal/simple/CitationConstant.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/simple/CitationConstant.java @@ -46,7 +46,7 @@ import static java.util.logging.Logger.getLogger; * is available, then that simple primary key will be used as the citation title. * * @author Martin Desruisseaux (Geomatys) - * @version 1.0 + * @version 1.3 * * @see IdentifierSpace * @see Citations @@ -193,12 +193,20 @@ public class CitationConstant extends SimpleCitation { return c; } + /** + * Returns the title, which is mandatory. + */ + @Override + public InternationalString getTitle() { + InternationalString title = delegate().getTitle(); + return (title != null) ? title : super.getTitle(); + } + /** * Redirects the call to the delegate citation (the instance which actually contain the data). * * @return the value returned by the delegate. */ - @Override public InternationalString getTitle() {return delegate().getTitle();} @Override public Collection<? extends InternationalString> getAlternateTitles() {return delegate().getAlternateTitles();} @Override public Collection<? extends CitationDate> getDates() {return delegate().getDates();} @Override public InternationalString getEdition() {return delegate().getEdition();} diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/NilObjectHandler.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/NilObjectHandler.java index 4cb46aeeb6..d06fac68c8 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/xml/NilObjectHandler.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/NilObjectHandler.java @@ -20,6 +20,7 @@ import java.util.Map; import java.util.List; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Objects; import java.lang.reflect.Proxy; import java.lang.reflect.Method; @@ -47,7 +48,7 @@ import org.apache.sis.internal.jaxb.ModifiableIdentifierMap; * For now, it doesn't seem worth to cache the handlers.</div> * * @author Martin Desruisseaux (Geomatys) - * @version 0.3 + * @version 1.3 * @since 0.3 * @module */ @@ -130,11 +131,11 @@ final class NilObjectHandler implements InvocationHandler { return (attribute instanceof NilReason) ? (NilReason) attribute : null; } case "getIdentifierMap": { - return (attribute instanceof IdentifierMap) ? (IdentifierMap) attribute : null; + return (attribute instanceof IdentifierMap) ? (IdentifierMap) attribute : Collections.emptyMap(); } case "getIdentifiers": { return (attribute instanceof IdentifierMapAdapter) ? - ((IdentifierMapAdapter) attribute).getIdentifiers(method.getReturnType()) : null; + ((IdentifierMapAdapter) attribute).getIdentifiers(method.getReturnType()) : Collections.emptyList(); } case "toString": { return Strings.bracket(getInterface(proxy), attribute); diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectVerifier.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectVerifier.java index a5ca080a42..51b22b649f 100644 --- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectVerifier.java +++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectVerifier.java @@ -42,7 +42,7 @@ import static org.apache.sis.test.Assert.*; * because IOGP allows implementations to modify non-essential properties. * * @author Martin Desruisseaux (Geomatys) - * @version 0.8 + * @version 1.3 * @since 0.4 * @module * @@ -181,8 +181,8 @@ public final strictfp class GeodeticObjectVerifier { * @param ellipsoid the ellipsoid to verify. */ public static void assertIsWGS84(final Ellipsoid ellipsoid) { - assertEquals("name", "WGS 84", ellipsoid.getName().getCode()); - assertEquals("axisUnit", Units.METRE, ellipsoid.getAxisUnit()); + assertTrue ("name", ellipsoid.getName().getCode().matches("WGS\\s?(?:19)?84")); + assertEquals("axisUnit", Units.METRE, ellipsoid.getAxisUnit()); assertEquals("semiMajorAxis", 6378137, ellipsoid.getSemiMajorAxis(), STRICT); assertEquals("semiMinorAxis", 6356752.314245179, ellipsoid.getSemiMinorAxis(), 0.001); assertEquals("inverseFlattening", 298.257223563, ellipsoid.getInverseFlattening(), STRICT); diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java index 310db89267..4217d64240 100644 --- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java +++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/CommonAuthorityFactoryTest.java @@ -234,8 +234,12 @@ public final strictfp class CommonAuthorityFactoryTest extends TestCase { assertSame("When the given parameters match exactly the UTM central meridian and latitude of origin," + " the CRS created by AUTO:42002 should be the same than the CRS created by AUTO:42001.", crs, factory.createProjectedCRS("AUTO2:42002,1,-123,0")); - - assertEpsgNameAndIdentifierEqual("WGS 84 / UTM zone 10N", 32610, crs); + /* + * Do not use `assertEpsgNameAndIdentifierEqual(…)` because the "EPSG" authority is missing + * (actually is "Subset of EPSG") if the CRS was built from the fallback factory. + */ + assertEquals("name", "WGS 84 / UTM zone 10N", crs.getName().getCode()); + assertEquals("identifier", "32610", getSingleton(crs.getIdentifiers()).getCode()); final ParameterValueGroup p = crs.getConversionFromBase().getParameterValues(); assertEquals(TransverseMercator.NAME, crs.getConversionFromBase().getMethod().getName().getCode()); assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH); @@ -368,30 +372,33 @@ public final strictfp class CommonAuthorityFactoryTest extends TestCase { @Test @DependsOnMethod("testCRS84") public void testWKT() throws FactoryException { + final String WGS84 = "“WGS\\E\\s?(?:19)?\\Q84”"; // Accept "WGS 84" or "WGS 1984" GeographicCRS crs = factory.createGeographicCRS("CRS:84"); - assertWktEquals(Convention.WKT1, - "GEOGCS[“WGS 84”,\n" + + assertWktEqualsRegex(Convention.WKT1, "(?m)\\Q" + // Multilines + "GEOGCS[" + WGS84 + ",\n" + " DATUM[“World Geodetic System 1984”,\n" + - " SPHEROID[“WGS 84”, 6378137.0, 298.257223563]],\n" + + " SPHEROID[" + WGS84 + ", 6378137.0, 298.257223563]],\n" + " PRIMEM[“Greenwich”, 0.0],\n" + " UNIT[“degree”, 0.017453292519943295],\n" + " AXIS[“Longitude”, EAST],\n" + " AXIS[“Latitude”, NORTH],\n" + - " AUTHORITY[“CRS”, “84”]]", crs); + " AUTHORITY[“CRS”, “84”]]\\E", crs); assertWktEqualsRegex(Convention.WKT2, "(?m)\\Q" + - "GEODCRS[“WGS 84”,\n" + + "GEODCRS[" + WGS84 + ",\n" + " DATUM[“World Geodetic System 1984”,\n" + - " ELLIPSOID[“WGS 84”, 6378137.0, 298.257223563, LENGTHUNIT[“metre”, 1]]],\n" + + " ELLIPSOID[" + WGS84 + ", 6378137.0, 298.257223563, LENGTHUNIT[“metre”, 1]]],\n" + " PRIMEM[“Greenwich”, 0.0, ANGLEUNIT[“degree”, 0.017453292519943295]],\n" + " CS[ellipsoidal, 2],\n" + " AXIS[“Longitude (L)”, east, ORDER[1]],\n" + " AXIS[“Latitude (B)”, north, ORDER[2]],\n" + " ANGLEUNIT[“degree”, 0.017453292519943295],\n" + - " SCOPE[“Horizontal component of 3D system.\\E.*\\Q”],\n" + + "\\E(?: SCOPE\\[“.+”\\],\n)?\\Q" + // Ignore SCOPE[…] if present. " AREA[“World\\E.*\\Q”],\n" + " BBOX[-90.00, -180.00, 90.00, 180.00],\n" + - " ID[“CRS”, 84, CITATION[“OGC:WMS”], URI[“urn:ogc:def:crs:OGC:1.3:CRS84”]]]\\E", crs); + " ID[“CRS”, 84, CITATION[“OGC:WMS”], URI[“urn:ogc:def:crs:OGC:1.3:CRS84”]]" + + "\\E(?:,\n REMARK\\[“.+”\\])?\\]", // Ignore trailing REMARK[…] if present. + crs); /* * Note: the WKT specification defines the ID element as: * diff --git a/pom.xml b/pom.xml index aaed720b9d..e4b29020f4 100644 --- a/pom.xml +++ b/pom.xml @@ -890,7 +890,7 @@ </group> <group> <title>Applications</title> - <packages>org.apache.sis.console*:org.apache.sis.services*</packages> + <packages>org.apache.sis.gui*:org.apache.sis.console*:org.apache.sis.services*:org.apache.sis.openoffice*</packages> </group> <group> <title>Data storage</title>