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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user