Java Code Examples for org.springframework.web.reactive.BindingContext#createDataBinder()
The following examples show how to use
org.springframework.web.reactive.BindingContext#createDataBinder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractMessageReaderArgumentResolver.java From java-technology-stack with MIT License | 5 votes |
private void validate(Object target, Object[] validationHints, MethodParameter param, BindingContext binding, ServerWebExchange exchange) { String name = Conventions.getVariableNameForParameter(param); WebExchangeDataBinder binder = binding.createDataBinder(exchange, target, name); binder.validate(validationHints); if (binder.getBindingResult().hasErrors()) { throw new WebExchangeBindException(param, binder.getBindingResult()); } }
Example 2
Source File: ControllerAdviceTests.java From java-technology-stack with MIT License | 5 votes |
@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()); }
Example 3
Source File: InitBinderBindingContextTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void createBinderTypeConversion() throws Exception { MockServerHttpRequest request = MockServerHttpRequest.get("/path?requestParam=22").build(); MockServerWebExchange exchange = MockServerWebExchange.from(request); ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); this.argumentResolvers.add(new RequestParamMethodArgumentResolver(null, adapterRegistry, false)); BindingContext context = createBindingContext("initBinderTypeConversion", WebDataBinder.class, int.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo"); assertNotNull(dataBinder.getDisallowedFields()); assertEquals("requestParam-22", dataBinder.getDisallowedFields()[0]); }
Example 4
Source File: InitBinderBindingContextTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void createBinderNullAttrName() throws Exception { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, null); assertNull(dataBinder.getDisallowedFields()); }
Example 5
Source File: InitBinderBindingContextTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void createBinderWithAttrNameNoMatch() throws Exception { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, "invalidName"); assertNull(dataBinder.getDisallowedFields()); }
Example 6
Source File: InitBinderBindingContextTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void createBinderWithAttrName() throws Exception { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo"); assertNotNull(dataBinder.getDisallowedFields()); assertEquals("id", dataBinder.getDisallowedFields()[0]); }
Example 7
Source File: InitBinderBindingContextTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void createBinderWithGlobalInitialization() throws Exception { ConversionService conversionService = new DefaultFormattingConversionService(); bindingInitializer.setConversionService(conversionService); MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinder", WebDataBinder.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, null); assertSame(conversionService, dataBinder.getConversionService()); }
Example 8
Source File: InitBinderBindingContextTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void createBinder() throws Exception { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinder", WebDataBinder.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, null); assertNotNull(dataBinder.getDisallowedFields()); assertEquals("id", dataBinder.getDisallowedFields()[0]); }
Example 9
Source File: AbstractMessageReaderArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
private void validate(Object target, Object[] validationHints, MethodParameter param, BindingContext binding, ServerWebExchange exchange) { String name = Conventions.getVariableNameForParameter(param); WebExchangeDataBinder binder = binding.createDataBinder(exchange, target, name); binder.validate(validationHints); if (binder.getBindingResult().hasErrors()) { throw new WebExchangeBindException(param, binder.getBindingResult()); } }
Example 10
Source File: ControllerAdviceTests.java From spring-analysis-note with MIT License | 5 votes |
@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()); }
Example 11
Source File: InitBinderBindingContextTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void createBinderTypeConversion() throws Exception { MockServerHttpRequest request = MockServerHttpRequest.get("/path?requestParam=22").build(); MockServerWebExchange exchange = MockServerWebExchange.from(request); ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); this.argumentResolvers.add(new RequestParamMethodArgumentResolver(null, adapterRegistry, false)); BindingContext context = createBindingContext("initBinderTypeConversion", WebDataBinder.class, int.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo"); assertNotNull(dataBinder.getDisallowedFields()); assertEquals("requestParam-22", dataBinder.getDisallowedFields()[0]); }
Example 12
Source File: InitBinderBindingContextTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void createBinderNullAttrName() throws Exception { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, null); assertNull(dataBinder.getDisallowedFields()); }
Example 13
Source File: InitBinderBindingContextTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void createBinderWithAttrNameNoMatch() throws Exception { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, "invalidName"); assertNull(dataBinder.getDisallowedFields()); }
Example 14
Source File: InitBinderBindingContextTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void createBinderWithAttrName() throws Exception { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo"); assertNotNull(dataBinder.getDisallowedFields()); assertEquals("id", dataBinder.getDisallowedFields()[0]); }
Example 15
Source File: InitBinderBindingContextTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void createBinderWithGlobalInitialization() throws Exception { ConversionService conversionService = new DefaultFormattingConversionService(); bindingInitializer.setConversionService(conversionService); MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinder", WebDataBinder.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, null); assertSame(conversionService, dataBinder.getConversionService()); }
Example 16
Source File: InitBinderBindingContextTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void createBinder() throws Exception { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinder", WebDataBinder.class); WebDataBinder dataBinder = context.createDataBinder(exchange, null, null); assertNotNull(dataBinder.getDisallowedFields()); assertEquals("id", dataBinder.getDisallowedFields()[0]); }
Example 17
Source File: InitBinderBindingContextTests.java From spring-analysis-note with MIT License | 4 votes |
@Test(expected = IllegalStateException.class) public void returnValueNotExpected() throws Exception { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinderReturnValue", WebDataBinder.class); context.createDataBinder(exchange, null, "invalidName"); }
Example 18
Source File: InitBinderBindingContextTests.java From java-technology-stack with MIT License | 4 votes |
@Test(expected = IllegalStateException.class) public void returnValueNotExpected() throws Exception { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); BindingContext context = createBindingContext("initBinderReturnValue", WebDataBinder.class); context.createDataBinder(exchange, null, "invalidName"); }