use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.
the class ModelFactoryTests method updateModelSessionAttributesSaved.
@Test
public void updateModelSessionAttributesSaved() throws Exception {
String attributeName = "sessionAttr";
String attribute = "value";
ModelAndViewContainer container = new ModelAndViewContainer();
container.addAttribute(attributeName, attribute);
WebDataBinder dataBinder = new WebDataBinder(attribute, attributeName);
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
given(binderFactory.createBinder(this.webRequest, attribute, attributeName)).willReturn(dataBinder);
ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.attributeHandler);
modelFactory.updateModel(this.webRequest, container);
assertEquals(attribute, container.getModel().get(attributeName));
assertEquals(attribute, this.attributeStore.retrieveAttribute(this.webRequest, attributeName));
}
use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.
the class ModelFactoryTests method updateModelWhenRedirecting.
// SPR-12542
@Test
public void updateModelWhenRedirecting() throws Exception {
String attributeName = "sessionAttr";
String attribute = "value";
ModelAndViewContainer container = new ModelAndViewContainer();
container.addAttribute(attributeName, attribute);
String queryParam = "123";
String queryParamName = "q";
container.setRedirectModel(new ModelMap(queryParamName, queryParam));
container.setRedirectModelScenario(true);
WebDataBinder dataBinder = new WebDataBinder(attribute, attributeName);
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
given(binderFactory.createBinder(this.webRequest, attribute, attributeName)).willReturn(dataBinder);
ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.attributeHandler);
modelFactory.updateModel(this.webRequest, container);
assertEquals(queryParam, container.getModel().get(queryParamName));
assertEquals(1, container.getModel().size());
assertEquals(attribute, this.attributeStore.retrieveAttribute(this.webRequest, attributeName));
}
use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method missingRequestParamEmptyValueNotRequired.
@Test
public void missingRequestParamEmptyValueNotRequired() throws Exception {
WebDataBinder binder = new WebRequestDataBinder(null);
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);
this.request.addParameter("name", "");
MethodParameter param = this.testMethod.annot(requestParam().notRequired()).arg(String.class);
Object arg = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertNull(arg);
}
use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.
the class InitBinderBindingContextTests method createBinder.
@Test
public void createBinder() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
assertNotNull(dataBinder.getDisallowedFields());
assertEquals("id", dataBinder.getDisallowedFields()[0]);
}
use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.
the class InitBinderBindingContextTests method createBinderWithAttrName.
@Test
public void createBinderWithAttrName() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo");
assertNotNull(dataBinder.getDisallowedFields());
assertEquals("id", dataBinder.getDisallowedFields()[0]);
}
Aggregations