Skip to content

Commit 01406f1

Browse files
authored
Cucumber fix (eugenp#2761)
* Rest-assured fix * Cucumber fix
1 parent fc0ed8f commit 01406f1

6 files changed

Lines changed: 21 additions & 34 deletions

File tree

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
package com.baeldung;
22

3-
import javax.servlet.http.HttpServletResponse;
4-
5-
import org.springframework.web.bind.annotation.RequestMapping;
6-
import org.springframework.web.bind.annotation.RequestMethod;
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.PostMapping;
75
import org.springframework.web.bind.annotation.RestController;
86

7+
import javax.servlet.http.HttpServletResponse;
8+
99
@RestController
1010
public class BaeldungController {
1111

12-
@RequestMapping(method = { RequestMethod.GET }, value = { "/hello" })
12+
@GetMapping("/hello")
1313
public String sayHello(HttpServletResponse response) {
1414
return "hello";
1515
}
1616

17-
@RequestMapping(method = { RequestMethod.POST }, value = { "/baeldung" })
17+
@PostMapping("/baeldung")
1818
public String sayHelloPost(HttpServletResponse response) {
1919
return "hello";
2020
}
21-
2221
}

‎spring-cucumber/src/main/java/com/baeldung/SpringDemoApplication.java‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5-
import org.springframework.boot.builder.SpringApplicationBuilder;
6-
import org.springframework.boot.context.web.SpringBootServletInitializer;
75
import org.springframework.context.annotation.Bean;
86
import org.springframework.web.client.RestTemplate;
97

108
@SpringBootApplication
11-
public class SpringDemoApplication extends SpringBootServletInitializer {
9+
public class SpringDemoApplication {
1210

1311
public static void main(String[] args) {
1412
SpringApplication.run(SpringDemoApplication.class, args);
1513
}
1614

17-
@Override
18-
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
19-
return application.sources(SpringDemoApplication.class);
20-
}
21-
2215
@Bean
2316
public RestTemplate getRestTemplate() {
2417
return new RestTemplate();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
server.port=8082

‎spring-cucumber/src/test/java/com/baeldung/OtherDefsIntegrationTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
public class OtherDefsIntegrationTest extends SpringIntegrationTest {
77
@When("^the client calls /baeldung$")
88
public void the_client_issues_POST_hello() throws Throwable {
9-
executePost("http://localhost:8080/baeldung");
9+
executePost("http://localhost:8082/baeldung");
1010
}
1111

1212
@Given("^the client calls /hello$")
1313
public void the_client_issues_GET_hello() throws Throwable {
14-
executeGet("http://localhost:8080/hello");
14+
executeGet("http://localhost:8082/hello");
1515
}
1616
}

‎spring-cucumber/src/test/java/com/baeldung/SpringIntegrationTest.java‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,11 @@ protected void executeGet(String url) throws IOException {
3232
final ResponseResultErrorHandler errorHandler = new ResponseResultErrorHandler();
3333

3434
restTemplate.setErrorHandler(errorHandler);
35-
latestResponse = restTemplate.execute(url, HttpMethod.GET, requestCallback, new ResponseExtractor<ResponseResults>() {
36-
@Override
37-
public ResponseResults extractData(ClientHttpResponse response) throws IOException {
38-
if (errorHandler.hadError) {
39-
return (errorHandler.getResults());
40-
} else {
41-
return (new ResponseResults(response));
42-
}
35+
latestResponse = restTemplate.execute(url, HttpMethod.GET, requestCallback, response -> {
36+
if (errorHandler.hadError) {
37+
return (errorHandler.getResults());
38+
} else {
39+
return (new ResponseResults(response));
4340
}
4441
});
4542

@@ -56,14 +53,11 @@ protected void executePost(String url) throws IOException {
5653
}
5754

5855
restTemplate.setErrorHandler(errorHandler);
59-
latestResponse = restTemplate.execute(url, HttpMethod.POST, requestCallback, new ResponseExtractor<ResponseResults>() {
60-
@Override
61-
public ResponseResults extractData(ClientHttpResponse response) throws IOException {
62-
if (errorHandler.hadError) {
63-
return (errorHandler.getResults());
64-
} else {
65-
return (new ResponseResults(response));
66-
}
56+
latestResponse = restTemplate.execute(url, HttpMethod.POST, requestCallback, response -> {
57+
if (errorHandler.hadError) {
58+
return (errorHandler.getResults());
59+
} else {
60+
return (new ResponseResults(response));
6761
}
6862
});
6963

‎spring-cucumber/src/test/java/com/baeldung/StepDefsIntegrationTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class StepDefsIntegrationTest extends SpringIntegrationTest {
1313

1414
@When("^the client calls /version$")
1515
public void the_client_issues_GET_version() throws Throwable {
16-
executeGet("http://localhost:8080/version");
16+
executeGet("http://localhost:8082/version");
1717
}
1818

1919
@Then("^the client receives status code of (\\d+)$")

0 commit comments

Comments
 (0)