This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new 2f3d1e0e3c Add `URISourceTest` for making sure that `isChildOfBase()`
does not wrongly accept a file with the same path but different hosts. Also
paid more attention to the logs of all tests doing XML (un)marshalling in order
to reduce the risk of unnoticed issues.
2f3d1e0e3c is described below
commit 2f3d1e0e3ceab3e4ca89827690d8aa877d3dbc2f
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Fri Nov 20 12:30:52 2026 +0100
Add `URISourceTest` for making sure that `isChildOfBase()` does not wrongly
accept a file with the same path but different hosts.
Also paid more attention to the logs of all tests doing XML (un)marshalling
in order to reduce the risk of unnoticed issues.
---
.../main/org/apache/sis/xml/ReferenceResolver.java | 1 +
.../org/apache/sis/xml/bind/TypeRegistration.java | 12 +-
.../xml/internal/shared/ExternalLinkHandler.java | 16 ++-
.../apache/sis/xml/internal/shared/URISource.java | 21 +++-
.../apache/sis/metadata/iso/MarshallingTest.java | 58 ++++-----
.../metadata/iso/citation/DefaultContactTest.java | 65 ++++------
.../org/apache/sis/metadata/xml/TestUsingFile.java | 14 ++-
.../org/apache/sis/xml/ReferenceResolverTest.java | 33 ++----
.../org/apache/sis/xml/XLinkMarshallingTest.java | 44 +++++--
.../apache/sis/xml/bind/gml/TimePeriodTest.java | 2 +-
.../sis/xml/internal/shared/URISourceTest.java | 68 +++++++++++
.../apache/sis/xml/test/DocumentComparator.java | 8 +-
.../test/org/apache/sis/xml/test/TestCase.java | 132 ++++++++++++++++++---
.../xml/bind/fra/DirectReferenceSystemTest.java | 6 +-
.../operation/transform/InterpolatedTransform.java | 4 +-
.../sis/parameter/ParameterMarshallingTest.java | 26 ++--
.../sis/referencing/ImmutableIdentifierTest.java | 12 +-
.../referencing/crs/DefaultCompoundCRSTest.java | 5 +-
.../referencing/crs/DefaultEngineeringCRSTest.java | 1 +
.../referencing/crs/DefaultProjectedCRSTest.java | 13 ++
.../referencing/datum/DefaultEllipsoidTest.java | 7 +-
.../datum/DefaultPrimeMeridianTest.java | 13 +-
.../datum/DefaultTemporalDatumTest.java | 2 +-
.../datum/DefaultVerticalDatumTest.java | 2 +-
.../operation/SingleOperationMarshallingTest.java | 18 +--
.../apache/sis/test/integration/MetadataTest.java | 2 +
.../sis/test/integration/MetadataVerticalTest.java | 1 +
.../CC_GeneralOperationParameterTest.java | 27 +++--
.../CC_OperationParameterGroupTest.java | 4 +-
.../main/org/apache/sis/system/DataURI.java | 3 +-
.../sis/util/resources/IndexedResourceBundle.java | 3 -
31 files changed, 425 insertions(+), 198 deletions(-)
diff --git
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/ReferenceResolver.java
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/ReferenceResolver.java
index da0088b8be..5af5473968 100644
---
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/ReferenceResolver.java
+++
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/ReferenceResolver.java
@@ -221,6 +221,7 @@ public class ReferenceResolver {
reasonIfNull = Errors.Keys.CanNotResolveAsAbsolutePath_1;
object = null;
} else {
+ // Access control verified by the default implementation of
`resolveExternal(…)`.
object = resolveExternal(context, source);
reasonIfNull = 0;
}
diff --git
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/TypeRegistration.java
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/TypeRegistration.java
index 57216c6496..263db54e74 100644
---
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/TypeRegistration.java
+++
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/TypeRegistration.java
@@ -152,11 +152,11 @@ public abstract class TypeRegistration {
* @return all input streams.
*/
public static synchronized Supplier<InputStream>
getRenameDefinitionsFiles(final boolean export, final String filename) {
- final Iterator<TypeRegistration> services = services().iterator();
+ final Iterator<TypeRegistration> it = services().iterator();
return () -> {
synchronized (TypeRegistration.class) {
- while (services.hasNext()) {
- final Optional<InputStream> next =
services.next().getRenameDefinitionsFile(export, filename);
+ while (it.hasNext()) {
+ final Optional<InputStream> next =
it.next().getRenameDefinitionsFile(export, filename);
if (next.isPresent()) return next.get();
}
return null;
@@ -199,8 +199,8 @@ public abstract class TypeRegistration {
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private static Class<?>[] load(final boolean getTypes) {
- final ArrayList<Class<?>> types = new ArrayList<>();
- final ArrayList<UnaryOperator<Object>> toImpl = new ArrayList<>();
+ final var types = new ArrayList<Class<?>>();
+ final var toImpl = new ArrayList<UnaryOperator<Object>>();
for (final TypeRegistration t : services()) {
if (getTypes) t.getTypes(types);
final UnaryOperator<Object> c = t.beforeMarshal();
@@ -259,7 +259,7 @@ public abstract class TypeRegistration {
if (properties == null) {
return Map.of(ROOT_ADAPTERS, c);
}
- final Map<String,Object> copy = new HashMap<>(properties);
+ final var copy = new HashMap<String, Object>(properties);
copy.put(ROOT_ADAPTERS, c);
return copy;
}
diff --git
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/internal/shared/ExternalLinkHandler.java
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/internal/shared/ExternalLinkHandler.java
index 4ed4e850f5..74890f558a 100644
---
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/internal/shared/ExternalLinkHandler.java
+++
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/internal/shared/ExternalLinkHandler.java
@@ -129,6 +129,8 @@ public class ExternalLinkHandler {
/**
* Returns the base URI of the link handler. The returned object may be an
instance of
* {@link String}, {@link File}, {@link URL} or {@link URI}, or it may be
{@code null}.
+ * If the base is a file rather than a directory, then it is considered as
a sibling,
+ * i.e. the file's directory will be used as the base.
*
* @return the base <abbr>URI</abbr>, or {@code null}.
*/
@@ -153,8 +155,8 @@ public class ExternalLinkHandler {
}
/**
- * Returns the base URI of the link handler. This is the same value as
{@link #getBase()},
- * but converted to an {@link URI} object when first invoked.
+ * Returns the base or sibling <abbr>URI</abbr> of the link handler.
+ * This is the same value as {@link #getBase()}, but converted to an
{@link URI} object when first invoked.
*
* @return the base URI of the link handler, or {@code null} if none.
*/
@@ -189,7 +191,7 @@ public class ExternalLinkHandler {
}
/**
- * Reports a warning about a URI that cannot be parsed.
+ * Reports a warning about an <abbr>URI</abbr> that cannot be parsed.
* This method declares {@link ReferenceResolver} as the public source of
the warning.
* The latter assumption is valid if {@code ReferenceResolver.resolve(…)}
is the only
* code invoking, directly or indirectly, this {@code warning(…)} method.
@@ -202,7 +204,13 @@ public class ExternalLinkHandler {
}
/**
- * Returns the source of the XML document at the given path.
+ * Returns the source of the <abbr>XML</abbr> document at the given path.
+ * The given path is resolved against the {@linkplain #getURI() base or
sibling URI}
+ * specified at construction time. If the result is not an absolute
<abbr>URI</abbr>
+ * (i.e. the given path could not be resolved), then this method returns
{@code null}.
+ *
+ * <p>Callers should invoke {@link URISource#isChildOfBase()} on the
returned object
+ * for checking if they have permission to read the file.</p>
*
* @param path relative or absolute path to the XML document to read.
* @return source of the XML document, or {@code null} if the path cannot
be resolved.
diff --git
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/internal/shared/URISource.java
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/internal/shared/URISource.java
index 1ee12c65d5..4dea000f39 100644
---
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/internal/shared/URISource.java
+++
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/internal/shared/URISource.java
@@ -26,16 +26,19 @@ import org.apache.sis.system.DataURI;
/**
- * A source of XML document which is read from an URL.
- * This class should be handled as a standard {@link StreamSource} by Java API,
- * but allows Apache SIS to keep a reference to the original {@link URI}
object.
+ * A source of <abbr>XML</abbr> document which is read from an
<abbr>URL</abbr>.
+ * This is handled as a standard {@link StreamSource} by Java <abbr>API</abbr>,
+ * but allows Apache <abbr>SIS</abbr> to remember the source {@link URI}.
*
* @author Martin Desruisseaux (Geomatys)
*/
public final class URISource extends StreamSource {
/**
* If the URI has been resolved relatively to some base directory or
sibling file, that base.
- * Otherwise {@code null}.
+ * Otherwise {@code null}. This is an argument given at construction time,
but kept non-null
+ * only if it has been verified that this is the base of {@link #document}.
+ *
+ * @see #isChildOfBase()
*/
private final URI base;
@@ -109,12 +112,18 @@ public final class URISource extends StreamSource {
}
/**
- * Returns whether the document URL is in the same directory or in a
sub-directory
- * of the base given at construction time. This is used for access control.
+ * Returns whether the {@linkplain #document} <abbr>URL</abbr> is in the
same
+ * directory or in a sub-directory of the base given at construction time.
+ * This method is used for access control.
*
* @return whether the document URL has been resolved relatively to the
base.
*/
public boolean isChildOfBase() {
+ /*
+ * The constructor verified that `document` was resolved against
`base`.
+ * If it found that it wasn't the case, then `base` has been forced to
null.
+ * Therefore, it has already been verified that the hosts are the same.
+ */
return (base != null) && DataURI.isPathInDirectory(base, document);
}
diff --git
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/MarshallingTest.java
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/MarshallingTest.java
index 1be0ea128d..2195fd69b2 100644
---
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/MarshallingTest.java
+++
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/MarshallingTest.java
@@ -23,7 +23,6 @@ import java.util.Set;
import java.util.Map;
import java.util.Collection;
import java.util.MissingResourceException;
-import java.util.logging.Filter;
import java.util.logging.LogRecord;
import java.time.Instant;
import java.time.Duration;
@@ -81,7 +80,7 @@ import org.apache.sis.util.iso.DefaultRecordSchemaTest;
* @see <a href="https://issues.apache.org/jira/browse/SIS-400">SIS-400</a>
*/
@SuppressWarnings("exports")
-public final class MarshallingTest extends TestUsingFile implements Filter {
+public final class MarshallingTest extends TestUsingFile {
/**
* The marshaller used to handle marshalling the created DefaultMetadata
object.
*/
@@ -108,10 +107,10 @@ public final class MarshallingTest extends TestUsingFile
implements Filter {
* @throws JAXBException if an error occurred while preparing the
marshaller.
*/
public MarshallingTest() throws JAXBException {
+ super(true); // This test is expected to emit some warnings.
output = new StringWriter();
pool = getMarshallerPool();
marshaller = pool.acquireMarshaller();
- marshaller.setProperty(XML.WARNING_FILTER, this);
}
/**
@@ -229,8 +228,7 @@ public final class MarshallingTest extends TestUsingFile
implements Filter {
new
DefaultResponsibility(Role.POINT_OF_CONTACT, null, individual2)));
}
// Date info (date stamp in legacy ISO 19115:2003 model)
- final var dateInfo = Set.of(new DefaultCitationDate(
- Instant.ofEpochMilli(1260961229580L), DateType.CREATION));
+ final var dateInfo = Set.of(new
DefaultCitationDate(Instant.ofEpochMilli(1260961229580L), DateType.CREATION));
md.setDateInfo(dateInfo);
{
// Metadata standard
@@ -345,7 +343,7 @@ public final class MarshallingTest extends TestUsingFile
implements Filter {
final var extent = new DefaultExtent();
extent.setDescription(new SimpleInternationalString("Azores"));
{
- final DefaultGeographicBoundingBox bbox = new
DefaultGeographicBoundingBox();
+ final var bbox = new DefaultGeographicBoundingBox();
bbox.setInclusion(true);
bbox.setNorthBoundLatitude( 40.00);
bbox.setEastBoundLongitude(-32.00);
@@ -507,7 +505,7 @@ public final class MarshallingTest extends TestUsingFile
implements Filter {
final Collection<AssociatedResource> associatedResources;
{
// Associated resources (AggregationInfo in 19139)
- final DefaultAssociatedResource associatedResource = new
DefaultAssociatedResource();
+ final var associatedResource = new DefaultAssociatedResource();
associatedResource.setAssociationType(AssociationType.DEPENDENCY);
associatedResource.setInitiativeType(InitiativeType.EXPERIMENT);
associatedResource.getIdentifierMap().putSpecialized(IdentifierSpace.ID,
"dependency");
@@ -610,8 +608,9 @@ public final class MarshallingTest extends TestUsingFile
implements Filter {
legacyXML = true;
final DefaultMetadata md = metadata();
marshaller.setProperty(XML.METADATA_VERSION, VERSION_2007);
+ marshaller.setProperty(XML.WARNING_FILTER, this);
marshaller.marshal(md, output);
- recycle();
+ verifyWarnings();
}
/**
@@ -627,37 +626,32 @@ public final class MarshallingTest extends TestUsingFile
implements Filter {
public void testCurrentSchema() throws JAXBException, URISyntaxException {
final DefaultMetadata md = metadata();
marshaller.setProperty(XML.METADATA_VERSION, VERSION_2014);
+ marshaller.setProperty(XML.WARNING_FILTER, this);
marshaller.marshal(md, output);
- recycle();
- }
-
- /**
- * Invoked only on success, for recycling the marshaller.
- */
- private void recycle() {
- pool.recycle(marshaller);
+ verifyWarnings();
}
/**
- * Invoked when a warning occurred while marshalling a test XML fragment.
Expected warnings are
+ * Verifies the warning that occurred while marshalling a test XML
fragment. Expected warnings are
* "Cannot find resource for bundle {@code
java.util.PropertyResourceBundle}, key <i>Foo</i>".
- * When marshalling legacy XML only, additional warnings may occur.
+ * When marshalling legacy <abbr>XML</abbr> only, additional warnings may
occur.
*
- * @param warning the warning.
+ * <p>This method shall be invoked last, because it opportunistically
recycle the marshaller on success.</p>
*/
- @Override
- public boolean isLoggable(final LogRecord warning) {
- if (warning.getThrown() instanceof MissingResourceException) {
- assertNull(warning.getParameters(), "Expected a warning message
without parameters.");
- return false;
- }
- final String message = warning.getMessage();
- if (legacyXML) {
- assertEquals("IgnoredPropertiesAfterFirst_1", message);
- assertArrayEquals(new String[] {"RangeDimension"},
warning.getParameters());
- } else {
- fail("Unexpected logging message: " + message);
+ private void verifyWarnings() {
+ for (final LogRecord warning : warnings) {
+ if (warning.getThrown() instanceof MissingResourceException) {
+ assertNull(warning.getParameters(), "Expected a warning
message without parameters.");
+ } else {
+ final String message = warning.getMessage();
+ if (legacyXML) {
+ assertEquals("IgnoredPropertiesAfterFirst_1", message);
+ assertArrayEquals(new String[] {"RangeDimension"},
warning.getParameters());
+ } else {
+ fail("Unexpected logging message: " + message);
+ }
+ }
}
- return false;
+ pool.recycle(marshaller); // Invoke only on success.
}
}
diff --git
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/citation/DefaultContactTest.java
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/citation/DefaultContactTest.java
index ec5ec33552..f25c1a9b14 100644
---
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/citation/DefaultContactTest.java
+++
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/iso/citation/DefaultContactTest.java
@@ -18,13 +18,13 @@ package org.apache.sis.metadata.iso.citation;
import java.util.List;
import java.util.Collection;
-import java.util.logging.Filter;
import java.util.logging.LogRecord;
+import jakarta.xml.bind.JAXBException;
import org.opengis.metadata.citation.Telephone;
-import org.apache.sis.xml.bind.Context;
// Test dependencies
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.BeforeEach;
import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.xml.test.TestCase;
@@ -40,44 +40,22 @@ import org.opengis.metadata.citation.TelephoneType;
* @author Martin Desruisseaux (Geomatys)
*/
@SuppressWarnings("exports")
-public final class DefaultContactTest extends TestCase implements Filter {
- /**
- * The resource key for the message of the warning that occurred, or
{@code null} if none.
- */
- private Object resourceKey;
-
- /**
- * The parameter of the warning that occurred, or {@code null} if none.
- */
- private Object[] parameters;
-
+public final class DefaultContactTest extends TestCase {
/**
* Creates a new test case.
*/
public DefaultContactTest() {
- }
-
- /**
- * Invoked when a warning occurred while unmarshalling a test XML
fragment. This method ensures that no other
- * warning occurred before this method call (i.e. each test is allowed to
cause at most one warning), then
- * remember the warning parameters for verification by the test method.
- *
- * @param warning the warning.
- */
- @Override
- public boolean isLoggable(final LogRecord warning) {
- assertNull(resourceKey);
- assertNull(parameters);
- assertNotNull(resourceKey = warning.getMessage());
- assertNotNull(parameters = warning.getParameters());
- return false;
+ super(true); // This test is expected to emit some warnings.
}
/**
* Initializes the test for catching warning messages.
+ *
+ * @throws JAXBException if an error occurred while creating the context
for the test.
*/
- private void init() {
- context = new Context(0, null, null, null, null, null, null, null,
null, null, this);
+ @BeforeEach
+ public void createContext() throws JAXBException {
+ createContext(false, null, null);
}
/**
@@ -87,13 +65,12 @@ public final class DefaultContactTest extends TestCase
implements Filter {
@Test
@SuppressWarnings("deprecation")
public void testSetPhones() {
- init();
- final DefaultTelephone tel1 = new DefaultTelephone("00.01",
TelephoneType.SMS);
- final DefaultTelephone tel2 = new DefaultTelephone("00.02",
TelephoneType.VOICE);
- final DefaultTelephone tel3 = new DefaultTelephone("00.03",
TelephoneType.FACSIMILE);
- final DefaultTelephone tel4 = new DefaultTelephone("00.04",
TelephoneType.VOICE);
- final DefaultTelephone[] tels = new DefaultTelephone[] {tel1, tel2,
tel3, tel4};
- final DefaultContact contact = new DefaultContact();
+ final var tel1 = new DefaultTelephone("00.01", TelephoneType.SMS);
+ final var tel2 = new DefaultTelephone("00.02", TelephoneType.VOICE);
+ final var tel3 = new DefaultTelephone("00.03",
TelephoneType.FACSIMILE);
+ final var tel4 = new DefaultTelephone("00.04", TelephoneType.VOICE);
+ final var tels = new DefaultTelephone[] {tel1, tel2, tel3, tel4};
+ final var contact = new DefaultContact();
contact.setPhones(List.of(tel1, tel2, tel3, tel4));
assertArrayEquals(tels, contact.getPhones().toArray());
/*
@@ -101,8 +78,9 @@ public final class DefaultContactTest extends TestCase
implements Filter {
* a warning, since the ISO 19115:2003 methods cannot represent SMS
numbers.
*/
assertSame(tel2, contact.getPhone()); // Shall ignore the
TelephoneType.SMS.
- assertEquals("IgnoredPropertyAssociatedTo_1", resourceKey);
- assertArrayEquals(new String[] {"TelephoneType.SMS"}, parameters);
+ final LogRecord warning = assertOneWarning();
+ assertEquals("IgnoredPropertyAssociatedTo_1", warning.getMessage());
+ assertArrayEquals(new String[] {"TelephoneType.SMS"},
warning.getParameters());
verifyLegacyLists(tels);
}
@@ -151,8 +129,7 @@ public final class DefaultContactTest extends TestCase
implements Filter {
*/
@SuppressWarnings("deprecation")
private void testSetPhone(final boolean hideSIS) {
- init();
- final DefaultTelephone tel = new DefaultTelephone();
+ final var tel = new DefaultTelephone();
tel.setVoices(List.of("00.02", "00.04"));
tel.setFacsimiles(List.of("00.03"));
final Telephone view;
@@ -170,7 +147,7 @@ public final class DefaultContactTest extends TestCase
implements Filter {
/*
* Give the telephone to a contact, and verify that new telephone
instances were created.
*/
- final DefaultContact contact = new DefaultContact();
+ final var contact = new DefaultContact();
contact.setPhone(view);
verifyLegacyLists(view);
assertArrayEquals(new DefaultTelephone[] {
@@ -178,5 +155,7 @@ public final class DefaultContactTest extends TestCase
implements Filter {
new DefaultTelephone("00.04", TelephoneType.VOICE),
new DefaultTelephone("00.03", TelephoneType.FACSIMILE)
}, contact.getPhones().toArray());
+
+ assertNoWarning();
}
}
diff --git
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/xml/TestUsingFile.java
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/xml/TestUsingFile.java
index c630eb76b0..b11e9df07b 100644
---
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/xml/TestUsingFile.java
+++
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/xml/TestUsingFile.java
@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
import java.io.InputStream;
import javax.xml.transform.Source;
import org.apache.sis.util.Version;
+import org.apache.sis.xml.XML;
import org.apache.sis.xml.internal.shared.URISource;
// Test dependencies
@@ -95,8 +96,19 @@ public abstract class TestUsingFile extends TestCase {
}
/**
- * For sub-class constructors only.
+ * Creates a new test case which is not expected to emit any warning.
*/
protected TestUsingFile() {
}
+
+ /**
+ * Creates a new test case which may emit some warnings.
+ * The {@code mayEmitWarnings} argument can be set to {@code false} as a
shortcut
+ * for avoiding to invoke {@link #assertNoWarning()} in every test method.
+ *
+ * @param mayEmitWarnings whether the tests may emit warnings
intercepted by {@link XML#WARNING_FILTER}.
+ */
+ protected TestUsingFile(final boolean mayEmitWarnings) {
+ super(mayEmitWarnings);
+ }
}
diff --git
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/ReferenceResolverTest.java
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/ReferenceResolverTest.java
index 64cce6bf79..041d7467fa 100644
---
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/ReferenceResolverTest.java
+++
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/ReferenceResolverTest.java
@@ -17,7 +17,6 @@
package org.apache.sis.xml;
import java.util.HashMap;
-import java.util.logging.Filter;
import java.util.logging.LogRecord;
import java.io.IOException;
import java.nio.file.AccessDeniedException;
@@ -43,31 +42,12 @@ import static
org.apache.sis.test.Assertions.assertSingleton;
* @author Martin Desruisseaux (Geomatys)
*/
@SuppressWarnings("exports")
-public final class ReferenceResolverTest extends TestUsingFile implements
Filter {
- /**
- * Number of times that an "access denied" warning is expected.
- */
- private int expectAccessDenied;
-
+public final class ReferenceResolverTest extends TestUsingFile {
/**
* Creates a new test case.
*/
public ReferenceResolverTest() {
- }
-
- /**
- * Invoked when a warning occurred during the XML unmarshalling.
- *
- * @param record the warning.
- * @return always {@code false} for keeping the output console quieter.
- */
- @Override
- public boolean isLoggable(final LogRecord record) {
- String file = assertInstanceOf(AccessDeniedException.class,
record.getThrown()).getFile();
- assertTrue(file.endsWith("Citation.xml"), file);
- assertNotEquals(0, expectAccessDenied, "Access should not be denied.");
- expectAccessDenied--;
- return false;
+ super(true); // This test is expected to emit some warnings.
}
/**
@@ -103,11 +83,14 @@ public final class ReferenceResolverTest extends
TestUsingFile implements Filter
*/
@Test
public void testAccessDenied() throws URISyntaxException, IOException,
JAXBException {
- expectAccessDenied = 2;
final DataIdentification data = data(Format.EXTERN, false);
final Citation citation = data.getCitation();
assertNull(citation.getTitle());
- assertEquals(0, expectAccessDenied, "Expected a warning.");
+ assertEquals(2, warnings.size());
+ for (final LogRecord record : warnings) {
+ String file = assertInstanceOf(AccessDeniedException.class,
record.getThrown()).getFile();
+ assertTrue(file.endsWith("Citation.xml"), file);
+ }
}
/**
@@ -160,5 +143,7 @@ public final class ReferenceResolverTest extends
TestUsingFile implements Filter
assertEquals("Little John", reusing.getName().toString());
assertSame(assertSingleton(parent .getContactInfo()),
assertSingleton(reusing.getContactInfo()));
+
+ assertNoWarning();
}
}
diff --git
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkMarshallingTest.java
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkMarshallingTest.java
index 7506544718..acbcab0110 100644
---
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkMarshallingTest.java
+++
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkMarshallingTest.java
@@ -17,13 +17,20 @@
package org.apache.sis.xml;
import java.util.Set;
+import java.util.Map;
+import java.util.logging.LogRecord;
+import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.file.AccessDeniedException;
+import javax.xml.transform.stream.StreamSource;
import jakarta.xml.bind.JAXBException;
import org.apache.sis.metadata.iso.DefaultMetadata;
import org.apache.sis.metadata.iso.identification.DefaultDataIdentification;
+import org.apache.sis.xml.internal.shared.URISource;
import org.apache.sis.util.SimpleInternationalString;
import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.ArraysExt;
// Test dependencies
import org.junit.jupiter.api.Test;
@@ -49,7 +56,7 @@ public final class XLinkMarshallingTest extends TestCase {
"</mdb:MD_Metadata>";
/**
- * A XML with a {@code xlink:href} without element definition.
+ * A XML with a {@code xlink:href} with element definition.
*/
private static final String LINK_WITH_ELEMENT_XML =
"<mdb:MD_Metadata xmlns:mdb=\"" + Namespaces.MDB + '"' +
@@ -84,6 +91,7 @@ public final class XLinkMarshallingTest extends TestCase {
* Creates a new test case.
*/
public XLinkMarshallingTest() {
+ super(true); // This test is expected to emit some warnings.
}
/**
@@ -101,15 +109,16 @@ public final class XLinkMarshallingTest extends TestCase {
*/
@Test
public void testLinkOnly() throws JAXBException, URISyntaxException {
- final XLink xlink = new XLink();
+ final var xlink = new XLink();
xlink.setHRef(new URI(DUMMY_URL));
- final DefaultDataIdentification identification = new
DefaultDataIdentification();
+ final var identification = new DefaultDataIdentification();
identification.getIdentifierMap().putSpecialized(IdentifierSpace.XLINK, xlink);
- final DefaultMetadata metadata = new DefaultMetadata();
+ final var metadata = new DefaultMetadata();
metadata.setIdentificationInfo(Set.of(identification));
assertXmlEquals(LINK_ONLY_XML, marshal(metadata), "xmlns:*");
verify(true, unmarshal(DefaultMetadata.class, LINK_ONLY_XML));
+ assertNoWarning();
}
/**
@@ -133,17 +142,38 @@ public final class XLinkMarshallingTest extends TestCase {
*/
@Test
public void testWithElement() throws JAXBException, URISyntaxException {
- final XLink xlink = new XLink();
+ final var xlink = new XLink();
xlink.setHRef(new URI(DUMMY_URL));
- final DefaultDataIdentification identification = new
DefaultDataIdentification();
+ final var identification = new DefaultDataIdentification();
identification.getIdentifierMap().putSpecialized(IdentifierSpace.XLINK, xlink);
identification.setAbstract(new SimpleInternationalString("This is a
test."));
- final DefaultMetadata metadata = new DefaultMetadata();
+ final var metadata = new DefaultMetadata();
metadata.setIdentificationInfo(Set.of(identification));
assertXmlEquals(LINK_WITH_ELEMENT_XML, marshal(metadata), "xmlns:*");
final DefaultMetadata unmarshal = unmarshal(DefaultMetadata.class,
LINK_WITH_ELEMENT_XML);
verify(false, unmarshal);
assertTrue(metadata.equals(unmarshal, ComparisonMode.DEBUG));
+ assertNoWarning();
+ }
+
+ /**
+ * Tests the enforcement of control access.
+ *
+ * @throws JAXBException if an error occurred during (un)marshalling.
+ * @throws URISyntaxException if the URI used in this test is malformed.
+ */
+ @Test
+ public void testControlAccess() throws JAXBException, URISyntaxException {
+ StreamSource source = URISource.create(null, null, new
URI("http://other.net/foo/parent.xml"));
+ source.setReader(new StringReader(LINK_ONLY_XML));
+
+ final var metadata = assertInstanceOf(DefaultMetadata.class,
XML.unmarshal(source, Map.of(XML.WARNING_FILTER, this)));
+ assertTrue(metadata.isEmpty());
+
+ // Expect a warning like: Cannot read "http://test.net/foo/bar.xml".
+ final LogRecord warning = assertOneWarning();
+ assertTrue(ArraysExt.contains(warning.getParameters(), new
URI(DUMMY_URL)));
+ assertEquals(DUMMY_URL, assertInstanceOf(AccessDeniedException.class,
warning.getThrown()).getFile());
}
}
diff --git
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/bind/gml/TimePeriodTest.java
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/bind/gml/TimePeriodTest.java
index 1f96de60cf..2f509fc632 100644
---
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/bind/gml/TimePeriodTest.java
+++
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/bind/gml/TimePeriodTest.java
@@ -59,7 +59,7 @@ public final class TimePeriodTest extends TestCase {
* @throws JAXBException if an error occurred while creating the pool.
*/
public TimePeriodTest() throws JAXBException {
- final var properties = new HashMap<String,Object>(4);
+ final var properties = new HashMap<String, Object>(4);
assertNull(properties.put(XML.LOCALE, Locale.FRANCE));
assertNull(properties.put(XML.TIMEZONE, "CET"));
pool = new MarshallerPool(JAXBContext.newInstance(TimeInstant.class,
TimePeriod.class), properties);
diff --git
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/internal/shared/URISourceTest.java
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/internal/shared/URISourceTest.java
new file mode 100644
index 0000000000..26695b3dbb
--- /dev/null
+++
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/internal/shared/URISourceTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.xml.internal.shared;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+// Test dependencies
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+import org.apache.sis.xml.test.TestCase;
+
+
+/**
+ * Tests {@link URISource}.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ */
+public final class URISourceTest extends TestCase {
+ /**
+ * Creates a new test case.
+ */
+ public URISourceTest() {
+ }
+
+ /**
+ * Tests {@link URISource#isChildOfBase()}, used for access control.
+ *
+ * @throws URISyntaxException if a test URI is invalid.
+ */
+ @Test
+ public void testIsChildOfBase() throws URISyntaxException {
+ final var base = new URI("http://foo.com/dir/dummy.txt");
+ URISource source = new URISource(base, new URI("sibling.txt"));
+ assertEquals(new URI("http://foo.com/dir/sibling.txt"),
source.document);
+ assertNull(source.fragment);
+ assertTrue(source.isChildOfBase());
+
+ source = new URISource(base, new URI("../dir/more/child.txt"));
+ assertEquals(new URI("http://foo.com/dir/more/child.txt"),
source.document);
+ assertNull(source.fragment);
+ assertTrue(source.isChildOfBase());
+
+ source = new URISource(base, new URI("../other/child.txt"));
+ assertEquals(new URI("http://foo.com/other/child.txt"),
source.document);
+ assertNull(source.fragment);
+ assertFalse(source.isChildOfBase());
+
+ source = new URISource(base, new
URI("http://other.com/dir/sibling.txt"));
+ assertEquals(new URI("http://other.com/dir/sibling.txt"),
source.document);
+ assertNull(source.fragment);
+ assertFalse(source.isChildOfBase());
+ }
+}
diff --git
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/DocumentComparator.java
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/DocumentComparator.java
index d50cf8533e..94a29b2d6c 100644
---
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/DocumentComparator.java
+++
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/DocumentComparator.java
@@ -541,7 +541,7 @@ public class DocumentComparator {
* If there is a namespace (which is the usual case), perform
the concatenation
* with the name before to check in the collection of ignored
attributes.
*/
- final StringBuilder buffer = new StringBuilder(ns);
+ final var buffer = new StringBuilder(ns);
int length = buffer.length();
if (length != 0 && buffer.charAt(length - 1) == '/') {
buffer.setLength(--length);
@@ -638,7 +638,7 @@ public class DocumentComparator {
return;
}
final String lineSeparator = System.lineSeparator();
- final StringBuilder buffer = new
StringBuilder(1024).append("Expected ")
+ final var buffer = new StringBuilder(1024).append("Expected ")
.append(propertyName).append(" \"")
.append(expected).append("\" but got \"")
.append(actual).append("\" for nodes:")
@@ -683,7 +683,7 @@ public class DocumentComparator {
*/
protected String formatErrorMessage(final Node expected, final Node
result) {
final String lineSeparator = System.lineSeparator();
- final StringBuilder buffer = new StringBuilder(256).append("Nodes are
not equal:").append(lineSeparator);
+ final var buffer = new StringBuilder(256).append("Nodes are not
equal:").append(lineSeparator);
formatErrorMessage(buffer, expected, result, lineSeparator);
return buffer.toString();
}
@@ -719,7 +719,7 @@ public class DocumentComparator {
private static List<String> formatHierarchy(final StringBuilder buffer,
Node node,
final List<String> expected, final String lineSeparator)
{
- final List<String> hierarchy = new ArrayList<>();
+ final var hierarchy = new ArrayList<String>();
while (node != null) {
hierarchy.add(node.getNodeName());
if (node instanceof Attr t) {
diff --git
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java
index ff51f48cee..6299a3023b 100644
---
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java
+++
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java
@@ -17,9 +17,14 @@
package org.apache.sis.xml.test;
import java.util.Map;
-import java.util.HashMap;
+import java.util.Set;
+import java.util.LinkedHashSet;
+import java.util.Iterator;
import java.util.Locale;
+import java.util.logging.Filter;
import java.util.logging.Logger;
+import java.util.logging.LogRecord;
+import java.util.logging.SimpleFormatter;
import java.time.ZoneId;
import java.io.InputStream;
import java.io.StringReader;
@@ -42,8 +47,6 @@ import org.apache.sis.util.Version;
import org.junit.jupiter.api.AfterEach;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.extension.RegisterExtension;
-import org.junit.jupiter.api.parallel.Execution;
-import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.api.parallel.ResourceAccessMode;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.apache.sis.test.LoggingWatcher;
@@ -66,10 +69,11 @@ import org.apache.sis.test.LoggingWatcher;
*
* @see DocumentComparator
*/
-@Execution(ExecutionMode.SAME_THREAD)
-public abstract class TestCase extends org.apache.sis.test.TestCase {
+public abstract class TestCase extends org.apache.sis.test.TestCase implements
Filter {
/**
* Base class of (un)marshalling tests that may emit logs.
+ * Used as an alternative to the {@link #warnings} field when the log
records
+ * cannot be intercepted by the listener specified at unmarshalling time.
*/
@ResourceLock(value=LoggingWatcher.LOCK, mode=ResourceAccessMode.READ)
public static abstract class WithLogs extends TestCase {
@@ -85,6 +89,7 @@ public abstract class TestCase extends
org.apache.sis.test.TestCase {
* @param logger the logger to listen to.
*/
protected WithLogs(final Logger logger) {
+ super(true);
loggings = new LoggingWatcher(logger);
}
@@ -94,6 +99,7 @@ public abstract class TestCase extends
org.apache.sis.test.TestCase {
* @param logger name of the logger to listen.
*/
protected WithLogs(final String logger) {
+ super(true);
loggings = new LoggingWatcher(logger);
}
}
@@ -102,7 +108,7 @@ public abstract class TestCase extends
org.apache.sis.test.TestCase {
* A dummy URL to not try to load. This URL is handled in a special way by
the unmarshallers created
* by {@link #getMarshallerPool()}: they will not try to download the
document at this address.
*/
- protected static final String DUMMY_URL = "http://test.net";
+ protected static final String DUMMY_URL = "http://test.net/foo/bar.xml";
/**
* Miscellaneous version constants used for ISO standards.
@@ -144,9 +150,57 @@ public abstract class TestCase extends
org.apache.sis.test.TestCase {
private StringWriter buffer;
/**
- * Creates a new test case.
+ * The warnings that occurred during (un)marshalling process.
+ * This set contains the warnings intercepted by the listener registered
with {@link XML#WARNING_FILTER}.
+ * It may not contain warnings emitted by codes other than
<abbr>XML</abbr> reader/writer, in particular
+ * the warnings emitted by the referencing module. For the latter, {@link
WithLogs} may be necessary.
+ *
+ * <p>This field is {@code null} if this test is not expected to emit any
warning.
+ * This is a shortcut for freeing subclasses from invoking {@link
#assertNoWarning()} in every methods.</p>
+ *
+ * @see #assertNoWarning()
+ * @see #assertOneWarning()
+ */
+ protected final Set<LogRecord> warnings;
+
+ /**
+ * Creates a new test case which is not expected to emit any warning.
*/
protected TestCase() {
+ warnings = null;
+ }
+
+ /**
+ * Creates a new test case which may emit some warnings.
+ * The {@code mayEmitWarnings} argument can be set to {@code false} as a
shortcut
+ * for avoiding to invoke {@link #assertNoWarning()} in every test method.
+ *
+ * @param mayEmitWarnings whether the tests may emit warnings
intercepted by {@link XML#WARNING_FILTER}.
+ */
+ protected TestCase(final boolean mayEmitWarnings) {
+ warnings = mayEmitWarnings ? new LinkedHashSet<>() : null;
+ }
+
+ /**
+ * Invoked when a warning occurred while (un)marshalling a test
<abbr>XML</abbr> fragment.
+ * This method verifies that the given warning has not been emitted twice,
then adds it to
+ * the {@link #warnings} set. This method is not expected to be invoked
directly.
+ *
+ * @param warning the warning.
+ */
+ @Override
+ public final boolean isLoggable(final LogRecord warning) {
+ assertNotNull(warning);
+ final String header;
+ if (warnings == null) {
+ header = "This test should not emit any warning, but got:";
+ } else if (warnings.add(warning)) {
+ return false;
+ } else {
+ header = "Warning added twice:";
+ }
+ fail(logMessages(Set.of(warning).iterator(), header));
+ return true;
}
/**
@@ -164,12 +218,11 @@ public abstract class TestCase extends
org.apache.sis.test.TestCase {
protected MarshallerPool getMarshallerPool() throws JAXBException {
synchronized (TestCase.class) {
if (defaultPool == null) {
- final Map<String,Object> properties = new HashMap<>(4);
- assertNull(properties.put(XML.LOCALE, Locale.UK));
- assertNull(properties.put(XML.TIMEZONE, TIMEZONE));
- assertNull(properties.put(XML.LENIENT_UNMARSHAL,
Boolean.TRUE));
- assertNull(properties.put(XML.RESOLVER, new
TestReferenceResolver(DUMMY_URL)));
- defaultPool = new MarshallerPool(properties);
+ defaultPool = new MarshallerPool(Map.of(
+ XML.LOCALE, Locale.UK,
+ XML.TIMEZONE, TIMEZONE,
+ XML.LENIENT_UNMARSHAL, Boolean.TRUE,
+ XML.RESOLVER, new
TestReferenceResolver(DUMMY_URL)));
}
return defaultPool;
}
@@ -187,7 +240,7 @@ public abstract class TestCase extends
org.apache.sis.test.TestCase {
*/
protected final void createContext(final boolean marshal, final Locale
locale, final String timezone) throws JAXBException {
context = new Context(marshal ? Context.MARSHALLING : 0,
getMarshallerPool(), locale,
- (timezone != null) ? ZoneId.of(timezone) : null, null, null,
null, null, null, null, null);
+ (timezone != null) ? ZoneId.of(timezone) : null, null, null,
null, null, null, null, this);
}
/**
@@ -204,6 +257,53 @@ public abstract class TestCase extends
org.apache.sis.test.TestCase {
}
}
+ /**
+ * Asserts the no warning has been emitted.
+ * This method verifies only the warnings intercepted by {@link
XML#WARNING_FILTER}.
+ * It does not check the warning emitted by codes other then
<abbr>XML</abbr> reader/writer.
+ *
+ * @see #warnings
+ */
+ protected final void assertNoWarning() {
+ assertNotNull(warnings, "This test is not collecting warnings because
no warning is expected.");
+ assertTrue(warnings.isEmpty(), () -> logMessages(warnings.iterator(),
"Unexpected warnings:"));
+ }
+
+ /**
+ * Asserts that exactly one warning has been emitted.
+ * This method verifies only the warnings intercepted by {@link
XML#WARNING_FILTER}.
+ * It does not check the warning emitted by codes other then
<abbr>XML</abbr> reader/writer.
+ *
+ * @see #warnings
+ *
+ * @return the warning which has been emitted.
+ */
+ protected final LogRecord assertOneWarning() {
+ assertNotNull(warnings, "This test is not collecting warnings because
no warning is expected.");
+ final Iterator<LogRecord> records = warnings.iterator();
+ assertTrue(records.hasNext(), "Expected one warning but got none.");
+ final LogRecord record = records.next();
+ assertFalse(records.hasNext(), () -> logMessages(records, "Warnings
after the first one:"));
+ return record;
+ }
+
+ /**
+ * Returns the following header message followed by a list of remaining
log records.
+ *
+ * @param records remaining log records to format.
+ * @param header header of the assertion failure message.
+ * @return message for the assertion failure.
+ */
+ private static String logMessages(final Iterator<LogRecord> records, final
String header) {
+ final var buffer = new StringBuilder(128).append(header);
+ final String lineSeparator = System.lineSeparator();
+ final var formatter = new SimpleFormatter();
+ do { // We expect at lest one log record.
+ buffer.append(lineSeparator).append(" ‣
").append(formatter.formatMessage(records.next()));
+ } while (records.hasNext());
+ return buffer.append(lineSeparator).toString();
+ }
+
/**
* Parses two <abbr>XML</abbr> trees as <abbr>DOM</abbr> documents and
compares the nodes.
* The inputs given to this method can be any of the following types:
@@ -534,8 +634,8 @@ public abstract class TestCase extends
org.apache.sis.test.TestCase {
* @return an XML compliant with ISO 19139:2007.
*/
protected static String toLegacyXML(final String xml) {
- final StringBuilder buffer = new StringBuilder(xml);
- for (int c=0; c < TO_LEGACY_XML.length;) {
+ final var buffer = new StringBuilder(xml);
+ for (int c = 0; c < TO_LEGACY_XML.length;) {
final String toSearch = TO_LEGACY_XML[c++];
final String replaceBy = TO_LEGACY_XML[c++];
final int length = toSearch.length();
diff --git
a/endorsed/src/org.apache.sis.profile.france/test/org/apache/sis/xml/bind/fra/DirectReferenceSystemTest.java
b/endorsed/src/org.apache.sis.profile.france/test/org/apache/sis/xml/bind/fra/DirectReferenceSystemTest.java
index a22a443de6..7c9f75eb01 100644
---
a/endorsed/src/org.apache.sis.profile.france/test/org/apache/sis/xml/bind/fra/DirectReferenceSystemTest.java
+++
b/endorsed/src/org.apache.sis.profile.france/test/org/apache/sis/xml/bind/fra/DirectReferenceSystemTest.java
@@ -67,14 +67,14 @@ public final class DirectReferenceSystemTest extends
TestCase {
*/
@SuppressWarnings("deprecation")
private static DefaultMetadata createMetadata(final boolean legacy) {
- final DefaultMetadata metadata = new DefaultMetadata();
- final DefaultCitation citation = new DefaultCitation("EPSG Geodetic
Parameter Dataset");
+ final var metadata = new DefaultMetadata();
+ final var citation = new DefaultCitation("EPSG Geodetic Parameter
Dataset");
Collection<Responsibility> r =
HardCodedCitations.EPSG.getCitedResponsibleParties();
if (legacy) {
r = Set.of(new DefaultResponsibleParty(assertSingleton(r)));
}
citation.setCitedResponsibleParties(r);
- final DirectReferenceSystem refSys = new DirectReferenceSystem(new
DefaultIdentifier(citation, "4326"));
+ final var refSys = new DirectReferenceSystem(new
DefaultIdentifier(citation, "4326"));
metadata.setReferenceSystemInfo(Set.of(refSys));
return metadata;
}
diff --git
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
index c45aba3b6e..bde1aa52da 100644
---
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
+++
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
@@ -127,7 +127,7 @@ public class InterpolatedTransform extends
DatumShiftTransform {
*
* @see #createGeodeticTransformation(MathTransformFactory, DatumShiftGrid)
*/
- @SuppressWarnings({"this-escape", "fallthrough"}) // `this` appears
in a cyclic graph.
+ @SuppressWarnings({"fallthrough", "this-escape",
"OverridableMethodCallInConstructor"}) // `this` appears in a cyclic graph.
protected <T extends Quantity<T>> InterpolatedTransform(final
DatumShiftGrid<T,T> grid) throws NoninvertibleMatrixException {
/*
* Create the contextual parameters using the descriptor of the
provider that created the datum shift grid.
@@ -385,6 +385,8 @@ public class InterpolatedTransform extends
DatumShiftTransform {
/**
* @hidden because nothing new to said.
+ *
+ * @return the hash code value.
*/
@Override
protected int computeHashCode() {
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/parameter/ParameterMarshallingTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/parameter/ParameterMarshallingTest.java
index a4a561b8ba..3d263b2023 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/parameter/ParameterMarshallingTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/parameter/ParameterMarshallingTest.java
@@ -34,7 +34,6 @@ import org.apache.sis.measure.Range;
import org.apache.sis.measure.MeasurementRange;
import org.apache.sis.system.Loggers;
import org.apache.sis.xml.Namespaces;
-import org.apache.sis.xml.XML;
// Test dependencies
import org.junit.jupiter.api.Test;
@@ -50,6 +49,7 @@ import static
org.apache.sis.referencing.Assertions.assertEpsgNameAndIdentifierE
*
* @author Martin Desruisseaux (Geomatys)
*/
+@SuppressWarnings("exports")
public final class ParameterMarshallingTest extends TestCase.WithLogs {
/**
* Creates a new test case.
@@ -101,12 +101,12 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
* @param parameter the parameter to marshal.
* @param expected the expected XML (ignoring {@code xmlns}).
*/
- private static void testMarshallAndUnmarshall(final
DefaultParameterValue<?> parameter, final String expected)
+ private void testMarshallAndUnmarshall(final DefaultParameterValue<?>
parameter, final String expected)
throws JAXBException
{
- final String xml = XML.marshal(parameter);
+ final String xml = marshal(parameter);
assertXmlEquals(expected, xml, "xmlns:*");
- final DefaultParameterValue<?> r = (DefaultParameterValue<?>)
XML.unmarshal(xml);
+ final DefaultParameterValue<?> r =
unmarshal(DefaultParameterValue.class, xml);
if (!Objects.deepEquals(parameter.getValue(), r.getValue())) {
/*
* If we enter in this block, then the line below should always
fail.
@@ -137,18 +137,18 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
*/
@Test
public void testDescriptor() throws JAXBException {
- final DefaultParameterDescriptor<Double> descriptor = new
DefaultParameterDescriptor<>(
+ final var descriptor = new DefaultParameterDescriptor<Double>(
Map.of(DefaultParameterDescriptor.NAME_KEY, "A descriptor"),
0, 1, Double.class, null, null, null);
- final String xml = XML.marshal(descriptor);
+ final String xml = marshal(descriptor);
assertXmlEquals(
"<gml:OperationParameter xmlns:gml=\"" + Namespaces.GML +
"\">\n"
+ " <gml:name>A descriptor</gml:name>\n"
+ " <gml:minimumOccurs>0</gml:minimumOccurs>\n"
+ "</gml:OperationParameter>", xml, "xmlns:*");
- final var r = (DefaultParameterDescriptor<?>) XML.unmarshal(xml);
+ final var r = unmarshal(DefaultParameterDescriptor.class, xml);
assertEquals("A descriptor", r.getName().getCode(), "name");
assertEquals(0, r.getMinimumOccurs(), "minimumOccurs");
assertEquals(1, r.getMaximumOccurs(), "maximumOccurs");
@@ -161,6 +161,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
assertNull(r.getValueDomain(), "valueDomain");
assertNull(r.getValueClass(), "valueClass"); // May
change in any future SIS release.
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -182,6 +183,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
+ " </gml:operationParameter>"
+ "</gml:ParameterValue>");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -204,6 +206,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
+ " </gml:operationParameter>"
+ "</gml:ParameterValue>");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -225,6 +228,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
+ " </gml:operationParameter>"
+ "</gml:ParameterValue>");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -246,6 +250,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
+ " </gml:operationParameter>"
+ "</gml:ParameterValue>");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -267,6 +272,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
+ " </gml:operationParameter>"
+ "</gml:ParameterValue>");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -289,6 +295,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
+ " </gml:operationParameter>"
+ "</gml:ParameterValue>");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -311,6 +318,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
+ " </gml:operationParameter>"
+ "</gml:ParameterValue>");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -327,6 +335,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
// Test unmarshalling.
verifyDescriptorGroup(unmarshalFile(DefaultParameterDescriptorGroup.class,
TestFile.DESCRIPTOR.openTestFile()));
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -403,6 +412,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
ParameterFormatTest.createMercatorParameters().createValue(),
"xmlns:*", "xsi:schemaLocation");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -415,6 +425,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
public void testValueGroupUnmarshalling() throws JAXBException {
testValueGroupUnmarshalling(TestFile.VALUE);
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -431,6 +442,7 @@ public final class ParameterMarshallingTest extends
TestCase.WithLogs {
loggings.assertNextLogContains("EPSG::8802");
loggings.assertNextLogContains("EPSG::8805");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/ImmutableIdentifierTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/ImmutableIdentifierTest.java
index 032c4bc63e..cd6aabc8e1 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/ImmutableIdentifierTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/ImmutableIdentifierTest.java
@@ -60,7 +60,7 @@ public final class ImmutableIdentifierTest extends TestCase {
* Returns the properties map to be used in argument to test methods.
*/
private static Map<String,Object> properties() {
- final var properties = new HashMap<String,Object>();
+ final var properties = new HashMap<String, Object>();
assertNull(properties.put(CODE_KEY, "This is a code"));
assertNull(properties.put(AUTHORITY_KEY, "This is an
authority"));
assertNull(properties.put(VERSION_KEY, "This is a version"));
@@ -76,7 +76,7 @@ public final class ImmutableIdentifierTest extends TestCase {
*/
@Test
public void testConstructorWithStringValues() {
- final Map<String,Object> properties = properties();
+ final Map<String, Object> properties = properties();
final var identifier = new ImmutableIdentifier(properties);
Validators.validate(identifier);
@@ -95,7 +95,7 @@ public final class ImmutableIdentifierTest extends TestCase {
*/
@Test
public void testConstructorWithInternationalString() {
- final Map<String,Object> properties = properties();
+ final Map<String, Object> properties = properties();
assertNotNull(properties.put("description", new
SimpleInternationalString("Overwritten description")));
final var identifier = new ImmutableIdentifier(properties);
Validators.validate(identifier);
@@ -114,7 +114,7 @@ public final class ImmutableIdentifierTest extends TestCase
{
*/
@Test
public void testConstructorWithCitation() {
- final Map<String,Object> properties = properties();
+ final Map<String, Object> properties = properties();
assertNotNull(properties.put(AUTHORITY_KEY, new
DefaultCitation("Another authority")));
final var identifier = new ImmutableIdentifier(properties);
Validators.validate(identifier);
@@ -135,7 +135,7 @@ public final class ImmutableIdentifierTest extends TestCase
{
*/
@Test
public void testPredefinedCitation() {
- final Map<String,Object> properties = properties();
+ final Map<String, Object> properties = properties();
assertNotNull(properties.put(AUTHORITY_KEY, Constants.EPSG));
final var identifier = new ImmutableIdentifier(properties);
Validators.validate(identifier);
@@ -154,7 +154,7 @@ public final class ImmutableIdentifierTest extends TestCase
{
*/
@Test
public void testConstructorWithWrongType() {
- final Map<String,Object> properties = properties();
+ final Map<String, Object> properties = properties();
assertNotNull(properties.put(AUTHORITY_KEY, Locale.CANADA));
var e = assertThrows(IllegalArgumentException.class, () -> new
ImmutableIdentifier(properties));
assertMessageContains(e, AUTHORITY_KEY);
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
index 779fba8196..1c80a1b699 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
@@ -50,6 +50,7 @@ import static
org.opengis.test.Assertions.assertAxisDirectionsEqual;
*
* @author Martin Desruisseaux (Geomatys)
*/
+@SuppressWarnings("exports")
public final class DefaultCompoundCRSTest extends TestCase {
/**
* The vertical CRS arbitrarily chosen in this class for the tests.
@@ -83,7 +84,7 @@ public final class DefaultCompoundCRSTest extends TestCase {
@Test
@SuppressWarnings("ResultOfObjectAllocationIgnored")
public void testDuplicatedComponent() {
- final Map<String,Object> properties = new HashMap<>(4);
+ final var properties = new HashMap<String, Object>(4);
assertNull(properties.put(DefaultCompoundCRS.LOCALE_KEY,
Locale.ENGLISH));
assertNull(properties.put(DefaultCompoundCRS.NAME_KEY, "3D +
illegal"));
@@ -111,7 +112,7 @@ public final class DefaultCompoundCRSTest extends TestCase {
@Test
@SuppressWarnings("ResultOfObjectAllocationIgnored")
public void testEllipsoidalHeight() {
- final Map<String,Object> properties = new HashMap<>(4);
+ final var properties = new HashMap<String, Object>(4);
assertNull(properties.put(DefaultCompoundCRS.LOCALE_KEY,
Locale.ENGLISH));
assertNull(properties.put(DefaultCompoundCRS.NAME_KEY, "3D"));
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultEngineeringCRSTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultEngineeringCRSTest.java
index ed6627d0e3..33e89d3943 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultEngineeringCRSTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultEngineeringCRSTest.java
@@ -42,6 +42,7 @@ import static
org.opengis.test.Assertions.assertAxisDirectionsEqual;
*
* @author Martin Desruisseaux (Geomatys)
*/
+@SuppressWarnings("exports")
public final class DefaultEngineeringCRSTest extends TestCase {
/**
* Creates a new test case.
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java
index e6ef3ea8f1..486ddeaaaa 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java
@@ -85,6 +85,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
verifyParameters(crs.getConversionFromBase().getParameterValues());
assertEquals(2, crs.getCoordinateSystem().getDimension(), "dimension");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -98,6 +99,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
verifyParameters(crs.getConversionFromBase().getParameterValues());
assertEquals(3, crs.getCoordinateSystem().getDimension(), "dimension");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -111,6 +113,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
"Should not accept a three-dimensional base CRS
with two-dimensional CS.");
assertMessageContains(e, "derivedCS");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -187,6 +190,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
crs);
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -219,6 +223,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
crs);
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -254,6 +259,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
crs);
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -293,6 +299,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
crs);
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -350,6 +357,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
crs);
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -403,6 +411,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
crs);
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -447,6 +456,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
loggings.assertNextLogContains("semi_minor", "WGS84");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -485,6 +495,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
crs);
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -516,6 +527,7 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
final String[] ignoredAttributes = {"xmlns:*", "xsi:schemaLocation",
"gml:id"};
assertMarshalEqualsFile(openTestFile(), crs, null, 0, ignoredNodes,
ignoredAttributes);
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -535,5 +547,6 @@ public final class DefaultProjectedCRSTest extends
TestCase.WithLogs {
assertTrue (c.equals(normalized, ComparisonMode.APPROXIMATE));
assertTrue (c.equals(normalized, ComparisonMode.ALLOW_VARIANT));
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
}
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
index 0142767b00..55be1d2df7 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
@@ -34,6 +34,7 @@ import static
org.apache.sis.referencing.Assertions.assertRemarksEquals;
*
* @author Martin Desruisseaux (IRD, Geomatys)
*/
+@SuppressWarnings("exports")
public final class DefaultEllipsoidTest extends TestCase {
/**
* Creates a new test case.
@@ -57,7 +58,7 @@ public final class DefaultEllipsoidTest extends TestCase {
*/
@Test
public void testGetEccentricity() {
- final DefaultEllipsoid e = new
DefaultEllipsoid(GeodeticDatumMock.WGS84.getEllipsoid());
+ final var e = new
DefaultEllipsoid(GeodeticDatumMock.WGS84.getEllipsoid());
assertEquals(6378137.0, e.getSemiMajorAxis()); //
By definition
assertEquals(298.257223563, e.getInverseFlattening()); //
By definition
assertEquals(0.006694379990141317, e.getEccentricitySquared());
@@ -70,7 +71,7 @@ public final class DefaultEllipsoidTest extends TestCase {
*/
@Test
public void testSemiMajorAxisDifference() {
- final DefaultEllipsoid e = new
DefaultEllipsoid(GeodeticDatumMock.WGS84.getEllipsoid());
+ final var e = new
DefaultEllipsoid(GeodeticDatumMock.WGS84.getEllipsoid());
assertEquals( 0,
e.semiMajorAxisDifference(GeodeticDatumMock.WGS84.getEllipsoid()));
assertEquals(251, e.semiMajorAxisDifference(GeodeticDatumMock.ED50
.getEllipsoid()));
}
@@ -81,7 +82,7 @@ public final class DefaultEllipsoidTest extends TestCase {
*/
@Test
public void testFlatteningDifference() {
- final DefaultEllipsoid e = new
DefaultEllipsoid(GeodeticDatumMock.WGS84.getEllipsoid());
+ final var e = new
DefaultEllipsoid(GeodeticDatumMock.WGS84.getEllipsoid());
assertEquals(0.0,
e.flatteningDifference(GeodeticDatumMock.WGS84.getEllipsoid()));
assertEquals(1.41927E-05,
e.flatteningDifference(GeodeticDatumMock.ED50 .getEllipsoid()), 1E-10);
}
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
index 7bd590c500..8a6004b13d 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
@@ -44,6 +44,7 @@ import static
org.apache.sis.referencing.Assertions.assertRemarksEquals;
*
* @author Martin Desruisseaux (Geomatys)
*/
+@SuppressWarnings("exports")
public final class DefaultPrimeMeridianTest extends TestCase {
/**
* Creates a new test case.
@@ -67,7 +68,7 @@ public final class DefaultPrimeMeridianTest extends TestCase {
*/
@Test
public void testToWKT() {
- final DefaultPrimeMeridian pm = new
DefaultPrimeMeridian(PrimeMeridianMock.GREENWICH);
+ final var 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);
@@ -91,7 +92,7 @@ public final class DefaultPrimeMeridianTest extends TestCase {
*/
@Test
public void testWKT_withUnformattableUnit() {
- final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(
+ final var pm = new DefaultPrimeMeridian(
Map.of(DefaultPrimeMeridian.NAME_KEY, "Test"),
10.3, Units.valueOfEPSG(9111).asType(Angle.class));
/*
@@ -126,7 +127,7 @@ public final class DefaultPrimeMeridianTest extends
TestCase {
*/
@Test
public void testMarshall() throws JAXBException {
- final DefaultPrimeMeridian pm = new
DefaultPrimeMeridian(PrimeMeridianMock.GREENWICH);
+ final var pm = new DefaultPrimeMeridian(PrimeMeridianMock.GREENWICH);
assertXmlEquals(getGreenwichXml(Namespaces.GML), marshal(pm),
"xmlns:*");
}
@@ -137,7 +138,7 @@ public final class DefaultPrimeMeridianTest extends
TestCase {
*/
@Test
public void testMarshallGML31() throws JAXBException {
- final DefaultPrimeMeridian pm = new
DefaultPrimeMeridian(PrimeMeridianMock.GREENWICH);
+ final var pm = new DefaultPrimeMeridian(PrimeMeridianMock.GREENWICH);
final MarshallerPool pool = getMarshallerPool();
final Marshaller marshaller = pool.acquireMarshaller();
marshaller.setProperty(XML.GML_VERSION, LegacyNamespaces.VERSION_3_0);
@@ -167,8 +168,8 @@ public final class DefaultPrimeMeridianTest extends
TestCase {
final MarshallerPool pool = getMarshallerPool();
final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
unmarshaller.setProperty(XML.GML_VERSION,
LegacyNamespaces.VERSION_3_0);
- final DefaultPrimeMeridian pm = (DefaultPrimeMeridian)
- unmarshal(unmarshaller, getGreenwichXml(LegacyNamespaces.GML));
+ final DefaultPrimeMeridian pm =
assertInstanceOf(DefaultPrimeMeridian.class,
+ unmarshal(unmarshaller,
getGreenwichXml(LegacyNamespaces.GML)));
pool.recycle(unmarshaller);
assertIsGreenwich(pm);
}
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultTemporalDatumTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultTemporalDatumTest.java
index d5a87c2e60..f2cf289bc5 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultTemporalDatumTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultTemporalDatumTest.java
@@ -74,7 +74,7 @@ public final class DefaultTemporalDatumTest extends TestCase {
* @param local whether the datum origin should be a local date.
*/
private static DefaultTemporalDatum create(final boolean local) {
- final var properties = new HashMap<String,Object>(4);
+ final var properties = new HashMap<String, Object>(4);
assertNull(properties.put(IDENTIFIERS_KEY,
new ImmutableIdentifier(HardCodedCitations.SIS, "SIS", "MJ")));
assertNull(properties.put(NAME_KEY, "Modified Julian"));
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java
index 1cf777e918..b07932e816 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java
@@ -46,7 +46,7 @@ import org.opengis.referencing.datum.RealizationMethod;
*
* @author Martin Desruisseaux (Geomatys)
*/
-@SuppressWarnings("deprecation")
+@SuppressWarnings({"exports", "deprecation"})
public final class DefaultVerticalDatumTest extends TestCase {
/**
* Creates a new test case.
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/SingleOperationMarshallingTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/SingleOperationMarshallingTest.java
index 2d3815d2c8..b03cc3ea36 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/SingleOperationMarshallingTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/SingleOperationMarshallingTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.sis.referencing.operation;
-import java.util.HashMap;
+import java.util.Map;
import java.util.Iterator;
import java.io.InputStream;
import jakarta.xml.bind.JAXBException;
@@ -36,7 +36,6 @@ import org.apache.sis.parameter.ParameterBuilder;
import org.apache.sis.measure.Units;
import org.apache.sis.system.Loggers;
import org.apache.sis.xml.Namespaces;
-import org.apache.sis.xml.XML;
import static org.apache.sis.metadata.iso.citation.Citations.EPSG;
// Test dependencies
@@ -94,10 +93,10 @@ public final class SingleOperationMarshallingTest extends
TestCase.WithLogs {
};
builder.addName(null, "Mercator (1SP)");
final ParameterDescriptorGroup descriptor =
builder.createGroup(parameters);
- final var properties = new HashMap<String,Object>(4);
- properties.put(DefaultOperationMethod.NAME_KEY, descriptor.getName());
- properties.put(DefaultOperationMethod.FORMULA_KEY, new
DefaultFormula("See EPSG guide."));
- return new DefaultOperationMethod(properties, descriptor);
+ return new DefaultOperationMethod(
+ Map.of(DefaultOperationMethod.NAME_KEY, descriptor.getName(),
+ DefaultOperationMethod.FORMULA_KEY, new
DefaultFormula("See EPSG guide.")),
+ descriptor);
}
/**
@@ -107,7 +106,7 @@ public final class SingleOperationMarshallingTest extends
TestCase.WithLogs {
*/
@Test
public void testOperationMethod() throws JAXBException {
- final String xml = XML.marshal(createMercatorMethod());
+ final String xml = marshal(createMercatorMethod());
assertXmlEquals("<gml:OperationMethod xmlns:gml=\"" + Namespaces.GML +
"\">\n" +
" <gml:name>Mercator (1SP)</gml:name>\n" +
" <gml:formula>See EPSG guide.</gml:formula>\n" +
@@ -125,10 +124,11 @@ public final class SingleOperationMarshallingTest extends
TestCase.WithLogs {
" </gml:parameter>\n" +
"</gml:OperationMethod>", xml, "xmlns:*");
- final var method = (OperationMethod) XML.unmarshal(xml);
+ final var method = unmarshal(OperationMethod.class, xml);
verifyMethod(method);
Validators.validate(method);
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -189,6 +189,7 @@ public final class SingleOperationMarshallingTest extends
TestCase.WithLogs {
loggings.assertNextLogContains("EPSG::8801");
loggings.assertNextLogContains("EPSG::8802");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -268,5 +269,6 @@ public final class SingleOperationMarshallingTest extends
TestCase.WithLogs {
Validators.validate(c);
loggings.assertNextLogContains("EPSG::8602");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
}
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/MetadataTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/MetadataTest.java
index 78dd1b5259..ec206b83da 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/MetadataTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/MetadataTest.java
@@ -384,6 +384,7 @@ public final class MetadataTest extends TestCase.WithLogs {
comparator.ignoreComments = true;
comparator.compare();
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -417,5 +418,6 @@ public final class MetadataTest extends TestCase.WithLogs {
final DefaultMetadata expected = createHardCoded();
assertTrue(metadata.equals(expected, ComparisonMode.DEBUG));
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
}
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/MetadataVerticalTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/MetadataVerticalTest.java
index e1c28de621..a3b35298b8 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/MetadataVerticalTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/MetadataVerticalTest.java
@@ -187,6 +187,7 @@ public final class MetadataVerticalTest extends
TestCase.WithLogs {
*/
assertMarshalEqualsFile(openTestFile(), metadata, VERSION_2007,
"xmlns:*", "xsi:schemaLocation");
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/xml/bind/referencing/CC_GeneralOperationParameterTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/xml/bind/referencing/CC_GeneralOperationParameterTest.java
index 1e8126c3e6..873d8f06d9 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/xml/bind/referencing/CC_GeneralOperationParameterTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/xml/bind/referencing/CC_GeneralOperationParameterTest.java
@@ -17,7 +17,6 @@
package org.apache.sis.xml.bind.referencing;
import java.util.List;
-import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import jakarta.xml.bind.JAXBException;
@@ -59,6 +58,8 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
final String[] expected = new String[] {"One", "Two", "Three"};
final String[] actual =
CC_GeneralOperationParameter.toArray(List.of(expected), String.class);
assertArrayEquals(expected, actual);
+ loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -104,7 +105,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
private static DefaultParameterDescriptor<Integer> create(final String
name, final String remarks,
final boolean mandatory, final Integer defaultValue)
{
- final var properties = new HashMap<String,String>(4);
+ final var properties = new HashMap<String, String>(4);
assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY, name));
assertNull(properties.put(DefaultParameterDescriptor.REMARKS_KEY,
remarks));
return new DefaultParameterDescriptor<>(properties, mandatory ? 1 : 0,
1, Integer.class, null, null, defaultValue);
@@ -136,6 +137,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
assertSame(complete, CC_GeneralOperationParameter.merge(provided,
complete));
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -148,7 +150,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
public void testParameterMerge() throws JAXBException {
ParameterDescriptor<?> provided = unmarshal("Test parameter", null);
ParameterDescriptor<?> complete = create("Test parameter", null, true,
null);
- ParameterDescriptor<?> merged = (ParameterDescriptor<?>)
CC_GeneralOperationParameter.merge(provided, complete);
+ ParameterDescriptor<?> merged =
assertInstanceOf(ParameterDescriptor.class,
CC_GeneralOperationParameter.merge(provided, complete));
assertNotSame(complete, merged);
assertSame (complete.getName(), merged.getName());
assertEquals (0, merged.getMinimumOccurs()); // From
provided descriptor.
@@ -161,7 +163,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
// Above assertion was tested by testParameterSubstitutions(), but was
verified again here
// for making sure that the following assertion verifies the effect of
the remarks alone.
provided = unmarshal("Test parameter", "More details here.");
- merged = (ParameterDescriptor<?>)
CC_GeneralOperationParameter.merge(provided, complete);
+ merged = assertInstanceOf(ParameterDescriptor.class,
CC_GeneralOperationParameter.merge(provided, complete));
assertNotSame(complete, merged);
assertSame (complete.getName(), merged.getName());
assertEquals (0, merged.getMinimumOccurs());
@@ -169,6 +171,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
assertEquals (Integer.class, merged.getValueClass());
assertEquals (provided.getRemarks(), merged.getRemarks());
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -179,7 +182,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
*/
@Test
public void testGroupSubstitution() throws JAXBException {
- final Map<String,String> properties = new HashMap<>(4);
+ final var properties = new HashMap<String, String>(4);
assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY,
"Group"));
final var provided = new DefaultParameterDescriptorGroup(properties,
1, 2,
unmarshal("Parameter A", null),
@@ -195,6 +198,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
assertSame(complete, CC_GeneralOperationParameter.merge(provided,
complete));
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -206,7 +210,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
*/
@Test
public void testGroupMergeBecauseDifferentProperties() throws
JAXBException {
- final Map<String,String> properties = new HashMap<>(4);
+ final var properties = new HashMap<String, String>(4);
assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY,
"Group"));
final var provided = new DefaultParameterDescriptorGroup(properties,
1, 2,
unmarshal("Parameter A", "Remarks A."),
@@ -220,7 +224,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
create("Parameter C", "Different.", false, 5),
create("Parameter D", "Remarks D.", false, 6));
- final var merged = (ParameterDescriptorGroup)
CC_GeneralOperationParameter.merge(provided, complete);
+ final var merged = assertInstanceOf(ParameterDescriptorGroup.class,
CC_GeneralOperationParameter.merge(provided, complete));
assertNotSame(complete, provided);
assertSame (complete.getName(), merged.getName());
assertEquals (complete.getRemarks(), merged.getRemarks());
@@ -235,6 +239,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
assertTrue (itc.hasNext());
assertFalse(itm.hasNext());
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -246,7 +251,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
*/
@Test
public void testGroupMergeBecauseMissingParameter() throws JAXBException {
- final Map<String,String> properties = new HashMap<>(4);
+ final var properties = new HashMap<String, String>(4);
assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY,
"Group"));
final var provided = new DefaultParameterDescriptorGroup(properties,
1, 2,
unmarshal("Parameter A", null),
@@ -258,7 +263,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
create("Parameter B", null, true, 4),
create("Parameter C", null, false, 5));
- final var merged = (ParameterDescriptorGroup)
CC_GeneralOperationParameter.merge(provided, complete);
+ final var merged = assertInstanceOf(ParameterDescriptorGroup.class,
CC_GeneralOperationParameter.merge(provided, complete));
assertNotSame(complete, provided);
assertSame (complete.getName(), merged.getName());
assertEquals (complete.getRemarks(), merged.getRemarks());
@@ -276,6 +281,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
assertFalse(itc.hasNext());
assertFalse(itm.hasNext());
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
@@ -287,7 +293,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
*/
@Test
public void testGroupMergeBecauseExtraParameter() throws JAXBException {
- final Map<String,String> properties = new HashMap<>(4);
+ final var properties = new HashMap<String, String>(4);
assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY,
"Group"));
final var provided = new DefaultParameterDescriptorGroup(properties,
1, 2,
unmarshal("Parameter A", "Remarks A."),
@@ -321,6 +327,7 @@ public final class CC_GeneralOperationParameterTest extends
TestCase.WithLogs {
assertFalse(itc.hasNext());
assertFalse(itm.hasNext());
loggings.assertNoUnexpectedLog();
+ assertNoWarning();
}
/**
diff --git
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/xml/bind/referencing/CC_OperationParameterGroupTest.java
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/xml/bind/referencing/CC_OperationParameterGroupTest.java
index 4e6eef2234..417b03eda9 100644
---
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/xml/bind/referencing/CC_OperationParameterGroupTest.java
+++
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/xml/bind/referencing/CC_OperationParameterGroupTest.java
@@ -94,7 +94,7 @@ public final class CC_OperationParameterGroupTest extends
TestCase {
* @param remarks Remarks to associate to the latitude parameter, or
{@code null} if none.
*/
private static ParameterDescriptor<?>[] create(final String remarks) {
- final ParameterBuilder builder = new ParameterBuilder();
+ final var builder = new ParameterBuilder();
builder.setCodeSpace(EPSG, "EPSG").setRequired(true);
return new ParameterDescriptor<?>[] {
builder.addIdentifier("8801").addName("Latitude of natural
origin") .setRemarks(remarks).create(0, Units.DEGREE),
@@ -134,7 +134,7 @@ public final class CC_OperationParameterGroupTest extends
TestCase {
public void testMerge() throws JAXBException {
final ParameterDescriptorGroup fromXML = unmarshal();
final ParameterDescriptor<?>[] fromValues = create(null);
- final Map<GeneralParameterDescriptor,GeneralParameterDescriptor>
replacements = new IdentityHashMap<>(4);
+ final var replacements = new
IdentityHashMap<GeneralParameterDescriptor, GeneralParameterDescriptor>(4);
final GeneralParameterDescriptor[] merged =
CC_OperationParameterGroup.merge(fromXML.descriptors(), fromValues.clone(),
replacements);
assertNotSame(fromValues, merged);
/*
diff --git
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/system/DataURI.java
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/system/DataURI.java
index b7cd6ce016..976f5c0e10 100644
--- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/system/DataURI.java
+++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/system/DataURI.java
@@ -107,7 +107,8 @@ public class DataURI {
return false;
}
final URI result = base.resolve(parameter).normalize();
- if (result != resolved) {
+ if (!result.equals(resolved)) {
+ // Host indirectly verified by `URI.resolve(…)` and the following
equality check.
isRelative = (result != parameter) && isPathInDirectory(base,
result);
resolved = result;
try {
diff --git
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/IndexedResourceBundle.java
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/IndexedResourceBundle.java
index 106a6cfa8e..af65f109e9 100644
---
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/IndexedResourceBundle.java
+++
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/IndexedResourceBundle.java
@@ -16,7 +16,6 @@
*/
package org.apache.sis.util.resources;
-import java.net.URI;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
@@ -408,8 +407,6 @@ public abstract class IndexedResourceBundle extends
ResourceBundle implements Lo
text = ((InternationalString)
element).toString(getLocale());
}
replacement = CharSequences.shortSentence(text,
MAX_STRING_LENGTH);
- } else if (element instanceof URI) {
- replacement = ((URI) element).getSchemeSpecificPart(); //
For decoding encoded characters.
} else if (element instanceof Class<?>) {
replacement = Classes.getShortName(getPublicType((Class<?>)
element));
} else if (element instanceof Type) {