Browse Source

adds test with variables in the prefix

pull/266/head
Spencer Gibb 7 years ago
parent
commit
b61eaef266
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 12
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactoryTests.java
  2. 5
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/HttpBinCompatibleController.java
  3. 9
      spring-cloud-gateway-core/src/test/resources/application.yml

12
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactoryTests.java

@ -25,6 +25,7 @@ import org.springframework.boot.test.context.SpringBootTest; @@ -25,6 +25,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.gateway.handler.RoutePredicateHandlerMapping;
import org.springframework.cloud.gateway.test.BaseWebClientTests;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpHeaders;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@ -37,6 +38,17 @@ public class PathRoutePredicateFactoryTests extends BaseWebClientTests { @@ -37,6 +38,17 @@ public class PathRoutePredicateFactoryTests extends BaseWebClientTests {
@Test
public void pathRouteWorks() {
testClient.get().uri("/abc/123/function")
.header(HttpHeaders.HOST, "www.path.org")
.exchange()
.expectStatus().isOk()
.expectHeader().valueEquals(HANDLER_MAPPER_HEADER, RoutePredicateHandlerMapping.class.getSimpleName())
.expectHeader().valueEquals("transfer-encoding", "chunked")
.expectHeader().valueEquals(ROUTE_ID_HEADER, "path_test");
}
@Test
public void defaultPathRouteWorks() {
testClient.get().uri("/get")
.exchange()
.expectStatus().isOk()

5
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/HttpBinCompatibleController.java

@ -62,6 +62,11 @@ public class HttpBinCompatibleController { @@ -62,6 +62,11 @@ public class HttpBinCompatibleController {
return get(exchange).delayElement(Duration.ofSeconds(delay));
}
@RequestMapping(path = "/anything/{anything}", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<Map<String, Object>> anything(ServerWebExchange exchange, @PathVariable String anything) {
return get(exchange);
}
@RequestMapping(path = "/get", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<Map<String, Object>> get(ServerWebExchange exchange) {
return getHeaders(exchange).map(map -> {

9
spring-cloud-gateway-core/src/test/resources/application.yml

@ -117,6 +117,15 @@ spring: @@ -117,6 +117,15 @@ spring:
- Host=**.notbetween.org
- Between=1000-03-13T10:39:37.518-04:00[America/New_York],1002-03-13T10:39:37.518-04:00[America/New_York]
# =====================================
- id: path_test
uri: ${test.uri}
predicates:
- Path=/{org}/{scope}/function
- Host=**.path.org
filters:
- SetPath=/anything/{org}{scope}
# =====================================
- id: redirect_to_test
uri: ${test.uri}

Loading…
Cancel
Save