Skip to content

Commit 3476e0b

Browse files
author
Anders Breid
authored
Fix multiple user login problem (#132)
* Fix login issue where only one user could be logged in using the EI front-end.
1 parent 1aac28a commit 3476e0b

File tree

7 files changed

+408
-260
lines changed

7 files changed

+408
-260
lines changed

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

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
package com.ericsson.ei.frontend;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
5+
import static org.mockserver.model.HttpRequest.request;
6+
import static org.mockserver.model.HttpResponse.response;
47

58
import java.io.File;
9+
import java.io.IOException;
610
import java.nio.file.Files;
711
import java.nio.file.Paths;
812

913
import org.apache.http.impl.client.CloseableHttpClient;
14+
import org.junit.AfterClass;
15+
import org.junit.BeforeClass;
1016
import org.junit.Test;
17+
import org.mockserver.client.MockServerClient;
18+
import org.mockserver.integration.ClientAndServer;
1119
import org.openqa.selenium.support.ui.WebDriverWait;
1220
import org.springframework.boot.test.mock.mockito.MockBean;
1321

@@ -17,6 +25,10 @@
1725

1826
public class TestRulesFunctionality extends SeleniumBaseClass {
1927

28+
private static MockServerClient mockClient;
29+
private static ClientAndServer mockServer;
30+
private static final String BASE_URL = "localhost";
31+
2032
private static final String DOWNLOADED_RULES_TEMPLATE_FILE_PATH = String.join(
2133
File.separator, SeleniumConfig.getTempDownloadDirectory().getPath(), "rulesTemplate.json");
2234
private static final String RULES_TEMPLATE_FILE_PATH = String.join(
@@ -35,9 +47,13 @@ public class TestRulesFunctionality extends SeleniumBaseClass {
3547

3648
@Test
3749
public void testJourneyToFindAggregatedObjectButton() throws Exception {
38-
initBaseMocks(mockedHttpClient);
39-
// Load index page and wait for it to load
40-
IndexPage indexPageObject = new IndexPage(mockedHttpClient, driver, baseUrl);
50+
// Set up
51+
int portServer = mockServer.getLocalPort();
52+
backEndInstancesUtils.setDefaultBackEndInstanceToNull();
53+
backEndInstancesUtils.setDefaultBackEndInstance("new_instance_default", "localhost", portServer, "", true);
54+
55+
// Open indexpage and verify that it is opened
56+
IndexPage indexPageObject = new IndexPage(null, driver, baseUrl);
4157
indexPageObject.loadPage();
4258

4359
// Verify that we can navigate to test rules page
@@ -47,15 +63,12 @@ public void testJourneyToFindAggregatedObjectButton() throws Exception {
4763
// Verify that "download rules template" button works
4864
String downloadedRulesTemplate = "";
4965
String mockedResponse = getJSONStringFromFile(RULES_TEMPLATE_FILE_PATH);
66+
mockClient.when(request().withMethod("GET").withPath("/download/rulesTemplate"))
67+
.respond(response().withStatusCode(200).withBody(mockedResponse));
5068

51-
// On windows this may require more then one try due to timing issues.
52-
int i = 0;
53-
while (!downloadedRulesTemplate.equals(mockedResponse) && i <= 5) {
54-
i++;
55-
testRulesPage.clickDownloadRulesTemplate(mockedResponse);
56-
new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADED_RULES_TEMPLATE_FILE_PATH)));
57-
downloadedRulesTemplate = getJSONStringFromFile(DOWNLOADED_RULES_TEMPLATE_FILE_PATH);
58-
}
69+
testRulesPage.clickDownloadRulesTemplate();
70+
new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADED_RULES_TEMPLATE_FILE_PATH)));
71+
downloadedRulesTemplate = getJSONStringFromFile(DOWNLOADED_RULES_TEMPLATE_FILE_PATH);
5972

6073
assertEquals(mockedResponse, downloadedRulesTemplate);
6174

@@ -65,6 +78,8 @@ public void testJourneyToFindAggregatedObjectButton() throws Exception {
6578
assertEquals(true, downloadedRulesTemplate.contains(firstRule));
6679

6780
// Verify that it is possible to download rules
81+
mockClient.when(request().withMethod("GET").withPath("/download/rules"))
82+
.respond(response().withStatusCode(200).withBody(downloadedRulesTemplate));
6883
testRulesPage.clickDownloadRulesButton();
6984
new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADED_RULES_FILE_PATH)));
7085
String downloadedRules = getJSONStringFromFile(DOWNLOADED_RULES_FILE_PATH);
@@ -79,7 +94,10 @@ public void testJourneyToFindAggregatedObjectButton() throws Exception {
7994

8095
// Verify that "download events template" button works
8196
String downloadEventsTemplateMockedResponse = getJSONStringFromFile(EVENTS_TEMPLATE_FILE_PATH);
82-
testRulesPage.clickDownloadEventsTemplate(downloadEventsTemplateMockedResponse);
97+
mockClient.when(request().withMethod("GET").withPath("/download/eventsTemplate"))
98+
.respond(response().withStatusCode(200).withBody(downloadEventsTemplateMockedResponse));
99+
100+
testRulesPage.clickDownloadEventsTemplate();
83101
new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADED_EVENTS_TEMPLATE_FILE_PATH)));
84102
String downloadedEventsTemplate = getJSONStringFromFile(DOWNLOADED_EVENTS_TEMPLATE_FILE_PATH);
85103
assertEquals(downloadEventsTemplateMockedResponse, downloadedEventsTemplate);
@@ -98,7 +116,23 @@ public void testJourneyToFindAggregatedObjectButton() throws Exception {
98116

99117
// Verify that find aggregated object button works
100118
String findAggregatedObjectResponse = getJSONStringFromFile(AGGREGATED_OBJECT_FILE_PATH);
101-
testRulesPage.clickFindAggregatedObject(findAggregatedObjectResponse);
119+
mockClient.when(request().withMethod("POST").withPath("/rules/rule-check/aggregation"))
120+
.respond(response().withStatusCode(200).withBody(findAggregatedObjectResponse));
121+
122+
testRulesPage.clickFindAggregatedObject();
102123
assertEquals(findAggregatedObjectResponse, testRulesPage.getAggregatedResultData());
103124
}
125+
126+
@BeforeClass
127+
public static void setUpMocks() throws IOException {
128+
mockServer = startClientAndServer();
129+
mockClient = new MockServerClient(BASE_URL, mockServer.getLocalPort());
130+
}
131+
132+
@AfterClass
133+
public static void tearDownMocks() throws IOException {
134+
mockClient.stop();
135+
mockServer.stop();
136+
}
137+
104138
}

0 commit comments

Comments
 (0)