26
26
public class TestSubscriptionHandling extends SeleniumBaseClass {
27
27
28
28
private static final String DOWNLOADED_TEMPLATE_FILE_PATH = String .join (File .separator ,
29
- SeleniumConfig .getTempDownloadDirectory ().getPath (), "subscriptionsTemplate.json" );
29
+ SeleniumConfig .getTempDownloadDirectory ()
30
+ .getPath (),
31
+ "subscriptionsTemplate.json" );
30
32
private static final String SUBSCRIPTION_TEMPLATE_FILE_PATH = String .join (File .separator , "src" , "functionaltest" ,
31
33
"resources" , "responses" , "SubscriptionTemplate.json" );
32
34
private static final String SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP = String .join (File .separator , "src" ,
@@ -70,15 +72,18 @@ public void testSubscriptionButtons() throws Exception {
70
72
71
73
// Setup mocks for "Bulk Delete" and get Template
72
74
String mockedTemplateResponse = getJSONStringFromFile (SUBSCRIPTION_TEMPLATE_FILE_PATH );
73
- mockClient
74
- .when (request ().withMethod ("DELETE" )
75
- .withPath ("/subscriptions/Subscription1,Subscription2,Subscription3" ))
76
- .respond (response ().withStatusCode (200 ).withBody ("" ));
77
- mockClient .when (request ().withMethod ("GET" ).withPath ("/download/subscriptionsTemplate" ))
78
- .respond (response ().withStatusCode (200 ).withBody (mockedTemplateResponse ));
75
+ mockClient .when (request ().withMethod ("DELETE" )
76
+ .withPath ("/subscriptions/Subscription1,Subscription2,Subscription3" ))
77
+ .respond (response ().withStatusCode (200 )
78
+ .withBody ("" ));
79
+ mockClient .when (request ().withMethod ("GET" )
80
+ .withPath ("/download/subscriptionsTemplate" ))
81
+ .respond (response ().withStatusCode (200 )
82
+ .withBody (mockedTemplateResponse ));
79
83
80
84
// Delete all subscriptions before continuing (This does not delete
81
- // subscriptions as subscriptions are mocked and cannot be deleted, we check mock
85
+ // subscriptions as subscriptions are mocked and cannot be deleted, we check
86
+ // mock
82
87
// server for correct call at the end of the test)
83
88
subscriptionPage .clickBulkDelete ();
84
89
@@ -95,13 +100,14 @@ public void testSubscriptionButtons() throws Exception {
95
100
// Upload a subscription
96
101
subscriptionPage .clickUploadSubscriptionFunctionality (DOWNLOADED_TEMPLATE_FILE_PATH );
97
102
98
-
99
103
// Verify that subscriptions where deleted and added via calls to mocked
100
104
// server
101
105
Thread .sleep (1000 );
102
- mockClient .verify (request ()
103
- .withMethod ("DELETE" ).withPath ("/subscriptions/Subscription1,Subscription2,Subscription3" ));
104
- mockClient .verify (request ().withMethod ("POST" ).withPath ("/subscriptions" ).withBody (getSubscriptionsTemplate ));
106
+ mockClient .verify (request ().withMethod ("DELETE" )
107
+ .withPath ("/subscriptions/Subscription1,Subscription2,Subscription3" ));
108
+ mockClient .verify (request ().withMethod ("POST" )
109
+ .withPath ("/subscriptions" )
110
+ .withBody (getSubscriptionsTemplate ));
105
111
}
106
112
107
113
@ Test
@@ -206,7 +212,8 @@ public void testAddSubscriptionAndVerifyForm() throws Exception {
206
212
assert (subscriptionPage .isRadioCheckboxSelected (mailRadioID ));
207
213
assertEquals ("mymail@company.com" , subscriptionPage .getValueFromElement (notificationMetaInputID ));
208
214
209
- // Save and verify that form was closed, if form was not closed something went wrong.
215
+ // Save and verify that form was closed, if form was not closed something went
216
+ // wrong.
210
217
subscriptionPage .clickFormsSaveBtn ();
211
218
assert (subscriptionPage .noPresenceOfHeader (formHeaderID ));
212
219
}
@@ -216,14 +223,12 @@ public void testSubscriptionHandlingWithLDAPDisabled() throws Exception {
216
223
// Set up
217
224
int portServer = mockServer .getLocalPort ();
218
225
backEndInstancesUtils .setDefaultBackEndInstanceToNull ();
219
- backEndInstancesUtils .setDefaultBackEndInstance ("new_instance_default" ,
220
- "localhost" , portServer , "" , true );
226
+ backEndInstancesUtils .setDefaultBackEndInstance ("new_instance_default" , "localhost" , portServer , "" , true );
221
227
setupMockEndpoints (false , "" );
222
228
223
229
// Open subscription page.
224
230
IndexPage indexPageObject = openIndexPage ();
225
- SubscriptionPage subscriptionPage =
226
- openSubscriptionPage (indexPageObject );
231
+ SubscriptionPage subscriptionPage = openSubscriptionPage (indexPageObject );
227
232
228
233
// Press "Reload" button without enabling LDAP and verify that two
229
234
// subscriptions with names "Subscription1" and "Subscription2" are
@@ -235,8 +240,8 @@ public void testSubscriptionHandlingWithLDAPDisabled() throws Exception {
235
240
236
241
// Test View button on a subscription
237
242
subscriptionPage .clickViewButtonByXPath (VIEW_BUTTON_XPATH2 );
238
- assert (new WebDriverWait (driver , 10 )
239
- . until (( webdriver ) -> driver . getPageSource () .contains ("View Subscription" )));
243
+ assert (new WebDriverWait (driver , 10 ). until (( webdriver ) -> driver . getPageSource ()
244
+ .contains ("View Subscription" )));
240
245
subscriptionPage .clickFormCloseBtn ();
241
246
}
242
247
@@ -245,21 +250,19 @@ public void testSubscriptionHandlingWithLDAPEnabledInvalidUser() throws Exceptio
245
250
// Set up
246
251
int portServer = mockServer .getLocalPort ();
247
252
backEndInstancesUtils .setDefaultBackEndInstanceToNull ();
248
- backEndInstancesUtils .setDefaultBackEndInstance ("new_instance_default" ,
249
- "localhost" , portServer , "" , true );
253
+ backEndInstancesUtils .setDefaultBackEndInstance ("new_instance_default" , "localhost" , portServer , "" , true );
250
254
setupMockEndpoints (true , "" );
251
255
252
256
// Open subscription page.
253
257
IndexPage indexPageObject = openIndexPage ();
254
- SubscriptionPage subscriptionPage =
255
- openSubscriptionPage (indexPageObject );
258
+ SubscriptionPage subscriptionPage = openSubscriptionPage (indexPageObject );
256
259
257
260
// Given LDAP is enabled, "Reload" subscriptions and reload
258
261
// subscription page with LDAP enabled with unauthorized user names
259
262
// Verify that subscriptions exists but only with "View" button
260
263
assert (subscriptionPage .clickExpandButtonByXPath (EXPAND_BUTTON_XPATH ));
261
- assert (subscriptionPage .buttonDoesNotExistByXPath (DELETE_BUTTON_XPATH ));
262
- assert (subscriptionPage .buttonDoesNotExistByXPath (EDIT_BUTTON_XPATH ));
264
+ assert (subscriptionPage .buttonDisabledByXPath (DELETE_BUTTON_XPATH ));
265
+ assert (subscriptionPage .buttonDisabledByXPath (EDIT_BUTTON_XPATH ));
263
266
assert (subscriptionPage .buttonExistByXPath (VIEW_BUTTON_XPATH ));
264
267
}
265
268
@@ -268,14 +271,12 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
268
271
// Set up
269
272
int portServer = mockServer .getLocalPort ();
270
273
backEndInstancesUtils .setDefaultBackEndInstanceToNull ();
271
- backEndInstancesUtils .setDefaultBackEndInstance ("new_instance_default" ,
272
- "localhost" , portServer , "" , true );
274
+ backEndInstancesUtils .setDefaultBackEndInstance ("new_instance_default" , "localhost" , portServer , "" , true );
273
275
setupMockEndpoints (true , "ABCD" );
274
276
275
277
// Open subscription page.
276
278
IndexPage indexPageObject = openIndexPage ();
277
- SubscriptionPage subscriptionPage =
278
- openSubscriptionPage (indexPageObject );
279
+ SubscriptionPage subscriptionPage = openSubscriptionPage (indexPageObject );
279
280
280
281
// Given LDAP is enabled, reload the index page and mock the user
281
282
// response as user 'ABCD'. Verify that current user can see only
@@ -291,8 +292,8 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
291
292
// is unauthorized for this subscription
292
293
assert (subscriptionPage .clickExpandButtonByXPath (EXPAND_BUTTON_XPATH2 ));
293
294
assert (subscriptionPage .buttonExistByXPath (VIEW_BUTTON_XPATH2 ));
294
- assert (subscriptionPage .buttonDoesNotExistByXPath (EDIT_BUTTON_XPATH2 ));
295
- assert (subscriptionPage .buttonDoesNotExistByXPath (DELETE_BUTTON_XPATH2 ));
295
+ assert (subscriptionPage .buttonDisabledByXPath (EDIT_BUTTON_XPATH2 ));
296
+ assert (subscriptionPage .buttonDisabledByXPath (DELETE_BUTTON_XPATH2 ));
296
297
297
298
}
298
299
@@ -306,36 +307,50 @@ private SubscriptionPage openSubscriptionPage(IndexPage indexPageObject) throws
306
307
// Click on Subscription Handling page button and verify that it is open
307
308
String subscriptionHeaderID = "subData" ;
308
309
SubscriptionPage subscriptionPage = indexPageObject .clickSubscriptionPage ();
309
- assert (new WebDriverWait (driver , 10 )
310
- . until ( (webdriver ) -> subscriptionPage .presenceOfHeader (subscriptionHeaderID )));
310
+ assert (new WebDriverWait (driver , 10 ). until (
311
+ (webdriver ) -> subscriptionPage .presenceOfHeader (subscriptionHeaderID )));
311
312
312
313
return subscriptionPage ;
313
314
}
314
315
315
316
private static void setupMockEndpoints (boolean security , String user ) throws IOException {
316
317
mockClient .clear (request ());
317
318
String subscriptionResponse = getJSONStringFromFile (SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP );
318
- mockClient .when (request ().withMethod ("GET" ).withPath ("/subscriptions" ))
319
- .respond (response ().withStatusCode (200 ).withBody (subscriptionResponse ));
320
- mockClient .when (request ().withMethod ("DELETE" ).withPath ("/subscriptions" ))
321
- .respond (response ().withStatusCode (200 ).withBody ("" ));
322
- mockClient .when (request ().withMethod ("POST" ).withPath ("/subscriptions" ))
323
- .respond (response ().withStatusCode (200 ).withBody ("" ));
319
+ mockClient .when (request ().withMethod ("GET" )
320
+ .withPath ("/subscriptions" ))
321
+ .respond (response ().withStatusCode (200 )
322
+ .withBody (subscriptionResponse ));
323
+ mockClient .when (request ().withMethod ("DELETE" )
324
+ .withPath ("/subscriptions" ))
325
+ .respond (response ().withStatusCode (200 )
326
+ .withBody ("" ));
327
+ mockClient .when (request ().withMethod ("POST" )
328
+ .withPath ("/subscriptions" ))
329
+ .respond (response ().withStatusCode (200 )
330
+ .withBody ("" ));
324
331
325
332
String subscriptionResponse2 = getJSONStringFromFile (SUBSCRIPTION_TEMPLATE_FILE_PATH );
326
- mockClient .when (request ().withMethod ("GET" ).withPath ("/subscriptions/Subscription2" ))
327
- .respond (response ().withStatusCode (200 ).withBody (subscriptionResponse2 ));
333
+ mockClient .when (request ().withMethod ("GET" )
334
+ .withPath ("/subscriptions/Subscription2" ))
335
+ .respond (response ().withStatusCode (200 )
336
+ .withBody (subscriptionResponse2 ));
328
337
329
338
String responseStatus = "{\" status\" :\" OK\" }" ;
330
- mockClient .when (request ().withMethod ("GET" ).withPath ("/auth/checkStatus" ))
331
- .respond (response ().withStatusCode (200 ).withBody (responseStatus ));
339
+ mockClient .when (request ().withMethod ("GET" )
340
+ .withPath ("/auth/checkStatus" ))
341
+ .respond (response ().withStatusCode (200 )
342
+ .withBody (responseStatus ));
332
343
333
344
String responseAuth = "{\" security\" :" + security + "}" ;
334
345
String responseUser = "{\" user\" :\" " + user + "\" }" ;
335
- mockClient .when (request ().withMethod ("GET" ).withPath ("/auth" ))
336
- .respond (response ().withStatusCode (200 ).withBody (responseAuth ));
337
- mockClient .when (request ().withMethod ("GET" ).withPath ("/auth/login" ))
338
- .respond (response ().withStatusCode (200 ).withBody (responseUser ));
346
+ mockClient .when (request ().withMethod ("GET" )
347
+ .withPath ("/auth" ))
348
+ .respond (response ().withStatusCode (200 )
349
+ .withBody (responseAuth ));
350
+ mockClient .when (request ().withMethod ("GET" )
351
+ .withPath ("/auth/login" ))
352
+ .respond (response ().withStatusCode (200 )
353
+ .withBody (responseUser ));
339
354
340
355
}
341
356
0 commit comments