use of cn.taketoday.web.view.ModelAndView in project today-infrastructure by TAKETODAY.
the class UrlFilenameViewControllerTests method withContextMapping.
@Test
void withContextMapping() throws Exception {
UrlFilenameViewController controller = new UrlFilenameViewController();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myapp/docs/cvs/commit.html");
request.setContextPath("/myapp");
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.refresh();
ServletRequestContext context = new ServletRequestContext(wac, request, new MockHttpServletResponse());
ModelAndView mv = controller.handleRequest(context);
assertThat(mv.getViewName()).isEqualTo("docs/cvs/commit");
assertThat(mv.getModel().isEmpty()).isTrue();
}
use of cn.taketoday.web.view.ModelAndView in project today-infrastructure by TAKETODAY.
the class ParameterizableViewControllerTests method redirectStatus.
@Test
public void redirectStatus() throws Exception {
this.controller.setStatusCode(HttpStatus.PERMANENT_REDIRECT);
this.controller.setViewName("/foo");
ModelAndView modelAndView = this.controller.handleRequest(this.context);
assertThat(modelAndView.getViewName()).isEqualTo("redirect:/foo");
assertThat(this.response.getStatus()).as("3xx status should be left to RedirectView to set").isEqualTo(200);
assertThat(this.request.getAttribute(View.RESPONSE_STATUS_ATTRIBUTE)).isEqualTo(HttpStatus.PERMANENT_REDIRECT);
}
use of cn.taketoday.web.view.ModelAndView in project today-infrastructure by TAKETODAY.
the class ParameterizableViewControllerTests method handleRequestWithFlashAttributes.
@Test
public void handleRequestWithFlashAttributes() throws Exception {
this.request.setAttribute(RedirectModel.INPUT_ATTRIBUTE, new RedirectModel("name", "value"));
ModelAndView mav = this.controller.handleRequest(this.context);
assertThat(mav.getModel().size()).isEqualTo(1);
assertThat(mav.getModel().get("name")).isEqualTo("value");
}
use of cn.taketoday.web.view.ModelAndView in project today-infrastructure by TAKETODAY.
the class ParameterizableViewControllerTests method handleRequestWithoutViewName.
@Test
public void handleRequestWithoutViewName() throws Exception {
ModelAndView mav = this.controller.handleRequest(this.context);
assertThat(mav.getViewName()).isNull();
assertThat(mav.getModel().isEmpty()).isTrue();
}
use of cn.taketoday.web.view.ModelAndView in project today-infrastructure by TAKETODAY.
the class ParameterizableViewControllerTests method viewNameAndStatus204.
@Test
public void viewNameAndStatus204() throws Exception {
this.controller.setStatusCode(HttpStatus.NO_CONTENT);
ModelAndView modelAndView = this.controller.handleRequest(this.context);
assertThat(modelAndView).isNull();
assertThat(this.response.getStatus()).isEqualTo(204);
}
Aggregations