Skip to content

Commit

Permalink
Making sure to return the primary mapped driver if the readonly database
Browse files Browse the repository at this point in the history
is equal to the primary database.
  • Loading branch information
narupley committed May 22, 2019
1 parent 2e2b53e commit 862dd36
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
6 changes: 3 additions & 3 deletions server/src/com/mirth/connect/model/DatabaseSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ String getMappedDatabaseDriver() {

String getMappedReadOnlyDatabaseDriver() {
if (StringUtils.isBlank(databaseReadOnlyDriver)) {
if (StringUtils.isBlank(getDatabaseReadOnly())) {
return getMappedDatabaseDriver();
} else {
if (StringUtils.isNotBlank(getDatabaseReadOnly()) && !StringUtils.equalsIgnoreCase(getDatabase(), getDatabaseReadOnly())) {
return MapUtils.getString(databaseDriverMap, getDatabaseReadOnly());
} else {
return getMappedDatabaseDriver();
}
} else {
return databaseReadOnlyDriver;
Expand Down
23 changes: 17 additions & 6 deletions server/test/com/mirth/connect/model/DatabaseSettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ public void getMappedDatabaseDriver_NullDriver_InvalidDatabase() throws Exceptio
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());
Expand All @@ -53,7 +53,7 @@ public void getMappedReadOnlyDatabaseDriver_NullDriver_NullRODriver_NullDatabase
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());
Expand All @@ -64,7 +64,18 @@ public void getMappedReadOnlyDatabaseDriver_NullDriver_NullRODriver_InvalidDatab
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());
Expand All @@ -75,7 +86,7 @@ public void getMappedReadOnlyDatabaseDriver_NullDriver_NullRODriver_ValidDatabas
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());
Expand Down

0 comments on commit 862dd36

Please sign in to comment.