|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
35 | 35 | import org.springframework.test.web.servlet.ResultMatcher;
|
36 | 36 | import org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder;
|
37 | 37 | import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
|
| 38 | +import org.springframework.test.web.servlet.setup.RouterFunctionMockMvcBuilder; |
38 | 39 | import org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder;
|
39 | 40 | import org.springframework.validation.Validator;
|
40 | 41 | import org.springframework.web.accept.ContentNegotiationManager;
|
|
47 | 48 | import org.springframework.web.servlet.LocaleResolver;
|
48 | 49 | import org.springframework.web.servlet.View;
|
49 | 50 | import org.springframework.web.servlet.ViewResolver;
|
| 51 | +import org.springframework.web.servlet.function.RouterFunction; |
50 | 52 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
51 | 53 | import org.springframework.web.util.pattern.PathPatternParser;
|
52 | 54 |
|
@@ -81,13 +83,25 @@ public interface MockMvcWebTestClient {
|
81 | 83 | * Begin creating a {@link WebTestClient} by providing the {@code @Controller}
|
82 | 84 | * instance(s) to handle requests with.
|
83 | 85 | * <p>Internally this is delegated to and equivalent to using
|
84 |
| - * {@link org.springframework.test.web.servlet.setup.MockMvcBuilders#standaloneSetup(Object...)}. |
| 86 | + * {@link org.springframework.test.web.servlet.setup.MockMvcBuilders#standaloneSetup(Object...)} |
85 | 87 | * to initialize {@link MockMvc}.
|
86 | 88 | */
|
87 | 89 | static ControllerSpec bindToController(Object... controllers) {
|
88 | 90 | return new StandaloneMockMvcSpec(controllers);
|
89 | 91 | }
|
90 | 92 |
|
| 93 | + /** |
| 94 | + * Begin creating a {@link WebTestClient} by providing the {@link RouterFunction} |
| 95 | + * instance(s) to handle requests with. |
| 96 | + * <p>Internally this is delegated to and equivalent to using |
| 97 | + * {@link org.springframework.test.web.servlet.setup.MockMvcBuilders#routerFunctions(RouterFunction[])} |
| 98 | + * to initialize {@link MockMvc}. |
| 99 | + * @since 6.2 |
| 100 | + */ |
| 101 | + static RouterFunctionSpec bindToRouterFunction(RouterFunction<?>... routerFunctions) { |
| 102 | + return new RouterFunctionMockMvcSpec(routerFunctions); |
| 103 | + } |
| 104 | + |
91 | 105 | /**
|
92 | 106 | * Begin creating a {@link WebTestClient} by providing a
|
93 | 107 | * {@link WebApplicationContext} with Spring MVC infrastructure and
|
@@ -381,4 +395,72 @@ ControllerSpec mappedInterceptors(
|
381 | 395 | ControllerSpec customHandlerMapping(Supplier<RequestMappingHandlerMapping> factory);
|
382 | 396 | }
|
383 | 397 |
|
| 398 | + |
| 399 | + /** |
| 400 | + * Specification for configuring {@link MockMvc} to test one or more |
| 401 | + * {@linkplain RouterFunction router functions} |
| 402 | + * directly, and a simple facade around {@link RouterFunctionMockMvcBuilder}. |
| 403 | + * @since 6.2 |
| 404 | + */ |
| 405 | + interface RouterFunctionSpec extends MockMvcServerSpec<RouterFunctionSpec> { |
| 406 | + |
| 407 | + /** |
| 408 | + * Set the message converters to use. |
| 409 | + * <p>This is delegated to |
| 410 | + * {@link RouterFunctionMockMvcBuilder#setMessageConverters(HttpMessageConverter[])}. |
| 411 | + */ |
| 412 | + RouterFunctionSpec messageConverters(HttpMessageConverter<?>... messageConverters); |
| 413 | + |
| 414 | + /** |
| 415 | + * Add global interceptors. |
| 416 | + * <p>This is delegated to |
| 417 | + * {@link RouterFunctionMockMvcBuilder#addInterceptors(HandlerInterceptor...)}. |
| 418 | + */ |
| 419 | + RouterFunctionSpec interceptors(HandlerInterceptor... interceptors); |
| 420 | + |
| 421 | + /** |
| 422 | + * Add interceptors for specific patterns. |
| 423 | + * <p>This is delegated to |
| 424 | + * {@link RouterFunctionMockMvcBuilder#addMappedInterceptors(String[], HandlerInterceptor...)}. |
| 425 | + */ |
| 426 | + RouterFunctionSpec mappedInterceptors( |
| 427 | + @Nullable String[] pathPatterns, HandlerInterceptor... interceptors); |
| 428 | + |
| 429 | + /** |
| 430 | + * Specify the timeout value for async execution. |
| 431 | + * <p>This is delegated to |
| 432 | + * {@link RouterFunctionMockMvcBuilder#setAsyncRequestTimeout(long)}. |
| 433 | + */ |
| 434 | + RouterFunctionSpec asyncRequestTimeout(long timeout); |
| 435 | + |
| 436 | + /** |
| 437 | + * Set the HandlerExceptionResolver types to use. |
| 438 | + * <p>This is delegated to |
| 439 | + * {@link RouterFunctionMockMvcBuilder#setHandlerExceptionResolvers(HandlerExceptionResolver...)}. |
| 440 | + */ |
| 441 | + RouterFunctionSpec handlerExceptionResolvers(HandlerExceptionResolver... exceptionResolvers); |
| 442 | + |
| 443 | + /** |
| 444 | + * Set up view resolution. |
| 445 | + * <p>This is delegated to |
| 446 | + * {@link RouterFunctionMockMvcBuilder#setViewResolvers(ViewResolver...)}. |
| 447 | + */ |
| 448 | + RouterFunctionSpec viewResolvers(ViewResolver... resolvers); |
| 449 | + |
| 450 | + /** |
| 451 | + * Set up a single {@link ViewResolver} with a fixed view. |
| 452 | + * <p>This is delegated to |
| 453 | + * {@link RouterFunctionMockMvcBuilder#setSingleView(View)}. |
| 454 | + */ |
| 455 | + RouterFunctionSpec singleView(View view); |
| 456 | + |
| 457 | + /** |
| 458 | + * Enable URL path matching with parsed |
| 459 | + * {@link org.springframework.web.util.pattern.PathPattern PathPatterns}. |
| 460 | + * <p>This is delegated to |
| 461 | + * {@link RouterFunctionMockMvcBuilder#setPatternParser(PathPatternParser)}. |
| 462 | + */ |
| 463 | + RouterFunctionSpec patternParser(PathPatternParser parser); |
| 464 | + } |
| 465 | + |
384 | 466 | }
|
0 commit comments