This commit is contained in:
Phillip Webb
2014-03-14 16:17:08 -07:00
parent bb3ea39d80
commit 80ac1fb0cd
50 changed files with 469 additions and 366 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,12 +46,12 @@ public abstract class SpringBootCondition implements Condition {
recordEvaluation(context, classOrMethodName, outcome);
return outcome.isMatch();
}
catch (NoClassDefFoundError e) {
catch (NoClassDefFoundError ex) {
throw new IllegalStateException(
"Could not evaluate condition owing to internal class not found. "
+ "This can happen if you are @ComponentScanning a springframework package "
+ "(e.g. if you put a @ComponentScan in the default package by mistake)",
e);
+ "This can happen if you are @ComponentScanning a "
+ "springframework package (e.g. if you put a @ComponentScan "
+ "in the default package by mistake)", ex);
}
}

View File

@@ -25,7 +25,7 @@ import org.springframework.util.StringUtils;
/**
* Base class for configuration of a database pool.
*
*
* @author Dave Syer
*/
@ConfigurationProperties(name = DataSourceAutoConfiguration.CONFIGURATION_PREFIX)
@@ -51,17 +51,17 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader
private String validationQuery;
private boolean testOnBorrow = false;
private boolean testOnBorrow;
private boolean testOnReturn = false;
private boolean testOnReturn;
private boolean testWhileIdle = false;
private boolean testWhileIdle;
private int timeBetweenEvictionRunsMillis = getDefaultTimeBetweenEvictionRunsMillis();
private Integer timeBetweenEvictionRunsMillis;
private int minEvictableIdleTimeMillis = getDefaultMinEvictableIdleTimeMillis();
private Integer minEvictableIdleTimeMillis;
private int maxWaitMillis = getDefaultMaxWaitMillis();
private Integer maxWaitMillis;
private ClassLoader classLoader;
@@ -184,7 +184,9 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
}
public void setMaxWait(int maxWaitMillis) { this.maxWaitMillis = maxWaitMillis; }
public void setMaxWait(int maxWaitMillis) {
this.maxWaitMillis = maxWaitMillis;
}
public int getInitialSize() {
return this.initialSize;
@@ -218,15 +220,16 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader
return this.testWhileIdle;
}
protected int getTimeBetweenEvictionRunsMillis() { return this.timeBetweenEvictionRunsMillis; }
protected Integer getTimeBetweenEvictionRunsMillis() {
return this.timeBetweenEvictionRunsMillis;
}
protected int getMinEvictableIdleTimeMillis() { return this.minEvictableIdleTimeMillis; }
protected Integer getMinEvictableIdleTimeMillis() {
return this.minEvictableIdleTimeMillis;
}
protected int getMaxWaitMillis() { return this.maxWaitMillis; }
protected Integer getMaxWaitMillis() {
return this.maxWaitMillis;
}
protected abstract int getDefaultTimeBetweenEvictionRunsMillis();
protected abstract int getDefaultMinEvictableIdleTimeMillis();
protected abstract int getDefaultMaxWaitMillis();
}

View File

@@ -24,7 +24,6 @@ import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.DataAccessResourceFailureException;
@@ -32,7 +31,7 @@ import org.springframework.dao.DataAccessResourceFailureException;
/**
* Configuration for a Commons DBCP database pool. The DBCP pool is popular but not
* recommended in high volume environments (the Tomcat DataSource is more reliable).
*
*
* @author Dave Syer
* @see DataSourceAutoConfiguration
*/
@@ -52,27 +51,38 @@ public class CommonsDataSourceConfiguration extends AbstractDataSourceConfigurat
public DataSource dataSource() {
logger.info("Hint: using Commons DBCP BasicDataSource. It's going to work, "
+ "but the Tomcat DataSource is more reliable.");
this.pool = new BasicDataSource();
this.pool.setDriverClassName(getDriverClassName());
this.pool.setUrl(getUrl());
this.pool = createAndSetupPool();
return this.pool;
}
private BasicDataSource createAndSetupPool() {
BasicDataSource pool = new BasicDataSource();
pool.setDriverClassName(getDriverClassName());
pool.setUrl(getUrl());
if (getUsername() != null) {
this.pool.setUsername(getUsername());
pool.setUsername(getUsername());
}
if (getPassword() != null) {
this.pool.setPassword(getPassword());
pool.setPassword(getPassword());
}
this.pool.setInitialSize(getInitialSize());
this.pool.setMaxActive(getMaxActive());
this.pool.setMaxIdle(getMaxIdle());
this.pool.setMinIdle(getMinIdle());
this.pool.setTestOnBorrow(isTestOnBorrow());
this.pool.setTestOnReturn(isTestOnReturn());
this.pool.setTestWhileIdle(isTestWhileIdle());
this.pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
this.pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
this.pool.setValidationQuery(getValidationQuery());
this.pool.setMaxWait(getMaxWaitMillis());
return this.pool;
pool.setInitialSize(getInitialSize());
pool.setMaxActive(getMaxActive());
pool.setMaxIdle(getMaxIdle());
pool.setMinIdle(getMinIdle());
pool.setTestOnBorrow(isTestOnBorrow());
pool.setTestOnReturn(isTestOnReturn());
pool.setTestWhileIdle(isTestWhileIdle());
pool.setValidationQuery(getValidationQuery());
if (getTimeBetweenEvictionRunsMillis() != null) {
pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
}
if (getMinEvictableIdleTimeMillis() != null) {
pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
}
if (getMaxWaitMillis() != null) {
pool.setMaxWait(getMaxWaitMillis());
}
return pool;
}
@PreDestroy
@@ -80,25 +90,12 @@ public class CommonsDataSourceConfiguration extends AbstractDataSourceConfigurat
if (this.pool != null) {
try {
this.pool.close();
} catch (SQLException ex) {
}
catch (SQLException ex) {
throw new DataAccessResourceFailureException(
"Could not close data source", ex);
}
}
}
@Override
protected int getDefaultTimeBetweenEvictionRunsMillis() {
return (int) GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
}
@Override
protected int getDefaultMinEvictableIdleTimeMillis() {
return (int) GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
}
@Override
protected int getDefaultMaxWaitMillis() {
return (int) GenericObjectPool.DEFAULT_MAX_WAIT;
}
}

View File

@@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration;
/**
* Configuration for a Tomcat database pool. The Tomcat pool provides superior performance
* and tends not to deadlock in high volume environments.
*
*
* @author Dave Syer
* @see DataSourceAutoConfiguration
*/
@@ -54,12 +54,19 @@ public class TomcatDataSourceConfiguration extends AbstractDataSourceConfigurati
this.pool.setTestOnBorrow(isTestOnBorrow());
this.pool.setTestOnReturn(isTestOnReturn());
this.pool.setTestWhileIdle(isTestWhileIdle());
this.pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
this.pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
if (getTimeBetweenEvictionRunsMillis() != null) {
this.pool
.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
}
if (getMinEvictableIdleTimeMillis() != null) {
this.pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
}
this.pool.setValidationQuery(getValidationQuery());
this.pool.setValidationInterval(this.validationInterval);
this.pool.setMaxWait(getMaxWaitMillis());
if (jdbcInterceptors != null) {
if (getMaxWaitMillis() != null) {
this.pool.setMaxWait(getMaxWaitMillis());
}
if (this.jdbcInterceptors != null) {
this.pool.setJdbcInterceptors(this.jdbcInterceptors);
}
return this.pool;
@@ -72,22 +79,11 @@ public class TomcatDataSourceConfiguration extends AbstractDataSourceConfigurati
}
}
@Override
protected int getDefaultTimeBetweenEvictionRunsMillis() {
return 5000;
public void setJdbcInterceptors(String jdbcInterceptors) {
this.jdbcInterceptors = jdbcInterceptors;
}
@Override
protected int getDefaultMinEvictableIdleTimeMillis() {
return 60000;
public void setValidationInterval(long validationInterval) {
this.validationInterval = validationInterval;
}
@Override
protected int getDefaultMaxWaitMillis() {
return 30000;
}
public void setJdbcInterceptors(String jdbcInterceptors) { this.jdbcInterceptors = jdbcInterceptors; }
public void setValidationInterval(long validationInterval) { this.validationInterval = validationInterval; }
}

View File

@@ -84,11 +84,9 @@ public class ThymeleafAutoConfiguration {
if (checkTemplateLocation) {
Resource resource = this.resourceLoader.getResource(this.environment
.getProperty("prefix", DEFAULT_PREFIX));
Assert.state(
resource.exists(),
"Cannot find template location: "
+ resource
+ " (please add some templates or check your Thymeleaf configuration)");
Assert.state(resource.exists(), "Cannot find template location: "
+ resource + " (please add some templates "
+ "or check your Thymeleaf configuration)");
}
}

View File

@@ -101,15 +101,11 @@ public class DispatcherServletAutoConfiguration {
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
ConditionOutcome outcome = checkServlets(beanFactory);
if (!outcome.isMatch()) {
return outcome;
}
return checkServletRegistrations(beanFactory);
}
@@ -123,9 +119,9 @@ public class DispatcherServletAutoConfiguration {
.containsBean(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
if (servlets.isEmpty()) {
if (containsDispatcherBean) {
return ConditionOutcome
.noMatch("found no DispatcherServlet but a non-DispatcherServlet named "
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
return ConditionOutcome.noMatch("found no DispatcherServlet "
+ "but a non-DispatcherServlet named "
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
}
return ConditionOutcome.match("no DispatcherServlet found");
}
@@ -138,9 +134,8 @@ public class DispatcherServletAutoConfiguration {
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
}
return ConditionOutcome
.match("one or more DispatcherServlets found and none is named "
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
return ConditionOutcome.match("one or more DispatcherServlets "
+ "found and none is named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
}
@@ -154,9 +149,9 @@ public class DispatcherServletAutoConfiguration {
if (registrations.isEmpty()) {
if (containsDispatcherRegistrationBean) {
return ConditionOutcome
.noMatch("found no ServletRegistrationBean but a non-ServletRegistrationBean named "
+ DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
return ConditionOutcome.noMatch("found no ServletRegistrationBean "
+ "but a non-ServletRegistrationBean named "
+ DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
}
return ConditionOutcome.match("no ServletRegistrationBean found");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,11 +29,13 @@ import static org.junit.Assert.assertNotNull;
/**
* Tests for {@link CommonsDataSourceConfiguration}.
*
*
* @author Dave Syer
*/
public class CommonsDataSourceConfigurationTests {
private static final String PREFIX = "spring.datasource.";
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@Test
@@ -47,13 +49,16 @@ public class CommonsDataSourceConfigurationTests {
@Test
public void testDataSourcePropertiesOverridden() throws Exception {
this.context.register(CommonsDataSourceConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.url:jdbc:foo//bar/spam");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testWhileIdle:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnBorrow:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnReturn:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.timeBetweenEvictionRunsMillis:10000");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.minEvictableIdleTimeMillis:12345");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.maxWait:1234");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX
+ "url:jdbc:foo//bar/spam");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testWhileIdle:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnBorrow:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnReturn:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX
+ "timeBetweenEvictionRunsMillis:10000");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX
+ "minEvictableIdleTimeMillis:12345");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "maxWait:1234");
this.context.refresh();
BasicDataSource ds = this.context.getBean(BasicDataSource.class);
assertEquals("jdbc:foo//bar/spam", ds.getUrl());
@@ -70,8 +75,10 @@ public class CommonsDataSourceConfigurationTests {
this.context.register(CommonsDataSourceConfiguration.class);
this.context.refresh();
BasicDataSource ds = this.context.getBean(BasicDataSource.class);
assertEquals(GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, ds.getTimeBetweenEvictionRunsMillis());
assertEquals(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, ds.getMinEvictableIdleTimeMillis());
assertEquals(GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
ds.getTimeBetweenEvictionRunsMillis());
assertEquals(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
ds.getMinEvictableIdleTimeMillis());
assertEquals(GenericObjectPool.DEFAULT_MAX_WAIT, ds.getMaxWait());
}

View File

@@ -37,11 +37,13 @@ import static org.junit.Assert.fail;
/**
* Tests for {@link TomcatDataSourceConfiguration}.
*
*
* @author Dave Syer
*/
public class TomcatDataSourceConfigurationTests {
private static final String PREFIX = "spring.datasource.";
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@After
@@ -60,17 +62,23 @@ public class TomcatDataSourceConfigurationTests {
@Test
public void testDataSourcePropertiesOverridden() throws Exception {
this.context.register(TomcatDataSourceConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.url:jdbc:foo//bar/spam");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testWhileIdle:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnBorrow:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.testOnReturn:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.timeBetweenEvictionRunsMillis:10000");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.minEvictableIdleTimeMillis:12345");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.maxWait:1234");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.jdbcInterceptors:SlowQueryReport");
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.validationInterval:9999");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX
+ "url:jdbc:foo//bar/spam");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testWhileIdle:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnBorrow:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnReturn:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX
+ "timeBetweenEvictionRunsMillis:10000");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX
+ "minEvictableIdleTimeMillis:12345");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "maxWait:1234");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX
+ "jdbcInterceptors:SlowQueryReport");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX
+ "validationInterval:9999");
this.context.refresh();
org.apache.tomcat.jdbc.pool.DataSource ds = this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class);
org.apache.tomcat.jdbc.pool.DataSource ds = this.context
.getBean(org.apache.tomcat.jdbc.pool.DataSource.class);
assertEquals("jdbc:foo//bar/spam", ds.getUrl());
assertEquals(true, ds.isTestWhileIdle());
assertEquals(true, ds.isTestOnBorrow());
@@ -82,8 +90,10 @@ public class TomcatDataSourceConfigurationTests {
assertDataSourceHasInterceptors(ds);
}
private void assertDataSourceHasInterceptors(DataSourceProxy ds) throws ClassNotFoundException {
PoolProperties.InterceptorDefinition[] interceptors = ds.getJdbcInterceptorsAsArray();
private void assertDataSourceHasInterceptors(DataSourceProxy ds)
throws ClassNotFoundException {
PoolProperties.InterceptorDefinition[] interceptors = ds
.getJdbcInterceptorsAsArray();
for (PoolProperties.InterceptorDefinition interceptor : interceptors) {
if (SlowQueryReport.class == interceptor.getInterceptorClass()) {
return;
@@ -96,7 +106,8 @@ public class TomcatDataSourceConfigurationTests {
public void testDataSourceDefaultsPreserved() throws Exception {
this.context.register(TomcatDataSourceConfiguration.class);
this.context.refresh();
org.apache.tomcat.jdbc.pool.DataSource ds = this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class);
org.apache.tomcat.jdbc.pool.DataSource ds = this.context
.getBean(org.apache.tomcat.jdbc.pool.DataSource.class);
assertEquals(5000, ds.getTimeBetweenEvictionRunsMillis());
assertEquals(60000, ds.getMinEvictableIdleTimeMillis());
assertEquals(30000, ds.getMaxWait());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletCont
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
@@ -76,7 +76,7 @@ public class ServerPropertiesTests {
public void testCustomizeTomcat() throws Exception {
ConfigurableEmbeddedServletContainer factory = mock(ConfigurableEmbeddedServletContainer.class);
this.properties.customize(factory);
verify(factory, times(0)).setContextPath("");
verify(factory, never()).setContextPath("");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package sample.actuator;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -26,22 +24,24 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertNotNull;
/**
* Basic integration tests for service demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorNoWebApplication.class)
@SpringApplicationConfiguration(classes = SampleActuatorNoWebApplication.class)
@DirtiesContext
public class SampleActuatorNoWebApplicationTests {
@Autowired
private MetricsEndpoint endpoint;
@Test
public void endpointsExist() throws Exception {
assertNotNull(endpoint);
assertNotNull(this.endpoint);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package sample.actuator.ui;
import static org.junit.Assert.assertEquals;
import java.util.Map;
import org.junit.Test;
@@ -35,13 +33,15 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/**
* Integration tests for separate management and main service ports.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorUiApplication.class)
@SpringApplicationConfiguration(classes = SampleActuatorUiApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext
@@ -60,7 +60,7 @@ public class SampleActuatorUiApplicationPortTests {
@Test
public void testHome() throws Exception {
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
"http://localhost:" + port, String.class);
"http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
}
@@ -68,14 +68,14 @@ public class SampleActuatorUiApplicationPortTests {
public void testMetrics() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
"http://localhost:" + managementPort + "/metrics", Map.class);
"http://localhost:" + this.managementPort + "/metrics", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
}
@Test
public void testHealth() throws Exception {
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
"http://localhost:" + managementPort + "/health", String.class);
"http://localhost:" + this.managementPort + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("ok", entity.getBody());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
package sample.actuator.ui;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Map;
@@ -37,13 +34,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Basic integration tests for demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorUiApplication.class)
@SpringApplicationConfiguration(classes = SampleActuatorUiApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package sample.actuator;
import static org.junit.Assert.assertEquals;
import java.util.Map;
import org.junit.Test;
@@ -32,6 +30,8 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/**
* Integration tests for endpoints configuration.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package sample.actuator;
import static org.junit.Assert.assertEquals;
import java.util.Map;
import org.junit.Test;
@@ -35,13 +33,15 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/**
* Integration tests for separate management and main service ports.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class)
@SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext
@@ -61,14 +61,16 @@ public class ManagementAddressActuatorApplicationTests {
public void testHome() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get().getForEntity(
"http://localhost:" + port, Map.class);
"http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
}
@Test
public void testHealth() throws Exception {
ResponseEntity<String> entity = RestTemplates.get().getForEntity(
"http://localhost:" + managementPort + "/admin/health", String.class);
ResponseEntity<String> entity = RestTemplates.get()
.getForEntity(
"http://localhost:" + this.managementPort + "/admin/health",
String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("ok", entity.getBody());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package sample.actuator;
import static org.junit.Assert.assertEquals;
import java.util.Map;
import org.junit.Test;
@@ -36,13 +34,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals;
/**
* Integration tests for separate management and main service ports.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class)
@SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext
@@ -62,7 +62,7 @@ public class ManagementPortSampleActuatorApplicationTests {
public void testHome() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate("user", getPassword()).getForEntity(
"http://localhost:" + port, Map.class);
"http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();
@@ -74,14 +74,14 @@ public class ManagementPortSampleActuatorApplicationTests {
testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate().getForEntity(
"http://localhost:" + managementPort + "/metrics", Map.class);
"http://localhost:" + this.managementPort + "/metrics", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
}
@Test
public void testHealth() throws Exception {
ResponseEntity<String> entity = getRestTemplate().getForEntity(
"http://localhost:" + managementPort + "/health", String.class);
"http://localhost:" + this.managementPort + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("ok", entity.getBody());
}
@@ -90,7 +90,7 @@ public class ManagementPortSampleActuatorApplicationTests {
public void testErrorPage() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate().getForEntity(
"http://localhost:" + managementPort + "/error", Map.class);
"http://localhost:" + this.managementPort + "/error", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();
@@ -98,7 +98,7 @@ public class ManagementPortSampleActuatorApplicationTests {
}
private String getPassword() {
return security.getUser().getPassword();
return this.security.getUser().getPassword();
}
private RestTemplate getRestTemplate() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package sample.actuator;
import static org.junit.Assert.assertEquals;
import java.util.Map;
import org.junit.Test;
@@ -34,13 +32,15 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/**
* Integration tests for switching off management endpoints.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class)
@SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext
@@ -53,8 +53,8 @@ public class NoManagementSampleActuatorApplicationTests {
@Test
public void testHome() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity(
"http://localhost:8080", Map.class);
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
.getForEntity("http://localhost:8080", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();
@@ -65,13 +65,13 @@ public class NoManagementSampleActuatorApplicationTests {
public void testMetricsNotAvailable() throws Exception {
testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity(
"http://localhost:8080/metrics", Map.class);
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
.getForEntity("http://localhost:8080/metrics", Map.class);
assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode());
}
private String getPassword() {
return security.getUser().getPassword();
return this.security.getUser().getPassword();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,6 @@
package sample.actuator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -42,13 +37,18 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Basic integration tests for service demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class)
@SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext
@@ -73,8 +73,8 @@ public class SampleActuatorApplicationTests {
@Test
public void testHome() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity(
"http://localhost:8080", Map.class);
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
.getForEntity("http://localhost:8080", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();
@@ -85,8 +85,8 @@ public class SampleActuatorApplicationTests {
public void testMetrics() throws Exception {
testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity(
"http://localhost:8080/metrics", Map.class);
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
.getForEntity("http://localhost:8080/metrics", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();
@@ -96,8 +96,8 @@ public class SampleActuatorApplicationTests {
@Test
public void testEnv() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity(
"http://localhost:8080/env", Map.class);
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
.getForEntity("http://localhost:8080/env", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();
@@ -127,8 +127,9 @@ public class SampleActuatorApplicationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<?> request = new HttpEntity<Void>(headers);
ResponseEntity<String> entity = RestTemplates.get("user", getPassword()).exchange(
"http://localhost:8080/foo", HttpMethod.GET, request, String.class);
ResponseEntity<String> entity = RestTemplates.get("user", getPassword())
.exchange("http://localhost:8080/foo", HttpMethod.GET, request,
String.class);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
String body = entity.getBody();
assertNotNull("Body was null", body);
@@ -178,7 +179,7 @@ public class SampleActuatorApplicationTests {
}
private String getPassword() {
return security.getUser().getPassword();
return this.security.getUser().getPassword();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
package sample.actuator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Map;
import org.junit.Test;
@@ -34,13 +31,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Integration tests for separate management and main service ports.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class)
@SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext
@@ -52,8 +52,8 @@ public class ShutdownSampleActuatorApplicationTests {
@Test
public void testHome() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword()).getForEntity(
"http://localhost:8080", Map.class);
ResponseEntity<Map> entity = RestTemplates.get("user", getPassword())
.getForEntity("http://localhost:8080", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();
@@ -73,7 +73,7 @@ public class ShutdownSampleActuatorApplicationTests {
}
private String getPassword() {
return security.getUser().getPassword();
return this.security.getUser().getPassword();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,6 @@
package sample.actuator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Map;
import org.junit.Test;
@@ -34,6 +30,10 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Integration tests for unsecured service endpoints (even with Spring Security on
* classpath).
@@ -41,7 +41,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class)
@SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
package sample.actuator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.util.Map;
import org.junit.Test;
@@ -33,6 +30,9 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/**
* Integration tests for unsecured service endpoints (even with Spring Security on
* classpath).
@@ -40,7 +40,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleActuatorApplication.class)
@SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package sample.jetty;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.IntegrationTest;
@@ -29,13 +27,15 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/**
* Basic integration tests for demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleJettyApplication.class)
@SpringApplicationConfiguration(classes = SampleJettyApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -1,6 +1,20 @@
package sample.servlet;
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static org.junit.Assert.assertEquals;
package sample.servlet;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -15,13 +29,15 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/**
* Basic integration tests for demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleServletApplication.class)
@SpringApplicationConfiguration(classes = SampleServletApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext
@@ -46,6 +62,6 @@ public class SampleServletApplicationTests {
}
private String getPassword() {
return security.getUser().getPassword();
return this.security.getUser().getPassword();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -16,8 +16,6 @@
package sample.tomcat;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.SpringApplication;
@@ -43,13 +41,15 @@ import sample.tomcat.NonAutoConfigurationSampleTomcatApplicationTests.NonAutoCon
import sample.tomcat.service.HelloWorldService;
import sample.tomcat.web.SampleController;
import static org.junit.Assert.assertEquals;
/**
* Basic integration tests for demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=NonAutoConfigurationSampleTomcatApplication.class)
@SpringApplicationConfiguration(classes = NonAutoConfigurationSampleTomcatApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package sample.tomcat;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.IntegrationTest;
@@ -29,13 +27,15 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
/**
* Basic integration tests for demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleTomcatApplication.class)
@SpringApplicationConfiguration(classes = SampleTomcatApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
package sample.traditional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.IntegrationTest;
@@ -30,13 +27,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Basic integration tests for demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleTraditionalApplication.class)
@SpringApplicationConfiguration(classes = SampleTraditionalApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.jsp;
import java.util.Date;
@@ -16,7 +32,7 @@ public class WelcomeController {
@RequestMapping("/")
public String welcome(Map<String, Object> model) {
model.put("time", new Date());
model.put("message", message);
model.put("message", this.message);
return "welcome";
}

View File

@@ -1,7 +1,20 @@
package sample.jsp;
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
package sample.jsp;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -14,13 +27,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Basic integration tests for JSP application.
*
* @author Phillip Webb
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleWebJspApplication.class)
@SpringApplicationConfiguration(classes = SampleWebJspApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -16,9 +16,6 @@
package sample.ui.method;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -40,13 +37,16 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Basic integration tests for demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleMethodSecurityApplication.class)
@SpringApplicationConfiguration(classes = SampleMethodSecurityApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -16,9 +16,6 @@
package sample.ui.secure;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import org.junit.Test;
@@ -36,13 +33,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Basic integration tests for demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleSecureApplication.class)
@SpringApplicationConfiguration(classes = SampleSecureApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -1,7 +1,20 @@
package sample.ui;
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
package sample.ui;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -15,13 +28,16 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Basic integration tests for demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleWebStaticApplication.class)
@SpringApplicationConfiguration(classes = SampleWebStaticApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.ui;
import java.util.regex.Pattern;
@@ -56,12 +72,12 @@ public class MessageControllerWebTests {
.andExpect(header().string("location", RegexMatcher.matches("/[0-9]+")));
}
@Test
public void testCreateValidation() throws Exception{
this.mockMvc.perform(post("/").param("text", "").param("summary", ""))
.andExpect(status().isOk())
.andExpect(content().string(containsString("is required")));
}
@Test
public void testCreateValidation() throws Exception {
this.mockMvc.perform(post("/").param("text", "").param("summary", ""))
.andExpect(status().isOk())
.andExpect(content().string(containsString("is required")));
}
private static class RegexMatcher extends TypeSafeMatcher<String> {
private final String regex;

View File

@@ -1,8 +1,20 @@
package sample.ui;
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
package sample.ui;
import java.net.URI;
@@ -19,13 +31,17 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Basic integration tests for demo application.
*
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleWebUiApplication.class)
@SpringApplicationConfiguration(classes = SampleWebUiApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package samples.websocket.echo;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -46,17 +44,21 @@ import samples.websocket.client.SimpleGreetingService;
import samples.websocket.config.SampleWebSocketsApplication;
import samples.websocket.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes={SampleWebSocketsApplication.class, CustomContainerConfiguration.class })
@SpringApplicationConfiguration(classes = { SampleWebSocketsApplication.class,
CustomContainerConfiguration.class })
@WebAppConfiguration
@IntegrationTest
@DirtiesContext
public class CustomContainerWebSocketsApplicationTests {
private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class);
private static Log logger = LogFactory
.getLog(CustomContainerWebSocketsApplicationTests.class);
private static final String WS_URI = "ws://localhost:9010/ws/echo/websocket";
@Configuration
protected static class CustomContainerConfiguration {
@Bean

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package samples.websocket.echo;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -43,8 +41,10 @@ import samples.websocket.client.SimpleClientWebSocketHandler;
import samples.websocket.client.SimpleGreetingService;
import samples.websocket.config.SampleWebSocketsApplication;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=SampleWebSocketsApplication.class)
@SpringApplicationConfiguration(classes = SampleWebSocketsApplication.class)
@WebAppConfiguration
@IntegrationTest
@DirtiesContext

View File

@@ -26,7 +26,6 @@ import java.util.concurrent.Callable;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.internal.file.collections.SimpleFileCollection;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.SourceSet;
@@ -45,15 +44,10 @@ public class RunApp extends DefaultTask {
final Project project = getProject();
final SourceSet main = ComputeMain.findMainSourceSet(project);
final File outputDir = (main == null ? null : main.getOutput().getResourcesDir());
final Set<File> allResources = new LinkedHashSet<File>();
final File outputs;
if (main != null) {
SourceDirectorySet resources = main.getResources();
allResources.addAll(resources.getSrcDirs());
outputs = main.getOutput().getResourcesDir();
} else {
outputs = null;
allResources.addAll(main.getResources().getSrcDirs());
}
project.getTasks().withType(JavaExec.class, new Action<JavaExec>() {
@@ -78,21 +72,25 @@ public class RunApp extends DefaultTask {
});
getLogger().info("Found main: " + mainClass);
}
if (outputs != null) {
// remove duplicates from resources and build
if (outputDir != null) {
for (File directory : allResources) {
if (directory.isDirectory()) {
for (String name : directory.list()) {
File file = new File(outputs, name);
if (file.exists() && file.canWrite()) {
getProject().delete(file);
}
}
}
removeDuplicatesFromOutputDir(directory, outputDir);
}
}
exec.exec();
}
private void removeDuplicatesFromOutputDir(File directory, File outputDir) {
if (directory.isDirectory()) {
for (String name : directory.list()) {
File outputFile = new File(outputDir, name);
if (outputFile.exists() && outputFile.canWrite()) {
getProject().delete(outputFile);
}
}
}
}
});
}
@@ -104,7 +102,8 @@ public class RunApp extends DefaultTask {
getLogger().info("Looking for main in: " + main.getOutput().getClassesDir());
try {
return MainClassFinder.findMainClass(main.getOutput().getClassesDir());
} catch (IOException ex) {
}
catch (IOException ex) {
throw new IllegalStateException("Cannot find main class", ex);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import org.springframework.boot.loader.jar.JarFile;
* {@link ClassLoader} used by the {@link Launcher}.
*
* @author Phillip Webb
* @author Dave Syer
*/
public class LaunchedURLClassLoader extends URLClassLoader {
@@ -67,31 +68,29 @@ public class LaunchedURLClassLoader extends URLClassLoader {
@Override
public URL findResource(String name) {
if (name.equals("")) {
URL[] urls = getURLs();
if (urls.length > 0) {
return urls[0];
}
}
try {
if (name.equals("") && hasURLs()) {
return getURLs()[0];
}
return super.findResource(name);
}
catch (IllegalArgumentException e) {
catch (IllegalArgumentException ex) {
return null;
}
}
@Override
public Enumeration<URL> findResources(String name) throws IOException {
if (name.equals("")) {
URL[] urls = getURLs();
if (urls.length > 0) {
return Collections.enumeration(Arrays.asList(urls));
}
if (name.equals("") && hasURLs()) {
return Collections.enumeration(Arrays.asList(getURLs()));
}
return super.findResources(name);
}
private boolean hasURLs() {
return getURLs().length > 0;
}
@Override
public Enumeration<URL> getResources(String name) throws IOException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,8 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link LaunchedURLClassLoader}.
*
* @author Dave Syer
*/
public class LaunchedURLClassLoaderTests {

View File

@@ -50,9 +50,6 @@ import org.springframework.boot.loader.tools.MainClassFinder;
@Execute(phase = LifecyclePhase.TEST_COMPILE)
public class RunMojo extends AbstractMojo {
/**
*
*/
private static final String SPRING_LOADED_AGENT_CLASSNAME = "org.springsource.loaded.agent.SpringLoadedAgent";
/**
@@ -201,18 +198,21 @@ public class RunMojo extends AbstractMojo {
for (Resource resource : this.project.getResources()) {
File directory = new File(resource.getDirectory());
urls.add(directory.toURI().toURL());
if (directory.isDirectory()) {
// Remove duplicates from the target directory...
for (String name : directory.list()) {
File file = new File(this.classesDirectory, name);
if (file.exists() && file.canWrite()) {
if (file.isDirectory()) {
FileUtils.deleteDirectory(file);
}
else {
file.delete();
}
}
removeDuplicatesFromTarget(directory);
}
}
}
private void removeDuplicatesFromTarget(File directory) throws IOException {
if (directory.isDirectory()) {
for (String name : directory.list()) {
File targetFile = new File(this.classesDirectory, name);
if (targetFile.exists() && targetFile.canWrite()) {
if (targetFile.isDirectory()) {
FileUtils.deleteDirectory(targetFile);
}
else {
targetFile.delete();
}
}
}

View File

@@ -383,9 +383,9 @@ public class SpringApplication {
/**
* Template method delegating to
* {@link #configurePropertySources(ConfigurableEnvironment, String[])} and
* {@link #configureProfiles(ConfigurableEnvironment, String[])} in that order. Override
* this method for complete control over Environment customization, or one of the above
* for fine-grained control over property sources or profiles, respectively.
* {@link #configureProfiles(ConfigurableEnvironment, String[])} in that order.
* Override this method for complete control over Environment customization, or one of
* the above for fine-grained control over property sources or profiles, respectively.
* @param environment this application's environment
* @param args arguments passed to the {@code run} method
* @see #configurePropertySources(ConfigurableEnvironment, String[])
@@ -397,12 +397,14 @@ public class SpringApplication {
}
/**
* Add, remove or re-order any {@link PropertySource}s in this application's environment.
* Add, remove or re-order any {@link PropertySource}s in this application's
* environment.
* @param environment this application's environment
* @param args arguments passed to the {@code run} method
* @see #configureEnvironment(ConfigurableEnvironment, String[])
*/
protected void configurePropertySources(ConfigurableEnvironment environment, String[] args) {
protected void configurePropertySources(ConfigurableEnvironment environment,
String[] args) {
MutablePropertySources sources = environment.getPropertySources();
if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) {
sources.addLast(new MapPropertySource("defaultProperties",
@@ -425,9 +427,10 @@ public class SpringApplication {
}
/**
* Configure which profiles are active (or active by default) for this application environment.
* Consider overriding this method to programmatically enforce profile rules and semantics,
* such as ensuring mutual exclusivity of profiles (e.g. 'dev' OR 'prod', but never both).
* Configure which profiles are active (or active by default) for this application
* environment. Consider overriding this method to programmatically enforce profile
* rules and semantics, such as ensuring mutual exclusivity of profiles (e.g. 'dev' OR
* 'prod', but never both).
* @param environment this application's environment
* @param args arguments passed to the {@code run} method
* @see #configureEnvironment(ConfigurableEnvironment, String[])

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -233,8 +233,8 @@ public class FilterRegistrationBean extends RegistrationBean {
String name = getOrDeduceName(this.filter);
FilterRegistration.Dynamic added = servletContext.addFilter(name, this.filter);
if (added == null) {
logger.info("Filter " + name
+ " was not registered (possibly already registered?)");
logger.info("Filter " + name + " was not registered "
+ "(possibly already registered?)");
return;
}
configure(added);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -161,8 +161,8 @@ public class ServletRegistrationBean extends RegistrationBean {
logger.info("Mapping servlet: '" + name + "' to " + this.urlMappings);
Dynamic added = servletContext.addServlet(name, this.servlet);
if (added == null) {
logger.info("Servlet " + name
+ " was not registered (possibly already registered?)");
logger.info("Servlet " + name + " was not registered "
+ "(possibly already registered?)");
return;
}
configure(added);

View File

@@ -121,26 +121,7 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
HttpServletResponse response, ErrorWrapperResponse wrapped, Throwable ex)
throws IOException, ServletException {
Class<?> type = ex.getClass();
String errorPath = this.global;
if (this.exceptions.containsKey(type)) {
errorPath = this.exceptions.get(type);
}
else {
if (this.subtypes.containsKey(type)) {
errorPath = this.exceptions.get(this.subtypes.get(type));
}
else {
Class<?> subtype = type;
while (subtype != Object.class) {
subtype = subtype.getSuperclass();
if (this.exceptions.containsKey(subtype)) {
this.subtypes.put(subtype, type);
errorPath = this.exceptions.get(subtype);
break;
}
}
}
}
String errorPath = getErrorPath(type);
if (errorPath == null) {
rethrow(ex);
return;
@@ -152,9 +133,27 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
request.getRequestDispatcher(errorPath).forward(request, response);
}
private String getErrorPath(Map<?, String> map, Object key) {
if (map.containsKey(key)) {
return map.get(key);
private String getErrorPath(Map<Integer, String> map, Integer status) {
if (map.containsKey(status)) {
return map.get(status);
}
return this.global;
}
private String getErrorPath(Class<?> type) {
if (this.exceptions.containsKey(type)) {
return this.exceptions.get(type);
}
if (this.subtypes.containsKey(type)) {
return this.exceptions.get(this.subtypes.get(type));
}
Class<?> subtype = type;
while (subtype != Object.class) {
subtype = subtype.getSuperclass();
if (this.exceptions.containsKey(subtype)) {
this.subtypes.put(subtype, type);
return this.exceptions.get(subtype);
}
}
return this.global;
}

View File

@@ -17,10 +17,7 @@
package org.springframework.boot.test;
/**
* @author dsyer
*/
/**
* Copied from Spring Security Crypto.
* Base64 Encoding Support. Copied from Spring Security Crypto.
*
* @author Luke Taylor
*/
@@ -643,4 +640,4 @@ class InvalidBase64CharacterException extends IllegalArgumentException {
InvalidBase64CharacterException(String message) {
super(message);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,7 +52,6 @@ public class RestTemplates {
/**
* Basic factory method for a RestTemplate that does not follow redirects, ignores
* cookies and does not throw exceptions on server side errors.
*
* @return a basic RestTemplate with no authentication
*/
public static RestTemplate get() {
@@ -63,7 +62,6 @@ public class RestTemplates {
* Factory method for a secure RestTemplate with Basic authentication that does not
* follow redirects, ignores cookies and does not throw exceptions on server side
* errors.
*
* @return a basic RestTemplate with Basic authentication
*/
public static RestTemplate get(final String username, final String password) {
@@ -71,20 +69,17 @@ public class RestTemplates {
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
if (username != null) {
interceptors.add(new ClientHttpRequestInterceptor() {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().add(
"Authorization",
"Basic "
+ new String(Base64
.encode((username + ":" + password)
.getBytes())));
byte[] token = Base64.encode((username + ":" + password).getBytes());
request.getHeaders().add("Authorization",
"Basic " + new String(token));
return execution.execute(request, body);
}
});
}

View File

@@ -54,6 +54,7 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
* create the application context.
*
* @author Dave Syer
* @see IntegrationTest
*/
public class SpringApplicationContextLoader extends AbstractContextLoader {

View File

@@ -38,7 +38,7 @@ import org.mockito.MockitoAnnotations;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
@@ -87,7 +87,7 @@ public class ServletRegistrationBeanTests {
.willReturn(null);
bean.onStartup(this.servletContext);
verify(this.servletContext).addServlet("mockServlet", this.servlet);
verify(this.registration, times(0)).setAsyncSupported(true);
verify(this.registration, never()).setAsyncSupported(true);
}
@Test