Search in sources :

Example 21 with ModelAndView

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();
}
Also used : ModelAndView(cn.taketoday.web.view.ModelAndView) RequestContext(cn.taketoday.web.RequestContext) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) MockServletRequestContext(cn.taketoday.web.servlet.MockServletRequestContext) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Example 22 with ModelAndView

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();
}
Also used : MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) ModelAndView(cn.taketoday.web.view.ModelAndView) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) MockServletRequestContext(cn.taketoday.web.servlet.MockServletRequestContext) StaticWebApplicationContext(cn.taketoday.web.context.support.StaticWebApplicationContext) MockHttpServletResponse(cn.taketoday.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Example 23 with ModelAndView

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();
}
Also used : ModelAndView(cn.taketoday.web.view.ModelAndView) RequestContext(cn.taketoday.web.RequestContext) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) MockServletRequestContext(cn.taketoday.web.servlet.MockServletRequestContext) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Example 24 with ModelAndView

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();
}
Also used : MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) ModelAndView(cn.taketoday.web.view.ModelAndView) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) StaticWebApplicationContext(cn.taketoday.web.context.support.StaticWebApplicationContext) MockHttpServletResponse(cn.taketoday.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 25 with ModelAndView

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);
}
Also used : ModelAndView(cn.taketoday.web.view.ModelAndView) Test(org.junit.jupiter.api.Test)

Aggregations

ModelAndView (cn.taketoday.web.view.ModelAndView)56 Test (org.junit.jupiter.api.Test)28 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)26 MockServletRequestContext (cn.taketoday.web.servlet.MockServletRequestContext)24 PathPatternsParameterizedTest (cn.taketoday.web.view.PathPatternsParameterizedTest)24 RequestContext (cn.taketoday.web.RequestContext)22 RedirectModel (cn.taketoday.web.view.RedirectModel)6 BindingContext (cn.taketoday.web.BindingContext)4 StaticWebApplicationContext (cn.taketoday.web.context.support.StaticWebApplicationContext)4 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)2 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)2 RedirectView (cn.taketoday.web.view.RedirectView)2 View (cn.taketoday.web.view.View)2