|
|
|
@ -17,6 +17,7 @@
|
|
|
|
|
package org.springframework.boot.autoconfigure.web;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
@ -25,6 +26,7 @@ import java.util.Map;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import org.joda.time.DateTime;
|
|
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.Rule;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
@ -41,6 +43,7 @@ import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
import org.springframework.core.io.Resource;
|
|
|
|
|
import org.springframework.format.support.FormattingConversionService;
|
|
|
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
|
|
|
import org.springframework.util.ReflectionUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
@ -152,6 +155,7 @@ public class WebMvcAutoConfigurationTests {
|
|
|
|
|
equalTo((Resource) new ClassPathResource("/foo/")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void noLocaleResolver() throws Exception {
|
|
|
|
|
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
|
|
|
|
this.context.register(AllResources.class, Config.class,
|
|
|
|
@ -183,6 +187,35 @@ public class WebMvcAutoConfigurationTests {
|
|
|
|
|
assertThat(locale.toString(), equalTo("en_UK"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void noDateFormat() throws Exception {
|
|
|
|
|
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
|
|
|
|
this.context.register(AllResources.class, Config.class,
|
|
|
|
|
WebMvcAutoConfiguration.class,
|
|
|
|
|
HttpMessageConvertersAutoConfiguration.class,
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
FormattingConversionService cs = this.context.getBean(FormattingConversionService.class);
|
|
|
|
|
Date date = new DateTime(1988, 6, 25, 20, 30).toDate();
|
|
|
|
|
// formatting cs should use simple toString()
|
|
|
|
|
assertThat(cs.convert(date, String.class), equalTo(date.toString()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void overrideDateFormat() throws Exception {
|
|
|
|
|
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
|
|
|
|
// set fixed date format
|
|
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, "spring.mvc.date-format:dd*MM*yyyy");
|
|
|
|
|
this.context.register(AllResources.class, Config.class,
|
|
|
|
|
WebMvcAutoConfiguration.class,
|
|
|
|
|
HttpMessageConvertersAutoConfiguration.class,
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
FormattingConversionService cs = this.context.getBean(FormattingConversionService.class);
|
|
|
|
|
Date date = new DateTime(1988, 6, 25, 20, 30).toDate();
|
|
|
|
|
assertThat(cs.convert(date, String.class), equalTo("25*06*1988"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void noMessageCodesResolver() throws Exception {
|
|
|
|
|
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
|
|
|
|