Search in sources :

Example 1 with PathPatternsParameterizedTest

use of cn.taketoday.web.view.PathPatternsParameterizedTest in project today-infrastructure by TAKETODAY.

the class UrlFilenameViewControllerTests method withPrefix.

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

use of cn.taketoday.web.view.PathPatternsParameterizedTest in project today-infrastructure by TAKETODAY.

the class UrlFilenameViewControllerTests method withPrefixAndSuffix.

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

use of cn.taketoday.web.view.PathPatternsParameterizedTest in project today-infrastructure 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 4 with PathPatternsParameterizedTest

use of cn.taketoday.web.view.PathPatternsParameterizedTest in project today-infrastructure 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 5 with PathPatternsParameterizedTest

use of cn.taketoday.web.view.PathPatternsParameterizedTest in project today-infrastructure by TAKETODAY.

the class RequestMappingInfoTests method matchPatternsCondition.

@PathPatternsParameterizedTest
void matchPatternsCondition(RequestMappingInfo.Builder builder) {
    boolean useParsedPatterns = builder.build().getPathPatternsCondition() != null;
    HttpServletRequest request = initRequest("GET", "/foo", useParsedPatterns);
    RequestMappingInfo info = builder.paths("/foo*", "/bar").build();
    RequestMappingInfo expected = builder.paths("/foo*").build();
    assertThat(info.getMatchingCondition(new ServletRequestContext(null, request, null))).isEqualTo(expected);
    info = builder.paths("/**", "/foo*", "/foo").build();
    expected = builder.paths("/foo", "/foo*", "/**").build();
    assertThat(info.getMatchingCondition(new ServletRequestContext(null, request, null))).isEqualTo(expected);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Aggregations

PathPatternsParameterizedTest (cn.taketoday.web.view.PathPatternsParameterizedTest)26 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)25 RequestContext (cn.taketoday.web.RequestContext)22 MockServletRequestContext (cn.taketoday.web.servlet.MockServletRequestContext)22 ModelAndView (cn.taketoday.web.view.ModelAndView)22 HttpMethod (cn.taketoday.http.HttpMethod)2 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)2 RedirectModel (cn.taketoday.web.view.RedirectModel)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 Method (java.lang.reflect.Method)2 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)1