Skip to content

Commit 63424e8

Browse files
Subscription endpoint changes (#258)
* Endpoints have been changed according to this issue #343
1 parent 47c4e42 commit 63424e8

File tree

11 files changed

+301
-116
lines changed

11 files changed

+301
-116
lines changed

pom.xml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@
8787
</exclusions>
8888
</dependency>
8989

90+
<dependency>
91+
<groupId>org.apache.commons</groupId>
92+
<artifactId>commons-lang3</artifactId>
93+
<version>3.9</version>
94+
</dependency>
9095
<dependency>
9196
<groupId>org.apache.httpcomponents</groupId>
9297
<artifactId>httpclient</artifactId>
@@ -127,23 +132,11 @@
127132
<artifactId>selenium-server</artifactId>
128133
<version>3.141.0</version>
129134
</dependency>
130-
<!-- https://mvnrepository.com/artifact/org.mock-server/mockserver-client-java -->
131-
<dependency>
132-
<groupId>org.mock-server</groupId>
133-
<artifactId>mockserver-client-java</artifactId>
134-
<version>5.4.1</version>
135-
<exclusions>
136-
<exclusion>
137-
<groupId>com.vaadin.external.google</groupId>
138-
<artifactId>android-json</artifactId>
139-
</exclusion>
140-
</exclusions>
141-
</dependency>
142135
<!-- https://mvnrepository.com/artifact/org.mock-server/mockserver-netty -->
143136
<dependency>
144137
<groupId>org.mock-server</groupId>
145138
<artifactId>mockserver-netty</artifactId>
146-
<version>5.4.1</version>
139+
<version>5.6.1</version>
147140
<scope>test</scope>
148141
</dependency>
149142
<dependency>

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

Lines changed: 89 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
5+
import static org.mockserver.stop.Stop.stopQuietly;
56
import static org.mockserver.model.HttpRequest.request;
67
import static org.mockserver.model.HttpResponse.response;
78

@@ -15,7 +16,6 @@
1516
import org.junit.Before;
1617
import org.junit.BeforeClass;
1718
import org.junit.Test;
18-
import org.mockserver.client.MockServerClient;
1919
import org.mockserver.integration.ClientAndServer;
2020
import org.openqa.selenium.support.ui.WebDriverWait;
2121
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -25,13 +25,17 @@
2525

2626
public class TestSubscriptionHandling extends SeleniumBaseClass {
2727

28-
private static final String DOWNLOADED_TEMPLATE_FILE_PATH = String.join(File.separator, SeleniumConfig.getTempDownloadDirectory().getPath(),
28+
private static final String DOWNLOADED_TEMPLATE_FILE_PATH = String.join(File.separator,
29+
SeleniumConfig.getTempDownloadDirectory().getPath(),
2930
"subscriptionsTemplate.json");
30-
private static final String DOWNLOADED_BULK_SUBSCRIPTIONS_FILE_PATH = String.join(File.separator, SeleniumConfig.getTempDownloadDirectory().getPath(),
31+
private static final String DOWNLOADED_BULK_SUBSCRIPTIONS_FILE_PATH = String.join(
32+
File.separator, SeleniumConfig.getTempDownloadDirectory().getPath(),
3133
"subscriptionsData.json");
32-
private static final String SUBSCRIPTION_TEMPLATE_FILE_PATH = String.join(File.separator, "src", "functionaltest", "resources", "responses",
34+
private static final String SUBSCRIPTION_TEMPLATE_FILE_PATH = String.join(File.separator, "src",
35+
"functionaltest", "resources", "responses",
3336
"SubscriptionTemplate.json");
34-
private static final String SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP = String.join(File.separator, "src", "functionaltest", "resources",
37+
private static final String SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP = String.join(
38+
File.separator, "src", "functionaltest", "resources",
3539
"responses", "SubscriptionForUploadLDAP.json");
3640

3741
private static final String EXPAND_BUTTON_XPATH = "//tr[contains(.,'Subscription1')]/td[1]";
@@ -59,9 +63,7 @@ public class TestSubscriptionHandling extends SeleniumBaseClass {
5963
private static final String TEMPLATE_JENKINS = "Jenkins Pipeline Parameterized Job Trigger";
6064
private static final String EXPECTED_JENKINS_URL = "http://<JenkinsHost:port>/job/<JobName>/job/<branch>/build";
6165

62-
private static MockServerClient mockClient;
63-
private static ClientAndServer mockServer;
64-
private static final String BASE_URL = "localhost";
66+
private static ClientAndServer clientAndServer;
6567

6668
@MockBean
6769
protected CloseableHttpClient mockedHttpClient;
@@ -70,14 +72,13 @@ public class TestSubscriptionHandling extends SeleniumBaseClass {
7072

7173
@BeforeClass
7274
public static void setUpMocks() throws IOException {
73-
mockServer = startClientAndServer();
74-
mockClient = new MockServerClient(BASE_URL, mockServer.getLocalPort());
75+
clientAndServer = startClientAndServer();
7576
}
7677

7778
@Before
7879
public void before() throws IOException {
79-
int serverPort = mockServer.getLocalPort();
80-
setBackendInstance("new_instance_default", "localhost", serverPort, "", true);
80+
int portServer = clientAndServer.getLocalPort();
81+
setBackendInstance("new_instance_default", "localhost", portServer, "", true);
8182
subscriptionPage = new SubscriptionPage(mockedHttpClient, driver, baseUrl);
8283
}
8384

@@ -88,9 +89,10 @@ public void testSubscriptionButtons() throws Exception {
8889
setupMockEndpoints(security, username);
8990
removeAllSubscriptions();
9091
clickAndVerifyGetTemplateButton();
91-
clickAndVerifyBulkDownloadButton();
9292
uploadSubscriptions();
9393
verifySubscriptionsRequestDeleteAndPost();
94+
setupMockEndpointMultiSubscription();
95+
clickAndVerifyBulkDownloadButton();
9496
}
9597

9698
@Test
@@ -146,7 +148,7 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
146148

147149
@AfterClass
148150
public static void tearDownMocks() throws IOException {
149-
mockClient.stop();
151+
stopQuietly(clientAndServer);
150152
}
151153

152154
private void loadAndRefreshSubscriptionPage() {
@@ -165,29 +167,41 @@ private void removeAllSubscriptions() throws IOException {
165167
subscriptionPage.refreshPage();
166168
}
167169

168-
private void verifySubscriptionsRequestDeleteAndPost() throws InterruptedException, IOException {
170+
private void verifySubscriptionsRequestDeleteAndPost()
171+
throws InterruptedException, IOException {
169172
Thread.sleep(1000);
170-
String downloadedSubscriptionsTemplate = getJSONStringFromFile(DOWNLOADED_TEMPLATE_FILE_PATH);
171-
mockClient.verify(request().withMethod("DELETE").withPath("/subscriptions/Subscription1,Subscription2,Subscription3"));
172-
mockClient.verify(request().withMethod("POST").withPath("/subscriptions").withBody(downloadedSubscriptionsTemplate));
173+
String downloadedSubscriptionsTemplate = getJSONStringFromFile(
174+
DOWNLOADED_TEMPLATE_FILE_PATH);
175+
clientAndServer.verify(request().withMethod("DELETE")
176+
.withPath("/subscriptions")
177+
.withQueryStringParameter("subscriptionNames",
178+
"Subscription1,Subscription2,Subscription3"));
179+
clientAndServer.verify(request().withMethod("POST")
180+
.withPath("/subscriptions")
181+
.withBody(downloadedSubscriptionsTemplate));
173182
}
174183

175184
private void clickAndVerifyBulkDownloadButton() throws IOException {
176185
subscriptionPage.loadPage();
177186
subscriptionPage.clickCheckAll();
178187
subscriptionPage.clickBulkDownload();
179-
new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADED_BULK_SUBSCRIPTIONS_FILE_PATH)));
180-
String downloadedSubscriptionsTemplate = getJSONStringFromFile(DOWNLOADED_BULK_SUBSCRIPTIONS_FILE_PATH);
188+
new WebDriverWait(driver, 10).until(
189+
(webdriver) -> Files.exists(Paths.get(DOWNLOADED_BULK_SUBSCRIPTIONS_FILE_PATH)));
190+
String downloadedSubscriptionsTemplate = getJSONStringFromFile(
191+
DOWNLOADED_BULK_SUBSCRIPTIONS_FILE_PATH);
181192
String subscriptions = getJSONStringFromFile(SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP);
182193
assertEquals(subscriptions, downloadedSubscriptionsTemplate);
183194
}
184195

185196
private void clickAndVerifyGetTemplateButton() throws IOException {
186-
new WebDriverWait(driver, 10).until((webdriver) -> subscriptionPage.presenceOfClickGetTemplateButton());
197+
new WebDriverWait(driver, 10).until(
198+
(webdriver) -> subscriptionPage.presenceOfClickGetTemplateButton());
187199
subscriptionPage.clickGetTemplate();
188-
new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADED_TEMPLATE_FILE_PATH)));
200+
new WebDriverWait(driver, 10).until(
201+
(webdriver) -> Files.exists(Paths.get(DOWNLOADED_TEMPLATE_FILE_PATH)));
189202
String subscriptionTemplate = getJSONStringFromFile(SUBSCRIPTION_TEMPLATE_FILE_PATH);
190-
String downloadedSubscriptionsTemplate = getJSONStringFromFile(DOWNLOADED_TEMPLATE_FILE_PATH);
203+
String downloadedSubscriptionsTemplate = getJSONStringFromFile(
204+
DOWNLOADED_TEMPLATE_FILE_PATH);
191205
assertEquals(subscriptionTemplate, downloadedSubscriptionsTemplate);
192206
}
193207

@@ -238,7 +252,8 @@ private void verifySelectTemplateJenkins() {
238252
assert (subscriptionPage.isRadioCheckboxSelected(RADIO_BUTTON_REST));
239253
assert (!subscriptionPage.isRadioCheckboxSelected(RADIO_BUTTON_JSON));
240254
assert (subscriptionPage.isRadioCheckboxSelected(RADIO_BUTTON_KEY_VALUE));
241-
assertEquals(EXPECTED_JENKINS_URL, subscriptionPage.getValueFromElement(NOTIFICATION_META_ID));
255+
assertEquals(EXPECTED_JENKINS_URL,
256+
subscriptionPage.getValueFromElement(NOTIFICATION_META_ID));
242257
}
243258

244259
private void verifySelectTemplateREST() {
@@ -274,7 +289,8 @@ private void clickCloneSubscriptionAndVerifyFormOpen() {
274289
private void verifyViewButtonOnSubscription() {
275290
subscriptionPage.clickExpandButtonByXPath(EXPAND_BUTTON_XPATH2);
276291
subscriptionPage.clickButtonByXPath(VIEW_BUTTON_XPATH2);
277-
assert (new WebDriverWait(driver, 10).until((webdriver) -> driver.getPageSource().contains("View Subscription")));
292+
assert (new WebDriverWait(driver, 10).until(
293+
(webdriver) -> driver.getPageSource().contains("View Subscription")));
278294
subscriptionPage.clickFormCloseBtn();
279295
}
280296

@@ -293,35 +309,62 @@ private void verifyUnauthorizedSubscriptionCRUD() {
293309
}
294310

295311
private void setupMockEndpoints(boolean security, String user) throws IOException {
296-
mockClient.clear(request());
297-
String subscriptionResponse = getJSONStringFromFile(SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP);
298-
String downloadBulkSubscriptionResponse = "{\"foundSubscriptions\": " + subscriptionResponse + "}";
299-
mockClient.when(request().withMethod("GET").withPath("/subscriptions"))
300-
.respond(response().withStatusCode(200).withBody(subscriptionResponse));
301-
mockClient.when(request().withMethod("GET").withPath("/subscriptions/Subscription1,Subscription2,Subscription3"))
302-
.respond(response().withStatusCode(200).withBody(downloadBulkSubscriptionResponse));
303-
mockClient.when(request().withMethod("DELETE").withPath("/subscriptions")).respond(response().withStatusCode(200).withBody(""));
304-
mockClient.when(request().withMethod("POST").withPath("/subscriptions")).respond(response().withStatusCode(200).withBody(""));
312+
clientAndServer.clear(request());
313+
String subscriptionResponse = getJSONStringFromFile(
314+
SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP);
315+
316+
clientAndServer.when(request().withMethod("GET").withPath("/subscriptions"))
317+
.respond(response().withStatusCode(200).withBody(subscriptionResponse));
318+
clientAndServer.when(
319+
request().withMethod("DELETE")
320+
.withPath("/subscriptions")
321+
.withQueryStringParameter("subscriptionNames",
322+
"Subscription1,Subscription2,Subscription3"))
323+
.respond(response().withStatusCode(200).withBody(""));
324+
clientAndServer.when(request().withMethod("POST").withPath("/subscriptions"))
325+
.respond(response().withStatusCode(200).withBody(""));
305326

306327
String subscriptionResponse2 = getJSONStringFromFile(SUBSCRIPTION_TEMPLATE_FILE_PATH);
307-
String downloadSubscriptionResponse = "{\"foundSubscriptions\": " + subscriptionResponse2 + "}";
308-
mockClient.when(request().withMethod("GET").withPath("/subscriptions/Subscription2"))
309-
.respond(response().withStatusCode(200).withBody(subscriptionResponse2));
310-
mockClient.when(request().withMethod("GET").withPath("/subscriptions/Subscription1"))
311-
.respond(response().withStatusCode(200).withBody(downloadSubscriptionResponse));
328+
clientAndServer.when(request().withMethod("GET").withPath("/subscriptions/Subscription2"))
329+
.respond(response().withStatusCode(200).withBody(subscriptionResponse2));
330+
clientAndServer.when(request().withMethod("GET").withPath("/subscriptions/Subscription1"))
331+
.respond(response().withStatusCode(200).withBody(subscriptionResponse2));
312332

313333
String responseStatus = "{\"status\":\"OK\"}";
314-
mockClient.when(request().withMethod("GET").withPath("/auth/checkStatus")).respond(response().withStatusCode(200).withBody(responseStatus));
334+
clientAndServer.when(request().withMethod("GET").withPath("/auth/checkStatus"))
335+
.respond(response().withStatusCode(200).withBody(responseStatus));
315336

316337
String mockedTemplateResponse = getJSONStringFromFile(SUBSCRIPTION_TEMPLATE_FILE_PATH);
317-
mockClient.when(request().withMethod("DELETE").withPath("/subscriptions/Subscription1,Subscription2,Subscription3"))
318-
.respond(response().withStatusCode(200).withBody(""));
319-
mockClient.when(request().withMethod("GET").withPath("/download/subscriptionsTemplate"))
320-
.respond(response().withStatusCode(200).withBody(mockedTemplateResponse));
338+
clientAndServer.when(
339+
request().withMethod("DELETE")
340+
.withPath("/subscriptions")
341+
.withQueryStringParameter("subscriptionNames",
342+
"Subscription1,Subscription2,Subscription3"))
343+
.respond(response().withStatusCode(200).withBody(""));
344+
clientAndServer.when(
345+
request().withMethod("GET").withPath("/download/subscriptionsTemplate"))
346+
.respond(response().withStatusCode(200).withBody(mockedTemplateResponse));
321347

322348
String responseAuth = "{\"security\":" + security + "}";
323349
String responseUser = "{\"user\":\"" + user + "\"}";
324-
mockClient.when(request().withMethod("GET").withPath("/auth")).respond(response().withStatusCode(200).withBody(responseAuth));
325-
mockClient.when(request().withMethod("GET").withPath("/auth/login")).respond(response().withStatusCode(200).withBody(responseUser));
350+
clientAndServer.when(request().withMethod("GET").withPath("/auth"))
351+
.respond(response().withStatusCode(200).withBody(responseAuth));
352+
clientAndServer.when(request().withMethod("GET").withPath("/auth/login"))
353+
.respond(response().withStatusCode(200).withBody(responseUser));
354+
}
355+
356+
private void setupMockEndpointMultiSubscription() throws IOException {
357+
clientAndServer.clear(request());
358+
String subscriptionResponse = getJSONStringFromFile(
359+
SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP);
360+
String downloadBulkSubscriptionResponse = "{\"foundSubscriptions\": " + subscriptionResponse
361+
+ "}";
362+
clientAndServer.when(
363+
request().withMethod("GET")
364+
.withPath("/subscriptions")
365+
.withQueryStringParameter("subscriptionNames",
366+
"Subscription1,Subscription2,Subscription3"))
367+
.respond(response().withStatusCode(200)
368+
.withBody(downloadBulkSubscriptionResponse));
326369
}
327370
}

src/integrationtest/java/com/ericsson/ei/frontend/CommonSteps.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,15 @@ public void response_body_contains(String contains) throws Throwable {
203203
assertEquals(true, response.getBody().contains(contains));
204204
}
205205

206+
@Then("^response body does not contain \'(.*)\'$")
207+
public void response_body_does_not_contain(String contains) throws Throwable {
208+
LOGGER.info("Response body: {}", response.getBody());
209+
LOGGER.info("Does not contain: {}", contains);
210+
assertEquals(true, !response.getBody().contains(contains));
211+
}
212+
206213
@Then("^remove \'(.*)\' from request headers at list index (\\d+)$")
207214
public void remove_key_from_request_headers_at_list_index(String headerKey, int index) {
208215
httpRequestList.get(index).removeHeader(headerKey);
209216
}
210-
211217
}

0 commit comments

Comments
 (0)