Skip to content

Commit

Permalink
feat: improve code quality
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kubányi <[email protected]>
  • Loading branch information
dkubanyi committed Jun 5, 2024
1 parent b19267f commit 2b3df1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
23 changes: 11 additions & 12 deletions gretl/src/test/java/ch/so/agi/gretl/steps/SqlExecutorStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
*/
public class SqlExecutorStepTest {

private static final String INIT_DB_SQL_PATH = "data/sql/init_postgresql.sql";
private static final String POSTGIS_VERSION_SQL_PATH = "data/sql/postgisversion.sql";
private static final String CREATE_TEST_DB_SQL_PATH = "data/sql/create_test_db.sql";

Expand All @@ -39,33 +38,33 @@ public class SqlExecutorStepTest {
(PostgreSQLContainer<?>) new PostgisContainerProvider().newInstance()
.withDatabaseName(TestUtil.PG_DB_NAME)
.withUsername(TestUtil.PG_DDLUSR_USR)
.withInitScript(INIT_DB_SQL_PATH)
.withInitScript(TestUtil.PG_INIT_SCRIPT_PATH)
.waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2));

@Rule
public TemporaryFolder folder = new TemporaryFolder();
private Connector connector;
private Connector duckDbConnector;
private final Connector connector;
private final Connector duckDbConnector;

public SqlExecutorStepTest() {
LogEnvironment.initStandalone();
connector = new Connector("jdbc:derby:memory:myInMemDB;create=true", "barpastu", null);
duckDbConnector = new Connector("jdbc:duckdb::memory:", null, null);
}

@Before
public void initialize() throws Exception {
connector = new Connector("jdbc:derby:memory:myInMemDB;create=true", "barpastu", null);
duckDbConnector = new Connector("jdbc:duckdb::memory:", null, null);
createTestDb(connector);
createTestDb();
}

@After
public void finalise() throws Exception {
clearTestDb(connector);
if (connector != null && !connector.isClosed()) {
clearTestDb();
if (!connector.isClosed()) {
connector.close();
}

if (duckDbConnector != null && !duckDbConnector.isClosed()) {
if (!duckDbConnector.isClosed()) {
duckDbConnector.close();
}
}
Expand Down Expand Up @@ -221,14 +220,14 @@ public void checkIfConnectionIsClosed() throws Exception {
assertTrue(connector.isClosed());
}

private void clearTestDb(Connector connector) throws Exception {
private void clearTestDb() throws Exception {
try (Connection connection = connector.connect(); Statement statement = connection.createStatement()) {
connection.setAutoCommit(true);
statement.execute("DROP TABLE colors");
}
}

private void createTestDb(Connector connector) throws Exception {
private void createTestDb() throws Exception {
try (Connection connection = connector.connect()) {
connection.setAutoCommit(true);

Expand Down
1 change: 1 addition & 0 deletions gretl/src/test/java/ch/so/agi/gretl/testutil/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class TestUtil {
public static final String PG_DMLUSR_PWD = "dmluser";
public static final String PG_READERUSR_USR = "readeruser";
public static final String PG_READERUSR_PWD = "readeruser";
public static final String PG_INIT_SCRIPT_PATH = "data/sql/init_postgresql.sql";
public static final String WAIT_PATTERN = ".*database system is ready to accept connections.*\\s";

public static File createTempFile(TemporaryFolder folder, String stm, String fileName) throws IOException {
Expand Down

0 comments on commit 2b3df1c

Please sign in to comment.