Skip to content

Commit

Permalink
Merge pull request #277 in MC/connect from bugfix/ROCKSOLID-4035-the-…
Browse files Browse the repository at this point in the history
…database-readonly.driver-property to development

* commit '862dd3643594595c4f1931619e3ae23048803a5c':
  Making sure to return the primary mapped driver if the readonly database is equal to the primary database.
  Fixing issue where the database-readonly.driver property wasn't correctly inheriting from the database.driver property when empty.
  • Loading branch information
Peter Ladesma authored and Peter Ladesma committed May 22, 2019
2 parents 9890df7 + 862dd36 commit a723295
Show file tree
Hide file tree
Showing 2 changed files with 109 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.isNotBlank(getDatabaseReadOnly()) && !StringUtils.equalsIgnoreCase(getDatabase(), getDatabaseReadOnly())) {
return MapUtils.getString(databaseDriverMap, getDatabaseReadOnly());
} else {
return getMappedDatabaseDriver();
}
} else {
return databaseReadOnlyDriver;
}
Expand Down
100 changes: 100 additions & 0 deletions server/test/com/mirth/connect/model/DatabaseSettingsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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_DifferentDatabaseRO() throws Exception {
DatabaseSettings databaseSettings = spy(new DatabaseSettings());
databaseSettings.setDatabase("oracle");
databaseSettings.setDatabaseDriver(null);
databaseSettings.setDatabaseReadOnly("mysql");
databaseSettings.setDatabaseReadOnlyDriver(null);
assertEquals("com.mysql.cj.jdbc.Driver", 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 a723295

Please sign in to comment.