Commit 29e691a4 by Dave Syer

Fix some zuul tests (clear request context before test)

parent 22b08f1a
......@@ -20,7 +20,9 @@ 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.feign.valid.FeignHttpClientTests;
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.
......@@ -28,7 +30,8 @@ import org.springframework.cloud.netflix.feign.valid.FeignHttpClientTests;
* @author Dave Syer
*/
@RunWith(Suite.class)
@SuiteClasses({ FeignHttpClientTests.class })
@SuiteClasses({ DiscoveryClientRouteLocatorTests.class,
CustomHostRoutingFilterTests.class, ProxyRequestHelperTests.class })
@Ignore
public class AdhocTestSuite {
......
......@@ -56,6 +56,12 @@ public class ProxyRequestHelperTests {
initMocks(this);
}
@Before
public void setTestRequestcontext() {
RequestContext context = new RequestContext();
RequestContext.testSetCurrentContext(context);
}
@Test
public void debug() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/");
......@@ -130,10 +136,7 @@ public class ProxyRequestHelperTests {
MultiValueMap<String, String> headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_ENCODING.toLowerCase(), "gzip");
helper.setResponse(
200,
request.getInputStream(),
headers);
helper.setResponse(200, request.getInputStream(), headers);
assertTrue(context.getResponseGZipped());
}
......@@ -151,10 +154,7 @@ public class ProxyRequestHelperTests {
MultiValueMap<String, String> headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_ENCODING, "gzip");
helper.setResponse(
200,
request.getInputStream(),
headers);
helper.setResponse(200, request.getInputStream(), headers);
assertTrue(context.getResponseGZipped());
}
}
......@@ -66,7 +66,7 @@ public class DiscoveryClientRouteLocatorTests {
@Before
public void init() {
initMocks(this);
setTestRequestcontext(); //re-initialize Zuul context for each test
setTestRequestcontext(); // re-initialize Zuul context for each test
}
@Test
......@@ -96,8 +96,9 @@ public class DiscoveryClientRouteLocatorTests {
@Test
public void testGetMatchingPathWithServletPath() throws Exception {
setTestRequestcontext();
RequestContext.getCurrentContext().set(RequestUtils.IS_DISPATCHERSERVLETREQUEST, true);
setTestRequestcontext();
RequestContext.getCurrentContext().set(RequestUtils.IS_DISPATCHERSERVLETREQUEST,
true);
DiscoveryClientRouteLocator routeLocator = new DiscoveryClientRouteLocator("/app",
this.discovery, this.properties);
this.properties.getRoutes().put("foo", new ZuulRoute("/foo/**"));
......@@ -107,20 +108,20 @@ public class DiscoveryClientRouteLocatorTests {
assertEquals("foo", route.getLocation());
assertEquals("/1", route.getPath());
}
@Test
public void testGetMatchingPathWithZuulServletPath() throws Exception {
RequestContext.getCurrentContext().setZuulEngineRan();
DiscoveryClientRouteLocator routeLocator = new DiscoveryClientRouteLocator("/app",
this.discovery, this.properties);
this.properties.getRoutes().put("foo", new ZuulRoute("/foo/**"));
this.properties.init();
routeLocator.getRoutes(); // force refresh
Route route = routeLocator.getMatchingRoute("/zuul/foo/1");
assertEquals("foo", route.getLocation());
assertEquals("/1", route.getPath());
}
@Test
public void testGetMatchingPathWithZuulServletPath() throws Exception {
RequestContext.getCurrentContext().setZuulEngineRan();
DiscoveryClientRouteLocator routeLocator = new DiscoveryClientRouteLocator("/app",
this.discovery, this.properties);
this.properties.getRoutes().put("foo", new ZuulRoute("/foo/**"));
this.properties.init();
routeLocator.getRoutes(); // force refresh
Route route = routeLocator.getMatchingRoute("/zuul/foo/1");
assertEquals("foo", route.getLocation());
assertEquals("/1", route.getPath());
}
@Test
public void testGetMatchingPathWithNoPrefixStripping() throws Exception {
......@@ -161,10 +162,12 @@ public class DiscoveryClientRouteLocatorTests {
assertEquals("foo", route.getLocation());
assertEquals("/foo/1", route.getPath());
}
@Test
public void testGetMatchingPathWithGlobalPrefixStrippingAndServletPath() throws Exception {
RequestContext.getCurrentContext().set(RequestUtils.IS_DISPATCHERSERVLETREQUEST, true);
public void testGetMatchingPathWithGlobalPrefixStrippingAndServletPath()
throws Exception {
RequestContext.getCurrentContext().set(RequestUtils.IS_DISPATCHERSERVLETREQUEST,
true);
DiscoveryClientRouteLocator routeLocator = new DiscoveryClientRouteLocator("/app",
this.discovery, this.properties);
this.properties.getRoutes().put("foo",
......@@ -174,10 +177,11 @@ public class DiscoveryClientRouteLocatorTests {
Route route = routeLocator.getMatchingRoute("/app/proxy/foo/1");
assertEquals("foo", route.getLocation());
assertEquals("/foo/1", route.getPath());
}
}
@Test
public void testGetMatchingPathWithGlobalPrefixStrippingAndZuulServletPath() throws Exception {
public void testGetMatchingPathWithGlobalPrefixStrippingAndZuulServletPath()
throws Exception {
RequestContext.getCurrentContext().setZuulEngineRan();
DiscoveryClientRouteLocator routeLocator = new DiscoveryClientRouteLocator("/",
this.discovery, this.properties);
......@@ -188,7 +192,7 @@ public class DiscoveryClientRouteLocatorTests {
Route route = routeLocator.getMatchingRoute("/zuul/proxy/foo/1");
assertEquals("foo", route.getLocation());
assertEquals("/foo/1", route.getPath());
}
}
@Test
public void testGetMatchingPathWithRoutePrefixStripping() throws Exception {
......@@ -644,10 +648,10 @@ public class DiscoveryClientRouteLocatorTests {
}
return null;
}
private void setTestRequestcontext() {
RequestContext context = new RequestContext();
RequestContext.testSetCurrentContext(context);
RequestContext context = new RequestContext();
RequestContext.testSetCurrentContext(context);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment