Skip to content

Commit 2e49a52

Browse files
Rename /download endpoint to /templates (#264)
Rename endpoint /download to /templates. Updated documentation and tests.
1 parent 68c0605 commit 2e49a52

File tree

20 files changed

+141
-307
lines changed

20 files changed

+141
-307
lines changed

src/functionaltest/java/com/ericsson/ei/config/Utils.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public static Properties getProperties(final String filePath) {
4242
/**
4343
* Extracts a BZip2 archive to a destination folder.
4444
*
45-
* @param firefoxTarballFilePath
45+
* @param firefoxBZip2FilePath
4646
* string containing the firefox BZip2 filepath.
47-
* @param destination
47+
* @param destinationPath
4848
* string containing a destination path.
4949
*/
5050
public static void extractBZip2InDir(final String firefoxBZip2FilePath, String destinationPath) {
@@ -73,20 +73,20 @@ public static void extractBZip2InDir(final String firefoxBZip2FilePath, String d
7373
}
7474

7575
/**
76-
* Downloads a file from a given URL to a given destination path.
76+
* Downloads a file from a given URL to a given destinationPath path.
7777
*
7878
* @param url
7979
* string containing a URL.
80-
* @param destination
81-
* string containing a destination path.
80+
* @param destinationPath
81+
* string containing a destinationPath path.
8282
*/
83-
public static void downloadFileFromUrlToDestination(final String url, final String destination) {
84-
final File file = new File(destination);
83+
public static void downloadFileFromUrlToDestination(final String url, final String destinationPath) {
84+
final File file = new File(destinationPath);
8585
URL urlObj = null;
8686

8787
try {
8888
urlObj = new URL(url);
89-
LOGGER.debug("Downloading file.\nSource: {}\nDestination: {}", url, destination);
89+
LOGGER.debug("Downloading file.\nSource: {}\nDestination: {}", url, destinationPath);
9090
FileUtils.copyURLToFile(urlObj, file);
9191
} catch (MalformedURLException e) {
9292
LOGGER.error("Failed to create URL object.\nURL: {}\nError: {}", url, e.getMessage());

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public class TestRulesFunctionality extends SeleniumBaseClass {
3131
private static final String BASE_URL = "localhost";
3232

3333
private static final String DOWNLOADED_RULES_TEMPLATE_FILE_PATH = String.join(File.separator, SeleniumConfig.getTempDownloadDirectory().getPath(),
34-
"rulesTemplate.json");
34+
"rules.json");
3535
private static final String RULES_TEMPLATE_FILE_PATH = String.join(File.separator, "src", "functionaltest", "resources", "responses",
3636
"RulesTemplateObject.json");
3737
private static final String DOWNLOADED_RULES_FILE_PATH = String.join(File.separator, SeleniumConfig.getTempDownloadDirectory().getPath(),
3838
"rules.json");
3939
private static final String DOWNLOADED_EVENTS_TEMPLATE_FILE_PATH = String.join(File.separator,
40-
SeleniumConfig.getTempDownloadDirectory().getPath(), "eventsTemplate.json");
40+
SeleniumConfig.getTempDownloadDirectory().getPath(), "events.json");
4141
private static final String EVENTS_TEMPLATE_FILE_PATH = String.join(File.separator, "src", "functionaltest", "resources", "responses",
4242
"EventsTemplateObject.json");
4343
private static final String AGGREGATED_OBJECT_FILE_PATH = String.join(File.separator, "src", "functionaltest", "resources", "responses",
@@ -108,7 +108,7 @@ private void verifyUploadEventsFile() {
108108

109109
private void verifyDownloadEventsTemplateButton() throws IOException {
110110
String downloadEventsTemplateMockedResponse = getJSONStringFromFile(EVENTS_TEMPLATE_FILE_PATH);
111-
mockClient.when(request().withMethod("GET").withPath("/download/eventsTemplate"))
111+
mockClient.when(request().withMethod("GET").withPath("/templates/events"))
112112
.respond(response().withStatusCode(200).withBody(downloadEventsTemplateMockedResponse));
113113

114114
testRulesPage.clickDownloadEventsTemplate();
@@ -124,7 +124,7 @@ private void verifyAddAndRemoveRuleButton() {
124124
}
125125

126126
private void verifyDownloadRulesButton() throws IOException {
127-
mockClient.when(request().withMethod("GET").withPath("/download/rules"))
127+
mockClient.when(request().withMethod("GET").withPath("/templates/rules"))
128128
.respond(response().withStatusCode(200).withBody(downloadedRulesTemplate));
129129
testRulesPage.clickDownloadRulesButton();
130130
new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADED_RULES_FILE_PATH)));
@@ -140,7 +140,7 @@ private void verifyUploadRulesFile() {
140140

141141
private void verifyDownloadRulesTemplateButton() throws IOException {
142142
String mockedResponse = getJSONStringFromFile(RULES_TEMPLATE_FILE_PATH);
143-
mockClient.when(request().withMethod("GET").withPath("/download/rulesTemplate"))
143+
mockClient.when(request().withMethod("GET").withPath("/templates/rules"))
144144
.respond(response().withStatusCode(200).withBody(mockedResponse));
145145
testRulesPage.clickDownloadRulesTemplate();
146146
new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADED_RULES_TEMPLATE_FILE_PATH)));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ private void setupMockEndpoints(boolean security, String user) throws IOExceptio
342342
"Subscription1,Subscription2,Subscription3"))
343343
.respond(response().withStatusCode(200).withBody(""));
344344
clientAndServer.when(
345-
request().withMethod("GET").withPath("/download/subscriptionsTemplate"))
345+
request().withMethod("GET").withPath("/templates/subscriptions"))
346346
.respond(response().withStatusCode(200).withBody(mockedTemplateResponse));
347347

348348
String responseAuth = "{\"security\":" + security + "}";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void request_sent_using_list(int index) throws Throwable {
159159
response = httpRequestList.get(index).performRequest();
160160
}
161161

162-
@When("^request is sent for (\\d+) seconds until reponse code no longer matches (\\d+)$")
162+
@When("^request is sent for (\\d+) seconds until response code no longer matches (\\d+)$")
163163
public void request_sent_body_not_received(int seconds, int statusCode) throws Throwable {
164164
long stopTime = System.currentTimeMillis() + (seconds * 1000);
165165
do {

src/integrationtest/java/com/ericsson/ei/frontend/DownloadRunnerIT.java renamed to src/integrationtest/java/com/ericsson/ei/frontend/TemplatesRunnerIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import cucumber.api.junit.Cucumber;
77

88
@RunWith(Cucumber.class)
9-
@CucumberOptions(features = "src/integrationtest/resources/features/download.feature", glue = {
9+
@CucumberOptions(features = "src/integrationtest/resources/features/templates.feature", glue = {
1010
"com.ericsson.ei.frontend" }, plugin = {
11-
"html:target/cucumber-reports/DownloadRunnerIT" })
12-
public class DownloadRunnerIT {
11+
"html:target/cucumber-reports/TemplatesRunnerIT" })
12+
public class TemplatesRunnerIT {
1313

1414
}

src/integrationtest/resources/features/query.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Feature: Query test
1616
And an aggregated object is created
1717
When a 'GET' request is prepared for REST API '/queryAggregatedObject'
1818
And param key 'ID' with value '6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43' is added
19-
And request is sent for 30 seconds until reponse code no longer matches 204
19+
And request is sent for 30 seconds until response code no longer matches 204
2020
And response body contains '6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43'
2121

2222
@QueryFreestyleScenario
@@ -25,5 +25,5 @@ Feature: Query test
2525
And an aggregated object is created
2626
When a 'POST' request is prepared for REST API '/query'
2727
And body is set to file 'queryFreestyle.json'
28-
And request is sent for 30 seconds until reponse code no longer matches 204
28+
And request is sent for 30 seconds until response code no longer matches 204
2929
And response body contains '6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43'
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
@DownloadFeature
2-
Feature: Download test
1+
@TemplatesFeature
2+
Feature: Test get templates
33

44
@GetSubscriptionsTemplateScenario
55
Scenario: Get subscriptions template
66
Given frontend is up and running
7-
When a 'GET' request is prepared for REST API '/download/subscriptionsTemplate'
7+
When a 'GET' request is prepared for REST API '/templates/subscriptions'
88
And request is sent
99
Then response code 200 is received
1010
And response body contains 'Subscription1'
1111

1212
@GetRulesTemplateScenario
1313
Scenario: Get rules template
1414
Given frontend is up and running
15-
When a 'GET' request is prepared for REST API '/download/rulesTemplate'
15+
When a 'GET' request is prepared for REST API '/templates/rules'
1616
And request is sent
1717
Then response code 200 is received
1818
And response body contains 'ARTIFACT_TEST'
1919

2020
@GetEventsTemplateScenario
2121
Scenario: Get events template
2222
Given frontend is up and running
23-
When a 'GET' request is prepared for REST API '/download/eventsTemplate'
23+
When a 'GET' request is prepared for REST API '/templates/events'
2424
And request is sent
2525
Then response code 200 is received
2626
And response body contains 'EiffelArtifactCreatedEvent'

src/main/java/com/ericsson/ei/frontend/EIRequestsController.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,24 @@ public class EIRequestsController {
6262
private EIRequestsControllerUtils eiRequestsControllerUtils;
6363

6464
/**
65-
* Bridge all EI Http Requests with GET method. Used for fetching Subscription by id or all subscriptions and EI Env
66-
* Info.
65+
* Bridge all Eiffel Intelligence HTTP GET requests.
6766
*
6867
* @param model
69-
* @param request
68+
* @param incomingRequest
7069
* @return
7170
*/
7271
@CrossOrigin
73-
@RequestMapping(value = { "/subscriptions", "/subscriptions/*", "/information", "/download/*", "/auth", "/auth/*",
72+
@RequestMapping(value = { "/subscriptions", "/subscriptions/*",
73+
"/information", "/templates/*", "/auth", "/auth/*",
7474
"/queryAggregatedObject", "/failed-notifications", "/query", "/rules", "/status",
7575
"/rules/rule-check/testRulePageEnabled" }, method = RequestMethod.GET)
7676
public ResponseEntity<String> getRequests(Model model, HttpServletRequest incomingRequest) {
7777
String eiRequestUrl;
7878
try {
7979
eiRequestUrl = eiRequestsControllerUtils.getEIRequestURL(incomingRequest);
8080
} catch (EiBackendInstancesException e) {
81-
LOG.info("Some failure when forwarding request to EI Backend. Error: " + e.getMessage());
81+
LOG.error("Some failure when forwarding request to EI Backend. "
82+
+ "Error: " + e.getMessage());
8283
String response = "{\"message\": \"Internal Error: " + e.getMessage() + "\"}";
8384
return new ResponseEntity<>(response, null, HttpStatus.INTERNAL_SERVER_ERROR);
8485
}
@@ -90,7 +91,7 @@ public ResponseEntity<String> getRequests(Model model, HttpServletRequest incomi
9091
}
9192

9293
/**
93-
* Bridge all EI Http Requests with POST method.
94+
* Bridge all Eiffel Intelligence HTTP POST requests.
9495
*
9596
* @param model
9697
* @param incomingRequest
@@ -104,7 +105,8 @@ public ResponseEntity<String> postRequests(Model model, HttpServletRequest incom
104105
try {
105106
eiRequestUrl = eiRequestsControllerUtils.getEIRequestURL(incomingRequest);
106107
} catch (EiBackendInstancesException e) {
107-
LOG.info("Some failure when forwarding request to EI Backend. Error: " + e.getMessage());
108+
LOG.error("Some failure when forwarding request to EI Backend. "
109+
+ "Error: " + e.getMessage());
108110
String response = "{\"message\": \"Internal Error: " + e.getMessage() + "\"}";
109111
return new ResponseEntity<>(response, null, HttpStatus.INTERNAL_SERVER_ERROR);
110112
}
@@ -121,7 +123,7 @@ public ResponseEntity<String> postRequests(Model model, HttpServletRequest incom
121123
LOG.error("Forward Request Errors: " + e);
122124
}
123125

124-
LOG.debug("Input Request JSON Content to be forwarded:\n" + requestBody);
126+
LOG.debug("Input request JSON content to be forwarded:\n" + requestBody);
125127

126128
HttpEntity inputReqJsonEntity = new ByteArrayEntity(requestBody.getBytes());
127129

@@ -135,7 +137,8 @@ public ResponseEntity<String> postRequests(Model model, HttpServletRequest incom
135137
}
136138

137139
/**
138-
* Bridge all EI Http Requests with PUT method. E.g. Making Update Subscription Request.
140+
* Bridge all Eiffel Intelligence HTTP PUT requests. For example updating
141+
* an existing subscription.
139142
*
140143
* @param model
141144
* @param incomingRequest
@@ -148,7 +151,8 @@ public ResponseEntity<String> putRequests(Model model, HttpServletRequest incomi
148151
try {
149152
eiRequestUrl = eiRequestsControllerUtils.getEIRequestURL(incomingRequest);
150153
} catch (EiBackendInstancesException e) {
151-
LOG.info("Some failure when forwarding request to EI Backend. Error: " + e.getMessage());
154+
LOG.error("Some failure when forwarding request to EI Backend. "
155+
+ "Error: " + e.getMessage());
152156
String response = "{\"message\": \"Internal Error: " + e.getMessage() + "\"}";
153157
return new ResponseEntity<>(response, null, HttpStatus.INTERNAL_SERVER_ERROR);
154158
}
@@ -163,7 +167,7 @@ public ResponseEntity<String> putRequests(Model model, HttpServletRequest incomi
163167
LOG.error("Forward Request Errors: " + e);
164168
}
165169

166-
LOG.debug("Input Request JSON Content to be forwarded:\n" + requestBody);
170+
LOG.debug("Input request JSON content to be forwarded:\n" + requestBody);
167171

168172
HttpEntity inputReqJsonEntity = new ByteArrayEntity(requestBody.getBytes());
169173

@@ -177,7 +181,8 @@ public ResponseEntity<String> putRequests(Model model, HttpServletRequest incomi
177181
}
178182

179183
/**
180-
* Bridge all EI Http Requests with DELETE method. Used for DELETE subscriptions.
184+
* Bridge all Eiffel Intelligence HTTP DELETE requests. For example to
185+
* delete a subscription.
181186
*
182187
* @param model
183188
* @param incomingRequest
@@ -190,7 +195,8 @@ public ResponseEntity<String> deleteRequests(Model model, HttpServletRequest inc
190195
try {
191196
eiRequestUrl = eiRequestsControllerUtils.getEIRequestURL(incomingRequest);
192197
} catch (EiBackendInstancesException e) {
193-
LOG.info("Some failure when forwarding request to EI Backend. Error: " + e.getMessage());
198+
LOG.error("Some failure when forwarding request to EI Backend. "
199+
+ "Error: " + e.getMessage());
194200
String response = "{\"message\": \"Internal Error: " + e.getMessage() + "\"}";
195201
return new ResponseEntity<>(response, null, HttpStatus.INTERNAL_SERVER_ERROR);
196202
}
@@ -234,7 +240,7 @@ private ResponseEntity<String> executeHttpRequest(HttpRequestBase outgoingReques
234240
statusCode = HttpStatus.INTERNAL_SERVER_ERROR.value();
235241
responseBody = "{\"statusCode\": " + statusCode + ", \"error\": \"Forward Request Error: "
236242
+ String.valueOf(e) + "\"}";
237-
LOG.error("Forward Request Errors: " + e);
243+
LOG.error("Forward request errors: " + e);
238244
}
239245

240246
headers.setContentType(MediaType.APPLICATION_JSON);
@@ -243,8 +249,8 @@ private ResponseEntity<String> executeHttpRequest(HttpRequestBase outgoingReques
243249
}
244250

245251
/**
246-
* This function copies headers from the made request and puts it into the response. It also extracts any
247-
* x-path-tokens if found.
252+
* This function copies headers from the made request and puts it into the response. It also
253+
* extracts any x-path-tokens if found.
248254
*
249255
* @param headers
250256
* @param eiResponse
@@ -284,7 +290,7 @@ private HttpHeaders getHeadersFromResponse(HttpHeaders headers, CloseableHttpRes
284290
}
285291

286292
/**
287-
* This function copies headers from the incomming request into the outgoing request headers.
293+
* This function copies headers from the incoming request into the outgoing request headers.
288294
*
289295
* @param outgoingRequest
290296
* @param incomingRequest
@@ -316,8 +322,8 @@ private HttpRequestBase addHeadersToRequest(HttpRequestBase outgoingRequest, Htt
316322
}
317323

318324
/**
319-
* This function adds an x-path-token to an outgoing request if it exists for the back-end the request is made
320-
* towards.
325+
* This function adds an x-path-token to an outgoing request if it exists, for the back-end the
326+
* request is made towards.
321327
*
322328
* @param outgoingRequest
323329
* @param incomingRequest
@@ -348,7 +354,8 @@ private HttpRequestBase addXauthTokenToRequest(HttpRequestBase outgoingRequest,
348354
}
349355

350356
/**
351-
* builds an xPathTokenKey, the token will be unique key for each http(s) host and port and stored for each session.
357+
* builds an xPathTokenKey, the token will be unique key for each http(s) host and port and
358+
* stored for each session.
352359
*
353360
* @param uri
354361
* @return

src/main/java/com/ericsson/ei/frontend/utils/BackendInstancesHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public BackendInstance getDefaultBackendInstance() {
111111
/**
112112
* Sets the backendInstances list, useful when mocking for tests
113113
*
114-
* @param backendInstances
114+
* @param backendInstancesJsonArray
115115
*/
116116
public void setBackendInstances(JsonArray backendInstancesJsonArray) {
117117
cleanBackendInstances();

src/main/resources/static/js/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function addBackendParameter(url) {
1212

1313
var delimiter = "?";
1414
if (stringContainsSubstring(url, delimiter)) {
15-
// url has delimeter ?, then delimeter should be &
15+
// url has delimiter ?, then delimiter should be &
1616
delimiter = "&";
1717
}
1818

0 commit comments

Comments
 (0)