-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand test coverage and fix some small issues with the HSQLDB support
- Loading branch information
Showing
10 changed files
with
214 additions
and
26 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
25 changes: 25 additions & 0 deletions
25
...e/src/test/java/org/zapodot/junit/db/plugin/LiquibaseInitializerIllegalMigrationTest.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,25 @@ | ||
package org.zapodot.junit.db.plugin; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.zapodot.junit.db.EmbeddedDatabaseRule; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
public class LiquibaseInitializerIllegalMigrationTest { | ||
|
||
@Rule | ||
public final EmbeddedDatabaseRule databaseRule = EmbeddedDatabaseRule.hsqldb().build(); | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void connectionMade() throws SQLException { | ||
final LiquibaseInitializer liquibaseInitializer = LiquibaseInitializer.builder() | ||
.withChangelogResource( | ||
"example-illegal.xml") | ||
.build(); | ||
try (final Connection connection = databaseRule.getConnection()) { | ||
liquibaseInitializer.connectionMade("name", connection); | ||
} | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
...rg/zapodot/junit/db/plugin/LiquibaseInitializerWithDbNameAddedToContextsHyperSQLTest.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,44 @@ | ||
package org.zapodot.junit.db.plugin; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.zapodot.junit.db.EmbeddedDatabaseRule; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* @author zapodot | ||
*/ | ||
public class LiquibaseInitializerWithDbNameAddedToContextsHyperSQLTest { | ||
|
||
private static final String DATABASE_NAME = "myDb"; | ||
|
||
@Rule | ||
public final EmbeddedDatabaseRule embeddedDatabaseRule = EmbeddedDatabaseRule | ||
.hsqldb() | ||
.withMode(EmbeddedDatabaseRule.CompatibilityMode.MSSQLServer) | ||
.withName(DATABASE_NAME) | ||
.initializedByPlugin(LiquibaseInitializer.builder() | ||
.withChangelogResource("example-changelog.xml") | ||
.addDatabaseNameToContext() | ||
.build()) | ||
.build(); | ||
|
||
@Test | ||
public void testFindRolesInsertedByLiquibase() throws Exception { | ||
try (final Connection connection = embeddedDatabaseRule.getConnection(); | ||
final PreparedStatement preparedStatement = connection.prepareStatement( | ||
"SELECT r.name from role r inner join userrole ur on r.id = ur.role_id inner join user u on u.id=ur.user_id where u.username = ?")) { | ||
preparedStatement.setString(1, "Ada"); | ||
try (final ResultSet resultSet = preparedStatement.executeQuery()) { | ||
assertFalse(resultSet.next()); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
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
8 changes: 8 additions & 0 deletions
8
embedded-db-junit-liquibase/src/test/resources/example-illegal.xml
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<databaseChangeLog | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd"> | ||
<blah></blah> | ||
</databaseChangeLog> |
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
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
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
85 changes: 85 additions & 0 deletions
85
...b-junit/src/test/java/org/zapodot/junit/db/internal/FilePathInitializationPluginTest.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,85 @@ | ||
package org.zapodot.junit.db.internal; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnit; | ||
import org.mockito.junit.MockitoRule; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class FilePathInitializationPluginTest { | ||
|
||
@Rule | ||
public final MockitoRule mockitoRule = MockitoJUnit.rule(); | ||
|
||
@Mock | ||
private Connection connection; | ||
|
||
@Mock | ||
private Statement statement; | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void resourceMissing() { | ||
new FilePathInitializationPlugin(null, null); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void charsetMissing() { | ||
new FilePathInitializationPlugin("resource", null); | ||
} | ||
|
||
@Test | ||
public void connectionMadeDone() throws SQLException { | ||
final FilePathInitializationPlugin filePathInitializationPlugin = new FilePathInitializationPlugin( | ||
"classpath:initial.sql", | ||
StandardCharsets.UTF_8); | ||
assertNotNull(filePathInitializationPlugin); | ||
|
||
when(connection.createStatement()).thenReturn(statement); | ||
filePathInitializationPlugin.connectionMade("name", connection); | ||
verify(connection).createStatement(); | ||
verify(statement).execute(anyString()); | ||
verify(statement).close(); | ||
verifyNoMoreInteractions(connection, statement); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void connectionSQLExecutionFails() throws SQLException { | ||
final FilePathInitializationPlugin filePathInitializationPlugin = new FilePathInitializationPlugin( | ||
"classpath:initial.sql", | ||
StandardCharsets.UTF_8); | ||
assertNotNull(filePathInitializationPlugin); | ||
|
||
when(connection.createStatement()).thenReturn(statement); | ||
when(statement.execute(anyString())).thenThrow(new SQLException("Error")); | ||
try { | ||
filePathInitializationPlugin.connectionMade("name", connection); | ||
} finally { | ||
verify(connection).createStatement(); | ||
verify(statement).execute(anyString()); | ||
verify(statement).close(); | ||
verifyNoMoreInteractions(connection, statement); | ||
} | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void connectionMadeIllegalPath() { | ||
final FilePathInitializationPlugin filePathInitializationPlugin = new FilePathInitializationPlugin( | ||
"classpath:nonexisting.sql", | ||
StandardCharsets.UTF_8); | ||
assertNotNull(filePathInitializationPlugin); | ||
try { | ||
filePathInitializationPlugin.connectionMade("name", connection); | ||
} finally { | ||
verifyNoMoreInteractions(connection, statement); | ||
} | ||
} | ||
} |