Search in sources :

Example 26 with RequestContext

use of cn.taketoday.web.RequestContext in project today-framework by TAKETODAY.

the class UrlFilenameViewControllerTests method nestedPathisUsedAsViewName_InBreakingChangeFromSpring12Line.

/**
 * This is the expected behavior, and it now has a test to prove it.
 * https://opensource.atlassian.com/projects/spring/browse/SPR-2789
 */
@PathPatternsParameterizedTest
void nestedPathisUsedAsViewName_InBreakingChangeFromSpring12Line(Function<String, RequestContext> requestFactory) throws Exception {
    UrlFilenameViewController controller = new UrlFilenameViewController();
    RequestContext request = requestFactory.apply("/products/view.html");
    ModelAndView mv = controller.handleRequest(request);
    assertThat(mv.getViewName()).isEqualTo("products/view");
    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 27 with RequestContext

use of cn.taketoday.web.RequestContext in project today-framework by TAKETODAY.

the class UrlFilenameViewControllerTests method multiLevelMappingWithFallback.

@PathPatternsParameterizedTest
void multiLevelMappingWithFallback(Function<String, RequestContext> requestFactory) throws Exception {
    UrlFilenameViewController controller = new UrlFilenameViewController();
    RequestContext request = requestFactory.apply("/docs/cvs/commit.html");
    exposePathInMapping(request, "/docs/cvs/commit.html");
    ModelAndView mv = controller.handleRequest(request);
    assertThat(mv.getViewName()).isEqualTo("docs/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 28 with RequestContext

use of cn.taketoday.web.RequestContext in project today-framework by TAKETODAY.

the class WebContentInterceptorTests method mappedCacheConfigurationOverridesGlobal.

@Test
void mappedCacheConfigurationOverridesGlobal() throws Exception {
    Properties mappings = new Properties();
    mappings.setProperty("/*/*handle.vm", "-1");
    interceptor.setCacheSeconds(10);
    interceptor.setCacheMappings(mappings);
    RequestContext request = requestFactory.apply("/example/adminhandle.vm");
    interceptor.beforeProcess(request, handler);
    List<String> cacheControlHeaders = response.getHeaders("Cache-Control");
    assertThat(cacheControlHeaders).isEmpty();
    request = requestFactory.apply("/example/bingo.html");
    interceptor.beforeProcess(request, handler);
    cacheControlHeaders = response.getHeaders("Cache-Control");
    assertThat(cacheControlHeaders).contains("max-age=10");
}
Also used : ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) RequestContext(cn.taketoday.web.RequestContext) MockServletRequestContext(cn.taketoday.web.servlet.MockServletRequestContext) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 29 with RequestContext

use of cn.taketoday.web.RequestContext in project today-framework by TAKETODAY.

the class UrlFilenameViewControllerTests method withSuffix.

@PathPatternsParameterizedTest
void withSuffix(Function<String, RequestContext> requestFactory) throws Exception {
    UrlFilenameViewController controller = new UrlFilenameViewController();
    controller.setSuffix("_mysuf");
    RequestContext request = requestFactory.apply("/index.html");
    ModelAndView mv = controller.handleRequest(request);
    assertThat(mv.getViewName()).isEqualTo("index_mysuf");
    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 30 with RequestContext

use of cn.taketoday.web.RequestContext 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)

Aggregations

RequestContext (cn.taketoday.web.RequestContext)109 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)65 MockServletRequestContext (cn.taketoday.web.servlet.MockServletRequestContext)46 Test (org.junit.jupiter.api.Test)42 ModelAndView (cn.taketoday.web.view.ModelAndView)22 PathPatternsParameterizedTest (cn.taketoday.web.view.PathPatternsParameterizedTest)22 HashMap (java.util.HashMap)22 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)12 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)12 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)12 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)12 WebServletApplicationContext (cn.taketoday.web.servlet.WebServletApplicationContext)10 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)9 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)9 Map (java.util.Map)8 Properties (java.util.Properties)8 MockServletContext (cn.taketoday.web.mock.MockServletContext)6 WebSession (cn.taketoday.web.session.WebSession)6 MockServletContext (cn.taketoday.web.testfixture.servlet.MockServletContext)6 View (cn.taketoday.web.view.View)6