Skip to content

Commit

Permalink
wip: homogenizing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kubányi <[email protected]>
  • Loading branch information
dkubanyi committed May 31, 2024
1 parent 973f209 commit b19267f
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DatabaseDocumentExportStepTest {
.newInstance().withDatabaseName("gretl")
.withUsername(TestUtil.PG_DDLUSR_USR)
.withPassword(TestUtil.PG_DDLUSR_PWD)
.withInitScript("init_postgresql.sql")
.withInitScript("data/sql/init_postgresql.sql")
.waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2));


Expand Down
32 changes: 16 additions & 16 deletions gretl/src/test/java/ch/so/agi/gretl/steps/Db2DbStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Db2DbStepTest {
(PostgreSQLContainer<?>) new PostgisContainerProvider().newInstance()
.withDatabaseName(TestUtil.PG_DB_NAME)
.withUsername(TestUtil.PG_DDLUSR_USR)
.withInitScript("init_postgresql.sql")
.withInitScript("data/sql/init_postgresql.sql")
.waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2));

private final GretlLogger log;
Expand All @@ -64,8 +64,8 @@ public void faultFreeExecutionTest() throws Exception {
Connector con = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null);
createTestDb(con);
try {
File sqlFile = TestUtil.createFile(folder, "SELECT * FROM colors; ", "query.sql");
File sqlFile2 = TestUtil.createFile(folder, "SELECT * FROM colors; ", "query2.sql");
File sqlFile = TestUtil.createTempFile(folder, "SELECT * FROM colors; ", "query.sql");
File sqlFile2 = TestUtil.createTempFile(folder, "SELECT * FROM colors; ", "query2.sql");

ArrayList<TransferSet> mylist = new ArrayList<TransferSet>();
mylist.add(new TransferSet(sqlFile.getAbsolutePath(), "colors_copy", new Boolean(true)));
Expand Down Expand Up @@ -186,7 +186,7 @@ public void sqlExceptionTest() throws Exception {
Connector con = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null);
createTestDb(con);
try {
File sqlFile = TestUtil.createFile(folder, "SELECT BLABLABLA FROM colors", "query.sql");
File sqlFile = TestUtil.createTempFile(folder, "SELECT BLABLABLA FROM colors", "query.sql");

ArrayList<TransferSet> mylist = new ArrayList<TransferSet>();
mylist.add(new TransferSet(sqlFile.getAbsolutePath(), "colors_copy", new Boolean(false)));
Expand Down Expand Up @@ -223,7 +223,7 @@ public void columnNumberTest() throws Exception {

stmt.execute("CREATE TABLE colors_copy (rot integer, gruen integer)");

File sqlFile = TestUtil.createFile(folder, "SELECT rot, gruen, blau, farbname FROM colors", "query.sql");
File sqlFile = TestUtil.createTempFile(folder, "SELECT rot, gruen, blau, farbname FROM colors", "query.sql");

ArrayList<TransferSet> mylist = new ArrayList<TransferSet>();
mylist.add(new TransferSet(sqlFile.getAbsolutePath(), "colors_copy", new Boolean(false)));
Expand Down Expand Up @@ -262,7 +262,7 @@ public void incompatibleDataTypeTest() throws Exception {

stmt.execute("CREATE TABLE colors_copy (rot integer, gruen integer, blau integer, farbname integer)");

File sqlFile = TestUtil.createFile(folder, "SELECT * FROM colors", "query.sql");
File sqlFile = TestUtil.createTempFile(folder, "SELECT * FROM colors", "query.sql");

ArrayList<TransferSet> mylist = new ArrayList<TransferSet>();
mylist.add(new TransferSet(sqlFile.getAbsolutePath(), "colors_copy", new Boolean(false)));
Expand All @@ -287,7 +287,7 @@ public void copyEmptyTableToOtherTableTest() throws Exception {
Connector con = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null);
createTestDb(con);
try {
File sqlFile = TestUtil.createFile(folder, "SELECT * FROM colors", "query.sql");
File sqlFile = TestUtil.createTempFile(folder, "SELECT * FROM colors", "query.sql");

ArrayList<TransferSet> mylist = new ArrayList<TransferSet>();
mylist.add(new TransferSet(sqlFile.getAbsolutePath(), "colors_copy", new Boolean(false)));
Expand Down Expand Up @@ -322,7 +322,7 @@ public void deleteTest() throws Exception {
con.close();
}

File sqlFile = TestUtil.createFile(folder, "SELECT * FROM colors;", "query.sql");
File sqlFile = TestUtil.createTempFile(folder, "SELECT * FROM colors;", "query.sql");

ArrayList<TransferSet> mylist = new ArrayList<TransferSet>();
mylist.add(new TransferSet(sqlFile.getAbsolutePath(), "colors_copy", new Boolean(true)));
Expand Down Expand Up @@ -354,7 +354,7 @@ public void closeConnectionsTest() throws Exception {
Connector con = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null);
createTestDb(con);
try {
File sqlFile = TestUtil.createFile(folder, "SELECT * FROM colors", "query.sql");
File sqlFile = TestUtil.createTempFile(folder, "SELECT * FROM colors", "query.sql");

ArrayList<TransferSet> mylist = new ArrayList<TransferSet>();
mylist.add(new TransferSet(sqlFile.getAbsolutePath(), "colors_copy", new Boolean(true)));
Expand All @@ -378,7 +378,7 @@ public void closeConnectionsAfterFailedTest() throws Exception {
Connector con = new Connector("jdbc:derby:memory:myInMemDB;create=true", "bjsvwsch", null);
createTestDb(con);
try {
File sqlFile = TestUtil.createFile(folder, "SELECT güggeliblau FROM colors_copy", "query.sql");
File sqlFile = TestUtil.createTempFile(folder, "SELECT güggeliblau FROM colors_copy", "query.sql");

ArrayList<TransferSet> mylist = new ArrayList<TransferSet>();
mylist.add(new TransferSet(sqlFile.getAbsolutePath(), "colors_copy", new Boolean(true)));
Expand Down Expand Up @@ -414,7 +414,7 @@ public void canWriteGeomFromWkbTest() throws Exception {
preparePgGeomSourceSinkTables(schemaName, con);

Db2DbStep step = new Db2DbStep();
File queryFile = TestUtil.createFile(folder,
File queryFile = TestUtil.createTempFile(folder,
String.format("select ST_AsBinary(geom) as geom from %s.source", schemaName), "select.sql");

Connector src = new Connector(postgres.getJdbcUrl(), TestUtil.PG_READERUSR_USR,
Expand Down Expand Up @@ -446,7 +446,7 @@ public void canWriteGeomFromWktTest() throws Exception {
preparePgGeomSourceSinkTables(schemaName, con);

Db2DbStep step = new Db2DbStep();
File queryFile = TestUtil.createFile(folder,
File queryFile = TestUtil.createTempFile(folder,
String.format("select ST_AsText(geom) as geom from %s.source", schemaName), "select.sql");

Connector src = new Connector(postgres.getJdbcUrl(), TestUtil.PG_READERUSR_USR,
Expand Down Expand Up @@ -478,7 +478,7 @@ public void canWriteGeomFromGeoJsonTest() throws Exception {
preparePgGeomSourceSinkTables(schemaName, con);

Db2DbStep step = new Db2DbStep();
File queryFile = TestUtil.createFile(folder,
File queryFile = TestUtil.createTempFile(folder,
String.format("select ST_AsGeoJSON(geom) as geom from %s.source", schemaName), "select.sql");

Connector src = new Connector(postgres.getJdbcUrl(), TestUtil.PG_READERUSR_USR,
Expand Down Expand Up @@ -520,7 +520,7 @@ public void positiveBulkLoadPostgisTest() throws Exception {
prepareSinkTable(schemaName, targetCon);

Db2DbStep step = new Db2DbStep();
File queryFile = TestUtil.createFile(folder, "select myint, myfloat, mytext, mywkt as mygeom from dtypes",
File queryFile = TestUtil.createTempFile(folder, "select myint, myfloat, mytext, mywkt as mygeom from dtypes",
"select.sql");

Connector src = new Connector("jdbc:sqlite:" + sqliteDb.getAbsolutePath());
Expand Down Expand Up @@ -571,7 +571,7 @@ public void positiveSqlite2PostgisTest() throws Exception {
prepareSinkTable(schemaName, targetCon);

Db2DbStep step = new Db2DbStep();
File queryFile = TestUtil.createFile(folder, "select myint, myfloat, mytext, mywkt as mygeom from dtypes",
File queryFile = TestUtil.createTempFile(folder, "select myint, myfloat, mytext, mywkt as mygeom from dtypes",
"select.sql");

Connector src = new Connector("jdbc:sqlite:" + sqliteDb.getAbsolutePath());
Expand Down Expand Up @@ -693,7 +693,7 @@ public void positivePostgis2SqliteTest() throws Exception {
String select = String.format(
"select myint, myfloat, mytext, mydate, mytime, myuuid, ST_AsText(mygeom) as mygeom_wkt from %s.dtypes",
schemaName);
File queryFile = TestUtil.createFile(folder, select, "select.sql");
File queryFile = TestUtil.createTempFile(folder, select, "select.sql");

Connector src = new Connector(postgres.getJdbcUrl(), TestUtil.PG_READERUSR_USR,
TestUtil.PG_READERUSR_PWD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand All @@ -33,7 +28,7 @@ public class JsonImportStepTest {
.newInstance().withDatabaseName("gretl")
.withUsername(TestUtil.PG_DDLUSR_USR)
.withPassword(TestUtil.PG_DDLUSR_PWD)
.withInitScript("init_postgresql.sql")
.withInitScript("data/sql/init_postgresql.sql")
.waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2));

public JsonImportStepTest() {
Expand All @@ -48,7 +43,7 @@ public JsonImportStepTest() {
@Test
public void importJsonObject_Ok() throws Exception {
Connector connector = new Connector(postgres.getJdbcUrl(), TestUtil.PG_DDLUSR_USR, TestUtil.PG_DDLUSR_PWD);
File jsonFile = TestUtil.createFile(folder, "{\"foo\":\"bar\"}", "test1.json");
File jsonFile = TestUtil.createTempFile(folder, "{\"foo\":\"bar\"}", "test1.json");

String schemaName = "jsonimport";
String tableName = "jsonobject";
Expand Down Expand Up @@ -82,7 +77,7 @@ public void importJsonObject_Ok() throws Exception {
@Test
public void appendJsonObject_Ok() throws Exception {
Connector connector = new Connector(postgres.getJdbcUrl(), TestUtil.PG_DDLUSR_USR, TestUtil.PG_DDLUSR_PWD);
File jsonFile = TestUtil.createFile(folder, "{\"foo\":\"bar\"}", "test2.json");
File jsonFile = TestUtil.createTempFile(folder, "{\"foo\":\"bar\"}", "test2.json");

String schemaName = "jsonimport";
String tableName = "jsonobject";
Expand Down Expand Up @@ -114,7 +109,7 @@ public void appendJsonObject_Ok() throws Exception {
@Test
public void importJsonArray_Ok() throws Exception {
Connector connector = new Connector(postgres.getJdbcUrl(), TestUtil.PG_DDLUSR_USR, TestUtil.PG_DDLUSR_PWD);
File jsonFile = TestUtil.createFile(folder, "[{\"type\":\"building\"}, {\"type\":\"street\"}]", "test3.json");
File jsonFile = TestUtil.createTempFile(folder, "[{\"type\":\"building\"}, {\"type\":\"street\"}]", "test3.json");

String schemaName = "jsonimport";
String tableName = "jsonarray";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import org.junit.ClassRule;
import org.junit.Rule;
Expand All @@ -22,7 +18,6 @@
import ch.so.agi.gretl.logging.GretlLogger;
import ch.so.agi.gretl.logging.LogEnvironment;
import ch.so.agi.gretl.testutil.TestUtil;
import net.sf.saxon.s9api.SaxonApiException;

public class PostgisRasterExportStepTest {
private GretlLogger log;
Expand All @@ -32,7 +27,7 @@ public class PostgisRasterExportStepTest {
(PostgreSQLContainer) new PostgisContainerProvider()
.newInstance().withDatabaseName("gretl")
.withUsername(TestUtil.PG_DDLUSR_USR)
.withInitScript("init_postgresql.sql")
.withInitScript("data/sql/init_postgresql.sql")
.waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2));

public PostgisRasterExportStepTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class PublisherStepDb2LocalTest {
.newInstance().withDatabaseName("gretl")
.withUsername(TestUtil.PG_DDLUSR_USR)
.withPassword(TestUtil.PG_DDLUSR_PWD)
.withInitScript("init_postgresql.sql")
.withInitScript("data/sql/init_postgresql.sql")
.waitingFor(Wait.forLogMessage(TestUtil.WAIT_PATTERN, 2)):null;

final protected Path localTestOut = Paths.get("build").resolve("out");
Expand Down
Loading

0 comments on commit b19267f

Please sign in to comment.