parent
fc0ed8fe3d
commit
01406f1c8b
@ -1,22 +1,21 @@
|
|||||||
package com.baeldung;
|
package com.baeldung;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class BaeldungController {
|
public class BaeldungController {
|
||||||
|
|
||||||
@RequestMapping(method = { RequestMethod.GET }, value = { "/hello" })
|
@GetMapping("/hello")
|
||||||
public String sayHello(HttpServletResponse response) {
|
public String sayHello(HttpServletResponse response) {
|
||||||
return "hello";
|
return "hello";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = { RequestMethod.POST }, value = { "/baeldung" })
|
@PostMapping("/baeldung")
|
||||||
public String sayHelloPost(HttpServletResponse response) {
|
public String sayHelloPost(HttpServletResponse response) {
|
||||||
return "hello";
|
return "hello";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,23 +2,16 @@ package com.baeldung;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
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.context.annotation.Bean;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class SpringDemoApplication extends SpringBootServletInitializer {
|
public class SpringDemoApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(SpringDemoApplication.class, args);
|
SpringApplication.run(SpringDemoApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
|
||||||
return application.sources(SpringDemoApplication.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RestTemplate getRestTemplate() {
|
public RestTemplate getRestTemplate() {
|
||||||
return new RestTemplate();
|
return new RestTemplate();
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
server.port=8082
|
@ -6,11 +6,11 @@ import cucumber.api.java.en.When;
|
|||||||
public class OtherDefsIntegrationTest extends SpringIntegrationTest {
|
public class OtherDefsIntegrationTest extends SpringIntegrationTest {
|
||||||
@When("^the client calls /baeldung$")
|
@When("^the client calls /baeldung$")
|
||||||
public void the_client_issues_POST_hello() throws Throwable {
|
public void the_client_issues_POST_hello() throws Throwable {
|
||||||
executePost("http://localhost:8080/baeldung");
|
executePost("http://localhost:8082/baeldung");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Given("^the client calls /hello$")
|
@Given("^the client calls /hello$")
|
||||||
public void the_client_issues_GET_hello() throws Throwable {
|
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();
|
final ResponseResultErrorHandler errorHandler = new ResponseResultErrorHandler();
|
||||||
|
|
||||||
restTemplate.setErrorHandler(errorHandler);
|
restTemplate.setErrorHandler(errorHandler);
|
||||||
latestResponse = restTemplate.execute(url, HttpMethod.GET, requestCallback, new ResponseExtractor<ResponseResults>() {
|
latestResponse = restTemplate.execute(url, HttpMethod.GET, requestCallback, response -> {
|
||||||
@Override
|
if (errorHandler.hadError) {
|
||||||
public ResponseResults extractData(ClientHttpResponse response) throws IOException {
|
return (errorHandler.getResults());
|
||||||
if (errorHandler.hadError) {
|
} else {
|
||||||
return (errorHandler.getResults());
|
return (new ResponseResults(response));
|
||||||
} else {
|
|
||||||
return (new ResponseResults(response));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -56,14 +53,11 @@ public class SpringIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
restTemplate.setErrorHandler(errorHandler);
|
restTemplate.setErrorHandler(errorHandler);
|
||||||
latestResponse = restTemplate.execute(url, HttpMethod.POST, requestCallback, new ResponseExtractor<ResponseResults>() {
|
latestResponse = restTemplate.execute(url, HttpMethod.POST, requestCallback, response -> {
|
||||||
@Override
|
if (errorHandler.hadError) {
|
||||||
public ResponseResults extractData(ClientHttpResponse response) throws IOException {
|
return (errorHandler.getResults());
|
||||||
if (errorHandler.hadError) {
|
} else {
|
||||||
return (errorHandler.getResults());
|
return (new ResponseResults(response));
|
||||||
} else {
|
|
||||||
return (new ResponseResults(response));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ public class StepDefsIntegrationTest extends SpringIntegrationTest {
|
|||||||
|
|
||||||
@When("^the client calls /version$")
|
@When("^the client calls /version$")
|
||||||
public void the_client_issues_GET_version() throws Throwable {
|
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+)$")
|
@Then("^the client receives status code of (\\d+)$")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user