polish

parent ac1ac4d5
...@@ -8,19 +8,17 @@ import org.junit.Before; ...@@ -8,19 +8,17 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient; import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.StaticServerList; import org.springframework.cloud.netflix.ribbon.StaticServerList;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy; import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.netflix.zuul.RoutesEndpoint; import org.springframework.cloud.netflix.zuul.RoutesEndpoint;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -39,21 +37,21 @@ import com.netflix.zuul.context.RequestContext; ...@@ -39,21 +37,21 @@ import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapperIntegrationTests.SERVICE_ID; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
/** /**
* @author Stéphane Leroy * @author Stéphane Leroy
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SampleCustomZuulProxyApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = { @SpringBootTest(webEnvironment = RANDOM_PORT,
"spring.application.name=regex-test-application", "spring.jmx.enabled=false", properties = { "spring.application.name=regex-test-application", "spring.jmx.enabled=false",
"eureka.client.enabled=false" }) "eureka.client.enabled=false" })
@DirtiesContext @DirtiesContext
public class PatternServiceRouteMapperIntegrationTests { public class PatternServiceRouteMapperIntegrationTests {
protected static final String SERVICE_ID = "domain-service-v1"; protected static final String SERVICE_ID = "domain-service-v1";
@Value("${local.server.port}") @LocalServerPort
private int port; private int port;
@Autowired @Autowired
...@@ -94,14 +92,12 @@ public class PatternServiceRouteMapperIntegrationTests { ...@@ -94,14 +92,12 @@ public class PatternServiceRouteMapperIntegrationTests {
assertEquals("Get 1", result.getBody()); assertEquals("Get 1", result.getBody());
} }
} @SpringBootConfiguration
@EnableAutoConfiguration
@Configuration @RestController
@EnableAutoConfiguration @EnableZuulProxy
@RestController @RibbonClient(value = SERVICE_ID, configuration = SimpleRibbonClientConfiguration.class)
@EnableZuulProxy protected static class SampleCustomZuulProxyApplication {
@RibbonClient(value = SERVICE_ID, configuration = SimpleRibbonClientConfiguration.class)
class SampleCustomZuulProxyApplication {
@Bean @Bean
public DiscoveryClient discoveryClient() { public DiscoveryClient discoveryClient() {
...@@ -124,19 +120,16 @@ class SampleCustomZuulProxyApplication { ...@@ -124,19 +120,16 @@ class SampleCustomZuulProxyApplication {
"${version}/${domain}/${name}"); "${version}/${domain}/${name}");
} }
public static void main(String[] args) {
SpringApplication.run(SampleCustomZuulProxyApplication.class, args);
} }
}
@Configuration protected static class SimpleRibbonClientConfiguration {
class SimpleRibbonClientConfiguration {
@Value("${local.server.port}") @LocalServerPort
private int port = 0; private int port = 0;
@Bean @Bean
public ServerList<Server> ribbonServerList() { public ServerList<Server> ribbonServerList() {
return new StaticServerList<>(new Server("localhost", this.port)); return new StaticServerList<>(new Server("localhost", this.port));
} }
}
} }
...@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.zuul.filters.post; ...@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.zuul.filters.post;
import com.netflix.util.Pair; import com.netflix.util.Pair;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.cloud.netflix.zuul.filters.Route; import org.springframework.cloud.netflix.zuul.filters.Route;
...@@ -57,6 +58,12 @@ public class LocationRewriteFilterTests { ...@@ -57,6 +58,12 @@ public class LocationRewriteFilterTests {
RequestContext.testSetCurrentContext(context); RequestContext.testSetCurrentContext(context);
} }
@After
public void reset() {
RequestContext.getCurrentContext().clear();
}
@Test @Test
public void shouldRewriteLocationHeadersWithRoutePrefix() { public void shouldRewriteLocationHeadersWithRoutePrefix() {
RequestContext context = RequestContext.getCurrentContext(); RequestContext context = RequestContext.getCurrentContext();
......
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