use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.
the class ExtendedServletRequestDataBinderTests method createBinder.
@Test
public void createBinder() throws Exception {
Map<String, String> uriTemplateVars = new HashMap<>();
uriTemplateVars.put("name", "nameValue");
uriTemplateVars.put("age", "25");
request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
TestBean target = new TestBean();
WebDataBinder binder = new ExtendedServletRequestDataBinder(target, "");
((ServletRequestDataBinder) binder).bind(request);
assertEquals("nameValue", target.getName());
assertEquals(25, target.getAge());
}
use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.
the class ModelAttributeMethodProcessorTests method testGetAttributeFromModel.
private void testGetAttributeFromModel(String expectedAttrName, MethodParameter param) throws Exception {
Object target = new TestBean();
this.container.addAttribute(expectedAttrName, target);
WebDataBinder dataBinder = new WebRequestDataBinder(target);
WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
given(factory.createBinder(this.request, target, expectedAttrName)).willReturn(dataBinder);
this.processor.resolveArgument(param, this.container, this.request, factory);
verify(factory).createBinder(this.request, target, expectedAttrName);
}
use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.
the class ModelAttributeMethodProcessorTests method resovleArgumentViaDefaultConstructor.
@Test
public void resovleArgumentViaDefaultConstructor() throws Exception {
WebDataBinder dataBinder = new WebRequestDataBinder(null);
WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
given(factory.createBinder(any(), notNull(), eq("attrName"))).willReturn(dataBinder);
this.processor.resolveArgument(this.paramNamedValidModelAttr, this.container, this.request, factory);
verify(factory).createBinder(any(), notNull(), eq("attrName"));
}
use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.
the class ModelFactoryTests method updateModelBindingResult.
@Test
public void updateModelBindingResult() throws Exception {
String commandName = "attr1";
Object command = new Object();
ModelAndViewContainer container = new ModelAndViewContainer();
container.addAttribute(commandName, command);
WebDataBinder dataBinder = new WebDataBinder(command, commandName);
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
given(binderFactory.createBinder(this.webRequest, command, commandName)).willReturn(dataBinder);
ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.attributeHandler);
modelFactory.updateModel(this.webRequest, container);
assertEquals(command, container.getModel().get(commandName));
String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + commandName;
assertSame(dataBinder.getBindingResult(), container.getModel().get(bindingResultKey));
assertEquals(2, container.getModel().size());
}
use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.
the class InitBinderDataBinderFactoryTests method createBinder.
@Test
public void createBinder() throws Exception {
WebDataBinderFactory factory = createFactory("initBinder", WebDataBinder.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, null);
assertNotNull(dataBinder.getDisallowedFields());
assertEquals("id", dataBinder.getDisallowedFields()[0]);
}
Aggregations