diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java index 7e34225d..3f029e1e 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java @@ -20,9 +20,6 @@ import org.junit.Ignore; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import org.springframework.cloud.netflix.zuul.filters.CustomHostRoutingFilterTests; -import org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelperTests; -import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocatorTests; /** * A test suite for probing weird ordering problems in the tests. @@ -30,8 +27,10 @@ import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientR * @author Dave Syer */ @RunWith(Suite.class) -@SuiteClasses({ DiscoveryClientRouteLocatorTests.class, - CustomHostRoutingFilterTests.class, ProxyRequestHelperTests.class }) +@SuiteClasses({ + org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelperTests.class, + org.springframework.cloud.netflix.zuul.SampleZuulProxyApplicationTests.class, + org.springframework.cloud.netflix.zuul.FormZuulProxyApplicationTests.class }) @Ignore public class AdhocTestSuite { diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulProxyApplicationTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulProxyApplicationTests.java index c7deef6e..2f864550 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulProxyApplicationTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulProxyApplicationTests.java @@ -16,14 +16,11 @@ package org.springframework.cloud.netflix.zuul; -import static org.junit.Assert.assertEquals; - import java.io.IOException; import java.io.InputStream; import java.util.Map; -import lombok.extern.slf4j.Slf4j; - +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; @@ -59,6 +56,11 @@ import org.springframework.web.multipart.MultipartFile; import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.ServerList; import com.netflix.zuul.ZuulFilter; +import com.netflix.zuul.context.RequestContext; + +import static org.junit.Assert.assertEquals; + +import lombok.extern.slf4j.Slf4j; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = FormZuulProxyApplication.class) @@ -70,6 +72,12 @@ public class FormZuulProxyApplicationTests { @Value("${local.server.port}") private int port; + @Before + public void setTestRequestcontext() { + RequestContext context = new RequestContext(); + RequestContext.testSetCurrentContext(context); + } + @Test public void postWithForm() { MultiValueMap form = new LinkedMultiValueMap(); @@ -120,8 +128,8 @@ public class FormZuulProxyApplicationTests { MultiValueMap form = new LinkedMultiValueMap(); form.set("foo", "bar"); HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType - .valueOf(MediaType.APPLICATION_FORM_URLENCODED_VALUE + "; charset=UTF-8")); + headers.setContentType(MediaType.valueOf( + MediaType.APPLICATION_FORM_URLENCODED_VALUE + "; charset=UTF-8")); ResponseEntity result = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/simple/form", HttpMethod.POST, new HttpEntity>(form, headers), @@ -211,11 +219,11 @@ class FormZuulProxyApplication { } public static void main(String[] args) { - new SpringApplicationBuilder(FormZuulProxyApplication.class).properties( - "zuul.routes.simple:/simple/**", - "zuul.routes.direct.url:http://localhost:9999", - "multipart.maxFileSize:4096MB", "multipart.maxRequestSize:4096MB").run( - args); + new SpringApplicationBuilder(FormZuulProxyApplication.class) + .properties("zuul.routes.simple:/simple/**", + "zuul.routes.direct.url:http://localhost:9999", + "multipart.maxFileSize:4096MB", "multipart.maxRequestSize:4096MB") + .run(args); } } @@ -229,7 +237,7 @@ class FormRibbonClientConfiguration { @Bean public ServerList ribbonServerList() { - return new StaticServerList<>(new Server("localhost", port)); + return new StaticServerList<>(new Server("localhost", this.port)); } } diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java index 3a08e3ac..eb1357ff 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java @@ -23,6 +23,7 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -88,6 +89,12 @@ public class SampleZuulProxyApplicationTests { @Autowired private RibbonCommandFactory ribbonCommandFactory; + @Before + public void setTestRequestcontext() { + RequestContext context = new RequestContext(); + RequestContext.testSetCurrentContext(context); + } + private String getRoute(String path) { for (Route route : this.routes.getRoutes()) { if (path.equals(route.getFullPath())) {