From 80ac1fb0cd3ce75715a758ce41898f033cf8c66a Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 14 Mar 2014 16:17:08 -0700 Subject: [PATCH] Polish --- .../actuate/health/SimpleHealthIndicator.java | 2 +- .../health/SimpleHealthIndicatorTests.java | 2 +- .../condition/SpringBootCondition.java | 10 +-- .../jdbc/AbstractDataSourceConfiguration.java | 35 +++++----- .../jdbc/CommonsDataSourceConfiguration.java | 65 +++++++++---------- .../jdbc/TomcatDataSourceConfiguration.java | 36 +++++----- .../thymeleaf/ThymeleafAutoConfiguration.java | 8 +-- .../DispatcherServletAutoConfiguration.java | 21 +++--- .../CommonsDataSourceConfigurationTests.java | 29 +++++---- .../TomcatDataSourceConfigurationTests.java | 39 +++++++---- .../web/ServerPropertiesTests.java | 6 +- .../SampleActuatorNoWebApplicationTests.java | 12 ++-- .../SampleActuatorUiApplicationPortTests.java | 14 ++-- .../ui/SampleActuatorUiApplicationTests.java | 10 +-- ...pertiesSampleActuatorApplicationTests.java | 6 +- ...gementAddressActuatorApplicationTests.java | 16 +++-- ...entPortSampleActuatorApplicationTests.java | 18 ++--- ...agementSampleActuatorApplicationTests.java | 18 ++--- .../SampleActuatorApplicationTests.java | 33 +++++----- ...hutdownSampleActuatorApplicationTests.java | 16 ++--- ...agementSampleActuatorApplicationTests.java | 12 ++-- ...nsecureSampleActuatorApplicationTests.java | 10 +-- .../jetty/SampleJettyApplicationTests.java | 8 +-- .../SampleServletApplicationTests.java | 24 +++++-- ...pringTestSampleSimpleApplicationTests.java | 2 +- ...igurationSampleTomcatApplicationTests.java | 6 +- .../tomcat/SampleTomcatApplicationTests.java | 8 +-- .../SampleTraditionalApplicationTests.java | 10 +-- .../java/sample/jsp/WelcomeController.java | 18 ++++- .../jsp/SampleWebJspApplicationTests.java | 24 +++++-- .../SampleMethodSecurityApplicationTests.java | 8 +-- .../secure/SampleSecureApplicationTests.java | 8 +-- .../ui/SampleWebStaticApplicationTests.java | 24 +++++-- .../sample/ui/MessageControllerWebTests.java | 28 ++++++-- .../ui/SampleWebUiApplicationTests.java | 26 ++++++-- ...omContainerWebSocketsApplicationTests.java | 14 ++-- .../SampleWebSocketsApplicationTests.java | 8 +-- .../boot/gradle/task/RunApp.java | 37 +++++------ .../boot/loader/LaunchedURLClassLoader.java | 25 ++++--- .../loader/LaunchedURLClassLoaderTests.java | 4 +- .../springframework/boot/maven/RunMojo.java | 30 ++++----- .../boot/SpringApplication.java | 19 +++--- .../embedded/FilterRegistrationBean.java | 6 +- .../embedded/ServletRegistrationBean.java | 6 +- .../boot/context/web/ErrorPageFilter.java | 45 +++++++------ .../org/springframework/boot/test/Base64.java | 7 +- .../boot/test/IntegrationTest.java | 2 +- .../boot/test/RestTemplates.java | 15 ++--- .../test/SpringApplicationContextLoader.java | 1 + .../ServletRegistrationBeanTests.java | 4 +- 50 files changed, 469 insertions(+), 366 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHealthIndicator.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHealthIndicator.java index 45d778144b..8893f89d70 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHealthIndicator.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHealthIndicator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SimpleHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SimpleHealthIndicatorTests.java index a9160cf191..1afb28c78e 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SimpleHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SimpleHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SpringBootCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SpringBootCondition.java index 085a2d862a..461c2417b5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SpringBootCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SpringBootCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,12 +46,12 @@ public abstract class SpringBootCondition implements Condition { recordEvaluation(context, classOrMethodName, outcome); return outcome.isMatch(); } - catch (NoClassDefFoundError e) { + catch (NoClassDefFoundError ex) { throw new IllegalStateException( "Could not evaluate condition owing to internal class not found. " - + "This can happen if you are @ComponentScanning a springframework package " - + "(e.g. if you put a @ComponentScan in the default package by mistake)", - e); + + "This can happen if you are @ComponentScanning a " + + "springframework package (e.g. if you put a @ComponentScan " + + "in the default package by mistake)", ex); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/AbstractDataSourceConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/AbstractDataSourceConfiguration.java index d13cd9d713..4923fd562d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/AbstractDataSourceConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/AbstractDataSourceConfiguration.java @@ -25,7 +25,7 @@ import org.springframework.util.StringUtils; /** * Base class for configuration of a database pool. - * + * * @author Dave Syer */ @ConfigurationProperties(name = DataSourceAutoConfiguration.CONFIGURATION_PREFIX) @@ -51,17 +51,17 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader private String validationQuery; - private boolean testOnBorrow = false; + private boolean testOnBorrow; - private boolean testOnReturn = false; + private boolean testOnReturn; - private boolean testWhileIdle = false; + private boolean testWhileIdle; - private int timeBetweenEvictionRunsMillis = getDefaultTimeBetweenEvictionRunsMillis(); + private Integer timeBetweenEvictionRunsMillis; - private int minEvictableIdleTimeMillis = getDefaultMinEvictableIdleTimeMillis(); + private Integer minEvictableIdleTimeMillis; - private int maxWaitMillis = getDefaultMaxWaitMillis(); + private Integer maxWaitMillis; private ClassLoader classLoader; @@ -184,7 +184,9 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; } - public void setMaxWait(int maxWaitMillis) { this.maxWaitMillis = maxWaitMillis; } + public void setMaxWait(int maxWaitMillis) { + this.maxWaitMillis = maxWaitMillis; + } public int getInitialSize() { return this.initialSize; @@ -218,15 +220,16 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader return this.testWhileIdle; } - protected int getTimeBetweenEvictionRunsMillis() { return this.timeBetweenEvictionRunsMillis; } + protected Integer getTimeBetweenEvictionRunsMillis() { + return this.timeBetweenEvictionRunsMillis; + } - protected int getMinEvictableIdleTimeMillis() { return this.minEvictableIdleTimeMillis; } + protected Integer getMinEvictableIdleTimeMillis() { + return this.minEvictableIdleTimeMillis; + } - protected int getMaxWaitMillis() { return this.maxWaitMillis; } + protected Integer getMaxWaitMillis() { + return this.maxWaitMillis; + } - protected abstract int getDefaultTimeBetweenEvictionRunsMillis(); - - protected abstract int getDefaultMinEvictableIdleTimeMillis(); - - protected abstract int getDefaultMaxWaitMillis(); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/CommonsDataSourceConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/CommonsDataSourceConfiguration.java index 5f47b671c3..47c709b3e7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/CommonsDataSourceConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/CommonsDataSourceConfiguration.java @@ -24,7 +24,6 @@ import javax.sql.DataSource; import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.commons.pool.impl.GenericObjectPool; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.dao.DataAccessResourceFailureException; @@ -32,7 +31,7 @@ import org.springframework.dao.DataAccessResourceFailureException; /** * Configuration for a Commons DBCP database pool. The DBCP pool is popular but not * recommended in high volume environments (the Tomcat DataSource is more reliable). - * + * * @author Dave Syer * @see DataSourceAutoConfiguration */ @@ -52,27 +51,38 @@ public class CommonsDataSourceConfiguration extends AbstractDataSourceConfigurat public DataSource dataSource() { logger.info("Hint: using Commons DBCP BasicDataSource. It's going to work, " + "but the Tomcat DataSource is more reliable."); - this.pool = new BasicDataSource(); - this.pool.setDriverClassName(getDriverClassName()); - this.pool.setUrl(getUrl()); + this.pool = createAndSetupPool(); + return this.pool; + } + + private BasicDataSource createAndSetupPool() { + BasicDataSource pool = new BasicDataSource(); + pool.setDriverClassName(getDriverClassName()); + pool.setUrl(getUrl()); if (getUsername() != null) { - this.pool.setUsername(getUsername()); + pool.setUsername(getUsername()); } if (getPassword() != null) { - this.pool.setPassword(getPassword()); + pool.setPassword(getPassword()); } - this.pool.setInitialSize(getInitialSize()); - this.pool.setMaxActive(getMaxActive()); - this.pool.setMaxIdle(getMaxIdle()); - this.pool.setMinIdle(getMinIdle()); - this.pool.setTestOnBorrow(isTestOnBorrow()); - this.pool.setTestOnReturn(isTestOnReturn()); - this.pool.setTestWhileIdle(isTestWhileIdle()); - this.pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis()); - this.pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis()); - this.pool.setValidationQuery(getValidationQuery()); - this.pool.setMaxWait(getMaxWaitMillis()); - return this.pool; + pool.setInitialSize(getInitialSize()); + pool.setMaxActive(getMaxActive()); + pool.setMaxIdle(getMaxIdle()); + pool.setMinIdle(getMinIdle()); + pool.setTestOnBorrow(isTestOnBorrow()); + pool.setTestOnReturn(isTestOnReturn()); + pool.setTestWhileIdle(isTestWhileIdle()); + pool.setValidationQuery(getValidationQuery()); + if (getTimeBetweenEvictionRunsMillis() != null) { + pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis()); + } + if (getMinEvictableIdleTimeMillis() != null) { + pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis()); + } + if (getMaxWaitMillis() != null) { + pool.setMaxWait(getMaxWaitMillis()); + } + return pool; } @PreDestroy @@ -80,25 +90,12 @@ public class CommonsDataSourceConfiguration extends AbstractDataSourceConfigurat if (this.pool != null) { try { this.pool.close(); - } catch (SQLException ex) { + } + catch (SQLException ex) { throw new DataAccessResourceFailureException( "Could not close data source", ex); } } } - @Override - protected int getDefaultTimeBetweenEvictionRunsMillis() { - return (int) GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS; - } - - @Override - protected int getDefaultMinEvictableIdleTimeMillis() { - return (int) GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS; - } - - @Override - protected int getDefaultMaxWaitMillis() { - return (int) GenericObjectPool.DEFAULT_MAX_WAIT; - } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfiguration.java index 0ea6043ef1..49e2523992 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfiguration.java @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration; /** * Configuration for a Tomcat database pool. The Tomcat pool provides superior performance * and tends not to deadlock in high volume environments. - * + * * @author Dave Syer * @see DataSourceAutoConfiguration */ @@ -54,12 +54,19 @@ public class TomcatDataSourceConfiguration extends AbstractDataSourceConfigurati this.pool.setTestOnBorrow(isTestOnBorrow()); this.pool.setTestOnReturn(isTestOnReturn()); this.pool.setTestWhileIdle(isTestWhileIdle()); - this.pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis()); - this.pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis()); + if (getTimeBetweenEvictionRunsMillis() != null) { + this.pool + .setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis()); + } + if (getMinEvictableIdleTimeMillis() != null) { + this.pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis()); + } this.pool.setValidationQuery(getValidationQuery()); this.pool.setValidationInterval(this.validationInterval); - this.pool.setMaxWait(getMaxWaitMillis()); - if (jdbcInterceptors != null) { + if (getMaxWaitMillis() != null) { + this.pool.setMaxWait(getMaxWaitMillis()); + } + if (this.jdbcInterceptors != null) { this.pool.setJdbcInterceptors(this.jdbcInterceptors); } return this.pool; @@ -72,22 +79,11 @@ public class TomcatDataSourceConfiguration extends AbstractDataSourceConfigurati } } - @Override - protected int getDefaultTimeBetweenEvictionRunsMillis() { - return 5000; + public void setJdbcInterceptors(String jdbcInterceptors) { + this.jdbcInterceptors = jdbcInterceptors; } - @Override - protected int getDefaultMinEvictableIdleTimeMillis() { - return 60000; + public void setValidationInterval(long validationInterval) { + this.validationInterval = validationInterval; } - - @Override - protected int getDefaultMaxWaitMillis() { - return 30000; - } - - public void setJdbcInterceptors(String jdbcInterceptors) { this.jdbcInterceptors = jdbcInterceptors; } - - public void setValidationInterval(long validationInterval) { this.validationInterval = validationInterval; } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index 85ee78d33e..b4a137efaa 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -84,11 +84,9 @@ public class ThymeleafAutoConfiguration { if (checkTemplateLocation) { Resource resource = this.resourceLoader.getResource(this.environment .getProperty("prefix", DEFAULT_PREFIX)); - Assert.state( - resource.exists(), - "Cannot find template location: " - + resource - + " (please add some templates or check your Thymeleaf configuration)"); + Assert.state(resource.exists(), "Cannot find template location: " + + resource + " (please add some templates " + + "or check your Thymeleaf configuration)"); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java index 05c0b206ee..c8b3cdd570 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java @@ -101,15 +101,11 @@ public class DispatcherServletAutoConfiguration { @Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { - ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); - ConditionOutcome outcome = checkServlets(beanFactory); - if (!outcome.isMatch()) { return outcome; } - return checkServletRegistrations(beanFactory); } @@ -123,9 +119,9 @@ public class DispatcherServletAutoConfiguration { .containsBean(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); if (servlets.isEmpty()) { if (containsDispatcherBean) { - return ConditionOutcome - .noMatch("found no DispatcherServlet but a non-DispatcherServlet named " - + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); + return ConditionOutcome.noMatch("found no DispatcherServlet " + + "but a non-DispatcherServlet named " + + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); } return ConditionOutcome.match("no DispatcherServlet found"); } @@ -138,9 +134,8 @@ public class DispatcherServletAutoConfiguration { + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); } - return ConditionOutcome - .match("one or more DispatcherServlets found and none is named " - + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); + return ConditionOutcome.match("one or more DispatcherServlets " + + "found and none is named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); } @@ -154,9 +149,9 @@ public class DispatcherServletAutoConfiguration { if (registrations.isEmpty()) { if (containsDispatcherRegistrationBean) { - return ConditionOutcome - .noMatch("found no ServletRegistrationBean but a non-ServletRegistrationBean named " - + DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); + return ConditionOutcome.noMatch("found no ServletRegistrationBean " + + "but a non-ServletRegistrationBean named " + + DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); } return ConditionOutcome.match("no ServletRegistrationBean found"); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/CommonsDataSourceConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/CommonsDataSourceConfigurationTests.java index f694d7feba..195262eb3a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/CommonsDataSourceConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/CommonsDataSourceConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,11 +29,13 @@ import static org.junit.Assert.assertNotNull; /** * Tests for {@link CommonsDataSourceConfiguration}. - * + * * @author Dave Syer */ public class CommonsDataSourceConfigurationTests { + private static final String PREFIX = "spring.datasource."; + private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); @Test @@ -47,13 +49,16 @@ public class CommonsDataSourceConfigurationTests { @Test public void testDataSourcePropertiesOverridden() throws Exception { this.context.register(CommonsDataSourceConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.url:jdbc:foo//bar/spam"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testWhileIdle:true"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnBorrow:true"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnReturn:true"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.timeBetweenEvictionRunsMillis:10000"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.minEvictableIdleTimeMillis:12345"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.maxWait:1234"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + + "url:jdbc:foo//bar/spam"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testWhileIdle:true"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnBorrow:true"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnReturn:true"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + + "timeBetweenEvictionRunsMillis:10000"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + + "minEvictableIdleTimeMillis:12345"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "maxWait:1234"); this.context.refresh(); BasicDataSource ds = this.context.getBean(BasicDataSource.class); assertEquals("jdbc:foo//bar/spam", ds.getUrl()); @@ -70,8 +75,10 @@ public class CommonsDataSourceConfigurationTests { this.context.register(CommonsDataSourceConfiguration.class); this.context.refresh(); BasicDataSource ds = this.context.getBean(BasicDataSource.class); - assertEquals(GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, ds.getTimeBetweenEvictionRunsMillis()); - assertEquals(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, ds.getMinEvictableIdleTimeMillis()); + assertEquals(GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, + ds.getTimeBetweenEvictionRunsMillis()); + assertEquals(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, + ds.getMinEvictableIdleTimeMillis()); assertEquals(GenericObjectPool.DEFAULT_MAX_WAIT, ds.getMaxWait()); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java index 6e8d267f12..7bf76e14d7 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java @@ -37,11 +37,13 @@ import static org.junit.Assert.fail; /** * Tests for {@link TomcatDataSourceConfiguration}. - * + * * @author Dave Syer */ public class TomcatDataSourceConfigurationTests { + private static final String PREFIX = "spring.datasource."; + private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); @After @@ -60,17 +62,23 @@ public class TomcatDataSourceConfigurationTests { @Test public void testDataSourcePropertiesOverridden() throws Exception { this.context.register(TomcatDataSourceConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.url:jdbc:foo//bar/spam"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testWhileIdle:true"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnBorrow:true"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnReturn:true"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.timeBetweenEvictionRunsMillis:10000"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.minEvictableIdleTimeMillis:12345"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.maxWait:1234"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.jdbcInterceptors:SlowQueryReport"); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.validationInterval:9999"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + + "url:jdbc:foo//bar/spam"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testWhileIdle:true"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnBorrow:true"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnReturn:true"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + + "timeBetweenEvictionRunsMillis:10000"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + + "minEvictableIdleTimeMillis:12345"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "maxWait:1234"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + + "jdbcInterceptors:SlowQueryReport"); + EnvironmentTestUtils.addEnvironment(this.context, PREFIX + + "validationInterval:9999"); this.context.refresh(); - org.apache.tomcat.jdbc.pool.DataSource ds = this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class); + org.apache.tomcat.jdbc.pool.DataSource ds = this.context + .getBean(org.apache.tomcat.jdbc.pool.DataSource.class); assertEquals("jdbc:foo//bar/spam", ds.getUrl()); assertEquals(true, ds.isTestWhileIdle()); assertEquals(true, ds.isTestOnBorrow()); @@ -82,8 +90,10 @@ public class TomcatDataSourceConfigurationTests { assertDataSourceHasInterceptors(ds); } - private void assertDataSourceHasInterceptors(DataSourceProxy ds) throws ClassNotFoundException { - PoolProperties.InterceptorDefinition[] interceptors = ds.getJdbcInterceptorsAsArray(); + private void assertDataSourceHasInterceptors(DataSourceProxy ds) + throws ClassNotFoundException { + PoolProperties.InterceptorDefinition[] interceptors = ds + .getJdbcInterceptorsAsArray(); for (PoolProperties.InterceptorDefinition interceptor : interceptors) { if (SlowQueryReport.class == interceptor.getInterceptorClass()) { return; @@ -96,7 +106,8 @@ public class TomcatDataSourceConfigurationTests { public void testDataSourceDefaultsPreserved() throws Exception { this.context.register(TomcatDataSourceConfiguration.class); this.context.refresh(); - org.apache.tomcat.jdbc.pool.DataSource ds = this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class); + org.apache.tomcat.jdbc.pool.DataSource ds = this.context + .getBean(org.apache.tomcat.jdbc.pool.DataSource.class); assertEquals(5000, ds.getTimeBetweenEvictionRunsMillis()); assertEquals(60000, ds.getMinEvictableIdleTimeMillis()); assertEquals(30000, ds.getMaxWait()); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index 4b36019cc2..07538ee253 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletCont import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** @@ -76,7 +76,7 @@ public class ServerPropertiesTests { public void testCustomizeTomcat() throws Exception { ConfigurableEmbeddedServletContainer factory = mock(ConfigurableEmbeddedServletContainer.class); this.properties.customize(factory); - verify(factory, times(0)).setContextPath(""); + verify(factory, never()).setContextPath(""); } @Test diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/SampleActuatorNoWebApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/SampleActuatorNoWebApplicationTests.java index 7f33581d9a..aeadb06ac5 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/SampleActuatorNoWebApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/SampleActuatorNoWebApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package sample.actuator; -import static org.junit.Assert.assertNotNull; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -26,22 +24,24 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertNotNull; + /** * Basic integration tests for service demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleActuatorNoWebApplication.class) +@SpringApplicationConfiguration(classes = SampleActuatorNoWebApplication.class) @DirtiesContext public class SampleActuatorNoWebApplicationTests { - + @Autowired private MetricsEndpoint endpoint; @Test public void endpointsExist() throws Exception { - assertNotNull(endpoint); + assertNotNull(this.endpoint); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java index a33a7c3523..09861b1297 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package sample.actuator.ui; -import static org.junit.Assert.assertEquals; - import java.util.Map; import org.junit.Test; @@ -35,13 +33,15 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; + /** * Integration tests for separate management and main service ports. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleActuatorUiApplication.class) +@SpringApplicationConfiguration(classes = SampleActuatorUiApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext @@ -60,7 +60,7 @@ public class SampleActuatorUiApplicationPortTests { @Test public void testHome() throws Exception { ResponseEntity entity = RestTemplates.get().getForEntity( - "http://localhost:" + port, String.class); + "http://localhost:" + this.port, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); } @@ -68,14 +68,14 @@ public class SampleActuatorUiApplicationPortTests { public void testMetrics() throws Exception { @SuppressWarnings("rawtypes") ResponseEntity entity = RestTemplates.get().getForEntity( - "http://localhost:" + managementPort + "/metrics", Map.class); + "http://localhost:" + this.managementPort + "/metrics", Map.class); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); } @Test public void testHealth() throws Exception { ResponseEntity entity = RestTemplates.get().getForEntity( - "http://localhost:" + managementPort + "/health", String.class); + "http://localhost:" + this.managementPort + "/health", String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("ok", entity.getBody()); } diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java index 5c82064575..f199ac9182 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,6 @@ package sample.actuator.ui; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.util.Arrays; import java.util.Map; @@ -37,13 +34,16 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Basic integration tests for demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleActuatorUiApplication.class) +@SpringApplicationConfiguration(classes = SampleActuatorUiApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java index 4b2b5a5fec..823803c708 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package sample.actuator; -import static org.junit.Assert.assertEquals; - import java.util.Map; import org.junit.Test; @@ -32,6 +30,8 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; + /** * Integration tests for endpoints configuration. * diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java index 8e2b8f8b05..dcbee314fd 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package sample.actuator; -import static org.junit.Assert.assertEquals; - import java.util.Map; import org.junit.Test; @@ -35,13 +33,15 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; + /** * Integration tests for separate management and main service ports. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) +@SpringApplicationConfiguration(classes = SampleActuatorApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext @@ -61,14 +61,16 @@ public class ManagementAddressActuatorApplicationTests { public void testHome() throws Exception { @SuppressWarnings("rawtypes") ResponseEntity entity = RestTemplates.get().getForEntity( - "http://localhost:" + port, Map.class); + "http://localhost:" + this.port, Map.class); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); } @Test public void testHealth() throws Exception { - ResponseEntity entity = RestTemplates.get().getForEntity( - "http://localhost:" + managementPort + "/admin/health", String.class); + ResponseEntity entity = RestTemplates.get() + .getForEntity( + "http://localhost:" + this.managementPort + "/admin/health", + String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("ok", entity.getBody()); } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java index 58555dff12..05ef2990fa 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package sample.actuator; -import static org.junit.Assert.assertEquals; - import java.util.Map; import org.junit.Test; @@ -36,13 +34,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; +import static org.junit.Assert.assertEquals; + /** * Integration tests for separate management and main service ports. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) +@SpringApplicationConfiguration(classes = SampleActuatorApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext @@ -62,7 +62,7 @@ public class ManagementPortSampleActuatorApplicationTests { public void testHome() throws Exception { @SuppressWarnings("rawtypes") ResponseEntity entity = getRestTemplate("user", getPassword()).getForEntity( - "http://localhost:" + port, Map.class); + "http://localhost:" + this.port, Map.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); @SuppressWarnings("unchecked") Map body = entity.getBody(); @@ -74,14 +74,14 @@ public class ManagementPortSampleActuatorApplicationTests { testHome(); // makes sure some requests have been made @SuppressWarnings("rawtypes") ResponseEntity entity = getRestTemplate().getForEntity( - "http://localhost:" + managementPort + "/metrics", Map.class); + "http://localhost:" + this.managementPort + "/metrics", Map.class); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); } @Test public void testHealth() throws Exception { ResponseEntity entity = getRestTemplate().getForEntity( - "http://localhost:" + managementPort + "/health", String.class); + "http://localhost:" + this.managementPort + "/health", String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("ok", entity.getBody()); } @@ -90,7 +90,7 @@ public class ManagementPortSampleActuatorApplicationTests { public void testErrorPage() throws Exception { @SuppressWarnings("rawtypes") ResponseEntity entity = getRestTemplate().getForEntity( - "http://localhost:" + managementPort + "/error", Map.class); + "http://localhost:" + this.managementPort + "/error", Map.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); @SuppressWarnings("unchecked") Map body = entity.getBody(); @@ -98,7 +98,7 @@ public class ManagementPortSampleActuatorApplicationTests { } private String getPassword() { - return security.getUser().getPassword(); + return this.security.getUser().getPassword(); } private RestTemplate getRestTemplate() { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java index 72781587cb..4f9e3c354d 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package sample.actuator; -import static org.junit.Assert.assertEquals; - import java.util.Map; import org.junit.Test; @@ -34,13 +32,15 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; + /** * Integration tests for switching off management endpoints. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) +@SpringApplicationConfiguration(classes = SampleActuatorApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext @@ -53,8 +53,8 @@ public class NoManagementSampleActuatorApplicationTests { @Test public void testHome() throws Exception { @SuppressWarnings("rawtypes") - ResponseEntity entity = RestTemplates.get("user", getPassword()).getForEntity( - "http://localhost:8080", Map.class); + ResponseEntity entity = RestTemplates.get("user", getPassword()) + .getForEntity("http://localhost:8080", Map.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); @SuppressWarnings("unchecked") Map body = entity.getBody(); @@ -65,13 +65,13 @@ public class NoManagementSampleActuatorApplicationTests { public void testMetricsNotAvailable() throws Exception { testHome(); // makes sure some requests have been made @SuppressWarnings("rawtypes") - ResponseEntity entity = RestTemplates.get("user", getPassword()).getForEntity( - "http://localhost:8080/metrics", Map.class); + ResponseEntity entity = RestTemplates.get("user", getPassword()) + .getForEntity("http://localhost:8080/metrics", Map.class); assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode()); } private String getPassword() { - return security.getUser().getPassword(); + return this.security.getUser().getPassword(); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java index 541e2ab258..34bb9cc1f9 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,6 @@ package sample.actuator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - import java.util.Arrays; import java.util.List; import java.util.Map; @@ -42,13 +37,18 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /** * Basic integration tests for service demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) +@SpringApplicationConfiguration(classes = SampleActuatorApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext @@ -73,8 +73,8 @@ public class SampleActuatorApplicationTests { @Test public void testHome() throws Exception { @SuppressWarnings("rawtypes") - ResponseEntity entity = RestTemplates.get("user", getPassword()).getForEntity( - "http://localhost:8080", Map.class); + ResponseEntity entity = RestTemplates.get("user", getPassword()) + .getForEntity("http://localhost:8080", Map.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); @SuppressWarnings("unchecked") Map body = entity.getBody(); @@ -85,8 +85,8 @@ public class SampleActuatorApplicationTests { public void testMetrics() throws Exception { testHome(); // makes sure some requests have been made @SuppressWarnings("rawtypes") - ResponseEntity entity = RestTemplates.get("user", getPassword()).getForEntity( - "http://localhost:8080/metrics", Map.class); + ResponseEntity entity = RestTemplates.get("user", getPassword()) + .getForEntity("http://localhost:8080/metrics", Map.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); @SuppressWarnings("unchecked") Map body = entity.getBody(); @@ -96,8 +96,8 @@ public class SampleActuatorApplicationTests { @Test public void testEnv() throws Exception { @SuppressWarnings("rawtypes") - ResponseEntity entity = RestTemplates.get("user", getPassword()).getForEntity( - "http://localhost:8080/env", Map.class); + ResponseEntity entity = RestTemplates.get("user", getPassword()) + .getForEntity("http://localhost:8080/env", Map.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); @SuppressWarnings("unchecked") Map body = entity.getBody(); @@ -127,8 +127,9 @@ public class SampleActuatorApplicationTests { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity request = new HttpEntity(headers); - ResponseEntity entity = RestTemplates.get("user", getPassword()).exchange( - "http://localhost:8080/foo", HttpMethod.GET, request, String.class); + ResponseEntity entity = RestTemplates.get("user", getPassword()) + .exchange("http://localhost:8080/foo", HttpMethod.GET, request, + String.class); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); String body = entity.getBody(); assertNotNull("Body was null", body); @@ -178,7 +179,7 @@ public class SampleActuatorApplicationTests { } private String getPassword() { - return security.getUser().getPassword(); + return this.security.getUser().getPassword(); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java index ab29b49df6..6e58abd58b 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,6 @@ package sample.actuator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.util.Map; import org.junit.Test; @@ -34,13 +31,16 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Integration tests for separate management and main service ports. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) +@SpringApplicationConfiguration(classes = SampleActuatorApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext @@ -52,8 +52,8 @@ public class ShutdownSampleActuatorApplicationTests { @Test public void testHome() throws Exception { @SuppressWarnings("rawtypes") - ResponseEntity entity = RestTemplates.get("user", getPassword()).getForEntity( - "http://localhost:8080", Map.class); + ResponseEntity entity = RestTemplates.get("user", getPassword()) + .getForEntity("http://localhost:8080", Map.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); @SuppressWarnings("unchecked") Map body = entity.getBody(); @@ -73,7 +73,7 @@ public class ShutdownSampleActuatorApplicationTests { } private String getPassword() { - return security.getUser().getPassword(); + return this.security.getUser().getPassword(); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/UnsecureManagementSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/UnsecureManagementSampleActuatorApplicationTests.java index 1e79a1266f..617d6d65e3 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/UnsecureManagementSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/UnsecureManagementSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,6 @@ package sample.actuator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.util.Map; import org.junit.Test; @@ -34,6 +30,10 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Integration tests for unsecured service endpoints (even with Spring Security on * classpath). @@ -41,7 +41,7 @@ import org.springframework.test.context.web.WebAppConfiguration; * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) +@SpringApplicationConfiguration(classes = SampleActuatorApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/UnsecureSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/UnsecureSampleActuatorApplicationTests.java index 94e310269f..24e0005113 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/UnsecureSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/UnsecureSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,6 @@ package sample.actuator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - import java.util.Map; import org.junit.Test; @@ -33,6 +30,9 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + /** * Integration tests for unsecured service endpoints (even with Spring Security on * classpath). @@ -40,7 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration; * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) +@SpringApplicationConfiguration(classes = SampleActuatorApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java index 143a57300b..4e485b3685 100644 --- a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package sample.jetty; -import static org.junit.Assert.assertEquals; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.IntegrationTest; @@ -29,13 +27,15 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; + /** * Basic integration tests for demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleJettyApplication.class) +@SpringApplicationConfiguration(classes = SampleJettyApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java index ee15011276..2f815d3b91 100644 --- a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java @@ -1,6 +1,20 @@ -package sample.servlet; +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.junit.Assert.assertEquals; +package sample.servlet; import org.junit.Test; import org.junit.runner.RunWith; @@ -15,13 +29,15 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; + /** * Basic integration tests for demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleServletApplication.class) +@SpringApplicationConfiguration(classes = SampleServletApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext @@ -46,6 +62,6 @@ public class SampleServletApplicationTests { } private String getPassword() { - return security.getUser().getPassword(); + return this.security.getUser().getPassword(); } } diff --git a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java index a37e3fba59..9cdd5b666d 100644 --- a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java index 6cffc01747..14400800c2 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java @@ -16,8 +16,6 @@ package sample.tomcat; -import static org.junit.Assert.assertEquals; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.SpringApplication; @@ -43,13 +41,15 @@ import sample.tomcat.NonAutoConfigurationSampleTomcatApplicationTests.NonAutoCon import sample.tomcat.service.HelloWorldService; import sample.tomcat.web.SampleController; +import static org.junit.Assert.assertEquals; + /** * Basic integration tests for demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=NonAutoConfigurationSampleTomcatApplication.class) +@SpringApplicationConfiguration(classes = NonAutoConfigurationSampleTomcatApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java index 1063eb6d7d..417b229544 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package sample.tomcat; -import static org.junit.Assert.assertEquals; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.IntegrationTest; @@ -29,13 +27,15 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; + /** * Basic integration tests for demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleTomcatApplication.class) +@SpringApplicationConfiguration(classes = SampleTomcatApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java b/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java index 589d7c4e65..1244e359b3 100644 --- a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,6 @@ package sample.traditional; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.IntegrationTest; @@ -30,13 +27,16 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Basic integration tests for demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleTraditionalApplication.class) +@SpringApplicationConfiguration(classes = SampleTraditionalApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/WelcomeController.java b/spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/WelcomeController.java index 4a701e2b6b..03d439caa3 100644 --- a/spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/WelcomeController.java +++ b/spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/WelcomeController.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package sample.jsp; import java.util.Date; @@ -16,7 +32,7 @@ public class WelcomeController { @RequestMapping("/") public String welcome(Map model) { model.put("time", new Date()); - model.put("message", message); + model.put("message", this.message); return "welcome"; } diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java index d4af97806e..ffd52a7e0d 100644 --- a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java @@ -1,7 +1,20 @@ -package sample.jsp; +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +package sample.jsp; import org.junit.Test; import org.junit.runner.RunWith; @@ -14,13 +27,16 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Basic integration tests for JSP application. * * @author Phillip Webb */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleWebJspApplication.class) +@SpringApplicationConfiguration(classes = SampleWebJspApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/ui/method/SampleMethodSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/ui/method/SampleMethodSecurityApplicationTests.java index e30f640583..82e8ff302b 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/ui/method/SampleMethodSecurityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/ui/method/SampleMethodSecurityApplicationTests.java @@ -16,9 +16,6 @@ package sample.ui.method; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -40,13 +37,16 @@ import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Basic integration tests for demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleMethodSecurityApplication.class) +@SpringApplicationConfiguration(classes = SampleMethodSecurityApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/ui/secure/SampleSecureApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/ui/secure/SampleSecureApplicationTests.java index 1aa6674b59..d5b5ba990c 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/ui/secure/SampleSecureApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/ui/secure/SampleSecureApplicationTests.java @@ -16,9 +16,6 @@ package sample.ui.secure; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.util.Arrays; import org.junit.Test; @@ -36,13 +33,16 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Basic integration tests for demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleSecureApplication.class) +@SpringApplicationConfiguration(classes = SampleSecureApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/ui/SampleWebStaticApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/ui/SampleWebStaticApplicationTests.java index deca6ef7db..5435326f3f 100644 --- a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/ui/SampleWebStaticApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/ui/SampleWebStaticApplicationTests.java @@ -1,7 +1,20 @@ -package sample.ui; +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +package sample.ui; import org.junit.Test; import org.junit.runner.RunWith; @@ -15,13 +28,16 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Basic integration tests for demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleWebStaticApplication.class) +@SpringApplicationConfiguration(classes = SampleWebStaticApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/MessageControllerWebTests.java b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/MessageControllerWebTests.java index e4b8d1fbed..37d4712794 100755 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/MessageControllerWebTests.java +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/MessageControllerWebTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package sample.ui; import java.util.regex.Pattern; @@ -56,12 +72,12 @@ public class MessageControllerWebTests { .andExpect(header().string("location", RegexMatcher.matches("/[0-9]+"))); } - @Test - public void testCreateValidation() throws Exception{ - this.mockMvc.perform(post("/").param("text", "").param("summary", "")) - .andExpect(status().isOk()) - .andExpect(content().string(containsString("is required"))); - } + @Test + public void testCreateValidation() throws Exception { + this.mockMvc.perform(post("/").param("text", "").param("summary", "")) + .andExpect(status().isOk()) + .andExpect(content().string(containsString("is required"))); + } private static class RegexMatcher extends TypeSafeMatcher { private final String regex; diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/SampleWebUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/SampleWebUiApplicationTests.java index dffd518e34..e12c40974e 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/SampleWebUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/SampleWebUiApplicationTests.java @@ -1,8 +1,20 @@ -package sample.ui; +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +package sample.ui; import java.net.URI; @@ -19,13 +31,17 @@ import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Basic integration tests for demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleWebUiApplication.class) +@SpringApplicationConfiguration(classes = SampleWebUiApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java index f73d6b0daa..8c44421f6e 100644 --- a/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/echo/CustomContainerWebSocketsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package samples.websocket.echo; -import static org.junit.Assert.assertEquals; - import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -46,17 +44,21 @@ import samples.websocket.client.SimpleGreetingService; import samples.websocket.config.SampleWebSocketsApplication; import samples.websocket.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; +import static org.junit.Assert.assertEquals; + @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes={SampleWebSocketsApplication.class, CustomContainerConfiguration.class }) +@SpringApplicationConfiguration(classes = { SampleWebSocketsApplication.class, + CustomContainerConfiguration.class }) @WebAppConfiguration @IntegrationTest @DirtiesContext public class CustomContainerWebSocketsApplicationTests { - private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class); + private static Log logger = LogFactory + .getLog(CustomContainerWebSocketsApplicationTests.class); private static final String WS_URI = "ws://localhost:9010/ws/echo/websocket"; - + @Configuration protected static class CustomContainerConfiguration { @Bean diff --git a/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/echo/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/echo/SampleWebSocketsApplicationTests.java index 96da6682ed..8e43904a7a 100644 --- a/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/echo/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket/src/test/java/samples/websocket/echo/SampleWebSocketsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package samples.websocket.echo; -import static org.junit.Assert.assertEquals; - import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -43,8 +41,10 @@ import samples.websocket.client.SimpleClientWebSocketHandler; import samples.websocket.client.SimpleGreetingService; import samples.websocket.config.SampleWebSocketsApplication; +import static org.junit.Assert.assertEquals; + @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=SampleWebSocketsApplication.class) +@SpringApplicationConfiguration(classes = SampleWebSocketsApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/RunApp.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/RunApp.java index 46c48559a7..111415de90 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/RunApp.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/RunApp.java @@ -26,7 +26,6 @@ import java.util.concurrent.Callable; import org.gradle.api.Action; import org.gradle.api.DefaultTask; import org.gradle.api.Project; -import org.gradle.api.file.SourceDirectorySet; import org.gradle.api.internal.file.collections.SimpleFileCollection; import org.gradle.api.tasks.JavaExec; import org.gradle.api.tasks.SourceSet; @@ -45,15 +44,10 @@ public class RunApp extends DefaultTask { final Project project = getProject(); final SourceSet main = ComputeMain.findMainSourceSet(project); - + final File outputDir = (main == null ? null : main.getOutput().getResourcesDir()); final Set allResources = new LinkedHashSet(); - final File outputs; if (main != null) { - SourceDirectorySet resources = main.getResources(); - allResources.addAll(resources.getSrcDirs()); - outputs = main.getOutput().getResourcesDir(); - } else { - outputs = null; + allResources.addAll(main.getResources().getSrcDirs()); } project.getTasks().withType(JavaExec.class, new Action() { @@ -78,21 +72,25 @@ public class RunApp extends DefaultTask { }); getLogger().info("Found main: " + mainClass); } - if (outputs != null) { - // remove duplicates from resources and build + if (outputDir != null) { for (File directory : allResources) { - if (directory.isDirectory()) { - for (String name : directory.list()) { - File file = new File(outputs, name); - if (file.exists() && file.canWrite()) { - getProject().delete(file); - } - } - } + removeDuplicatesFromOutputDir(directory, outputDir); } } exec.exec(); } + + private void removeDuplicatesFromOutputDir(File directory, File outputDir) { + if (directory.isDirectory()) { + for (String name : directory.list()) { + File outputFile = new File(outputDir, name); + if (outputFile.exists() && outputFile.canWrite()) { + getProject().delete(outputFile); + } + } + } + } + }); } @@ -104,7 +102,8 @@ public class RunApp extends DefaultTask { getLogger().info("Looking for main in: " + main.getOutput().getClassesDir()); try { return MainClassFinder.findMainClass(main.getOutput().getClassesDir()); - } catch (IOException ex) { + } + catch (IOException ex) { throw new IllegalStateException("Cannot find main class", ex); } } diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java index 9d20e04094..b840f22e90 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ import org.springframework.boot.loader.jar.JarFile; * {@link ClassLoader} used by the {@link Launcher}. * * @author Phillip Webb + * @author Dave Syer */ public class LaunchedURLClassLoader extends URLClassLoader { @@ -67,31 +68,29 @@ public class LaunchedURLClassLoader extends URLClassLoader { @Override public URL findResource(String name) { - if (name.equals("")) { - URL[] urls = getURLs(); - if (urls.length > 0) { - return urls[0]; - } - } try { + if (name.equals("") && hasURLs()) { + return getURLs()[0]; + } return super.findResource(name); } - catch (IllegalArgumentException e) { + catch (IllegalArgumentException ex) { return null; } } @Override public Enumeration findResources(String name) throws IOException { - if (name.equals("")) { - URL[] urls = getURLs(); - if (urls.length > 0) { - return Collections.enumeration(Arrays.asList(urls)); - } + if (name.equals("") && hasURLs()) { + return Collections.enumeration(Arrays.asList(getURLs())); } return super.findResources(name); } + private boolean hasURLs() { + return getURLs().length > 0; + } + @Override public Enumeration getResources(String name) throws IOException { diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/LaunchedURLClassLoaderTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/LaunchedURLClassLoaderTests.java index a96c72d45d..b453c5851c 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/LaunchedURLClassLoaderTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/LaunchedURLClassLoaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; /** + * Tests for {@link LaunchedURLClassLoader}. + * * @author Dave Syer */ public class LaunchedURLClassLoaderTests { diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java index 5ffccaebc5..3027fae730 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java @@ -50,9 +50,6 @@ import org.springframework.boot.loader.tools.MainClassFinder; @Execute(phase = LifecyclePhase.TEST_COMPILE) public class RunMojo extends AbstractMojo { - /** - * - */ private static final String SPRING_LOADED_AGENT_CLASSNAME = "org.springsource.loaded.agent.SpringLoadedAgent"; /** @@ -201,18 +198,21 @@ public class RunMojo extends AbstractMojo { for (Resource resource : this.project.getResources()) { File directory = new File(resource.getDirectory()); urls.add(directory.toURI().toURL()); - if (directory.isDirectory()) { - // Remove duplicates from the target directory... - for (String name : directory.list()) { - File file = new File(this.classesDirectory, name); - if (file.exists() && file.canWrite()) { - if (file.isDirectory()) { - FileUtils.deleteDirectory(file); - } - else { - file.delete(); - } - } + removeDuplicatesFromTarget(directory); + } + } + } + + private void removeDuplicatesFromTarget(File directory) throws IOException { + if (directory.isDirectory()) { + for (String name : directory.list()) { + File targetFile = new File(this.classesDirectory, name); + if (targetFile.exists() && targetFile.canWrite()) { + if (targetFile.isDirectory()) { + FileUtils.deleteDirectory(targetFile); + } + else { + targetFile.delete(); } } } diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index c54de9dbc1..2197a3265a 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -383,9 +383,9 @@ public class SpringApplication { /** * Template method delegating to * {@link #configurePropertySources(ConfigurableEnvironment, String[])} and - * {@link #configureProfiles(ConfigurableEnvironment, String[])} in that order. Override - * this method for complete control over Environment customization, or one of the above - * for fine-grained control over property sources or profiles, respectively. + * {@link #configureProfiles(ConfigurableEnvironment, String[])} in that order. + * Override this method for complete control over Environment customization, or one of + * the above for fine-grained control over property sources or profiles, respectively. * @param environment this application's environment * @param args arguments passed to the {@code run} method * @see #configurePropertySources(ConfigurableEnvironment, String[]) @@ -397,12 +397,14 @@ public class SpringApplication { } /** - * Add, remove or re-order any {@link PropertySource}s in this application's environment. + * Add, remove or re-order any {@link PropertySource}s in this application's + * environment. * @param environment this application's environment * @param args arguments passed to the {@code run} method * @see #configureEnvironment(ConfigurableEnvironment, String[]) */ - protected void configurePropertySources(ConfigurableEnvironment environment, String[] args) { + protected void configurePropertySources(ConfigurableEnvironment environment, + String[] args) { MutablePropertySources sources = environment.getPropertySources(); if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) { sources.addLast(new MapPropertySource("defaultProperties", @@ -425,9 +427,10 @@ public class SpringApplication { } /** - * Configure which profiles are active (or active by default) for this application environment. - * Consider overriding this method to programmatically enforce profile rules and semantics, - * such as ensuring mutual exclusivity of profiles (e.g. 'dev' OR 'prod', but never both). + * Configure which profiles are active (or active by default) for this application + * environment. Consider overriding this method to programmatically enforce profile + * rules and semantics, such as ensuring mutual exclusivity of profiles (e.g. 'dev' OR + * 'prod', but never both). * @param environment this application's environment * @param args arguments passed to the {@code run} method * @see #configureEnvironment(ConfigurableEnvironment, String[]) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/FilterRegistrationBean.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/FilterRegistrationBean.java index 2c092cf463..493f5e2ab8 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/FilterRegistrationBean.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/FilterRegistrationBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -233,8 +233,8 @@ public class FilterRegistrationBean extends RegistrationBean { String name = getOrDeduceName(this.filter); FilterRegistration.Dynamic added = servletContext.addFilter(name, this.filter); if (added == null) { - logger.info("Filter " + name - + " was not registered (possibly already registered?)"); + logger.info("Filter " + name + " was not registered " + + "(possibly already registered?)"); return; } configure(added); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletRegistrationBean.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletRegistrationBean.java index b014f5a802..419787bac9 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletRegistrationBean.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletRegistrationBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -161,8 +161,8 @@ public class ServletRegistrationBean extends RegistrationBean { logger.info("Mapping servlet: '" + name + "' to " + this.urlMappings); Dynamic added = servletContext.addServlet(name, this.servlet); if (added == null) { - logger.info("Servlet " + name - + " was not registered (possibly already registered?)"); + logger.info("Servlet " + name + " was not registered " + + "(possibly already registered?)"); return; } configure(added); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java index 9b46e5b644..b36796f9dc 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java @@ -121,26 +121,7 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple HttpServletResponse response, ErrorWrapperResponse wrapped, Throwable ex) throws IOException, ServletException { Class type = ex.getClass(); - String errorPath = this.global; - if (this.exceptions.containsKey(type)) { - errorPath = this.exceptions.get(type); - } - else { - if (this.subtypes.containsKey(type)) { - errorPath = this.exceptions.get(this.subtypes.get(type)); - } - else { - Class subtype = type; - while (subtype != Object.class) { - subtype = subtype.getSuperclass(); - if (this.exceptions.containsKey(subtype)) { - this.subtypes.put(subtype, type); - errorPath = this.exceptions.get(subtype); - break; - } - } - } - } + String errorPath = getErrorPath(type); if (errorPath == null) { rethrow(ex); return; @@ -152,9 +133,27 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple request.getRequestDispatcher(errorPath).forward(request, response); } - private String getErrorPath(Map map, Object key) { - if (map.containsKey(key)) { - return map.get(key); + private String getErrorPath(Map map, Integer status) { + if (map.containsKey(status)) { + return map.get(status); + } + return this.global; + } + + private String getErrorPath(Class type) { + if (this.exceptions.containsKey(type)) { + return this.exceptions.get(type); + } + if (this.subtypes.containsKey(type)) { + return this.exceptions.get(this.subtypes.get(type)); + } + Class subtype = type; + while (subtype != Object.class) { + subtype = subtype.getSuperclass(); + if (this.exceptions.containsKey(subtype)) { + this.subtypes.put(subtype, type); + return this.exceptions.get(subtype); + } } return this.global; } diff --git a/spring-boot/src/main/java/org/springframework/boot/test/Base64.java b/spring-boot/src/main/java/org/springframework/boot/test/Base64.java index 94e56ae892..364e758d97 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/Base64.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/Base64.java @@ -17,10 +17,7 @@ package org.springframework.boot.test; /** - * @author dsyer - */ -/** - * Copied from Spring Security Crypto. + * Base64 Encoding Support. Copied from Spring Security Crypto. * * @author Luke Taylor */ @@ -643,4 +640,4 @@ class InvalidBase64CharacterException extends IllegalArgumentException { InvalidBase64CharacterException(String message) { super(message); } -} \ No newline at end of file +} diff --git a/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTest.java b/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTest.java index 43ef3fd539..7b2b1bd7e0 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTest.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot/src/main/java/org/springframework/boot/test/RestTemplates.java b/spring-boot/src/main/java/org/springframework/boot/test/RestTemplates.java index 02bc9d483f..2a3f87f9b4 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/RestTemplates.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/RestTemplates.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,6 @@ public class RestTemplates { /** * Basic factory method for a RestTemplate that does not follow redirects, ignores * cookies and does not throw exceptions on server side errors. - * * @return a basic RestTemplate with no authentication */ public static RestTemplate get() { @@ -63,7 +62,6 @@ public class RestTemplates { * Factory method for a secure RestTemplate with Basic authentication that does not * follow redirects, ignores cookies and does not throw exceptions on server side * errors. - * * @return a basic RestTemplate with Basic authentication */ public static RestTemplate get(final String username, final String password) { @@ -71,20 +69,17 @@ public class RestTemplates { List interceptors = new ArrayList(); if (username != null) { - interceptors.add(new ClientHttpRequestInterceptor() { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { - request.getHeaders().add( - "Authorization", - "Basic " - + new String(Base64 - .encode((username + ":" + password) - .getBytes()))); + byte[] token = Base64.encode((username + ":" + password).getBytes()); + request.getHeaders().add("Authorization", + "Basic " + new String(token)); return execution.execute(request, body); } + }); } diff --git a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java index 6b1c906895..477750b158 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java @@ -54,6 +54,7 @@ import org.springframework.web.context.support.GenericWebApplicationContext; * create the application context. * * @author Dave Syer + * @see IntegrationTest */ public class SpringApplicationContextLoader extends AbstractContextLoader { diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/ServletRegistrationBeanTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/ServletRegistrationBeanTests.java index 5e7c1e0ce0..631b5e4be8 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/ServletRegistrationBeanTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/ServletRegistrationBeanTests.java @@ -38,7 +38,7 @@ import org.mockito.MockitoAnnotations; import static org.mockito.BDDMockito.given; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.times; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** @@ -87,7 +87,7 @@ public class ServletRegistrationBeanTests { .willReturn(null); bean.onStartup(this.servletContext); verify(this.servletContext).addServlet("mockServlet", this.servlet); - verify(this.registration, times(0)).setAsyncSupported(true); + verify(this.registration, never()).setAsyncSupported(true); } @Test