sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1728236 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/ sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/ s...
Date Tue, 02 Feb 2016 23:16:55 GMT
Author: desruisseaux
Date: Tue Feb  2 23:16:55 2016
New Revision: 1728236

URL: http://svn.apache.org/viewvc?rev=1728236&view=rev
Log:
Begin EPSGInstaller tests.

Added:
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java
  (with props)
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java?rev=1728236&r1=1728235&r2=1728236&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] Tue Feb  2 23:16:55 2016
@@ -397,7 +397,11 @@ public abstract class Initializer {
             try {
                 ds.getConnection().close();     // Does the actual shutdown.
             } catch (SQLException e) {          // This is the expected exception.
-                final LogRecord record = new LogRecord(Level.CONFIG, e.getLocalizedMessage());
     // Not WARNING.
+                Level level = Level.CONFIG;
+                if (e.getErrorCode() != 45000 || !"08006".equals(e.getSQLState())) {
+                    level = Level.WARNING;
+                }
+                final LogRecord record = new LogRecord(level, e.getLocalizedMessage());
                 record.setLoggerName(Loggers.SQL);
                 Logging.log(Initializer.class, "shutdown", record);
             }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java?rev=1728236&r1=1728235&r2=1728236&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
[UTF-8] Tue Feb  2 23:16:55 2016
@@ -19,6 +19,7 @@ package org.apache.sis.internal.metadata
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Locale;
+import java.util.function.BiFunction;
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -318,6 +319,16 @@ public class ScriptRunner implements Aut
     }
 
     /**
+     * For every entries in the replacements map, replace the entry value by the value returned
by
+     * {@code function(key, value)}.
+     *
+     * @param function The function that modify the replacement mapping.
+     */
+    protected final void modifyReplacements(final BiFunction<String,String,String>
function) {
+        replacements.replaceAll(function);
+    }
+
+    /**
      * Runs the given SQL script.
      * Lines are read and grouped up to the terminal {@value #END_OF_STATEMENT} character,
then sent to the database.
      *
@@ -476,7 +487,7 @@ parseLine:  while (pos < length) {
                         if (!isInsideIdentifier) {
                             if (!isInsideText) {
                                 isInsideText = true;
-                            } else if ((pos += n) >= length || buffer.codePointAt(pos)
== QUOTE) {
+                            } else if ((pos += n) >= length || buffer.codePointAt(pos)
!= QUOTE) {
                                 isInsideText = false;
                                 continue;   // Because we already skipped the ' character.
                             } // else found a double ' character, which means to escape it.

Added: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java?rev=1728236&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java
(added)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java
[UTF-8] Tue Feb  2 23:16:55 2016
@@ -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.internal.metadata.sql;
+
+import java.sql.SQLException;
+import javax.sql.DataSource;
+import org.apache.sis.internal.system.DataDirectory;
+
+import static org.junit.Assume.*;
+
+// Branch-dependent imports
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+
+/**
+ * Utility methods for creating temporary databases with Derby.
+ * The databases are in-memory only.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+public final strictfp class TestDatabase {
+    /**
+     * Do not allow (for now) instantiation of this class.
+     */
+    private TestDatabase() {
+    }
+
+    /**
+     * Returns the path to the directory of the given name in {@code $SIS_DATA/Databases}.
+     * If the directory is not found, then the test will be interrupted by an {@code org.junit.Assume}
statement.
+     *
+     * @param name The name of the sub-directory.
+     * @return The path to the given sub-directory.
+     */
+    public static Path directory(final String name) {
+        Path dir = DataDirectory.DATABASES.getDirectory();
+        assumeNotNull("$SIS_DATA/Databases directory not found.", dir);
+        dir = dir.resolve(name);
+        assumeTrue("Specified directory not found.", Files.isDirectory(dir));
+        return dir;
+    }
+
+    /**
+     * Creates a Derby database in memory. If no Derby or JavaDB driver is not found,
+     * then the test will be interrupted by an {@code org.junit.Assume} statement.
+     *
+     * @param  name The database name (without {@code "memory:"} prefix).
+     * @return The data source.
+     * @throws Exception if an error occurred while creating the database.
+     */
+    public static DataSource create(final String name) throws Exception {
+        final DataSource ds;
+        try {
+            ds = Initializer.forJavaDB("memory:" + name);
+        } catch (ClassNotFoundException e) {
+            assumeNoException("No Derby or JavaDB driver has been found.", e);
+            throw e;
+        }
+        ds.getClass().getMethod("setCreateDatabase", String.class).invoke(ds, "create");
+        return ds;
+    }
+
+    /**
+     * Drops an in-memory Derby database after usage.
+     *
+     * @param  ds The data source created by {@link #create(String)}.
+     * @throws Exception if an error occurred while dropping the database.
+     */
+    public static void drop(final DataSource ds) throws Exception {
+        ds.getClass().getMethod("setCreateDatabase", String.class).invoke(ds, "no");
+        ds.getClass().getMethod("setConnectionAttributes", String.class).invoke(ds, "drop=true");
+        try {
+            ds.getConnection();
+        } catch (SQLException e) {          // This is the expected exception.
+            if (e.getErrorCode() != 45000 || !"08006".equals(e.getSQLState())) {
+                throw e;
+            }
+        }
+    }
+}

Propchange: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java?rev=1728236&r1=1728235&r2=1728236&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] Tue Feb  2 23:16:55 2016
@@ -136,6 +136,9 @@ final class EPSGInstaller extends Script
              * Mapping from the table names used in the SQL scripts to the original names
used in the MS-Access database.
              * We use those original names because they are easier to read than the names
in SQL scripts.
              */
+            replace(SQLTranslator.TABLE_PREFIX + "alias",                      "Alias");
+            replace(SQLTranslator.TABLE_PREFIX + "area",                       "Area");
+            replace(SQLTranslator.TABLE_PREFIX + "change",                     "Change");
             replace(SQLTranslator.TABLE_PREFIX + "coordinateaxis",             "Coordinate
Axis");
             replace(SQLTranslator.TABLE_PREFIX + "coordinateaxisname",         "Coordinate
Axis Name");
             replace(SQLTranslator.TABLE_PREFIX + "coordoperation",             "Coordinate_Operation");
@@ -146,10 +149,15 @@ final class EPSGInstaller extends Script
             replace(SQLTranslator.TABLE_PREFIX + "coordoperationpath",         "Coordinate_Operation
Path");
             replace(SQLTranslator.TABLE_PREFIX + "coordinatereferencesystem",  "Coordinate
Reference System");
             replace(SQLTranslator.TABLE_PREFIX + "coordinatesystem",           "Coordinate
System");
+            replace(SQLTranslator.TABLE_PREFIX + "datum",                      "Datum");
+            replace(SQLTranslator.TABLE_PREFIX + "deprecation",                "Deprecation");
+            replace(SQLTranslator.TABLE_PREFIX + "ellipsoid",                  "Ellipsoid");
             replace(SQLTranslator.TABLE_PREFIX + "namingsystem",               "Naming System");
             replace(SQLTranslator.TABLE_PREFIX + "primemeridian",              "Prime Meridian");
+            replace(SQLTranslator.TABLE_PREFIX + "supersession",               "Supersession");
             replace(SQLTranslator.TABLE_PREFIX + "unitofmeasure",              "Unit of Measure");
             replace(SQLTranslator.TABLE_PREFIX + "versionhistory",             "Version History");
+            modifyReplacements((String key, String value) -> schema + '.' + identifierQuote
+ value + identifierQuote);
         }
     }
 

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java?rev=1728236&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
[UTF-8] Tue Feb  2 23:16:55 2016
@@ -0,0 +1,60 @@
+/*
+ * 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.referencing.factory.sql;
+
+import java.sql.Connection;
+import javax.sql.DataSource;
+import org.apache.sis.internal.metadata.sql.TestDatabase;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+// Branch-dependent imports
+import java.nio.file.Path;
+
+
+/**
+ * Tests {@link EPSGInstaller}. Every databases created by this test suite exists only in
memory.
+ * This class does not write anything to disk (except maybe some temporary files).
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+@DependsOn(EPSGFactoryTest.class)
+public final strictfp class EPSGInstallerTest extends TestCase {
+    /**
+     * Tests the creation of an EPSG database on Derby.
+     * This test is skipped if no Derby or JavaDB driver has been found.
+     *
+     * @throws Exception if an error occurred while creating the database.
+     */
+    @Test
+    public void testCreationOnDerby() throws Exception {
+        final Path scripts = TestDatabase.directory("Scripts");
+        final DataSource ds = TestDatabase.create("test");
+        try (Connection c = ds.getConnection()) {
+            try (EPSGInstaller installer = new EPSGInstaller(c)) {
+                installer.setSchema("EPSG");
+                installer.run(scripts);
+            }
+        } finally {
+            TestDatabase.drop(ds);
+        }
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1728236&r1=1728235&r2=1728236&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Tue Feb  2 23:16:55 2016
@@ -201,6 +201,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.factory.IdentifiedObjectFinderTest.class,
     org.apache.sis.referencing.factory.MultiAuthoritiesFactoryTest.class,
     org.apache.sis.referencing.factory.sql.EPSGFactoryTest.class,
+    org.apache.sis.referencing.factory.sql.EPSGInstallerTest.class,
     org.apache.sis.referencing.EPSGFactoryFallbackTest.class,
     org.apache.sis.referencing.AuthorityFactoriesTest.class,
     org.apache.sis.referencing.CRSTest.class,
@@ -217,7 +218,7 @@ import org.junit.BeforeClass;
     org.apache.sis.geometry.CurveExtremumTest.class,
     org.apache.sis.geometry.EnvelopesTest.class,
 
-    org.apache.sis.distance.LatLonPointRadiusTest.class, // Pending refactoring in a geometry
package.
+    org.apache.sis.distance.LatLonPointRadiusTest.class,        // Pending refactoring in
a geometry package.
 
     org.apache.sis.referencing.operation.builder.LinearTransformBuilderTest.class,
     org.apache.sis.internal.referencing.ServicesForMetadataTest.class,



Mime
View raw message