Rename RoutingFunction to RouterFunction
This commit is contained in:
@@ -83,7 +83,7 @@ class DefaultRequest implements Request {
|
||||
|
||||
@Override
|
||||
public Map<String, String> pathVariables() {
|
||||
return this.exchange.<Map<String, String>>getAttribute(RoutingFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE).
|
||||
return this.exchange.<Map<String, String>>getAttribute(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE).
|
||||
orElseGet(Collections::emptyMap);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ import org.springframework.util.Assert;
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.0
|
||||
* @see RequestPredicates
|
||||
* @see RoutingFunctions#route(RequestPredicate, HandlerFunction)
|
||||
* @see RoutingFunctions#subroute(RequestPredicate, RoutingFunction)
|
||||
* @see RouterFunctions#route(RequestPredicate, HandlerFunction)
|
||||
* @see RouterFunctions#subroute(RequestPredicate, RouterFunction)
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface RequestPredicate {
|
||||
|
||||
@@ -249,7 +249,7 @@ public abstract class RequestPredicates {
|
||||
if (request instanceof DefaultRequest) {
|
||||
DefaultRequest defaultRequest = (DefaultRequest) request;
|
||||
Map<String, String> uriTemplateVariables = this.pathMatcher.extractUriTemplateVariables(this.pattern, path);
|
||||
defaultRequest.exchange().getAttributes().put(RoutingFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVariables);
|
||||
defaultRequest.exchange().getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVariables);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ import java.util.Optional;
|
||||
* @param <T> the type of the {@linkplain HandlerFunction handler function} to route to
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.0
|
||||
* @see RoutingFunctions
|
||||
* @see RouterFunctions
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface RoutingFunction<T> {
|
||||
public interface RouterFunction<T> {
|
||||
|
||||
/**
|
||||
* Return the {@linkplain HandlerFunction handler function} that matches the given request.
|
||||
@@ -46,7 +46,7 @@ public interface RoutingFunction<T> {
|
||||
* @return a composed function that first routes with this function and then the {@code other} function if this
|
||||
* function has no result
|
||||
*/
|
||||
default RoutingFunction<T> andSame(RoutingFunction<T> other) {
|
||||
default RouterFunction<T> andSame(RouterFunction<T> other) {
|
||||
return request -> {
|
||||
Optional<HandlerFunction<T>> result = this.route(request);
|
||||
return result.isPresent() ? result : other.route(request);
|
||||
@@ -62,12 +62,12 @@ public interface RoutingFunction<T> {
|
||||
* @return a composed function that first routes with this function and then the {@code other} function if this
|
||||
* function has no result
|
||||
*/
|
||||
default RoutingFunction<?> and(RoutingFunction<?> other) {
|
||||
default RouterFunction<?> and(RouterFunction<?> other) {
|
||||
return request -> {
|
||||
Optional<HandlerFunction<Object>> result = this.route(request).
|
||||
map(RoutingFunctions::cast);
|
||||
map(RouterFunctions::cast);
|
||||
return result.isPresent() ? result : other.route(request)
|
||||
.map(RoutingFunctions::cast);
|
||||
.map(RouterFunctions::cast);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public interface RoutingFunction<T> {
|
||||
* @param <S> the filter return type
|
||||
* @return the filtered routing function
|
||||
*/
|
||||
default <S> RoutingFunction<S> filter(FilterFunction<T, S> filterFunction) {
|
||||
default <S> RouterFunction<S> filter(FilterFunction<T, S> filterFunction) {
|
||||
return request -> this.route(request)
|
||||
.map(handlerFunction -> filterRequest -> filterFunction.filter(filterRequest, handlerFunction));
|
||||
}
|
||||
@@ -30,36 +30,36 @@ import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
|
||||
/**
|
||||
* <strong>Central entry point to Spring's functional web framework.</strong>
|
||||
* Exposes routing functionality, such as to
|
||||
* {@linkplain #route(RequestPredicate, HandlerFunction) create} a {@code RoutingFunction} given a
|
||||
* {@linkplain #route(RequestPredicate, HandlerFunction) create} a {@code RouterFunction} given a
|
||||
* {@code RequestPredicate} and {@code HandlerFunction}, and to do further
|
||||
* {@linkplain #subroute(RequestPredicate, RoutingFunction) subrouting} on an existing routing
|
||||
* {@linkplain #subroute(RequestPredicate, RouterFunction) subrouting} on an existing routing
|
||||
* function.
|
||||
*
|
||||
* <p>Additionally, this class can {@linkplain #toHttpHandler(RoutingFunction) transform} a
|
||||
* {@code RoutingFunction} into an {@code HttpHandler}, which can be run in Servlet 3.1+,
|
||||
* <p>Additionally, this class can {@linkplain #toHttpHandler(RouterFunction) transform} a
|
||||
* {@code RouterFunction} into an {@code HttpHandler}, which can be run in Servlet 3.1+,
|
||||
* Reactor, RxNetty, or Undertow.
|
||||
* And it can {@linkplain #toHandlerMapping(RoutingFunction, Configuration) transform} a
|
||||
* {@code RoutingFunction} into an {@code HandlerMapping}, which can be run in a
|
||||
* And it can {@linkplain #toHandlerMapping(RouterFunction, Configuration) transform} a
|
||||
* {@code RouterFunction} into an {@code HandlerMapping}, which can be run in a
|
||||
* {@code DispatcherHandler}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.0
|
||||
*
|
||||
*/
|
||||
public abstract class RoutingFunctions {
|
||||
public abstract class RouterFunctions {
|
||||
|
||||
private static final HandlerFunction<Void> NOT_FOUND_HANDLER = request -> Response.notFound().build();
|
||||
|
||||
/**
|
||||
* Name of the {@link ServerWebExchange} attribute that contains the {@link Request}.
|
||||
*/
|
||||
public static final String REQUEST_ATTRIBUTE = RoutingFunctions.class.getName() + ".request";
|
||||
public static final String REQUEST_ATTRIBUTE = RouterFunctions.class.getName() + ".request";
|
||||
|
||||
/**
|
||||
* Name of the {@link ServerWebExchange} attribute that contains the URI
|
||||
* templates map, mapping variable names to values.
|
||||
*/
|
||||
public static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE = RoutingFunctions.class.getName() + ".uriTemplateVariables";
|
||||
public static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE = RouterFunctions.class.getName() + ".uriTemplateVariables";
|
||||
|
||||
/**
|
||||
* Route to the given handler function if the given request predicate applies.
|
||||
@@ -70,7 +70,7 @@ public abstract class RoutingFunctions {
|
||||
* @return a routing function that routes to {@code handlerFunction} if {@code predicate} evaluates to {@code true}
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
public static <T> RoutingFunction<T> route(RequestPredicate predicate, HandlerFunction<T> handlerFunction) {
|
||||
public static <T> RouterFunction<T> route(RequestPredicate predicate, HandlerFunction<T> handlerFunction) {
|
||||
Assert.notNull(predicate, "'predicate' must not be null");
|
||||
Assert.notNull(handlerFunction, "'handlerFunction' must not be null");
|
||||
|
||||
@@ -81,19 +81,19 @@ public abstract class RoutingFunctions {
|
||||
* Route to the given routing function if the given request predicate applies.
|
||||
*
|
||||
* @param predicate the predicate to test
|
||||
* @param routingFunction the routing function to route to
|
||||
* @param routerFunction the routing function to route to
|
||||
* @param <T> the type of the handler function
|
||||
* @return a routing function that routes to {@code routingFunction} if {@code predicate} evaluates to {@code true}
|
||||
* @return a routing function that routes to {@code routerFunction} if {@code predicate} evaluates to {@code true}
|
||||
* @see RequestPredicates
|
||||
*/
|
||||
public static <T> RoutingFunction<T> subroute(RequestPredicate predicate, RoutingFunction<T> routingFunction) {
|
||||
public static <T> RouterFunction<T> subroute(RequestPredicate predicate, RouterFunction<T> routerFunction) {
|
||||
Assert.notNull(predicate, "'predicate' must not be null");
|
||||
Assert.notNull(routingFunction, "'routingFunction' must not be null");
|
||||
Assert.notNull(routerFunction, "'routerFunction' must not be null");
|
||||
|
||||
return request -> {
|
||||
if (predicate.test(request)) {
|
||||
Request subRequest = predicate.subRequest(request);
|
||||
return routingFunction.route(subRequest);
|
||||
return routerFunction.route(subRequest);
|
||||
}
|
||||
else {
|
||||
return Optional.empty();
|
||||
@@ -102,7 +102,7 @@ public abstract class RoutingFunctions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@linkplain RoutingFunction routing function} into a {@link HttpHandler}.
|
||||
* Converts the given {@linkplain RouterFunction routing function} into a {@link HttpHandler}.
|
||||
* This conversion uses the {@linkplain Configuration#builder() default configuration}.
|
||||
*
|
||||
* <p>The returned {@code HttpHandler} can be adapted to run in
|
||||
@@ -117,15 +117,15 @@ public abstract class RoutingFunctions {
|
||||
* {@link org.springframework.http.server.reactive.UndertowHttpHandlerAdapter}.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param routingFunction the routing function to convert
|
||||
* @param routerFunction the routing function to convert
|
||||
* @return an http handler that handles HTTP request using the given routing function
|
||||
*/
|
||||
public static HttpHandler toHttpHandler(RoutingFunction<?> routingFunction) {
|
||||
return toHttpHandler(routingFunction, defaultConfiguration());
|
||||
public static HttpHandler toHttpHandler(RouterFunction<?> routerFunction) {
|
||||
return toHttpHandler(routerFunction, defaultConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@linkplain RoutingFunction routing function} into a {@link HttpHandler},
|
||||
* Converts the given {@linkplain RouterFunction routing function} into a {@link HttpHandler},
|
||||
* using the given configuration.
|
||||
*
|
||||
* <p>The returned {@code HttpHandler} can be adapted to run in
|
||||
@@ -140,61 +140,61 @@ public abstract class RoutingFunctions {
|
||||
* {@link org.springframework.http.server.reactive.UndertowHttpHandlerAdapter}.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param routingFunction the routing function to convert
|
||||
* @param routerFunction the routing function to convert
|
||||
* @param configuration the configuration to use
|
||||
* @return an http handler that handles HTTP request using the given routing function
|
||||
*/
|
||||
public static HttpHandler toHttpHandler(RoutingFunction<?> routingFunction, Configuration configuration) {
|
||||
Assert.notNull(routingFunction, "'routingFunction' must not be null");
|
||||
public static HttpHandler toHttpHandler(RouterFunction<?> routerFunction, Configuration configuration) {
|
||||
Assert.notNull(routerFunction, "'routerFunction' must not be null");
|
||||
Assert.notNull(configuration, "'configuration' must not be null");
|
||||
|
||||
return new HttpWebHandlerAdapter(exchange -> {
|
||||
Request request = new DefaultRequest(exchange, configuration);
|
||||
addAttributes(exchange, request);
|
||||
|
||||
HandlerFunction<?> handlerFunction = routingFunction.route(request).orElse(notFound());
|
||||
HandlerFunction<?> handlerFunction = routerFunction.route(request).orElse(notFound());
|
||||
Response<?> response = handlerFunction.handle(request);
|
||||
return response.writeTo(exchange, configuration);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@code RoutingFunction} into a {@code HandlerMapping}.
|
||||
* Converts the given {@code RouterFunction} into a {@code HandlerMapping}.
|
||||
* This conversion uses the {@linkplain Configuration#builder() default configuration}.
|
||||
*
|
||||
* <p>The returned {@code HandlerMapping} can be run in a
|
||||
* {@link org.springframework.web.reactive.DispatcherHandler}.
|
||||
*
|
||||
* @param routingFunction the routing function to convert
|
||||
* @param routerFunction the routing function to convert
|
||||
* @return an handler mapping that maps HTTP request to a handler using the given routing function
|
||||
* @see org.springframework.web.reactive.function.support.HandlerFunctionAdapter
|
||||
* @see org.springframework.web.reactive.function.support.ResponseResultHandler
|
||||
*/
|
||||
public static HandlerMapping toHandlerMapping(RoutingFunction<?> routingFunction) {
|
||||
return toHandlerMapping(routingFunction, defaultConfiguration());
|
||||
public static HandlerMapping toHandlerMapping(RouterFunction<?> routerFunction) {
|
||||
return toHandlerMapping(routerFunction, defaultConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@linkplain RoutingFunction routing function} into a {@link HandlerMapping}
|
||||
* Converts the given {@linkplain RouterFunction routing function} into a {@link HandlerMapping}
|
||||
* using the given configuration.
|
||||
*
|
||||
* <p>The returned {@code HandlerMapping} can be run in a
|
||||
* {@link org.springframework.web.reactive.DispatcherHandler}.
|
||||
*
|
||||
* @param routingFunction the routing function to convert
|
||||
* @param routerFunction the routing function to convert
|
||||
* @return an handler mapping that maps HTTP request to a handler using the given routing function
|
||||
* @see org.springframework.web.reactive.function.support.HandlerFunctionAdapter
|
||||
* @see org.springframework.web.reactive.function.support.ResponseResultHandler
|
||||
*/
|
||||
public static HandlerMapping toHandlerMapping(RoutingFunction<?> routingFunction, Configuration configuration) {
|
||||
Assert.notNull(routingFunction, "'routingFunction' must not be null");
|
||||
public static HandlerMapping toHandlerMapping(RouterFunction<?> routerFunction, Configuration configuration) {
|
||||
Assert.notNull(routerFunction, "'routerFunction' must not be null");
|
||||
Assert.notNull(configuration, "'configuration' must not be null");
|
||||
|
||||
return exchange -> {
|
||||
Request request = new DefaultRequest(exchange, configuration);
|
||||
addAttributes(exchange, request);
|
||||
|
||||
Optional<? extends HandlerFunction<?>> route = routingFunction.route(request);
|
||||
Optional<? extends HandlerFunction<?>> route = routerFunction.route(request);
|
||||
return Mono.justOrEmpty(route);
|
||||
};
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import org.springframework.web.reactive.HandlerResult;
|
||||
import org.springframework.web.reactive.function.HandlerFunction;
|
||||
import org.springframework.web.reactive.function.Request;
|
||||
import org.springframework.web.reactive.function.Response;
|
||||
import org.springframework.web.reactive.function.RoutingFunctions;
|
||||
import org.springframework.web.reactive.function.RouterFunctions;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ public class HandlerFunctionAdapter implements HandlerAdapter {
|
||||
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
|
||||
HandlerFunction<?> handlerFunction = (HandlerFunction<?>) handler;
|
||||
Request request =
|
||||
exchange.<Request>getAttribute(RoutingFunctions.REQUEST_ATTRIBUTE)
|
||||
exchange.<Request>getAttribute(RouterFunctions.REQUEST_ATTRIBUTE)
|
||||
.orElseThrow(() -> new IllegalStateException("Could not find Request in exchange attributes"));
|
||||
|
||||
Response<?> response = handlerFunction.handle(request);
|
||||
|
||||
@@ -22,14 +22,14 @@ import org.springframework.http.server.reactive.HttpHandler;
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public abstract class AbstractRoutingFunctionIntegrationTests
|
||||
public abstract class AbstractRouterFunctionIntegrationTests
|
||||
extends AbstractHttpHandlerIntegrationTests {
|
||||
|
||||
@Override
|
||||
protected final HttpHandler createHttpHandler() {
|
||||
RoutingFunction<?> routingFunction = routingFunction();
|
||||
return RoutingFunctions.toHttpHandler(routingFunction);
|
||||
RouterFunction<?> routerFunction = routerFunction();
|
||||
return RouterFunctions.toHttpHandler(routerFunction);
|
||||
}
|
||||
|
||||
protected abstract RoutingFunction<?> routingFunction();
|
||||
protected abstract RouterFunction<?> routerFunction();
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class DefaultRequestTests {
|
||||
@Test
|
||||
public void pathVariable() throws Exception {
|
||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||
when(mockExchange.getAttribute(RoutingFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE)).thenReturn(Optional.of(pathVariables));
|
||||
when(mockExchange.getAttribute(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE)).thenReturn(Optional.of(pathVariables));
|
||||
|
||||
assertEquals(Optional.of("bar"), defaultRequest.pathVariable("foo"));
|
||||
}
|
||||
@@ -125,7 +125,7 @@ public class DefaultRequestTests {
|
||||
@Test
|
||||
public void pathVariables() throws Exception {
|
||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||
when(mockExchange.getAttribute(RoutingFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE)).thenReturn(Optional.of(pathVariables));
|
||||
when(mockExchange.getAttribute(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE)).thenReturn(Optional.of(pathVariables));
|
||||
|
||||
assertEquals(pathVariables, defaultRequest.pathVariables());
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.web.reactive.function.RoutingFunctions.route;
|
||||
import static org.springframework.web.reactive.function.RouterFunctions.route;
|
||||
|
||||
/**
|
||||
* Tests the use of {@link HandlerFunction} and {@link RoutingFunction} in a
|
||||
* Tests the use of {@link HandlerFunction} and {@link RouterFunction} in a
|
||||
* {@link DispatcherHandler}.
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@@ -117,9 +117,9 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HandlerMapping handlerMapping(RoutingFunction<?> routingFunction,
|
||||
public HandlerMapping handlerMapping(RouterFunction<?> routerFunction,
|
||||
ApplicationContext applicationContext) {
|
||||
return RoutingFunctions.toHandlerMapping(routingFunction,
|
||||
return RouterFunctions.toHandlerMapping(routerFunction,
|
||||
new org.springframework.web.reactive.function.Configuration() {
|
||||
@Override
|
||||
public Supplier<Stream<HttpMessageReader<?>>> messageReaders() {
|
||||
@@ -139,7 +139,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RoutingFunction<?> routingFunction() {
|
||||
public RouterFunction<?> routerFunction() {
|
||||
PersonHandler personHandler = personHandler();
|
||||
return route(RequestPredicates.GET("/mono"), personHandler::mono)
|
||||
.and(route(RequestPredicates.GET("/flux"), personHandler::flux));
|
||||
|
||||
@@ -37,13 +37,13 @@ import static org.springframework.web.reactive.function.BodyExtractors.toMono;
|
||||
import static org.springframework.web.reactive.function.BodyPopulators.fromPublisher;
|
||||
import static org.springframework.web.reactive.function.RequestPredicates.GET;
|
||||
import static org.springframework.web.reactive.function.RequestPredicates.POST;
|
||||
import static org.springframework.web.reactive.function.RoutingFunctions.route;
|
||||
import static org.springframework.web.reactive.function.RouterFunctions.route;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class PublisherHandlerFunctionIntegrationTests
|
||||
extends AbstractRoutingFunctionIntegrationTests {
|
||||
extends AbstractRouterFunctionIntegrationTests {
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class PublisherHandlerFunctionIntegrationTests
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RoutingFunction<?> routingFunction() {
|
||||
protected RouterFunction<?> routerFunction() {
|
||||
PersonHandler personHandler = new PersonHandler();
|
||||
return route(GET("/mono"), personHandler::mono)
|
||||
.and(route(POST("/mono"), personHandler::postMono))
|
||||
|
||||
@@ -29,15 +29,15 @@ import static org.springframework.web.reactive.function.BodyPopulators.fromObjec
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class RoutingFunctionTests {
|
||||
public class RouterFunctionTests {
|
||||
|
||||
@Test
|
||||
public void andSame() throws Exception {
|
||||
HandlerFunction<Void> handlerFunction = request -> Response.ok().build();
|
||||
RoutingFunction<Void> routingFunction1 = request -> Optional.empty();
|
||||
RoutingFunction<Void> routingFunction2 = request -> Optional.of(handlerFunction);
|
||||
RouterFunction<Void> routerFunction1 = request -> Optional.empty();
|
||||
RouterFunction<Void> routerFunction2 = request -> Optional.of(handlerFunction);
|
||||
|
||||
RoutingFunction<Void> result = routingFunction1.andSame(routingFunction2);
|
||||
RouterFunction<Void> result = routerFunction1.andSame(routerFunction2);
|
||||
assertNotNull(result);
|
||||
|
||||
MockRequest request = MockRequest.builder().build();
|
||||
@@ -49,10 +49,10 @@ public class RoutingFunctionTests {
|
||||
@Test
|
||||
public void and() throws Exception {
|
||||
HandlerFunction<String> handlerFunction = request -> Response.ok().body(fromObject("42"));
|
||||
RoutingFunction<Void> routingFunction1 = request -> Optional.empty();
|
||||
RoutingFunction<String> routingFunction2 = request -> Optional.of(handlerFunction);
|
||||
RouterFunction<Void> routerFunction1 = request -> Optional.empty();
|
||||
RouterFunction<String> routerFunction2 = request -> Optional.of(handlerFunction);
|
||||
|
||||
RoutingFunction<?> result = routingFunction1.and(routingFunction2);
|
||||
RouterFunction<?> result = routerFunction1.and(routerFunction2);
|
||||
assertNotNull(result);
|
||||
|
||||
MockRequest request = MockRequest.builder().build();
|
||||
@@ -64,14 +64,14 @@ public class RoutingFunctionTests {
|
||||
@Test
|
||||
public void filter() throws Exception {
|
||||
HandlerFunction<String> handlerFunction = request -> Response.ok().body(fromObject("42"));
|
||||
RoutingFunction<String> routingFunction = request -> Optional.of(handlerFunction);
|
||||
RouterFunction<String> routerFunction = request -> Optional.of(handlerFunction);
|
||||
|
||||
FilterFunction<String, Integer> filterFunction = (request, next) -> {
|
||||
Response<String> response = next.handle(request);
|
||||
int i = Integer.parseInt(response.body());
|
||||
return Response.ok().body(fromObject(i));
|
||||
};
|
||||
RoutingFunction<Integer> result = routingFunction.filter(filterFunction);
|
||||
RouterFunction<Integer> result = routerFunction.filter(filterFunction);
|
||||
assertNotNull(result);
|
||||
|
||||
MockRequest request = MockRequest.builder().build();
|
||||
@@ -44,7 +44,7 @@ import static org.mockito.Mockito.when;
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class RoutingFunctionsTests {
|
||||
public class RouterFunctionsTests {
|
||||
|
||||
@Test
|
||||
public void routeMatch() throws Exception {
|
||||
@@ -54,7 +54,7 @@ public class RoutingFunctionsTests {
|
||||
RequestPredicate requestPredicate = mock(RequestPredicate.class);
|
||||
when(requestPredicate.test(request)).thenReturn(true);
|
||||
|
||||
RoutingFunction<Void> result = RoutingFunctions.route(requestPredicate, handlerFunction);
|
||||
RouterFunction<Void> result = RouterFunctions.route(requestPredicate, handlerFunction);
|
||||
assertNotNull(result);
|
||||
|
||||
Optional<HandlerFunction<Void>> resultHandlerFunction = result.route(request);
|
||||
@@ -70,7 +70,7 @@ public class RoutingFunctionsTests {
|
||||
RequestPredicate requestPredicate = mock(RequestPredicate.class);
|
||||
when(requestPredicate.test(request)).thenReturn(false);
|
||||
|
||||
RoutingFunction<Void> result = RoutingFunctions.route(requestPredicate, handlerFunction);
|
||||
RouterFunction<Void> result = RouterFunctions.route(requestPredicate, handlerFunction);
|
||||
assertNotNull(result);
|
||||
|
||||
Optional<HandlerFunction<Void>> resultHandlerFunction = result.route(request);
|
||||
@@ -80,13 +80,13 @@ public class RoutingFunctionsTests {
|
||||
@Test
|
||||
public void subrouteMatch() throws Exception {
|
||||
HandlerFunction<Void> handlerFunction = request -> Response.ok().build();
|
||||
RoutingFunction<Void> routingFunction = request -> Optional.of(handlerFunction);
|
||||
RouterFunction<Void> routerFunction = request -> Optional.of(handlerFunction);
|
||||
|
||||
MockRequest request = MockRequest.builder().build();
|
||||
RequestPredicate requestPredicate = mock(RequestPredicate.class);
|
||||
when(requestPredicate.test(request)).thenReturn(true);
|
||||
|
||||
RoutingFunction<Void> result = RoutingFunctions.subroute(requestPredicate, routingFunction);
|
||||
RouterFunction<Void> result = RouterFunctions.subroute(requestPredicate, routerFunction);
|
||||
assertNotNull(result);
|
||||
|
||||
Optional<HandlerFunction<Void>> resultHandlerFunction = result.route(request);
|
||||
@@ -97,13 +97,13 @@ public class RoutingFunctionsTests {
|
||||
@Test
|
||||
public void subrouteNoMatch() throws Exception {
|
||||
HandlerFunction<Void> handlerFunction = request -> Response.ok().build();
|
||||
RoutingFunction<Void> routingFunction = request -> Optional.of(handlerFunction);
|
||||
RouterFunction<Void> routerFunction = request -> Optional.of(handlerFunction);
|
||||
|
||||
MockRequest request = MockRequest.builder().build();
|
||||
RequestPredicate requestPredicate = mock(RequestPredicate.class);
|
||||
when(requestPredicate.test(request)).thenReturn(false);
|
||||
|
||||
RoutingFunction<Void> result = RoutingFunctions.subroute(requestPredicate, routingFunction);
|
||||
RouterFunction<Void> result = RouterFunctions.subroute(requestPredicate, routerFunction);
|
||||
assertNotNull(result);
|
||||
|
||||
Optional<HandlerFunction<Void>> resultHandlerFunction = result.route(request);
|
||||
@@ -127,14 +127,14 @@ public class RoutingFunctionsTests {
|
||||
HandlerFunction handlerFunction = mock(HandlerFunction.class);
|
||||
when(handlerFunction.handle(any(Request.class))).thenReturn(response);
|
||||
|
||||
RoutingFunction routingFunction = mock(RoutingFunction.class);
|
||||
when(routingFunction.route(any(Request.class))).thenReturn(Optional.of(handlerFunction));
|
||||
RouterFunction routerFunction = mock(RouterFunction.class);
|
||||
when(routerFunction.route(any(Request.class))).thenReturn(Optional.of(handlerFunction));
|
||||
|
||||
RequestPredicate requestPredicate = mock(RequestPredicate.class);
|
||||
when(requestPredicate.test(request)).thenReturn(false);
|
||||
|
||||
|
||||
HttpHandler result = RoutingFunctions.toHttpHandler(routingFunction, configuration);
|
||||
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction, configuration);
|
||||
assertNotNull(result);
|
||||
|
||||
MockServerHttpRequest httpRequest =
|
||||
@@ -32,13 +32,13 @@ import org.springframework.web.client.reactive.WebClient;
|
||||
|
||||
import static org.springframework.web.client.reactive.ClientWebRequestBuilders.get;
|
||||
import static org.springframework.web.client.reactive.ResponseExtractors.bodyStream;
|
||||
import static org.springframework.web.reactive.function.RoutingFunctions.route;
|
||||
import static org.springframework.web.reactive.function.RouterFunctions.route;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class SseHandlerFunctionIntegrationTests
|
||||
extends AbstractRoutingFunctionIntegrationTests {
|
||||
extends AbstractRouterFunctionIntegrationTests {
|
||||
|
||||
private WebClient webClient;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class SseHandlerFunctionIntegrationTests
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RoutingFunction<?> routingFunction() {
|
||||
protected RouterFunction<?> routerFunction() {
|
||||
SseHandler sseHandler = new SseHandler();
|
||||
return route(RequestPredicates.GET("/string"), sseHandler::string)
|
||||
.and(route(RequestPredicates.GET("/person"), sseHandler::person))
|
||||
|
||||
Reference in New Issue
Block a user