Browse Source

Add tests to verify old constructors

pull/6/head
Stéphane Lagraulet 8 years ago
parent
commit
b98c9ebc1d
  1. 4
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommandContext.java
  2. 35
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandTests.java

4
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommandContext.java

@ -54,6 +54,10 @@ public class RibbonCommandContext {
private final List<RibbonRequestCustomizer> requestCustomizers; private final List<RibbonRequestCustomizer> requestCustomizers;
private Long contentLength; private Long contentLength;
/**
* Kept for backwards compatibility with Spring Cloud Sleuth 1.x versions
*/
@Deprecated
public RibbonCommandContext(String serviceId, String method, String uri, public RibbonCommandContext(String serviceId, String method, String uri,
Boolean retryable, MultiValueMap<String, String> headers, Boolean retryable, MultiValueMap<String, String> headers,
MultiValueMap<String, String> params, InputStream requestEntity) { MultiValueMap<String, String> params, InputStream requestEntity) {

35
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandTests.java

@ -38,6 +38,7 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import com.netflix.client.http.HttpRequest; import com.netflix.client.http.HttpRequest;
import com.netflix.client.http.HttpRequest.Verb;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
@ -51,6 +52,38 @@ public class RestClientRibbonCommandTests {
zuulProperties = new ZuulProperties(); zuulProperties = new ZuulProperties();
} }
/**
* Tests old constructors kept for backwards compatibility with Spring Cloud Sleuth 1.x versions
*/
@Test
@Deprecated
public void testNullEntityWithOldConstruct() throws Exception {
String uri = "http://example.com";
LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("my-header", "my-value");
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("myparam", "myparamval");
RestClientRibbonCommand command =
new RestClientRibbonCommand("cmd", null,Verb.GET ,uri, false, headers, params, null);
HttpRequest request = command.createRequest();
assertThat("uri is wrong", request.getUri().toString(), startsWith(uri));
assertThat("my-header is wrong", request.getHttpHeaders().getFirstValue("my-header"), is(equalTo("my-value")));
assertThat("myparam is missing", request.getQueryParams().get("myparam").iterator().next(), is(equalTo("myparamval")));
command =
new RestClientRibbonCommand("cmd", null,
new RibbonCommandContext("example", "GET", uri, false, headers, params, null),
zuulProperties);
request = command.createRequest();
assertThat("uri is wrong", request.getUri().toString(), startsWith(uri));
assertThat("my-header is wrong", request.getHttpHeaders().getFirstValue("my-header"), is(equalTo("my-value")));
assertThat("myparam is missing", request.getQueryParams().get("myparam").iterator().next(), is(equalTo("myparamval")));
}
@Test @Test
public void testNullEntity() throws Exception { public void testNullEntity() throws Exception {
String uri = "http://example.com"; String uri = "http://example.com";
@ -60,7 +93,7 @@ public class RestClientRibbonCommandTests {
params.add("myparam", "myparamval"); params.add("myparam", "myparamval");
RestClientRibbonCommand command = RestClientRibbonCommand command =
new RestClientRibbonCommand("cmd", null, new RestClientRibbonCommand("cmd", null,
new RibbonCommandContext("example", "GET", uri, false, headers, params, null,new ArrayList<RibbonRequestCustomizer>()), new RibbonCommandContext("example", "GET", uri, false, headers, params, null, new ArrayList<RibbonRequestCustomizer>()),
zuulProperties); zuulProperties);
HttpRequest request = command.createRequest(); HttpRequest request = command.createRequest();

Loading…
Cancel
Save