use of org.springframework.web.reactive.BindingContext in project spring-framework by spring-projects.
the class PathVariableMethodArgumentResolverTests method resolveArgument.
@Test
public void resolveArgument() throws Exception {
Map<String, String> uriTemplateVars = new HashMap<>();
uriTemplateVars.put("name", "value");
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
BindingContext bindingContext = new BindingContext();
Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedString, bindingContext, this.exchange);
Object result = mono.block();
assertEquals("value", result);
}
use of org.springframework.web.reactive.BindingContext in project spring-framework by spring-projects.
the class PathVariableMethodArgumentResolverTests method wrapEmptyWithOptional.
@Test
public void wrapEmptyWithOptional() throws Exception {
BindingContext bindingContext = new BindingContext();
Mono<Object> mono = this.resolver.resolveArgument(this.paramOptional, bindingContext, this.exchange);
StepVerifier.create(mono).consumeNextWith(value -> {
assertTrue(value instanceof Optional);
assertFalse(((Optional<?>) value).isPresent());
}).expectComplete().verify();
}
use of org.springframework.web.reactive.BindingContext in project spring-framework by spring-projects.
the class ControllerAdviceTests method initBinderAdvice.
@Test
public void initBinderAdvice() throws Exception {
ApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
RequestMappingHandlerAdapter adapter = createAdapter(context);
TestController controller = context.getBean(TestController.class);
Validator validator = mock(Validator.class);
controller.setValidator(validator);
BindingContext bindingContext = handle(adapter, controller, "handle").getBindingContext();
WebExchangeDataBinder binder = bindingContext.createDataBinder(this.exchange, "name");
assertEquals(Collections.singletonList(validator), binder.getValidators());
}
use of org.springframework.web.reactive.BindingContext in project spring-framework by spring-projects.
the class CookieValueMethodArgumentResolverTests method setup.
@Before
public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh();
ReactiveAdapterRegistry adapterRegistry = new ReactiveAdapterRegistry();
this.resolver = new CookieValueMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
this.bindingContext = new BindingContext();
Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
this.cookieParameter = new SynthesizingMethodParameter(method, 0);
this.cookieStringParameter = new SynthesizingMethodParameter(method, 1);
this.stringParameter = new SynthesizingMethodParameter(method, 2);
this.cookieMonoParameter = new SynthesizingMethodParameter(method, 3);
}
use of org.springframework.web.reactive.BindingContext in project spring-framework by spring-projects.
the class PathVariableMethodArgumentResolverTests method resolveArgumentWrappedAsOptional.
@Test
public void resolveArgumentWrappedAsOptional() throws Exception {
Map<String, String> uriTemplateVars = new HashMap<>();
uriTemplateVars.put("name", "value");
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultFormattingConversionService());
BindingContext bindingContext = new BindingContext(initializer);
Mono<Object> mono = this.resolver.resolveArgument(this.paramOptional, bindingContext, this.exchange);
Object result = mono.block();
assertEquals(Optional.of("value"), result);
}
Aggregations