diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultControllerSpec.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultControllerSpec.java index 0f8cb0f202..47a196fbe2 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultControllerSpec.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultControllerSpec.java @@ -35,6 +35,7 @@ import org.springframework.web.reactive.config.DelegatingWebFluxConfiguration; import org.springframework.web.reactive.config.PathMatchConfigurer; import org.springframework.web.reactive.config.ViewResolverRegistry; import org.springframework.web.reactive.config.WebFluxConfigurer; +import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; /** @@ -77,6 +78,12 @@ class DefaultControllerSpec extends AbstractMockServerSpec consumer) { + this.configurer.argumentResolverConsumer = consumer; + return this; + } + @Override public DefaultControllerSpec pathMatching(Consumer consumer) { this.configurer.pathMatchConsumer = consumer; @@ -136,6 +143,8 @@ class DefaultControllerSpec extends AbstractMockServerSpec corsRegistryConsumer; + private Consumer argumentResolverConsumer; + private Consumer pathMatchConsumer; private Consumer messageCodecsConsumer; @@ -168,6 +177,13 @@ class DefaultControllerSpec extends AbstractMockServerSpec consumer); /** - * Modify or extend the list of built-in message readers and writers. + * Configure resolvers for custom controller method arguments. + * @see WebFluxConfigurer#configureHttpMessageCodecs + */ + ControllerSpec argumentResolvers(Consumer configurer); + + /** + * Configure custom HTTP message readers and writers or override built-in ones. * @see WebFluxConfigurer#configureHttpMessageCodecs */ ControllerSpec httpMessageCodecs(Consumer configurer); diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultControllerSpecTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultControllerSpecTests.java index e0ea870149..60d2748cc4 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultControllerSpecTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultControllerSpecTests.java @@ -16,13 +16,24 @@ package org.springframework.test.web.reactive.server; +import java.util.function.Consumer; + import org.junit.Test; +import org.springframework.format.FormatterRegistry; import org.springframework.http.ResponseEntity; +import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder; +import org.springframework.web.reactive.config.CorsRegistry; +import org.springframework.web.reactive.config.PathMatchConfigurer; +import org.springframework.web.reactive.config.ViewResolverRegistry; +import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; + +import static org.junit.Assert.assertNotNull; /** * Unit tests for {@link DefaultControllerSpec}. @@ -52,6 +63,36 @@ public class DefaultControllerSpecTests { .expectBody(String.class).isEqualTo("Handled exception"); } + @Test + public void configurerConsumers() throws Exception { + + TestConsumer argumentResolverConsumer = new TestConsumer<>(); + TestConsumer contenTypeResolverConsumer = new TestConsumer<>(); + TestConsumer corsRegistryConsumer = new TestConsumer<>(); + TestConsumer formatterConsumer = new TestConsumer<>(); + TestConsumer codecsConsumer = new TestConsumer<>(); + TestConsumer pathMatchingConsumer = new TestConsumer<>(); + TestConsumer viewResolverConsumer = new TestConsumer<>(); + + new DefaultControllerSpec(new MyController()) + .argumentResolvers(argumentResolverConsumer) + .contentTypeResolver(contenTypeResolverConsumer) + .corsMappings(corsRegistryConsumer) + .formatters(formatterConsumer) + .httpMessageCodecs(codecsConsumer) + .pathMatching(pathMatchingConsumer) + .viewResolvers(viewResolverConsumer) + .build(); + + assertNotNull(argumentResolverConsumer.getValue()); + assertNotNull(contenTypeResolverConsumer.getValue()); + assertNotNull(corsRegistryConsumer.getValue()); + assertNotNull(formatterConsumer.getValue()); + assertNotNull(codecsConsumer.getValue()); + assertNotNull(pathMatchingConsumer.getValue()); + assertNotNull(viewResolverConsumer.getValue()); + + } @RestController private static class MyController { @@ -77,4 +118,19 @@ public class DefaultControllerSpecTests { } } + private static class TestConsumer implements Consumer { + + private T value; + + + public T getValue() { + return this.value; + } + + @Override + public void accept(T t) { + this.value = t; + } + } + }