Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public static boolean compareResultSetData(ResultSet rsSource, ResultSet rsTarge
return true;
}


public static void createSourceTable(String sourceTable) throws SQLException, ClassNotFoundException {
try (Connection connect = getMysqlConnection();
Statement statement = connect.createStatement()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.cdap.plugin.MysqlClient;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import org.apache.commons.lang3.RandomStringUtils;

import java.sql.SQLException;

Expand All @@ -28,8 +29,17 @@
*/
public class TestSetupHooks {

private static void setTableName() {
String randomString = RandomStringUtils.randomAlphabetic(10);
String sourceTableName = String.format("SourceTable_%s", randomString);
String targetTableName = String.format("TargetTable_%s", randomString);
PluginPropertyUtils.addPluginProp("sourceTable", sourceTableName);
PluginPropertyUtils.addPluginProp("targetTable", targetTableName);
PluginPropertyUtils.addPluginProp("selectQuery", String.format("select * from %s", sourceTableName));
}

@Before(order = 1)
public static void overrideUserAndPasswordIfProvided() {
public static void initializeDBProperties() {
String username = System.getenv("username");
if (username != null && !username.isEmpty()) {
PluginPropertyUtils.addPluginProp("username", username);
Expand All @@ -38,14 +48,7 @@ public static void overrideUserAndPasswordIfProvided() {
if (password != null && !password.isEmpty()) {
PluginPropertyUtils.addPluginProp("password", password);
}
}

@Before(order = 1, value = "@MYSQL_SOURCE_TEST")
public static void setSelectQuery() {
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
PluginPropertyUtils.addPluginProp("selectQuery",
PluginPropertyUtils.pluginProp("selectQuery").
replace("${table}", sourceTable));
TestSetupHooks.setTableName();
}

@Before(order = 2, value = "@MYSQL_SOURCE_TEST")
Expand All @@ -54,14 +57,6 @@ public static void createTables() throws SQLException, ClassNotFoundException {
MysqlClient.createTargetTable(PluginPropertyUtils.pluginProp("targetTable"));
}

@Before(order = 1, value = "@MYSQL_SOURCE_DATATYPES_TEST")
public static void setSelectQueryForDatatypes() {
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
PluginPropertyUtils.addPluginProp("selectQuery",
PluginPropertyUtils.pluginProp("selectQuery").
replace("${table}", sourceTable));
}

@Before(order = 2, value = "@MYSQL_SOURCE_DATATYPES_TEST")
public static void createDatatypesTable() throws SQLException, ClassNotFoundException {
MysqlClient.createSourceDatatypesTable(PluginPropertyUtils.pluginProp("sourceTable"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ username=MYSQL_USERNAME
password=MYSQL_PASSWORD
databaseName=sakila
port=MYSQL_PORT
selectQuery=select * from ${table}
sourceRef=source
targetRef=target
sourceTable=sourceTable
targetTable=targetTable
outputSchema=[{"key":"id","value":"int"},{"key":"lastName","value":"string"}]

datatypesColumns=(ID varchar(100) PRIMARY KEY, COL1 bigint(20), COL2 bigint(20) unsigned, COL3 binary(1), \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.cdap.plugin.OracleClient;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import org.apache.commons.lang3.RandomStringUtils;

import java.sql.SQLException;

Expand All @@ -28,13 +29,16 @@
*/
public class TestSetupHooks {

@Before(order = 1, value = "@ORACLE_SOURCE_TEST")
public static void setSelectQuery() {
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
@Before(order = 1)
public static void setTableName() {
String randomString = RandomStringUtils.randomAlphabetic(10).toUpperCase();
String sourceTableName = String.format("SOURCETABLE_%s", randomString);
String targetTableName = String.format("TARGETTABLE_%s", randomString);
PluginPropertyUtils.addPluginProp("sourceTable", sourceTableName);
PluginPropertyUtils.addPluginProp("targetTable", targetTableName);
String schema = PluginPropertyUtils.pluginProp("schema");
PluginPropertyUtils.addPluginProp("selectQuery",
PluginPropertyUtils.pluginProp("selectQuery").
replace("${table}", sourceTable).replace("${schema}", schema));
PluginPropertyUtils.addPluginProp("selectQuery", String.format("select * from %s.%s", schema,
sourceTableName));
}

@Before(order = 2, value = "@ORACLE_SOURCE_TEST")
Expand All @@ -45,15 +49,6 @@ public static void createTables() throws SQLException, ClassNotFoundException {
PluginPropertyUtils.pluginProp("schema"));
}

@Before(order = 1, value = "@ORACLE_SOURCE_DATATYPES_TEST")
public static void setSelectQueryForAllDatatypes() {
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
String schema = PluginPropertyUtils.pluginProp("schema");
PluginPropertyUtils.addPluginProp("selectQuery",
PluginPropertyUtils.pluginProp("selectQuery").
replace("${table}", sourceTable).replace("${schema}", schema));
}

@Before(order = 2, value = "@ORACLE_SOURCE_DATATYPES_TEST")
public static void createAllDatatypesTables() throws SQLException, ClassNotFoundException {
OracleClient.createSourceDatatypesTable(PluginPropertyUtils.pluginProp("sourceTable"),
Expand All @@ -62,15 +57,6 @@ public static void createAllDatatypesTables() throws SQLException, ClassNotFound
PluginPropertyUtils.pluginProp("schema"));
}

@Before(order = 1, value = "@ORACLE_SOURCE_DATATYPES_TEST2")
public static void setSelectQueryForLongDatatype() {
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
String schema = PluginPropertyUtils.pluginProp("schema");
PluginPropertyUtils.addPluginProp("selectQuery",
PluginPropertyUtils.pluginProp("selectQuery").
replace("${table}", sourceTable).replace("${schema}", schema));
}

@Before(order = 2, value = "@ORACLE_SOURCE_DATATYPES_TEST2")
public static void createDatatypesTablesLong() throws SQLException, ClassNotFoundException {
OracleClient.createSourceLongTable(PluginPropertyUtils.pluginProp("sourceTable"),
Expand All @@ -79,15 +65,6 @@ public static void createDatatypesTablesLong() throws SQLException, ClassNotFoun
PluginPropertyUtils.pluginProp("schema"));
}

@Before(order = 1, value = "@ORACLE_SOURCE_LONGRAW_TEST")
public static void setSelectQueryForDatatypesLongRaw() {
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
String schema = PluginPropertyUtils.pluginProp("schema");
PluginPropertyUtils.addPluginProp("selectQuery",
PluginPropertyUtils.pluginProp("selectQuery").
replace("${table}", sourceTable).replace("${schema}", schema));
}

@Before(order = 2, value = "@ORACLE_SOURCE_LONGRAW_TEST")
public static void createDatatypesTablesLongRaw() throws SQLException, ClassNotFoundException {
OracleClient.createSourceLongRawTable(PluginPropertyUtils.pluginProp("sourceTable"),
Expand All @@ -96,15 +73,6 @@ public static void createDatatypesTablesLongRaw() throws SQLException, ClassNotF
PluginPropertyUtils.pluginProp("schema"));
}

@Before(order = 1, value = "@ORACLE_SOURCE_DATATYPES_TEST4")
public static void setSelectQueryForLongVarchar() {
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
String schema = PluginPropertyUtils.pluginProp("schema");
PluginPropertyUtils.addPluginProp("selectQuery",
PluginPropertyUtils.pluginProp("selectQuery").
replace("${table}", sourceTable).replace("${schema}", schema));
}

@Before(order = 2, value = "@ORACLE_SOURCE_DATATYPES_TEST4")
public static void createLongVarcharTables() throws SQLException, ClassNotFoundException {
OracleClient.createSourceLongVarcharTable(PluginPropertyUtils.pluginProp("sourceTable"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
driverName=oracle
databaseName=xe
selectQuery=select * from ${schema}.${table}
sourceRef=source
targetRef=target
sourceTable=SOURCETABLE
targetTable=TARGETTABLE
schema=HR
host=ORACLE_HOST
port=ORACLE_PORT
Expand Down