Commit d39a2294 by Dave Syer

Merge branch '1.3.x'

parents 310f558e aac7799e
......@@ -22,7 +22,7 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.springframework.cloud.netflix.zuul.FormZuulServletProxyApplicationTests;
import org.springframework.cloud.netflix.zuul.ZuulProxyAutoConfigurationTests;
import org.springframework.cloud.netflix.zuul.filters.route.LazyLoadOfZuulConfigurationTests;
/**
* A test suite for probing weird ordering problems in the tests.
......@@ -30,8 +30,8 @@ import org.springframework.cloud.netflix.zuul.ZuulProxyAutoConfigurationTests;
* @author Dave Syer
*/
@RunWith(Suite.class)
@SuiteClasses({ ZuulProxyAutoConfigurationTests.class,
FormZuulServletProxyApplicationTests.class })
@SuiteClasses({ FormZuulServletProxyApplicationTests.class,
LazyLoadOfZuulConfigurationTests.class })
@Ignore
public class AdhocTestSuite {
......
......@@ -16,11 +16,13 @@
package org.springframework.cloud.netflix.zuul;
import static org.junit.Assert.assertEquals;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.LocalServerPort;
......@@ -41,13 +43,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(
classes = ContextPathZuulProxyApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT,
value = {"server.contextPath: /app"})
@SpringBootTest(classes = ContextPathZuulProxyApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
"server.contextPath: /app" })
@DirtiesContext
public class ContextPathZuulProxyApplicationTests {
......@@ -69,6 +69,11 @@ public class ContextPathZuulProxyApplicationTests {
RequestContext.testSetCurrentContext(context);
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void getOnSelfViaSimpleHostRoutingFilter() {
this.routes.addRoute("/self/**", "http://localhost:" + this.port + "/app/local");
......
......@@ -16,19 +16,22 @@
package org.springframework.cloud.netflix.zuul;
import static java.nio.charset.Charset.defaultCharset;
import static org.junit.Assert.assertEquals;
import static org.springframework.util.StreamUtils.copyToString;
import java.io.IOException;
import java.util.Map;
import javax.inject.Inject;
import javax.servlet.http.Part;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.actuate.trace.InMemoryTraceRepository;
import org.springframework.boot.actuate.trace.TraceRepository;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
......@@ -58,18 +61,15 @@ import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
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 java.nio.charset.Charset.defaultCharset;
import static org.junit.Assert.assertEquals;
import static org.springframework.util.StreamUtils.copyToString;
import lombok.extern.slf4j.Slf4j;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(
classes = FormZuulProxyApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT,
value = {"zuul.routes.simple:/simple/**"})
@SpringBootTest(classes = FormZuulProxyApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
"zuul.routes.simple:/simple/**" })
@DirtiesContext
public class FormZuulProxyApplicationTests {
......@@ -81,6 +81,11 @@ public class FormZuulProxyApplicationTests {
RequestContext.testSetCurrentContext(new RequestContext());
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void postWithForm() {
MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
......@@ -170,7 +175,8 @@ public class FormZuulProxyApplicationTests {
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 = sendPost("/simple/form", form, headers);
......@@ -185,7 +191,8 @@ public class FormZuulProxyApplicationTests {
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 = sendPost("/simple/form?uriParam=uriValue", form, headers);
......@@ -201,8 +208,10 @@ public class FormZuulProxyApplicationTests {
assertEquals("Posted! {uriParam=[uriValue]}", result.getBody());
}
private ResponseEntity<String> sendPost(String url, MultiValueMap form, HttpHeaders headers) {
return restTemplate.postForEntity(url, new HttpEntity<>(form, headers), String.class);
private ResponseEntity<String> sendPost(String url, MultiValueMap form,
HttpHeaders headers) {
return restTemplate.postForEntity(url, new HttpEntity<>(form, headers),
String.class);
}
private ResponseEntity<String> sendGet(String url) {
......@@ -217,7 +226,7 @@ public class FormZuulProxyApplicationTests {
@EnableZuulProxy
@RibbonClients({
@RibbonClient(name = "simple", configuration = FormRibbonClientConfiguration.class),
@RibbonClient(name = "psimple", configuration = FormRibbonClientConfiguration.class)})
@RibbonClient(name = "psimple", configuration = FormRibbonClientConfiguration.class) })
@Slf4j
class FormZuulProxyApplication {
......@@ -242,17 +251,18 @@ class FormZuulProxyApplication {
}
@RequestMapping(value = "/fileandform", method = RequestMethod.POST)
public String fileAndForm(@RequestParam MultipartFile file, @RequestParam String field)
throws IOException {
public String fileAndForm(@RequestParam MultipartFile file,
@RequestParam String field) throws IOException {
return "Posted! " + copyToString(file.getInputStream(), defaultCharset()) + "!field!" + field;
return "Posted! " + copyToString(file.getInputStream(), defaultCharset())
+ "!field!" + field;
}
@RequestMapping(value = "/json", method = RequestMethod.POST)
public String fileAndJson(@RequestPart Part field)
throws IOException {
public String fileAndJson(@RequestPart Part field) throws IOException {
return "Posted! " + copyToString(field.getInputStream(), defaultCharset()) + " as " + field.getContentType();
return "Posted! " + copyToString(field.getInputStream(), defaultCharset())
+ " as " + field.getContentType();
}
@Bean
......@@ -299,8 +309,7 @@ class FormZuulProxyApplication {
new SpringApplicationBuilder(FormZuulProxyApplication.class)
.properties("zuul.routes.simple:/simple/**",
"zuul.routes.direct.url:http://localhost:9999",
"multipart.maxFileSize:4096MB",
"multipart.maxRequestSize:4096MB")
"multipart.maxFileSize:4096MB", "multipart.maxRequestSize:4096MB")
.run(args);
}
......
......@@ -16,15 +16,20 @@
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 com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.trace.InMemoryTraceRepository;
import org.springframework.boot.actuate.trace.TraceRepository;
......@@ -55,18 +60,12 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
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)
@SpringBootTest(
classes = FormZuulServletProxyApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT,
value = "zuul.routes.simple:/simple/**")
@SpringBootTest(classes = FormZuulServletProxyApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = "zuul.routes.simple:/simple/**")
@DirtiesContext
public class FormZuulServletProxyApplicationTests {
......@@ -79,15 +78,19 @@ public class FormZuulServletProxyApplicationTests {
RequestContext.testSetCurrentContext(context);
}
@After
public void unsetTestRequestContext() {
RequestContext.getCurrentContext().clear();
}
@Test
public void postWithForm() {
MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
form.set("foo", "bar");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
ResponseEntity<String> result = testRestTemplate.exchange(
"/zuul/simple/form", HttpMethod.POST,
new HttpEntity<>(form, headers), String.class);
ResponseEntity<String> result = testRestTemplate.exchange("/zuul/simple/form",
HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("Posted! {foo=[bar]}", result.getBody());
}
......@@ -98,9 +101,8 @@ public class FormZuulServletProxyApplicationTests {
form.set("foo", "bar");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
ResponseEntity<String> result = testRestTemplate.exchange(
"/zuul/simple/form", HttpMethod.POST,
new HttpEntity<>(form, headers), String.class);
ResponseEntity<String> result = testRestTemplate.exchange("/zuul/simple/form",
HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("Posted! {foo=[bar]}", result.getBody());
}
......@@ -116,9 +118,8 @@ public class FormZuulServletProxyApplicationTests {
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.set("Transfer-Encoding", "chunked");
headers.setContentLength(-1);
ResponseEntity<String> result = testRestTemplate.exchange(
"/zuul/simple/file", HttpMethod.POST,
new HttpEntity<>(form, headers), String.class);
ResponseEntity<String> result = testRestTemplate.exchange("/zuul/simple/file",
HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("Posted! bar", result.getBody());
}
......@@ -130,9 +131,8 @@ public class FormZuulServletProxyApplicationTests {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.valueOf(
MediaType.APPLICATION_FORM_URLENCODED_VALUE + "; charset=UTF-8"));
ResponseEntity<String> result = testRestTemplate.exchange(
"/zuul/simple/form", HttpMethod.POST,
new HttpEntity<>(form, headers), String.class);
ResponseEntity<String> result = testRestTemplate.exchange("/zuul/simple/form",
HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("Posted! {foo=[bar]}", result.getBody());
}
......@@ -167,7 +167,8 @@ class FormZuulServletProxyApplication {
while (inputStream.read(buffer) >= 0) {
log.info("Read more bytes");
}
} else {
}
else {
bytes = file.getBytes();
}
}
......@@ -219,8 +220,7 @@ class FormZuulServletProxyApplication {
.properties("zuul.routes.simple:/zuul/simple/**",
"zuul.routes.direct.url:http://localhost:9999",
"zuul.routes.direct.path:/zuul/direct/**",
"multipart.maxFileSize:4096MB",
"multipart.maxRequestSize:4096MB")
"multipart.maxFileSize:4096MB", "multipart.maxRequestSize:4096MB")
.run(args);
}
......
package org.springframework.cloud.netflix.zuul;
import static org.junit.Assert.assertEquals;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.LocalServerPort;
......@@ -31,20 +36,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
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;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(
classes = RetryableZuulProxyApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT,
value = {
"zuul.routes.simple.path: /simple/**",
"zuul.routes.simple.retryable: true",
"ribbon.OkToRetryOnAllOperations: true",
"simple.ribbon.retryableStatusCodes: 404"})
@SpringBootTest(classes = RetryableZuulProxyApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
"zuul.routes.simple.path: /simple/**", "zuul.routes.simple.retryable: true",
"ribbon.OkToRetryOnAllOperations: true",
"simple.ribbon.retryableStatusCodes: 404" })
@DirtiesContext
public class RetryableZuulProxyApplicationTests {
......@@ -65,15 +63,19 @@ public class RetryableZuulProxyApplicationTests {
RequestContext.testSetCurrentContext(context);
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void postWithForm() {
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
form.set("foo", "bar");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
ResponseEntity<String> result = testRestTemplate.exchange(
"/simple/poster", HttpMethod.POST,
new HttpEntity<>(form, headers), String.class);
ResponseEntity<String> result = testRestTemplate.exchange("/simple/poster",
HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("Posted! {foo=[bar]}", result.getBody());
}
......
......@@ -16,13 +16,15 @@
package org.springframework.cloud.netflix.zuul;
import static org.junit.Assert.assertEquals;
import java.net.URI;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.LocalServerPort;
......@@ -46,13 +48,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(
classes = ServletPathZuulProxyApplicationTests.ServletPathZuulProxyApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT,
value = {"server.servletPath: /app"})
@SpringBootTest(classes = ServletPathZuulProxyApplicationTests.ServletPathZuulProxyApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
"server.servletPath: /app" })
@DirtiesContext
public class ServletPathZuulProxyApplicationTests {
......@@ -74,14 +74,17 @@ public class ServletPathZuulProxyApplicationTests {
RequestContext.testSetCurrentContext(context);
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void getOnSelfViaSimpleHostRoutingFilter() {
this.routes.addRoute("/self/**",
"http://localhost:" + this.port + "/app/local");
this.routes.addRoute("/self/**", "http://localhost:" + this.port + "/app/local");
this.endpoint.reset();
ResponseEntity<String> result = testRestTemplate.exchange(
"/app/self/1", HttpMethod.GET,
new HttpEntity<>((Void) null), String.class);
ResponseEntity<String> result = testRestTemplate.exchange("/app/self/1",
HttpMethod.GET, new HttpEntity<>((Void) null), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("Gotten 1!", result.getBody());
}
......@@ -89,42 +92,37 @@ public class ServletPathZuulProxyApplicationTests {
@Test
public void optionsOnRawEndpoint() throws Exception {
ResponseEntity<String> result = testRestTemplate.exchange(
RequestEntity
.options(new URI("/app/local/1"))
RequestEntity.options(new URI("/app/local/1"))
.header("Origin", "http://localhost:9000")
.header("Access-Control-Request-Method", "GET")
.build(),
.header("Access-Control-Request-Method", "GET").build(),
String.class);
HttpHeaders httpHeaders = result.getHeaders();
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("http://localhost:9000", httpHeaders.getFirst("Access-Control-Allow-Origin"));
assertEquals("http://localhost:9000",
httpHeaders.getFirst("Access-Control-Allow-Origin"));
}
@Test
public void optionsOnSelf() throws Exception {
this.routes.addRoute("/self/**",
"http://localhost:" + this.port + "/app/local");
this.routes.addRoute("/self/**", "http://localhost:" + this.port + "/app/local");
this.endpoint.reset();
ResponseEntity<String> result = testRestTemplate.exchange(
RequestEntity
.options(new URI("/app/self/1"))
RequestEntity.options(new URI("/app/self/1"))
.header("Origin", "http://localhost:9000")
.header("Access-Control-Request-Method", "GET")
.build(),
.header("Access-Control-Request-Method", "GET").build(),
String.class);
HttpHeaders httpHeaders = result.getHeaders();
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("http://localhost:9000", httpHeaders.getFirst("Access-Control-Allow-Origin"));
assertEquals("http://localhost:9000",
httpHeaders.getFirst("Access-Control-Allow-Origin"));
}
@Test
public void contentOnRawEndpoint() throws Exception {
ResponseEntity<String> result = testRestTemplate.exchange(
RequestEntity
.get(new URI("/app/local/1"))
.build(), String.class);
RequestEntity.get(new URI("/app/local/1")).build(), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("Gotten 1!", result.getBody());
}
......@@ -134,9 +132,8 @@ public class ServletPathZuulProxyApplicationTests {
this.routes.addRoute(new ZuulRoute("strip", "/strip/**", "strip",
"http://localhost:" + this.port + "/app/local", false, false, null));
this.endpoint.reset();
ResponseEntity<String> result = testRestTemplate.exchange(
"/app/strip", HttpMethod.GET,
new HttpEntity<>((Void) null), String.class);
ResponseEntity<String> result = testRestTemplate.exchange("/app/strip",
HttpMethod.GET, new HttpEntity<>((Void) null), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
// Prefix not stripped to it goes to /local/strip
assertEquals("Gotten strip!", result.getBody());
......
......@@ -16,17 +16,19 @@
package org.springframework.cloud.netflix.zuul;
import static org.junit.Assert.assertEquals;
import java.net.URI;
import java.net.URISyntaxException;
import javax.servlet.http.HttpServletRequest;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.LocalServerPort;
......@@ -46,13 +48,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(
classes = SimpleZuulProxyApplicationTests.SimpleZuulProxyApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT,
value = {"zuul.forceOriginalQueryStringEncoding: true"})
@SpringBootTest(classes = SimpleZuulProxyApplicationTests.SimpleZuulProxyApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
"zuul.forceOriginalQueryStringEncoding: true" })
@DirtiesContext
public class SimpleZuulProxyApplicationTests {
......@@ -77,6 +77,11 @@ public class SimpleZuulProxyApplicationTests {
this.endpoint.reset();
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void getOnSelfViaSimpleHostRoutingFilter() {
ResponseEntity<String> result = executeSimpleRequest(HttpMethod.GET);
......@@ -125,15 +130,14 @@ public class SimpleZuulProxyApplicationTests {
}
private void assertResponseCodeAndBody(ResponseEntity<String> result,
String expectedBody) {
String expectedBody) {
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(expectedBody, result.getBody());
}
private ResponseEntity<String> executeSimpleRequest(HttpMethod httpMethod) {
ResponseEntity<String> result = testRestTemplate.exchange(
"/foo?id=bar", httpMethod,
new HttpEntity<>((Void) null), String.class);
ResponseEntity<String> result = testRestTemplate.exchange("/foo?id=bar",
httpMethod, new HttpEntity<>((Void) null), String.class);
return result;
}
......@@ -149,7 +153,7 @@ public class SimpleZuulProxyApplicationTests {
return "get " + id;
}
@RequestMapping(value = "/bar", method = RequestMethod.GET, params = {"foo"})
@RequestMapping(value = "/bar", method = RequestMethod.GET, params = { "foo" })
public String complexGet(@RequestParam String foo, HttpServletRequest request) {
return request.getQueryString();
}
......
......@@ -16,12 +16,14 @@
package org.springframework.cloud.netflix.zuul;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
......@@ -41,13 +43,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(
classes = SimpleZuulServerApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT)
@SpringBootTest(classes = SimpleZuulServerApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class SimpleZuulServerApplicationTests {
......@@ -70,6 +70,11 @@ public class SimpleZuulServerApplicationTests {
RequestContext.testSetCurrentContext(context);
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void bindRoute() {
assertNotNull(getRoute("/testing123/**"));
......@@ -77,8 +82,7 @@ public class SimpleZuulServerApplicationTests {
@Test
public void getOnSelf() {
ResponseEntity<String> result = testRestTemplate.exchange(
"/", HttpMethod.GET,
ResponseEntity<String> result = testRestTemplate.exchange("/", HttpMethod.GET,
new HttpEntity<>((Void) null), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("Hello world", result.getBody());
......@@ -86,9 +90,8 @@ public class SimpleZuulServerApplicationTests {
@Test
public void getOnSelfViaFilter() {
ResponseEntity<String> result = testRestTemplate.exchange(
"/testing123/1", HttpMethod.GET,
new HttpEntity<>((Void) null), String.class);
ResponseEntity<String> result = testRestTemplate.exchange("/testing123/1",
HttpMethod.GET, new HttpEntity<>((Void) null), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
}
......
......@@ -17,9 +17,15 @@
package org.springframework.cloud.netflix.zuul;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -40,10 +46,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
......@@ -61,10 +63,16 @@ public class ZuulProxyApplicationTests {
RequestContext.testSetCurrentContext(context);
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void getHasCorrectTransferEncoding() {
ResponseEntity<String> result = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/simple/transferencoding", String.class);
"http://localhost:" + this.port + "/simple/transferencoding",
String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("missing", result.getBody());
}
......@@ -72,8 +80,8 @@ public class ZuulProxyApplicationTests {
@Test
public void postHasCorrectTransferEncoding() {
ResponseEntity<String> result = new TestRestTemplate().postForEntity(
"http://localhost:" + this.port + "/simple/transferencoding", new HttpEntity<>("hello"),
String.class);
"http://localhost:" + this.port + "/simple/transferencoding",
new HttpEntity<>("hello"), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("missing", result.getBody());
}
......@@ -87,7 +95,8 @@ public class ZuulProxyApplicationTests {
static class ZuulProxyApplication {
@RequestMapping(value = "/transferencoding", method = RequestMethod.GET)
public String get(@RequestHeader(name = "Transfer-Encoding", required = false) String transferEncoding) {
public String get(
@RequestHeader(name = "Transfer-Encoding", required = false) String transferEncoding) {
if (transferEncoding == null) {
return "missing";
}
......@@ -95,8 +104,9 @@ public class ZuulProxyApplicationTests {
}
@RequestMapping(value = "/transferencoding", method = RequestMethod.POST)
public String post(@RequestHeader(name = "Transfer-Encoding", required = false) String transferEncoding,
@RequestBody String hello) {
public String post(
@RequestHeader(name = "Transfer-Encoding", required = false) String transferEncoding,
@RequestBody String hello) {
if (transferEncoding == null) {
return "missing";
}
......@@ -119,4 +129,3 @@ public class ZuulProxyApplicationTests {
}
}
......@@ -16,21 +16,21 @@
package org.springframework.cloud.netflix.zuul.filters;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.netflix.zuul.context.RequestContext;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
......@@ -59,7 +59,9 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.netflix.zuul.context.RequestContext;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SampleCustomZuulProxyApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
......@@ -82,6 +84,11 @@ public class CustomHostRoutingFilterTests {
RequestContext.testSetCurrentContext(context);
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void getOnSelfViaCustomHostRoutingFilter() {
this.routes.addRoute("/self/**", "http://localhost:" + this.port + "/app");
......
......@@ -19,9 +19,13 @@ package org.springframework.cloud.netflix.zuul.filters;
import java.io.IOException;
import java.util.List;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.springframework.boot.actuate.trace.InMemoryTraceRepository;
import org.springframework.boot.actuate.trace.Trace;
import org.springframework.boot.actuate.trace.TraceRepository;
......@@ -32,8 +36,6 @@ import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import com.netflix.zuul.context.RequestContext;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
......@@ -64,6 +66,11 @@ public class ProxyRequestHelperTests {
RequestContext.testSetCurrentContext(context);
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void debug() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/");
......
......@@ -20,9 +20,13 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.zuul.filters.Route;
......@@ -31,8 +35,6 @@ import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.cloud.netflix.zuul.util.RequestUtils;
import org.springframework.core.env.ConfigurableEnvironment;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
......@@ -86,6 +88,11 @@ public class DiscoveryClientRouteLocatorTests {
setTestRequestcontext(); // re-initialize Zuul context for each test
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void testGetMatchingPath() throws Exception {
DiscoveryClientRouteLocator routeLocator = new DiscoveryClientRouteLocator("/",
......@@ -603,8 +610,7 @@ public class DiscoveryClientRouteLocatorTests {
@Test
public void testLocalServiceExceptionIgnored() {
given(this.discovery.getServices())
.willReturn(Collections.<String>emptyList());
given(this.discovery.getServices()).willReturn(Collections.<String>emptyList());
given(this.discovery.getLocalServiceInstance()).willThrow(new RuntimeException());
DiscoveryClientRouteLocator routeLocator = new DiscoveryClientRouteLocator("/",
......@@ -680,6 +686,5 @@ public class DiscoveryClientRouteLocatorTests {
private void setTestRequestcontext() {
RequestContext context = new RequestContext();
RequestContext.testSetCurrentContext(context);
}
}
package org.springframework.cloud.netflix.zuul.filters.discovery;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapperIntegrationTests.SERVICE_ID;
import java.util.ArrayList;
import java.util.List;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
......@@ -36,9 +37,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapperIntegrationTests.SERVICE_ID;
/**
* @author Stéphane Leroy
......@@ -67,6 +69,11 @@ public class PatternServiceRouteMapperIntegrationTests {
RequestContext.testSetCurrentContext(context);
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void getRegexMappedService() {
this.endpoint.reset();
......
package org.springframework.cloud.netflix.zuul.filters.discovery;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
/**
......@@ -25,6 +26,11 @@ public class PatternServiceRouteMapperTests {
RequestContext.testSetCurrentContext(context);
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void test_return_mapped_route_if_serviceid_matches() {
PatternServiceRouteMapper toTest = new PatternServiceRouteMapper(SERVICE_PATTERN,
......
......@@ -19,9 +19,16 @@ package org.springframework.cloud.netflix.zuul.filters.post;
import javax.servlet.http.HttpServletRequest;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.LocalServerPort;
......@@ -38,11 +45,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
......@@ -50,9 +52,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
* @author Spencer Gibb
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SendErrorFilterIntegrationTests.Config.class,
properties = "zuul.routes.filtertest:/filtertest/**",
webEnvironment = RANDOM_PORT)
@SpringBootTest(classes = SendErrorFilterIntegrationTests.Config.class, properties = "zuul.routes.filtertest:/filtertest/**", webEnvironment = RANDOM_PORT)
@DirtiesContext
public class SendErrorFilterIntegrationTests {
......@@ -65,24 +65,32 @@ public class SendErrorFilterIntegrationTests {
RequestContext.testSetCurrentContext(context);
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void testPreFails() {
String url = "http://localhost:" + port + "/filtertest/get?failpre=true";
ResponseEntity<String> response = new TestRestTemplate().getForEntity(url, String.class);
ResponseEntity<String> response = new TestRestTemplate().getForEntity(url,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
@Test
public void testRouteFails() {
String url = "http://localhost:" + port + "/filtertest/get?failroute=true";
ResponseEntity<String> response = new TestRestTemplate().getForEntity(url, String.class);
ResponseEntity<String> response = new TestRestTemplate().getForEntity(url,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
@Test
public void testPostFails() {
String url = "http://localhost:" + port + "/filtertest/get?failpost=true";
ResponseEntity<String> response = new TestRestTemplate().getForEntity(url, String.class);
ResponseEntity<String> response = new TestRestTemplate().getForEntity(url,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
......@@ -149,13 +157,13 @@ public class SendErrorFilterIntegrationTests {
@Override
public boolean shouldFilter() {
HttpServletRequest request = RequestContext.getCurrentContext().getRequest();
return request.getParameter("fail"+filterType()) != null;
return request.getParameter("fail" + filterType()) != null;
}
@Override
public Object run() {
HttpServletRequest request = RequestContext.getCurrentContext().getRequest();
if (request.getParameter("fail"+filterType()) != null) {
if (request.getParameter("fail" + filterType()) != null) {
throw new RuntimeException("failing on purpose in " + filterType());
}
return null;
......
......@@ -22,9 +22,14 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.netflix.util.Pair;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
......@@ -32,9 +37,6 @@ import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
import org.springframework.mock.web.MockHttpServletRequest;
import com.netflix.util.Pair;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
......@@ -74,6 +76,11 @@ public class PreDecorationFilterTests {
ctx.setRequest(this.request);
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void basicProperties() throws Exception {
assertEquals(5, this.filter.filterOrder());
......@@ -103,7 +110,8 @@ public class PreDecorationFilterTests {
new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("localhost:8080",
ctx.getZuulRequestHeaders().get("x-forwarded-host"));
}
@Test
......@@ -118,7 +126,8 @@ public class PreDecorationFilterTests {
new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("example.com,localhost:8080", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("example.com,localhost:8080",
ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("443,8080", ctx.getZuulRequestHeaders().get("x-forwarded-port"));
assertEquals("https,http", ctx.getZuulRequestHeaders().get("x-forwarded-proto"));
}
......@@ -151,7 +160,8 @@ public class PreDecorationFilterTests {
new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("localhost:8080",
ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("443,8080", ctx.getZuulRequestHeaders().get("x-forwarded-port"));
assertEquals("https,http", ctx.getZuulRequestHeaders().get("x-forwarded-proto"));
}
......@@ -167,7 +177,8 @@ public class PreDecorationFilterTests {
new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("localhost:8080",
ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("80,8080", ctx.getZuulRequestHeaders().get("x-forwarded-port"));
assertEquals("http,http", ctx.getZuulRequestHeaders().get("x-forwarded-proto"));
}
......@@ -183,7 +194,8 @@ public class PreDecorationFilterTests {
new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("localhost:8080",
ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("456,8080", ctx.getZuulRequestHeaders().get("x-forwarded-port"));
assertEquals("http", ctx.getZuulRequestHeaders().get("x-forwarded-proto"));
}
......@@ -200,7 +212,8 @@ public class PreDecorationFilterTests {
new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("localhost:8080",
ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("456,8080", ctx.getZuulRequestHeaders().get("x-forwarded-port"));
assertEquals("https,http", ctx.getZuulRequestHeaders().get("x-forwarded-proto"));
}
......@@ -216,7 +229,8 @@ public class PreDecorationFilterTests {
new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("localhost:8080",
ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("host"));
}
......@@ -319,8 +333,7 @@ public class PreDecorationFilterTests {
assertEquals("localhost", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("80", ctx.getZuulRequestHeaders().get("x-forwarded-port"));
assertEquals("http", ctx.getZuulRequestHeaders().get("x-forwarded-proto"));
assertEquals("/prefix",
ctx.getZuulRequestHeaders().get("x-forwarded-prefix"));
assertEquals("/prefix", ctx.getZuulRequestHeaders().get("x-forwarded-prefix"));
assertEquals("foo",
getHeader(ctx.getOriginResponseHeaders(), "x-zuul-serviceid"));
}
......@@ -507,7 +520,7 @@ public class PreDecorationFilterTests {
this.properties.setSensitiveHeaders(Collections.singleton("x-bar"));
this.request.setRequestURI("/api/foo/1");
ZuulRoute route = new ZuulRoute("/foo/**", "foo");
route.setSensitiveHeaders(Collections.<String> emptySet());
route.setSensitiveHeaders(Collections.<String>emptySet());
this.routeLocator.addRoute(route);
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
......
......@@ -14,13 +14,18 @@
* limitations under the License.
*/
package org.springframework.cloud.netflix.zuul.filters.route;
import java.util.concurrent.atomic.AtomicInteger;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -38,8 +43,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.atomic.AtomicInteger;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
......@@ -51,6 +54,11 @@ public class LazyLoadOfZuulConfigurationTests {
@Value("${local.server.port}")
protected int port;
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
@Test
public void testEagerLoading() {
// Child context FooConfig should be lazily created..
......
......@@ -18,14 +18,15 @@ package org.springframework.cloud.netflix.zuul.filters.route;
import javax.servlet.http.HttpServletRequest;
import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.FORWARD_TO_KEY;
......@@ -37,7 +38,7 @@ public class SendForwardFilterTests {
@After
public void reset() {
RequestContext.testSetCurrentContext(null);
RequestContext.getCurrentContext().clear();
}
@Before
......
......@@ -18,32 +18,31 @@
package org.springframework.cloud.netflix.zuul.filters.route.apache;
import com.netflix.zuul.context.RequestContext;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.netflix.zuul.filters.route.support.RibbonCommandFallbackTests;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import com.netflix.zuul.context.RequestContext;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/**
* @author Ryan Baxter
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = RibbonCommandFallbackTests.TestConfig.class, webEnvironment = RANDOM_PORT,
properties = {
@SpringBootTest(classes = RibbonCommandFallbackTests.TestConfig.class, webEnvironment = RANDOM_PORT, properties = {
"zuul.routes.simple: /simple/**", "zuul.routes.another: /another/twolevel/**",
"ribbon.ReadTimeout: 1"})
"ribbon.ReadTimeout: 1" })
@DirtiesContext
public class HttpClientRibbonCommandFallbackTests extends RibbonCommandFallbackTests {
@Before
public void init() {
RequestContext.testSetCurrentContext(null);
RequestContext.getCurrentContext().unset();
RequestContext.getCurrentContext().clear();
}
}
......@@ -18,27 +18,27 @@
package org.springframework.cloud.netflix.zuul.filters.route.okhttp;
import com.netflix.zuul.context.RequestContext;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.netflix.zuul.filters.route.support.RibbonCommandFallbackTests;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.netflix.zuul.context.RequestContext;
/**
* @author Ryan Baxter
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = RibbonCommandFallbackTests.TestConfig.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = {
"zuul.routes.simple: /simple/**", "zuul.routes.another: /another/twolevel/**",
"ribbon.ReadTimeout: 1"})
"ribbon.ReadTimeout: 1" })
@DirtiesContext
public class OkHttpRibbonCommandFallbackTests extends RibbonCommandFallbackTests {
@Before
public void init() {
RequestContext.testSetCurrentContext(null);
RequestContext.getCurrentContext().unset();
RequestContext.getCurrentContext().clear();
}
}
......@@ -18,27 +18,27 @@
package org.springframework.cloud.netflix.zuul.filters.route.restclient;
import com.netflix.zuul.context.RequestContext;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.netflix.zuul.filters.route.support.RibbonCommandFallbackTests;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.netflix.zuul.context.RequestContext;
/**
* @author Ryan Baxter
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = RibbonCommandFallbackTests.TestConfig.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = {
"zuul.routes.simple: /simple/**", "zuul.routes.another: /another/twolevel/**",
"ribbon.ReadTimeout: 1"})
"ribbon.ReadTimeout: 1" })
@DirtiesContext
public class RestClientRibbonCommandFallbackTests extends RibbonCommandFallbackTests {
@Before
public void init() {
RequestContext.testSetCurrentContext(null);
RequestContext.getCurrentContext().unset();
RequestContext.getCurrentContext().clear();
}
}
......@@ -37,6 +37,7 @@ import com.netflix.zuul.context.RequestContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -114,6 +115,11 @@ public abstract class ZuulProxyTestBase {
RequestContext.getCurrentContext().unset();
}
@After
public void clear() {
RequestContext.getCurrentContext().clear();
}
/**
* used to disable patch tests if client doesn't support it
*/
......
......@@ -4,9 +4,6 @@ server:
enabled: true
min-response-size: 1024
mime-types: application/xml,application/json
logging:
level:
org.springframework.web: INFO
spring:
application:
name: testclient
......
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