|
43 | 43 | * Tests for {@link DispatcherServletAutoConfiguration}.
|
44 | 44 | *
|
45 | 45 | * @author Dave Syer
|
| 46 | + * @author Andy Wilkinson |
46 | 47 | */
|
47 | 48 | public class DispatcherServletAutoConfigurationTests {
|
48 | 49 |
|
@@ -146,21 +147,38 @@ public void renamesMultipartResolver() throws Exception {
|
146 | 147 | }
|
147 | 148 |
|
148 | 149 | @Test
|
149 |
| - public void dispatcherServletConfig() { |
| 150 | + public void dispatcherServletDefaultConfig() { |
| 151 | + this.context = new AnnotationConfigWebApplicationContext(); |
| 152 | + this.context.setServletContext(new MockServletContext()); |
| 153 | + this.context.register(ServerPropertiesAutoConfiguration.class, |
| 154 | + DispatcherServletAutoConfiguration.class); |
| 155 | + this.context.refresh(); |
| 156 | + DispatcherServlet bean = this.context.getBean(DispatcherServlet.class); |
| 157 | + assertThat(bean).extracting("throwExceptionIfNoHandlerFound") |
| 158 | + .containsExactly(false); |
| 159 | + assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(true); |
| 160 | + assertThat(bean).extracting("dispatchTraceRequest").containsExactly(false); |
| 161 | + assertThat(new DirectFieldAccessor( |
| 162 | + this.context.getBean("dispatcherServletRegistration")) |
| 163 | + .getPropertyValue("loadOnStartup")).isEqualTo(-1); |
| 164 | + } |
| 165 | + |
| 166 | + @Test |
| 167 | + public void dispatcherServletCustomConfig() { |
150 | 168 | this.context = new AnnotationConfigWebApplicationContext();
|
151 | 169 | this.context.setServletContext(new MockServletContext());
|
152 | 170 | this.context.register(ServerPropertiesAutoConfiguration.class,
|
153 | 171 | DispatcherServletAutoConfiguration.class);
|
154 | 172 | EnvironmentTestUtils.addEnvironment(this.context,
|
155 | 173 | "spring.mvc.throw-exception-if-no-handler-found:true",
|
156 |
| - "spring.mvc.dispatch-options-request:true", |
| 174 | + "spring.mvc.dispatch-options-request:false", |
157 | 175 | "spring.mvc.dispatch-trace-request:true",
|
158 | 176 | "spring.mvc.servlet.load-on-startup=5");
|
159 | 177 | this.context.refresh();
|
160 | 178 | DispatcherServlet bean = this.context.getBean(DispatcherServlet.class);
|
161 | 179 | assertThat(bean).extracting("throwExceptionIfNoHandlerFound")
|
162 | 180 | .containsExactly(true);
|
163 |
| - assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(true); |
| 181 | + assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(false); |
164 | 182 | assertThat(bean).extracting("dispatchTraceRequest").containsExactly(true);
|
165 | 183 | assertThat(new DirectFieldAccessor(
|
166 | 184 | this.context.getBean("dispatcherServletRegistration"))
|
|
0 commit comments