private void testBindFoo(String modelKey, MethodParameter param, Function<Object, Foo> valueExtractor) throws Exception { Object value = createResolver() .resolveArgument(param, this.bindContext, postForm("name=Robert&age=25")) .block(Duration.ZERO); Foo foo = valueExtractor.apply(value); assertEquals("Robert", foo.getName()); assertEquals(25, foo.getAge()); String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + modelKey; Map<String, Object> map = bindContext.getModel().asMap(); assertEquals(map.toString(), 2, map.size()); assertSame(foo, map.get(modelKey)); assertNotNull(map.get(bindingResultKey)); assertTrue(map.get(bindingResultKey) instanceof BindingResult); }
private void testBindBar(MethodParameter param) throws Exception { Object value = createResolver() .resolveArgument(param, this.bindContext, postForm("name=Robert&age=25&count=1")) .block(Duration.ZERO); Bar bar = (Bar) value; assertEquals("Robert", bar.getName()); assertEquals(25, bar.getAge()); assertEquals(1, bar.getCount()); String key = "bar"; String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + key; Map<String, Object> map = bindContext.getModel().asMap(); assertEquals(map.toString(), 2, map.size()); assertSame(bar, map.get(key)); assertNotNull(map.get(bindingResultKey)); assertTrue(map.get(bindingResultKey) instanceof BindingResult); }
private void testValidationError(MethodParameter param, Function<Mono<?>, Mono<?>> valueMonoExtractor) throws URISyntaxException { ServerWebExchange exchange = postForm("age=invalid"); Mono<?> mono = createResolver().resolveArgument(param, this.bindContext, exchange); mono = valueMonoExtractor.apply(mono); StepVerifier.create(mono) .consumeErrorWith(ex -> { assertTrue(ex instanceof WebExchangeBindException); WebExchangeBindException bindException = (WebExchangeBindException) ex; assertEquals(1, bindException.getErrorCount()); assertTrue(bindException.hasFieldErrors("age")); }) .verify(); }