Skip to content

Commit fea9601

Browse files
User can CRUD anonymous subscriptions (#192)
* disabling button for edit and delete when logout * disabling edit/delete buttons * subscription page buttons are visible now
1 parent 55707ea commit fea9601

File tree

7 files changed

+158
-136
lines changed

7 files changed

+158
-136
lines changed

src/functionaltest/java/com/ericsson/ei/frontend/TestSubscriptionHandling.java

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
public class TestSubscriptionHandling extends SeleniumBaseClass {
2727

2828
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");
3032
private static final String SUBSCRIPTION_TEMPLATE_FILE_PATH = String.join(File.separator, "src", "functionaltest",
3133
"resources", "responses", "SubscriptionTemplate.json");
3234
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 {
7072

7173
// Setup mocks for "Bulk Delete" and get Template
7274
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));
7983

8084
// 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
8287
// server for correct call at the end of the test)
8388
subscriptionPage.clickBulkDelete();
8489

@@ -95,13 +100,14 @@ public void testSubscriptionButtons() throws Exception {
95100
// Upload a subscription
96101
subscriptionPage.clickUploadSubscriptionFunctionality(DOWNLOADED_TEMPLATE_FILE_PATH);
97102

98-
99103
// Verify that subscriptions where deleted and added via calls to mocked
100104
// server
101105
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));
105111
}
106112

107113
@Test
@@ -206,7 +212,8 @@ public void testAddSubscriptionAndVerifyForm() throws Exception {
206212
assert (subscriptionPage.isRadioCheckboxSelected(mailRadioID));
207213
assertEquals("mymail@company.com", subscriptionPage.getValueFromElement(notificationMetaInputID));
208214

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.
210217
subscriptionPage.clickFormsSaveBtn();
211218
assert (subscriptionPage.noPresenceOfHeader(formHeaderID));
212219
}
@@ -216,14 +223,12 @@ public void testSubscriptionHandlingWithLDAPDisabled() throws Exception {
216223
// Set up
217224
int portServer = mockServer.getLocalPort();
218225
backEndInstancesUtils.setDefaultBackEndInstanceToNull();
219-
backEndInstancesUtils.setDefaultBackEndInstance("new_instance_default",
220-
"localhost", portServer, "", true);
226+
backEndInstancesUtils.setDefaultBackEndInstance("new_instance_default", "localhost", portServer, "", true);
221227
setupMockEndpoints(false, "");
222228

223229
// Open subscription page.
224230
IndexPage indexPageObject = openIndexPage();
225-
SubscriptionPage subscriptionPage =
226-
openSubscriptionPage(indexPageObject);
231+
SubscriptionPage subscriptionPage = openSubscriptionPage(indexPageObject);
227232

228233
// Press "Reload" button without enabling LDAP and verify that two
229234
// subscriptions with names "Subscription1" and "Subscription2" are
@@ -235,8 +240,8 @@ public void testSubscriptionHandlingWithLDAPDisabled() throws Exception {
235240

236241
// Test View button on a subscription
237242
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")));
240245
subscriptionPage.clickFormCloseBtn();
241246
}
242247

@@ -245,21 +250,19 @@ public void testSubscriptionHandlingWithLDAPEnabledInvalidUser() throws Exceptio
245250
// Set up
246251
int portServer = mockServer.getLocalPort();
247252
backEndInstancesUtils.setDefaultBackEndInstanceToNull();
248-
backEndInstancesUtils.setDefaultBackEndInstance("new_instance_default",
249-
"localhost", portServer, "", true);
253+
backEndInstancesUtils.setDefaultBackEndInstance("new_instance_default", "localhost", portServer, "", true);
250254
setupMockEndpoints(true, "");
251255

252256
// Open subscription page.
253257
IndexPage indexPageObject = openIndexPage();
254-
SubscriptionPage subscriptionPage =
255-
openSubscriptionPage(indexPageObject);
258+
SubscriptionPage subscriptionPage = openSubscriptionPage(indexPageObject);
256259

257260
// Given LDAP is enabled, "Reload" subscriptions and reload
258261
// subscription page with LDAP enabled with unauthorized user names
259262
// Verify that subscriptions exists but only with "View" button
260263
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));
263266
assert (subscriptionPage.buttonExistByXPath(VIEW_BUTTON_XPATH));
264267
}
265268

@@ -268,14 +271,12 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
268271
// Set up
269272
int portServer = mockServer.getLocalPort();
270273
backEndInstancesUtils.setDefaultBackEndInstanceToNull();
271-
backEndInstancesUtils.setDefaultBackEndInstance("new_instance_default",
272-
"localhost", portServer, "", true);
274+
backEndInstancesUtils.setDefaultBackEndInstance("new_instance_default", "localhost", portServer, "", true);
273275
setupMockEndpoints(true, "ABCD");
274276

275277
// Open subscription page.
276278
IndexPage indexPageObject = openIndexPage();
277-
SubscriptionPage subscriptionPage =
278-
openSubscriptionPage(indexPageObject);
279+
SubscriptionPage subscriptionPage = openSubscriptionPage(indexPageObject);
279280

280281
// Given LDAP is enabled, reload the index page and mock the user
281282
// response as user 'ABCD'. Verify that current user can see only
@@ -291,8 +292,8 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
291292
// is unauthorized for this subscription
292293
assert (subscriptionPage.clickExpandButtonByXPath(EXPAND_BUTTON_XPATH2));
293294
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));
296297

297298
}
298299

@@ -306,36 +307,50 @@ private SubscriptionPage openSubscriptionPage(IndexPage indexPageObject) throws
306307
// Click on Subscription Handling page button and verify that it is open
307308
String subscriptionHeaderID = "subData";
308309
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)));
311312

312313
return subscriptionPage;
313314
}
314315

315316
private static void setupMockEndpoints(boolean security, String user) throws IOException {
316317
mockClient.clear(request());
317318
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(""));
324331

325332
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));
328337

329338
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));
332343

333344
String responseAuth = "{\"security\":" + security + "}";
334345
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));
339354

340355
}
341356

0 commit comments

Comments
 (0)