|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2013-2020 the original author or authors. |
|
|
|
|
* Copyright 2013-2022 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -17,6 +17,7 @@
@@ -17,6 +17,7 @@
|
|
|
|
|
package org.springframework.cloud.gateway.filter.factory; |
|
|
|
|
|
|
|
|
|
import java.net.URI; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.LinkedHashSet; |
|
|
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
@ -26,6 +27,7 @@ import reactor.core.publisher.Mono;
@@ -26,6 +27,7 @@ import reactor.core.publisher.Mono;
|
|
|
|
|
import org.springframework.cloud.gateway.filter.GatewayFilter; |
|
|
|
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
|
|
|
|
import org.springframework.cloud.gateway.filter.factory.PrefixPathGatewayFilterFactory.Config; |
|
|
|
|
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils; |
|
|
|
|
import org.springframework.mock.http.server.reactive.MockServerHttpRequest; |
|
|
|
|
import org.springframework.mock.web.server.MockServerWebExchange; |
|
|
|
|
import org.springframework.web.server.ServerWebExchange; |
|
|
|
@ -46,11 +48,33 @@ public class PrefixPathGatewayFilterFactoryTest {
@@ -46,11 +48,33 @@ public class PrefixPathGatewayFilterFactoryTest {
|
|
|
|
|
testPrefixPathFilter("/foo", "/hello%20world", "/foo/hello%20world"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testPrefixPathWithVariable() { |
|
|
|
|
HashMap<String, String> variables = new HashMap<>(); |
|
|
|
|
variables.put("id", "foo"); |
|
|
|
|
testPrefixPathFilter("/{id}", "/bar", "/foo/bar", variables); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testPrefixPathWithMultipleVariables() { |
|
|
|
|
HashMap<String, String> variables = new HashMap<>(); |
|
|
|
|
variables.put("id", "foo"); |
|
|
|
|
variables.put("hello", "world"); |
|
|
|
|
variables.put("product", "bar"); |
|
|
|
|
testPrefixPathFilter("/{id}/v1/{hello}/{product}", "/test", "/foo/v1/world/bar/test", variables); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void testPrefixPathFilter(String prefix, String path, String expectedPath) { |
|
|
|
|
testPrefixPathFilter(prefix, path, expectedPath, new HashMap<>()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void testPrefixPathFilter(String prefix, String path, String expectedPath, |
|
|
|
|
HashMap<String, String> variables) { |
|
|
|
|
GatewayFilter filter = new PrefixPathGatewayFilterFactory().apply(c -> c.setPrefix(prefix)); |
|
|
|
|
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost" + path).build(); |
|
|
|
|
|
|
|
|
|
ServerWebExchange exchange = MockServerWebExchange.from(request); |
|
|
|
|
ServerWebExchangeUtils.putUriTemplateVariables(exchange, variables); |
|
|
|
|
|
|
|
|
|
GatewayFilterChain filterChain = mock(GatewayFilterChain.class); |
|
|
|
|
|
|
|
|
|