use of cn.taketoday.web.view.ModelMap in project today-framework by TAKETODAY.
the class ModelMethodProcessorTests method supportsReturnType.
@Test
public void supportsReturnType() throws NoSuchMethodException {
Method method = getClass().getDeclaredMethod("model", Model.class);
HandlerMethod handlerMethod = new HandlerMethod(this, method);
assertThat(processor.supportsHandler(null)).isFalse();
assertThat(processor.supportsHandler(handlerMethod)).isTrue();
assertThat(processor.supportsHandler(redirectModelHandler)).isTrue();
assertThat(processor.supportsReturnValue(handlerMethod)).isFalse();
assertThat(processor.supportsReturnValue(new ModelMap())).isTrue();
}
use of cn.taketoday.web.view.ModelMap in project today-framework by TAKETODAY.
the class ModelMethodProcessorTests method resolveArgumentValue.
@Test
public void resolveArgumentValue() throws Throwable {
BindingContext bindingContext = webRequest.getBindingContext();
ModelMap model = bindingContext.getModel();
assertThat(processor.resolveArgument(webRequest, new ResolvableMethodParameter(paramModel))).isSameAs(model);
assertThat(processor.resolveArgument(webRequest, new ResolvableMethodParameter(redirectModelParam))).isSameAs(bindingContext.getRedirectModel());
assertThat(webRequest.hasAttribute(RedirectModel.OUTPUT_ATTRIBUTE)).isTrue();
assertThat((Object) RedirectModel.findOutputModel(webRequest)).isSameAs(bindingContext.getRedirectModel());
}
use of cn.taketoday.web.view.ModelMap in project today-framework by TAKETODAY.
the class ErrorsMethodArgumentResolver method resolveArgument.
@Nullable
@Override
public Object resolveArgument(RequestContext context, ResolvableMethodParameter resolvable) throws Throwable {
BindingContext bindingContext = context.getBindingContext();
ModelMap model = bindingContext.getModel();
String lastKey = CollectionUtils.lastElement(model.keySet());
if (lastKey != null && lastKey.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
return model.getAttribute(lastKey);
}
throw new IllegalStateException("An Errors/BindingResult argument is expected to be declared immediately after " + "the model attribute, the @RequestBody or the @RequestPart arguments " + "to which they apply: " + resolvable.getMethod());
}
use of cn.taketoday.web.view.ModelMap in project today-framework by TAKETODAY.
the class ModelMethodProcessorTests method handleModelReturnValue.
@Test
public void handleModelReturnValue() throws Exception {
BindingContext bindingContext = webRequest.getBindingContext();
bindingContext.addAttribute("attr1", "value1");
ModelMap returnValue = new ModelMap();
returnValue.addAttribute("attr2", "value2");
Method method = getClass().getDeclaredMethod("model", Model.class);
HandlerMethod handlerMethod = new HandlerMethod(this, method);
processor.handleReturnValue(webRequest, handlerMethod, returnValue);
assertThat(bindingContext.getModel().get("attr1")).isEqualTo("value1");
assertThat(bindingContext.getModel().get("attr2")).isEqualTo("value2");
// RedirectModel
assertThat((Object) bindingContext.getRedirectModel()).isNull();
assertThat(webRequest.hasAttribute(RedirectModel.OUTPUT_ATTRIBUTE)).isFalse();
assertThat((Object) RedirectModel.findOutputModel(webRequest)).isNull();
assertThat((Object) RedirectModel.findOutputModel(webRequest)).isSameAs(bindingContext.getRedirectModel());
processor.handleReturnValue(webRequest, redirectModelHandler, new RedirectModel("attr3", "value3"));
assertThat(webRequest.hasAttribute(RedirectModel.OUTPUT_ATTRIBUTE)).isTrue();
assertThat((Object) RedirectModel.findOutputModel(webRequest)).isSameAs(bindingContext.getRedirectModel());
assertThat((Object) bindingContext.getRedirectModel()).isNotNull();
assertThat(bindingContext.getRedirectModel().getAttribute("attr3")).isEqualTo("value3");
processor.handleReturnValue(webRequest, redirectModelHandler, new RedirectModel("attr4", "value4"));
assertThat(bindingContext.getRedirectModel().getAttribute("attr3")).isEqualTo("value3");
assertThat(bindingContext.getRedirectModel().getAttribute("attr4")).isEqualTo("value4");
}
use of cn.taketoday.web.view.ModelMap in project today-framework by TAKETODAY.
the class SessionAttributesHandlerTests method storeAttributes.
@Test
public void storeAttributes() throws Exception {
ModelMap model = new ModelMap();
model.put("attr1", "value1");
model.put("attr2", "value2");
model.put("attr3", new TestBean());
sessionAttributesHandler.storeAttributes(request, model);
assertThat(sessionAttributeStore.retrieveAttribute(request, "attr1")).isEqualTo("value1");
assertThat(sessionAttributeStore.retrieveAttribute(request, "attr2")).isEqualTo("value2");
boolean condition = sessionAttributeStore.retrieveAttribute(request, "attr3") instanceof TestBean;
assertThat(condition).isTrue();
}
Aggregations