Skip to content

Commit

Permalink
Fixing issue where the database-readonly.driver property wasn't
Browse files Browse the repository at this point in the history
correctly inheriting from the database.driver property when empty.
  • Loading branch information
narupley committed May 22, 2019
1 parent f315f12 commit 2e2b53e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 5 deletions.
14 changes: 9 additions & 5 deletions server/src/com/mirth/connect/model/DatabaseSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,21 @@ public void setDirBase(String dirBase) {
this.dirBase = dirBase;
}

private String getMappedDatabaseDriver() {
if (StringUtils.isEmpty(databaseDriver)) {
String getMappedDatabaseDriver() {
if (StringUtils.isBlank(databaseDriver)) {
return MapUtils.getString(databaseDriverMap, getDatabase());
} else {
return databaseDriver;
}
}

private String getMappedReadOnlyDatabaseDriver() {
if (StringUtils.isEmpty(databaseReadOnlyDriver)) {
return MapUtils.getString(databaseDriverMap, StringUtils.defaultIfBlank(getDatabaseReadOnly(), getDatabase()));
String getMappedReadOnlyDatabaseDriver() {
if (StringUtils.isBlank(databaseReadOnlyDriver)) {
if (StringUtils.isBlank(getDatabaseReadOnly())) {
return getMappedDatabaseDriver();
} else {
return MapUtils.getString(databaseDriverMap, getDatabaseReadOnly());
}
} else {
return databaseReadOnlyDriver;
}
Expand Down
89 changes: 89 additions & 0 deletions server/test/com/mirth/connect/model/DatabaseSettingsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) Mirth Corporation. All rights reserved.
*
* http://www.mirthcorp.com
*
* The software in this package is published under the terms of the MPL license a copy of which has
* been included with this distribution in the LICENSE.txt file.
*/

package com.mirth.connect.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import org.junit.Test;

public class DatabaseSettingsTest {

@Test
public void getMappedDatabaseDriver_NullDriver_InvalidDatabase() throws Exception {
DatabaseSettings databaseSettings = new DatabaseSettings();
databaseSettings.setDatabase("dummy");
databaseSettings.setDatabaseDriver(null);
assertNull(databaseSettings.getMappedDatabaseDriver());
}

@Test
public void getMappedDatabaseDriver_BlankDriver_ValidDatabase() throws Exception {
DatabaseSettings databaseSettings = new DatabaseSettings();
databaseSettings.setDatabase("postgres");
databaseSettings.setDatabaseDriver(" ");
assertEquals("org.postgresql.Driver", databaseSettings.getMappedDatabaseDriver());
}

@Test
public void getMappedDatabaseDriver_NonBlankDriver() throws Exception {
DatabaseSettings databaseSettings = new DatabaseSettings();
databaseSettings.setDatabase("mysql");
databaseSettings.setDatabaseDriver("test");
assertEquals("test", databaseSettings.getMappedDatabaseDriver());
}

@Test
public void getMappedReadOnlyDatabaseDriver_NullDriver_NullRODriver_NullDatabaseRO() throws Exception {
DatabaseSettings databaseSettings = spy(new DatabaseSettings());
databaseSettings.setDatabase("oracle");
databaseSettings.setDatabaseDriver(null);
databaseSettings.setDatabaseReadOnly(null);
databaseSettings.setDatabaseReadOnlyDriver(null);
assertEquals("oracle.jdbc.OracleDriver", databaseSettings.getMappedReadOnlyDatabaseDriver());
verify(databaseSettings, times(1)).getMappedDatabaseDriver();
}

@Test
public void getMappedReadOnlyDatabaseDriver_NullDriver_NullRODriver_InvalidDatabaseRO() throws Exception {
DatabaseSettings databaseSettings = spy(new DatabaseSettings());
databaseSettings.setDatabase("oracle");
databaseSettings.setDatabaseDriver(null);
databaseSettings.setDatabaseReadOnly("dummy");
databaseSettings.setDatabaseReadOnlyDriver(null);
assertNull(databaseSettings.getMappedReadOnlyDatabaseDriver());
verify(databaseSettings, times(0)).getMappedDatabaseDriver();
}

@Test
public void getMappedReadOnlyDatabaseDriver_NullDriver_NullRODriver_ValidDatabaseRO() throws Exception {
DatabaseSettings databaseSettings = spy(new DatabaseSettings());
databaseSettings.setDatabase("oracle");
databaseSettings.setDatabaseDriver(null);
databaseSettings.setDatabaseReadOnly("sqlserver");
databaseSettings.setDatabaseReadOnlyDriver(null);
assertEquals("net.sourceforge.jtds.jdbc.Driver", databaseSettings.getMappedReadOnlyDatabaseDriver());
verify(databaseSettings, times(0)).getMappedDatabaseDriver();
}

@Test
public void getMappedReadOnlyDatabaseDriver_NonBlankRODriver() throws Exception {
DatabaseSettings databaseSettings = spy(new DatabaseSettings());
databaseSettings.setDatabase("oracle");
databaseSettings.setDatabaseDriver(null);
databaseSettings.setDatabaseReadOnly(null);
databaseSettings.setDatabaseReadOnlyDriver("test");
assertEquals("test", databaseSettings.getMappedReadOnlyDatabaseDriver());
verify(databaseSettings, times(0)).getMappedDatabaseDriver();
}
}

0 comments on commit 2e2b53e

Please sign in to comment.