-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathTestSetupHooks.java
More file actions
91 lines (79 loc) · 4.23 KB
/
TestSetupHooks.java
File metadata and controls
91 lines (79 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright © 2023 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package io.cdap.plugin.common.stepsdesign;
import io.cdap.e2e.utils.PluginPropertyUtils;
import io.cdap.plugin.MssqlClient;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import org.apache.commons.lang3.RandomStringUtils;
import java.sql.SQLException;
/**
* Mssql test hooks.
*/
public class TestSetupHooks {
@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", String.format("select * from %s.%s", schema,
sourceTableName));
}
@Before(order = 2, value = "@MSSQL_SOURCE_TEST")
public static void createTables() throws SQLException, ClassNotFoundException {
MssqlClient.createSourceTable(PluginPropertyUtils.pluginProp("sourceTable"),
PluginPropertyUtils.pluginProp("schema"));
MssqlClient.createTargetTable(PluginPropertyUtils.pluginProp("targetTable"),
PluginPropertyUtils.pluginProp("schema"));
}
@Before(order = 2, value = "@MSSQL_SOURCE_DATATYPES_TEST")
public static void createAllDatatypesTables() throws SQLException, ClassNotFoundException {
MssqlClient.createSourceDatatypesTable(PluginPropertyUtils.pluginProp("sourceTable"),
PluginPropertyUtils.pluginProp("schema"));
MssqlClient.createTargetDatatypesTable(PluginPropertyUtils.pluginProp("targetTable"),
PluginPropertyUtils.pluginProp("schema"));
}
@Before(order = 2, value = "@MSSQL_SOURCE_DATATYPES_IMAGE_TEST")
public static void createDatatypesTablesImage() throws SQLException, ClassNotFoundException {
MssqlClient.createSourceImageTable(PluginPropertyUtils.pluginProp("sourceTable"),
PluginPropertyUtils.pluginProp("schema"));
MssqlClient.createTargetImageTable(PluginPropertyUtils.pluginProp("targetTable"),
PluginPropertyUtils.pluginProp("schema"));
}
@Before(order = 2, value = "@MSSQL_SOURCE_DATATYPES_UIDTYPE_TEST")
public static void createDatatypesTablesUniqueIdentifier() throws SQLException, ClassNotFoundException {
MssqlClient.createSourceUniqueIdentifierTable(PluginPropertyUtils.pluginProp("sourceTable"),
PluginPropertyUtils.pluginProp("schema"));
MssqlClient.createTargetUniqueIdentifierTable(PluginPropertyUtils.pluginProp("targetTable"),
PluginPropertyUtils.pluginProp("schema"));
}
@Before(order = 2, value = "@MSSQL_SOURCE_DATATYPES_DATETIME_TEST")
public static void createDatatypesTablesDateTime() throws SQLException, ClassNotFoundException {
MssqlClient.createSourceDateTimeTable(PluginPropertyUtils.pluginProp("sourceTable"),
PluginPropertyUtils.pluginProp("schema"));
MssqlClient.createTargetDateTimeTable(PluginPropertyUtils.pluginProp("targetTable"),
PluginPropertyUtils.pluginProp("schema"));
}
@After(order = 1, value = "@MSSQL_SINK_TEST")
public static void dropTables() throws SQLException, ClassNotFoundException {
MssqlClient.deleteTables(PluginPropertyUtils.pluginProp("schema"),
new String[]{PluginPropertyUtils.pluginProp("sourceTable"),
PluginPropertyUtils.pluginProp("targetTable")});
}
}