WebFlux AbstractUrlHandlerMapping support URI vars

Closes gh-25648
This commit is contained in:
Rossen Stoyanchev
2020-08-28 21:56:28 +01:00
parent a8d953afa4
commit c4e1e4ee1e
2 changed files with 21 additions and 2 deletions

View File

@@ -17,6 +17,8 @@
package org.springframework.web.reactive.handler;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import org.junit.jupiter.api.Test;
@@ -115,6 +117,19 @@ public class SimpleUrlHandlerMappingTests {
}
}
@Test
void uriTemplateVariables() {
Object handler = new Object();
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
mapping.registerHandlers(Collections.singletonMap("/foo/{bar}/baz", handler));
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo/123/baz").build());
Object expected = mapping.getHandler(exchange).block();
assertThat(expected).isSameAs(handler);
Map<String, String> vars = exchange.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
assertThat(vars).isNotNull().containsEntry("bar", "123");
}
@Configuration
static class WebConfig {