Skip to content

Commit 7497de0

Browse files
authored
replace mockMvc (#153)
1 parent 0bc8825 commit 7497de0

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/functionaltests/java/com/ericsson/ei/subscriptions/repeatHandler/SubscriptionRepeatHandlerSteps.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import com.ericsson.ei.services.ISubscriptionService;
77
import com.ericsson.ei.subscriptionhandler.RunSubscription;
88
import com.ericsson.ei.utils.FunctionalTestBase;
9+
import com.ericsson.ei.utils.HttpRequest;
910
import com.fasterxml.jackson.databind.JsonNode;
1011
import com.fasterxml.jackson.databind.ObjectMapper;
1112
import com.fasterxml.jackson.databind.node.ArrayNode;
12-
1313
import cucumber.api.java.Before;
1414
import cucumber.api.java.en.Given;
1515
import cucumber.api.java.en.Then;
@@ -22,12 +22,9 @@
2222
import org.junit.Ignore;
2323
import org.springframework.beans.factory.annotation.Autowired;
2424
import org.springframework.beans.factory.annotation.Value;
25-
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
25+
import org.springframework.boot.web.server.LocalServerPort;
2626
import org.springframework.http.HttpStatus;
27-
import org.springframework.http.MediaType;
28-
import org.springframework.test.web.servlet.MockMvc;
29-
import org.springframework.test.web.servlet.MvcResult;
30-
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
27+
import org.springframework.http.ResponseEntity;
3128

3229
import java.io.File;
3330
import java.io.IOException;
@@ -39,8 +36,8 @@
3936
import static org.junit.Assert.assertTrue;
4037

4138
@Ignore
42-
@AutoConfigureMockMvc
4339
public class SubscriptionRepeatHandlerSteps extends FunctionalTestBase {
40+
4441
private static final String AGGREGATED_OBJECT_FILE_PATH = "src/functionaltests/resources/aggragatedObject.json";
4542
private static final String EVENTS_FILE_PATH = "src/test/resources/TestExecutionTestEvents.json";
4643
private static final String RULES_FILE_PATH = "src/test/resources/TestExecutionObjectRules.json";
@@ -65,8 +62,8 @@ public class SubscriptionRepeatHandlerSteps extends FunctionalTestBase {
6562
@Value("${subscription.collection.repeatFlagHandlerName}")
6663
private String repeatFlagHandlerCollection;
6764

68-
@Autowired
69-
private MockMvc mockMvc;
65+
@LocalServerPort
66+
private int applicationPort;
7067

7168
@Autowired
7269
private MongoDBHandler mongoDBHandler;
@@ -116,12 +113,15 @@ public void in_MongoDb_RepeatFlagHandler_and_subscription_collections_the_subscr
116113
}
117114

118115
@Then("^I make a DELETE request with subscription name \"([^\"]*)\" to the subscription REST API \"([^\"]*)\"$")
119-
public void i_make_a_DELETE_request_with_subscription_name_to_the_subscription_REST_API(String name,
120-
String subscriptionEndPoint) throws Exception {
121-
MvcResult result = mockMvc
122-
.perform(MockMvcRequestBuilders.delete(subscriptionEndPoint + name).accept(MediaType.APPLICATION_JSON))
123-
.andReturn();
124-
assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus());
116+
public void i_make_a_DELETE_request_with_subscription_name_to_the_subscription_REST_API(String name, String subscriptionEndPoint) throws Exception {
117+
HttpRequest deleteRequest = new HttpRequest(HttpRequest.HttpMethod.DELETE);
118+
ResponseEntity response = deleteRequest.setHost(getHostName())
119+
.setPort(applicationPort)
120+
.setHeaders("content-type", "application/json")
121+
.setHeaders("Accept", "application/json")
122+
.setEndpoint(subscriptionEndPoint + name)
123+
.performRequest();
124+
assertEquals(HttpStatus.OK.value(), response.getStatusCodeValue());
125125
}
126126

127127
@Then("^Check in MongoDB RepeatFlagHandler collection that the subscription has been removed$")
@@ -154,9 +154,8 @@ public List<String> getEventNamesToSend() {
154154

155155
/**
156156
* Process list of documents which gotten from RepeatFlagHandler collection
157-
*
158-
* @param resultRepeatFlagHandler
159-
* list from RepeatFlagHandler collection
157+
*
158+
* @param resultRepeatFlagHandler list from RepeatFlagHandler collection
160159
* @param index
161160
* @return value of aggregatedObjectId
162161
*/
@@ -169,7 +168,7 @@ private String getAggregatedObjectId(List<String> resultRepeatFlagHandler, int i
169168

170169
/**
171170
* Adding subscription to RepeatFlagHandler collection
172-
*
171+
*
173172
* @param subscriptionStrValue
174173
* @param subscriptionObject
175174
* @throws IOException

0 commit comments

Comments
 (0)