Skip to content

Commit 7a6ca1d

Browse files
authored
Merge pull request #359 from data-integrations/random_table_name
Added functionality to create tables with random names in E2E tests
2 parents 99511b4 + d2c569e commit 7a6ca1d

File tree

5 files changed

+22
-66
lines changed

5 files changed

+22
-66
lines changed

mysql-plugin/src/e2e-test/java/io/cdap/plugin/MysqlClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ public static boolean compareResultSetData(ResultSet rsSource, ResultSet rsTarge
121121
return true;
122122
}
123123

124-
125124
public static void createSourceTable(String sourceTable) throws SQLException, ClassNotFoundException {
126125
try (Connection connect = getMysqlConnection();
127126
Statement statement = connect.createStatement()) {

mysql-plugin/src/e2e-test/java/io/cdap/plugin/common/stepsdesign/TestSetupHooks.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.cdap.plugin.MysqlClient;
2121
import io.cucumber.java.After;
2222
import io.cucumber.java.Before;
23+
import org.apache.commons.lang3.RandomStringUtils;
2324

2425
import java.sql.SQLException;
2526

@@ -28,8 +29,17 @@
2829
*/
2930
public class TestSetupHooks {
3031

32+
private static void setTableName() {
33+
String randomString = RandomStringUtils.randomAlphabetic(10);
34+
String sourceTableName = String.format("SourceTable_%s", randomString);
35+
String targetTableName = String.format("TargetTable_%s", randomString);
36+
PluginPropertyUtils.addPluginProp("sourceTable", sourceTableName);
37+
PluginPropertyUtils.addPluginProp("targetTable", targetTableName);
38+
PluginPropertyUtils.addPluginProp("selectQuery", String.format("select * from %s", sourceTableName));
39+
}
40+
3141
@Before(order = 1)
32-
public static void overrideUserAndPasswordIfProvided() {
42+
public static void initializeDBProperties() {
3343
String username = System.getenv("username");
3444
if (username != null && !username.isEmpty()) {
3545
PluginPropertyUtils.addPluginProp("username", username);
@@ -38,14 +48,7 @@ public static void overrideUserAndPasswordIfProvided() {
3848
if (password != null && !password.isEmpty()) {
3949
PluginPropertyUtils.addPluginProp("password", password);
4050
}
41-
}
42-
43-
@Before(order = 1, value = "@MYSQL_SOURCE_TEST")
44-
public static void setSelectQuery() {
45-
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
46-
PluginPropertyUtils.addPluginProp("selectQuery",
47-
PluginPropertyUtils.pluginProp("selectQuery").
48-
replace("${table}", sourceTable));
51+
TestSetupHooks.setTableName();
4952
}
5053

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

57-
@Before(order = 1, value = "@MYSQL_SOURCE_DATATYPES_TEST")
58-
public static void setSelectQueryForDatatypes() {
59-
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
60-
PluginPropertyUtils.addPluginProp("selectQuery",
61-
PluginPropertyUtils.pluginProp("selectQuery").
62-
replace("${table}", sourceTable));
63-
}
64-
6560
@Before(order = 2, value = "@MYSQL_SOURCE_DATATYPES_TEST")
6661
public static void createDatatypesTable() throws SQLException, ClassNotFoundException {
6762
MysqlClient.createSourceDatatypesTable(PluginPropertyUtils.pluginProp("sourceTable"));

mysql-plugin/src/e2e-test/resources/pluginParameters.properties

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ username=MYSQL_USERNAME
44
password=MYSQL_PASSWORD
55
databaseName=sakila
66
port=MYSQL_PORT
7-
selectQuery=select * from ${table}
87
sourceRef=source
98
targetRef=target
10-
sourceTable=sourceTable
11-
targetTable=targetTable
129
outputSchema=[{"key":"id","value":"int"},{"key":"lastName","value":"string"}]
1310

1411
datatypesColumns=(ID varchar(100) PRIMARY KEY, COL1 bigint(20), COL2 bigint(20) unsigned, COL3 binary(1), \

oracle-plugin/src/e2e-test/java/io.cdap.plugin/common.stepsdesign/TestSetupHooks.java

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.cdap.plugin.OracleClient;
2121
import io.cucumber.java.After;
2222
import io.cucumber.java.Before;
23+
import org.apache.commons.lang3.RandomStringUtils;
2324

2425
import java.sql.SQLException;
2526

@@ -28,13 +29,16 @@
2829
*/
2930
public class TestSetupHooks {
3031

31-
@Before(order = 1, value = "@ORACLE_SOURCE_TEST")
32-
public static void setSelectQuery() {
33-
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
32+
@Before(order = 1)
33+
public static void setTableName() {
34+
String randomString = RandomStringUtils.randomAlphabetic(10).toUpperCase();
35+
String sourceTableName = String.format("SOURCETABLE_%s", randomString);
36+
String targetTableName = String.format("TARGETTABLE_%s", randomString);
37+
PluginPropertyUtils.addPluginProp("sourceTable", sourceTableName);
38+
PluginPropertyUtils.addPluginProp("targetTable", targetTableName);
3439
String schema = PluginPropertyUtils.pluginProp("schema");
35-
PluginPropertyUtils.addPluginProp("selectQuery",
36-
PluginPropertyUtils.pluginProp("selectQuery").
37-
replace("${table}", sourceTable).replace("${schema}", schema));
40+
PluginPropertyUtils.addPluginProp("selectQuery", String.format("select * from %s.%s", schema,
41+
sourceTableName));
3842
}
3943

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

48-
@Before(order = 1, value = "@ORACLE_SOURCE_DATATYPES_TEST")
49-
public static void setSelectQueryForAllDatatypes() {
50-
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
51-
String schema = PluginPropertyUtils.pluginProp("schema");
52-
PluginPropertyUtils.addPluginProp("selectQuery",
53-
PluginPropertyUtils.pluginProp("selectQuery").
54-
replace("${table}", sourceTable).replace("${schema}", schema));
55-
}
56-
5752
@Before(order = 2, value = "@ORACLE_SOURCE_DATATYPES_TEST")
5853
public static void createAllDatatypesTables() throws SQLException, ClassNotFoundException {
5954
OracleClient.createSourceDatatypesTable(PluginPropertyUtils.pluginProp("sourceTable"),
@@ -62,15 +57,6 @@ public static void createAllDatatypesTables() throws SQLException, ClassNotFound
6257
PluginPropertyUtils.pluginProp("schema"));
6358
}
6459

65-
@Before(order = 1, value = "@ORACLE_SOURCE_DATATYPES_TEST2")
66-
public static void setSelectQueryForLongDatatype() {
67-
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
68-
String schema = PluginPropertyUtils.pluginProp("schema");
69-
PluginPropertyUtils.addPluginProp("selectQuery",
70-
PluginPropertyUtils.pluginProp("selectQuery").
71-
replace("${table}", sourceTable).replace("${schema}", schema));
72-
}
73-
7460
@Before(order = 2, value = "@ORACLE_SOURCE_DATATYPES_TEST2")
7561
public static void createDatatypesTablesLong() throws SQLException, ClassNotFoundException {
7662
OracleClient.createSourceLongTable(PluginPropertyUtils.pluginProp("sourceTable"),
@@ -79,15 +65,6 @@ public static void createDatatypesTablesLong() throws SQLException, ClassNotFoun
7965
PluginPropertyUtils.pluginProp("schema"));
8066
}
8167

82-
@Before(order = 1, value = "@ORACLE_SOURCE_LONGRAW_TEST")
83-
public static void setSelectQueryForDatatypesLongRaw() {
84-
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
85-
String schema = PluginPropertyUtils.pluginProp("schema");
86-
PluginPropertyUtils.addPluginProp("selectQuery",
87-
PluginPropertyUtils.pluginProp("selectQuery").
88-
replace("${table}", sourceTable).replace("${schema}", schema));
89-
}
90-
9168
@Before(order = 2, value = "@ORACLE_SOURCE_LONGRAW_TEST")
9269
public static void createDatatypesTablesLongRaw() throws SQLException, ClassNotFoundException {
9370
OracleClient.createSourceLongRawTable(PluginPropertyUtils.pluginProp("sourceTable"),
@@ -96,15 +73,6 @@ public static void createDatatypesTablesLongRaw() throws SQLException, ClassNotF
9673
PluginPropertyUtils.pluginProp("schema"));
9774
}
9875

99-
@Before(order = 1, value = "@ORACLE_SOURCE_DATATYPES_TEST4")
100-
public static void setSelectQueryForLongVarchar() {
101-
String sourceTable = PluginPropertyUtils.pluginProp("sourceTable");
102-
String schema = PluginPropertyUtils.pluginProp("schema");
103-
PluginPropertyUtils.addPluginProp("selectQuery",
104-
PluginPropertyUtils.pluginProp("selectQuery").
105-
replace("${table}", sourceTable).replace("${schema}", schema));
106-
}
107-
10876
@Before(order = 2, value = "@ORACLE_SOURCE_DATATYPES_TEST4")
10977
public static void createLongVarcharTables() throws SQLException, ClassNotFoundException {
11078
OracleClient.createSourceLongVarcharTable(PluginPropertyUtils.pluginProp("sourceTable"),

oracle-plugin/src/e2e-test/resources/pluginParameters.properties

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
driverName=oracle
22
databaseName=xe
3-
selectQuery=select * from ${schema}.${table}
43
sourceRef=source
54
targetRef=target
6-
sourceTable=SOURCETABLE
7-
targetTable=TARGETTABLE
85
schema=HR
96
host=ORACLE_HOST
107
port=ORACLE_PORT

0 commit comments

Comments
 (0)