Cucumber fix (#2761)

* Rest-assured fix

* Cucumber fix
This commit is contained in:
Grzegorz Piwowarek 2017-10-19 17:51:31 +02:00 committed by GitHub
parent fc0ed8fe3d
commit 01406f1c8b
6 changed files with 21 additions and 34 deletions

View File

@ -1,22 +1,21 @@
package com.baeldung;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
@RestController
public class BaeldungController {
@RequestMapping(method = { RequestMethod.GET }, value = { "/hello" })
@GetMapping("/hello")
public String sayHello(HttpServletResponse response) {
return "hello";
}
@RequestMapping(method = { RequestMethod.POST }, value = { "/baeldung" })
@PostMapping("/baeldung")
public String sayHelloPost(HttpServletResponse response) {
return "hello";
}
}

View File

@ -2,23 +2,16 @@ package com.baeldung;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class SpringDemoApplication extends SpringBootServletInitializer {
public class SpringDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringDemoApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringDemoApplication.class);
}
@Bean
public RestTemplate getRestTemplate() {
return new RestTemplate();

View File

@ -0,0 +1 @@
server.port=8082

View File

@ -6,11 +6,11 @@ import cucumber.api.java.en.When;
public class OtherDefsIntegrationTest extends SpringIntegrationTest {
@When("^the client calls /baeldung$")
public void the_client_issues_POST_hello() throws Throwable {
executePost("http://localhost:8080/baeldung");
executePost("http://localhost:8082/baeldung");
}
@Given("^the client calls /hello$")
public void the_client_issues_GET_hello() throws Throwable {
executeGet("http://localhost:8080/hello");
executeGet("http://localhost:8082/hello");
}
}

View File

@ -32,14 +32,11 @@ public class SpringIntegrationTest {
final ResponseResultErrorHandler errorHandler = new ResponseResultErrorHandler();
restTemplate.setErrorHandler(errorHandler);
latestResponse = restTemplate.execute(url, HttpMethod.GET, requestCallback, new ResponseExtractor<ResponseResults>() {
@Override
public ResponseResults extractData(ClientHttpResponse response) throws IOException {
if (errorHandler.hadError) {
return (errorHandler.getResults());
} else {
return (new ResponseResults(response));
}
latestResponse = restTemplate.execute(url, HttpMethod.GET, requestCallback, response -> {
if (errorHandler.hadError) {
return (errorHandler.getResults());
} else {
return (new ResponseResults(response));
}
});
@ -56,14 +53,11 @@ public class SpringIntegrationTest {
}
restTemplate.setErrorHandler(errorHandler);
latestResponse = restTemplate.execute(url, HttpMethod.POST, requestCallback, new ResponseExtractor<ResponseResults>() {
@Override
public ResponseResults extractData(ClientHttpResponse response) throws IOException {
if (errorHandler.hadError) {
return (errorHandler.getResults());
} else {
return (new ResponseResults(response));
}
latestResponse = restTemplate.execute(url, HttpMethod.POST, requestCallback, response -> {
if (errorHandler.hadError) {
return (errorHandler.getResults());
} else {
return (new ResponseResults(response));
}
});

View File

@ -13,7 +13,7 @@ public class StepDefsIntegrationTest extends SpringIntegrationTest {
@When("^the client calls /version$")
public void the_client_issues_GET_version() throws Throwable {
executeGet("http://localhost:8080/version");
executeGet("http://localhost:8082/version");
}
@Then("^the client receives status code of (\\d+)$")