Mercurial > dive4elements > river
changeset 9671:9cfc495a9f40 3.2.x
Add minimal test coverage for MapServer connection generation
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 22 May 2020 19:45:08 +0200 (2020-05-22) |
parents | 07d854c325d8 |
children | b70b1bc0eece |
files | artifacts/pom.xml artifacts/src/main/java/org/dive4elements/river/utils/MapUtils.java artifacts/src/test/java/org/dive4elements/river/utils/MapUtilsTest.java |
diffstat | 3 files changed, 55 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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>
--- 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; }
--- /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); + } +}