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

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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new ee6e4b795c Use a separated option for enabling tests on the PostgreSQL 
database.
ee6e4b795c is described below

commit ee6e4b795c7786e3033a7a727f0c67506ed5f268
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Feb 21 14:30:17 2024 +0100

    Use a separated option for enabling tests on the PostgreSQL database.
---
 .../test/org/apache/sis/metadata/sql/TestDatabase.java       |  6 ++++++
 .../test/org/apache/sis/test/TestCase.java                   | 12 +++++++++---
 .../test/org/apache/sis/test/TestConfiguration.java          | 10 ++++++++++
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java
 
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java
index 6e4a998542..2e7d712b42 100644
--- 
a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java
+++ 
b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java
@@ -35,6 +35,8 @@ import org.apache.sis.util.Debug;
 
 // Test dependencies
 import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+import org.apache.sis.test.TestCase;
 
 
 /**
@@ -97,6 +99,8 @@ public class TestDatabase implements AutoCloseable {
     /**
      * Name of the database to use for testing purpose. This is used only when 
running tests on database engine
      * that do not support in-memory database, like PostgreSQL.
+     *
+     * @see #createOnPostgreSQL(String, boolean)
      */
     private static final String NAME = "SpatialMetadataTest";
 
@@ -228,6 +232,7 @@ public class TestDatabase implements AutoCloseable {
      * This method returns only if all the following conditions are true:
      *
      * <ol>
+     *   <li>{@link TestCase#USE_POSTGRESQL} is {@code true} (for reducing the 
risk of messing with user installation).</li>
      *   <li>A PostgreSQL server is running on the local host and listening to 
the default port.</li>
      *   <li>A database named {@value #NAME} exists.</li>
      *   <li>A role with Unix user name exists and can connect to the database 
without password.</li>
@@ -249,6 +254,7 @@ public class TestDatabase implements AutoCloseable {
      * @see <a href="https://sis.apache.org/source.html#postgres";>Configuring 
PostgreSQL for Apache SIS tests</a>
      */
     public static TestDatabase createOnPostgreSQL(final String schema, final 
boolean create) throws SQLException {
+        assumeTrue(TestCase.USE_POSTGRESQL, "Use of PostgreSQL database is not 
enabled.");
         final var ds = new PGSimpleDataSource();
         // Server default to "localhost".
         ds.setDatabaseName(NAME);
diff --git 
a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java 
b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java
index 8c60ca339f..200dae670d 100644
--- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java
+++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java
@@ -97,6 +97,11 @@ public abstract class TestCase {
      */
     public static final boolean RUN_EXTENSIVE_TESTS;
 
+    /**
+     * Whether the tests can use the PostgreSQL database on the local host.
+     */
+    public static final boolean USE_POSTGRESQL;
+
     /**
      * Whether the tests should print debugging information. This is set to 
the value specified by the
      * {@value org.apache.sis.test.TestConfiguration#VERBOSE_OUTPUT_KEY} 
system property if defined,
@@ -138,9 +143,10 @@ public abstract class TestCase {
     static {
         out = new PrintWriter(buffer = new StringWriter());
         final Set<String> options = 
Set.of(Strings.orEmpty(System.getenv(TestConfiguration.SIS_TEST_OPTIONS)).split(","));
-        RUN_EXTENSIVE_TESTS = isEnabled(options, "extensive", 
TestConfiguration.EXTENSIVE_TESTS_KEY);
-        SHOW_WIDGET = isEnabled(options, "widget", 
TestConfiguration.SHOW_WIDGET_KEY);
-        VERBOSE = isEnabled(options, "verbose", 
TestConfiguration.VERBOSE_OUTPUT_KEY);
+        RUN_EXTENSIVE_TESTS = isEnabled(options, "extensive",  
TestConfiguration.EXTENSIVE_TESTS_KEY);
+        USE_POSTGRESQL      = isEnabled(options, "postgresql", 
TestConfiguration.USE_POSTGRESQL_KEY);
+        SHOW_WIDGET         = isEnabled(options, "widget",     
TestConfiguration.SHOW_WIDGET_KEY);
+        VERBOSE             = isEnabled(options, "verbose",    
TestConfiguration.VERBOSE_OUTPUT_KEY);
         if (VERBOSE) {
             System.setErr(System.out);      // For avoiding log records to be 
interleaved with block of text.
         }
diff --git 
a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestConfiguration.java
 
b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestConfiguration.java
index 64dd808442..fa56ccf190 100644
--- 
a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestConfiguration.java
+++ 
b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestConfiguration.java
@@ -45,6 +45,16 @@ public final class TestConfiguration extends Static {
      */
     public static final String EXTENSIVE_TESTS_KEY = 
"org.apache.sis.test.extensive";
 
+    /**
+     * The {@systemProperty org.apache.sis.test.postgresql} system property 
for enabling tests
+     * on the PostgreSQL database. If this {@linkplain System#getProperties() 
system property}
+     * is set to {@code true}, then the {@code "SpatialMetadataTest"} database 
will be used.
+     *
+     * @see TestCase#USE_POSTGRESQL
+     * @see org.apache.sis.metadata.sql.TestDatabase
+     */
+    public static final String USE_POSTGRESQL_KEY = 
"org.apache.sis.test.postgresql";
+
     /**
      * The {@systemProperty org.apache.sis.test.verbose} system property for 
enabling verbose outputs.
      * If this {@linkplain System#getProperties() system property} is set to 
{@code true},

Reply via email to