use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolveOptionalRequestPart.
@Test
public void resolveOptionalRequestPart() throws Exception {
SimpleBean simpleBean = new SimpleBean("foo");
given(messageConverter.canRead(SimpleBean.class, MediaType.TEXT_PLAIN)).willReturn(true);
given(messageConverter.read(eq(SimpleBean.class), isA(HttpInputMessage.class))).willReturn(simpleBean);
ModelAndViewContainer mavContainer = new ModelAndViewContainer();
Object actualValue = resolver.resolveArgument(optionalRequestPart, mavContainer, webRequest, new ValidatingBinderFactory());
assertThat(actualValue).as("Invalid argument value").isEqualTo(Optional.of(simpleBean));
assertThat(mavContainer.isRequestHandled()).as("The requestHandled flag shouldn't change").isFalse();
actualValue = resolver.resolveArgument(optionalRequestPart, mavContainer, webRequest, new ValidatingBinderFactory());
assertThat(actualValue).as("Invalid argument value").isEqualTo(Optional.of(simpleBean));
assertThat(mavContainer.isRequestHandled()).as("The requestHandled flag shouldn't change").isFalse();
}
use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method testResolveArgument.
private void testResolveArgument(SimpleBean argValue, MethodParameter parameter) throws Exception {
given(messageConverter.canRead(SimpleBean.class, MediaType.TEXT_PLAIN)).willReturn(true);
given(messageConverter.read(eq(SimpleBean.class), isA(HttpInputMessage.class))).willReturn(argValue);
ModelAndViewContainer mavContainer = new ModelAndViewContainer();
Object actualValue = resolver.resolveArgument(parameter, mavContainer, webRequest, new ValidatingBinderFactory());
assertThat(actualValue).as("Invalid argument value").isEqualTo(argValue);
assertThat(mavContainer.isRequestHandled()).as("The requestHandled flag shouldn't change").isFalse();
assertThat(trackedStream != null && trackedStream.closed).isTrue();
}
use of org.springframework.web.method.support.ModelAndViewContainer 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);
assertThat(container.getModel().get(attributeName)).isEqualTo(attribute);
assertThat(this.attributeStore.retrieveAttribute(this.webRequest, attributeName)).isEqualTo(attribute);
}
use of org.springframework.web.method.support.ModelAndViewContainer 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);
assertThat(container.getModel().get(queryParamName)).isEqualTo(queryParam);
assertThat(container.getModel().size()).isEqualTo(1);
assertThat(this.attributeStore.retrieveAttribute(this.webRequest, attributeName)).isEqualTo(attribute);
}
use of org.springframework.web.method.support.ModelAndViewContainer in project spring-framework by spring-projects.
the class ModelFactoryOrderingTests method setup.
@Before
public void setup() {
this.sessionAttributeStore = new DefaultSessionAttributeStore();
this.webRequest = new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse());
this.mavContainer = new ModelAndViewContainer();
this.mavContainer.addAttribute("methods", new ArrayList<String>());
}
Aggregations