|
| 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 | +} |
0 commit comments