Skip to content

Commit e429cc6

Browse files
author
Anders Breid
authored
Fix information endpoint add test for endpoints (#308)
* Add JsonIgnore on classes in RabbitMqHandler * Add test for all endpoints
1 parent 380d3da commit e429cc6

File tree

4 files changed

+178
-3
lines changed

4 files changed

+178
-3
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.ericsson.ei.restendpoints;
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/restEndpoints.feature", glue = {
10+
"com.ericsson.ei.restendpoints" }, plugin = { "pretty",
11+
"html:target/cucumber-reports/RestEndpointsTestRunner" })
12+
public class RestEndpointsTestRunner {
13+
14+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.ericsson.ei.restendpoints;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Ignore;
6+
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
8+
import org.springframework.boot.web.server.LocalServerPort;
9+
import org.springframework.http.ResponseEntity;
10+
import org.springframework.test.context.TestPropertySource;
11+
12+
import com.ericsson.ei.utils.FunctionalTestBase;
13+
import com.ericsson.ei.utils.HttpRequest;
14+
import com.ericsson.ei.utils.HttpRequest.HttpMethod;
15+
import com.ericsson.eiffelcommons.helpers.MediaType;
16+
import com.ericsson.eiffelcommons.subscriptionobject.RestPostSubscriptionObject;
17+
18+
import cucumber.api.java.en.Given;
19+
import cucumber.api.java.en.Then;
20+
import cucumber.api.java.en.When;
21+
22+
@Ignore
23+
@TestPropertySource(properties = {
24+
"spring.data.mongodb.database: RestEndpointsTestSteps",
25+
"missedNotificationDataBaseName: RestEndpointsTestSteps-missedNotifications",
26+
"rabbitmq.exchange.name: RestEndpointsTestSteps-exchange",
27+
"rabbitmq.consumerName: RestEndpointsTestStepsConsumer" })
28+
@AutoConfigureMockMvc
29+
public class RestEndpointsTestSteps extends FunctionalTestBase {
30+
31+
@LocalServerPort
32+
private int applicationPort;
33+
private ResponseEntity response;
34+
35+
@Value("${spring.data.mongodb.database}")
36+
private String eiDatabaseName;
37+
38+
@Value("${aggregated.collection.name}")
39+
private String aggrCollectionName;
40+
41+
@Value("${missedNotificationCollectionName}")
42+
private String missedNotificationCollectionName;
43+
44+
@Value("${missedNotificationDataBaseName}")
45+
private String missedNotificationDatabaseName;
46+
47+
HttpRequest request;
48+
49+
@Given("^A GET request is prepared$")
50+
public void a_GET_request_is_prepared() {
51+
request = new HttpRequest(HttpMethod.GET);
52+
setRequestDefaults();
53+
}
54+
55+
@Given("^A POST request is prepared$")
56+
public void a_POST_request_is_prepared() {
57+
request = new HttpRequest(HttpMethod.POST);
58+
setRequestDefaults();
59+
}
60+
61+
@Given("^A PUT request is prepared$")
62+
public void a_PUT_request_is_prepared() {
63+
request = new HttpRequest(HttpMethod.PUT);
64+
setRequestDefaults();
65+
}
66+
67+
@Given("^A DELETE request is prepared$")
68+
public void a_DELETE_request_is_prepared() {
69+
request = new HttpRequest(HttpMethod.DELETE);
70+
setRequestDefaults();
71+
}
72+
73+
@Given("^\"([^\"]*)\" add subscription with name \"([^\"]*)\" to the request body$")
74+
public void add_subscription_with_name_to_the_request_body(String doAdd, String subscriptionName) throws Throwable {
75+
if (doAdd.equals("do not")) {
76+
return;
77+
}
78+
RestPostSubscriptionObject restPostSubscription = new RestPostSubscriptionObject(subscriptionName);
79+
restPostSubscription.setNotificationMeta("some_url")
80+
.setAuthenticationType("NO_AUTH")
81+
.setRestPostBodyMediaType(MediaType.APPLICATION_FORM_URLENCODED);
82+
request.setBody(restPostSubscription.getAsSubscriptions().toString());
83+
}
84+
85+
@Given("^Event rule json data is added as body$")
86+
public void event_rule_json_data_is_added_as_body() {
87+
String body = "{\"event\":{}, \"rule\":{}}";
88+
request.setBody(body);
89+
}
90+
91+
@When("^Perform request on endpoint \"([^\"]*)\"$")
92+
public void perform_request_on_endpoint(String endpoint) throws Throwable {
93+
response = request.setEndpoint(endpoint)
94+
.performRequest();
95+
}
96+
97+
@Then("^Request should get response code (\\d+)$")
98+
public void request_should_get_response_code(int expectedStatusCode) throws Throwable {
99+
int actualStatusCode = response.getStatusCodeValue();
100+
assertEquals("EI rest API status code: ", expectedStatusCode, actualStatusCode);
101+
response = null;
102+
}
103+
104+
private void setRequestDefaults() {
105+
request.setHost(getHostName())
106+
.setPort(applicationPort)
107+
.addHeader("content-type", "application/json")
108+
.addHeader("Accept", "application/json");
109+
}
110+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@RestEndpoints
2+
Feature: Test Rest Endpoints
3+
4+
# Note: /query is not tested since it has its own test.
5+
# /rules/rule-check/aggregation is not tested since it performs an agregation.
6+
7+
Scenario Outline: Perform GET request on <endpoint> and expect response code <responsecode>
8+
Given A GET request is prepared
9+
When Perform request on endpoint "<endpoint>"
10+
Then Request should get response code <responsecode>
11+
12+
# Note: 404 responses are when no data in database was found,
13+
# since this scenario is not about fetching data.
14+
Examples:
15+
| responsecode | endpoint |
16+
| 200 | /information |
17+
| 200 | /auth |
18+
| 200 | /auth/login |
19+
| 200 | /auth/checkStatus |
20+
| 200 | /download |
21+
| 200 | /download/eventsTemplate |
22+
| 200 | /download/rulesTemplate |
23+
| 200 | /download/subscriptionsTemplate |
24+
| 404 | /queryMissedNotifications/subs_name |
25+
| 404 | /queryAggregatedObject/id |
26+
| 200 | /rules |
27+
| 200 | /rules/rule-check/testRulePageEnabled |
28+
29+
@Test_Post_Put_Get_Delete_and_Get_(not_found)_subscription
30+
Scenario Outline: Perform <type> request on <endpoint> and expect response code <responsecode>
31+
Given A <type> request is prepared
32+
Given "<add_sub>" add subscription with name "test_subscription" to the request body
33+
When Perform request on endpoint "<endpoint>"
34+
Then Request should get response code <responsecode>
35+
36+
Examples:
37+
| responsecode | type | add_sub | endpoint |
38+
| 200 | POST | do | /subscriptions |
39+
| 200 | PUT | do | /subscriptions |
40+
| 200 | GET | do not | /subscriptions/test_subscription |
41+
| 200 | DELETE | do not | /subscriptions/test_subscription |
42+
| 404 | GET | do not | /subscriptions/test_subscription |
43+
44+
Scenario: Test POST on /rules/rule-check endpoint
45+
Given A POST request is prepared
46+
And Event rule json data is added as body
47+
When Perform request on endpoint "/rules/rule-check"
48+
Then Request should get response code 200
49+

src/main/java/com/ericsson/ei/handlers/RmqHandler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ public class RmqHandler {
6969
@Value("${rabbitmq.tlsVersion}")
7070
private String tlsVersion;
7171

72-
@JsonIgnore
7372
@Getter
7473
@Setter
74+
@JsonIgnore
7575
@Value("${rabbitmq.user}")
7676
private String user;
7777

78-
@JsonIgnore
7978
@Getter
8079
@Setter
80+
@JsonIgnore
8181
@Value("${rabbitmq.password}")
8282
private String password;
8383

@@ -110,11 +110,13 @@ public class RmqHandler {
110110
private int maxThreads;
111111

112112
@Setter
113+
@JsonIgnore
113114
private RabbitTemplate rabbitTemplate;
114115
@Getter
116+
@JsonIgnore
115117
private CachingConnectionFactory cachingConnectionFactory;
116-
117118
@Getter
119+
@JsonIgnore
118120
private SimpleMessageListenerContainer container;
119121

120122
@Bean

0 commit comments

Comments
 (0)