# HG changeset patch # User Tom Gottfried # Date 1590169508 -7200 # 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 @@ junit junit - 3.8.1 + 4.13 test 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); + } +}