From 5d097be8721617329173dd2851eec5b8e961dc3f Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Mon, 2 Apr 2018 12:41:42 -0400 Subject: [PATCH] adds variables with a prefix --- .../SetPathGatewayFilterFactoryTests.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactoryTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactoryTests.java index 2300f0fcf..2b37a6312 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactoryTests.java @@ -37,10 +37,8 @@ import org.springframework.web.util.pattern.PathPattern.PathMatchInfo; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.springframework.cloud.gateway.filter.factory.SetPathGatewayFilterFactory.TEMPLATE_KEY; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE; -import static org.springframework.tuple.TupleBuilder.tuple; import reactor.core.publisher.Mono; @@ -52,21 +50,29 @@ public class SetPathGatewayFilterFactoryTests { @Test public void setPathFilterWorks() { HashMap variables = new HashMap<>(); - testRewriteFilter("/baz/bar", "/foo/bar", "/baz/bar", variables); + testFilter("/baz/bar","/baz/bar", variables); } @Test public void setPathFilterWithTemplateVarsWorks() { HashMap variables = new HashMap<>(); variables.put("id", "123"); - testRewriteFilter("/bar/baz/{id}", "/foo/123", "/bar/baz/123", variables); + testFilter("/bar/baz/{id}","/bar/baz/123", variables); } - private void testRewriteFilter(String template, String actualPath, String expectedPath, HashMap variables) { + @Test + public void setPathFilterWithTemplatePrefixVarsWorks() { + HashMap variables = new HashMap<>(); + variables.put("org", "123"); + variables.put("scope", "abc"); + testFilter("/{org}/{scope}/function","/123/abc/function", variables); + } + + private void testFilter(String template, String expectedPath, HashMap variables) { GatewayFilter filter = new SetPathGatewayFilterFactory().apply(c -> c.setTemplate(template)); MockServerHttpRequest request = MockServerHttpRequest - .get("http://localhost"+ actualPath) + .get("http://localhost") .build(); ServerWebExchange exchange = MockServerWebExchange.from(request);