use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class ModelAttributeMethodProcessorTests method resolveArgumentOrdering.
// SPR-9378
@Test
public void resolveArgumentOrdering() throws Throwable {
String name = "testBean";
Object testBean = new TestBean(name);
StubRequestDataBinder dataBinder = new StubRequestDataBinder(testBean, name);
BindingContext factory = new ModelFactoryTests.BindingContext0(dataBinder);
factory.addAttribute(name, testBean);
factory.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, testBean);
Object anotherTestBean = new TestBean();
factory.addAttribute("anotherTestBean", anotherTestBean);
request.setBindingContext(factory);
this.processor.resolveArgument(request, this.paramModelAttr);
Object[] values = factory.getModel().values().toArray();
assertThat(values[1]).as("Resolved attribute should be updated to be last").isSameAs(testBean);
assertThat(values[2]).as("BindingResult of resolved attr should be last").isSameAs(dataBinder.getBindingResult());
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class ModelAttributeMethodProcessorTests method setup.
@BeforeEach
public void setup() throws Throwable {
this.request = new ServletRequestContext(null, new MockHttpServletRequest(), null);
this.container = new BindingContext();
request.setBindingContext(container);
this.processor = new ModelAttributeMethodProcessor(false);
Method method = ModelAttributeHandler.class.getDeclaredMethod("modelAttribute", TestBean.class, Errors.class, int.class, TestBean.class, TestBean.class, TestBean.class, TestBeanWithConstructorArgs.class);
this.paramNamedValidModelAttr = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 0));
this.paramErrors = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 1));
this.paramInt = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 2));
this.paramModelAttr = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 3));
this.paramBindingDisabledAttr = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 4));
this.paramNonSimpleType = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 5));
this.beanWithConstructorArgs = new ResolvableMethodParameter(new SynthesizingMethodParameter(method, 6));
method = getClass().getDeclaredMethod("annotatedReturnValue");
this.returnParamNamedModelAttrHandler = new HandlerMethod(this, method);
method = getClass().getDeclaredMethod("notAnnotatedReturnValue");
this.returnParamNonSimpleTypeHandler = new HandlerMethod(this, method);
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class ModelFactoryOrderingTests method runTest.
private void runTest(Object controller) throws Throwable {
ParameterResolvingRegistry resolvers = new ParameterResolvingRegistry();
resolvers.addStrategies(new ModelAttributeMethodProcessor(false));
resolvers.addStrategies(new ModelMethodProcessor());
BindingContext dataBinderFactory = new BindingContext(null);
Class<?> type = controller.getClass();
Set<Method> methods = MethodIntrospector.filterMethods(type, METHOD_FILTER);
List<InvocableHandlerMethod> modelMethods = new ArrayList<>();
for (Method method : methods) {
InvocableHandlerMethod modelMethod = new InvocableHandlerMethod(controller, method);
modelMethod.setResolvingRegistry(resolvers);
modelMethods.add(modelMethod);
}
Collections.shuffle(modelMethods);
SessionAttributesHandler sessionHandler = new SessionAttributesHandler(type, this.sessionAttributeStore);
ModelFactory factory = new ModelFactory(modelMethods, dataBinderFactory, sessionHandler);
factory.initModel(this.webRequest, this.mavContainer, new HandlerMethod(controller, "handle"));
if (logger.isDebugEnabled()) {
logger.debug(String.join(" >> ", getInvokedMethods()));
}
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class ErrorsMethodArgumentResolverTests method bindingResultNotFound.
@Test
public void bindingResultNotFound() throws Exception {
BindingContext mavContainer = new BindingContext();
mavContainer.addAllAttributes(bindingResult.getModel());
mavContainer.addAttribute("ignore1", "value1");
webRequest.setBindingContext(mavContainer);
assertThatIllegalStateException().isThrownBy(() -> resolver.resolveArgument(webRequest, paramErrors));
}
use of cn.taketoday.web.BindingContext in project today-framework by TAKETODAY.
the class ErrorsMethodArgumentResolverTests method noBindingResult.
@Test
public void noBindingResult() throws Exception {
BindingContext mavContainer = new BindingContext();
webRequest.setBindingContext(mavContainer);
assertThatIllegalStateException().isThrownBy(() -> resolver.resolveArgument(webRequest, paramErrors));
}
Aggregations