-
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.
- Loading branch information
Showing
16 changed files
with
495 additions
and
111 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...c/test/java/org/zapodot/junit/db/plugin/FlywayInitializerDefaultSettingsHypersqlTest.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,32 @@ | ||
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.ResultSet; | ||
import java.sql.Statement; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class FlywayInitializerDefaultSettingsHypersqlTest { | ||
|
||
@Rule | ||
public final EmbeddedDatabaseRule embeddedDatabaseRule = EmbeddedDatabaseRule.hsqldb() | ||
.initializedByPlugin( | ||
new FlywayInitializer.Builder() | ||
.withLocations( | ||
"classpath:migrations/") | ||
.build()).build(); | ||
|
||
|
||
@Test | ||
public void checkMigrationsHasRun() throws Exception { | ||
try (final Connection connection = embeddedDatabaseRule.getConnection(); | ||
final Statement statement = connection.createStatement(); | ||
final ResultSet resultSet = statement.executeQuery("SELECT * FROM USER")) { | ||
assertTrue(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
2 changes: 1 addition & 1 deletion
2
embedded-db-flyway/src/test/resources/migrations/V1_0_0__Create_tables_for_user_and_role.sql
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
39 changes: 39 additions & 0 deletions
39
...test/java/org/zapodot/junit/db/plugin/LiquibaseInitializerWithSchemaNameHyperSQLTest.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,39 @@ | ||
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 LiquibaseInitializerWithSchemaNameHyperSQLTest { | ||
|
||
@Rule | ||
public final EmbeddedDatabaseRule embeddedDatabaseRule = EmbeddedDatabaseRule | ||
.hsqldb() | ||
.withMode(EmbeddedDatabaseRule.CompatibilityMode.MSSQLServer) | ||
.initializedByPlugin(LiquibaseInitializer.builder() | ||
.withChangelogResource("example-changelog.xml") | ||
.withDefaultSchemaName("some_schema_name") | ||
.build()) | ||
.build(); | ||
|
||
@Test | ||
public void testFindUserTable() throws Exception { | ||
try (final Connection connection = embeddedDatabaseRule.getConnection(); | ||
final PreparedStatement preparedStatement = connection | ||
.prepareStatement("SELECT * FROM some_schema_name.USER"); | ||
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
30 changes: 30 additions & 0 deletions
30
embedded-db-junit-liquibase/src/test/java/org/zapodot/junit/db/plugin/dao/RoleDao.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,30 @@ | ||
package org.zapodot.junit.db.plugin.dao; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public class RoleDao { | ||
|
||
private final Connection connection; | ||
|
||
public RoleDao(final Connection connection) { | ||
this.connection = connection; | ||
} | ||
|
||
public List<String> rolesForUser(final String userName) throws SQLException { | ||
try(final PreparedStatement statement = connection.prepareStatement("Select * FROM ROLE r INNER JOIN USERROLE ur on r.ID = ur.ROLE_ID INNER JOIN USER u on ur.USER_ID = u.ID where u.NAME = ?")) { | ||
statement.setString(1, userName); | ||
try(final ResultSet resultSet = statement.executeQuery()) { | ||
final List<String> roles = new LinkedList<>(); | ||
while(resultSet.next()) { | ||
roles.add(resultSet.getString("name")); | ||
} | ||
return roles; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.