You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by am...@apache.org on 2020/01/21 15:34:56 UTC

[sis] branch fix/fast-envelope updated (09430ce -> b3ac6a5)

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

amanin pushed a change to branch fix/fast-envelope
in repository https://gitbox.apache.org/repos/asf/sis.git.


    from 09430ce  fix(SQLStore): Add a feature to ask database for an estimate of a dataset envelope (table, simple query)
     new fb7741d  chore(Feature): add unit tests for new feature utility methods
     new 602c728  chore(Core): Add tests for H2 database support
     new 125b08b  chore(SQLStore): add basic testing on H2.
     new b3ac6a5  wip(SQLStore): Start test cases for spatial functions over in memory H2GIS

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


Summary of changes:
 .../java/org/apache/sis/feature/FeaturesTest.java  | 103 ++++++++++++++++++++-
 core/sis-metadata/pom.xml                          |   6 ++
 .../java/org/apache/sis/test/sql/TestDatabase.java |  43 +++++++--
 .../referencing/factory/sql/EPSGInstallerTest.java |  54 +++++++----
 storage/sis-sqlstore/pom.xml                       |   6 ++
 .../apache/sis/internal/sql/feature/EWKBTest.java  |  13 +--
 .../org/apache/sis/storage/sql/H2SpatialTest.java  |  98 ++++++++++++++++++++
 .../org/apache/sis/storage/sql/SQLStoreTest.java   |  10 ++
 .../org/apache/sis/storage/sql/h2_base.sql         |   9 ++
 9 files changed, 307 insertions(+), 35 deletions(-)
 create mode 100644 storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/H2SpatialTest.java
 create mode 100644 storage/sis-sqlstore/src/test/resources/org/apache/sis/storage/sql/h2_base.sql


[sis] 04/04: wip(SQLStore): Start test cases for spatial functions over in memory H2GIS

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

amanin pushed a commit to branch fix/fast-envelope
in repository https://gitbox.apache.org/repos/asf/sis.git

commit b3ac6a59bc58d63293e3a42c2f8fc626edc387ea
Author: Alexis Manin <am...@apache.org>
AuthorDate: Tue Jan 21 16:34:30 2020 +0100

    wip(SQLStore): Start test cases for spatial functions over in memory H2GIS
---
 storage/sis-sqlstore/pom.xml                       |  6 ++
 .../apache/sis/internal/sql/feature/EWKBTest.java  | 13 +--
 .../org/apache/sis/storage/sql/H2SpatialTest.java  | 98 ++++++++++++++++++++++
 .../org/apache/sis/storage/sql/h2_base.sql         |  9 ++
 4 files changed, 120 insertions(+), 6 deletions(-)

diff --git a/storage/sis-sqlstore/pom.xml b/storage/sis-sqlstore/pom.xml
index 86d7cc4..65d2e13 100644
--- a/storage/sis-sqlstore/pom.xml
+++ b/storage/sis-sqlstore/pom.xml
@@ -171,6 +171,12 @@
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.orbisgis</groupId>
+      <artifactId>h2gis</artifactId>
+      <version>1.5.0</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
 </project>
diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/EWKBTest.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/EWKBTest.java
index 9653e34..398fb83 100644
--- a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/EWKBTest.java
+++ b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/EWKBTest.java
@@ -9,11 +9,10 @@ import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.setup.GeometryLibrary;
 import org.apache.sis.test.TestCase;
 
-import org.junit.Assert;
-import org.junit.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.CsvFileSource;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class EWKBTest extends TestCase {
 
@@ -24,15 +23,17 @@ public class EWKBTest extends TestCase {
     public void decodeHexadecimal(String wkt, String hexEWKB) throws Exception {
         final GeographicCRS expectedCrs = CommonCRS.defaultGeographic();
         final EWKBReader reader = new EWKBReader(GF).forCrs(expectedCrs);
-        Assert.assertEquals("WKT and hexadecimal EWKB representation don't match",
-                GF.parseWKT(wkt).implementation(), reader.readHexa(hexEWKB));
+        assertEquals(
+                GF.parseWKT(wkt).implementation(), reader.readHexa(hexEWKB),
+                "WKT and hexadecimal EWKB representation don't match"
+        );
     }
 
     /**
      * The purpose of this test is not to check complex geometries, which is validated by above one. We just want to
      * ensure that decoding directly a byte stream behaves in the same way than through hexadecimal.
      */
-    @Test
+    @org.junit.Test
     public void testBinary() {
         final ByteBuffer point = ByteBuffer.allocate(163);
         // Skip first byte: XDR mode
@@ -46,6 +47,6 @@ public class EWKBTest extends TestCase {
         point.position(0);
 
         final Object read = new EWKBReader(GeometryLibrary.JTS).read(point);
-        Assert.assertEquals(GF.createPoint(42.2, 43.3), read);
+        assertEquals(GF.createPoint(42.2, 43.3), read);
     }
 }
diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/H2SpatialTest.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/H2SpatialTest.java
new file mode 100644
index 0000000..9d67a3a
--- /dev/null
+++ b/storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/H2SpatialTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.storage.sql;
+
+import java.sql.Connection;
+import java.util.logging.Level;
+
+import org.opengis.feature.FeatureType;
+import org.opengis.feature.PropertyType;
+import org.opengis.geometry.Envelope;
+
+import org.apache.sis.feature.Features;
+import org.apache.sis.geometry.AbstractEnvelope;
+import org.apache.sis.geometry.Envelope2D;
+import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.FeatureSet;
+import org.apache.sis.storage.StorageConnector;
+import org.apache.sis.test.sql.TestDatabase;
+import org.apache.sis.util.logging.Logging;
+
+import org.h2gis.functions.factory.H2GISFunctions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class H2SpatialTest {
+
+    private static TestDatabase db;
+    private static SQLStore store;
+
+    @BeforeAll
+    public static void createDatabase() throws Exception {
+        db = TestDatabase.createOnH2("spatialFunctions", false);
+        try (Connection c = db.source.getConnection()) {
+            H2GISFunctions.load(c);
+        }
+        db.executeSQL(H2SpatialTest.class, "file:"+"h2_base.sql");
+
+        store = new SQLStore(
+                new SQLStoreProvider(), new StorageConnector(db.source),
+                SQLStoreProvider.createTableName(null, null, "roads")
+        );
+    }
+
+    @org.junit.Test public void preventVintageError() {}
+
+    @Test
+    public void getEnvelope() throws DataStoreException {
+        final FeatureSet roads = (FeatureSet) store.findResource("roads");
+        final Envelope envelope = roads.getEnvelope()
+                .orElseThrow(() -> new AssertionError("No envelope available for spatial dataset"));
+        final Envelope2D expected = new Envelope2D(CommonCRS.WGS84.geographic(), 15, 5, 16, 20);
+
+        assertTrue(
+                AbstractEnvelope.castOrCopy(envelope).equals(expected, 1e-4, false),
+                () -> String.format("Bad envelope.%nExpected: %s%nBut was: %s", expected.toString(), envelope.toString())
+        );
+    }
+
+    //@Test
+    public void readGeometries() throws DataStoreException {
+        final FeatureSet roads = (FeatureSet) store.findResource("ROADS");
+        final FeatureType type = roads.getType();
+        final PropertyType geom = Features.getDefaultGeometry(type);
+        // TODO: check CRS and if it's a linestring, then try to read rows.
+    }
+
+    //@Test
+    public void bboxFilter() throws DataStoreException {
+        // TODO: try to execute a simple query with an envelope.
+    }
+
+    @AfterAll
+    public static void destroyDb() {
+        if (db == null) return;
+        try (AutoCloseable closeDb = db::close ; AutoCloseable closeStore = () -> { if (store != null) store.close(); }) {
+        } catch (Exception e) {
+            Logging.getLogger("org.apache.sis.storage.sql").log(Level.WARNING, "Cannot properly free test database", e);
+        }
+    }
+}
diff --git a/storage/sis-sqlstore/src/test/resources/org/apache/sis/storage/sql/h2_base.sql b/storage/sis-sqlstore/src/test/resources/org/apache/sis/storage/sql/h2_base.sql
new file mode 100644
index 0000000..0090da9
--- /dev/null
+++ b/storage/sis-sqlstore/src/test/resources/org/apache/sis/storage/sql/h2_base.sql
@@ -0,0 +1,9 @@
+-- A sample database to test spatial operations over database.
+-- This is designed to work over orbisgis:H2GIS database.
+-- Inspired by official example at https://github.com/orbisgis/orbisgis-samples/blob/master/demoh2gis/src/main/java/org/orbisgis/demoh2gis/Main.java
+
+CREATE TABLE ROADS (geometry LINESTRING, speed_limit INT) CHECK ST_SRID(geometry)=4326;
+
+INSERT INTO ROADS VALUES (ST_GeomFromText('LINESTRING(15 5, 20 6, 25 7)', 4326), 80)
+INSERT INTO ROADS VALUES (ST_GeomFromText('LINESTRING(20 6, 21 15, 21 25)', 4326), 50)
+INSERT INTO ROADS VALUES (ST_GeomFromText('LINESTRING(34 12, 36 13, 35.2 16)', 4326), 70)


[sis] 02/04: chore(Core): Add tests for H2 database support

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

amanin pushed a commit to branch fix/fast-envelope
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 602c728c93c4d26823d6373dd33afcb85a0b5faf
Author: Alexis Manin <am...@apache.org>
AuthorDate: Tue Jan 21 14:32:41 2020 +0100

    chore(Core): Add tests for H2 database support
---
 core/sis-metadata/pom.xml                          |  6 +++
 .../java/org/apache/sis/test/sql/TestDatabase.java | 43 +++++++++++++----
 .../referencing/factory/sql/EPSGInstallerTest.java | 54 +++++++++++++++-------
 3 files changed, 79 insertions(+), 24 deletions(-)

diff --git a/core/sis-metadata/pom.xml b/core/sis-metadata/pom.xml
index 02226e6..9e20bbf 100644
--- a/core/sis-metadata/pom.xml
+++ b/core/sis-metadata/pom.xml
@@ -174,6 +174,12 @@
       <artifactId>postgresql</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>com.h2database</groupId>
+      <artifactId>h2</artifactId>
+      <version>1.4.200</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
 </project>
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/test/sql/TestDatabase.java b/core/sis-metadata/src/test/java/org/apache/sis/test/sql/TestDatabase.java
index 625817f..bfb605b 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/test/sql/TestDatabase.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/test/sql/TestDatabase.java
@@ -17,22 +17,27 @@
 package org.apache.sis.test.sql;
 
 import java.io.IOException;
-import javax.sql.DataSource;
 import java.sql.Connection;
-import java.sql.Statement;
 import java.sql.ResultSet;
-import java.sql.SQLException;
 import java.sql.SQLDataException;
-import org.postgresql.PGProperty;
-import org.postgresql.ds.PGSimpleDataSource;
-import org.hsqldb.jdbc.JDBCDataSource;
-import org.hsqldb.jdbc.JDBCPool;
-import org.apache.derby.jdbc.EmbeddedDataSource;
+import java.sql.SQLException;
+import java.sql.Statement;
+import javax.sql.DataSource;
+
 import org.apache.sis.internal.metadata.sql.Initializer;
 import org.apache.sis.internal.metadata.sql.ScriptRunner;
 import org.apache.sis.test.TestCase;
 import org.apache.sis.util.Debug;
 
+import org.apache.derby.jdbc.EmbeddedDataSource;
+
+import org.h2.jdbcx.JdbcConnectionPool;
+import org.h2.jdbcx.JdbcDataSource;
+import org.hsqldb.jdbc.JDBCDataSource;
+import org.hsqldb.jdbc.JDBCPool;
+import org.postgresql.PGProperty;
+import org.postgresql.ds.PGSimpleDataSource;
+
 import static org.junit.Assume.assumeFalse;
 import static org.junit.Assume.assumeTrue;
 
@@ -174,6 +179,28 @@ public strictfp class TestDatabase implements AutoCloseable {
         };
     }
 
+    public static TestDatabase createOnH2(final String name, final boolean pooled) throws SQLException {
+        final String url = "jdbc:h2:mem:".concat(name).concat(";DB_CLOSE_DELAY=-1");
+        final DataSource ds;
+        if (pooled) {
+            // A null pointer exception occurs on pooled connection is not set
+            ds = JdbcConnectionPool.create(url, "sis", "sis");
+        } else {
+            final JdbcDataSource tmpDs = new JdbcDataSource();
+            tmpDs.setURL(url);
+            ds = tmpDs;
+        }
+
+        return new TestDatabase(ds) {
+            @Override
+            public void close() throws SQLException {
+                try (Connection c = ds.getConnection(); Statement s = c.createStatement()) {
+                    s.execute("SHUTDOWN");
+                }
+            }
+        };
+    }
+
     /**
      * Creates a connection to an existing PostgreSQL database.
      * This method returns only if all the following conditions are true:
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
index 8ffed08..565cf78 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
@@ -16,39 +16,45 @@
  */
 package org.apache.sis.referencing.factory.sql;
 
-import java.util.Map;
-import java.util.Set;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.regex.Pattern;
 import java.io.IOException;
-import javax.sql.DataSource;
 import java.sql.Connection;
-import java.sql.Statement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import org.opengis.util.FactoryException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+import javax.sql.DataSource;
+
 import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.ProjectedCRS;
-import org.apache.sis.referencing.CommonCRS;
+import org.opengis.util.FactoryException;
+
+import org.apache.sis.internal.metadata.sql.Reflection;
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.util.Constants;
-import org.apache.sis.internal.metadata.sql.Reflection;
+import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.LoggingWatcher;
+import org.apache.sis.test.TestCase;
+import org.apache.sis.test.sql.TestDatabase;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Utilities;
 
-// Test dependencies
-import org.apache.sis.test.sql.TestDatabase;
-import org.apache.sis.test.LoggingWatcher;
-import org.apache.sis.test.DependsOn;
-import org.apache.sis.test.TestCase;
 import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assume.assumeTrue;
 
+// Test dependencies
+
 
 /**
  * Tests {@link EPSGInstaller} indirectly, through {@link EPSGFactory#install(Connection)}.
@@ -161,6 +167,22 @@ public final strictfp class EPSGInstallerTest extends TestCase {
         loggings.assertNextLogContains("EPSG", "jdbc:hsqldb:mem:EPSGInstaller");
         loggings.assertNoUnexpectedLog();
     }
+    /**
+     * Tests the creation of an EPSG database on H2.
+     * This test is skipped if the SQL scripts are not found.
+     *
+     * @throws Exception if an error occurred while creating the database.
+     */
+    @Test
+    public void testCreationOnH2() throws Exception {
+        final InstallationScriptProvider scripts = getScripts();            // Needs to be invoked first.
+        try (TestDatabase db = TestDatabase.createOnH2("EPSGInstaller", false)) {
+            createAndTest(db.source, scripts);
+            verifyParameterValues(db.source);
+        }
+        loggings.assertNextLogContains("EPSG", "jdbc:h2:mem:EPSGInstaller");
+        loggings.assertNoUnexpectedLog();
+    }
 
     /**
      * Tests the creation of an EPSG database on PostgreSQL. This test requires a PostgreSQL server


[sis] 03/04: chore(SQLStore): add basic testing on H2.

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

amanin pushed a commit to branch fix/fast-envelope
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 125b08b10adc5d8081baebe68b9916e2dbe8e287
Author: Alexis Manin <am...@apache.org>
AuthorDate: Tue Jan 21 16:33:32 2020 +0100

    chore(SQLStore): add basic testing on H2.
---
 .../src/test/java/org/apache/sis/storage/sql/SQLStoreTest.java | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/SQLStoreTest.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/SQLStoreTest.java
index d1bcd97..10a9348 100644
--- a/storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/SQLStoreTest.java
+++ b/storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/SQLStoreTest.java
@@ -123,6 +123,16 @@ public final strictfp class SQLStoreTest extends TestCase {
     }
 
     /**
+     * Tests on H2.
+     *
+     * @throws Exception if an error occurred while testing the database.
+     */
+    @Test
+    public void testOnH2() throws Exception {
+        test(TestDatabase.createOnH2("SQLStore", true), true);
+    }
+
+    /**
      * Tests on PostgreSQL.
      *
      * @throws Exception if an error occurred while testing the database.


[sis] 01/04: chore(Feature): add unit tests for new feature utility methods

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

amanin pushed a commit to branch fix/fast-envelope
in repository https://gitbox.apache.org/repos/asf/sis.git

commit fb7741df6d3b92d41209897367d0758fe69323c7
Author: Alexis Manin <am...@apache.org>
AuthorDate: Tue Jan 21 11:18:56 2020 +0100

    chore(Feature): add unit tests for new feature utility methods
---
 .../java/org/apache/sis/feature/FeaturesTest.java  | 103 ++++++++++++++++++++-
 1 file changed, 98 insertions(+), 5 deletions(-)

diff --git a/core/sis-feature/src/test/java/org/apache/sis/feature/FeaturesTest.java b/core/sis-feature/src/test/java/org/apache/sis/feature/FeaturesTest.java
index 73972bb..71f7f0a 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/feature/FeaturesTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/feature/FeaturesTest.java
@@ -16,16 +16,36 @@
  */
 package org.apache.sis.feature;
 
+import java.util.Collections;
+import java.util.Optional;
+
+import org.opengis.feature.AttributeType;
+import org.opengis.feature.Feature;
+import org.opengis.feature.InvalidPropertyValueException;
+import org.opengis.feature.Operation;
+import org.opengis.feature.PropertyNotFoundException;
+import org.opengis.feature.PropertyType;
+import org.opengis.metadata.acquisition.GeometryType;
+
+import org.apache.sis.feature.builder.AttributeRole;
+import org.apache.sis.feature.builder.AttributeTypeBuilder;
+import org.apache.sis.feature.builder.FeatureTypeBuilder;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
+
 import org.junit.Test;
 
-import static org.junit.Assert.*;
+import static org.apache.sis.feature.CharacteristicTypeMapTest.temperature;
+import static org.apache.sis.feature.DefaultAttributeTypeTest.city;
+import static org.apache.sis.feature.DefaultAttributeTypeTest.parliament;
+import static org.apache.sis.feature.DefaultFeatureTypeTest.capital;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 // Branch-dependent imports
-import org.opengis.feature.Feature;
-import org.opengis.feature.InvalidPropertyValueException;
-
 
 /**
  * Tests {@link Features}.
@@ -43,7 +63,7 @@ public final strictfp class FeaturesTest extends TestCase {
      */
     @Test
     public void testCastAttributeType() {
-        final DefaultAttributeType<String> parliament = DefaultAttributeTypeTest.parliament();
+        final DefaultAttributeType<String> parliament = parliament();
         assertSame(parliament, Features.cast(parliament, String.class));
         try {
             Features.cast(parliament, CharSequence.class);
@@ -95,4 +115,77 @@ public final strictfp class FeaturesTest extends TestCase {
         feature.setPropertyValue("population", 10);
         Features.validate(feature);
     }
+
+    @Test
+    public void unwrapAttribute() {
+        final Operation link = new LinkOperation(Collections.singletonMap("name", "link"), city());
+        AttributeType<?> attr = Features.castOrUnwrap(link)
+                .orElseThrow(() -> new AssertionError("Attribute result of link operation has not been found"));
+        assertEquals("Found attribute should the link target", city(), attr);
+
+        final LinkOperation overLink = new LinkOperation(Collections.singletonMap("name", "linkOfLink"), link);
+        attr = Features.castOrUnwrap(overLink)
+                .orElseThrow(() -> new AssertionError("Attribute result of link operation has not been found"));
+
+        assertEquals("Found attribute should the link target", city(), attr);
+
+        attr = Features.castOrUnwrap(city())
+                .orElseThrow(() -> new AssertionError("Given attribute should be returned directly"));
+        assertEquals("Attribute should be returned directly", attr, city());
+    }
+
+    @Test
+    public void getCharacteristicAndItsValue() {
+        final String characteristicName = "units";
+        Optional<AttributeType> units = Features.getCharacteristic(temperature(), characteristicName);
+        assertTrue("We should have found a characteristic for "+characteristicName, units.isPresent());
+        assertEquals("Characteristic name", characteristicName, units.get().getName().tip().toString());
+
+        // Even through a link, we should be able to find the characteristic
+        final LinkOperation link = new LinkOperation(Collections.singletonMap("name", "link for temperature"), temperature());
+        units = Features.getCharacteristic(link, characteristicName);
+        assertTrue("We should have found a characteristic for "+characteristicName, units.isPresent());
+        assertEquals("Characteristic name", characteristicName, units.get().getName().tip().toString());
+
+        // Now we'll check the commodity method to get directly the value
+        Optional<String> unitValue = Features.getCharacteristicValue(link, characteristicName);
+        assertTrue("We should have found a value for characteristic: "+characteristicName, unitValue.isPresent());
+        assertEquals("Unit value", "°C", unitValue.get());
+    }
+
+    @Test
+    public void getDefaultGeometry() {
+        try {
+            final PropertyType found = Features.getDefaultGeometry(capital());
+            fail("Utility method should fail on given feature type because no geometry is available in it, but returned: "+found);
+        } catch (PropertyNotFoundException e) {
+            // That's expected behavior
+        }
+
+        final FeatureTypeBuilder builder = new FeatureTypeBuilder()
+                .setName("CapitalPosition")
+                .setSuperTypes(capital());
+
+        final AttributeTypeBuilder<?> geomBuilder = builder.addAttribute(GeometryType.POINT).setName("location");
+
+        final PropertyType geometry = Features.getDefaultGeometry(builder.build());
+        assertNotNull("Should have found the location", geometry);
+        assertEquals("Found attribute: ", "location", geometry.getName().tip().toString());
+
+        builder.addAttribute(GeometryType.POINT)
+                .setName("parliament.location");
+
+        try {
+            final PropertyType found = Features.getDefaultGeometry(builder.build());
+            fail("Ambiguity (two geometries available without convention) should prevent a result, but got: "+found);
+        } catch (IllegalStateException e) {
+            // Expected behavior
+        }
+
+        // We should be able to choose the SIS convention by default.
+        geomBuilder.addRole(AttributeRole.DEFAULT_GEOMETRY);
+        final PropertyType found = Features.getDefaultGeometry(builder.build());
+        assertNotNull("Should have found the location", geometry);
+        assertEquals("Found attribute: ", "location", geometry.getName().tip().toString());
+    }
 }