use of cn.taketoday.web.view.ModelAndView in project today-framework by TAKETODAY.
the class UrlFilenameViewControllerTests method multiLevelWithMapping.
@PathPatternsParameterizedTest
void multiLevelWithMapping(Function<String, RequestContext> requestFactory) throws Exception {
UrlFilenameViewController controller = new UrlFilenameViewController();
RequestContext request = requestFactory.apply("/cvs/commit.html");
ModelAndView mv = controller.handleRequest(request);
assertThat(mv.getViewName()).isEqualTo("cvs/commit");
assertThat(mv.getModel().isEmpty()).isTrue();
}
use of cn.taketoday.web.view.ModelAndView in project today-framework 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-framework by TAKETODAY.
the class UrlFilenameViewControllerTests method withFilenamePlusExtension.
@PathPatternsParameterizedTest
void withFilenamePlusExtension(Function<String, RequestContext> requestFactory) throws Exception {
UrlFilenameViewController controller = new UrlFilenameViewController();
RequestContext request = requestFactory.apply("/index.html");
ModelAndView mv = controller.handleRequest(request);
assertThat(mv.getViewName()).isEqualTo("index");
assertThat(mv.getModel().isEmpty()).isTrue();
}
use of cn.taketoday.web.view.ModelAndView in project today-framework by TAKETODAY.
the class ControllerTests method parameterizableViewController.
@Test
public void parameterizableViewController() throws Exception {
String viewName = "viewName";
ParameterizableViewController pvc = new ParameterizableViewController();
pvc.setViewName(viewName);
// We don't care about the params.
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.refresh();
ServletRequestContext context = new ServletRequestContext(wac, new MockHttpServletRequest("GET", "foo.html"), new MockHttpServletResponse());
ModelAndView mv = pvc.handleRequest(context);
assertThat(mv.getModel().size() == 0).as("model has no data").isTrue();
assertThat(mv.getViewName().equals(viewName)).as("model has correct viewname").isTrue();
assertThat(pvc.getViewName().equals(viewName)).as("getViewName matches").isTrue();
}
use of cn.taketoday.web.view.ModelAndView in project today-framework by TAKETODAY.
the class ParameterizableViewControllerTests method statusOnly.
@Test
public void statusOnly() throws Exception {
this.controller.setStatusCode(HttpStatus.NOT_FOUND);
this.controller.setStatusOnly(true);
ModelAndView modelAndView = this.controller.handleRequest(this.context);
assertThat(modelAndView).isNull();
assertThat(this.response.getStatus()).isEqualTo(404);
}
Aggregations