Search in sources :

Example 6 with ModelAndView

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

Example 7 with ModelAndView

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

Example 8 with ModelAndView

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

Example 9 with ModelAndView

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

Example 10 with ModelAndView

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);
}
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