|
|
@ -13,6 +13,7 @@
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.bootstrap.autoconfigure.web;
|
|
|
|
package org.springframework.bootstrap.autoconfigure.web;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.MultipartConfigElement;
|
|
|
|
import javax.servlet.MultipartConfigElement;
|
|
|
@ -40,8 +41,8 @@ import static org.junit.Assert.assertNull;
|
|
|
|
import static org.junit.Assert.assertSame;
|
|
|
|
import static org.junit.Assert.assertSame;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* A series of embedded unit tests, based on an empty configuration, no multipart
|
|
|
|
* Tests for {@link MultipartAutoConfiguration}. Tests an empty configuration, no
|
|
|
|
* configuration, and a multipart configuration, with both Jetty and Tomcat.
|
|
|
|
* multipart configuration, and a multipart configuration (with both Jetty and Tomcat).
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Greg Turnquist
|
|
|
|
* @author Greg Turnquist
|
|
|
|
* @author Dave Syer
|
|
|
|
* @author Dave Syer
|
|
|
@ -51,7 +52,7 @@ public class MultipartAutoConfigurationTests {
|
|
|
|
private AnnotationConfigEmbeddedWebApplicationContext context;
|
|
|
|
private AnnotationConfigEmbeddedWebApplicationContext context;
|
|
|
|
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
@Rule
|
|
|
|
public ExpectedException exception = ExpectedException.none();
|
|
|
|
public ExpectedException thrown = ExpectedException.none();
|
|
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
@After
|
|
|
|
public void close() {
|
|
|
|
public void close() {
|
|
|
@ -121,8 +122,39 @@ public class MultipartAutoConfigurationTests {
|
|
|
|
verifyServletWorks();
|
|
|
|
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
|
|
|
|
@Configuration
|
|
|
|
public static class ContainerWithNoMultipartTomcat {
|
|
|
|
public static class ContainerWithNoMultipartTomcat {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
TomcatEmbeddedServletContainerFactory containerFactory() {
|
|
|
|
TomcatEmbeddedServletContainerFactory containerFactory() {
|
|
|
|
return new TomcatEmbeddedServletContainerFactory();
|
|
|
|
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
|
|
|
|
@Configuration
|
|
|
|
public static class ContainerWithEverythingJetty {
|
|
|
|
public static class ContainerWithEverythingJetty {
|
|
|
|
@Bean
|
|
|
|
@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
|
|
|
|
@Configuration
|
|
|
|
@EnableWebMvc
|
|
|
|
@EnableWebMvc
|
|
|
|
public static class ContainerWithEverythingTomcat {
|
|
|
|
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");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|