1
1
package com .ericsson .ei .frontend ;
2
2
3
- import org .apache .http .impl .client .CloseableHttpClient ;
4
- import org .junit .*;
5
- import org .openqa .selenium .JavascriptExecutor ;
6
- import org .openqa .selenium .support .ui .WebDriverWait ;
7
- import org .springframework .boot .test .mock .mockito .MockBean ;
8
-
9
- import static org .junit .Assert .*;
3
+ import static org .junit .Assert .assertEquals ;
10
4
11
5
import java .io .File ;
12
6
import java .nio .file .Files ;
13
7
import java .nio .file .Paths ;
14
8
9
+ import org .apache .http .impl .client .CloseableHttpClient ;
10
+ import org .junit .Test ;
11
+ import org .openqa .selenium .JavascriptExecutor ;
12
+ import org .openqa .selenium .support .ui .WebDriverWait ;
13
+ import org .springframework .boot .test .mock .mockito .MockBean ;
14
+
15
15
import com .ericsson .ei .config .SeleniumConfig ;
16
16
import com .ericsson .ei .frontend .pageobjects .IndexPage ;
17
17
import com .ericsson .ei .frontend .pageobjects .SubscriptionPage ;
@@ -38,7 +38,7 @@ public class SubscriptionHandlingFunctionality extends SeleniumBaseClass {
38
38
39
39
@ Test
40
40
public void testSubscription () throws Exception {
41
- // Open index page
41
+ // Open index page.
42
42
IndexPage indexPageObject = new IndexPage (mockedHttpClient , driver , baseUrl );
43
43
indexPageObject .loadPage ();
44
44
@@ -48,57 +48,65 @@ public void testSubscription() throws Exception {
48
48
assert (new WebDriverWait (driver , 10 )
49
49
.until ((webdriver ) -> subscriptionPage .presenceOfHeader (subscriptionHeaderID )));
50
50
51
- // Press "Reload" button without enabling LDAP and verify that two subscriptions
52
- // with names "Subscription1" and "Subscription2" are present AND there exists "edit" and
53
- // "delete buttons" for unauthorized user "ABCD"
54
- String response = this .getJSONStringFromFile (SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH );
51
+ // Press "Reload" button without enabling LDAP and verify that two
52
+ // subscriptions with names "Subscription1" and "Subscription2" are
53
+ // present AND there exists "edit" and" delete buttons" for unauthorized
54
+ // user "ABCD"
55
+ String response = getJSONStringFromFile (SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH );
55
56
String viewButtonXPath = "(//button[@id='view-Subscription1'])[2]" ;
56
57
String editButtonXPath = "(//button[@id='edit-Subscription1'])[2]" ;
57
58
String deleteButtonXPath = "(//button[@id='delete-Subscription1'])[2]" ;
58
59
String expandButtonXPath = "//tr[contains(.,'Subscription1')]/td[1]" ;
60
+
59
61
subscriptionPage .clickReload (response );
62
+
60
63
assert (subscriptionPage .textExistsInTable ("Subscription1" ));
61
64
assert (subscriptionPage .textExistsInTable ("Subscription2" ));
62
65
assert (subscriptionPage .clickElementByXPath (expandButtonXPath ));
63
66
assert (subscriptionPage .buttonExist (deleteButtonXPath ));
64
67
assert (subscriptionPage .buttonExist (editButtonXPath ));
65
68
assert (subscriptionPage .buttonExist (viewButtonXPath ));
66
69
67
- // Given LDAP is enabled, "Reload" subscriptions and then click subscription
68
- // page with LDAP enabled with unauthorized user names
70
+ // Given LDAP is enabled, "Reload" subscriptions and then click
71
+ // subscription page with LDAP enabled with unauthorized user names
69
72
// Verify that subscriptions exists but only with "View" button
70
- String responseSub = this . getJSONStringFromFile (SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP );
73
+ String responseSub = getJSONStringFromFile (SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP );
71
74
String responseAuth = "{\" security\" :true}" ;
75
+
72
76
subscriptionPage .clickReloadLDAP (responseSub , responseAuth );
73
77
indexPageObject .clickSubscriptionPage ();
78
+
74
79
assert (subscriptionPage .clickElementByXPath (expandButtonXPath ));
75
80
assert (!subscriptionPage .buttonExist (deleteButtonXPath ));
76
81
assert (!subscriptionPage .buttonExist (editButtonXPath ));
77
82
assert (subscriptionPage .buttonExist (viewButtonXPath ));
78
83
79
- // Given LDAP is enabled, "Reload" subscriptions and then click subscription
80
- // page with LDAP enabled with both unauthorized and unauthorized user names (in
81
- // this case authorized user is "ABCD" with subscriptions, "subscription1" and
82
- // " subscription2")
83
- // Verify that current user can see only their own subscriptions' edit and
84
- // delete buttons.
84
+ // Given LDAP is enabled, "Reload" subscriptions and then click
85
+ // subscription page with LDAP enabled with both unauthorized and
86
+ // unauthorized user names (in this case authorized user is "ABCD" with
87
+ // subscriptions, "subscription1" and " subscription2") Verify that
88
+ // current user can see only their own subscriptions' edit and delete
89
+ // buttons.
85
90
String keyForUser = "currentUser" ;
86
91
String valueForUser = "ABCD" ;
87
- js = ((JavascriptExecutor ) driver );
92
+
93
+ js = (driver );
88
94
js .executeScript (String .format ("window.localStorage.setItem('%s','%s');" , keyForUser , valueForUser ));
89
95
indexPageObject .clickSubscriptionPage ();
96
+
90
97
assert (subscriptionPage .textExistsInTable ("Subscription1" ));
91
98
assert (subscriptionPage .clickElementByXPath (expandButtonXPath ));
92
99
assert (subscriptionPage .buttonExist (deleteButtonXPath ));
93
100
assert (subscriptionPage .buttonExist (editButtonXPath ));
94
101
assert (subscriptionPage .buttonExist (viewButtonXPath ));
95
102
96
- // Now, path for "subscriptions2" with user name "DEF", so user "ABCD" is
97
- // unauthorized for this subscription
103
+ // Now, path for "subscriptions2" with user name "DEF", so user "ABCD"
104
+ // is unauthorized for this subscription
98
105
String viewButtonXPath2 = "(//button[@id='view-Subscription2'])[2]" ;
99
106
String editButtonXPath2 = "(//button[@id='edit-Subscription2'])[2]" ;
100
107
String deleteButtonXPath2 = "(//button[@id='delete-Subscription2'])[2]" ;
101
108
String expandButtonXPath2 = "//tr[contains(.,'Subscription2')]/td[1]" ;
109
+
102
110
assert (subscriptionPage .clickElementByXPath (expandButtonXPath2 ));
103
111
assert (subscriptionPage .buttonExist (viewButtonXPath2 ));
104
112
assert (!subscriptionPage .buttonExist (editButtonXPath2 ));
@@ -114,41 +122,46 @@ public void testSubscription() throws Exception {
114
122
indexPageObject .loadPage ();
115
123
indexPageObject .clickSubscriptionPage ().clickReload (response );
116
124
117
- // Delete all subscriptions with "Bulk Delete" button and verify that all
118
- // subscriptions are deleted
125
+ // Delete all subscriptions with "Bulk Delete" button and verify that
126
+ // all subscriptions are deleted
119
127
String mockedDeleteResponse = "" ;
120
128
subscriptionPage .clickBulkDelete (mockedDeleteResponse );
121
129
assert (!subscriptionPage .textExistsInTable ("Subscription1" ));
122
130
assert (!subscriptionPage .textExistsInTable ("Subscription2" ));
123
131
124
132
// Verify that "get template" button works
125
- String mockedTemplateResponse = this . getJSONStringFromFile (SUBSCRIPTION_TEMPLATE_FILE_PATH );
133
+ String mockedTemplateResponse = getJSONStringFromFile (SUBSCRIPTION_TEMPLATE_FILE_PATH );
126
134
new WebDriverWait (driver , 10 ).until ((webdriver ) -> subscriptionPage .presenceOfClickGetTemplateButton ());
127
135
subscriptionPage .clickDownloadGetTemplate (mockedTemplateResponse );
128
136
new WebDriverWait (driver , 10 ).until ((webdriver ) -> Files .exists (Paths .get (DOWNLOADED_TEMPLATE_FILE_PATH )));
129
- String getSubscriptionsTemplate = this . getJSONStringFromFile (DOWNLOADED_TEMPLATE_FILE_PATH );
137
+ String getSubscriptionsTemplate = getJSONStringFromFile (DOWNLOADED_TEMPLATE_FILE_PATH );
130
138
assertEquals (mockedTemplateResponse , getSubscriptionsTemplate );
131
139
132
140
// Upload a subscription, name as "Subscription_uploaded" with "Upload
133
141
// SUbscriptions" button and verify
134
- String mockedUploadResponse = this . getJSONStringFromFile (SUBSCRIPTION_FOR_UPLOAD_FILE_PATH );
142
+ String mockedUploadResponse = getJSONStringFromFile (SUBSCRIPTION_FOR_UPLOAD_FILE_PATH );
135
143
subscriptionPage .clickUploadSubscriptionFunctionality (DOWNLOADED_TEMPLATE_FILE_PATH , mockedUploadResponse );
136
144
assert (subscriptionPage .textExistsInTable ("Subscription_uploaded" ));
137
145
138
- // Click "Add Subscription" button and verify that "Subscription Form" is open
146
+ // Click "Add Subscription" button and verify that "Subscription Form"
147
+ // is open
139
148
subscriptionPage .clickAddSubscription ();
140
149
String formHeaderID = "formHeader" ;
141
150
assert ((new WebDriverWait (driver , 10 ).until ((webdriver ) -> subscriptionPage .presenceOfHeader (formHeaderID ))));
142
-
143
- // Test form "Cancel" button:Click "Cancel" button and verify that "Subscription Form" is closed
151
+
152
+ // On subscription form, select the template as "Mail Trigger" and
153
+ // verify Test form "Cancel" button:Click "Cancel" button and verify
154
+ // that "Subscription Form" is closed
144
155
subscriptionPage .clickFormsCancelBtn ();
145
- assert (!subscriptionPage .presenceOfHeader (formHeaderID ));
146
-
147
- // Again, click "Add Subscription" button and verify that "Subscription Form" is open
156
+ assert (!subscriptionPage .presenceOfHeader (formHeaderID ));
157
+
158
+ // Again, click "Add Subscription" button and verify that "Subscription
159
+ // Form" is open
148
160
subscriptionPage .clickAddSubscription ();
149
161
assert ((new WebDriverWait (driver , 10 ).until ((webdriver ) -> subscriptionPage .presenceOfHeader (formHeaderID ))));
150
-
151
- // On subscription form, select the template as "Mail Trigger" and verify
162
+
163
+ // On subscription form, select the template as "Mail Trigger" and
164
+ // verify
152
165
String selectID = "selectTemplate" ;
153
166
String tempMail = "Mail Trigger" ;
154
167
subscriptionPage .selectDropdown (selectID , tempMail );
@@ -157,26 +170,26 @@ public void testSubscription() throws Exception {
157
170
assert (new WebDriverWait (driver , 10 )
158
171
.until ((webdriver ) -> (subscriptionPage .getValueFromElement ().equals ("mymail@company.com" ))));
159
172
160
- // On subscription form, select the template as "REST POST (Raw Body :JSON)"
161
- // and verify
173
+ // On subscription form, select the template as "REST POST (Raw
174
+ // Body:JSON)" and verify
162
175
String tempPost = "REST POST (Raw Body : JSON)" ;
163
176
subscriptionPage .selectDropdown (selectID , tempPost );
164
177
assert (new WebDriverWait (driver , 10 )
165
178
.until ((webdriver ) -> (subscriptionPage .getValueFromSelect ().equals ("REST_POST" ))));
166
179
assert (new WebDriverWait (driver , 10 ).until (
167
180
(webdriver ) -> (subscriptionPage .getValueFromElement ().equals ("http://<MyHost:port>/api/doit" ))));
168
181
169
- // On subscription form, select the template as "Jenkins Pipeline Parameterized
170
- // Job Trigger" and verify
182
+ // On subscription form, select the template as "Jenkins Pipeline
183
+ // Parameterized Job Trigger" and verify
171
184
String tempJenkins = "Jenkins Pipeline Parameterized Job Trigger" ;
172
185
subscriptionPage .selectDropdown (selectID , tempJenkins );
173
186
assertEquals ("REST_POST" , subscriptionPage .getValueFromSelect ());
174
187
assertEquals ("http://<JenkinsHost:port>/job/<JobName>/job/<branch>/build" ,
175
188
subscriptionPage .getValueFromElement ());
176
189
177
- // Choose Authorization as "Basic_AUTH" ===> input User Name as "ABCD" and Token
178
- // as "EFGH" ===> click "Generate Key/Value Pair", verify the basic
179
- // authentication is generated
190
+ // Choose Authorization as "Basic_AUTH" ===> input User Name as "ABCD"
191
+ // and Token as "EFGH" ===> click "Generate Key/Value Pair", verify the
192
+ // basic authentication is generated
180
193
String selectAuthID = "selectAuth" ;
181
194
String authValue = "BASIC_AUTH" ;
182
195
String userName = "ABCD" ;
@@ -191,34 +204,37 @@ public void testSubscription() throws Exception {
191
204
String requirementFieldID = "requirementID" ;
192
205
193
206
subscriptionPage .selectDropdown (selectAuthID , authValue );
194
-
207
+
195
208
subscriptionPage .addFieldValue (userNameID , userName );
196
209
subscriptionPage .addFieldValue (tokenID , token );
197
210
String kvID = "kvID" ;
198
- subscriptionPage .clickKVbtn (kvID );
211
+ subscriptionPage .clickKVbtn (kvID );
199
212
assert (new WebDriverWait (driver , 10 ).until ((webdriver ) -> driver .getPageSource ().contains ("Authorization" )));
200
-
201
- // Test "Repeat" dropdown: Select repeat value as "true" and then verify the selected value
213
+
214
+ // Test "Repeat" dropdown: Select repeat value as "true" and then verify
215
+ // the selected value
202
216
subscriptionPage .selectDropdown (selectRepeatID , repeatValue );
203
217
assert (new WebDriverWait (driver , 10 )
204
- .until ((webdriver ) -> (subscriptionPage .getValueFromSelectRepeat ().equals (repeatValue ))));
205
-
206
- // Test "Add Condition" button: click add condition button and check that it adds an additional "condition" field
218
+ .until ((webdriver ) -> (subscriptionPage .getValueFromSelectRepeat ().equals (repeatValue ))));
219
+
220
+ // Test "Add Condition" button: click add condition button and check
221
+ // that it adds an additional "condition" field
207
222
subscriptionPage .clickAddConditionBtn ();
208
223
assertEquals (2 , subscriptionPage .countElements (conditionFieldID ));
209
-
210
- // Test "Add Requirement" button: click the button and assert that it adds an additional "requirement" field
224
+
225
+ // Test "Add Requirement" button: click the button and assert that it
226
+ // adds an additional "requirement" field
211
227
subscriptionPage .clickAddRequirementBtn ();
212
228
assertEquals (2 , subscriptionPage .countElements (requirementFieldID ));
213
229
214
- // Test save subscription form: add subscription name as
215
- // "selenium_test_subscription" and then click "save" button verification
216
- // that subscription is added in the datatable (and is displayed on the main
217
- // page)
218
- String responseSave = this . getJSONStringFromFile (SUBSCRIPTION_FOR_SAVE_TEST_FILE_PATH );
230
+ // Test save subscription form: add subscription name
231
+ // as "selenium_test_subscription" and then click "save" button
232
+ // verification that subscription is added in the datatable (and is
233
+ // displayed on the main page)
234
+ String responseSave = getJSONStringFromFile (SUBSCRIPTION_FOR_SAVE_TEST_FILE_PATH );
219
235
subscriptionPage .addFieldValue (subNameID , subName );
220
236
subscriptionPage .clickFormsSaveBtn (responseSave );
221
- assert (subscriptionPage .textExistsInTable ("Selenium_test_subscription" ));
237
+ assert (subscriptionPage .textExistsInTable ("Selenium_test_subscription" ));
222
238
223
239
}
224
240
}
0 commit comments