Fix another test from gh-708
This commit is contained in:
parent
26c5a3edb2
commit
3173646635
|
|
@ -16,9 +16,13 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.web;
|
||||
|
||||
import javax.servlet.MultipartConfigElement;
|
||||
import javax.servlet.Servlet;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
|
||||
import org.springframework.boot.context.embedded.MultipartConfigFactory;
|
||||
|
|
@ -28,58 +32,55 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
|
||||
|
||||
import javax.servlet.MultipartConfigElement;
|
||||
import javax.servlet.Servlet;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for multi-part uploads. Adds a
|
||||
* {@link StandardServletMultipartResolver} if none is present, and adds a
|
||||
* {@link javax.servlet.MultipartConfigElement multipartConfigElement} if none is otherwise defined.
|
||||
* The {@link EmbeddedWebApplicationContext} will associate the
|
||||
* {@link javax.servlet.MultipartConfigElement multipartConfigElement} if none is
|
||||
* otherwise defined. The {@link EmbeddedWebApplicationContext} will associate the
|
||||
* {@link MultipartConfigElement} bean to any {@link Servlet} beans.
|
||||
* <p/>
|
||||
* The {@link javax.servlet.MultipartConfigElement} is a Servlet API that's used to configure how the container handles
|
||||
* file uploads. By default
|
||||
* The {@link javax.servlet.MultipartConfigElement} is a Servlet API that's used to
|
||||
* configure how the container handles file uploads. By default
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @author Josh Long
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({Servlet.class, StandardServletMultipartResolver.class})
|
||||
@ConditionalOnClass({ Servlet.class, StandardServletMultipartResolver.class })
|
||||
@ConditionalOnExpression("${multipart.enabled:true}")
|
||||
@EnableConfigurationProperties(MultipartProperties.class)
|
||||
public class MultipartAutoConfiguration {
|
||||
|
||||
@Autowired
|
||||
private MultipartProperties multipartProperties = new MultipartProperties();
|
||||
@Autowired
|
||||
private MultipartProperties multipartProperties = new MultipartProperties();
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MultipartConfigElement multipartConfigElement() {
|
||||
MultipartConfigFactory factory = new MultipartConfigFactory();
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MultipartConfigElement multipartConfigElement() {
|
||||
MultipartConfigFactory factory = new MultipartConfigFactory();
|
||||
|
||||
if (StringUtils.hasText(this.multipartProperties.getFileSizeThreshold())) {
|
||||
factory.setFileSizeThreshold(this.multipartProperties.getFileSizeThreshold());
|
||||
}
|
||||
if (StringUtils.hasText(this.multipartProperties.getFileSizeThreshold())) {
|
||||
factory.setFileSizeThreshold(this.multipartProperties.getFileSizeThreshold());
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(this.multipartProperties.getLocation())) {
|
||||
factory.setLocation(this.multipartProperties.getLocation());
|
||||
}
|
||||
if (StringUtils.hasText(this.multipartProperties.getLocation())) {
|
||||
factory.setLocation(this.multipartProperties.getLocation());
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(this.multipartProperties.getMaxRequestSize())) {
|
||||
factory.setMaxRequestSize(this.multipartProperties.getMaxRequestSize());
|
||||
}
|
||||
if (StringUtils.hasText(this.multipartProperties.getMaxRequestSize())) {
|
||||
factory.setMaxRequestSize(this.multipartProperties.getMaxRequestSize());
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(this.multipartProperties.getMaxFileSize())) {
|
||||
factory.setMaxFileSize(this.multipartProperties.getMaxFileSize());
|
||||
}
|
||||
if (StringUtils.hasText(this.multipartProperties.getMaxFileSize())) {
|
||||
factory.setMaxFileSize(this.multipartProperties.getMaxFileSize());
|
||||
}
|
||||
|
||||
return factory.createMultipartConfig();
|
||||
}
|
||||
return factory.createMultipartConfig();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public StandardServletMultipartResolver multipartResolver() {
|
||||
return new StandardServletMultipartResolver();
|
||||
}
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public StandardServletMultipartResolver multipartResolver() {
|
||||
return new StandardServletMultipartResolver();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
|||
import org.springframework.context.annotation.Condition;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
|
|
@ -211,7 +211,7 @@ public class AutoConfigurationReportTests {
|
|||
ConditionAndOutcomes outcomes = report.getConditionAndOutcomesBySource().get(
|
||||
autoconfigKey);
|
||||
assertThat(outcomes, not(nullValue()));
|
||||
assertThat(getNumberOfOutcomes(outcomes), equalTo(1));
|
||||
assertThat(getNumberOfOutcomes(outcomes), equalTo(2));
|
||||
|
||||
List<String> messages = new ArrayList<String>();
|
||||
for (ConditionAndOutcome outcome : outcomes) {
|
||||
|
|
@ -221,7 +221,7 @@ public class AutoConfigurationReportTests {
|
|||
|
||||
Matcher<String> onClassMessage = containsString("@ConditionalOnClass "
|
||||
+ "classes found: javax.servlet.Servlet,org.springframework.web.multipart.support.StandardServletMultipartResolver");
|
||||
assertThat(messages, contains(onClassMessage));
|
||||
assertThat(messages, hasItem(onClassMessage));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue