Skip to content

Commit

Permalink
Merged master into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
nvoxland committed Jul 13, 2022
1 parent 556f0b1 commit ad612b8
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 75 deletions.
Expand Up @@ -5,15 +5,15 @@

public class AbstractDb2DatabaseTest extends TestCase {

public void testGetDateLiteral() throws DatabaseException {
try (AbstractDb2Database database = new DB2Database()) {
assertEquals("DATE('2018-12-31')", database.getDateLiteral("2018-12-31"));
assertEquals("TIME('23:58:59')", database.getDateLiteral("23:58:59"));
assertEquals("TIMESTAMP('2018-12-31 23:58:59')", database.getDateLiteral("2018-12-31 23:58:59"));
assertEquals("UNSUPPORTED:foo", database.getDateLiteral("foo"));
} catch (final DatabaseException e) {
throw e;
public void testGetDateLiteral() throws DatabaseException {
try (AbstractDb2Database database = new DB2Database()) {
assertEquals("DATE('2018-12-31')", database.getDateLiteral("2018-12-31"));
assertEquals("TIME('23:58:59')", database.getDateLiteral("23:58:59"));
assertEquals("TIMESTAMP('2018-12-31 23:58:59')", database.getDateLiteral("2018-12-31 23:58:59"));
assertEquals("UNSUPPORTED:foo", database.getDateLiteral("foo"));
} catch (final DatabaseException e) {
throw e;
}
}
}

}
Expand Up @@ -6,14 +6,14 @@

public class DB2DatabaseTest extends TestCase {

public void testGetDefaultDriver() throws DatabaseException {
try (Database database = new DB2Database()) {
assertEquals("com.ibm.db2.jcc.DB2Driver", database.getDefaultDriver("jdbc:db2://localhost:50000/liquibas"));
public void testGetDefaultDriver() throws DatabaseException {
try (Database database = new DB2Database()) {
assertEquals("com.ibm.db2.jcc.DB2Driver", database.getDefaultDriver("jdbc:db2://localhost:50000/liquibas"));

assertNull(database.getDefaultDriver("jdbc:oracle://localhost;databaseName=liquibase"));
} catch (final DatabaseException e) {
throw e;
assertNull(database.getDefaultDriver("jdbc:oracle://localhost;databaseName=liquibase"));
} catch (final DatabaseException e) {
throw e;
}
}
}

}
Expand Up @@ -6,14 +6,14 @@

public class DB2zDatabaseTest extends TestCase {

public void testGetDefaultDriver() throws DatabaseException {
try (Database database = new Db2zDatabase()) {
assertEquals("com.ibm.db2.jcc.DB2Driver", database.getDefaultDriver("jdbc:db2://localhost:50000/liquibas"));
public void testGetDefaultDriver() throws DatabaseException {
try (Database database = new Db2zDatabase()) {
assertEquals("com.ibm.db2.jcc.DB2Driver", database.getDefaultDriver("jdbc:db2://localhost:50000/liquibas"));

assertNull(database.getDefaultDriver("jdbc:oracle://localhost;databaseName=liquibase"));
} catch (final DatabaseException e) {
throw e;
assertNull(database.getDefaultDriver("jdbc:oracle://localhost;databaseName=liquibase"));
} catch (final DatabaseException e) {
throw e;
}
}
}

}
Expand Up @@ -8,68 +8,70 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

import junit.framework.TestCase;
import liquibase.database.Database;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.DatabaseException;

public class DerbyDatabaseTest extends TestCase {

public void testGetDefaultDriver() throws DatabaseException {
try (Database database = new DerbyDatabase()) {
assertEquals("org.apache.derby.jdbc.EmbeddedDriver", database.getDefaultDriver("java:derby:liquibase;create=true"));
public void testGetDefaultDriver() throws DatabaseException {
try (Database database = new DerbyDatabase()) {
assertEquals("org.apache.derby.jdbc.EmbeddedDriver", database.getDefaultDriver("java:derby:liquibase;create=true"));

assertNull(database.getDefaultDriver("jdbc:oracle://localhost;databaseName=liquibase"));
} catch (final DatabaseException e) {
throw e;
}
}

public void testGetDateLiteral() {
assertEquals("TIMESTAMP('2008-01-25 13:57:41')", new DerbyDatabase().getDateLiteral("2008-01-25 13:57:41"));
assertEquals("TIMESTAMP('2008-01-25 13:57:41.300000')", new DerbyDatabase().getDateLiteral("2008-01-25 13:57:41.3"));
assertEquals("TIMESTAMP('2008-01-25 13:57:41.340000')", new DerbyDatabase().getDateLiteral("2008-01-25 13:57:41.34"));
assertEquals("TIMESTAMP('2008-01-25 13:57:41.347000')", new DerbyDatabase().getDateLiteral("2008-01-25 13:57:41.347"));
}

public void testCloseShutsEmbeddedDerbyDown() throws Exception {
Connection con = mockConnection();
DerbyDatabase database = spyDatabase(con);

database.close();

verify(database).shutdownDerby(anyString(), anyString());
verify(con).close();
}

public void testCloseDoesNotShutEmbeddedDerbyDown() throws Exception {
Connection con = mockConnection();
DerbyDatabase database = spyDatabase(con);
database.setShutdownEmbeddedDerby(false);

database.close();

verify(database, never()).shutdownDerby(anyString(), anyString());
verify(con).close();
}

private static DerbyDatabase spyDatabase(Connection con) throws DatabaseException {
DerbyDatabase database = spy(new DerbyDatabase());
doNothing().when(database).shutdownDerby(anyString(), anyString());
database.setConnection(new JdbcConnection(con));
return database;
}

assertNull(database.getDefaultDriver("jdbc:oracle://localhost;databaseName=liquibase"));
} catch (final DatabaseException e) {
throw e;
private static Connection mockConnection() throws SQLException {
Connection con = mock(Connection.class);
DatabaseMetaData metaData = mock(DatabaseMetaData.class, RETURNS_SMART_NULLS);
when(metaData.getURL()).thenReturn("jdbc:derby:memory:foo");
when(metaData.getDriverName()).thenReturn("org.apache.derby.jdbc.EmbeddedDriver");
when(con.getMetaData()).thenReturn(metaData);
return con;
}
}

public void testGetDateLiteral() {
assertEquals("TIMESTAMP('2008-01-25 13:57:41')", new DerbyDatabase().getDateLiteral("2008-01-25 13:57:41"));
assertEquals("TIMESTAMP('2008-01-25 13:57:41.300000')", new DerbyDatabase().getDateLiteral("2008-01-25 13:57:41.3"));
assertEquals("TIMESTAMP('2008-01-25 13:57:41.340000')", new DerbyDatabase().getDateLiteral("2008-01-25 13:57:41.34"));
assertEquals("TIMESTAMP('2008-01-25 13:57:41.347000')", new DerbyDatabase().getDateLiteral("2008-01-25 13:57:41.347"));
}

public void testCloseShutsEmbeddedDerbyDown() throws Exception {
Connection con = mockConnection();
DerbyDatabase database = spyDatabase(con);

database.close();

verify(database).shutdownDerby(anyString(), anyString());
verify(con).close();
}

public void testCloseDoesNotShutEmbeddedDerbyDown() throws Exception {
Connection con = mockConnection();
DerbyDatabase database = spyDatabase(con);
database.setShutdownEmbeddedDerby(false);

database.close();

verify(database, never()).shutdownDerby(anyString(), anyString());
verify(con).close();
}

private static DerbyDatabase spyDatabase(Connection con) throws DatabaseException {
DerbyDatabase database = spy(new DerbyDatabase());
doNothing().when(database).shutdownDerby(anyString(), anyString());
database.setConnection(new JdbcConnection(con));
return database;
}

private static Connection mockConnection() throws SQLException {
Connection con = mock(Connection.class);
DatabaseMetaData metaData = mock(DatabaseMetaData.class, RETURNS_SMART_NULLS);
when(metaData.getURL()).thenReturn("jdbc:derby:memory:foo");
when(metaData.getDriverName()).thenReturn("org.apache.derby.jdbc.EmbeddedDriver");
when(con.getMetaData()).thenReturn(metaData);
return con;
}

}
Expand Up @@ -4,6 +4,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import liquibase.database.AbstractJdbcDatabaseTest;
import liquibase.database.Database;
Expand Down Expand Up @@ -40,7 +41,7 @@ public void getCurrentDateTimeFunction() {
public void getDefaultDriver() throws DatabaseException {
try (Database database = new MSSQLDatabase()) {
assertEquals("com.microsoft.sqlserver.jdbc.SQLServerDriver", database.getDefaultDriver("jdbc:sqlserver://localhost;databaseName=liquibase"));

assertNull(database.getDefaultDriver("jdbc:oracle:thin://localhost;databaseName=liquibase"));
} catch (final DatabaseException e) {
throw e;
Expand Down
Expand Up @@ -3,6 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;

import org.junit.Assert;
import org.junit.Test;
import liquibase.database.AbstractJdbcDatabaseTest;
Expand Down
Expand Up @@ -5,8 +5,10 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.ResourceBundle;

import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;
Expand Down
Expand Up @@ -3,6 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import org.junit.Assert;
import org.junit.Test;
import liquibase.GlobalConfiguration;
Expand Down

0 comments on commit ad612b8

Please sign in to comment.