use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class ModelFactoryTests method modelAttributeMethodWithNullReturnValue.
@Test
public void modelAttributeMethodWithNullReturnValue() throws Throwable {
BindingContext bindingContext = webRequest.getBindingContext();
ModelFactory modelFactory = createModelFactory("nullModelAttr");
HandlerMethod handlerMethod = createHandlerMethod("handle");
modelFactory.initModel(this.webRequest, bindingContext, handlerMethod);
assertThat(bindingContext.containsAttribute("name")).isTrue();
assertThat(bindingContext.getModel().get("name")).isNull();
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class ModelFactoryTests method updateModelBindingResult.
@Test
public void updateModelBindingResult() throws Throwable {
String commandName = "attr1";
Object command = new Object();
RequestContextDataBinder dataBinder = new RequestContextDataBinder(command, commandName);
BindingContext container = new BindingContext0(dataBinder);
container.addAttribute(commandName, command);
ModelFactory modelFactory = new ModelFactory(null, container, this.attributeHandler);
modelFactory.updateModel(this.webRequest, container);
assertThat(container.getModel().get(commandName)).isEqualTo(command);
String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + commandName;
assertThat(container.getModel().get(bindingResultKey)).isSameAs(dataBinder.getBindingResult());
assertThat(container.getModel().size()).isEqualTo(2);
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class ModelFactoryTests method updateModelWhenRedirecting.
// SPR-12542
@Test
public void updateModelWhenRedirecting() throws Throwable {
String attributeName = "sessionAttr";
String attribute = "value";
RequestContextDataBinder dataBinder = new RequestContextDataBinder(attribute, attributeName);
BindingContext container = new BindingContext0(dataBinder);
container.addAttribute(attributeName, attribute);
String queryParam = "123";
String queryParamName = "q";
container.setRedirectModel(new RedirectModel(queryParamName, queryParam));
ModelFactory modelFactory = new ModelFactory(null, container, this.attributeHandler);
modelFactory.updateModel(this.webRequest, container);
assertThat(container.getRedirectModel().get(queryParamName)).isEqualTo(queryParam);
assertThat(container.getRedirectModel().size()).isEqualTo(1);
assertThat(this.attributeStore.retrieveAttribute(this.webRequest, attributeName)).isEqualTo(attribute);
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class ModelFactoryTests method modelAttributeMethod.
@Test
public void modelAttributeMethod() throws Throwable {
BindingContext container = webRequest.getBindingContext();
ModelFactory modelFactory = createModelFactory("modelAttr", Model.class);
HandlerMethod handlerMethod = createHandlerMethod("handle");
modelFactory.initModel(this.webRequest, container, handlerMethod);
assertThat(container.getModel().get("modelAttr")).isEqualTo(Boolean.TRUE);
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class ModelAttributeMethodProcessorTests method resolveArgumentBindingDisabled.
@Test
public void resolveArgumentBindingDisabled() throws Throwable {
String name = "noBindAttr";
Object target = new TestBean();
StubRequestDataBinder dataBinder = new StubRequestDataBinder(target, name);
BindingContext factory = new ModelFactoryTests.BindingContext0(dataBinder);
factory.addAttribute(name, target);
request.setBindingContext(factory);
this.processor.resolveArgument(request, this.paramBindingDisabledAttr);
assertThat(dataBinder.isBindInvoked()).isFalse();
assertThat(dataBinder.isValidateInvoked()).isTrue();
}
Aggregations