sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1811215 - in /sis/data/non-free: sis-embedded-data/src/main/java/org/apache/sis/resources/embedded/ sis-embedded-data/src/test/java/org/apache/sis/resources/embedded/ sis-epsg/src/test/java/org/apache/sis/referencing/factory/sql/epsg/
Date Thu, 05 Oct 2017 15:55:17 GMT
Author: desruisseaux
Date: Thu Oct  5 15:55:17 2017
New Revision: 1811215

URL: http://svn.apache.org/viewvc?rev=1811215&view=rev
Log:
Add tests for embedded Derby database.

Added:
    sis/data/non-free/sis-embedded-data/src/test/java/org/apache/sis/resources/embedded/EmbeddedResourcesTest.java
  (with props)
Modified:
    sis/data/non-free/sis-embedded-data/src/main/java/org/apache/sis/resources/embedded/EmbeddedResources.java
    sis/data/non-free/sis-epsg/src/test/java/org/apache/sis/referencing/factory/sql/epsg/ScriptProviderTest.java

Modified: sis/data/non-free/sis-embedded-data/src/main/java/org/apache/sis/resources/embedded/EmbeddedResources.java
URL: http://svn.apache.org/viewvc/sis/data/non-free/sis-embedded-data/src/main/java/org/apache/sis/resources/embedded/EmbeddedResources.java?rev=1811215&r1=1811214&r2=1811215&view=diff
==============================================================================
--- sis/data/non-free/sis-embedded-data/src/main/java/org/apache/sis/resources/embedded/EmbeddedResources.java
[UTF-8] (original)
+++ sis/data/non-free/sis-embedded-data/src/main/java/org/apache/sis/resources/embedded/EmbeddedResources.java
[UTF-8] Thu Oct  5 15:55:17 2017
@@ -42,11 +42,6 @@ import org.apache.sis.util.resources.Err
  */
 public class EmbeddedResources extends InstallationResources {
     /**
-     * The pseudo-authority name used for the embedded data resources.
-     */
-    private static final String AUTHORITY = "Embedded";
-
-    /**
      * Creates a new provider for connections to the embedded database.
      */
     public EmbeddedResources() {
@@ -59,14 +54,14 @@ public class EmbeddedResources extends I
      */
     @Override
     public Set<String> getAuthorities() {
-        return Collections.singleton(AUTHORITY);
+        return Collections.singleton(Initializer.EMBEDDED);
     }
 
     /**
      * Verifies that the given authority is the expected values.
      */
     private void verifyAuthority(final String authority) {
-        if (!AUTHORITY.equalsIgnoreCase(authority)) {
+        if (!Initializer.EMBEDDED.equalsIgnoreCase(authority)) {
             throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2,
"authority", authority));
         }
     }

Added: sis/data/non-free/sis-embedded-data/src/test/java/org/apache/sis/resources/embedded/EmbeddedResourcesTest.java
URL: http://svn.apache.org/viewvc/sis/data/non-free/sis-embedded-data/src/test/java/org/apache/sis/resources/embedded/EmbeddedResourcesTest.java?rev=1811215&view=auto
==============================================================================
--- sis/data/non-free/sis-embedded-data/src/test/java/org/apache/sis/resources/embedded/EmbeddedResourcesTest.java
(added)
+++ sis/data/non-free/sis-embedded-data/src/test/java/org/apache/sis/resources/embedded/EmbeddedResourcesTest.java
[UTF-8] Thu Oct  5 15:55:17 2017
@@ -0,0 +1,84 @@
+/*
+ * 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.resources.embedded;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.Iterator;
+import java.util.ServiceLoader;
+import javax.sql.DataSource;
+import org.apache.sis.setup.InstallationResources;
+import org.apache.sis.internal.metadata.sql.Initializer;
+import org.apache.sis.internal.system.DataDirectory;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link EmbeddedResources}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 0.8
+ * @since   0.8
+ */
+public final strictfp class EmbeddedResourcesTest {
+    /**
+     * Returns the {@link ScriptProvider} instance declared in the {@code META-INF/services/}
directory.
+     */
+    private static InstallationResources getInstance() {
+        final Iterator<InstallationResources> it = ServiceLoader.load(InstallationResources.class).iterator();
+        final InstallationResources provider = it.next();
+        assertFalse("Expected only one instance.", it.hasNext());
+        return provider;
+    }
+
+    /**
+     * Tests fetching the licenses.
+     *
+     * @throws IOException if an error occurred while reading a license.
+     */
+    @Test
+    public void testLicences() throws IOException {
+        final InstallationResources provider = getInstance();
+        assertTrue(provider.getLicense("Embedded", null, "text/plain").contains("IOGP"));
+        assertTrue(provider.getLicense("Embedded", null, "text/html" ).contains("IOGP"));
+    }
+
+    /**
+     * Tests connecting to the database.
+     *
+     * @throws Exception if an error occurred while fetching the data source, or connecting
to the database.
+     */
+    @Test
+    public void testConnection() throws Exception {
+        assertTrue("The SIS_DATA environment variable must be unset for enabling this test.",
DataDirectory.isEnvClear());
+        final DataSource ds = Initializer.getDataSource();
+        assertNotNull("Can not find the data source.", ds);
+        try (Connection c = ds.getConnection()) {
+            try (Statement s = c.createStatement()) {
+                try (ResultSet r = s.executeQuery("SELECT COORD_REF_SYS_NAME FROM EPSG.\"Coordinate
Reference System\" WHERE COORD_REF_SYS_CODE = 4326")) {
+                    assertTrue("ResultSet.next()", r.next());
+                    assertEquals("WGS 84", r.getString(1));
+                    assertFalse("ResultSet.next()", r.next());
+                }
+            }
+        }
+    }
+}

Propchange: sis/data/non-free/sis-embedded-data/src/test/java/org/apache/sis/resources/embedded/EmbeddedResourcesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/data/non-free/sis-embedded-data/src/test/java/org/apache/sis/resources/embedded/EmbeddedResourcesTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/data/non-free/sis-epsg/src/test/java/org/apache/sis/referencing/factory/sql/epsg/ScriptProviderTest.java
URL: http://svn.apache.org/viewvc/sis/data/non-free/sis-epsg/src/test/java/org/apache/sis/referencing/factory/sql/epsg/ScriptProviderTest.java?rev=1811215&r1=1811214&r2=1811215&view=diff
==============================================================================
--- sis/data/non-free/sis-epsg/src/test/java/org/apache/sis/referencing/factory/sql/epsg/ScriptProviderTest.java
[UTF-8] (original)
+++ sis/data/non-free/sis-epsg/src/test/java/org/apache/sis/referencing/factory/sql/epsg/ScriptProviderTest.java
[UTF-8] Thu Oct  5 15:55:17 2017
@@ -29,7 +29,9 @@ import static org.junit.Assert.*;
 /**
  * Test {@link ScriptProvider}.
  *
- * @author Martin Desruisseaux (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 0.7
+ * @since   0.7
  */
 public final strictfp class ScriptProviderTest {
     /**
@@ -43,16 +45,25 @@ public final strictfp class ScriptProvid
     }
 
     /**
-     * Tests fetching the resources.
+     * Tests fetching the licenses.
      *
-     * @throws IOException if an error occurred while reading a resource.
+     * @throws IOException if an error occurred while reading a license.
      */
     @Test
-    public void testResources() throws IOException {
-        final ScriptProvider provider = (ScriptProvider) getInstance();
+    public void testLicences() throws IOException {
+        final InstallationResources provider = getInstance();
         assertTrue(provider.getLicense("EPSG", null, "text/plain").contains("IOGP"));
         assertTrue(provider.getLicense("EPSG", null, "text/html" ).contains("IOGP"));
+    }
 
+    /**
+     * Tests fetching the resources.
+     *
+     * @throws IOException if an error occurred while reading a resource.
+     */
+    @Test
+    public void testResources() throws IOException {
+        final InstallationResources provider = getInstance();
         final String[] names = provider.getResourceNames("EPSG");
         assertArrayEquals(new String[] {"Prepare", "Tables.sql", "Data.sql", "FKeys.sql",
"Finish"}, names);
         for (int i=0; i<names.length; i++) {



Mime
View raw message