Commit 80ac1fb0 authored by Phillip Webb's avatar Phillip Webb

Polish

parent bb3ea39d
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -46,12 +46,12 @@ public abstract class SpringBootCondition implements Condition { ...@@ -46,12 +46,12 @@ public abstract class SpringBootCondition implements Condition {
recordEvaluation(context, classOrMethodName, outcome); recordEvaluation(context, classOrMethodName, outcome);
return outcome.isMatch(); return outcome.isMatch();
} }
catch (NoClassDefFoundError e) { catch (NoClassDefFoundError ex) {
throw new IllegalStateException( throw new IllegalStateException(
"Could not evaluate condition owing to internal class not found. " "Could not evaluate condition owing to internal class not found. "
+ "This can happen if you are @ComponentScanning a springframework package " + "This can happen if you are @ComponentScanning a "
+ "(e.g. if you put a @ComponentScan in the default package by mistake)", + "springframework package (e.g. if you put a @ComponentScan "
e); + "in the default package by mistake)", ex);
} }
} }
......
...@@ -25,7 +25,7 @@ import org.springframework.util.StringUtils; ...@@ -25,7 +25,7 @@ import org.springframework.util.StringUtils;
/** /**
* Base class for configuration of a database pool. * Base class for configuration of a database pool.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@ConfigurationProperties(name = DataSourceAutoConfiguration.CONFIGURATION_PREFIX) @ConfigurationProperties(name = DataSourceAutoConfiguration.CONFIGURATION_PREFIX)
...@@ -51,17 +51,17 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader ...@@ -51,17 +51,17 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader
private String validationQuery; 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; private ClassLoader classLoader;
...@@ -184,7 +184,9 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader ...@@ -184,7 +184,9 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
} }
public void setMaxWait(int maxWaitMillis) { this.maxWaitMillis = maxWaitMillis; } public void setMaxWait(int maxWaitMillis) {
this.maxWaitMillis = maxWaitMillis;
}
public int getInitialSize() { public int getInitialSize() {
return this.initialSize; return this.initialSize;
...@@ -218,15 +220,16 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader ...@@ -218,15 +220,16 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader
return this.testWhileIdle; return this.testWhileIdle;
} }
protected int getTimeBetweenEvictionRunsMillis() { return this.timeBetweenEvictionRunsMillis; } protected Integer getTimeBetweenEvictionRunsMillis() {
return this.timeBetweenEvictionRunsMillis;
protected int getMinEvictableIdleTimeMillis() { return this.minEvictableIdleTimeMillis; } }
protected int getMaxWaitMillis() { return this.maxWaitMillis; }
protected abstract int getDefaultTimeBetweenEvictionRunsMillis(); protected Integer getMinEvictableIdleTimeMillis() {
return this.minEvictableIdleTimeMillis;
}
protected abstract int getDefaultMinEvictableIdleTimeMillis(); protected Integer getMaxWaitMillis() {
return this.maxWaitMillis;
}
protected abstract int getDefaultMaxWaitMillis();
} }
...@@ -24,7 +24,6 @@ import javax.sql.DataSource; ...@@ -24,7 +24,6 @@ import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.dao.DataAccessResourceFailureException;
...@@ -32,7 +31,7 @@ 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 * 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). * recommended in high volume environments (the Tomcat DataSource is more reliable).
* *
* @author Dave Syer * @author Dave Syer
* @see DataSourceAutoConfiguration * @see DataSourceAutoConfiguration
*/ */
...@@ -52,27 +51,38 @@ public class CommonsDataSourceConfiguration extends AbstractDataSourceConfigurat ...@@ -52,27 +51,38 @@ public class CommonsDataSourceConfiguration extends AbstractDataSourceConfigurat
public DataSource dataSource() { public DataSource dataSource() {
logger.info("Hint: using Commons DBCP BasicDataSource. It's going to work, " logger.info("Hint: using Commons DBCP BasicDataSource. It's going to work, "
+ "but the Tomcat DataSource is more reliable."); + "but the Tomcat DataSource is more reliable.");
this.pool = new BasicDataSource(); this.pool = createAndSetupPool();
this.pool.setDriverClassName(getDriverClassName()); return this.pool;
this.pool.setUrl(getUrl()); }
private BasicDataSource createAndSetupPool() {
BasicDataSource pool = new BasicDataSource();
pool.setDriverClassName(getDriverClassName());
pool.setUrl(getUrl());
if (getUsername() != null) { if (getUsername() != null) {
this.pool.setUsername(getUsername()); pool.setUsername(getUsername());
} }
if (getPassword() != null) { if (getPassword() != null) {
this.pool.setPassword(getPassword()); pool.setPassword(getPassword());
} }
this.pool.setInitialSize(getInitialSize()); pool.setInitialSize(getInitialSize());
this.pool.setMaxActive(getMaxActive()); pool.setMaxActive(getMaxActive());
this.pool.setMaxIdle(getMaxIdle()); pool.setMaxIdle(getMaxIdle());
this.pool.setMinIdle(getMinIdle()); pool.setMinIdle(getMinIdle());
this.pool.setTestOnBorrow(isTestOnBorrow()); pool.setTestOnBorrow(isTestOnBorrow());
this.pool.setTestOnReturn(isTestOnReturn()); pool.setTestOnReturn(isTestOnReturn());
this.pool.setTestWhileIdle(isTestWhileIdle()); pool.setTestWhileIdle(isTestWhileIdle());
this.pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis()); pool.setValidationQuery(getValidationQuery());
this.pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis()); if (getTimeBetweenEvictionRunsMillis() != null) {
this.pool.setValidationQuery(getValidationQuery()); pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
this.pool.setMaxWait(getMaxWaitMillis()); }
return this.pool; if (getMinEvictableIdleTimeMillis() != null) {
pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
}
if (getMaxWaitMillis() != null) {
pool.setMaxWait(getMaxWaitMillis());
}
return pool;
} }
@PreDestroy @PreDestroy
...@@ -80,25 +90,12 @@ public class CommonsDataSourceConfiguration extends AbstractDataSourceConfigurat ...@@ -80,25 +90,12 @@ public class CommonsDataSourceConfiguration extends AbstractDataSourceConfigurat
if (this.pool != null) { if (this.pool != null) {
try { try {
this.pool.close(); this.pool.close();
} catch (SQLException ex) { }
catch (SQLException ex) {
throw new DataAccessResourceFailureException( throw new DataAccessResourceFailureException(
"Could not close data source", ex); "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;
}
} }
...@@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration;
/** /**
* Configuration for a Tomcat database pool. The Tomcat pool provides superior performance * Configuration for a Tomcat database pool. The Tomcat pool provides superior performance
* and tends not to deadlock in high volume environments. * and tends not to deadlock in high volume environments.
* *
* @author Dave Syer * @author Dave Syer
* @see DataSourceAutoConfiguration * @see DataSourceAutoConfiguration
*/ */
...@@ -54,12 +54,19 @@ public class TomcatDataSourceConfiguration extends AbstractDataSourceConfigurati ...@@ -54,12 +54,19 @@ public class TomcatDataSourceConfiguration extends AbstractDataSourceConfigurati
this.pool.setTestOnBorrow(isTestOnBorrow()); this.pool.setTestOnBorrow(isTestOnBorrow());
this.pool.setTestOnReturn(isTestOnReturn()); this.pool.setTestOnReturn(isTestOnReturn());
this.pool.setTestWhileIdle(isTestWhileIdle()); this.pool.setTestWhileIdle(isTestWhileIdle());
this.pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis()); if (getTimeBetweenEvictionRunsMillis() != null) {
this.pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis()); this.pool
.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
}
if (getMinEvictableIdleTimeMillis() != null) {
this.pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
}
this.pool.setValidationQuery(getValidationQuery()); this.pool.setValidationQuery(getValidationQuery());
this.pool.setValidationInterval(this.validationInterval); this.pool.setValidationInterval(this.validationInterval);
this.pool.setMaxWait(getMaxWaitMillis()); if (getMaxWaitMillis() != null) {
if (jdbcInterceptors != null) { this.pool.setMaxWait(getMaxWaitMillis());
}
if (this.jdbcInterceptors != null) {
this.pool.setJdbcInterceptors(this.jdbcInterceptors); this.pool.setJdbcInterceptors(this.jdbcInterceptors);
} }
return this.pool; return this.pool;
...@@ -72,22 +79,11 @@ public class TomcatDataSourceConfiguration extends AbstractDataSourceConfigurati ...@@ -72,22 +79,11 @@ public class TomcatDataSourceConfiguration extends AbstractDataSourceConfigurati
} }
} }
@Override public void setJdbcInterceptors(String jdbcInterceptors) {
protected int getDefaultTimeBetweenEvictionRunsMillis() { this.jdbcInterceptors = jdbcInterceptors;
return 5000;
} }
@Override public void setValidationInterval(long validationInterval) {
protected int getDefaultMinEvictableIdleTimeMillis() { this.validationInterval = validationInterval;
return 60000;
} }
@Override
protected int getDefaultMaxWaitMillis() {
return 30000;
}
public void setJdbcInterceptors(String jdbcInterceptors) { this.jdbcInterceptors = jdbcInterceptors; }
public void setValidationInterval(long validationInterval) { this.validationInterval = validationInterval; }
} }
...@@ -84,11 +84,9 @@ public class ThymeleafAutoConfiguration { ...@@ -84,11 +84,9 @@ public class ThymeleafAutoConfiguration {
if (checkTemplateLocation) { if (checkTemplateLocation) {
Resource resource = this.resourceLoader.getResource(this.environment Resource resource = this.resourceLoader.getResource(this.environment
.getProperty("prefix", DEFAULT_PREFIX)); .getProperty("prefix", DEFAULT_PREFIX));
Assert.state( Assert.state(resource.exists(), "Cannot find template location: "
resource.exists(), + resource + " (please add some templates "
"Cannot find template location: " + "or check your Thymeleaf configuration)");
+ resource
+ " (please add some templates or check your Thymeleaf configuration)");
} }
} }
......
...@@ -101,15 +101,11 @@ public class DispatcherServletAutoConfiguration { ...@@ -101,15 +101,11 @@ public class DispatcherServletAutoConfiguration {
@Override @Override
public ConditionOutcome getMatchOutcome(ConditionContext context, public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) { AnnotatedTypeMetadata metadata) {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
ConditionOutcome outcome = checkServlets(beanFactory); ConditionOutcome outcome = checkServlets(beanFactory);
if (!outcome.isMatch()) { if (!outcome.isMatch()) {
return outcome; return outcome;
} }
return checkServletRegistrations(beanFactory); return checkServletRegistrations(beanFactory);
} }
...@@ -123,9 +119,9 @@ public class DispatcherServletAutoConfiguration { ...@@ -123,9 +119,9 @@ public class DispatcherServletAutoConfiguration {
.containsBean(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); .containsBean(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
if (servlets.isEmpty()) { if (servlets.isEmpty()) {
if (containsDispatcherBean) { if (containsDispatcherBean) {
return ConditionOutcome return ConditionOutcome.noMatch("found no DispatcherServlet "
.noMatch("found no DispatcherServlet but a non-DispatcherServlet named " + "but a non-DispatcherServlet named "
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
} }
return ConditionOutcome.match("no DispatcherServlet found"); return ConditionOutcome.match("no DispatcherServlet found");
} }
...@@ -138,9 +134,8 @@ public class DispatcherServletAutoConfiguration { ...@@ -138,9 +134,8 @@ public class DispatcherServletAutoConfiguration {
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
} }
return ConditionOutcome return ConditionOutcome.match("one or more DispatcherServlets "
.match("one or more DispatcherServlets found and none is named " + "found and none is named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
} }
...@@ -154,9 +149,9 @@ public class DispatcherServletAutoConfiguration { ...@@ -154,9 +149,9 @@ public class DispatcherServletAutoConfiguration {
if (registrations.isEmpty()) { if (registrations.isEmpty()) {
if (containsDispatcherRegistrationBean) { if (containsDispatcherRegistrationBean) {
return ConditionOutcome return ConditionOutcome.noMatch("found no ServletRegistrationBean "
.noMatch("found no ServletRegistrationBean but a non-ServletRegistrationBean named " + "but a non-ServletRegistrationBean named "
+ DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); + DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
} }
return ConditionOutcome.match("no ServletRegistrationBean found"); return ConditionOutcome.match("no ServletRegistrationBean found");
} }
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -29,11 +29,13 @@ import static org.junit.Assert.assertNotNull; ...@@ -29,11 +29,13 @@ import static org.junit.Assert.assertNotNull;
/** /**
* Tests for {@link CommonsDataSourceConfiguration}. * Tests for {@link CommonsDataSourceConfiguration}.
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class CommonsDataSourceConfigurationTests { public class CommonsDataSourceConfigurationTests {
private static final String PREFIX = "spring.datasource.";
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@Test @Test
...@@ -47,13 +49,16 @@ public class CommonsDataSourceConfigurationTests { ...@@ -47,13 +49,16 @@ public class CommonsDataSourceConfigurationTests {
@Test @Test
public void testDataSourcePropertiesOverridden() throws Exception { public void testDataSourcePropertiesOverridden() throws Exception {
this.context.register(CommonsDataSourceConfiguration.class); this.context.register(CommonsDataSourceConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.url:jdbc:foo//bar/spam"); EnvironmentTestUtils.addEnvironment(this.context, PREFIX
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testWhileIdle:true"); + "url:jdbc:foo//bar/spam");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnBorrow:true"); EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testWhileIdle:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnReturn:true"); EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnBorrow:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.timeBetweenEvictionRunsMillis:10000"); EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnReturn:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.minEvictableIdleTimeMillis:12345"); EnvironmentTestUtils.addEnvironment(this.context, PREFIX
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.maxWait:1234"); + "timeBetweenEvictionRunsMillis:10000");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX
+ "minEvictableIdleTimeMillis:12345");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "maxWait:1234");
this.context.refresh(); this.context.refresh();
BasicDataSource ds = this.context.getBean(BasicDataSource.class); BasicDataSource ds = this.context.getBean(BasicDataSource.class);
assertEquals("jdbc:foo//bar/spam", ds.getUrl()); assertEquals("jdbc:foo//bar/spam", ds.getUrl());
...@@ -70,8 +75,10 @@ public class CommonsDataSourceConfigurationTests { ...@@ -70,8 +75,10 @@ public class CommonsDataSourceConfigurationTests {
this.context.register(CommonsDataSourceConfiguration.class); this.context.register(CommonsDataSourceConfiguration.class);
this.context.refresh(); this.context.refresh();
BasicDataSource ds = this.context.getBean(BasicDataSource.class); BasicDataSource ds = this.context.getBean(BasicDataSource.class);
assertEquals(GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, ds.getTimeBetweenEvictionRunsMillis()); assertEquals(GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
assertEquals(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, ds.getMinEvictableIdleTimeMillis()); ds.getTimeBetweenEvictionRunsMillis());
assertEquals(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
ds.getMinEvictableIdleTimeMillis());
assertEquals(GenericObjectPool.DEFAULT_MAX_WAIT, ds.getMaxWait()); assertEquals(GenericObjectPool.DEFAULT_MAX_WAIT, ds.getMaxWait());
} }
......
...@@ -37,11 +37,13 @@ import static org.junit.Assert.fail; ...@@ -37,11 +37,13 @@ import static org.junit.Assert.fail;
/** /**
* Tests for {@link TomcatDataSourceConfiguration}. * Tests for {@link TomcatDataSourceConfiguration}.
* *
* @author Dave Syer * @author Dave Syer
*/ */
public class TomcatDataSourceConfigurationTests { public class TomcatDataSourceConfigurationTests {
private static final String PREFIX = "spring.datasource.";
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@After @After
...@@ -60,17 +62,23 @@ public class TomcatDataSourceConfigurationTests { ...@@ -60,17 +62,23 @@ public class TomcatDataSourceConfigurationTests {
@Test @Test
public void testDataSourcePropertiesOverridden() throws Exception { public void testDataSourcePropertiesOverridden() throws Exception {
this.context.register(TomcatDataSourceConfiguration.class); this.context.register(TomcatDataSourceConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.url:jdbc:foo//bar/spam"); EnvironmentTestUtils.addEnvironment(this.context, PREFIX
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testWhileIdle:true"); + "url:jdbc:foo//bar/spam");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnBorrow:true"); EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testWhileIdle:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnReturn:true"); EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnBorrow:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.timeBetweenEvictionRunsMillis:10000"); EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnReturn:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.minEvictableIdleTimeMillis:12345"); EnvironmentTestUtils.addEnvironment(this.context, PREFIX
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.maxWait:1234"); + "timeBetweenEvictionRunsMillis:10000");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.jdbcInterceptors:SlowQueryReport"); EnvironmentTestUtils.addEnvironment(this.context, PREFIX
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.validationInterval:9999"); + "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(); 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("jdbc:foo//bar/spam", ds.getUrl());
assertEquals(true, ds.isTestWhileIdle()); assertEquals(true, ds.isTestWhileIdle());
assertEquals(true, ds.isTestOnBorrow()); assertEquals(true, ds.isTestOnBorrow());
...@@ -82,8 +90,10 @@ public class TomcatDataSourceConfigurationTests { ...@@ -82,8 +90,10 @@ public class TomcatDataSourceConfigurationTests {
assertDataSourceHasInterceptors(ds); assertDataSourceHasInterceptors(ds);
} }
private void assertDataSourceHasInterceptors(DataSourceProxy ds) throws ClassNotFoundException { private void assertDataSourceHasInterceptors(DataSourceProxy ds)
PoolProperties.InterceptorDefinition[] interceptors = ds.getJdbcInterceptorsAsArray(); throws ClassNotFoundException {
PoolProperties.InterceptorDefinition[] interceptors = ds
.getJdbcInterceptorsAsArray();
for (PoolProperties.InterceptorDefinition interceptor : interceptors) { for (PoolProperties.InterceptorDefinition interceptor : interceptors) {
if (SlowQueryReport.class == interceptor.getInterceptorClass()) { if (SlowQueryReport.class == interceptor.getInterceptorClass()) {
return; return;
...@@ -96,7 +106,8 @@ public class TomcatDataSourceConfigurationTests { ...@@ -96,7 +106,8 @@ public class TomcatDataSourceConfigurationTests {
public void testDataSourceDefaultsPreserved() throws Exception { public void testDataSourceDefaultsPreserved() throws Exception {
this.context.register(TomcatDataSourceConfiguration.class); this.context.register(TomcatDataSourceConfiguration.class);
this.context.refresh(); 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(5000, ds.getTimeBetweenEvictionRunsMillis());
assertEquals(60000, ds.getMinEvictableIdleTimeMillis()); assertEquals(60000, ds.getMinEvictableIdleTimeMillis());
assertEquals(30000, ds.getMaxWait()); assertEquals(30000, ds.getMaxWait());
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 ...@@ -29,7 +29,7 @@ import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletCont
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
...@@ -76,7 +76,7 @@ public class ServerPropertiesTests { ...@@ -76,7 +76,7 @@ public class ServerPropertiesTests {
public void testCustomizeTomcat() throws Exception { public void testCustomizeTomcat() throws Exception {
ConfigurableEmbeddedServletContainer factory = mock(ConfigurableEmbeddedServletContainer.class); ConfigurableEmbeddedServletContainer factory = mock(ConfigurableEmbeddedServletContainer.class);
this.properties.customize(factory); this.properties.customize(factory);
verify(factory, times(0)).setContextPath(""); verify(factory, never()).setContextPath("");
} }
@Test @Test
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package sample.actuator; package sample.actuator;
import static org.junit.Assert.assertNotNull;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -26,22 +24,24 @@ import org.springframework.boot.test.SpringApplicationConfiguration; ...@@ -26,22 +24,24 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertNotNull;
/** /**
* Basic integration tests for service demo application. * Basic integration tests for service demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorNoWebApplication.class) @SpringApplicationConfiguration(classes = SampleActuatorNoWebApplication.class)
@DirtiesContext @DirtiesContext
public class SampleActuatorNoWebApplicationTests { public class SampleActuatorNoWebApplicationTests {
@Autowired @Autowired
private MetricsEndpoint endpoint; private MetricsEndpoint endpoint;
@Test @Test
public void endpointsExist() throws Exception { public void endpointsExist() throws Exception {
assertNotNull(endpoint); assertNotNull(this.endpoint);
} }
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package sample.actuator.ui; package sample.actuator.ui;
import static org.junit.Assert.assertEquals;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
...@@ -35,13 +33,15 @@ import org.springframework.test.context.ActiveProfiles; ...@@ -35,13 +33,15 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/** /**
* Integration tests for separate management and main service ports. * Integration tests for separate management and main service ports.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorUiApplication.class) @SpringApplicationConfiguration(classes = SampleActuatorUiApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
...@@ -60,7 +60,7 @@ public class SampleActuatorUiApplicationPortTests { ...@@ -60,7 +60,7 @@ public class SampleActuatorUiApplicationPortTests {
@Test @Test
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = RestTemplates.get().getForEntity( ResponseEntity<String> entity = RestTemplates.get().getForEntity(
"http://localhost:" + port, String.class); "http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
} }
...@@ -68,14 +68,14 @@ public class SampleActuatorUiApplicationPortTests { ...@@ -68,14 +68,14 @@ public class SampleActuatorUiApplicationPortTests {
public void testMetrics() throws Exception { public void testMetrics() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get().getForEntity( ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
"http://localhost:" + managementPort + "/metrics", Map.class); "http://localhost:" + this.managementPort + "/metrics", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
} }
@Test @Test
public void testHealth() throws Exception { public void testHealth() throws Exception {
ResponseEntity<String> entity = RestTemplates.get().getForEntity( ResponseEntity<String> entity = RestTemplates.get().getForEntity(
"http://localhost:" + managementPort + "/health", String.class); "http://localhost:" + this.managementPort + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("ok", entity.getBody()); assertEquals("ok", entity.getBody());
} }
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
package sample.actuator.ui; package sample.actuator.ui;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
...@@ -37,13 +34,16 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -37,13 +34,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; 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. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorUiApplication.class) @SpringApplicationConfiguration(classes = SampleActuatorUiApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package sample.actuator; package sample.actuator;
import static org.junit.Assert.assertEquals;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
...@@ -32,6 +30,8 @@ import org.springframework.test.context.ActiveProfiles; ...@@ -32,6 +30,8 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/** /**
* Integration tests for endpoints configuration. * Integration tests for endpoints configuration.
* *
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package sample.actuator; package sample.actuator;
import static org.junit.Assert.assertEquals;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
...@@ -35,13 +33,15 @@ import org.springframework.test.context.ActiveProfiles; ...@@ -35,13 +33,15 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/** /**
* Integration tests for separate management and main service ports. * Integration tests for separate management and main service ports.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) @SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
...@@ -61,14 +61,16 @@ public class ManagementAddressActuatorApplicationTests { ...@@ -61,14 +61,16 @@ public class ManagementAddressActuatorApplicationTests {
public void testHome() throws Exception { public void testHome() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get().getForEntity( ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
"http://localhost:" + port, Map.class); "http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
} }
@Test @Test
public void testHealth() throws Exception { public void testHealth() throws Exception {
ResponseEntity<String> entity = RestTemplates.get().getForEntity( ResponseEntity<String> entity = RestTemplates.get()
"http://localhost:" + managementPort + "/admin/health", String.class); .getForEntity(
"http://localhost:" + this.managementPort + "/admin/health",
String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("ok", entity.getBody()); assertEquals("ok", entity.getBody());
} }
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package sample.actuator; package sample.actuator;
import static org.junit.Assert.assertEquals;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
...@@ -36,13 +34,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -36,13 +34,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals;
/** /**
* Integration tests for separate management and main service ports. * Integration tests for separate management and main service ports.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) @SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
...@@ -62,7 +62,7 @@ public class ManagementPortSampleActuatorApplicationTests { ...@@ -62,7 +62,7 @@ public class ManagementPortSampleActuatorApplicationTests {
public void testHome() throws Exception { public void testHome() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate("user", getPassword()).getForEntity( ResponseEntity<Map> entity = getRestTemplate("user", getPassword()).getForEntity(
"http://localhost:" + port, Map.class); "http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
...@@ -74,14 +74,14 @@ public class ManagementPortSampleActuatorApplicationTests { ...@@ -74,14 +74,14 @@ public class ManagementPortSampleActuatorApplicationTests {
testHome(); // makes sure some requests have been made testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate().getForEntity( ResponseEntity<Map> entity = getRestTemplate().getForEntity(
"http://localhost:" + managementPort + "/metrics", Map.class); "http://localhost:" + this.managementPort + "/metrics", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
} }
@Test @Test
public void testHealth() throws Exception { public void testHealth() throws Exception {
ResponseEntity<String> entity = getRestTemplate().getForEntity( ResponseEntity<String> entity = getRestTemplate().getForEntity(
"http://localhost:" + managementPort + "/health", String.class); "http://localhost:" + this.managementPort + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("ok", entity.getBody()); assertEquals("ok", entity.getBody());
} }
...@@ -90,7 +90,7 @@ public class ManagementPortSampleActuatorApplicationTests { ...@@ -90,7 +90,7 @@ public class ManagementPortSampleActuatorApplicationTests {
public void testErrorPage() throws Exception { public void testErrorPage() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate().getForEntity( ResponseEntity<Map> entity = getRestTemplate().getForEntity(
"http://localhost:" + managementPort + "/error", Map.class); "http://localhost:" + this.managementPort + "/error", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
...@@ -98,7 +98,7 @@ public class ManagementPortSampleActuatorApplicationTests { ...@@ -98,7 +98,7 @@ public class ManagementPortSampleActuatorApplicationTests {
} }
private String getPassword() { private String getPassword() {
return security.getUser().getPassword(); return this.security.getUser().getPassword();
} }
private RestTemplate getRestTemplate() { private RestTemplate getRestTemplate() {
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package sample.actuator; package sample.actuator;
import static org.junit.Assert.assertEquals;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
...@@ -34,13 +32,15 @@ import org.springframework.test.context.ActiveProfiles; ...@@ -34,13 +32,15 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/** /**
* Integration tests for switching off management endpoints. * Integration tests for switching off management endpoints.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) @SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
...@@ -53,8 +53,8 @@ public class NoManagementSampleActuatorApplicationTests { ...@@ -53,8 +53,8 @@ public class NoManagementSampleActuatorApplicationTests {
@Test @Test
public void testHome() throws Exception { public void testHome() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity( ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
"http://localhost:8080", Map.class); .getForEntity("http://localhost:8080", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
...@@ -65,13 +65,13 @@ public class NoManagementSampleActuatorApplicationTests { ...@@ -65,13 +65,13 @@ public class NoManagementSampleActuatorApplicationTests {
public void testMetricsNotAvailable() throws Exception { public void testMetricsNotAvailable() throws Exception {
testHome(); // makes sure some requests have been made testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity( ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
"http://localhost:8080/metrics", Map.class); .getForEntity("http://localhost:8080/metrics", Map.class);
assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode()); assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode());
} }
private String getPassword() { private String getPassword() {
return security.getUser().getPassword(); return this.security.getUser().getPassword();
} }
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,11 +16,6 @@ ...@@ -16,11 +16,6 @@
package sample.actuator; 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.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -42,13 +37,18 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -42,13 +37,18 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; 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. * Basic integration tests for service demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) @SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
...@@ -73,8 +73,8 @@ public class SampleActuatorApplicationTests { ...@@ -73,8 +73,8 @@ public class SampleActuatorApplicationTests {
@Test @Test
public void testHome() throws Exception { public void testHome() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity( ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
"http://localhost:8080", Map.class); .getForEntity("http://localhost:8080", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
...@@ -85,8 +85,8 @@ public class SampleActuatorApplicationTests { ...@@ -85,8 +85,8 @@ public class SampleActuatorApplicationTests {
public void testMetrics() throws Exception { public void testMetrics() throws Exception {
testHome(); // makes sure some requests have been made testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity( ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
"http://localhost:8080/metrics", Map.class); .getForEntity("http://localhost:8080/metrics", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
...@@ -96,8 +96,8 @@ public class SampleActuatorApplicationTests { ...@@ -96,8 +96,8 @@ public class SampleActuatorApplicationTests {
@Test @Test
public void testEnv() throws Exception { public void testEnv() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity( ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
"http://localhost:8080/env", Map.class); .getForEntity("http://localhost:8080/env", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
...@@ -127,8 +127,9 @@ public class SampleActuatorApplicationTests { ...@@ -127,8 +127,9 @@ public class SampleActuatorApplicationTests {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<?> request = new HttpEntity<Void>(headers); HttpEntity<?> request = new HttpEntity<Void>(headers);
ResponseEntity<String> entity = RestTemplates.get("user", getPassword()).exchange( ResponseEntity<String> entity = RestTemplates.get("user", getPassword())
"http://localhost:8080/foo", HttpMethod.GET, request, String.class); .exchange("http://localhost:8080/foo", HttpMethod.GET, request,
String.class);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
String body = entity.getBody(); String body = entity.getBody();
assertNotNull("Body was null", body); assertNotNull("Body was null", body);
...@@ -178,7 +179,7 @@ public class SampleActuatorApplicationTests { ...@@ -178,7 +179,7 @@ public class SampleActuatorApplicationTests {
} }
private String getPassword() { private String getPassword() {
return security.getUser().getPassword(); return this.security.getUser().getPassword();
} }
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
package sample.actuator; package sample.actuator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
...@@ -34,13 +31,16 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -34,13 +31,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; 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. * Integration tests for separate management and main service ports.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) @SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
...@@ -52,8 +52,8 @@ public class ShutdownSampleActuatorApplicationTests { ...@@ -52,8 +52,8 @@ public class ShutdownSampleActuatorApplicationTests {
@Test @Test
public void testHome() throws Exception { public void testHome() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity( ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
"http://localhost:8080", Map.class); .getForEntity("http://localhost:8080", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
...@@ -73,7 +73,7 @@ public class ShutdownSampleActuatorApplicationTests { ...@@ -73,7 +73,7 @@ public class ShutdownSampleActuatorApplicationTests {
} }
private String getPassword() { private String getPassword() {
return security.getUser().getPassword(); return this.security.getUser().getPassword();
} }
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,10 +16,6 @@ ...@@ -16,10 +16,6 @@
package sample.actuator; 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 java.util.Map;
import org.junit.Test; import org.junit.Test;
...@@ -34,6 +30,10 @@ import org.springframework.test.context.ActiveProfiles; ...@@ -34,6 +30,10 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; 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 * Integration tests for unsecured service endpoints (even with Spring Security on
* classpath). * classpath).
...@@ -41,7 +41,7 @@ import org.springframework.test.context.web.WebAppConfiguration; ...@@ -41,7 +41,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) @SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
package sample.actuator; package sample.actuator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
...@@ -33,6 +30,9 @@ import org.springframework.test.context.ActiveProfiles; ...@@ -33,6 +30,9 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; 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 * Integration tests for unsecured service endpoints (even with Spring Security on
* classpath). * classpath).
...@@ -40,7 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration; ...@@ -40,7 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class) @SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package sample.jetty; package sample.jetty;
import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
...@@ -29,13 +27,15 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -29,13 +27,15 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleJettyApplication.class) @SpringApplicationConfiguration(classes = SampleJettyApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
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.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -15,13 +29,15 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -15,13 +29,15 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleServletApplication.class) @SpringApplicationConfiguration(classes = SampleServletApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
...@@ -46,6 +62,6 @@ public class SampleServletApplicationTests { ...@@ -46,6 +62,6 @@ public class SampleServletApplicationTests {
} }
private String getPassword() { private String getPassword() {
return security.getUser().getPassword(); return this.security.getUser().getPassword();
} }
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package sample.tomcat; package sample.tomcat;
import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
...@@ -43,13 +41,15 @@ import sample.tomcat.NonAutoConfigurationSampleTomcatApplicationTests.NonAutoCon ...@@ -43,13 +41,15 @@ import sample.tomcat.NonAutoConfigurationSampleTomcatApplicationTests.NonAutoCon
import sample.tomcat.service.HelloWorldService; import sample.tomcat.service.HelloWorldService;
import sample.tomcat.web.SampleController; import sample.tomcat.web.SampleController;
import static org.junit.Assert.assertEquals;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=NonAutoConfigurationSampleTomcatApplication.class) @SpringApplicationConfiguration(classes = NonAutoConfigurationSampleTomcatApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package sample.tomcat; package sample.tomcat;
import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
...@@ -29,13 +27,15 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -29,13 +27,15 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleTomcatApplication.class) @SpringApplicationConfiguration(classes = SampleTomcatApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
package sample.traditional; package sample.traditional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.IntegrationTest;
...@@ -30,13 +27,16 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -30,13 +27,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; 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. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleTraditionalApplication.class) @SpringApplicationConfiguration(classes = SampleTraditionalApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
/*
* 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; package sample.jsp;
import java.util.Date; import java.util.Date;
...@@ -16,7 +32,7 @@ public class WelcomeController { ...@@ -16,7 +32,7 @@ public class WelcomeController {
@RequestMapping("/") @RequestMapping("/")
public String welcome(Map<String, Object> model) { public String welcome(Map<String, Object> model) {
model.put("time", new Date()); model.put("time", new Date());
model.put("message", message); model.put("message", this.message);
return "welcome"; return "welcome";
} }
......
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; package sample.jsp;
import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -14,13 +27,16 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -14,13 +27,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; 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. * Basic integration tests for JSP application.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleWebJspApplication.class) @SpringApplicationConfiguration(classes = SampleWebJspApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
package sample.ui.method; package sample.ui.method;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays; import java.util.Arrays;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -40,13 +37,16 @@ import org.springframework.test.context.web.WebAppConfiguration; ...@@ -40,13 +37,16 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleMethodSecurityApplication.class) @SpringApplicationConfiguration(classes = SampleMethodSecurityApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
package sample.ui.secure; package sample.ui.secure;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays; import java.util.Arrays;
import org.junit.Test; import org.junit.Test;
...@@ -36,13 +33,16 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -36,13 +33,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; 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. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleSecureApplication.class) @SpringApplicationConfiguration(classes = SampleSecureApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
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; package sample.ui;
import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -15,13 +28,16 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -15,13 +28,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; 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. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleWebStaticApplication.class) @SpringApplicationConfiguration(classes = SampleWebStaticApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
/*
* 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; package sample.ui;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -56,12 +72,12 @@ public class MessageControllerWebTests { ...@@ -56,12 +72,12 @@ public class MessageControllerWebTests {
.andExpect(header().string("location", RegexMatcher.matches("/[0-9]+"))); .andExpect(header().string("location", RegexMatcher.matches("/[0-9]+")));
} }
@Test @Test
public void testCreateValidation() throws Exception{ public void testCreateValidation() throws Exception {
this.mockMvc.perform(post("/").param("text", "").param("summary", "")) this.mockMvc.perform(post("/").param("text", "").param("summary", ""))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().string(containsString("is required"))); .andExpect(content().string(containsString("is required")));
} }
private static class RegexMatcher extends TypeSafeMatcher<String> { private static class RegexMatcher extends TypeSafeMatcher<String> {
private final String regex; private final String regex;
......
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; package sample.ui;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.net.URI; import java.net.URI;
...@@ -19,13 +31,17 @@ import org.springframework.test.context.web.WebAppConfiguration; ...@@ -19,13 +31,17 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; 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. * Basic integration tests for demo application.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleWebUiApplication.class) @SpringApplicationConfiguration(classes = SampleWebUiApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package samples.websocket.echo; package samples.websocket.echo;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -46,17 +44,21 @@ import samples.websocket.client.SimpleGreetingService; ...@@ -46,17 +44,21 @@ import samples.websocket.client.SimpleGreetingService;
import samples.websocket.config.SampleWebSocketsApplication; import samples.websocket.config.SampleWebSocketsApplication;
import samples.websocket.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; import samples.websocket.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes={SampleWebSocketsApplication.class, CustomContainerConfiguration.class }) @SpringApplicationConfiguration(classes = { SampleWebSocketsApplication.class,
CustomContainerConfiguration.class })
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
public class CustomContainerWebSocketsApplicationTests { 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"; private static final String WS_URI = "ws://localhost:9010/ws/echo/websocket";
@Configuration @Configuration
protected static class CustomContainerConfiguration { protected static class CustomContainerConfiguration {
@Bean @Bean
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package samples.websocket.echo; package samples.websocket.echo;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -43,8 +41,10 @@ import samples.websocket.client.SimpleClientWebSocketHandler; ...@@ -43,8 +41,10 @@ import samples.websocket.client.SimpleClientWebSocketHandler;
import samples.websocket.client.SimpleGreetingService; import samples.websocket.client.SimpleGreetingService;
import samples.websocket.config.SampleWebSocketsApplication; import samples.websocket.config.SampleWebSocketsApplication;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleWebSocketsApplication.class) @SpringApplicationConfiguration(classes = SampleWebSocketsApplication.class)
@WebAppConfiguration @WebAppConfiguration
@IntegrationTest @IntegrationTest
@DirtiesContext @DirtiesContext
......
...@@ -26,7 +26,6 @@ import java.util.concurrent.Callable; ...@@ -26,7 +26,6 @@ import java.util.concurrent.Callable;
import org.gradle.api.Action; import org.gradle.api.Action;
import org.gradle.api.DefaultTask; import org.gradle.api.DefaultTask;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.internal.file.collections.SimpleFileCollection; import org.gradle.api.internal.file.collections.SimpleFileCollection;
import org.gradle.api.tasks.JavaExec; import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSet;
...@@ -45,15 +44,10 @@ public class RunApp extends DefaultTask { ...@@ -45,15 +44,10 @@ public class RunApp extends DefaultTask {
final Project project = getProject(); final Project project = getProject();
final SourceSet main = ComputeMain.findMainSourceSet(project); final SourceSet main = ComputeMain.findMainSourceSet(project);
final File outputDir = (main == null ? null : main.getOutput().getResourcesDir());
final Set<File> allResources = new LinkedHashSet<File>(); final Set<File> allResources = new LinkedHashSet<File>();
final File outputs;
if (main != null) { if (main != null) {
SourceDirectorySet resources = main.getResources(); allResources.addAll(main.getResources().getSrcDirs());
allResources.addAll(resources.getSrcDirs());
outputs = main.getOutput().getResourcesDir();
} else {
outputs = null;
} }
project.getTasks().withType(JavaExec.class, new Action<JavaExec>() { project.getTasks().withType(JavaExec.class, new Action<JavaExec>() {
...@@ -78,21 +72,25 @@ public class RunApp extends DefaultTask { ...@@ -78,21 +72,25 @@ public class RunApp extends DefaultTask {
}); });
getLogger().info("Found main: " + mainClass); getLogger().info("Found main: " + mainClass);
} }
if (outputs != null) { if (outputDir != null) {
// remove duplicates from resources and build
for (File directory : allResources) { for (File directory : allResources) {
if (directory.isDirectory()) { removeDuplicatesFromOutputDir(directory, outputDir);
for (String name : directory.list()) {
File file = new File(outputs, name);
if (file.exists() && file.canWrite()) {
getProject().delete(file);
}
}
}
} }
} }
exec.exec(); 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 { ...@@ -104,7 +102,8 @@ public class RunApp extends DefaultTask {
getLogger().info("Looking for main in: " + main.getOutput().getClassesDir()); getLogger().info("Looking for main in: " + main.getOutput().getClassesDir());
try { try {
return MainClassFinder.findMainClass(main.getOutput().getClassesDir()); return MainClassFinder.findMainClass(main.getOutput().getClassesDir());
} catch (IOException ex) { }
catch (IOException ex) {
throw new IllegalStateException("Cannot find main class", ex); throw new IllegalStateException("Cannot find main class", ex);
} }
} }
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; ...@@ -31,6 +31,7 @@ import org.springframework.boot.loader.jar.JarFile;
* {@link ClassLoader} used by the {@link Launcher}. * {@link ClassLoader} used by the {@link Launcher}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Dave Syer
*/ */
public class LaunchedURLClassLoader extends URLClassLoader { public class LaunchedURLClassLoader extends URLClassLoader {
...@@ -67,31 +68,29 @@ public class LaunchedURLClassLoader extends URLClassLoader { ...@@ -67,31 +68,29 @@ public class LaunchedURLClassLoader extends URLClassLoader {
@Override @Override
public URL findResource(String name) { public URL findResource(String name) {
if (name.equals("")) {
URL[] urls = getURLs();
if (urls.length > 0) {
return urls[0];
}
}
try { try {
if (name.equals("") && hasURLs()) {
return getURLs()[0];
}
return super.findResource(name); return super.findResource(name);
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException ex) {
return null; return null;
} }
} }
@Override @Override
public Enumeration<URL> findResources(String name) throws IOException { public Enumeration<URL> findResources(String name) throws IOException {
if (name.equals("")) { if (name.equals("") && hasURLs()) {
URL[] urls = getURLs(); return Collections.enumeration(Arrays.asList(getURLs()));
if (urls.length > 0) {
return Collections.enumeration(Arrays.asList(urls));
}
} }
return super.findResources(name); return super.findResources(name);
} }
private boolean hasURLs() {
return getURLs().length > 0;
}
@Override @Override
public Enumeration<URL> getResources(String name) throws IOException { public Enumeration<URL> getResources(String name) throws IOException {
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -25,6 +25,8 @@ import static org.junit.Assert.assertNull; ...@@ -25,6 +25,8 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link LaunchedURLClassLoader}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class LaunchedURLClassLoaderTests { public class LaunchedURLClassLoaderTests {
......
...@@ -50,9 +50,6 @@ import org.springframework.boot.loader.tools.MainClassFinder; ...@@ -50,9 +50,6 @@ import org.springframework.boot.loader.tools.MainClassFinder;
@Execute(phase = LifecyclePhase.TEST_COMPILE) @Execute(phase = LifecyclePhase.TEST_COMPILE)
public class RunMojo extends AbstractMojo { public class RunMojo extends AbstractMojo {
/**
*
*/
private static final String SPRING_LOADED_AGENT_CLASSNAME = "org.springsource.loaded.agent.SpringLoadedAgent"; private static final String SPRING_LOADED_AGENT_CLASSNAME = "org.springsource.loaded.agent.SpringLoadedAgent";
/** /**
...@@ -201,18 +198,21 @@ public class RunMojo extends AbstractMojo { ...@@ -201,18 +198,21 @@ public class RunMojo extends AbstractMojo {
for (Resource resource : this.project.getResources()) { for (Resource resource : this.project.getResources()) {
File directory = new File(resource.getDirectory()); File directory = new File(resource.getDirectory());
urls.add(directory.toURI().toURL()); urls.add(directory.toURI().toURL());
if (directory.isDirectory()) { removeDuplicatesFromTarget(directory);
// 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()) { private void removeDuplicatesFromTarget(File directory) throws IOException {
FileUtils.deleteDirectory(file); if (directory.isDirectory()) {
} for (String name : directory.list()) {
else { File targetFile = new File(this.classesDirectory, name);
file.delete(); if (targetFile.exists() && targetFile.canWrite()) {
} if (targetFile.isDirectory()) {
} FileUtils.deleteDirectory(targetFile);
}
else {
targetFile.delete();
} }
} }
} }
......
...@@ -383,9 +383,9 @@ public class SpringApplication { ...@@ -383,9 +383,9 @@ public class SpringApplication {
/** /**
* Template method delegating to * Template method delegating to
* {@link #configurePropertySources(ConfigurableEnvironment, String[])} and * {@link #configurePropertySources(ConfigurableEnvironment, String[])} and
* {@link #configureProfiles(ConfigurableEnvironment, String[])} in that order. Override * {@link #configureProfiles(ConfigurableEnvironment, String[])} in that order.
* this method for complete control over Environment customization, or one of the above * Override this method for complete control over Environment customization, or one of
* for fine-grained control over property sources or profiles, respectively. * the above for fine-grained control over property sources or profiles, respectively.
* @param environment this application's environment * @param environment this application's environment
* @param args arguments passed to the {@code run} method * @param args arguments passed to the {@code run} method
* @see #configurePropertySources(ConfigurableEnvironment, String[]) * @see #configurePropertySources(ConfigurableEnvironment, String[])
...@@ -397,12 +397,14 @@ public class SpringApplication { ...@@ -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 environment this application's environment
* @param args arguments passed to the {@code run} method * @param args arguments passed to the {@code run} method
* @see #configureEnvironment(ConfigurableEnvironment, String[]) * @see #configureEnvironment(ConfigurableEnvironment, String[])
*/ */
protected void configurePropertySources(ConfigurableEnvironment environment, String[] args) { protected void configurePropertySources(ConfigurableEnvironment environment,
String[] args) {
MutablePropertySources sources = environment.getPropertySources(); MutablePropertySources sources = environment.getPropertySources();
if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) { if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) {
sources.addLast(new MapPropertySource("defaultProperties", sources.addLast(new MapPropertySource("defaultProperties",
...@@ -425,9 +427,10 @@ public class SpringApplication { ...@@ -425,9 +427,10 @@ public class SpringApplication {
} }
/** /**
* Configure which profiles are active (or active by default) for this application environment. * Configure which profiles are active (or active by default) for this application
* Consider overriding this method to programmatically enforce profile rules and semantics, * environment. Consider overriding this method to programmatically enforce profile
* such as ensuring mutual exclusivity of profiles (e.g. 'dev' OR 'prod', but never both). * 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 environment this application's environment
* @param args arguments passed to the {@code run} method * @param args arguments passed to the {@code run} method
* @see #configureEnvironment(ConfigurableEnvironment, String[]) * @see #configureEnvironment(ConfigurableEnvironment, String[])
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -233,8 +233,8 @@ public class FilterRegistrationBean extends RegistrationBean { ...@@ -233,8 +233,8 @@ public class FilterRegistrationBean extends RegistrationBean {
String name = getOrDeduceName(this.filter); String name = getOrDeduceName(this.filter);
FilterRegistration.Dynamic added = servletContext.addFilter(name, this.filter); FilterRegistration.Dynamic added = servletContext.addFilter(name, this.filter);
if (added == null) { if (added == null) {
logger.info("Filter " + name logger.info("Filter " + name + " was not registered "
+ " was not registered (possibly already registered?)"); + "(possibly already registered?)");
return; return;
} }
configure(added); configure(added);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -161,8 +161,8 @@ public class ServletRegistrationBean extends RegistrationBean { ...@@ -161,8 +161,8 @@ public class ServletRegistrationBean extends RegistrationBean {
logger.info("Mapping servlet: '" + name + "' to " + this.urlMappings); logger.info("Mapping servlet: '" + name + "' to " + this.urlMappings);
Dynamic added = servletContext.addServlet(name, this.servlet); Dynamic added = servletContext.addServlet(name, this.servlet);
if (added == null) { if (added == null) {
logger.info("Servlet " + name logger.info("Servlet " + name + " was not registered "
+ " was not registered (possibly already registered?)"); + "(possibly already registered?)");
return; return;
} }
configure(added); configure(added);
......
...@@ -121,26 +121,7 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple ...@@ -121,26 +121,7 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
HttpServletResponse response, ErrorWrapperResponse wrapped, Throwable ex) HttpServletResponse response, ErrorWrapperResponse wrapped, Throwable ex)
throws IOException, ServletException { throws IOException, ServletException {
Class<?> type = ex.getClass(); Class<?> type = ex.getClass();
String errorPath = this.global; String errorPath = getErrorPath(type);
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;
}
}
}
}
if (errorPath == null) { if (errorPath == null) {
rethrow(ex); rethrow(ex);
return; return;
...@@ -152,9 +133,27 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple ...@@ -152,9 +133,27 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
request.getRequestDispatcher(errorPath).forward(request, response); request.getRequestDispatcher(errorPath).forward(request, response);
} }
private String getErrorPath(Map<?, String> map, Object key) { private String getErrorPath(Map<Integer, String> map, Integer status) {
if (map.containsKey(key)) { if (map.containsKey(status)) {
return map.get(key); 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; return this.global;
} }
......
...@@ -17,10 +17,7 @@ ...@@ -17,10 +17,7 @@
package org.springframework.boot.test; package org.springframework.boot.test;
/** /**
* @author dsyer * Base64 Encoding Support. Copied from Spring Security Crypto.
*/
/**
* Copied from Spring Security Crypto.
* *
* @author Luke Taylor * @author Luke Taylor
*/ */
...@@ -643,4 +640,4 @@ class InvalidBase64CharacterException extends IllegalArgumentException { ...@@ -643,4 +640,4 @@ class InvalidBase64CharacterException extends IllegalArgumentException {
InvalidBase64CharacterException(String message) { InvalidBase64CharacterException(String message) {
super(message); super(message);
} }
} }
\ No newline at end of file
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -52,7 +52,6 @@ public class RestTemplates { ...@@ -52,7 +52,6 @@ public class RestTemplates {
/** /**
* Basic factory method for a RestTemplate that does not follow redirects, ignores * Basic factory method for a RestTemplate that does not follow redirects, ignores
* cookies and does not throw exceptions on server side errors. * cookies and does not throw exceptions on server side errors.
*
* @return a basic RestTemplate with no authentication * @return a basic RestTemplate with no authentication
*/ */
public static RestTemplate get() { public static RestTemplate get() {
...@@ -63,7 +62,6 @@ public class RestTemplates { ...@@ -63,7 +62,6 @@ public class RestTemplates {
* Factory method for a secure RestTemplate with Basic authentication that does not * Factory method for a secure RestTemplate with Basic authentication that does not
* follow redirects, ignores cookies and does not throw exceptions on server side * follow redirects, ignores cookies and does not throw exceptions on server side
* errors. * errors.
*
* @return a basic RestTemplate with Basic authentication * @return a basic RestTemplate with Basic authentication
*/ */
public static RestTemplate get(final String username, final String password) { public static RestTemplate get(final String username, final String password) {
...@@ -71,20 +69,17 @@ public class RestTemplates { ...@@ -71,20 +69,17 @@ public class RestTemplates {
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>(); List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
if (username != null) { if (username != null) {
interceptors.add(new ClientHttpRequestInterceptor() { interceptors.add(new ClientHttpRequestInterceptor() {
@Override @Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException { ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().add( byte[] token = Base64.encode((username + ":" + password).getBytes());
"Authorization", request.getHeaders().add("Authorization",
"Basic " "Basic " + new String(token));
+ new String(Base64
.encode((username + ":" + password)
.getBytes())));
return execution.execute(request, body); return execution.execute(request, body);
} }
}); });
} }
......
...@@ -54,6 +54,7 @@ import org.springframework.web.context.support.GenericWebApplicationContext; ...@@ -54,6 +54,7 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
* create the application context. * create the application context.
* *
* @author Dave Syer * @author Dave Syer
* @see IntegrationTest
*/ */
public class SpringApplicationContextLoader extends AbstractContextLoader { public class SpringApplicationContextLoader extends AbstractContextLoader {
......
...@@ -38,7 +38,7 @@ import org.mockito.MockitoAnnotations; ...@@ -38,7 +38,7 @@ import org.mockito.MockitoAnnotations;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
...@@ -87,7 +87,7 @@ public class ServletRegistrationBeanTests { ...@@ -87,7 +87,7 @@ public class ServletRegistrationBeanTests {
.willReturn(null); .willReturn(null);
bean.onStartup(this.servletContext); bean.onStartup(this.servletContext);
verify(this.servletContext).addServlet("mockServlet", this.servlet); verify(this.servletContext).addServlet("mockServlet", this.servlet);
verify(this.registration, times(0)).setAsyncSupported(true); verify(this.registration, never()).setAsyncSupported(true);
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment