use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class ModelAndViewResolverMethodReturnValueHandlerTests method modelAndViewResolver.
@Test
public void modelAndViewResolver() throws Exception {
MethodParameter returnType = new MethodParameter(getClass().getDeclaredMethod("testBeanReturnValue"), -1);
mavResolvers.add(new TestModelAndViewResolver(TestBean.class));
TestBean testBean = new TestBean("name");
handler.handleReturnValue(testBean, returnType, mavContainer, request);
assertThat(mavContainer.getViewName()).isEqualTo("viewName");
assertThat(mavContainer.getModel().get("modelAttrName")).isSameAs(testBean);
assertThat(mavContainer.isRequestHandled()).isFalse();
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class DispatcherServletTests method noCleanupAfterInclude.
@Test
public void noCleanupAfterInclude() throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/main.do");
MockHttpServletResponse response = new MockHttpServletResponse();
request.setAttribute("test1", "value1");
request.setAttribute("test2", "value2");
WebApplicationContext wac = new StaticWebApplicationContext();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
TestBean command = new TestBean();
request.setAttribute("command", command);
request.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "/form.do");
simpleDispatcherServlet.setCleanupAfterInclude(false);
simpleDispatcherServlet.service(request, response);
assertThat(request.getAttribute("test1")).isEqualTo("value1");
assertThat(request.getAttribute("test2")).isEqualTo("value2");
assertThat(request.getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE)).isSameAs(wac);
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class DefaultHandlerExceptionResolverTests method handleMethodArgumentNotValid.
@Test
public void handleMethodArgumentNotValid() throws Exception {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(new TestBean(), "testBean");
errors.rejectValue("name", "invalid");
MethodParameter parameter = new MethodParameter(this.getClass().getMethod("handle", String.class), 0);
MethodArgumentNotValidException ex = new MethodArgumentNotValidException(parameter, errors);
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertThat(mav).as("No ModelAndView returned").isNotNull();
assertThat(mav.isEmpty()).as("No Empty ModelAndView returned").isTrue();
assertThat(response.getStatus()).as("Invalid status code").isEqualTo(400);
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class RedirectAttributesModelMapTests method mergeAttributes.
@Test
void mergeAttributes() {
Map<String, Object> map = new HashMap<>();
map.put("person", new TestBean("Fred"));
map.put("age", 33);
this.redirectAttributes.addAttribute("person", new TestBean("Ralph"));
this.redirectAttributes.mergeAttributes(map);
assertThat(this.redirectAttributes.get("person")).isEqualTo("Ralph");
assertThat(this.redirectAttributes.get("age")).isEqualTo("33");
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class RedirectAttributesModelMapTests method putAll.
@Test
void putAll() {
Map<String, Object> map = new HashMap<>();
map.put("person", new TestBean("Fred"));
map.put("age", 33);
this.redirectAttributes.putAll(map);
assertThat(this.redirectAttributes.get("person")).isEqualTo("Fred");
assertThat(this.redirectAttributes.get("age")).isEqualTo("33");
}
Aggregations