Various improvements to web.reactive.function

This commit introduces the following changes to web.reactive.function:

- Added RouterFunction.andRoute(), a combination of RouterFunction.and()
with RouterFunctions.route()
- ServerRequest.pathVariable() returns String instead of
Optional<String>. An exception is thrown if the variable is not present.
- Added HandlerFilterFunction.andThen and HandlerFilterFunction.apply()
This commit is contained in:
Arjen Poutsma
2016-10-13 16:59:33 +02:00
parent 921bf5fb70
commit 59e4326989
7 changed files with 67 additions and 9 deletions

View File

@@ -119,7 +119,15 @@ public class DefaultServerRequestTests {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
when(mockExchange.getAttribute(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE)).thenReturn(Optional.of(pathVariables));
assertEquals(Optional.of("bar"), defaultRequest.pathVariable("foo"));
assertEquals("bar", defaultRequest.pathVariable("foo"));
}
@Test(expected = IllegalArgumentException.class)
public void pathVariableNotFound() throws Exception {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
when(mockExchange.getAttribute(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE)).thenReturn(Optional.of(pathVariables));
assertEquals("bar", defaultRequest.pathVariable("baz"));
}
@Test

View File

@@ -116,9 +116,9 @@ public class ServerRequestWrapperTests {
public void pathVariable() throws Exception {
String name = "foo";
String value = "bar";
when(mockRequest.pathVariable(name)).thenReturn(Optional.of(value));
when(mockRequest.pathVariable(name)).thenReturn(value);
assertEquals(Optional.of(value), wrapper.pathVariable(name));
assertEquals(value, wrapper.pathVariable(name));
}
@Test