1
+ /*
2
+ * Copyright (c) 2023.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ * use this file except in compliance with the License. You may obtain a copy of
6
+ * the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ * License for the specific language governing permissions and limitations under
14
+ * the License.
15
+ */
16
+
17
+ package io .cdap .plugin .actions ;
18
+
19
+ import io .cdap .e2e .pages .actions .CdfPipelineRunAction ;
20
+ import io .cdap .e2e .pages .locators .CdfPipelineRunLocators ;
21
+ import io .cdap .e2e .utils .*;
22
+ import io .cdap .plugin .locators .ReplicationLocators ;
23
+ import io .cdap .plugin .utils .OracleClient ;
24
+ import io .cdap .plugin .utils .ValidationHelper ;
25
+ import org .apache .commons .lang .StringUtils ;
26
+ import org .junit .Assert ;
27
+ import stepsdesign .BeforeActions ;
28
+
29
+ import java .io .IOException ;
30
+ import java .sql .SQLException ;
31
+ import java .util .ArrayList ;
32
+ import java .util .List ;
33
+ import java .util .Map ;
34
+ import java .util .concurrent .TimeUnit ;
35
+
36
+ public class ReplicationActions {
37
+ private static String parentWindow = StringUtils .EMPTY ;
38
+ private static final String projectId = PluginPropertyUtils .pluginProp ("projectId" );
39
+ private static final String database = PluginPropertyUtils .pluginProp ("database" );
40
+ public static String tableName = PluginPropertyUtils .pluginProp ("sourceTable" );
41
+ public static String schemaName = PluginPropertyUtils .pluginProp ("schema" );
42
+ public static String datatypeColumnNames = PluginPropertyUtils .pluginProp ("datatypeColumnNames" );
43
+ public static String datatypeValues = PluginPropertyUtils .pluginProp ("datatypeValuesForInsertOperation" );
44
+ public static String deleteCondition = PluginPropertyUtils .pluginProp ("deleteRowCondition" );
45
+ public static String updateCondition = PluginPropertyUtils .pluginProp ("updateRowCondition" );
46
+ public static String updatedValue = PluginPropertyUtils .pluginProp ("updatedRow" );
47
+
48
+ static {
49
+ SeleniumHelper .getPropertiesLocators (ReplicationLocators .class );
50
+ }
51
+ public static void clickNextButton () throws InterruptedException {
52
+ TimeUnit time = TimeUnit .SECONDS ;
53
+ time .sleep (1 );
54
+ ElementHelper .clickOnElement (ReplicationLocators .next );
55
+ }
56
+ public static void clickOnOraclePlugin () {
57
+ ElementHelper .clickOnElement (ReplicationLocators .oraclePlugin );
58
+ }
59
+
60
+ public static void selectTable (String tableName ) {
61
+ WaitHelper .waitForElementToBeDisplayed (ReplicationLocators .selectTable (tableName ));
62
+ AssertionHelper .verifyElementDisplayed (ReplicationLocators .selectTable (tableName ));
63
+ ElementHelper .clickOnElement (ReplicationLocators .selectTable (tableName ));
64
+ }
65
+
66
+ public static void deployPipeline () {
67
+ ElementHelper .clickOnElement (ReplicationLocators .deployPipeline );
68
+ }
69
+
70
+ public static void startPipeline () {
71
+ ElementHelper .clickIfDisplayed (ReplicationLocators .start , ConstantsUtil .DEFAULT_TIMEOUT_SECONDS );
72
+ }
73
+
74
+ public static void runThePipeline () {
75
+ startPipeline ();
76
+ WaitHelper .waitForElementToBeDisplayed (ReplicationLocators .running );
77
+ }
78
+
79
+ public static void openAdvanceLogs () {
80
+ ReplicationLocators .logs .click ();
81
+ parentWindow = SeleniumDriver .getDriver ().getWindowHandle ();
82
+ ArrayList <String > tabs = new ArrayList (SeleniumDriver .getDriver ().getWindowHandles ());
83
+ SeleniumDriver .getDriver ().switchTo ().window (tabs .get (tabs .indexOf (parentWindow ) + 1 ));
84
+ ReplicationLocators .advancedLogs .click ();
85
+ }
86
+
87
+ public static void captureRawLog () {
88
+ //Capturing raw logs.
89
+ try {
90
+ String rawLogs = getRawLogs ();
91
+ String logsSeparatorMessage = ConstantsUtil .LOGS_SEPARATOR_MESSAGE
92
+ .replace ("MESSAGE" , "DEPLOYED PIPELINE RUNTIME LOGS" );
93
+ BeforeActions .scenario .write (rawLogs );
94
+ CdfPipelineRunAction .writeRawLogsToFile (BeforeActions .file , logsSeparatorMessage , rawLogs );
95
+ } catch (Exception e ) {
96
+ BeforeActions .scenario .write ("Exception in capturing logs : " + e );
97
+ }
98
+ }
99
+
100
+ public static String getRawLogs () {
101
+ CdfPipelineRunAction .viewRawLogs ();
102
+ ArrayList <String > tabs = new ArrayList (SeleniumDriver .getDriver ().getWindowHandles ());
103
+ PageHelper .switchToWindow (tabs .indexOf (parentWindow ) + 2 );
104
+ String logs = CdfPipelineRunLocators .logsTextbox .getText ();
105
+ Assert .assertNotNull (logs );
106
+ PageHelper .closeCurrentWindow ();
107
+ return logs ;
108
+ }
109
+
110
+ public static void waitTillPipelineIsRunningAndCheckForErrors () throws InterruptedException {
111
+ //wait for datastream to startup
112
+ int defaultTimeout = Integer .parseInt (PluginPropertyUtils .pluginProp ("datastream.timeout" ));
113
+ TimeUnit time = TimeUnit .SECONDS ;
114
+ time .sleep (defaultTimeout );
115
+ // Checking if an error message is displayed.
116
+ Assert .assertFalse (ElementHelper .isElementDisplayed (ReplicationLocators .error ));
117
+ }
118
+
119
+ public static void closeTheLogsAndClickOnStopButton () {
120
+ //As the logs get opened in a new window in this plugin so after closing them we have to switch to parent window.
121
+ SeleniumDriver .getDriver ().switchTo ().window (parentWindow );
122
+ //Stopping the pipeline
123
+ ElementHelper .clickOnElement (ReplicationLocators .stop );
124
+ WaitHelper .waitForElementToBeDisplayed (ReplicationLocators .stopped );
125
+ }
126
+ public static void verifyTargetBigQueryRecordMatchesExpectedOracleRecord ()
127
+ throws IOException , InterruptedException , SQLException , ClassNotFoundException {
128
+ // Checking if an error message is displayed.
129
+ Assert .assertFalse (ElementHelper .isElementDisplayed (ReplicationLocators .error ));
130
+
131
+ List <Map <String , Object >> sourceOracleRecords = OracleClient .getOracleRecordsAsMap (tableName , schemaName );
132
+ List <Map <String , Object >> targetBigQueryRecords = ValidationHelper .getBigQueryRecordsAsMap (projectId , database , tableName ); //+ "_v1`"
133
+ ValidationHelper .validateRecords (sourceOracleRecords , targetBigQueryRecords );
134
+ }
135
+
136
+ public static void insertRecordAndWait ()
137
+ throws IOException , InterruptedException , SQLException , ClassNotFoundException { //JCoException,
138
+ OracleClient .insertRow (tableName ,schemaName , datatypeColumnNames ,datatypeValues );
139
+ OracleClient .forceFlushCDC ();
140
+ ValidationHelper .waitForFlush ();
141
+ }
142
+
143
+ public static void deleteRecordAndWait () throws SQLException , ClassNotFoundException , IOException , InterruptedException {
144
+ OracleClient .deleteRow (tableName ,schemaName , deleteCondition );
145
+ OracleClient .forceFlushCDC ();
146
+ ValidationHelper .waitForFlush ();
147
+ }
148
+
149
+ public static void updateRecordAndWait () throws SQLException , ClassNotFoundException , IOException , InterruptedException {
150
+ OracleClient .updateRow (tableName ,schemaName , updateCondition , updatedValue );
151
+ OracleClient .forceFlushCDC ();
152
+ ValidationHelper .waitForFlush ();
153
+ }
154
+ }
0 commit comments