-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 in MC/connect from bugfix/ROCKSOLID-4035-the-…
…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
Showing
2 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
server/test/com/mirth/connect/model/DatabaseSettingsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |