|
52 | 52 |
|
53 | 53 | import javax.servlet.ServletConfig;
|
54 | 54 | import javax.servlet.ServletContext;
|
| 55 | +import javax.servlet.ServletException; |
55 | 56 | import javax.servlet.http.Cookie;
|
56 | 57 | import javax.servlet.http.HttpServletRequest;
|
57 | 58 | import javax.servlet.http.HttpServletResponse;
|
|
60 | 61 | import javax.validation.constraints.NotNull;
|
61 | 62 | import javax.xml.bind.annotation.XmlRootElement;
|
62 | 63 |
|
| 64 | +import org.junit.jupiter.api.Test; |
| 65 | + |
63 | 66 | import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
64 | 67 | import org.springframework.aop.interceptor.SimpleTraceInterceptor;
|
65 | 68 | import org.springframework.aop.support.DefaultPointcutAdvisor;
|
|
134 | 137 | import org.springframework.web.context.WebApplicationContext;
|
135 | 138 | import org.springframework.web.context.request.NativeWebRequest;
|
136 | 139 | import org.springframework.web.context.request.WebRequest;
|
| 140 | +import org.springframework.web.context.support.GenericWebApplicationContext; |
137 | 141 | import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
138 | 142 | import org.springframework.web.multipart.support.StringMultipartFileEditor;
|
| 143 | +import org.springframework.web.servlet.DispatcherServlet; |
139 | 144 | import org.springframework.web.servlet.ModelAndView;
|
140 | 145 | import org.springframework.web.servlet.View;
|
141 | 146 | import org.springframework.web.servlet.ViewResolver;
|
| 147 | +import org.springframework.web.servlet.function.RouterFunction; |
| 148 | +import org.springframework.web.servlet.function.RouterFunctions; |
| 149 | +import org.springframework.web.servlet.function.ServerResponse; |
142 | 150 | import org.springframework.web.servlet.handler.PathPatternsParameterizedTest;
|
143 | 151 | import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver;
|
144 | 152 | import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
163 | 171 | */
|
164 | 172 | public class ServletAnnotationControllerHandlerMethodTests extends AbstractServletHandlerMethodTests {
|
165 | 173 |
|
166 |
| - @SuppressWarnings("unused") |
167 | 174 | static Stream<Boolean> pathPatternsArguments() {
|
168 | 175 | return Stream.of(true, false);
|
169 | 176 | }
|
170 | 177 |
|
171 |
| - |
172 | 178 | @PathPatternsParameterizedTest
|
173 | 179 | void emptyValueMapping(boolean usePathPatterns) throws Exception {
|
174 | 180 | initDispatcherServlet(ControllerWithEmptyValueMapping.class, usePathPatterns);
|
@@ -2099,6 +2105,26 @@ void dataClassBindingWithLocalDate(boolean usePathPatterns) throws Exception {
|
2099 | 2105 | assertThat(response.getContentAsString()).isEqualTo("2010-01-01");
|
2100 | 2106 | }
|
2101 | 2107 |
|
| 2108 | + @Test |
| 2109 | + void routerFunction() throws ServletException, IOException { |
| 2110 | + GenericWebApplicationContext wac = new GenericWebApplicationContext(); |
| 2111 | + wac.registerBean(RouterFunction.class, () -> |
| 2112 | + RouterFunctions.route() |
| 2113 | + .GET("/foo", request -> ServerResponse.ok().body("foo-body")) |
| 2114 | + .build()); |
| 2115 | + wac.refresh(); |
| 2116 | + |
| 2117 | + DispatcherServlet servlet = new DispatcherServlet(); |
| 2118 | + servlet.setApplicationContext(wac); |
| 2119 | + servlet.init(new MockServletConfig()); |
| 2120 | + |
| 2121 | + MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); |
| 2122 | + MockHttpServletResponse response = new MockHttpServletResponse(); |
| 2123 | + servlet.service(request, response); |
| 2124 | + |
| 2125 | + assertThat(response.getStatus()).isEqualTo(200); |
| 2126 | + assertThat(response.getContentAsString()).isEqualTo("foo-body"); |
| 2127 | + } |
2102 | 2128 |
|
2103 | 2129 | @Controller
|
2104 | 2130 | static class ControllerWithEmptyValueMapping {
|
|
0 commit comments