parent
fc0ed8fe3d
commit
01406f1c8b
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
server.port=8082
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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+)$")
|
||||
|
|
Loading…
Reference in New Issue