From b98c9ebc1d197a38f9b5d2abbf0c5616e60e3a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lagraulet?= Date: Thu, 18 Aug 2016 14:27:11 +0200 Subject: [PATCH] Add tests to verify old constructors --- .../filters/route/RibbonCommandContext.java | 4 +++ .../route/RestClientRibbonCommandTests.java | 35 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommandContext.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommandContext.java index 288f4e52..79c2e72c 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommandContext.java +++ b/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 requestCustomizers; private Long contentLength; + /** + * Kept for backwards compatibility with Spring Cloud Sleuth 1.x versions + */ + @Deprecated public RibbonCommandContext(String serviceId, String method, String uri, Boolean retryable, MultiValueMap headers, MultiValueMap params, InputStream requestEntity) { diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandTests.java index 5b4671d4..7b0b4614 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandTests.java +++ b/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 com.netflix.client.http.HttpRequest; +import com.netflix.client.http.HttpRequest.Verb; /** * @author Spencer Gibb @@ -51,6 +52,38 @@ public class RestClientRibbonCommandTests { 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 headers = new LinkedMultiValueMap<>(); + headers.add("my-header", "my-value"); + LinkedMultiValueMap 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 public void testNullEntity() throws Exception { String uri = "http://example.com"; @@ -60,7 +93,7 @@ public class RestClientRibbonCommandTests { params.add("myparam", "myparamval"); RestClientRibbonCommand command = new RestClientRibbonCommand("cmd", null, - new RibbonCommandContext("example", "GET", uri, false, headers, params, null,new ArrayList()), + new RibbonCommandContext("example", "GET", uri, false, headers, params, null, new ArrayList()), zuulProperties); HttpRequest request = command.createRequest();