tom@9671: /* Copyright (C) 2020 by Bundesanstalt für Gewässerkunde tom@9671: * Software engineering by Intevation GmbH tom@9671: * tom@9671: * This file is Free Software under the GNU AGPL (>=v3) tom@9671: * and comes with ABSOLUTELY NO WARRANTY! Check out the tom@9671: * documentation coming with Dive4Elements River for details. tom@9671: */ tom@9671: g@9683: package org.dive4elements.river.utils; g@9683: tom@9671: import static org.junit.Assert.assertEquals; tom@9672: import static org.junit.Assert.assertNull; tom@9671: tom@9671: import org.junit.Test; tom@9671: tom@9671: public class MapUtilsTest { tom@9671: tom@9671: private static final String DRV_PG = "jdbc:postgresql:"; tom@9671: private static final String DRV_ORA = "jdbc:oracle:thin:"; tom@9671: tom@9671: private static final String USER = "d4euser"; tom@9671: private static final String PSWD = "d4epswd"; tom@9671: private static final String DB = "d4edb"; tom@9671: private static final String HOST = "d4ehost"; tom@9671: private static final String PORT = "2345"; tom@9671: tom@9671: private static final String PG_CON_SUFFIX = " sslmode=disable"; tom@9671: tom@9671: @Test tom@9672: public void noJDBCURL() { g@9683: final String con = MapUtils.getConnection(USER, PSWD, "xx"); tom@9672: assertNull(con); tom@9672: } tom@9672: tom@9672: @Test tom@9672: public void invalidHostPG() { g@9683: final String con = MapUtils.getConnection( g@9683: USER, PSWD, DRV_PG + "//invalid_host_name/"); tom@9672: assertNull(con); tom@9672: } tom@9672: tom@9672: @Test tom@9672: public void localNamedPG() { g@9683: final String con = MapUtils.getConnection( g@9683: USER, PSWD, DRV_PG + DB); tom@9672: assertEquals( g@9683: "dbname=" + DB g@9683: + " user=" + USER g@9683: + " password='" + PSWD + "'" + PG_CON_SUFFIX, g@9683: con); tom@9672: } tom@9672: tom@9672: @Test tom@9672: public void localUserPG() { g@9683: final String con = MapUtils.getConnection( g@9683: USER, PSWD, DRV_PG + "/"); tom@9672: assertEquals( g@9683: "dbname=" + USER g@9683: + " user=" + USER g@9683: + " password='" + PSWD + "'" + PG_CON_SUFFIX, g@9683: con); tom@9672: } tom@9672: tom@9672: @Test tom@9672: public void hostNamedPG() { g@9683: final String con = MapUtils.getConnection( g@9683: USER, PSWD, DRV_PG + "//" + HOST + "/" + DB); tom@9672: assertEquals( g@9683: "dbname=" + DB g@9683: + " user=" + USER g@9683: + " host='" + HOST + "'" g@9683: + " password='" + PSWD + "'" + PG_CON_SUFFIX, g@9683: con); tom@9672: } tom@9672: tom@9672: @Test tom@9672: public void hostUserPG() { g@9683: final String con = MapUtils.getConnection( g@9683: USER, PSWD, DRV_PG + "//" + HOST + "/"); tom@9672: assertEquals( g@9683: "dbname=" + USER g@9683: + " user=" + USER g@9683: + " host='" + HOST + "'" g@9683: + " password='" + PSWD + "'" + PG_CON_SUFFIX, g@9683: con); tom@9672: } tom@9672: tom@9672: @Test tom@9672: public void hostPortUserPG() { g@9683: final String con = MapUtils.getConnection( g@9683: USER, PSWD, DRV_PG + "//" + HOST + ":" + PORT + "/"); tom@9672: assertEquals( g@9683: "dbname=" + USER g@9683: + " user=" + USER g@9683: + " host='" + HOST + "' port=" + PORT g@9683: + " password='" + PSWD + "'" + PG_CON_SUFFIX, g@9683: con); tom@9672: } tom@9672: tom@9672: @Test tom@9671: public void hostPortNamedPG() { g@9683: final String con = MapUtils.getConnection( g@9683: USER, PSWD, DRV_PG + "//" + HOST + ":" + PORT + "/" + DB); tom@9671: assertEquals( g@9683: "dbname=" + DB g@9683: + " user=" + USER g@9683: + " host='" + HOST + "' port=" + PORT g@9683: + " password='" + PSWD + "'" + PG_CON_SUFFIX, g@9683: con); tom@9671: } tom@9671: tom@9671: @Test tom@9671: public void serviceNameORA() { g@9683: final String con = MapUtils.getConnection( g@9683: USER, PSWD, DRV_ORA + "@//" + HOST + ":" + PORT + "/" + DB); tom@9671: assertEquals( g@9683: USER + "/" + PSWD + "@" + HOST + ":" + PORT + "/" + DB, g@9683: con); tom@9671: } tom@9672: tom@9672: @Test tom@9672: public void connectDescriptorORA() { g@9683: final String con = MapUtils.getConnection( g@9683: USER, PSWD, DRV_ORA g@9683: + "@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" g@9683: + HOST + ")(PORT=" + PORT + "))(CONNECT_DATA=(SERVICE_NAME=" g@9683: + DB + ")))"); tom@9672: assertEquals( g@9683: USER + "/" + PSWD g@9683: + "@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" g@9683: + HOST + ")(PORT=" + PORT + "))(CONNECT_DATA=(SERVICE_NAME=" g@9683: + DB + ")))", g@9683: con); tom@9672: } tom@9671: }