[PATCH] Add minimal test coverage for MapServer connection generation

Wald Commits scm-commit at wald.intevation.org
Fri May 22 20:08:55 CEST 2020


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1590169508 -7200
#      Fri May 22 19:45:08 2020 +0200
# Branch 3.2.x
# Node ID 9cfc495a9f40b1a64d58c609076be47a8f2e1cc3
# Parent  07d854c325d8bf776e95bb83b20a02ca69446081
Add minimal test coverage for MapServer connection generation

diff -r 07d854c325d8 -r 9cfc495a9f40 artifacts/pom.xml
--- a/artifacts/pom.xml	Wed May 20 17:50:27 2020 +0200
+++ b/artifacts/pom.xml	Fri May 22 19:45:08 2020 +0200
@@ -77,7 +77,7 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>3.8.1</version>
+      <version>4.13</version>
       <scope>test</scope>
     </dependency>
     <dependency>
diff -r 07d854c325d8 -r 9cfc495a9f40 artifacts/src/main/java/org/dive4elements/river/utils/MapUtils.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/MapUtils.java	Wed May 20 17:50:27 2020 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/MapUtils.java	Fri May 22 19:45:08 2020 +0200
@@ -38,6 +38,10 @@
         String pass = SessionFactoryProvider.getPass(sf);
         String url  = SessionFactoryProvider.getURL(sf);
 
+        return getConnection(user, pass, url);
+    }
+
+    public static String getConnection(String user, String pass, String url) {
         log.debug("Parse connection url: " + url);
 
         Matcher m = DB_URL_PATTERN.matcher(url);
@@ -65,7 +69,7 @@
         String port = m.group(3);
         String db   = m.group(4);
 
-        if (RiverUtils.isUsingOracle()) {
+        if (url.startsWith("jdbc:oracle:")) {
             connection = user + "/" + pass
                 + "@" + host + ":" + port + "/" + db;
         }
diff -r 07d854c325d8 -r 9cfc495a9f40 artifacts/src/test/java/org/dive4elements/river/utils/MapUtilsTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/test/java/org/dive4elements/river/utils/MapUtilsTest.java	Fri May 22 19:45:08 2020 +0200
@@ -0,0 +1,49 @@
+/* Copyright (C) 2020 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import org.dive4elements.river.utils.MapUtils;
+
+public class MapUtilsTest {
+
+    private static final String DRV_PG  = "jdbc:postgresql:";
+    private static final String DRV_ORA = "jdbc:oracle:thin:";
+
+    private static final String USER = "d4euser";
+    private static final String PSWD = "d4epswd";
+    private static final String DB   = "d4edb";
+    private static final String HOST = "d4ehost";
+    private static final String PORT = "2345";
+
+    private static final String PG_CON_SUFFIX = " sslmode=disable";
+
+    @Test
+    public void hostPortNamedPG() {
+        MapUtils mu = new MapUtils();
+        String con = MapUtils.getConnection(
+            USER, PSWD, DRV_PG + "//" + HOST + ":" + PORT + "/" + DB);
+        assertEquals(
+            "dbname=" + DB
+            + " host='" + HOST + "' user=" + USER + " port=" + PORT
+            + " password='" + PSWD + "'" + PG_CON_SUFFIX,
+            con);
+    }
+
+    @Test
+    public void serviceNameORA() {
+        MapUtils mu = new MapUtils();
+        String con = MapUtils.getConnection(
+            USER, PSWD, DRV_ORA + "@//" + HOST + ":" + PORT + "/" + DB);
+        assertEquals(
+            USER + "/" + PSWD + "@" + HOST + ":" + PORT + "/" + DB,
+            con);
+    }
+}


More information about the Dive4Elements-commits mailing list