Skip to content

Commit c88c201

Browse files
Rename /download endpoint to /templates (#372)
Renamed /download endpoint to /templates. Updated the template file names. Updated documentation.
1 parent ce1943a commit c88c201

File tree

17 files changed

+144
-148
lines changed

17 files changed

+144
-148
lines changed

src/functionaltests/java/com/ericsson/ei/files/DownloadFilesTestRunner.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ericsson.ei.templates;
2+
3+
import org.junit.runner.RunWith;
4+
5+
import cucumber.api.CucumberOptions;
6+
import cucumber.api.junit.Cucumber;
7+
8+
@RunWith(Cucumber.class)
9+
@CucumberOptions(features = "src/functionaltests/resources/features/templates.feature", glue = {
10+
"com.ericsson.ei.templates" }, plugin = { "pretty", "html:target/cucumber-reports/TemplatesTestRunner" })
11+
public class TemplatesTestRunner {
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ericsson.ei.files;
1+
package com.ericsson.ei.templates;
22

33
import static org.junit.Assert.assertEquals;
44

@@ -26,17 +26,17 @@
2626
import cucumber.api.java.en.Then;
2727

2828
@Ignore
29-
@TestPropertySource(properties = { "spring.data.mongodb.database: DownloadFilesTestSteps",
30-
"rabbitmq.exchange.name: DownloadFilesTestSteps-exchange",
31-
"rabbitmq.consumerName: rabbitmq.consumerName: DownloadFilesTestStepsConsumer" })
29+
@TestPropertySource(properties = {"spring.data.mongodb.database: TemplatesTestSteps",
30+
"rabbitmq.exchange.name: TemplatesTestSteps-exchange",
31+
"rabbitmq.consumerName: TemplatesTestStepsConsumer" })
3232
@AutoConfigureMockMvc
33-
public class DownloadFilesTestSteps extends FunctionalTestBase {
33+
public class TemplatesTestSteps extends FunctionalTestBase {
3434

35-
private static final Logger LOGGER = LoggerFactory.getLogger(DownloadFilesTestSteps.class);
35+
private static final Logger LOGGER = LoggerFactory.getLogger(TemplatesTestSteps.class);
3636

37-
private static final String SUBSCRIPTIONS_TEMPLATE_FILEPATH = "src/main/resources/templates/subscriptionsTemplate.json";
38-
private static final String RULES_TEMPLATE_FILEPATH = "src/main/resources/templates/rulesTemplate.json";
39-
private static final String EVENTS_TEMPLATE_FILEPATH = "src/main/resources/templates/eventsTemplate.json";
37+
private static final String SUBSCRIPTIONS_TEMPLATE_FILEPATH = "src/main/resources/templates/subscriptions.json";
38+
private static final String RULES_TEMPLATE_FILEPATH = "src/main/resources/templates/rules.json";
39+
private static final String EVENTS_TEMPLATE_FILEPATH = "src/main/resources/templates/events.json";
4040

4141
private ObjectMapper objMapper = new ObjectMapper();
4242
private HttpRequest httpRequest = new HttpRequest(HttpMethod.GET);
@@ -51,7 +51,7 @@ public void eiffel_intelligence_instance_is_up_and_running() throws Exception {
5151
LOGGER.debug("Checking if Eiffel Intelligence instance is up and running.");
5252
httpRequest.setHost(hostName)
5353
.setPort(applicationPort)
54-
.addHeader("Content-type:", MediaType.APPLICATION_JSON_VALUE.toString())
54+
.addHeader("Content-type:", MediaType.APPLICATION_JSON_VALUE)
5555
.setEndpoint("/subscriptions");
5656

5757
response = httpRequest.performRequest();
@@ -60,66 +60,59 @@ public void eiffel_intelligence_instance_is_up_and_running() throws Exception {
6060

6161
@Then("^List available files$")
6262
public void list_available_files() throws Exception {
63-
LOGGER.debug("Listing all availble files that can be download via RestApi.");
64-
String expectedSubscriptionsValue = "/download/subscriptionsTemplate";
63+
LOGGER.debug("Listing all available template files that can be downloaded via REST API.");
64+
String expectedSubscriptionsValue = "/templates/subscriptions";
6565

66-
httpRequest.setEndpoint("/download");
66+
httpRequest.setEndpoint("/templates");
6767
response = httpRequest.performRequest();
6868

6969
assertEquals(HttpStatus.OK, response.getStatusCode());
7070

7171
String actualSubscriptionsValue = objMapper.readValue(response.getBody(), JsonNode.class).get("subscriptions").asText();
72-
assertEquals("List all files don't return expected subscriptions file value. \nExpected: "
73-
+ expectedSubscriptionsValue + "\nActual: "+ actualSubscriptionsValue,
74-
expectedSubscriptionsValue, actualSubscriptionsValue);
72+
assertEquals("Template endpoints did not return expected subscriptions endpoint.",
73+
expectedSubscriptionsValue, actualSubscriptionsValue);
7574
}
7675

7776
@And("^Get subscription template file$")
7877
public void get_subscription_template_file() throws Exception {
7978
String expectedSubscriptionTemplateContent = FileUtils.readFileToString(
8079
new File(SUBSCRIPTIONS_TEMPLATE_FILEPATH), "UTF-8");
8180

82-
httpRequest.setEndpoint("/download/subscriptionsTemplate");
81+
httpRequest.setEndpoint("/templates/subscriptions");
8382
response = httpRequest.performRequest();
8483

8584
assertEquals(HttpStatus.OK, response.getStatusCode());
8685

8786
String actualSubscriptionTemplateContent = response.getBody();
88-
assertEquals(
89-
"Get SubscriptionTemplate file failed or contents is not as expected. \nExpected: "
90-
+ expectedSubscriptionTemplateContent + "\nActual: " + actualSubscriptionTemplateContent,
91-
expectedSubscriptionTemplateContent, actualSubscriptionTemplateContent);
87+
assertEquals("Failed to get template file for subscriptions. ",
88+
expectedSubscriptionTemplateContent, actualSubscriptionTemplateContent);
9289
}
9390

9491
@And("^Get rules template file$")
9592
public void get_rules_template_file() throws Exception {
9693
String expectedRulesTemplateContent = FileUtils.readFileToString(new File(RULES_TEMPLATE_FILEPATH), "UTF-8");
9794

98-
httpRequest.setEndpoint("/download/rulesTemplate");
95+
httpRequest.setEndpoint("/templates/rules");
9996
response = httpRequest.performRequest();
10097

10198
assertEquals(HttpStatus.OK, response.getStatusCode());
10299

103100
String actualRulesTemplateContent = response.getBody();
104-
assertEquals(
105-
"Get RulesTemplate file failed or contents is not as expected. \nExpected: "
106-
+ expectedRulesTemplateContent + "\nActual: " + actualRulesTemplateContent,
101+
assertEquals("Failed to get template file for rules.",
107102
expectedRulesTemplateContent, actualRulesTemplateContent);
108103
}
109104

110105
@And("^Get event template file$")
111106
public void get_event_template_file() throws Exception {
112107
String expectedEventsTemplateContent = FileUtils.readFileToString(new File(EVENTS_TEMPLATE_FILEPATH), "UTF-8");
113108

114-
httpRequest.setEndpoint("/download/eventsTemplate");
109+
httpRequest.setEndpoint("/templates/events");
115110
response = httpRequest.performRequest();
116111

117112
assertEquals(HttpStatus.OK, response.getStatusCode());
118113

119114
String actualEventsTemplateContent = response.getBody();
120-
assertEquals(
121-
"Get EventsTemplate file failed or contents is not as expected. \nExpected: "
122-
+ expectedEventsTemplateContent + "\nActual: " + actualEventsTemplateContent,
115+
assertEquals("Failed to get template file for events.",
123116
expectedEventsTemplateContent, actualEventsTemplateContent);
124117
}
125118
}

src/functionaltests/resources/features/restEndpoints.feature

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
Feature: Test Rest Endpoints
33

44
# Note: /query is not tested since it has its own test.
5-
# /rules/rule-check/aggregation is not tested since it performs an agregation.
5+
# /rules/rule-check/aggregation is not tested since it performs an aggregation.
66

77
Scenario Outline: Perform GET request on <endpoint> and expect response code <responsecode>
88
Given A GET request is prepared
99
When Perform request on endpoint "<endpoint>"
1010
Then Request should get response code <responsecode>
1111

1212
# Note: 404 responses are when no data in database was found,
13-
# since this scenario is not about fetching data.
14-
Examples:
13+
# since this scenario is not about fetching data.
14+
Examples:
1515
| responsecode | endpoint |
1616
| 200 | /information |
1717
| 200 | /auth |
1818
| 200 | /auth/login |
1919
| 200 | /status |
20-
| 200 | /download |
21-
| 200 | /download/eventsTemplate |
22-
| 200 | /download/rulesTemplate |
23-
| 200 | /download/subscriptionsTemplate |
20+
| 200 | /templates |
21+
| 200 | /templates/events |
22+
| 200 | /templates/rules |
23+
| 200 | /templates/subscriptions |
2424
| 404 | /queryMissedNotifications/subs_name |
2525
| 404 | /queryAggregatedObject/id |
2626
| 200 | /rules |
@@ -33,7 +33,7 @@ Feature: Test Rest Endpoints
3333
When Perform request on endpoint "<endpoint>"
3434
Then Request should get response code <responsecode>
3535

36-
Examples:
36+
Examples:
3737
| responsecode | type | add_sub | endpoint |
3838
| 200 | POST | do | /subscriptions |
3939
| 200 | PUT | do | /subscriptions |
@@ -46,4 +46,3 @@ Feature: Test Rest Endpoints
4646
And Event rule json data is added as body
4747
When Perform request on endpoint "/rules/rule-check"
4848
Then Request should get response code 200
49-

src/functionaltests/resources/features/downloadFiles.feature renamed to src/functionaltests/resources/features/templates.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
@DownloadFiles
2-
Feature: Test Download Files
1+
@Templates
2+
Feature: Test get templates
33

4-
@DownloadFilesScenario
5-
Scenario: Test DownloadFiles Entrypoints
4+
@GetTemplatesScenario
5+
Scenario: Test Template entry-points
66
Given Eiffel Intelligence instance is up and running
77
Then List available files
88
And Get subscription template file

src/main/java/com/ericsson/ei/controller/DownloadController.java renamed to src/main/java/com/ericsson/ei/controller/TemplateController.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,36 @@
1616
*/
1717
@RestController
1818
@Validated
19-
@RequestMapping(value = "/download", produces = "application/json")
20-
public interface DownloadController {
19+
@RequestMapping(value = "/templates", produces = "application/json")
20+
public interface TemplateController {
2121

2222

2323
/**
2424
* This method returns a list of endpoints for downloading templates.
2525
*
2626
*/
2727
@RequestMapping(value = "", method = RequestMethod.GET)
28-
public ResponseEntity<?> getDownload(HttpServletRequest httpRequest);
28+
public ResponseEntity<?> getTemplates(HttpServletRequest httpRequest);
2929

3030
/**
31-
* This method returns a subscription template.
31+
* This method returns subscription templates.
3232
*
3333
*/
34-
@RequestMapping(value = "/subscriptionsTemplate", method = RequestMethod.GET)
35-
public ResponseEntity<?> getDownloadSubscriptionsTemplate(HttpServletRequest httpRequest);
34+
@RequestMapping(value = "/subscriptions", method = RequestMethod.GET)
35+
public ResponseEntity<?> getTemplatesSubscriptions(HttpServletRequest httpRequest);
3636

3737
/**
3838
* This method returns a template for rules.
3939
*
4040
*/
41-
@RequestMapping(value = "/rulesTemplate", method = RequestMethod.GET)
42-
public ResponseEntity<?> getDownloadRulesTemplate(HttpServletRequest httpRequest);
41+
@RequestMapping(value = "/rules", method = RequestMethod.GET)
42+
public ResponseEntity<?> getTemplatesRules(HttpServletRequest httpRequest);
4343

4444
/**
4545
* This method returns a template for Eiffel events.
4646
*
4747
*/
48-
@RequestMapping(value = "/eventsTemplate", method = RequestMethod.GET)
49-
public ResponseEntity<?> getDownloadEventsTemplate(HttpServletRequest httpRequest);
48+
@RequestMapping(value = "/events", method = RequestMethod.GET)
49+
public ResponseEntity<?> getTemplatesEvents(HttpServletRequest httpRequest);
5050

5151
}

src/main/java/com/ericsson/ei/controller/DownloadControllerImpl.java renamed to src/main/java/com/ericsson/ei/controller/TemplateControllerImpl.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,23 @@
3636

3737
@Component
3838
@CrossOrigin
39-
@Api(value = "Download templates", tags = {"Download"})
40-
public class DownloadControllerImpl implements DownloadController {
39+
@Api(value = "Get templates", tags = {"Templates"})
40+
public class TemplateControllerImpl implements TemplateController {
4141

42-
private static final Logger LOGGER = LoggerFactory.getLogger(DownloadControllerImpl.class);
42+
private static final Logger LOGGER = LoggerFactory.getLogger(
43+
TemplateControllerImpl.class);
4344

4445
@Override
4546
@ApiOperation(value = "Retrieve REST endpoints for downloading templates")
46-
public ResponseEntity<?> getDownload(final HttpServletRequest httpRequest) {
47+
public ResponseEntity<?> getTemplates(final HttpServletRequest httpRequest) {
4748
try {
4849
JSONObject response = new JSONObject();
49-
response.put("subscriptions", "/download/subscriptionsTemplate");
50-
response.put("rules", "/download/rulesTemplate");
51-
response.put("events", "/download/eventsTemplate");
50+
response.put("subscriptions", "/templates/subscriptions");
51+
response.put("rules", "/templates/rules");
52+
response.put("events", "/templates/events");
5253
return new ResponseEntity<>(response.toString(), HttpStatus.OK);
5354
} catch (Exception e) {
54-
String errorMessage = "Internal Server Error: Failed to get information about download endpoints.";
55+
String errorMessage = "Failed to get information about template endpoints.";
5556
LOGGER.error(errorMessage, e);
5657
String errorJsonAsString = ResponseMessage.createJsonMessage(errorMessage);
5758
return new ResponseEntity<>(errorJsonAsString, HttpStatus.INTERNAL_SERVER_ERROR);
@@ -60,17 +61,18 @@ public ResponseEntity<?> getDownload(final HttpServletRequest httpRequest) {
6061

6162
@Override
6263
@ApiOperation(value = "Download subscription template")
63-
public ResponseEntity<?> getDownloadSubscriptionsTemplate(final HttpServletRequest httpRequest) {
64+
public ResponseEntity<?> getTemplatesSubscriptions(final HttpServletRequest httpRequest) {
6465
try {
65-
InputStream is = getClass().getResourceAsStream("/templates/subscriptionsTemplate.json");
66+
InputStream is = getClass().getResourceAsStream(
67+
"/templates/subscriptions.json");
6668
if (is == null) {
67-
String errorMessage = "Subscriptions template file is not found.";
69+
String errorMessage = "Subscriptions template file was not found.";
6870
LOGGER.error(errorMessage);
6971
return new ResponseEntity<>(ResponseMessage.createJsonMessage(errorMessage), HttpStatus.NOT_FOUND);
7072
}
7173
return new ResponseEntity<>(IOUtils.toByteArray(is), HttpStatus.OK);
7274
} catch (Exception e) {
73-
String errorMessage = "Internal Server Error: Failed to download subscriptions template file.";
75+
String errorMessage = "Failed to download subscriptions template file.";
7476
LOGGER.error(e.getMessage(), e);
7577
String errorJsonAsString = ResponseMessage.createJsonMessage(errorMessage);
7678
return new ResponseEntity<>(errorJsonAsString, HttpStatus.INTERNAL_SERVER_ERROR);
@@ -79,17 +81,18 @@ public ResponseEntity<?> getDownloadSubscriptionsTemplate(final HttpServletReque
7981

8082
@Override
8183
@ApiOperation(value = "Download rules template")
82-
public ResponseEntity<?> getDownloadRulesTemplate(final HttpServletRequest httpRequest) {
84+
public ResponseEntity<?> getTemplatesRules(final HttpServletRequest httpRequest) {
8385
try {
84-
InputStream is = getClass().getResourceAsStream("/templates/rulesTemplate.json");
86+
InputStream is = getClass().getResourceAsStream(
87+
"/templates/rules.json");
8588
if (is == null) {
86-
String errorMessage = "Rules template file is not found.";
89+
String errorMessage = "Rules template file was not found.";
8790
LOGGER.error(errorMessage);
8891
return new ResponseEntity<>(ResponseMessage.createJsonMessage(errorMessage), HttpStatus.NOT_FOUND);
8992
}
9093
return new ResponseEntity<>(IOUtils.toByteArray(is), HttpStatus.OK);
9194
} catch (Exception e) {
92-
String errorMessage = "Internal Server Error: Failed to download rules template file.";
95+
String errorMessage = "Failed to download rules template file.";
9396
LOGGER.error(errorMessage, e);
9497
String errorJsonAsString = ResponseMessage.createJsonMessage(errorMessage);
9598
return new ResponseEntity<>(errorJsonAsString, HttpStatus.INTERNAL_SERVER_ERROR);
@@ -98,17 +101,18 @@ public ResponseEntity<?> getDownloadRulesTemplate(final HttpServletRequest httpR
98101

99102
@Override
100103
@ApiOperation(value = "Download Eiffel events template")
101-
public ResponseEntity<?> getDownloadEventsTemplate(final HttpServletRequest httpRequest) {
104+
public ResponseEntity<?> getTemplatesEvents(final HttpServletRequest httpRequest) {
102105
try {
103-
InputStream is = getClass().getResourceAsStream("/templates/eventsTemplate.json");
106+
InputStream is = getClass().getResourceAsStream(
107+
"/templates/events.json");
104108
if (is == null) {
105-
String errorMessage = "Events template file is not found.";
109+
String errorMessage = "Eiffel events template file was not found.";
106110
LOGGER.error(errorMessage);
107111
return new ResponseEntity<>(ResponseMessage.createJsonMessage(errorMessage), HttpStatus.NOT_FOUND);
108112
}
109113
return new ResponseEntity<>(IOUtils.toByteArray(is), HttpStatus.OK);
110114
} catch (Exception e) {
111-
String errorMessage = "Internal Server Error: Failed to download events template file.";
115+
String errorMessage = "Failed to download Eiffel events template file.";
112116
LOGGER.error(errorMessage, e);
113117
String errorJsonAsString = ResponseMessage.createJsonMessage(errorMessage);
114118
return new ResponseEntity<>(errorJsonAsString, HttpStatus.INTERNAL_SERVER_ERROR);

src/main/resources/public/raml/eiffel-intelligence.raml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ baseUri: /
3737
/subscriptions: !include resourceTypes/subscription.raml
3838
/query: !include resourceTypes/query.raml
3939
/queryAggregatedObject: !include resourceTypes/query-aggregated_object.raml
40+
/templates: !include resourceTypes/templates.raml
4041
/failed-notifications: !include resourceTypes/failed-notifications.raml
41-
/download: !include resourceTypes/download.raml
4242
/rules: !include resourceTypes/rules.raml
4343
/auth: !include resourceTypes/auth.raml
4444
/status: !include resourceTypes/status.raml

src/main/resources/public/raml/resourceTypes/download.raml renamed to src/main/resources/public/raml/resourceTypes/templates.raml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ get:
66
body:
77
application/string:
88

9-
/subscriptionsTemplate:
9+
/subscriptions:
1010
get:
11-
description: This method returns a subscription template.
11+
description: This method returns subscription templates.
1212
responses:
1313
200:
1414
body:
1515
application/string:
1616

17-
/rulesTemplate:
17+
/rules:
1818
get:
1919
description: This method returns a template for rules.
2020
responses:
2121
200:
2222
body:
2323
application/string:
2424

25-
/eventsTemplate:
25+
/events:
2626
get:
2727
description: This method returns a template for Eiffel events.
2828
responses:

0 commit comments

Comments
 (0)