25
25
import org .springframework .context .annotation .Configuration ;
26
26
import org .springframework .stereotype .Controller ;
27
27
import org .springframework .ui .ModelMap ;
28
- import org .springframework .web .bind .annotation .RequestMapping ;
29
- import org .springframework .web .bind .annotation .RequestMethod ;
28
+ import org .springframework .web .bind .annotation .GetMapping ;
30
29
import org .springframework .web .context .support .AnnotationConfigWebApplicationContext ;
31
30
import org .springframework .web .servlet .DispatcherServlet ;
32
31
import org .springframework .web .servlet .view .freemarker .FreeMarkerConfigurer ;
48
47
*/
49
48
class ViewResolutionIntegrationTests {
50
49
50
+ private static final String EXPECTED_BODY = "<html><body>Hello World!</body></html>" ;
51
+
52
+
51
53
@ Test
52
54
void freemarker () throws Exception {
53
55
MockHttpServletResponse response = runTest (FreeMarkerWebConfig .class );
54
- assertThat (response .getContentAsString ()).isEqualTo ("<html><body>Hello World!</body></html>" );
56
+ assertThat (response .getContentAsString ()).isEqualTo (EXPECTED_BODY );
57
+ }
58
+
59
+ @ Test // SPR-12013
60
+ void freemarkerWithExistingViewResolver () throws Exception {
61
+ MockHttpServletResponse response = runTest (ExistingViewResolverConfig .class );
62
+ assertThat (response .getContentAsString ()).isEqualTo (EXPECTED_BODY );
55
63
}
56
64
57
65
@ Test
58
66
void groovyMarkup () throws Exception {
59
67
MockHttpServletResponse response = runTest (GroovyMarkupWebConfig .class );
60
- assertThat (response .getContentAsString ()).isEqualTo ("<html><body>Hello World!</body></html>" );
68
+ assertThat (response .getContentAsString ()).isEqualTo (EXPECTED_BODY );
61
69
}
62
70
63
71
@ Test
@@ -74,14 +82,6 @@ void groovyMarkupInvalidConfig() {
74
82
.withMessageContaining ("In addition to a Groovy markup view resolver " );
75
83
}
76
84
77
- // SPR-12013
78
-
79
- @ Test
80
- void existingViewResolver () throws Exception {
81
- MockHttpServletResponse response = runTest (ExistingViewResolverConfig .class );
82
- assertThat (response .getContentAsString ()).isEqualTo ("<html><body>Hello World!</body></html>" );
83
- }
84
-
85
85
86
86
private MockHttpServletResponse runTest (Class <?> configClass ) throws ServletException , IOException {
87
87
String basePath = "org/springframework/web/servlet/config/annotation" ;
@@ -104,7 +104,7 @@ private MockHttpServletResponse runTest(Class<?> configClass) throws ServletExce
104
104
@ Controller
105
105
static class SampleController {
106
106
107
- @ RequestMapping ( value = "/" , method = RequestMethod . GET )
107
+ @ GetMapping
108
108
public String sample (ModelMap model ) {
109
109
model .addAttribute ("hello" , "Hello World!" );
110
110
return "index" ;
@@ -136,6 +136,25 @@ public FreeMarkerConfigurer freeMarkerConfigurer() {
136
136
}
137
137
}
138
138
139
+ /**
140
+ * Test @EnableWebMvc in the presence of a pre-existing ViewResolver.
141
+ */
142
+ @ Configuration
143
+ static class ExistingViewResolverConfig extends AbstractWebConfig {
144
+
145
+ @ Bean
146
+ public FreeMarkerViewResolver freeMarkerViewResolver () {
147
+ return new FreeMarkerViewResolver ("" , ".ftl" );
148
+ }
149
+
150
+ @ Bean
151
+ public FreeMarkerConfigurer freeMarkerConfigurer () {
152
+ FreeMarkerConfigurer configurer = new FreeMarkerConfigurer ();
153
+ configurer .setTemplateLoaderPath ("/WEB-INF/" );
154
+ return configurer ;
155
+ }
156
+ }
157
+
139
158
@ Configuration
140
159
static class GroovyMarkupWebConfig extends AbstractWebConfig {
141
160
@@ -170,23 +189,4 @@ public void configureViewResolvers(ViewResolverRegistry registry) {
170
189
}
171
190
}
172
191
173
- /**
174
- * Test @EnableWebMvc in the presence of pre-existing ViewResolver.
175
- */
176
- @ Configuration
177
- static class ExistingViewResolverConfig extends AbstractWebConfig {
178
-
179
- @ Bean
180
- public FreeMarkerViewResolver freeMarkerViewResolver () {
181
- return new FreeMarkerViewResolver ("" , ".ftl" );
182
- }
183
-
184
- @ Bean
185
- public FreeMarkerConfigurer freeMarkerConfigurer () {
186
- FreeMarkerConfigurer configurer = new FreeMarkerConfigurer ();
187
- configurer .setTemplateLoaderPath ("/WEB-INF/" );
188
- return configurer ;
189
- }
190
- }
191
-
192
192
}
0 commit comments