Cucumber fix (#2765)
* Rest-assured fix * Cucumber fix * HystrixManualTest * Reformat HystrixTimeoutManualTest
This commit is contained in:
parent
aed9c8bfa8
commit
8616b07506
|
@ -2,7 +2,6 @@
|
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>hystrix</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>hystrix</name>
|
||||
|
|
|
@ -10,10 +10,10 @@ import org.junit.Test;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class HystrixTimeoutIntegrationTest {
|
||||
public class HystrixTimeoutManualTest {
|
||||
|
||||
@Test
|
||||
public void givenInputBobAndDefaultSettings_whenCommandExecuted_thenReturnHelloBob(){
|
||||
public void givenInputBobAndDefaultSettings_whenCommandExecuted_thenReturnHelloBob() {
|
||||
assertThat(new CommandHelloWorld("Bob").execute(), equalTo("Hello Bob!"));
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package com.baeldung;
|
||||
|
||||
import cucumber.api.java.en.Given;
|
||||
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:8082/baeldung");
|
||||
}
|
||||
|
||||
@Given("^the client calls /hello$")
|
||||
public void the_client_issues_GET_hello() throws Throwable {
|
||||
executeGet("http://localhost:8082/hello");
|
||||
}
|
||||
}
|
|
@ -11,23 +11,19 @@ public class ResponseResults {
|
|||
private final ClientHttpResponse theResponse;
|
||||
private final String body;
|
||||
|
||||
protected ResponseResults(final ClientHttpResponse response) throws IOException {
|
||||
ResponseResults(final ClientHttpResponse response) throws IOException {
|
||||
this.theResponse = response;
|
||||
final InputStream bodyInputStream = response.getBody();
|
||||
if (null == bodyInputStream) {
|
||||
this.body = "{}";
|
||||
} else {
|
||||
final StringWriter stringWriter = new StringWriter();
|
||||
IOUtils.copy(bodyInputStream, stringWriter);
|
||||
this.body = stringWriter.toString();
|
||||
}
|
||||
}
|
||||
|
||||
protected ClientHttpResponse getTheResponse() {
|
||||
ClientHttpResponse getTheResponse() {
|
||||
return theResponse;
|
||||
}
|
||||
|
||||
protected String getBody() {
|
||||
String getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,5 @@
|
|||
package com.baeldung;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationContextLoader;
|
||||
|
@ -12,20 +8,23 @@ import org.springframework.http.client.ClientHttpResponse;
|
|||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.client.ResponseErrorHandler;
|
||||
import org.springframework.web.client.ResponseExtractor;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
//@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = SpringDemoApplication.class, loader = SpringApplicationContextLoader.class)
|
||||
@WebAppConfiguration
|
||||
@IntegrationTest
|
||||
public class SpringIntegrationTest {
|
||||
protected static ResponseResults latestResponse = null;
|
||||
static ResponseResults latestResponse = null;
|
||||
|
||||
@Autowired
|
||||
protected RestTemplate restTemplate;
|
||||
|
||||
protected void executeGet(String url) throws IOException {
|
||||
void executeGet(String url) throws IOException {
|
||||
final Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Accept", "application/json");
|
||||
final HeaderSettingRequestCallback requestCallback = new HeaderSettingRequestCallback(headers);
|
||||
|
@ -39,10 +38,9 @@ public class SpringIntegrationTest {
|
|||
return (new ResponseResults(response));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void executePost(String url) throws IOException {
|
||||
void executePost() throws IOException {
|
||||
final Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Accept", "application/json");
|
||||
final HeaderSettingRequestCallback requestCallback = new HeaderSettingRequestCallback(headers);
|
||||
|
@ -53,14 +51,14 @@ public class SpringIntegrationTest {
|
|||
}
|
||||
|
||||
restTemplate.setErrorHandler(errorHandler);
|
||||
latestResponse = restTemplate.execute(url, HttpMethod.POST, requestCallback, response -> {
|
||||
latestResponse = restTemplate
|
||||
.execute("http://localhost:8082/baeldung", HttpMethod.POST, requestCallback, response -> {
|
||||
if (errorHandler.hadError) {
|
||||
return (errorHandler.getResults());
|
||||
} else {
|
||||
return (new ResponseResults(response));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private class ResponseResultErrorHandler implements ResponseErrorHandler {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.baeldung;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import cucumber.api.java.en.Given;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import cucumber.api.java.en.And;
|
||||
|
@ -11,6 +12,16 @@ import cucumber.api.java.en.When;
|
|||
|
||||
public class StepDefsIntegrationTest extends SpringIntegrationTest {
|
||||
|
||||
@When("^the client calls /baeldung$")
|
||||
public void the_client_issues_POST_hello() throws Throwable {
|
||||
executePost();
|
||||
}
|
||||
|
||||
@Given("^the client calls /hello$")
|
||||
public void the_client_issues_GET_hello() throws Throwable {
|
||||
executeGet("http://localhost:8082/hello");
|
||||
}
|
||||
|
||||
@When("^the client calls /version$")
|
||||
public void the_client_issues_GET_version() throws Throwable {
|
||||
executeGet("http://localhost:8082/version");
|
||||
|
|
Loading…
Reference in New Issue