Polish Spring Mobile Auto-configuration

Update Spring Mobile support with the following changes:
- Apply source formatting
- User lowercase property prefixes
- Use dashed notation when accessing properties
- Inline some constants

See gh-1049
This commit is contained in:
Phillip Webb 2014-06-08 23:22:44 -07:00
parent 6902f2ac97
commit 2852f7422e
5 changed files with 146 additions and 139 deletions

View File

@ -45,7 +45,7 @@ import org.thymeleaf.spring4.view.ThymeleafViewResolver;
* {@link LiteDeviceDelegatingViewResolver}. If {@link ThymeleafViewResolver} is available
* it is configured as the delegate view resolver. Otherwise,
* {@link InternalResourceViewResolver} is used as a fallback.
*
*
* @author Roy Clarkson
* @since 1.1.0
*/
@ -57,21 +57,49 @@ public class DeviceDelegatingViewResolverAutoConfiguration {
private static Log logger = LogFactory.getLog(WebMvcConfigurerAdapter.class);
public static final String DEFAULT_NORMAL_PREFIX = "";
private static abstract class AbstractDelegateConfiguration implements
EnvironmentAware {
public static final String DEFAULT_MOBILE_PREFIX = "mobile/";
private RelaxedPropertyResolver environment;
public static final String DEFAULT_TABLET_PREFIX = "tablet/";
@Override
public void setEnvironment(Environment environment) {
this.environment = new RelaxedPropertyResolver(environment,
"spring.mobile.devicedelegatingviewresolver.");
}
public static final String DEFAULT_NORMAL_SUFFIX = "";
protected LiteDeviceDelegatingViewResolver getConfiguredViewResolver(
ViewResolver delegate, int delegateOrder) {
LiteDeviceDelegatingViewResolver resolver = new LiteDeviceDelegatingViewResolver(
delegate);
resolver.setNormalPrefix(getProperty("normal-prefix", ""));
resolver.setNormalSuffix(getProperty("normal-suffix", ""));
resolver.setMobilePrefix(getProperty("mobile-prefix", "mobile/"));
resolver.setMobileSuffix(getProperty("mobile-suffix", ""));
resolver.setTabletPrefix(getProperty("tablet-prefix", "tablet/"));
resolver.setTabletSuffix(getProperty("tablet-suffix", ""));
resolver.setOrder(getAdjustedOrder(delegateOrder));
return resolver;
}
public static final String DEFAULT_MOBILE_SUFFIX = "";
private String getProperty(String key, String defaultValue) {
return this.environment.getProperty(key, defaultValue);
}
public static final String DEFAULT_TABLET_SUFFIX = "";
private int getAdjustedOrder(int order) {
if (order == Ordered.HIGHEST_PRECEDENCE) {
return Ordered.HIGHEST_PRECEDENCE;
}
// The view resolver must be ordered higher than the delegate view
// resolver, otherwise the view names will not be adjusted
return order - 1;
}
}
@Configuration
@ConditionalOnMissingBean(name = "deviceDelegatingViewResolver")
@ConditionalOnExpression("${spring.mobile.deviceDelegatingViewResolver.enabled:false}")
@ConditionalOnExpression("${spring.mobile.devicedelegatingviewresolver.enabled:false}")
protected static class DeviceDelegatingViewResolverConfiguration {
@Configuration
@ -81,15 +109,16 @@ public class DeviceDelegatingViewResolverAutoConfiguration {
extends AbstractDelegateConfiguration {
@Autowired
private ThymeleafViewResolver thymeleafViewResolver;
private ThymeleafViewResolver viewResolver;
@Bean
public LiteDeviceDelegatingViewResolver deviceDelegatingViewResolver() {
if (logger.isDebugEnabled()) {
logger.debug("LiteDeviceDelegatingViewResolver delegates to ThymeleafViewResolver");
logger.debug("LiteDeviceDelegatingViewResolver delegates to "
+ "ThymeleafViewResolver");
}
return getConfiguredViewResolver(thymeleafViewResolver,
thymeleafViewResolver.getOrder());
return getConfiguredViewResolver(this.viewResolver,
this.viewResolver.getOrder());
}
}
@ -101,58 +130,16 @@ public class DeviceDelegatingViewResolverAutoConfiguration {
AbstractDelegateConfiguration {
@Autowired
private InternalResourceViewResolver internalResourceViewResolver;
private InternalResourceViewResolver viewResolver;
@Bean
public LiteDeviceDelegatingViewResolver deviceDelegatingViewResolver() {
if (logger.isDebugEnabled()) {
logger.debug("LiteDeviceDelegatingViewResolver delegates to InternalResourceViewResolver");
}
return getConfiguredViewResolver(internalResourceViewResolver,
internalResourceViewResolver.getOrder());
}
}
private static abstract class AbstractDelegateConfiguration implements
EnvironmentAware {
private RelaxedPropertyResolver environment;
@Override
public void setEnvironment(Environment environment) {
this.environment = new RelaxedPropertyResolver(environment,
"spring.mobile.deviceDelegatingViewResolver.");
}
protected LiteDeviceDelegatingViewResolver getConfiguredViewResolver(
ViewResolver delegate, int delegateOrder) {
LiteDeviceDelegatingViewResolver resolver = new LiteDeviceDelegatingViewResolver(
delegate);
resolver.setNormalPrefix(this.environment.getProperty("normalPrefix",
DEFAULT_NORMAL_PREFIX));
resolver.setMobilePrefix(this.environment.getProperty("mobilePrefix",
DEFAULT_MOBILE_PREFIX));
resolver.setTabletPrefix(this.environment.getProperty("tabletPrefix",
DEFAULT_TABLET_PREFIX));
resolver.setNormalSuffix(this.environment.getProperty("normalSuffix",
DEFAULT_NORMAL_SUFFIX));
resolver.setMobileSuffix(this.environment.getProperty("mobileSuffix",
DEFAULT_MOBILE_SUFFIX));
resolver.setTabletSuffix(this.environment.getProperty("tabletSuffix",
DEFAULT_TABLET_SUFFIX));
resolver.setOrder(getAdjustedOrder(delegateOrder));
return resolver;
}
private int getAdjustedOrder(int delegateViewResolverOrder) {
if (delegateViewResolverOrder == Ordered.HIGHEST_PRECEDENCE) {
return Ordered.HIGHEST_PRECEDENCE;
} else {
// The view resolver must be ordered higher than the delegate view
// resolver, otherwise the view names will not be adjusted
return delegateViewResolverOrder - 1;
logger.debug("LiteDeviceDelegatingViewResolver delegates to "
+ "InternalResourceViewResolver");
}
return getConfiguredViewResolver(this.viewResolver,
this.viewResolver.getOrder());
}
}

View File

@ -45,9 +45,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
*/
@Configuration
@ConditionalOnClass({ SitePreferenceHandlerInterceptor.class,
SitePreferenceHandlerMethodArgumentResolver.class })
SitePreferenceHandlerMethodArgumentResolver.class })
@AutoConfigureAfter(DeviceResolverAutoConfiguration.class)
@ConditionalOnExpression("${spring.mobile.sitePreference.enabled:true}")
@ConditionalOnExpression("${spring.mobile.sitepreference.enabled:true}")
public class SitePreferenceAutoConfiguration {
@Configuration

View File

@ -16,10 +16,6 @@
package org.springframework.boot.autoconfigure.mobile;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Field;
import org.junit.After;
@ -43,9 +39,13 @@ import org.springframework.util.ReflectionUtils;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link DeviceDelegatingViewResolverAutoConfiguration}.
*
*
* @author Roy Clarkson
*/
public class DeviceDelegatingViewResolverAutoConfigurationTests {
@ -74,33 +74,36 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
@Test
public void deviceDelegatingInternalResourceViewResolverEnabled() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"spring.mobile.deviceDelegatingViewResolver.enabled:true");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:true");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DeviceDelegatingViewResolverConfiguration.class);
this.context.refresh();
InternalResourceViewResolver internalResourceViewResolver = this.context.getBean(InternalResourceViewResolver.class);
AbstractDeviceDelegatingViewResolver deviceDelegatingViewResolver = this.context.getBean(
"deviceDelegatingViewResolver",
AbstractDeviceDelegatingViewResolver.class);
InternalResourceViewResolver internalResourceViewResolver = this.context
.getBean(InternalResourceViewResolver.class);
AbstractDeviceDelegatingViewResolver deviceDelegatingViewResolver = this.context
.getBean("deviceDelegatingViewResolver",
AbstractDeviceDelegatingViewResolver.class);
assertNotNull(internalResourceViewResolver);
assertNotNull(deviceDelegatingViewResolver);
assertTrue(deviceDelegatingViewResolver.getViewResolver() instanceof InternalResourceViewResolver);
try {
this.context.getBean(ThymeleafViewResolver.class);
} catch (NoSuchBeanDefinitionException e) {
}
catch (NoSuchBeanDefinitionException e) {
// expected. ThymeleafViewResolver shouldn't be defined.
}
assertTrue(deviceDelegatingViewResolver.getOrder() == internalResourceViewResolver.getOrder() - 1);
assertTrue(deviceDelegatingViewResolver.getOrder() == internalResourceViewResolver
.getOrder() - 1);
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void deviceDelegatingInternalResourceViewResolverDisabled() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"spring.mobile.deviceDelegatingViewResolver.enabled:false");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:false");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
@ -109,7 +112,8 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
assertNotNull(this.context.getBean(InternalResourceViewResolver.class));
try {
this.context.getBean(ThymeleafViewResolver.class);
} catch (NoSuchBeanDefinitionException e) {
}
catch (NoSuchBeanDefinitionException e) {
// expected. ThymeleafViewResolver shouldn't be defined.
}
this.context.getBean("deviceDelegatingViewResolver",
@ -119,31 +123,33 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
@Test
public void deviceDelegatingThymeleafViewResolverEnabled() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"spring.mobile.deviceDelegatingViewResolver.enabled:true");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:true");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
ThymeleafAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DeviceDelegatingViewResolverConfiguration.class);
this.context.refresh();
ThymeleafViewResolver thymeleafViewResolver = this.context.getBean(ThymeleafViewResolver.class);
AbstractDeviceDelegatingViewResolver deviceDelegatingViewResolver = this.context.getBean(
"deviceDelegatingViewResolver",
AbstractDeviceDelegatingViewResolver.class);
ThymeleafViewResolver thymeleafViewResolver = this.context
.getBean(ThymeleafViewResolver.class);
AbstractDeviceDelegatingViewResolver deviceDelegatingViewResolver = this.context
.getBean("deviceDelegatingViewResolver",
AbstractDeviceDelegatingViewResolver.class);
assertNotNull(thymeleafViewResolver);
assertNotNull(deviceDelegatingViewResolver);
assertTrue(deviceDelegatingViewResolver.getViewResolver() instanceof ThymeleafViewResolver);
assertNotNull(this.context.getBean(InternalResourceViewResolver.class));
assertNotNull(this.context.getBean(ThymeleafViewResolver.class));
assertTrue(deviceDelegatingViewResolver.getOrder() == thymeleafViewResolver.getOrder() - 1);
assertTrue(deviceDelegatingViewResolver.getOrder() == thymeleafViewResolver
.getOrder() - 1);
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void deviceDelegatingThymeleafViewResolverDisabled() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"spring.mobile.deviceDelegatingViewResolver.enabled:false");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:false");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
ThymeleafAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
@ -159,15 +165,16 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
@Test
public void defaultPropertyValues() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"spring.mobile.deviceDelegatingViewResolver.enabled:true");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:true");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DeviceDelegatingViewResolverConfiguration.class);
this.context.refresh();
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context.getBean(
"deviceDelegatingViewResolver", LiteDeviceDelegatingViewResolver.class);
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context
.getBean("deviceDelegatingViewResolver",
LiteDeviceDelegatingViewResolver.class);
Field normalPrefixField = ReflectionUtils.findField(
LiteDeviceDelegatingViewResolver.class, "normalPrefix");
@ -215,16 +222,17 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
@Test
public void overrideNormalPrefix() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"spring.mobile.deviceDelegatingViewResolver.enabled:true",
"spring.mobile.deviceDelegatingViewResolver.normalPrefix:normal/");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:true",
"spring.mobile.devicedelegatingviewresolver.normalPrefix:normal/");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DeviceDelegatingViewResolverConfiguration.class);
this.context.refresh();
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context.getBean(
"deviceDelegatingViewResolver", LiteDeviceDelegatingViewResolver.class);
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context
.getBean("deviceDelegatingViewResolver",
LiteDeviceDelegatingViewResolver.class);
Field normalPrefixField = ReflectionUtils.findField(
LiteDeviceDelegatingViewResolver.class, "normalPrefix");
normalPrefixField.setAccessible(true);
@ -236,16 +244,17 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
@Test
public void overrideMobilePrefix() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"spring.mobile.deviceDelegatingViewResolver.enabled:true",
"spring.mobile.deviceDelegatingViewResolver.mobilePrefix:mob/");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:true",
"spring.mobile.devicedelegatingviewresolver.mobilePrefix:mob/");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DeviceDelegatingViewResolverConfiguration.class);
this.context.refresh();
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context.getBean(
"deviceDelegatingViewResolver", LiteDeviceDelegatingViewResolver.class);
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context
.getBean("deviceDelegatingViewResolver",
LiteDeviceDelegatingViewResolver.class);
Field mobilePrefixField = ReflectionUtils.findField(
LiteDeviceDelegatingViewResolver.class, "mobilePrefix");
mobilePrefixField.setAccessible(true);
@ -257,16 +266,17 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
@Test
public void overrideTabletPrefix() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"spring.mobile.deviceDelegatingViewResolver.enabled:true",
"spring.mobile.deviceDelegatingViewResolver.tabletPrefix:tab/");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:true",
"spring.mobile.devicedelegatingviewresolver.tabletPrefix:tab/");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DeviceDelegatingViewResolverConfiguration.class);
this.context.refresh();
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context.getBean(
"deviceDelegatingViewResolver", LiteDeviceDelegatingViewResolver.class);
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context
.getBean("deviceDelegatingViewResolver",
LiteDeviceDelegatingViewResolver.class);
Field tabletPrefixField = ReflectionUtils.findField(
LiteDeviceDelegatingViewResolver.class, "tabletPrefix");
tabletPrefixField.setAccessible(true);
@ -278,16 +288,17 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
@Test
public void overrideNormalSuffix() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"spring.mobile.deviceDelegatingViewResolver.enabled:true",
"spring.mobile.deviceDelegatingViewResolver.normalSuffix:.nor");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:true",
"spring.mobile.devicedelegatingviewresolver.normalSuffix:.nor");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DeviceDelegatingViewResolverConfiguration.class);
this.context.refresh();
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context.getBean(
"deviceDelegatingViewResolver", LiteDeviceDelegatingViewResolver.class);
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context
.getBean("deviceDelegatingViewResolver",
LiteDeviceDelegatingViewResolver.class);
Field normalSuffixField = ReflectionUtils.findField(
LiteDeviceDelegatingViewResolver.class, "normalSuffix");
normalSuffixField.setAccessible(true);
@ -299,16 +310,17 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
@Test
public void overrideMobileSuffix() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"spring.mobile.deviceDelegatingViewResolver.enabled:true",
"spring.mobile.deviceDelegatingViewResolver.mobileSuffix:.mob");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:true",
"spring.mobile.devicedelegatingviewresolver.mobileSuffix:.mob");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DeviceDelegatingViewResolverConfiguration.class);
this.context.refresh();
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context.getBean(
"deviceDelegatingViewResolver", LiteDeviceDelegatingViewResolver.class);
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context
.getBean("deviceDelegatingViewResolver",
LiteDeviceDelegatingViewResolver.class);
Field mobileSuffixField = ReflectionUtils.findField(
LiteDeviceDelegatingViewResolver.class, "mobileSuffix");
mobileSuffixField.setAccessible(true);
@ -320,16 +332,17 @@ public class DeviceDelegatingViewResolverAutoConfigurationTests {
@Test
public void overrideTabletSuffix() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"spring.mobile.deviceDelegatingViewResolver.enabled:true",
"spring.mobile.deviceDelegatingViewResolver.tabletSuffix:.tab");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:true",
"spring.mobile.devicedelegatingviewresolver.tabletSuffix:.tab");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DeviceDelegatingViewResolverConfiguration.class);
this.context.refresh();
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context.getBean(
"deviceDelegatingViewResolver", LiteDeviceDelegatingViewResolver.class);
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context
.getBean("deviceDelegatingViewResolver",
LiteDeviceDelegatingViewResolver.class);
Field tabletSuffixField = ReflectionUtils.findField(
LiteDeviceDelegatingViewResolver.class, "tabletSuffix");
tabletSuffixField.setAccessible(true);

View File

@ -16,9 +16,6 @@
package org.springframework.boot.autoconfigure.mobile;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.lang.reflect.Field;
import java.util.List;
@ -41,9 +38,12 @@ import org.springframework.util.ReflectionUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
/**
* Tests for {@link SitePreferenceAutoConfiguration}.
*
*
* @author Roy Clarkson
*/
public class SitePreferenceAutoConfigurationTests {
@ -70,7 +70,8 @@ public class SitePreferenceAutoConfigurationTests {
@Test
public void sitePreferenceHandlerInterceptorEnabled() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context, "spring.mobile.sitePreference.enabled:true");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.sitepreference.enabled:true");
this.context.register(SitePreferenceAutoConfiguration.class);
this.context.refresh();
assertNotNull(this.context.getBean(SitePreferenceHandlerInterceptor.class));
@ -79,7 +80,8 @@ public class SitePreferenceAutoConfigurationTests {
@Test(expected = NoSuchBeanDefinitionException.class)
public void sitePreferenceHandlerInterceptorDisabled() {
this.context = new AnnotationConfigWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context, "spring.mobile.sitePreference.enabled:false");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.sitepreference.enabled:false");
this.context.register(SitePreferenceAutoConfiguration.class);
this.context.refresh();
this.context.getBean(SitePreferenceHandlerInterceptor.class);
@ -90,22 +92,26 @@ public class SitePreferenceAutoConfigurationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SitePreferenceAutoConfiguration.class);
this.context.refresh();
assertNotNull(this.context.getBean(SitePreferenceHandlerMethodArgumentResolver.class));
assertNotNull(this.context
.getBean(SitePreferenceHandlerMethodArgumentResolver.class));
}
@Test
public void sitePreferenceMethodArgumentResolverEnabled() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context, "spring.mobile.sitePreference.enabled:true");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.sitepreference.enabled:true");
this.context.register(SitePreferenceAutoConfiguration.class);
this.context.refresh();
assertNotNull(this.context.getBean(SitePreferenceHandlerMethodArgumentResolver.class));
assertNotNull(this.context
.getBean(SitePreferenceHandlerMethodArgumentResolver.class));
}
@Test(expected = NoSuchBeanDefinitionException.class)
public void sitePreferenceMethodArgumentResolverDisabled() {
this.context = new AnnotationConfigWebApplicationContext();
EnvironmentTestUtils.addEnvironment(context, "spring.mobile.sitePreference.enabled:false");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.sitepreference.enabled:false");
this.context.register(SitePreferenceAutoConfiguration.class);
this.context.refresh();
this.context.getBean(SitePreferenceHandlerMethodArgumentResolver.class);
@ -120,7 +126,8 @@ public class SitePreferenceAutoConfigurationTests {
SitePreferenceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
RequestMappingHandlerMapping mapping = (RequestMappingHandlerMapping) context.getBean("requestMappingHandlerMapping");
RequestMappingHandlerMapping mapping = (RequestMappingHandlerMapping) context
.getBean("requestMappingHandlerMapping");
Field interceptorsField = ReflectionUtils.findField(
RequestMappingHandlerMapping.class, "interceptors");
interceptorsField.setAccessible(true);

View File

@ -290,16 +290,16 @@ content into your application; rather pick only the properties that you need.
spring.social.twitter.appSecret= # your application's Twitter App Secret
# SPRING MOBILE SITE PREFERENCE ({sc-spring-boot-autoconfigure}/mobile/SitePreferenceAutoConfiguration.{sc-ext}[SitePreferenceAutoConfiguration])
spring.mobile.sitePreference.enabled=true # enabled by default
spring.mobile.sitepreference.enabled=true # enabled by default
# SPRING MOBILE DEVICE VIEWS ({sc-spring-boot-autoconfigure}/mobile/DevceDelegatingViewResolverAutoConfiguration.{sc-ext}[DevceDelegatingViewResolverAutoConfiguration])
spring.mobile.deviceDelegatingViewResolver.enabled=true # disabled by default
spring.mobile.deviceDelegatingViewResolver.normalPrefix=nor/
spring.mobile.deviceDelegatingViewResolver.mobilePrefix=mob/ # default is "mobile/"
spring.mobile.deviceDelegatingViewResolver.tabletPrefix=tab/ # default is "tablet/"
spring.mobile.deviceDelegatingViewResolver.normalSuffix=.nor
spring.mobile.deviceDelegatingViewResolver.mobileSuffix=.mob
spring.mobile.deviceDelegatingViewResolver.tabletSuffix=.tab
spring.mobile.devicedelegatingviewresolver.enabled=true # disabled by default
spring.mobile.devicedelegatingviewresolver.normalPrefix=
spring.mobile.devicedelegatingviewresolver.normalSuffix=
spring.mobile.devicedelegatingviewresolver.mobilePrefix=mobile/
spring.mobile.devicedelegatingviewresolver.mobileSuffix=
spring.mobile.devicedelegatingviewresolver.tabletPrefix=tablet/
spring.mobile.devicedelegatingviewresolver.tabletSuffix=
# ----------------------------------------
# ACTUATOR PROPERTIES