|
|
|
@ -13,6 +13,7 @@
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.springframework.bootstrap.autoconfigure.web;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.MultipartConfigElement;
|
|
|
|
@ -40,8 +41,8 @@ import static org.junit.Assert.assertNull;
|
|
|
|
|
import static org.junit.Assert.assertSame;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A series of embedded unit tests, based on an empty configuration, no multipart
|
|
|
|
|
* configuration, and a multipart configuration, with both Jetty and Tomcat.
|
|
|
|
|
* Tests for {@link MultipartAutoConfiguration}. Tests an empty configuration, no
|
|
|
|
|
* multipart configuration, and a multipart configuration (with both Jetty and Tomcat).
|
|
|
|
|
*
|
|
|
|
|
* @author Greg Turnquist
|
|
|
|
|
* @author Dave Syer
|
|
|
|
@ -51,7 +52,7 @@ public class MultipartAutoConfigurationTests {
|
|
|
|
|
private AnnotationConfigEmbeddedWebApplicationContext context;
|
|
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
|
public ExpectedException exception = ExpectedException.none();
|
|
|
|
|
public ExpectedException thrown = ExpectedException.none();
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
public void close() {
|
|
|
|
@ -121,8 +122,39 @@ public class MultipartAutoConfigurationTests {
|
|
|
|
|
verifyServletWorks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void containerWithAutomatedMultipartJettyConfiguration() {
|
|
|
|
|
this.context = new AnnotationConfigEmbeddedWebApplicationContext(
|
|
|
|
|
ContainerWithEverythingJetty.class,
|
|
|
|
|
EmbeddedServletContainerAutoConfiguration.class,
|
|
|
|
|
MultipartAutoConfiguration.class);
|
|
|
|
|
this.context.getBean(MultipartConfigElement.class);
|
|
|
|
|
assertSame(this.context.getBean(DispatcherServlet.class).getMultipartResolver(),
|
|
|
|
|
this.context.getBean(StandardServletMultipartResolver.class));
|
|
|
|
|
verifyServletWorks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void containerWithAutomatedMultipartTomcatConfiguration() {
|
|
|
|
|
this.context = new AnnotationConfigEmbeddedWebApplicationContext(
|
|
|
|
|
ContainerWithEverythingTomcat.class,
|
|
|
|
|
EmbeddedServletContainerAutoConfiguration.class,
|
|
|
|
|
MultipartAutoConfiguration.class);
|
|
|
|
|
this.context.getBean(MultipartConfigElement.class);
|
|
|
|
|
assertSame(this.context.getBean(DispatcherServlet.class).getMultipartResolver(),
|
|
|
|
|
this.context.getBean(StandardServletMultipartResolver.class));
|
|
|
|
|
verifyServletWorks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void verifyServletWorks() {
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
assertEquals(restTemplate.getForObject("http://localhost:8080/", String.class),
|
|
|
|
|
"Hello");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
public static class ContainerWithNoMultipartTomcat {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
TomcatEmbeddedServletContainerFactory containerFactory() {
|
|
|
|
|
return new TomcatEmbeddedServletContainerFactory();
|
|
|
|
@ -134,18 +166,6 @@ public class MultipartAutoConfigurationTests {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void containerWithAutomatedMultipartJettyConfiguration() {
|
|
|
|
|
this.context = new AnnotationConfigEmbeddedWebApplicationContext(
|
|
|
|
|
ContainerWithEverythingJetty.class,
|
|
|
|
|
EmbeddedServletContainerAutoConfiguration.class,
|
|
|
|
|
MultipartAutoConfiguration.class);
|
|
|
|
|
this.context.getBean(MultipartConfigElement.class);
|
|
|
|
|
assertSame(this.context.getBean(DispatcherServlet.class).getMultipartResolver(),
|
|
|
|
|
this.context.getBean(StandardServletMultipartResolver.class));
|
|
|
|
|
verifyServletWorks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
public static class ContainerWithEverythingJetty {
|
|
|
|
|
@Bean
|
|
|
|
@ -164,18 +184,6 @@ public class MultipartAutoConfigurationTests {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void containerWithAutomatedMultipartTomcatConfiguration() {
|
|
|
|
|
this.context = new AnnotationConfigEmbeddedWebApplicationContext(
|
|
|
|
|
ContainerWithEverythingTomcat.class,
|
|
|
|
|
EmbeddedServletContainerAutoConfiguration.class,
|
|
|
|
|
MultipartAutoConfiguration.class);
|
|
|
|
|
this.context.getBean(MultipartConfigElement.class);
|
|
|
|
|
assertSame(this.context.getBean(DispatcherServlet.class).getMultipartResolver(),
|
|
|
|
|
this.context.getBean(StandardServletMultipartResolver.class));
|
|
|
|
|
verifyServletWorks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@EnableWebMvc
|
|
|
|
|
public static class ContainerWithEverythingTomcat {
|
|
|
|
@ -204,10 +212,4 @@ public class MultipartAutoConfigurationTests {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void verifyServletWorks() {
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
assertEquals(restTemplate.getForObject("http://localhost:8080/", String.class),
|
|
|
|
|
"Hello");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|