Rename ApplicationContextTester -> Runner
Rename `ApplicationContextTester` and related classes to `ApplicationContextRunner` and refactor existing tests to use correctly named variables. See gh-9875
This commit is contained in:
parent
5616915621
commit
497457c397
|
|
@ -60,7 +60,7 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration;
|
import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
import org.springframework.boot.test.context.AssertableApplicationContext;
|
import org.springframework.boot.test.context.AssertableApplicationContext;
|
||||||
import org.springframework.boot.test.context.ContextConsumer;
|
import org.springframework.boot.test.context.ContextConsumer;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
@ -84,39 +84,39 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class HealthIndicatorAutoConfigurationTests {
|
public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
public final ApplicationContextTester context = new ApplicationContextTester()
|
public final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(HealthIndicatorAutoConfiguration.class,
|
AutoConfigurations.of(HealthIndicatorAutoConfiguration.class,
|
||||||
ManagementServerProperties.class));
|
ManagementServerProperties.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultHealthIndicator() {
|
public void defaultHealthIndicator() {
|
||||||
this.context.withPropertyValues("management.health.diskspace.enabled:false")
|
this.contextRunner.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultHealthIndicatorsDisabled() {
|
public void defaultHealthIndicatorsDisabled() {
|
||||||
this.context.withPropertyValues("management.health.defaults.enabled:false")
|
this.contextRunner.withPropertyValues("management.health.defaults.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultHealthIndicatorsDisabledWithCustomOne() {
|
public void defaultHealthIndicatorsDisabledWithCustomOne() {
|
||||||
this.context.withUserConfiguration(CustomHealthIndicator.class)
|
this.contextRunner.withUserConfiguration(CustomHealthIndicator.class)
|
||||||
.withPropertyValues("management.health.defaults.enabled:false")
|
.withPropertyValues("management.health.defaults.enabled:false")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
Map<String, HealthIndicator> beans = loaded
|
Map<String, HealthIndicator> beans = context
|
||||||
.getBeansOfType(HealthIndicator.class);
|
.getBeansOfType(HealthIndicator.class);
|
||||||
assertThat(beans).hasSize(1);
|
assertThat(beans).hasSize(1);
|
||||||
assertThat(loaded.getBean("customHealthIndicator"))
|
assertThat(context.getBean("customHealthIndicator"))
|
||||||
.isSameAs(beans.values().iterator().next());
|
.isSameAs(beans.values().iterator().next());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultHealthIndicatorsDisabledButOne() {
|
public void defaultHealthIndicatorsDisabledButOne() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues("management.health.defaults.enabled:false",
|
.withPropertyValues("management.health.defaults.enabled:false",
|
||||||
"management.health.diskspace.enabled:true")
|
"management.health.diskspace.enabled:true")
|
||||||
.run(hasSingleHealthIndicator(DiskSpaceHealthIndicator.class));
|
.run(hasSingleHealthIndicator(DiskSpaceHealthIndicator.class));
|
||||||
|
|
@ -124,7 +124,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void redisHealthIndicator() {
|
public void redisHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(RedisHealthIndicator.class));
|
.run(hasSingleHealthIndicator(RedisHealthIndicator.class));
|
||||||
|
|
@ -132,7 +132,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notRedisHealthIndicator() {
|
public void notRedisHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.redis.enabled:false",
|
.withPropertyValues("management.health.redis.enabled:false",
|
||||||
"management.health.diskspace.enabled:false")
|
"management.health.diskspace.enabled:false")
|
||||||
|
|
@ -141,7 +141,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mongoHealthIndicator() {
|
public void mongoHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class,
|
||||||
MongoDataAutoConfiguration.class))
|
MongoDataAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
|
|
@ -150,7 +150,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notMongoHealthIndicator() {
|
public void notMongoHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class,
|
||||||
MongoDataAutoConfiguration.class))
|
MongoDataAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.mongo.enabled:false",
|
.withPropertyValues("management.health.mongo.enabled:false",
|
||||||
|
|
@ -160,10 +160,12 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combinedHealthIndicator() {
|
public void combinedHealthIndicator() {
|
||||||
this.context.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class,
|
this.contextRunner
|
||||||
|
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class,
|
||||||
RedisAutoConfiguration.class, MongoDataAutoConfiguration.class,
|
RedisAutoConfiguration.class, MongoDataAutoConfiguration.class,
|
||||||
SolrAutoConfiguration.class)).run((loaded) -> {
|
SolrAutoConfiguration.class))
|
||||||
Map<String, HealthIndicator> beans = loaded
|
.run((context) -> {
|
||||||
|
Map<String, HealthIndicator> beans = context
|
||||||
.getBeansOfType(HealthIndicator.class);
|
.getBeansOfType(HealthIndicator.class);
|
||||||
assertThat(beans).hasSize(4);
|
assertThat(beans).hasSize(4);
|
||||||
});
|
});
|
||||||
|
|
@ -171,7 +173,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dataSourceHealthIndicator() {
|
public void dataSourceHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(DataSourceAutoConfiguration.class))
|
AutoConfigurations.of(DataSourceAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
|
|
@ -180,12 +182,12 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dataSourceHealthIndicatorWithSeveralDataSources() {
|
public void dataSourceHealthIndicatorWithSeveralDataSources() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withUserConfiguration(EmbeddedDataSourceConfiguration.class,
|
.withUserConfiguration(EmbeddedDataSourceConfiguration.class,
|
||||||
DataSourceConfig.class)
|
DataSourceConfig.class)
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
Map<String, HealthIndicator> beans = loaded
|
Map<String, HealthIndicator> beans = context
|
||||||
.getBeansOfType(HealthIndicator.class);
|
.getBeansOfType(HealthIndicator.class);
|
||||||
assertThat(beans).hasSize(1);
|
assertThat(beans).hasSize(1);
|
||||||
HealthIndicator bean = beans.values().iterator().next();
|
HealthIndicator bean = beans.values().iterator().next();
|
||||||
|
|
@ -197,7 +199,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dataSourceHealthIndicatorWithAbstractRoutingDataSource() {
|
public void dataSourceHealthIndicatorWithAbstractRoutingDataSource() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withUserConfiguration(EmbeddedDataSourceConfiguration.class,
|
.withUserConfiguration(EmbeddedDataSourceConfiguration.class,
|
||||||
RoutingDatasourceConfig.class)
|
RoutingDatasourceConfig.class)
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
|
|
@ -206,15 +208,15 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dataSourceHealthIndicatorWithCustomValidationQuery() {
|
public void dataSourceHealthIndicatorWithCustomValidationQuery() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withUserConfiguration(DataSourceConfig.class,
|
.withUserConfiguration(DataSourceConfig.class,
|
||||||
DataSourcePoolMetadataProvidersConfiguration.class,
|
DataSourcePoolMetadataProvidersConfiguration.class,
|
||||||
HealthIndicatorAutoConfiguration.class)
|
HealthIndicatorAutoConfiguration.class)
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.datasource.test.validation-query:SELECT from FOOBAR",
|
"spring.datasource.test.validation-query:SELECT from FOOBAR",
|
||||||
"management.health.diskspace.enabled:false")
|
"management.health.diskspace.enabled:false")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
Map<String, HealthIndicator> beans = loaded
|
Map<String, HealthIndicator> beans = context
|
||||||
.getBeansOfType(HealthIndicator.class);
|
.getBeansOfType(HealthIndicator.class);
|
||||||
assertThat(beans).hasSize(1);
|
assertThat(beans).hasSize(1);
|
||||||
HealthIndicator healthIndicator = beans.values().iterator().next();
|
HealthIndicator healthIndicator = beans.values().iterator().next();
|
||||||
|
|
@ -228,7 +230,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notDataSourceHealthIndicator() {
|
public void notDataSourceHealthIndicator() {
|
||||||
this.context.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||||
.withPropertyValues("management.health.db.enabled:false",
|
.withPropertyValues("management.health.db.enabled:false",
|
||||||
"management.health.diskspace.enabled:false")
|
"management.health.diskspace.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
||||||
|
|
@ -236,7 +238,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rabbitHealthIndicator() {
|
public void rabbitHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(RabbitAutoConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(RabbitAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(RabbitHealthIndicator.class));
|
.run(hasSingleHealthIndicator(RabbitHealthIndicator.class));
|
||||||
|
|
@ -244,7 +246,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notRabbitHealthIndicator() {
|
public void notRabbitHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(RabbitAutoConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(RabbitAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.rabbit.enabled:false",
|
.withPropertyValues("management.health.rabbit.enabled:false",
|
||||||
"management.health.diskspace.enabled:false")
|
"management.health.diskspace.enabled:false")
|
||||||
|
|
@ -253,14 +255,16 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void solrHealthIndicator() {
|
public void solrHealthIndicator() {
|
||||||
this.context.withConfiguration(AutoConfigurations.of(SolrAutoConfiguration.class))
|
this.contextRunner
|
||||||
|
.withConfiguration(AutoConfigurations.of(SolrAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(SolrHealthIndicator.class));
|
.run(hasSingleHealthIndicator(SolrHealthIndicator.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notSolrHealthIndicator() {
|
public void notSolrHealthIndicator() {
|
||||||
this.context.withConfiguration(AutoConfigurations.of(SolrAutoConfiguration.class))
|
this.contextRunner
|
||||||
|
.withConfiguration(AutoConfigurations.of(SolrAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.solr.enabled:false",
|
.withPropertyValues("management.health.solr.enabled:false",
|
||||||
"management.health.diskspace.enabled:false")
|
"management.health.diskspace.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
||||||
|
|
@ -268,12 +272,12 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void diskSpaceHealthIndicator() {
|
public void diskSpaceHealthIndicator() {
|
||||||
this.context.run(hasSingleHealthIndicator(DiskSpaceHealthIndicator.class));
|
this.contextRunner.run(hasSingleHealthIndicator(DiskSpaceHealthIndicator.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mailHealthIndicator() {
|
public void mailHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(MailSenderAutoConfiguration.class))
|
AutoConfigurations.of(MailSenderAutoConfiguration.class))
|
||||||
.withPropertyValues("spring.mail.host:smtp.acme.org",
|
.withPropertyValues("spring.mail.host:smtp.acme.org",
|
||||||
|
|
@ -283,7 +287,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notMailHealthIndicator() {
|
public void notMailHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(MailSenderAutoConfiguration.class))
|
AutoConfigurations.of(MailSenderAutoConfiguration.class))
|
||||||
.withPropertyValues("spring.mail.host:smtp.acme.org",
|
.withPropertyValues("spring.mail.host:smtp.acme.org",
|
||||||
|
|
@ -294,7 +298,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jmsHealthIndicator() {
|
public void jmsHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(ActiveMQAutoConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(ActiveMQAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(JmsHealthIndicator.class));
|
.run(hasSingleHealthIndicator(JmsHealthIndicator.class));
|
||||||
|
|
@ -302,7 +306,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notJmsHealthIndicator() {
|
public void notJmsHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(ActiveMQAutoConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(ActiveMQAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.jms.enabled:false",
|
.withPropertyValues("management.health.jms.enabled:false",
|
||||||
"management.health.diskspace.enabled:false")
|
"management.health.diskspace.enabled:false")
|
||||||
|
|
@ -311,7 +315,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void elasticsearchHealthIndicator() {
|
public void elasticsearchHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(JestClientConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(JestClientConfiguration.class,
|
||||||
JestAutoConfiguration.class,
|
JestAutoConfiguration.class,
|
||||||
ElasticsearchAutoConfiguration.class))
|
ElasticsearchAutoConfiguration.class))
|
||||||
|
|
@ -323,7 +327,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void elasticsearchJestHealthIndicator() {
|
public void elasticsearchJestHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(JestClientConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(JestClientConfiguration.class,
|
||||||
JestAutoConfiguration.class))
|
JestAutoConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
|
|
@ -333,7 +337,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notElasticsearchHealthIndicator() {
|
public void notElasticsearchHealthIndicator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(JestClientConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(JestClientConfiguration.class,
|
||||||
JestAutoConfiguration.class,
|
JestAutoConfiguration.class,
|
||||||
ElasticsearchAutoConfiguration.class))
|
ElasticsearchAutoConfiguration.class))
|
||||||
|
|
@ -345,7 +349,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cassandraHealthIndicator() throws Exception {
|
public void cassandraHealthIndicator() throws Exception {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(CassandraConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(CassandraConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(CassandraHealthIndicator.class));
|
.run(hasSingleHealthIndicator(CassandraHealthIndicator.class));
|
||||||
|
|
@ -353,7 +357,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notCassandraHealthIndicator() throws Exception {
|
public void notCassandraHealthIndicator() throws Exception {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(CassandraConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(CassandraConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false",
|
.withPropertyValues("management.health.diskspace.enabled:false",
|
||||||
"management.health.cassandra.enabled:false")
|
"management.health.cassandra.enabled:false")
|
||||||
|
|
@ -362,7 +366,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void couchbaseHealthIndicator() throws Exception {
|
public void couchbaseHealthIndicator() throws Exception {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(CouchbaseConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(CouchbaseConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(CouchbaseHealthIndicator.class));
|
.run(hasSingleHealthIndicator(CouchbaseHealthIndicator.class));
|
||||||
|
|
@ -370,7 +374,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notCouchbaseHealthIndicator() throws Exception {
|
public void notCouchbaseHealthIndicator() throws Exception {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(CouchbaseConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(CouchbaseConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false",
|
.withPropertyValues("management.health.diskspace.enabled:false",
|
||||||
"management.health.couchbase.enabled:false")
|
"management.health.couchbase.enabled:false")
|
||||||
|
|
@ -379,14 +383,16 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ldapHealthIndicator() throws Exception {
|
public void ldapHealthIndicator() throws Exception {
|
||||||
this.context.withConfiguration(AutoConfigurations.of(LdapConfiguration.class))
|
this.contextRunner
|
||||||
|
.withConfiguration(AutoConfigurations.of(LdapConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(LdapHealthIndicator.class));
|
.run(hasSingleHealthIndicator(LdapHealthIndicator.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notLdapHealthIndicator() throws Exception {
|
public void notLdapHealthIndicator() throws Exception {
|
||||||
this.context.withConfiguration(AutoConfigurations.of(LdapConfiguration.class))
|
this.contextRunner
|
||||||
|
.withConfiguration(AutoConfigurations.of(LdapConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false",
|
.withPropertyValues("management.health.diskspace.enabled:false",
|
||||||
"management.health.ldap.enabled:false")
|
"management.health.ldap.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
||||||
|
|
@ -394,14 +400,16 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void neo4jHealthIndicator() throws Exception {
|
public void neo4jHealthIndicator() throws Exception {
|
||||||
this.context.withConfiguration(AutoConfigurations.of(Neo4jConfiguration.class))
|
this.contextRunner
|
||||||
|
.withConfiguration(AutoConfigurations.of(Neo4jConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(Neo4jHealthIndicator.class));
|
.run(hasSingleHealthIndicator(Neo4jHealthIndicator.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notNeo4jHealthIndicator() throws Exception {
|
public void notNeo4jHealthIndicator() throws Exception {
|
||||||
this.context.withConfiguration(AutoConfigurations.of(Neo4jConfiguration.class))
|
this.contextRunner
|
||||||
|
.withConfiguration(AutoConfigurations.of(Neo4jConfiguration.class))
|
||||||
.withPropertyValues("management.health.diskspace.enabled:false",
|
.withPropertyValues("management.health.diskspace.enabled:false",
|
||||||
"management.health.neo4j.enabled:false")
|
"management.health.neo4j.enabled:false")
|
||||||
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
.run(hasSingleHealthIndicator(ApplicationHealthIndicator.class));
|
||||||
|
|
@ -409,8 +417,8 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||||
|
|
||||||
private ContextConsumer<AssertableApplicationContext> hasSingleHealthIndicator(
|
private ContextConsumer<AssertableApplicationContext> hasSingleHealthIndicator(
|
||||||
Class<? extends HealthIndicator> type) {
|
Class<? extends HealthIndicator> type) {
|
||||||
return (loaded) -> {
|
return (context) -> {
|
||||||
assertThat(loaded).getBeans(HealthIndicator.class).hasSize(1)
|
assertThat(context).getBeans(HealthIndicator.class).hasSize(1)
|
||||||
.hasValueSatisfying(new Condition<>(
|
.hasValueSatisfying(new Condition<>(
|
||||||
(indicator) -> indicator.getClass().equals(type),
|
(indicator) -> indicator.getClass().equals(type),
|
||||||
"Wrong indicator type"));
|
"Wrong indicator type"));
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.autoconfigure.cache.support.MockCachingProvider;
|
import org.springframework.boot.autoconfigure.cache.support.MockCachingProvider;
|
||||||
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
|
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
import org.springframework.boot.test.context.AssertableApplicationContext;
|
import org.springframework.boot.test.context.AssertableApplicationContext;
|
||||||
import org.springframework.boot.test.context.ContextConsumer;
|
import org.springframework.boot.test.context.ContextConsumer;
|
||||||
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
|
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
|
||||||
|
|
@ -100,58 +100,59 @@ public class CacheAutoConfigurationTests {
|
||||||
@Rule
|
@Rule
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
private final ApplicationContextTester context = new ApplicationContextTester()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(CacheAutoConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(CacheAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noEnableCaching() {
|
public void noEnableCaching() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class).run((loaded) -> {
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
assertThat(loaded).doesNotHaveBean(CacheManager.class);
|
.run((context) -> {
|
||||||
|
assertThat(context).doesNotHaveBean(CacheManager.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheManagerBackOff() {
|
public void cacheManagerBackOff() {
|
||||||
this.context.withUserConfiguration(CustomCacheManagerConfiguration.class)
|
this.contextRunner.withUserConfiguration(CustomCacheManagerConfiguration.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(getCacheManager(loaded, ConcurrentMapCacheManager.class)
|
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
|
||||||
.getCacheNames()).containsOnly("custom1");
|
.getCacheNames()).containsOnly("custom1");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheManagerFromSupportBackOff() {
|
public void cacheManagerFromSupportBackOff() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withUserConfiguration(CustomCacheManagerFromSupportConfiguration.class)
|
.withUserConfiguration(CustomCacheManagerFromSupportConfiguration.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(getCacheManager(loaded, ConcurrentMapCacheManager.class)
|
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
|
||||||
.getCacheNames()).containsOnly("custom1");
|
.getCacheNames()).containsOnly("custom1");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheResolverFromSupportBackOff() throws Exception {
|
public void cacheResolverFromSupportBackOff() throws Exception {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withUserConfiguration(CustomCacheResolverFromSupportConfiguration.class)
|
.withUserConfiguration(CustomCacheResolverFromSupportConfiguration.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).doesNotHaveBean(CacheManager.class);
|
assertThat(context).doesNotHaveBean(CacheManager.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customCacheResolverCanBeDefined() throws Exception {
|
public void customCacheResolverCanBeDefined() throws Exception {
|
||||||
this.context.withUserConfiguration(SpecificCacheResolverConfiguration.class)
|
this.contextRunner.withUserConfiguration(SpecificCacheResolverConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=simple").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=simple").run((context) -> {
|
||||||
getCacheManager(loaded, ConcurrentMapCacheManager.class);
|
getCacheManager(context, ConcurrentMapCacheManager.class);
|
||||||
assertThat(loaded).getBeans(CacheResolver.class).hasSize(1);
|
assertThat(context).getBeans(CacheResolver.class).hasSize(1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notSupportedCachingMode() {
|
public void notSupportedCachingMode() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=foobar").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=foobar").run((context) -> {
|
||||||
assertThat(loaded).getFailure()
|
assertThat(context).getFailure()
|
||||||
.isInstanceOf(BeanCreationException.class)
|
.isInstanceOf(BeanCreationException.class)
|
||||||
.hasMessageContaining(
|
.hasMessageContaining(
|
||||||
"Failed to bind properties under 'spring.cache.type'");
|
"Failed to bind properties under 'spring.cache.type'");
|
||||||
|
|
@ -160,28 +161,29 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void simpleCacheExplicit() {
|
public void simpleCacheExplicit() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=simple").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=simple").run((context) -> {
|
||||||
assertThat(getCacheManager(loaded, ConcurrentMapCacheManager.class)
|
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
|
||||||
.getCacheNames()).isEmpty();
|
.getCacheNames()).isEmpty();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void simpleCacheWithCustomizers() {
|
public void simpleCacheWithCustomizers() {
|
||||||
this.context.withUserConfiguration(DefaultCacheAndCustomizersConfiguration.class)
|
this.contextRunner
|
||||||
|
.withUserConfiguration(DefaultCacheAndCustomizersConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=" + "simple")
|
.withPropertyValues("spring.cache.type=" + "simple")
|
||||||
.run(dunno("allCacheManagerCustomizer", "simpleCacheManagerCustomizer"));
|
.run(dunno("allCacheManagerCustomizer", "simpleCacheManagerCustomizer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void simpleCacheExplicitWithCacheNames() {
|
public void simpleCacheExplicitWithCacheNames() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=simple",
|
.withPropertyValues("spring.cache.type=simple",
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
"spring.cache.cacheNames[1]=bar")
|
"spring.cache.cacheNames[1]=bar")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
ConcurrentMapCacheManager cacheManager = getCacheManager(loaded,
|
ConcurrentMapCacheManager cacheManager = getCacheManager(context,
|
||||||
ConcurrentMapCacheManager.class);
|
ConcurrentMapCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
||||||
});
|
});
|
||||||
|
|
@ -189,23 +191,23 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void genericCacheWithCaches() {
|
public void genericCacheWithCaches() {
|
||||||
this.context.withUserConfiguration(GenericCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(GenericCacheConfiguration.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
SimpleCacheManager cacheManager = getCacheManager(loaded,
|
SimpleCacheManager cacheManager = getCacheManager(context,
|
||||||
SimpleCacheManager.class);
|
SimpleCacheManager.class);
|
||||||
assertThat(cacheManager.getCache("first"))
|
assertThat(cacheManager.getCache("first"))
|
||||||
.isEqualTo(loaded.getBean("firstCache"));
|
.isEqualTo(context.getBean("firstCache"));
|
||||||
assertThat(cacheManager.getCache("second"))
|
assertThat(cacheManager.getCache("second"))
|
||||||
.isEqualTo(loaded.getBean("secondCache"));
|
.isEqualTo(context.getBean("secondCache"));
|
||||||
assertThat(cacheManager.getCacheNames()).hasSize(2);
|
assertThat(cacheManager.getCacheNames()).hasSize(2);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void genericCacheExplicit() {
|
public void genericCacheExplicit() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=generic").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=generic").run((context) -> {
|
||||||
assertThat(loaded).getFailure()
|
assertThat(context).getFailure()
|
||||||
.isInstanceOf(BeanCreationException.class)
|
.isInstanceOf(BeanCreationException.class)
|
||||||
.hasMessageContaining(
|
.hasMessageContaining(
|
||||||
"No cache manager could be auto-configured")
|
"No cache manager could be auto-configured")
|
||||||
|
|
@ -215,30 +217,31 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void genericCacheWithCustomizers() {
|
public void genericCacheWithCustomizers() {
|
||||||
this.context.withUserConfiguration(GenericCacheAndCustomizersConfiguration.class)
|
this.contextRunner
|
||||||
|
.withUserConfiguration(GenericCacheAndCustomizersConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=" + "generic")
|
.withPropertyValues("spring.cache.type=" + "generic")
|
||||||
.run(dunno("allCacheManagerCustomizer", "genericCacheManagerCustomizer"));
|
.run(dunno("allCacheManagerCustomizer", "genericCacheManagerCustomizer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void genericCacheExplicitWithCaches() {
|
public void genericCacheExplicitWithCaches() {
|
||||||
this.context.withUserConfiguration(GenericCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(GenericCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=generic").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=generic").run((context) -> {
|
||||||
SimpleCacheManager cacheManager = getCacheManager(loaded,
|
SimpleCacheManager cacheManager = getCacheManager(context,
|
||||||
SimpleCacheManager.class);
|
SimpleCacheManager.class);
|
||||||
assertThat(cacheManager.getCache("first"))
|
assertThat(cacheManager.getCache("first"))
|
||||||
.isEqualTo(loaded.getBean("firstCache"));
|
.isEqualTo(context.getBean("firstCache"));
|
||||||
assertThat(cacheManager.getCache("second"))
|
assertThat(cacheManager.getCache("second"))
|
||||||
.isEqualTo(loaded.getBean("secondCache"));
|
.isEqualTo(context.getBean("secondCache"));
|
||||||
assertThat(cacheManager.getCacheNames()).hasSize(2);
|
assertThat(cacheManager.getCacheNames()).hasSize(2);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void couchbaseCacheExplicit() {
|
public void couchbaseCacheExplicit() {
|
||||||
this.context.withUserConfiguration(CouchbaseCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(CouchbaseCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=couchbase").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=couchbase").run((context) -> {
|
||||||
CouchbaseCacheManager cacheManager = getCacheManager(loaded,
|
CouchbaseCacheManager cacheManager = getCacheManager(context,
|
||||||
CouchbaseCacheManager.class);
|
CouchbaseCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).isEmpty();
|
assertThat(cacheManager.getCacheNames()).isEmpty();
|
||||||
});
|
});
|
||||||
|
|
@ -246,7 +249,7 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void couchbaseCacheWithCustomizers() {
|
public void couchbaseCacheWithCustomizers() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withUserConfiguration(CouchbaseCacheAndCustomizersConfiguration.class)
|
.withUserConfiguration(CouchbaseCacheAndCustomizersConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=" + "couchbase").run(dunno(
|
.withPropertyValues("spring.cache.type=" + "couchbase").run(dunno(
|
||||||
"allCacheManagerCustomizer", "couchbaseCacheManagerCustomizer"));
|
"allCacheManagerCustomizer", "couchbaseCacheManagerCustomizer"));
|
||||||
|
|
@ -254,45 +257,45 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void couchbaseCacheExplicitWithCaches() {
|
public void couchbaseCacheExplicitWithCaches() {
|
||||||
this.context.withUserConfiguration(CouchbaseCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(CouchbaseCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=couchbase",
|
.withPropertyValues("spring.cache.type=couchbase",
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
"spring.cache.cacheNames[1]=bar")
|
"spring.cache.cacheNames[1]=bar")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
CouchbaseCacheManager cacheManager = getCacheManager(loaded,
|
CouchbaseCacheManager cacheManager = getCacheManager(context,
|
||||||
CouchbaseCacheManager.class);
|
CouchbaseCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
||||||
Cache cache = cacheManager.getCache("foo");
|
Cache cache = cacheManager.getCache("foo");
|
||||||
assertThat(cache).isInstanceOf(CouchbaseCache.class);
|
assertThat(cache).isInstanceOf(CouchbaseCache.class);
|
||||||
assertThat(((CouchbaseCache) cache).getTtl()).isEqualTo(0);
|
assertThat(((CouchbaseCache) cache).getTtl()).isEqualTo(0);
|
||||||
assertThat(((CouchbaseCache) cache).getNativeCache())
|
assertThat(((CouchbaseCache) cache).getNativeCache())
|
||||||
.isEqualTo(loaded.getBean("bucket"));
|
.isEqualTo(context.getBean("bucket"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void couchbaseCacheExplicitWithTtl() {
|
public void couchbaseCacheExplicitWithTtl() {
|
||||||
this.context.withUserConfiguration(CouchbaseCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(CouchbaseCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=couchbase",
|
.withPropertyValues("spring.cache.type=couchbase",
|
||||||
"spring.cache.cacheNames=foo,bar",
|
"spring.cache.cacheNames=foo,bar",
|
||||||
"spring.cache.couchbase.expiration=2000")
|
"spring.cache.couchbase.expiration=2000")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
CouchbaseCacheManager cacheManager = getCacheManager(loaded,
|
CouchbaseCacheManager cacheManager = getCacheManager(context,
|
||||||
CouchbaseCacheManager.class);
|
CouchbaseCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
||||||
Cache cache = cacheManager.getCache("foo");
|
Cache cache = cacheManager.getCache("foo");
|
||||||
assertThat(cache).isInstanceOf(CouchbaseCache.class);
|
assertThat(cache).isInstanceOf(CouchbaseCache.class);
|
||||||
assertThat(((CouchbaseCache) cache).getTtl()).isEqualTo(2);
|
assertThat(((CouchbaseCache) cache).getTtl()).isEqualTo(2);
|
||||||
assertThat(((CouchbaseCache) cache).getNativeCache())
|
assertThat(((CouchbaseCache) cache).getNativeCache())
|
||||||
.isEqualTo(loaded.getBean("bucket"));
|
.isEqualTo(context.getBean("bucket"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void redisCacheExplicit() {
|
public void redisCacheExplicit() {
|
||||||
this.context.withUserConfiguration(RedisCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(RedisCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=redis").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=redis").run((context) -> {
|
||||||
RedisCacheManager cacheManager = getCacheManager(loaded,
|
RedisCacheManager cacheManager = getCacheManager(context,
|
||||||
RedisCacheManager.class);
|
RedisCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).isEmpty();
|
assertThat(cacheManager.getCacheNames()).isEmpty();
|
||||||
assertThat(
|
assertThat(
|
||||||
|
|
@ -304,19 +307,20 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void redisCacheWithCustomizers() {
|
public void redisCacheWithCustomizers() {
|
||||||
this.context.withUserConfiguration(RedisCacheAndCustomizersConfiguration.class)
|
this.contextRunner
|
||||||
|
.withUserConfiguration(RedisCacheAndCustomizersConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=" + "redis")
|
.withPropertyValues("spring.cache.type=" + "redis")
|
||||||
.run(dunno("allCacheManagerCustomizer", "redisCacheManagerCustomizer"));
|
.run(dunno("allCacheManagerCustomizer", "redisCacheManagerCustomizer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void redisCacheExplicitWithCaches() {
|
public void redisCacheExplicitWithCaches() {
|
||||||
this.context.withUserConfiguration(RedisCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(RedisCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=redis",
|
.withPropertyValues("spring.cache.type=redis",
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
"spring.cache.cacheNames[1]=bar")
|
"spring.cache.cacheNames[1]=bar")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
RedisCacheManager cacheManager = getCacheManager(loaded,
|
RedisCacheManager cacheManager = getCacheManager(context,
|
||||||
RedisCacheManager.class);
|
RedisCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
||||||
});
|
});
|
||||||
|
|
@ -324,9 +328,9 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noOpCacheExplicit() {
|
public void noOpCacheExplicit() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=none").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=none").run((context) -> {
|
||||||
NoOpCacheManager cacheManager = getCacheManager(loaded,
|
NoOpCacheManager cacheManager = getCacheManager(context,
|
||||||
NoOpCacheManager.class);
|
NoOpCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).isEmpty();
|
assertThat(cacheManager.getCacheNames()).isEmpty();
|
||||||
});
|
});
|
||||||
|
|
@ -334,9 +338,9 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jCacheCacheNoProviderExplicit() {
|
public void jCacheCacheNoProviderExplicit() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=jcache").run((context) -> {
|
||||||
assertThat(loaded).getFailure()
|
assertThat(context).getFailure()
|
||||||
.isInstanceOf(BeanCreationException.class)
|
.isInstanceOf(BeanCreationException.class)
|
||||||
.hasMessageContaining(
|
.hasMessageContaining(
|
||||||
"No cache manager could be auto-configured")
|
"No cache manager could be auto-configured")
|
||||||
|
|
@ -347,14 +351,14 @@ public class CacheAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void jCacheCacheWithProvider() {
|
public void jCacheCacheWithProvider() {
|
||||||
String cachingProviderFqn = MockCachingProvider.class.getName();
|
String cachingProviderFqn = MockCachingProvider.class.getName();
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderFqn)
|
"spring.cache.jcache.provider=" + cachingProviderFqn)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JCacheCacheManager cacheManager = getCacheManager(loaded,
|
JCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
JCacheCacheManager.class);
|
JCacheCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).isEmpty();
|
assertThat(cacheManager.getCacheNames()).isEmpty();
|
||||||
assertThat(loaded.getBean(javax.cache.CacheManager.class))
|
assertThat(context.getBean(javax.cache.CacheManager.class))
|
||||||
.isEqualTo(cacheManager.getCacheManager());
|
.isEqualTo(cacheManager.getCacheManager());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -362,13 +366,13 @@ public class CacheAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void jCacheCacheWithCaches() {
|
public void jCacheCacheWithCaches() {
|
||||||
String cachingProviderFqn = MockCachingProvider.class.getName();
|
String cachingProviderFqn = MockCachingProvider.class.getName();
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
"spring.cache.cacheNames[1]=bar")
|
"spring.cache.cacheNames[1]=bar")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JCacheCacheManager cacheManager = getCacheManager(loaded,
|
JCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
JCacheCacheManager.class);
|
JCacheCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
||||||
});
|
});
|
||||||
|
|
@ -377,16 +381,16 @@ public class CacheAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void jCacheCacheWithCachesAndCustomConfig() {
|
public void jCacheCacheWithCachesAndCustomConfig() {
|
||||||
String cachingProviderFqn = MockCachingProvider.class.getName();
|
String cachingProviderFqn = MockCachingProvider.class.getName();
|
||||||
this.context.withUserConfiguration(JCacheCustomConfiguration.class)
|
this.contextRunner.withUserConfiguration(JCacheCustomConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
||||||
"spring.cache.cacheNames[0]=one",
|
"spring.cache.cacheNames[0]=one",
|
||||||
"spring.cache.cacheNames[1]=two")
|
"spring.cache.cacheNames[1]=two")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JCacheCacheManager cacheManager = getCacheManager(loaded,
|
JCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
JCacheCacheManager.class);
|
JCacheCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).containsOnly("one", "two");
|
assertThat(cacheManager.getCacheNames()).containsOnly("one", "two");
|
||||||
CompleteConfiguration<?, ?> defaultCacheConfiguration = loaded
|
CompleteConfiguration<?, ?> defaultCacheConfiguration = context
|
||||||
.getBean(CompleteConfiguration.class);
|
.getBean(CompleteConfiguration.class);
|
||||||
verify(cacheManager.getCacheManager()).createCache("one",
|
verify(cacheManager.getCacheManager()).createCache("one",
|
||||||
defaultCacheConfiguration);
|
defaultCacheConfiguration);
|
||||||
|
|
@ -397,23 +401,23 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jCacheCacheWithExistingJCacheManager() {
|
public void jCacheCacheWithExistingJCacheManager() {
|
||||||
this.context.withUserConfiguration(JCacheCustomCacheManager.class)
|
this.contextRunner.withUserConfiguration(JCacheCustomCacheManager.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=jcache").run((context) -> {
|
||||||
JCacheCacheManager cacheManager = getCacheManager(loaded,
|
JCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
JCacheCacheManager.class);
|
JCacheCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheManager())
|
assertThat(cacheManager.getCacheManager())
|
||||||
.isEqualTo(loaded.getBean("customJCacheCacheManager"));
|
.isEqualTo(context.getBean("customJCacheCacheManager"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jCacheCacheWithUnknownProvider() {
|
public void jCacheCacheWithUnknownProvider() {
|
||||||
String wrongCachingProviderClassName = "org.acme.FooBar";
|
String wrongCachingProviderClassName = "org.acme.FooBar";
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + wrongCachingProviderClassName)
|
"spring.cache.jcache.provider=" + wrongCachingProviderClassName)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getFailure()
|
assertThat(context).getFailure()
|
||||||
.isInstanceOf(BeanCreationException.class)
|
.isInstanceOf(BeanCreationException.class)
|
||||||
.hasMessageContaining(wrongCachingProviderClassName);
|
.hasMessageContaining(wrongCachingProviderClassName);
|
||||||
});
|
});
|
||||||
|
|
@ -423,12 +427,12 @@ public class CacheAutoConfigurationTests {
|
||||||
public void jCacheCacheWithConfig() {
|
public void jCacheCacheWithConfig() {
|
||||||
String cachingProviderFqn = MockCachingProvider.class.getName();
|
String cachingProviderFqn = MockCachingProvider.class.getName();
|
||||||
String configLocation = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml";
|
String configLocation = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml";
|
||||||
this.context.withUserConfiguration(JCacheCustomConfiguration.class)
|
this.contextRunner.withUserConfiguration(JCacheCustomConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
||||||
"spring.cache.jcache.config=" + configLocation)
|
"spring.cache.jcache.config=" + configLocation)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JCacheCacheManager cacheManager = getCacheManager(loaded,
|
JCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
JCacheCacheManager.class);
|
JCacheCacheManager.class);
|
||||||
Resource configResource = new ClassPathResource(configLocation);
|
Resource configResource = new ClassPathResource(configLocation);
|
||||||
assertThat(cacheManager.getCacheManager().getURI())
|
assertThat(cacheManager.getCacheManager().getURI())
|
||||||
|
|
@ -440,12 +444,12 @@ public class CacheAutoConfigurationTests {
|
||||||
public void jCacheCacheWithWrongConfig() {
|
public void jCacheCacheWithWrongConfig() {
|
||||||
String cachingProviderFqn = MockCachingProvider.class.getName();
|
String cachingProviderFqn = MockCachingProvider.class.getName();
|
||||||
String configLocation = "org/springframework/boot/autoconfigure/cache/does-not-exist.xml";
|
String configLocation = "org/springframework/boot/autoconfigure/cache/does-not-exist.xml";
|
||||||
this.context.withUserConfiguration(JCacheCustomConfiguration.class)
|
this.contextRunner.withUserConfiguration(JCacheCustomConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
||||||
"spring.cache.jcache.config=" + configLocation)
|
"spring.cache.jcache.config=" + configLocation)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getFailure()
|
assertThat(context).getFailure()
|
||||||
.isInstanceOf(BeanCreationException.class)
|
.isInstanceOf(BeanCreationException.class)
|
||||||
.hasMessageContaining("does not exist")
|
.hasMessageContaining("does not exist")
|
||||||
.hasMessageContaining(configLocation);
|
.hasMessageContaining(configLocation);
|
||||||
|
|
@ -454,31 +458,32 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ehcacheCacheWithCaches() {
|
public void ehcacheCacheWithCaches() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=ehcache").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=ehcache").run((context) -> {
|
||||||
EhCacheCacheManager cacheManager = getCacheManager(loaded,
|
EhCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
EhCacheCacheManager.class);
|
EhCacheCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).containsOnly("cacheTest1",
|
assertThat(cacheManager.getCacheNames()).containsOnly("cacheTest1",
|
||||||
"cacheTest2");
|
"cacheTest2");
|
||||||
assertThat(loaded.getBean(net.sf.ehcache.CacheManager.class))
|
assertThat(context.getBean(net.sf.ehcache.CacheManager.class))
|
||||||
.isEqualTo(cacheManager.getCacheManager());
|
.isEqualTo(cacheManager.getCacheManager());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ehcacheCacheWithCustomizers() {
|
public void ehcacheCacheWithCustomizers() {
|
||||||
this.context.withUserConfiguration(DefaultCacheAndCustomizersConfiguration.class)
|
this.contextRunner
|
||||||
|
.withUserConfiguration(DefaultCacheAndCustomizersConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=" + "ehcache")
|
.withPropertyValues("spring.cache.type=" + "ehcache")
|
||||||
.run(dunno("allCacheManagerCustomizer", "ehcacheCacheManagerCustomizer"));
|
.run(dunno("allCacheManagerCustomizer", "ehcacheCacheManagerCustomizer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ehcacheCacheWithConfig() {
|
public void ehcacheCacheWithConfig() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=ehcache",
|
.withPropertyValues("spring.cache.type=ehcache",
|
||||||
"spring.cache.ehcache.config=cache/ehcache-override.xml")
|
"spring.cache.ehcache.config=cache/ehcache-override.xml")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
EhCacheCacheManager cacheManager = getCacheManager(loaded,
|
EhCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
EhCacheCacheManager.class);
|
EhCacheCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames())
|
assertThat(cacheManager.getCacheNames())
|
||||||
.containsOnly("cacheOverrideTest1", "cacheOverrideTest2");
|
.containsOnly("cacheOverrideTest1", "cacheOverrideTest2");
|
||||||
|
|
@ -487,25 +492,25 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ehcacheCacheWithExistingCacheManager() {
|
public void ehcacheCacheWithExistingCacheManager() {
|
||||||
this.context.withUserConfiguration(EhCacheCustomCacheManager.class)
|
this.contextRunner.withUserConfiguration(EhCacheCustomCacheManager.class)
|
||||||
.withPropertyValues("spring.cache.type=ehcache").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=ehcache").run((context) -> {
|
||||||
EhCacheCacheManager cacheManager = getCacheManager(loaded,
|
EhCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
EhCacheCacheManager.class);
|
EhCacheCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheManager())
|
assertThat(cacheManager.getCacheManager())
|
||||||
.isEqualTo(loaded.getBean("customEhCacheCacheManager"));
|
.isEqualTo(context.getBean("customEhCacheCacheManager"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ehcache3AsJCacheWithCaches() {
|
public void ehcache3AsJCacheWithCaches() {
|
||||||
String cachingProviderFqn = EhcacheCachingProvider.class.getName();
|
String cachingProviderFqn = EhcacheCachingProvider.class.getName();
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
"spring.cache.cacheNames[1]=bar")
|
"spring.cache.cacheNames[1]=bar")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JCacheCacheManager cacheManager = getCacheManager(loaded,
|
JCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
JCacheCacheManager.class);
|
JCacheCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
||||||
});
|
});
|
||||||
|
|
@ -515,12 +520,12 @@ public class CacheAutoConfigurationTests {
|
||||||
public void ehcache3AsJCacheWithConfig() throws IOException {
|
public void ehcache3AsJCacheWithConfig() throws IOException {
|
||||||
String cachingProviderFqn = EhcacheCachingProvider.class.getName();
|
String cachingProviderFqn = EhcacheCachingProvider.class.getName();
|
||||||
String configLocation = "ehcache3.xml";
|
String configLocation = "ehcache3.xml";
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
||||||
"spring.cache.jcache.config=" + configLocation)
|
"spring.cache.jcache.config=" + configLocation)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JCacheCacheManager cacheManager = getCacheManager(loaded,
|
JCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
JCacheCacheManager.class);
|
JCacheCacheManager.class);
|
||||||
|
|
||||||
Resource configResource = new ClassPathResource(configLocation);
|
Resource configResource = new ClassPathResource(configLocation);
|
||||||
|
|
@ -532,25 +537,25 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hazelcastCacheExplicit() {
|
public void hazelcastCacheExplicit() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(HazelcastAutoConfiguration.class))
|
AutoConfigurations.of(HazelcastAutoConfiguration.class))
|
||||||
.withUserConfiguration(DefaultCacheConfiguration.class)
|
.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=hazelcast").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=hazelcast").run((context) -> {
|
||||||
HazelcastCacheManager cacheManager = getCacheManager(loaded,
|
HazelcastCacheManager cacheManager = getCacheManager(context,
|
||||||
HazelcastCacheManager.class);
|
HazelcastCacheManager.class);
|
||||||
// NOTE: the hazelcast implementation knows about a cache in a lazy
|
// NOTE: the hazelcast implementation knows about a cache in a lazy
|
||||||
// manner.
|
// manner.
|
||||||
cacheManager.getCache("defaultCache");
|
cacheManager.getCache("defaultCache");
|
||||||
assertThat(cacheManager.getCacheNames()).containsOnly("defaultCache");
|
assertThat(cacheManager.getCacheNames()).containsOnly("defaultCache");
|
||||||
assertThat(loaded.getBean(HazelcastInstance.class))
|
assertThat(context.getBean(HazelcastInstance.class))
|
||||||
.isEqualTo(cacheManager.getHazelcastInstance());
|
.isEqualTo(cacheManager.getHazelcastInstance());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hazelcastCacheWithCustomizers() {
|
public void hazelcastCacheWithCustomizers() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withUserConfiguration(HazelcastCacheAndCustomizersConfiguration.class)
|
.withUserConfiguration(HazelcastCacheAndCustomizersConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=" + "hazelcast").run(dunno(
|
.withPropertyValues("spring.cache.type=" + "hazelcast").run(dunno(
|
||||||
"allCacheManagerCustomizer", "hazelcastCacheManagerCustomizer"));
|
"allCacheManagerCustomizer", "hazelcastCacheManagerCustomizer"));
|
||||||
|
|
@ -558,28 +563,28 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hazelcastCacheWithExistingHazelcastInstance() {
|
public void hazelcastCacheWithExistingHazelcastInstance() {
|
||||||
this.context.withUserConfiguration(HazelcastCustomHazelcastInstance.class)
|
this.contextRunner.withUserConfiguration(HazelcastCustomHazelcastInstance.class)
|
||||||
.withPropertyValues("spring.cache.type=hazelcast").run((loaded) -> {
|
.withPropertyValues("spring.cache.type=hazelcast").run((context) -> {
|
||||||
HazelcastCacheManager cacheManager = getCacheManager(loaded,
|
HazelcastCacheManager cacheManager = getCacheManager(context,
|
||||||
HazelcastCacheManager.class);
|
HazelcastCacheManager.class);
|
||||||
assertThat(cacheManager.getHazelcastInstance())
|
assertThat(cacheManager.getHazelcastInstance())
|
||||||
.isEqualTo(loaded.getBean("customHazelcastInstance"));
|
.isEqualTo(context.getBean("customHazelcastInstance"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hazelcastCacheWithHazelcastAutoConfiguration() throws IOException {
|
public void hazelcastCacheWithHazelcastAutoConfiguration() throws IOException {
|
||||||
String hazelcastConfig = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml";
|
String hazelcastConfig = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml";
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(HazelcastAutoConfiguration.class))
|
AutoConfigurations.of(HazelcastAutoConfiguration.class))
|
||||||
.withUserConfiguration(DefaultCacheConfiguration.class)
|
.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=hazelcast",
|
.withPropertyValues("spring.cache.type=hazelcast",
|
||||||
"spring.hazelcast.config=" + hazelcastConfig)
|
"spring.hazelcast.config=" + hazelcastConfig)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
HazelcastCacheManager cacheManager = getCacheManager(loaded,
|
HazelcastCacheManager cacheManager = getCacheManager(context,
|
||||||
HazelcastCacheManager.class);
|
HazelcastCacheManager.class);
|
||||||
HazelcastInstance hazelcastInstance = loaded
|
HazelcastInstance hazelcastInstance = context
|
||||||
.getBean(HazelcastInstance.class);
|
.getBean(HazelcastInstance.class);
|
||||||
assertThat(cacheManager.getHazelcastInstance())
|
assertThat(cacheManager.getHazelcastInstance())
|
||||||
.isSameAs(hazelcastInstance);
|
.isSameAs(hazelcastInstance);
|
||||||
|
|
@ -594,13 +599,13 @@ public class CacheAutoConfigurationTests {
|
||||||
public void hazelcastAsJCacheWithCaches() {
|
public void hazelcastAsJCacheWithCaches() {
|
||||||
String cachingProviderFqn = HazelcastCachingProvider.class.getName();
|
String cachingProviderFqn = HazelcastCachingProvider.class.getName();
|
||||||
try {
|
try {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
"spring.cache.cacheNames[1]=bar")
|
"spring.cache.cacheNames[1]=bar")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JCacheCacheManager cacheManager = getCacheManager(loaded,
|
JCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
JCacheCacheManager.class);
|
JCacheCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).containsOnly("foo",
|
assertThat(cacheManager.getCacheNames()).containsOnly("foo",
|
||||||
"bar");
|
"bar");
|
||||||
|
|
@ -617,12 +622,12 @@ public class CacheAutoConfigurationTests {
|
||||||
String cachingProviderFqn = HazelcastCachingProvider.class.getName();
|
String cachingProviderFqn = HazelcastCachingProvider.class.getName();
|
||||||
try {
|
try {
|
||||||
String configLocation = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml";
|
String configLocation = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml";
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
||||||
"spring.cache.jcache.config=" + configLocation)
|
"spring.cache.jcache.config=" + configLocation)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JCacheCacheManager cacheManager = getCacheManager(loaded,
|
JCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
JCacheCacheManager.class);
|
JCacheCacheManager.class);
|
||||||
Resource configResource = new ClassPathResource(configLocation);
|
Resource configResource = new ClassPathResource(configLocation);
|
||||||
assertThat(cacheManager.getCacheManager().getURI())
|
assertThat(cacheManager.getCacheManager().getURI())
|
||||||
|
|
@ -638,21 +643,22 @@ public class CacheAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void hazelcastAsJCacheWithExistingHazelcastInstance() throws IOException {
|
public void hazelcastAsJCacheWithExistingHazelcastInstance() throws IOException {
|
||||||
String cachingProviderFqn = HazelcastCachingProvider.class.getName();
|
String cachingProviderFqn = HazelcastCachingProvider.class.getName();
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(HazelcastAutoConfiguration.class))
|
AutoConfigurations.of(HazelcastAutoConfiguration.class))
|
||||||
.withUserConfiguration(DefaultCacheConfiguration.class)
|
.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderFqn)
|
"spring.cache.jcache.provider=" + cachingProviderFqn)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JCacheCacheManager cacheManager = getCacheManager(loaded,
|
JCacheCacheManager cacheManager = getCacheManager(context,
|
||||||
JCacheCacheManager.class);
|
JCacheCacheManager.class);
|
||||||
javax.cache.CacheManager jCacheManager = cacheManager
|
javax.cache.CacheManager jCacheManager = cacheManager
|
||||||
.getCacheManager();
|
.getCacheManager();
|
||||||
assertThat(jCacheManager).isInstanceOf(
|
assertThat(jCacheManager).isInstanceOf(
|
||||||
com.hazelcast.cache.HazelcastCacheManager.class);
|
com.hazelcast.cache.HazelcastCacheManager.class);
|
||||||
assertThat(loaded.getBeansOfType(HazelcastInstance.class)).hasSize(1);
|
assertThat(context.getBeansOfType(HazelcastInstance.class))
|
||||||
HazelcastInstance hazelcastInstance = loaded
|
.hasSize(1);
|
||||||
|
HazelcastInstance hazelcastInstance = context
|
||||||
.getBean(HazelcastInstance.class);
|
.getBean(HazelcastInstance.class);
|
||||||
assertThat(((com.hazelcast.cache.HazelcastCacheManager) jCacheManager)
|
assertThat(((com.hazelcast.cache.HazelcastCacheManager) jCacheManager)
|
||||||
.getHazelcastInstance()).isSameAs(hazelcastInstance);
|
.getHazelcastInstance()).isSameAs(hazelcastInstance);
|
||||||
|
|
@ -663,11 +669,11 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void infinispanCacheWithConfig() {
|
public void infinispanCacheWithConfig() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=infinispan",
|
.withPropertyValues("spring.cache.type=infinispan",
|
||||||
"spring.cache.infinispan.config=infinispan.xml")
|
"spring.cache.infinispan.config=infinispan.xml")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
SpringEmbeddedCacheManager cacheManager = getCacheManager(loaded,
|
SpringEmbeddedCacheManager cacheManager = getCacheManager(context,
|
||||||
SpringEmbeddedCacheManager.class);
|
SpringEmbeddedCacheManager.class);
|
||||||
assertThat(cacheManager.getCacheNames()).contains("foo", "bar");
|
assertThat(cacheManager.getCacheNames()).contains("foo", "bar");
|
||||||
});
|
});
|
||||||
|
|
@ -675,46 +681,47 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void infinispanCacheWithCustomizers() {
|
public void infinispanCacheWithCustomizers() {
|
||||||
this.context.withUserConfiguration(DefaultCacheAndCustomizersConfiguration.class)
|
this.contextRunner
|
||||||
|
.withUserConfiguration(DefaultCacheAndCustomizersConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=" + "infinispan").run(dunno(
|
.withPropertyValues("spring.cache.type=" + "infinispan").run(dunno(
|
||||||
"allCacheManagerCustomizer", "infinispanCacheManagerCustomizer"));
|
"allCacheManagerCustomizer", "infinispanCacheManagerCustomizer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void infinispanCacheWithCaches() {
|
public void infinispanCacheWithCaches() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=infinispan",
|
.withPropertyValues("spring.cache.type=infinispan",
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
"spring.cache.cacheNames[1]=bar")
|
"spring.cache.cacheNames[1]=bar")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(getCacheManager(loaded, SpringEmbeddedCacheManager.class)
|
assertThat(getCacheManager(context, SpringEmbeddedCacheManager.class)
|
||||||
.getCacheNames()).containsOnly("foo", "bar");
|
.getCacheNames()).containsOnly("foo", "bar");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void infinispanCacheWithCachesAndCustomConfig() {
|
public void infinispanCacheWithCachesAndCustomConfig() {
|
||||||
this.context.withUserConfiguration(InfinispanCustomConfiguration.class)
|
this.contextRunner.withUserConfiguration(InfinispanCustomConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=infinispan",
|
.withPropertyValues("spring.cache.type=infinispan",
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
"spring.cache.cacheNames[1]=bar")
|
"spring.cache.cacheNames[1]=bar")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(getCacheManager(loaded, SpringEmbeddedCacheManager.class)
|
assertThat(getCacheManager(context, SpringEmbeddedCacheManager.class)
|
||||||
.getCacheNames()).containsOnly("foo", "bar");
|
.getCacheNames()).containsOnly("foo", "bar");
|
||||||
verify(loaded.getBean(ConfigurationBuilder.class), times(2)).build();
|
verify(context.getBean(ConfigurationBuilder.class), times(2)).build();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void infinispanAsJCacheWithCaches() {
|
public void infinispanAsJCacheWithCaches() {
|
||||||
String cachingProviderClassName = JCachingProvider.class.getName();
|
String cachingProviderClassName = JCachingProvider.class.getName();
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderClassName,
|
"spring.cache.jcache.provider=" + cachingProviderClassName,
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
"spring.cache.cacheNames[1]=bar")
|
"spring.cache.cacheNames[1]=bar")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(getCacheManager(loaded, JCacheCacheManager.class)
|
assertThat(getCacheManager(context, JCacheCacheManager.class)
|
||||||
.getCacheNames()).containsOnly("foo", "bar");
|
.getCacheNames()).containsOnly("foo", "bar");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -723,13 +730,13 @@ public class CacheAutoConfigurationTests {
|
||||||
public void infinispanAsJCacheWithConfig() throws IOException {
|
public void infinispanAsJCacheWithConfig() throws IOException {
|
||||||
String cachingProviderClassName = JCachingProvider.class.getName();
|
String cachingProviderClassName = JCachingProvider.class.getName();
|
||||||
String configLocation = "infinispan.xml";
|
String configLocation = "infinispan.xml";
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderClassName,
|
"spring.cache.jcache.provider=" + cachingProviderClassName,
|
||||||
"spring.cache.jcache.config=" + configLocation)
|
"spring.cache.jcache.config=" + configLocation)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
Resource configResource = new ClassPathResource(configLocation);
|
Resource configResource = new ClassPathResource(configLocation);
|
||||||
assertThat(getCacheManager(loaded, JCacheCacheManager.class)
|
assertThat(getCacheManager(context, JCacheCacheManager.class)
|
||||||
.getCacheManager().getURI())
|
.getCacheManager().getURI())
|
||||||
.isEqualTo(configResource.getURI());
|
.isEqualTo(configResource.getURI());
|
||||||
});
|
});
|
||||||
|
|
@ -739,14 +746,15 @@ public class CacheAutoConfigurationTests {
|
||||||
public void jCacheCacheWithCachesAndCustomizer() {
|
public void jCacheCacheWithCachesAndCustomizer() {
|
||||||
String cachingProviderClassName = HazelcastCachingProvider.class.getName();
|
String cachingProviderClassName = HazelcastCachingProvider.class.getName();
|
||||||
try {
|
try {
|
||||||
this.context.withUserConfiguration(JCacheWithCustomizerConfiguration.class)
|
this.contextRunner
|
||||||
|
.withUserConfiguration(JCacheWithCustomizerConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=jcache",
|
.withPropertyValues("spring.cache.type=jcache",
|
||||||
"spring.cache.jcache.provider=" + cachingProviderClassName,
|
"spring.cache.jcache.provider=" + cachingProviderClassName,
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
"spring.cache.cacheNames[1]=bar")
|
"spring.cache.cacheNames[1]=bar")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
// see customizer
|
// see customizer
|
||||||
assertThat(getCacheManager(loaded, JCacheCacheManager.class)
|
assertThat(getCacheManager(context, JCacheCacheManager.class)
|
||||||
.getCacheNames()).containsOnly("foo", "custom1");
|
.getCacheNames()).containsOnly("foo", "custom1");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -757,11 +765,11 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void caffeineCacheWithExplicitCaches() {
|
public void caffeineCacheWithExplicitCaches() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=caffeine",
|
.withPropertyValues("spring.cache.type=caffeine",
|
||||||
"spring.cache.cacheNames=foo")
|
"spring.cache.cacheNames=foo")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
CaffeineCacheManager manager = getCacheManager(loaded,
|
CaffeineCacheManager manager = getCacheManager(context,
|
||||||
CaffeineCacheManager.class);
|
CaffeineCacheManager.class);
|
||||||
assertThat(manager.getCacheNames()).containsOnly("foo");
|
assertThat(manager.getCacheNames()).containsOnly("foo");
|
||||||
Cache foo = manager.getCache("foo");
|
Cache foo = manager.getCache("foo");
|
||||||
|
|
@ -774,14 +782,15 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void caffeineCacheWithCustomizers() {
|
public void caffeineCacheWithCustomizers() {
|
||||||
this.context.withUserConfiguration(DefaultCacheAndCustomizersConfiguration.class)
|
this.contextRunner
|
||||||
|
.withUserConfiguration(DefaultCacheAndCustomizersConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=" + "caffeine").run(dunno(
|
.withPropertyValues("spring.cache.type=" + "caffeine").run(dunno(
|
||||||
"allCacheManagerCustomizer", "caffeineCacheManagerCustomizer"));
|
"allCacheManagerCustomizer", "caffeineCacheManagerCustomizer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void caffeineCacheWithExplicitCacheBuilder() {
|
public void caffeineCacheWithExplicitCacheBuilder() {
|
||||||
this.context.withUserConfiguration(CaffeineCacheBuilderConfiguration.class)
|
this.contextRunner.withUserConfiguration(CaffeineCacheBuilderConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=caffeine",
|
.withPropertyValues("spring.cache.type=caffeine",
|
||||||
"spring.cache.cacheNames=foo,bar")
|
"spring.cache.cacheNames=foo,bar")
|
||||||
.run(this::validateCaffeineCacheWithStats);
|
.run(this::validateCaffeineCacheWithStats);
|
||||||
|
|
@ -789,7 +798,7 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void caffeineCacheExplicitWithSpec() {
|
public void caffeineCacheExplicitWithSpec() {
|
||||||
this.context.withUserConfiguration(CaffeineCacheSpecConfiguration.class)
|
this.contextRunner.withUserConfiguration(CaffeineCacheSpecConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=caffeine",
|
.withPropertyValues("spring.cache.type=caffeine",
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
"spring.cache.cacheNames[1]=bar")
|
"spring.cache.cacheNames[1]=bar")
|
||||||
|
|
@ -798,7 +807,7 @@ public class CacheAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void caffeineCacheExplicitWithSpecString() {
|
public void caffeineCacheExplicitWithSpecString() {
|
||||||
this.context.withUserConfiguration(DefaultCacheConfiguration.class)
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
||||||
.withPropertyValues("spring.cache.type=caffeine",
|
.withPropertyValues("spring.cache.type=caffeine",
|
||||||
"spring.cache.caffeine.spec=recordStats",
|
"spring.cache.caffeine.spec=recordStats",
|
||||||
"spring.cache.cacheNames[0]=foo",
|
"spring.cache.cacheNames[0]=foo",
|
||||||
|
|
@ -819,11 +828,11 @@ public class CacheAutoConfigurationTests {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
private ContextConsumer<AssertableApplicationContext> dunno(
|
private ContextConsumer<AssertableApplicationContext> dunno(
|
||||||
String... expectedCustomizerNames) {
|
String... expectedCustomizerNames) {
|
||||||
return (loaded) -> {
|
return (context) -> {
|
||||||
CacheManager cacheManager = getCacheManager(loaded, CacheManager.class);
|
CacheManager cacheManager = getCacheManager(context, CacheManager.class);
|
||||||
List<String> expected = new ArrayList<>(
|
List<String> expected = new ArrayList<>(
|
||||||
Arrays.asList(expectedCustomizerNames));
|
Arrays.asList(expectedCustomizerNames));
|
||||||
Map<String, CacheManagerTestCustomizer> customizer = loaded
|
Map<String, CacheManagerTestCustomizer> customizer = context
|
||||||
.getBeansOfType(CacheManagerTestCustomizer.class);
|
.getBeansOfType(CacheManagerTestCustomizer.class);
|
||||||
customizer.forEach((key, value) -> {
|
customizer.forEach((key, value) -> {
|
||||||
if (expected.contains(key)) {
|
if (expected.contains(key)) {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import org.springframework.boot.autoconfigure.data.neo4j.city.City;
|
||||||
import org.springframework.boot.autoconfigure.data.neo4j.country.Country;
|
import org.springframework.boot.autoconfigure.data.neo4j.country.Country;
|
||||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
|
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.WebApplicationContextTester;
|
import org.springframework.boot.test.context.WebApplicationContextRunner;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
@ -54,30 +54,31 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class Neo4jDataAutoConfigurationTests {
|
public class Neo4jDataAutoConfigurationTests {
|
||||||
|
|
||||||
private WebApplicationContextTester context = new WebApplicationContextTester()
|
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||||
.withUserConfiguration(TestConfiguration.class)
|
.withUserConfiguration(TestConfiguration.class)
|
||||||
.withConfiguration(AutoConfigurations.of(Neo4jDataAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(Neo4jDataAutoConfiguration.class,
|
||||||
TransactionAutoConfiguration.class));
|
TransactionAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultConfiguration() {
|
public void defaultConfiguration() {
|
||||||
this.context.withPropertyValues("spring.data.neo4j.uri=http://localhost:8989")
|
this.contextRunner
|
||||||
.run((loaded) -> {
|
.withPropertyValues("spring.data.neo4j.uri=http://localhost:8989")
|
||||||
assertThat(loaded)
|
.run((context) -> {
|
||||||
|
assertThat(context)
|
||||||
.hasSingleBean(org.neo4j.ogm.config.Configuration.class);
|
.hasSingleBean(org.neo4j.ogm.config.Configuration.class);
|
||||||
assertThat(loaded).hasSingleBean(SessionFactory.class);
|
assertThat(context).hasSingleBean(SessionFactory.class);
|
||||||
assertThat(loaded).hasSingleBean(Neo4jTransactionManager.class);
|
assertThat(context).hasSingleBean(Neo4jTransactionManager.class);
|
||||||
assertThat(loaded).hasSingleBean(OpenSessionInViewInterceptor.class);
|
assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customNeo4jTransactionManagerUsingProperties() {
|
public void customNeo4jTransactionManagerUsingProperties() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues("spring.transaction.default-timeout=30",
|
.withPropertyValues("spring.transaction.default-timeout=30",
|
||||||
"spring.transaction.rollback-on-commit-failure:true")
|
"spring.transaction.rollback-on-commit-failure:true")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
Neo4jTransactionManager transactionManager = loaded
|
Neo4jTransactionManager transactionManager = context
|
||||||
.getBean(Neo4jTransactionManager.class);
|
.getBean(Neo4jTransactionManager.class);
|
||||||
assertThat(transactionManager.getDefaultTimeout()).isEqualTo(30);
|
assertThat(transactionManager.getDefaultTimeout()).isEqualTo(30);
|
||||||
assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue();
|
assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue();
|
||||||
|
|
@ -86,19 +87,23 @@ public class Neo4jDataAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customSessionFactory() {
|
public void customSessionFactory() {
|
||||||
this.context.withUserConfiguration(CustomSessionFactory.class).run((loaded) -> {
|
this.contextRunner.withUserConfiguration(CustomSessionFactory.class)
|
||||||
assertThat(loaded).doesNotHaveBean(org.neo4j.ogm.config.Configuration.class);
|
.run((context) -> {
|
||||||
assertThat(loaded).hasSingleBean(SessionFactory.class);
|
assertThat(context)
|
||||||
|
.doesNotHaveBean(org.neo4j.ogm.config.Configuration.class);
|
||||||
|
assertThat(context).hasSingleBean(SessionFactory.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customConfiguration() {
|
public void customConfiguration() {
|
||||||
this.context.withUserConfiguration(CustomConfiguration.class).run((loaded) -> {
|
this.contextRunner.withUserConfiguration(CustomConfiguration.class)
|
||||||
assertThat(loaded.getBean(org.neo4j.ogm.config.Configuration.class))
|
.run((context) -> {
|
||||||
.isSameAs(loaded.getBean("myConfiguration"));
|
assertThat(context.getBean(org.neo4j.ogm.config.Configuration.class))
|
||||||
assertThat(loaded).hasSingleBean(SessionFactory.class);
|
.isSameAs(context.getBean("myConfiguration"));
|
||||||
assertThat(loaded).hasSingleBean(org.neo4j.ogm.config.Configuration.class);
|
assertThat(context).hasSingleBean(SessionFactory.class);
|
||||||
|
assertThat(context)
|
||||||
|
.hasSingleBean(org.neo4j.ogm.config.Configuration.class);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -122,21 +127,21 @@ public class Neo4jDataAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void openSessionInViewInterceptorCanBeDisabled() {
|
public void openSessionInViewInterceptorCanBeDisabled() {
|
||||||
this.context.withPropertyValues("spring.data.neo4j.open-in-view:false")
|
this.contextRunner.withPropertyValues("spring.data.neo4j.open-in-view:false")
|
||||||
.run((loaded) -> assertThat(loaded)
|
.run((context) -> assertThat(context)
|
||||||
.doesNotHaveBean(OpenSessionInViewInterceptor.class));
|
.doesNotHaveBean(OpenSessionInViewInterceptor.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void eventListenersAreAutoRegistered() {
|
public void eventListenersAreAutoRegistered() {
|
||||||
this.context.withUserConfiguration(EventListenerConfiguration.class)
|
this.contextRunner.withUserConfiguration(EventListenerConfiguration.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
Session session = loaded.getBean(SessionFactory.class).openSession();
|
Session session = context.getBean(SessionFactory.class).openSession();
|
||||||
session.notifyListeners(
|
session.notifyListeners(
|
||||||
new PersistenceEvent(null, Event.TYPE.PRE_SAVE));
|
new PersistenceEvent(null, Event.TYPE.PRE_SAVE));
|
||||||
verify(loaded.getBean("eventListenerOne", EventListener.class))
|
verify(context.getBean("eventListenerOne", EventListener.class))
|
||||||
.onPreSave(any(Event.class));
|
.onPreSave(any(Event.class));
|
||||||
verify(loaded.getBean("eventListenerTwo", EventListener.class))
|
verify(context.getBean("eventListenerTwo", EventListener.class))
|
||||||
.onPreSave(any(Event.class));
|
.onPreSave(any(Event.class));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
|
@ -61,17 +61,17 @@ public class HazelcastAutoConfigurationClientTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ApplicationContextTester context = new ApplicationContextTester()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void systemProperty() throws IOException {
|
public void systemProperty() throws IOException {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY
|
.withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY
|
||||||
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/"
|
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/"
|
||||||
+ "hazelcast-client-specific.xml")
|
+ "hazelcast-client-specific.xml")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getBean(HazelcastInstance.class)
|
assertThat(context).getBean(HazelcastInstance.class)
|
||||||
.isInstanceOf(HazelcastInstance.class)
|
.isInstanceOf(HazelcastInstance.class)
|
||||||
.has(nameStartingWith("hz.client_"));
|
.has(nameStartingWith("hz.client_"));
|
||||||
});
|
});
|
||||||
|
|
@ -79,12 +79,12 @@ public class HazelcastAutoConfigurationClientTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void explicitConfigFile() throws IOException {
|
public void explicitConfigFile() throws IOException {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.hazelcast.config=org/springframework/boot/autoconfigure/"
|
"spring.hazelcast.config=org/springframework/boot/autoconfigure/"
|
||||||
+ "hazelcast/hazelcast-client-specific.xml")
|
+ "hazelcast/hazelcast-client-specific.xml")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getBean(HazelcastInstance.class)
|
assertThat(context).getBean(HazelcastInstance.class)
|
||||||
.isInstanceOf(HazelcastClientProxy.class)
|
.isInstanceOf(HazelcastClientProxy.class)
|
||||||
.has(nameStartingWith("hz.client_"));
|
.has(nameStartingWith("hz.client_"));
|
||||||
});
|
});
|
||||||
|
|
@ -92,11 +92,11 @@ public class HazelcastAutoConfigurationClientTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void explicitConfigUrl() throws IOException {
|
public void explicitConfigUrl() throws IOException {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.hazelcast.config=hazelcast-client-default.xml")
|
"spring.hazelcast.config=hazelcast-client-default.xml")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getBean(HazelcastInstance.class)
|
assertThat(context).getBean(HazelcastInstance.class)
|
||||||
.isInstanceOf(HazelcastClientProxy.class)
|
.isInstanceOf(HazelcastClientProxy.class)
|
||||||
.has(nameStartingWith("hz.client_"));
|
.has(nameStartingWith("hz.client_"));
|
||||||
});
|
});
|
||||||
|
|
@ -104,9 +104,10 @@ public class HazelcastAutoConfigurationClientTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unknownConfigFile() {
|
public void unknownConfigFile() {
|
||||||
this.context.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
|
this.contextRunner
|
||||||
.run((loaded) -> {
|
.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
|
||||||
assertThat(loaded).getFailure()
|
.run((context) -> {
|
||||||
|
assertThat(context).getFailure()
|
||||||
.isInstanceOf(BeanCreationException.class)
|
.isInstanceOf(BeanCreationException.class)
|
||||||
.hasMessageContaining("foo/bar/unknown.xml");
|
.hasMessageContaining("foo/bar/unknown.xml");
|
||||||
});
|
});
|
||||||
|
|
@ -114,10 +115,10 @@ public class HazelcastAutoConfigurationClientTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clientConfigTakesPrecedence() {
|
public void clientConfigTakesPrecedence() {
|
||||||
this.context.withUserConfiguration(HazelcastServerAndClientConfig.class)
|
this.contextRunner.withUserConfiguration(HazelcastServerAndClientConfig.class)
|
||||||
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
|
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getBean(HazelcastInstance.class)
|
assertThat(context).getBean(HazelcastInstance.class)
|
||||||
.isInstanceOf(HazelcastClientProxy.class);
|
.isInstanceOf(HazelcastClientProxy.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
|
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
|
||||||
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
|
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
@ -46,14 +46,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@ClassPathExclusions("hazelcast-client-*.jar")
|
@ClassPathExclusions("hazelcast-client-*.jar")
|
||||||
public class HazelcastAutoConfigurationServerTests {
|
public class HazelcastAutoConfigurationServerTests {
|
||||||
|
|
||||||
private final ApplicationContextTester context = new ApplicationContextTester()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultConfigFile() throws IOException {
|
public void defaultConfigFile() throws IOException {
|
||||||
// hazelcast.xml present in root classpath
|
// hazelcast.xml present in root classpath
|
||||||
this.context.run((loaded) -> {
|
this.contextRunner.run((context) -> {
|
||||||
Config config = loaded.getBean(HazelcastInstance.class).getConfig();
|
Config config = context.getBean(HazelcastInstance.class).getConfig();
|
||||||
assertThat(config.getConfigurationUrl())
|
assertThat(config.getConfigurationUrl())
|
||||||
.isEqualTo(new ClassPathResource("hazelcast.xml").getURL());
|
.isEqualTo(new ClassPathResource("hazelcast.xml").getURL());
|
||||||
});
|
});
|
||||||
|
|
@ -61,22 +61,22 @@ public class HazelcastAutoConfigurationServerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void systemProperty() throws IOException {
|
public void systemProperty() throws IOException {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withSystemProperties(HazelcastServerConfiguration.CONFIG_SYSTEM_PROPERTY
|
.withSystemProperties(HazelcastServerConfiguration.CONFIG_SYSTEM_PROPERTY
|
||||||
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml")
|
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
Config config = loaded.getBean(HazelcastInstance.class).getConfig();
|
Config config = context.getBean(HazelcastInstance.class).getConfig();
|
||||||
assertThat(config.getQueueConfigs().keySet()).containsOnly("foobar");
|
assertThat(config.getQueueConfigs().keySet()).containsOnly("foobar");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void explicitConfigFile() throws IOException {
|
public void explicitConfigFile() throws IOException {
|
||||||
this.context.withPropertyValues(
|
this.contextRunner.withPropertyValues(
|
||||||
"spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
|
"spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
|
||||||
+ "hazelcast-specific.xml")
|
+ "hazelcast-specific.xml")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
Config config = loaded.getBean(HazelcastInstance.class).getConfig();
|
Config config = context.getBean(HazelcastInstance.class).getConfig();
|
||||||
assertThat(config.getConfigurationFile())
|
assertThat(config.getConfigurationFile())
|
||||||
.isEqualTo(new ClassPathResource(
|
.isEqualTo(new ClassPathResource(
|
||||||
"org/springframework/boot/autoconfigure/hazelcast"
|
"org/springframework/boot/autoconfigure/hazelcast"
|
||||||
|
|
@ -86,9 +86,10 @@ public class HazelcastAutoConfigurationServerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void explicitConfigUrl() throws IOException {
|
public void explicitConfigUrl() throws IOException {
|
||||||
this.context.withPropertyValues("spring.hazelcast.config=hazelcast-default.xml")
|
this.contextRunner
|
||||||
.run((loaded) -> {
|
.withPropertyValues("spring.hazelcast.config=hazelcast-default.xml")
|
||||||
Config config = loaded.getBean(HazelcastInstance.class).getConfig();
|
.run((context) -> {
|
||||||
|
Config config = context.getBean(HazelcastInstance.class).getConfig();
|
||||||
assertThat(config.getConfigurationUrl()).isEqualTo(
|
assertThat(config.getConfigurationUrl()).isEqualTo(
|
||||||
new ClassPathResource("hazelcast-default.xml").getURL());
|
new ClassPathResource("hazelcast-default.xml").getURL());
|
||||||
});
|
});
|
||||||
|
|
@ -96,9 +97,10 @@ public class HazelcastAutoConfigurationServerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unknownConfigFile() {
|
public void unknownConfigFile() {
|
||||||
this.context.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
|
this.contextRunner
|
||||||
.run((loaded) -> {
|
.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
|
||||||
assertThat(loaded).getFailure()
|
.run((context) -> {
|
||||||
|
assertThat(context).getFailure()
|
||||||
.isInstanceOf(BeanCreationException.class)
|
.isInstanceOf(BeanCreationException.class)
|
||||||
.hasMessageContaining("foo/bar/unknown.xml");
|
.hasMessageContaining("foo/bar/unknown.xml");
|
||||||
});
|
});
|
||||||
|
|
@ -109,10 +111,10 @@ public class HazelcastAutoConfigurationServerTests {
|
||||||
Config config = new Config("my-test-instance");
|
Config config = new Config("my-test-instance");
|
||||||
HazelcastInstance existing = Hazelcast.newHazelcastInstance(config);
|
HazelcastInstance existing = Hazelcast.newHazelcastInstance(config);
|
||||||
try {
|
try {
|
||||||
this.context.withUserConfiguration(HazelcastConfigWithName.class)
|
this.contextRunner.withUserConfiguration(HazelcastConfigWithName.class)
|
||||||
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
|
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
|
||||||
.run(loaded -> {
|
.run((context) -> {
|
||||||
HazelcastInstance hazelcast = (loaded)
|
HazelcastInstance hazelcast = context
|
||||||
.getBean(HazelcastInstance.class);
|
.getBean(HazelcastInstance.class);
|
||||||
assertThat(hazelcast.getConfig().getInstanceName())
|
assertThat(hazelcast.getConfig().getInstanceName())
|
||||||
.isEqualTo("my-test-instance");
|
.isEqualTo("my-test-instance");
|
||||||
|
|
@ -127,10 +129,10 @@ public class HazelcastAutoConfigurationServerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void configInstanceWithoutName() {
|
public void configInstanceWithoutName() {
|
||||||
this.context.withUserConfiguration(HazelcastConfigNoName.class)
|
this.contextRunner.withUserConfiguration(HazelcastConfigNoName.class)
|
||||||
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
|
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
Config config = loaded.getBean(HazelcastInstance.class).getConfig();
|
Config config = context.getBean(HazelcastInstance.class).getConfig();
|
||||||
Map<String, QueueConfig> queueConfigs = config.getQueueConfigs();
|
Map<String, QueueConfig> queueConfigs = config.getQueueConfigs();
|
||||||
assertThat(queueConfigs.keySet()).containsOnly("another-queue");
|
assertThat(queueConfigs.keySet()).containsOnly("another-queue");
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import com.hazelcast.core.HazelcastInstance;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
@ -35,14 +35,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class HazelcastAutoConfigurationTests {
|
public class HazelcastAutoConfigurationTests {
|
||||||
|
|
||||||
private final ApplicationContextTester context = new ApplicationContextTester()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultConfigFile() throws IOException {
|
public void defaultConfigFile() throws IOException {
|
||||||
// no hazelcast-client.xml and hazelcast.xml is present in root classpath
|
// no hazelcast-client.xml and hazelcast.xml is present in root classpath
|
||||||
this.context.run((loaded) -> {
|
this.contextRunner.run((context) -> {
|
||||||
Config config = loaded.getBean(HazelcastInstance.class).getConfig();
|
Config config = context.getBean(HazelcastInstance.class).getConfig();
|
||||||
assertThat(config.getConfigurationUrl())
|
assertThat(config.getConfigurationUrl())
|
||||||
.isEqualTo(new ClassPathResource("hazelcast.xml").getURL());
|
.isEqualTo(new ClassPathResource("hazelcast.xml").getURL());
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import retrofit2.Retrofit;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
import org.springframework.boot.test.context.AssertableApplicationContext;
|
import org.springframework.boot.test.context.AssertableApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
@ -41,59 +41,60 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class InfluxDbAutoConfigurationTests {
|
public class InfluxDbAutoConfigurationTests {
|
||||||
|
|
||||||
private final ApplicationContextTester context = new ApplicationContextTester()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(InfluxDbAutoConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(InfluxDbAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void influxDbRequiresUrl() {
|
public void influxDbRequiresUrl() {
|
||||||
this.context.run(
|
this.contextRunner
|
||||||
(loaded) -> assertThat(loaded.getBeansOfType(InfluxDB.class)).isEmpty());
|
.run((context) -> assertThat(context.getBeansOfType(InfluxDB.class))
|
||||||
|
.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void influxDbCanBeCustomized() {
|
public void influxDbCanBeCustomized() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues("spring.influx.url=http://localhost",
|
.withPropertyValues("spring.influx.url=http://localhost",
|
||||||
"spring.influx.password:password", "spring.influx.user:user")
|
"spring.influx.password:password", "spring.influx.user:user")
|
||||||
.run((loaded -> assertThat(loaded.getBeansOfType(InfluxDB.class))
|
.run(((context) -> assertThat(context.getBeansOfType(InfluxDB.class))
|
||||||
.hasSize(1)));
|
.hasSize(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void influxDbCanBeCreatedWithoutCredentials() {
|
public void influxDbCanBeCreatedWithoutCredentials() {
|
||||||
this.context.withPropertyValues("spring.influx.url=http://localhost")
|
this.contextRunner.withPropertyValues("spring.influx.url=http://localhost")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded.getBeansOfType(InfluxDB.class)).hasSize(1);
|
assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
||||||
int readTimeout = getReadTimeoutProperty(loaded);
|
int readTimeout = getReadTimeoutProperty(context);
|
||||||
assertThat(readTimeout).isEqualTo(10_000);
|
assertThat(readTimeout).isEqualTo(10_000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void influxDbWithoutCredentialsAndOkHttpClientBuilder() {
|
public void influxDbWithoutCredentialsAndOkHttpClientBuilder() {
|
||||||
this.context.withUserConfiguration(CustomOkHttpClientBuilderConfig.class)
|
this.contextRunner.withUserConfiguration(CustomOkHttpClientBuilderConfig.class)
|
||||||
.withPropertyValues("spring.influx.url=http://localhost")
|
.withPropertyValues("spring.influx.url=http://localhost")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded.getBeansOfType(InfluxDB.class)).hasSize(1);
|
assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
||||||
int readTimeout = getReadTimeoutProperty(loaded);
|
int readTimeout = getReadTimeoutProperty(context);
|
||||||
assertThat(readTimeout).isEqualTo(30_000);
|
assertThat(readTimeout).isEqualTo(30_000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void influxDbWithOkHttpClientBuilder() {
|
public void influxDbWithOkHttpClientBuilder() {
|
||||||
this.context.withUserConfiguration(CustomOkHttpClientBuilderConfig.class)
|
this.contextRunner.withUserConfiguration(CustomOkHttpClientBuilderConfig.class)
|
||||||
.withPropertyValues("spring.influx.url=http://localhost",
|
.withPropertyValues("spring.influx.url=http://localhost",
|
||||||
"spring.influx.password:password", "spring.influx.user:user")
|
"spring.influx.password:password", "spring.influx.user:user")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded.getBeansOfType(InfluxDB.class)).hasSize(1);
|
assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
|
||||||
int readTimeout = getReadTimeoutProperty(loaded);
|
int readTimeout = getReadTimeoutProperty(context);
|
||||||
assertThat(readTimeout).isEqualTo(30_000);
|
assertThat(readTimeout).isEqualTo(30_000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getReadTimeoutProperty(AssertableApplicationContext loaded) {
|
private int getReadTimeoutProperty(AssertableApplicationContext context) {
|
||||||
InfluxDB influxDB = loaded.getBean(InfluxDB.class);
|
InfluxDB influxDB = context.getBean(InfluxDB.class);
|
||||||
Retrofit retrofit = (Retrofit) new DirectFieldAccessor(influxDB)
|
Retrofit retrofit = (Retrofit) new DirectFieldAccessor(influxDB)
|
||||||
.getPropertyValue("retrofit");
|
.getPropertyValue("retrofit");
|
||||||
OkHttpClient callFactory = (OkHttpClient) new DirectFieldAccessor(retrofit)
|
OkHttpClient callFactory = (OkHttpClient) new DirectFieldAccessor(retrofit)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.jdbc.DatabaseDriver;
|
import org.springframework.boot.jdbc.DatabaseDriver;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
import org.springframework.boot.test.context.AssertableApplicationContext;
|
import org.springframework.boot.test.context.AssertableApplicationContext;
|
||||||
import org.springframework.boot.test.context.HidePackagesClassLoader;
|
import org.springframework.boot.test.context.HidePackagesClassLoader;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
@ -58,7 +58,7 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class DataSourceAutoConfigurationTests {
|
public class DataSourceAutoConfigurationTests {
|
||||||
|
|
||||||
private final ApplicationContextTester context = new ApplicationContextTester()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class))
|
||||||
.withPropertyValues("spring.datasource.initialize=false",
|
.withPropertyValues("spring.datasource.initialize=false",
|
||||||
"spring.datasource.url:jdbc:hsqldb:mem:testdb-"
|
"spring.datasource.url:jdbc:hsqldb:mem:testdb-"
|
||||||
|
|
@ -66,13 +66,14 @@ public class DataSourceAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultDataSourceExists() throws Exception {
|
public void testDefaultDataSourceExists() throws Exception {
|
||||||
this.context.run((loaded) -> assertThat(loaded).hasSingleBean(DataSource.class));
|
this.contextRunner
|
||||||
|
.run((context) -> assertThat(context).hasSingleBean(DataSource.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDataSourceHasEmbeddedDefault() throws Exception {
|
public void testDataSourceHasEmbeddedDefault() throws Exception {
|
||||||
this.context.run((loaded) -> {
|
this.contextRunner.run((context) -> {
|
||||||
HikariDataSource dataSource = loaded.getBean(HikariDataSource.class);
|
HikariDataSource dataSource = context.getBean(HikariDataSource.class);
|
||||||
assertThat(dataSource.getJdbcUrl()).isNotNull();
|
assertThat(dataSource.getJdbcUrl()).isNotNull();
|
||||||
assertThat(dataSource.getDriverClassName()).isNotNull();
|
assertThat(dataSource.getDriverClassName()).isNotNull();
|
||||||
});
|
});
|
||||||
|
|
@ -82,10 +83,10 @@ public class DataSourceAutoConfigurationTests {
|
||||||
public void testBadUrl() throws Exception {
|
public void testBadUrl() throws Exception {
|
||||||
try {
|
try {
|
||||||
EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE;
|
EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE;
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues("spring.datasource.url:jdbc:not-going-to-work")
|
.withPropertyValues("spring.datasource.url:jdbc:not-going-to-work")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getFailure()
|
assertThat(context).getFailure()
|
||||||
.isInstanceOf(BeanCreationException.class);
|
.isInstanceOf(BeanCreationException.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -96,11 +97,11 @@ public class DataSourceAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBadDriverClass() throws Exception {
|
public void testBadDriverClass() throws Exception {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.datasource.driverClassName:org.none.jdbcDriver")
|
"spring.datasource.driverClassName:org.none.jdbcDriver")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getFailure()
|
assertThat(context).getFailure()
|
||||||
.isInstanceOf(BeanCreationException.class)
|
.isInstanceOf(BeanCreationException.class)
|
||||||
.hasMessageContaining("org.none.jdbcDriver");
|
.hasMessageContaining("org.none.jdbcDriver");
|
||||||
});
|
});
|
||||||
|
|
@ -153,10 +154,10 @@ public class DataSourceAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public void testEmbeddedTypeDefaultsUsername() throws Exception {
|
public void testEmbeddedTypeDefaultsUsername() throws Exception {
|
||||||
this.context.withPropertyValues(
|
this.contextRunner.withPropertyValues(
|
||||||
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
|
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
|
||||||
"spring.datasource.url:jdbc:hsqldb:mem:testdb").run((loaded) -> {
|
"spring.datasource.url:jdbc:hsqldb:mem:testdb").run((context) -> {
|
||||||
DataSource bean = loaded.getBean(DataSource.class);
|
DataSource bean = context.getBean(DataSource.class);
|
||||||
HikariDataSource pool = (HikariDataSource) bean;
|
HikariDataSource pool = (HikariDataSource) bean;
|
||||||
assertThat(pool.getDriverClassName())
|
assertThat(pool.getDriverClassName())
|
||||||
.isEqualTo("org.hsqldb.jdbcDriver");
|
.isEqualTo("org.hsqldb.jdbcDriver");
|
||||||
|
|
@ -170,7 +171,7 @@ public class DataSourceAutoConfigurationTests {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void explicitTypeNoSupportedDataSource() {
|
public void explicitTypeNoSupportedDataSource() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withClassLoader(new HidePackagesClassLoader("org.apache.tomcat",
|
.withClassLoader(new HidePackagesClassLoader("org.apache.tomcat",
|
||||||
"com.zaxxer.hikari", "org.apache.commons.dbcp",
|
"com.zaxxer.hikari", "org.apache.commons.dbcp",
|
||||||
"org.apache.commons.dbcp2"))
|
"org.apache.commons.dbcp2"))
|
||||||
|
|
@ -184,7 +185,7 @@ public class DataSourceAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void explicitTypeSupportedDataSource() {
|
public void explicitTypeSupportedDataSource() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
|
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
|
||||||
"spring.datasource.url:jdbc:hsqldb:mem:testdb",
|
"spring.datasource.url:jdbc:hsqldb:mem:testdb",
|
||||||
|
|
@ -193,19 +194,20 @@ public class DataSourceAutoConfigurationTests {
|
||||||
.run(this::containsOnlySimpleDriverDataSource);
|
.run(this::containsOnlySimpleDriverDataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void containsOnlySimpleDriverDataSource(AssertableApplicationContext loaded) {
|
private void containsOnlySimpleDriverDataSource(
|
||||||
assertThat(loaded).hasSingleBean(DataSource.class);
|
AssertableApplicationContext context) {
|
||||||
assertThat(loaded).getBean(DataSource.class)
|
assertThat(context).hasSingleBean(DataSource.class);
|
||||||
|
assertThat(context).getBean(DataSource.class)
|
||||||
.isExactlyInstanceOf(SimpleDriverDataSource.class);
|
.isExactlyInstanceOf(SimpleDriverDataSource.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitDriverClassClearsUsername() throws Exception {
|
public void testExplicitDriverClassClearsUsername() throws Exception {
|
||||||
this.context.withPropertyValues(
|
this.contextRunner.withPropertyValues(
|
||||||
"spring.datasource.driverClassName:" + DatabaseTestDriver.class.getName(),
|
"spring.datasource.driverClassName:" + DatabaseTestDriver.class.getName(),
|
||||||
"spring.datasource.url:jdbc:foo://localhost").run((loaded) -> {
|
"spring.datasource.url:jdbc:foo://localhost").run((context) -> {
|
||||||
assertThat(loaded).hasSingleBean(DataSource.class);
|
assertThat(context).hasSingleBean(DataSource.class);
|
||||||
HikariDataSource dataSource = loaded.getBean(HikariDataSource.class);
|
HikariDataSource dataSource = context.getBean(HikariDataSource.class);
|
||||||
assertThat(dataSource.getDriverClassName())
|
assertThat(dataSource.getDriverClassName())
|
||||||
.isEqualTo(DatabaseTestDriver.class.getName());
|
.isEqualTo(DatabaseTestDriver.class.getName());
|
||||||
assertThat(dataSource.getUsername()).isNull();
|
assertThat(dataSource.getUsername()).isNull();
|
||||||
|
|
@ -214,18 +216,19 @@ public class DataSourceAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultDataSourceCanBeOverridden() throws Exception {
|
public void testDefaultDataSourceCanBeOverridden() throws Exception {
|
||||||
this.context.withUserConfiguration(TestDataSourceConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getBean(DataSource.class)
|
assertThat(context).getBean(DataSource.class)
|
||||||
.isInstanceOf(BasicDataSource.class);
|
.isInstanceOf(BasicDataSource.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDataSourceIsInitializedEarly() {
|
public void testDataSourceIsInitializedEarly() {
|
||||||
this.context.withUserConfiguration(TestInitializedDataSourceConfiguration.class)
|
this.contextRunner
|
||||||
|
.withUserConfiguration(TestInitializedDataSourceConfiguration.class)
|
||||||
.withPropertyValues("spring.datasource.initialize=true")
|
.withPropertyValues("spring.datasource.initialize=true")
|
||||||
.run((loaded) -> assertThat(loaded
|
.run((context) -> assertThat(context
|
||||||
.getBean(TestInitializedDataSourceConfiguration.class).called)
|
.getBean(TestInitializedDataSourceConfiguration.class).called)
|
||||||
.isTrue());
|
.isTrue());
|
||||||
}
|
}
|
||||||
|
|
@ -234,8 +237,8 @@ public class DataSourceAutoConfigurationTests {
|
||||||
List<String> hiddenPackages, Consumer<T> consumer) {
|
List<String> hiddenPackages, Consumer<T> consumer) {
|
||||||
HidePackagesClassLoader classLoader = new HidePackagesClassLoader(
|
HidePackagesClassLoader classLoader = new HidePackagesClassLoader(
|
||||||
hiddenPackages.toArray(new String[hiddenPackages.size()]));
|
hiddenPackages.toArray(new String[hiddenPackages.size()]));
|
||||||
this.context.withClassLoader(classLoader).run((loaded) -> {
|
this.contextRunner.withClassLoader(classLoader).run((context) -> {
|
||||||
DataSource bean = loaded.getBean(DataSource.class);
|
DataSource bean = context.getBean(DataSource.class);
|
||||||
assertThat(bean).isInstanceOf(expectedType);
|
assertThat(bean).isInstanceOf(expectedType);
|
||||||
consumer.accept(expectedType.cast(bean));
|
consumer.accept(expectedType.cast(bean));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
import org.springframework.boot.test.context.AssertableApplicationContext;
|
import org.springframework.boot.test.context.AssertableApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
@ -63,13 +63,13 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
private static final String ACTIVEMQ_NETWORK_URL = "tcp://localhost:61616";
|
private static final String ACTIVEMQ_NETWORK_URL = "tcp://localhost:61616";
|
||||||
|
|
||||||
private final ApplicationContextTester context = new ApplicationContextTester()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(ActiveMQAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(ActiveMQAutoConfiguration.class,
|
||||||
JmsAutoConfiguration.class));
|
JmsAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultJmsConfiguration() {
|
public void testDefaultJmsConfiguration() {
|
||||||
this.context.withUserConfiguration(TestConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||||
.run(this::testDefaultJmsConfiguration);
|
.run(this::testDefaultJmsConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,29 +88,29 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectionFactoryBackOff() {
|
public void testConnectionFactoryBackOff() {
|
||||||
this.context.withUserConfiguration(TestConfiguration2.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration2.class)
|
||||||
.run((loaded) -> assertThat(
|
.run((context) -> assertThat(
|
||||||
loaded.getBean(ActiveMQConnectionFactory.class).getBrokerURL())
|
context.getBean(ActiveMQConnectionFactory.class).getBrokerURL())
|
||||||
.isEqualTo("foobar"));
|
.isEqualTo("foobar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJmsTemplateBackOff() {
|
public void testJmsTemplateBackOff() {
|
||||||
this.context.withUserConfiguration(TestConfiguration3.class).run(
|
this.contextRunner.withUserConfiguration(TestConfiguration3.class).run(
|
||||||
(loaded) -> assertThat(loaded.getBean(JmsTemplate.class).getPriority())
|
(context) -> assertThat(context.getBean(JmsTemplate.class).getPriority())
|
||||||
.isEqualTo(999));
|
.isEqualTo(999));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJmsMessagingTemplateBackOff() {
|
public void testJmsMessagingTemplateBackOff() {
|
||||||
this.context.withUserConfiguration(TestConfiguration5.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration5.class)
|
||||||
.run((loaded) -> assertThat(loaded.getBean(JmsMessagingTemplate.class)
|
.run((context) -> assertThat(context.getBean(JmsMessagingTemplate.class)
|
||||||
.getDefaultDestinationName()).isEqualTo("fooBar"));
|
.getDefaultDestinationName()).isEqualTo("fooBar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJmsTemplateBackOffEverything() {
|
public void testJmsTemplateBackOffEverything() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withUserConfiguration(TestConfiguration2.class, TestConfiguration3.class,
|
.withUserConfiguration(TestConfiguration2.class, TestConfiguration3.class,
|
||||||
TestConfiguration5.class)
|
TestConfiguration5.class)
|
||||||
.run(this::testJmsTemplateBackOffEverything);
|
.run(this::testJmsTemplateBackOffEverything);
|
||||||
|
|
@ -129,8 +129,8 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEnableJmsCreateDefaultContainerFactory() {
|
public void testEnableJmsCreateDefaultContainerFactory() {
|
||||||
this.context.withUserConfiguration(EnableJmsConfiguration.class)
|
this.contextRunner.withUserConfiguration(EnableJmsConfiguration.class)
|
||||||
.run((loaded) -> assertThat(loaded)
|
.run((context) -> assertThat(context)
|
||||||
.getBean("jmsListenerContainerFactory",
|
.getBean("jmsListenerContainerFactory",
|
||||||
JmsListenerContainerFactory.class)
|
JmsListenerContainerFactory.class)
|
||||||
.isExactlyInstanceOf(DefaultJmsListenerContainerFactory.class));
|
.isExactlyInstanceOf(DefaultJmsListenerContainerFactory.class));
|
||||||
|
|
@ -138,10 +138,10 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJmsListenerContainerFactoryBackOff() {
|
public void testJmsListenerContainerFactoryBackOff() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withUserConfiguration(TestConfiguration6.class,
|
.withUserConfiguration(TestConfiguration6.class,
|
||||||
EnableJmsConfiguration.class)
|
EnableJmsConfiguration.class)
|
||||||
.run((loaded) -> assertThat(loaded)
|
.run((context) -> assertThat(context)
|
||||||
.getBean("jmsListenerContainerFactory",
|
.getBean("jmsListenerContainerFactory",
|
||||||
JmsListenerContainerFactory.class)
|
JmsListenerContainerFactory.class)
|
||||||
.isExactlyInstanceOf(SimpleJmsListenerContainerFactory.class));
|
.isExactlyInstanceOf(SimpleJmsListenerContainerFactory.class));
|
||||||
|
|
@ -149,7 +149,7 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJmsListenerContainerFactoryWithCustomSettings() {
|
public void testJmsListenerContainerFactoryWithCustomSettings() {
|
||||||
this.context.withUserConfiguration(EnableJmsConfiguration.class)
|
this.contextRunner.withUserConfiguration(EnableJmsConfiguration.class)
|
||||||
.withPropertyValues("spring.jms.listener.autoStartup=false",
|
.withPropertyValues("spring.jms.listener.autoStartup=false",
|
||||||
"spring.jms.listener.acknowledgeMode=client",
|
"spring.jms.listener.acknowledgeMode=client",
|
||||||
"spring.jms.listener.concurrency=2",
|
"spring.jms.listener.concurrency=2",
|
||||||
|
|
@ -170,22 +170,22 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultContainerFactoryWithJtaTransactionManager() {
|
public void testDefaultContainerFactoryWithJtaTransactionManager() {
|
||||||
this.context.withUserConfiguration(TestConfiguration7.class,
|
this.contextRunner.withUserConfiguration(TestConfiguration7.class,
|
||||||
EnableJmsConfiguration.class).run((loaded) -> {
|
EnableJmsConfiguration.class).run((context) -> {
|
||||||
DefaultMessageListenerContainer container = getContainer(loaded,
|
DefaultMessageListenerContainer container = getContainer(context,
|
||||||
"jmsListenerContainerFactory");
|
"jmsListenerContainerFactory");
|
||||||
assertThat(container.isSessionTransacted()).isFalse();
|
assertThat(container.isSessionTransacted()).isFalse();
|
||||||
assertThat(new DirectFieldAccessor(container)
|
assertThat(new DirectFieldAccessor(container)
|
||||||
.getPropertyValue("transactionManager")).isSameAs(
|
.getPropertyValue("transactionManager")).isSameAs(
|
||||||
loaded.getBean(JtaTransactionManager.class));
|
context.getBean(JtaTransactionManager.class));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultContainerFactoryNonJtaTransactionManager() {
|
public void testDefaultContainerFactoryNonJtaTransactionManager() {
|
||||||
this.context.withUserConfiguration(TestConfiguration8.class,
|
this.contextRunner.withUserConfiguration(TestConfiguration8.class,
|
||||||
EnableJmsConfiguration.class).run((loaded) -> {
|
EnableJmsConfiguration.class).run((context) -> {
|
||||||
DefaultMessageListenerContainer container = getContainer(loaded,
|
DefaultMessageListenerContainer container = getContainer(context,
|
||||||
"jmsListenerContainerFactory");
|
"jmsListenerContainerFactory");
|
||||||
assertThat(container.isSessionTransacted()).isTrue();
|
assertThat(container.isSessionTransacted()).isTrue();
|
||||||
assertThat(new DirectFieldAccessor(container)
|
assertThat(new DirectFieldAccessor(container)
|
||||||
|
|
@ -195,8 +195,9 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultContainerFactoryNoTransactionManager() {
|
public void testDefaultContainerFactoryNoTransactionManager() {
|
||||||
this.context.withUserConfiguration(EnableJmsConfiguration.class).run((loaded) -> {
|
this.contextRunner.withUserConfiguration(EnableJmsConfiguration.class)
|
||||||
DefaultMessageListenerContainer container = getContainer(loaded,
|
.run((context) -> {
|
||||||
|
DefaultMessageListenerContainer container = getContainer(context,
|
||||||
"jmsListenerContainerFactory");
|
"jmsListenerContainerFactory");
|
||||||
assertThat(container.isSessionTransacted()).isTrue();
|
assertThat(container.isSessionTransacted()).isTrue();
|
||||||
assertThat(new DirectFieldAccessor(container)
|
assertThat(new DirectFieldAccessor(container)
|
||||||
|
|
@ -206,23 +207,23 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultContainerFactoryWithMessageConverters() {
|
public void testDefaultContainerFactoryWithMessageConverters() {
|
||||||
this.context.withUserConfiguration(MessageConvertersConfiguration.class,
|
this.contextRunner.withUserConfiguration(MessageConvertersConfiguration.class,
|
||||||
EnableJmsConfiguration.class).run((loaded) -> {
|
EnableJmsConfiguration.class).run((context) -> {
|
||||||
DefaultMessageListenerContainer container = getContainer(loaded,
|
DefaultMessageListenerContainer container = getContainer(context,
|
||||||
"jmsListenerContainerFactory");
|
"jmsListenerContainerFactory");
|
||||||
assertThat(container.getMessageConverter())
|
assertThat(container.getMessageConverter())
|
||||||
.isSameAs(loaded.getBean("myMessageConverter"));
|
.isSameAs(context.getBean("myMessageConverter"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomContainerFactoryWithConfigurer() {
|
public void testCustomContainerFactoryWithConfigurer() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withUserConfiguration(TestConfiguration9.class,
|
.withUserConfiguration(TestConfiguration9.class,
|
||||||
EnableJmsConfiguration.class)
|
EnableJmsConfiguration.class)
|
||||||
.withPropertyValues("spring.jms.listener.autoStartup=false")
|
.withPropertyValues("spring.jms.listener.autoStartup=false")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
DefaultMessageListenerContainer container = getContainer(loaded,
|
DefaultMessageListenerContainer container = getContainer(context,
|
||||||
"customListenerContainerFactory");
|
"customListenerContainerFactory");
|
||||||
assertThat(container.getCacheLevel())
|
assertThat(container.getCacheLevel())
|
||||||
.isEqualTo(DefaultMessageListenerContainer.CACHE_CONSUMER);
|
.isEqualTo(DefaultMessageListenerContainer.CACHE_CONSUMER);
|
||||||
|
|
@ -241,35 +242,35 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJmsTemplateWithMessageConverter() {
|
public void testJmsTemplateWithMessageConverter() {
|
||||||
this.context.withUserConfiguration(MessageConvertersConfiguration.class)
|
this.contextRunner.withUserConfiguration(MessageConvertersConfiguration.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
assertThat(jmsTemplate.getMessageConverter())
|
assertThat(jmsTemplate.getMessageConverter())
|
||||||
.isSameAs(loaded.getBean("myMessageConverter"));
|
.isSameAs(context.getBean("myMessageConverter"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJmsTemplateWithDestinationResolver() {
|
public void testJmsTemplateWithDestinationResolver() {
|
||||||
this.context.withUserConfiguration(DestinationResolversConfiguration.class)
|
this.contextRunner.withUserConfiguration(DestinationResolversConfiguration.class)
|
||||||
.run((loaded) -> assertThat(
|
.run((context) -> assertThat(
|
||||||
loaded.getBean(JmsTemplate.class).getDestinationResolver())
|
context.getBean(JmsTemplate.class).getDestinationResolver())
|
||||||
.isSameAs(loaded.getBean("myDestinationResolver")));
|
.isSameAs(context.getBean("myDestinationResolver")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJmsTemplateFullCustomization() {
|
public void testJmsTemplateFullCustomization() {
|
||||||
this.context.withUserConfiguration(MessageConvertersConfiguration.class)
|
this.contextRunner.withUserConfiguration(MessageConvertersConfiguration.class)
|
||||||
.withPropertyValues("spring.jms.template.default-destination=testQueue",
|
.withPropertyValues("spring.jms.template.default-destination=testQueue",
|
||||||
"spring.jms.template.delivery-delay=500",
|
"spring.jms.template.delivery-delay=500",
|
||||||
"spring.jms.template.delivery-mode=non-persistent",
|
"spring.jms.template.delivery-mode=non-persistent",
|
||||||
"spring.jms.template.priority=6",
|
"spring.jms.template.priority=6",
|
||||||
"spring.jms.template.time-to-live=6000",
|
"spring.jms.template.time-to-live=6000",
|
||||||
"spring.jms.template.receive-timeout=2000")
|
"spring.jms.template.receive-timeout=2000")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
assertThat(jmsTemplate.getMessageConverter())
|
assertThat(jmsTemplate.getMessageConverter())
|
||||||
.isSameAs(loaded.getBean("myMessageConverter"));
|
.isSameAs(context.getBean("myMessageConverter"));
|
||||||
assertThat(jmsTemplate.isPubSubDomain()).isFalse();
|
assertThat(jmsTemplate.isPubSubDomain()).isFalse();
|
||||||
assertThat(jmsTemplate.getDefaultDestinationName())
|
assertThat(jmsTemplate.getDefaultDestinationName())
|
||||||
.isEqualTo("testQueue");
|
.isEqualTo("testQueue");
|
||||||
|
|
@ -284,24 +285,24 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPubSubDisabledByDefault() {
|
public void testPubSubDisabledByDefault() {
|
||||||
this.context.withUserConfiguration(TestConfiguration.class).run(
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||||
(loaded) -> assertThat(loaded.getBean(JmsTemplate.class).isPubSubDomain())
|
.run((context) -> assertThat(
|
||||||
.isFalse());
|
context.getBean(JmsTemplate.class).isPubSubDomain()).isFalse());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJmsTemplatePostProcessedSoThatPubSubIsTrue() {
|
public void testJmsTemplatePostProcessedSoThatPubSubIsTrue() {
|
||||||
this.context.withUserConfiguration(TestConfiguration4.class).run(
|
this.contextRunner.withUserConfiguration(TestConfiguration4.class)
|
||||||
(loaded) -> assertThat(loaded.getBean(JmsTemplate.class).isPubSubDomain())
|
.run((context) -> assertThat(
|
||||||
.isTrue());
|
context.getBean(JmsTemplate.class).isPubSubDomain()).isTrue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPubSubDomainActive() {
|
public void testPubSubDomainActive() {
|
||||||
this.context.withUserConfiguration(TestConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||||
.withPropertyValues("spring.jms.pubSubDomain:true").run((loaded) -> {
|
.withPropertyValues("spring.jms.pubSubDomain:true").run((context) -> {
|
||||||
JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
DefaultMessageListenerContainer defaultMessageListenerContainer = loaded
|
DefaultMessageListenerContainer defaultMessageListenerContainer = context
|
||||||
.getBean(DefaultJmsListenerContainerFactory.class)
|
.getBean(DefaultJmsListenerContainerFactory.class)
|
||||||
.createListenerContainer(mock(JmsListenerEndpoint.class));
|
.createListenerContainer(mock(JmsListenerEndpoint.class));
|
||||||
assertThat(jmsTemplate.isPubSubDomain()).isTrue();
|
assertThat(jmsTemplate.isPubSubDomain()).isTrue();
|
||||||
|
|
@ -311,10 +312,10 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPubSubDomainOverride() {
|
public void testPubSubDomainOverride() {
|
||||||
this.context.withUserConfiguration(TestConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||||
.withPropertyValues("spring.jms.pubSubDomain:false").run((loaded) -> {
|
.withPropertyValues("spring.jms.pubSubDomain:false").run((context) -> {
|
||||||
JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
ActiveMQConnectionFactory factory = loaded
|
ActiveMQConnectionFactory factory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
assertThat(jmsTemplate).isNotNull();
|
assertThat(jmsTemplate).isNotNull();
|
||||||
assertThat(jmsTemplate.isPubSubDomain()).isFalse();
|
assertThat(jmsTemplate.isPubSubDomain()).isFalse();
|
||||||
|
|
@ -325,10 +326,10 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testActiveMQOverriddenStandalone() {
|
public void testActiveMQOverriddenStandalone() {
|
||||||
this.context.withUserConfiguration(TestConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||||
.withPropertyValues("spring.activemq.inMemory:false").run((loaded) -> {
|
.withPropertyValues("spring.activemq.inMemory:false").run((context) -> {
|
||||||
JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
ActiveMQConnectionFactory factory = loaded
|
ActiveMQConnectionFactory factory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
assertThat(jmsTemplate).isNotNull();
|
assertThat(jmsTemplate).isNotNull();
|
||||||
assertThat(factory).isNotNull()
|
assertThat(factory).isNotNull()
|
||||||
|
|
@ -341,11 +342,11 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testActiveMQOverriddenRemoteHost() {
|
public void testActiveMQOverriddenRemoteHost() {
|
||||||
this.context.withUserConfiguration(TestConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||||
.withPropertyValues("spring.activemq.brokerUrl:tcp://remote-host:10000")
|
.withPropertyValues("spring.activemq.brokerUrl:tcp://remote-host:10000")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
ActiveMQConnectionFactory factory = loaded
|
ActiveMQConnectionFactory factory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
assertThat(jmsTemplate).isNotNull();
|
assertThat(jmsTemplate).isNotNull();
|
||||||
assertThat(factory).isNotNull();
|
assertThat(factory).isNotNull();
|
||||||
|
|
@ -358,10 +359,11 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testActiveMQOverriddenPool() {
|
public void testActiveMQOverriddenPool() {
|
||||||
this.context.withUserConfiguration(TestConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||||
.withPropertyValues("spring.activemq.pool.enabled:true").run((loaded) -> {
|
.withPropertyValues("spring.activemq.pool.enabled:true")
|
||||||
JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
|
.run((context) -> {
|
||||||
PooledConnectionFactory pool = loaded
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
|
PooledConnectionFactory pool = context
|
||||||
.getBean(PooledConnectionFactory.class);
|
.getBean(PooledConnectionFactory.class);
|
||||||
assertThat(jmsTemplate).isNotNull();
|
assertThat(jmsTemplate).isNotNull();
|
||||||
assertThat(pool).isNotNull();
|
assertThat(pool).isNotNull();
|
||||||
|
|
@ -374,12 +376,12 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testActiveMQOverriddenPoolAndStandalone() {
|
public void testActiveMQOverriddenPoolAndStandalone() {
|
||||||
this.context.withUserConfiguration(TestConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||||
.withPropertyValues("spring.activemq.pool.enabled:true",
|
.withPropertyValues("spring.activemq.pool.enabled:true",
|
||||||
"spring.activemq.inMemory:false")
|
"spring.activemq.inMemory:false")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
PooledConnectionFactory pool = loaded
|
PooledConnectionFactory pool = context
|
||||||
.getBean(PooledConnectionFactory.class);
|
.getBean(PooledConnectionFactory.class);
|
||||||
assertThat(jmsTemplate).isNotNull();
|
assertThat(jmsTemplate).isNotNull();
|
||||||
assertThat(pool).isNotNull();
|
assertThat(pool).isNotNull();
|
||||||
|
|
@ -392,12 +394,12 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testActiveMQOverriddenPoolAndRemoteServer() {
|
public void testActiveMQOverriddenPoolAndRemoteServer() {
|
||||||
this.context.withUserConfiguration(TestConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||||
.withPropertyValues("spring.activemq.pool.enabled:true",
|
.withPropertyValues("spring.activemq.pool.enabled:true",
|
||||||
"spring.activemq.brokerUrl:tcp://remote-host:10000")
|
"spring.activemq.brokerUrl:tcp://remote-host:10000")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
PooledConnectionFactory pool = loaded
|
PooledConnectionFactory pool = context
|
||||||
.getBean(PooledConnectionFactory.class);
|
.getBean(PooledConnectionFactory.class);
|
||||||
assertThat(jmsTemplate).isNotNull();
|
assertThat(jmsTemplate).isNotNull();
|
||||||
assertThat(pool).isNotNull();
|
assertThat(pool).isNotNull();
|
||||||
|
|
@ -411,9 +413,9 @@ public class JmsAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void enableJmsAutomatically() throws Exception {
|
public void enableJmsAutomatically() throws Exception {
|
||||||
this.context.withUserConfiguration(NoEnableJmsConfiguration.class)
|
this.contextRunner.withUserConfiguration(NoEnableJmsConfiguration.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded)
|
assertThat(context)
|
||||||
.hasBean(
|
.hasBean(
|
||||||
JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)
|
JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)
|
||||||
.hasBean(
|
.hasBean(
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
|
@ -42,36 +42,39 @@ import static org.mockito.Mockito.mockingDetails;
|
||||||
*/
|
*/
|
||||||
public class ActiveMQAutoConfigurationTests {
|
public class ActiveMQAutoConfigurationTests {
|
||||||
|
|
||||||
private final ApplicationContextTester context = new ApplicationContextTester()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(ActiveMQAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(ActiveMQAutoConfiguration.class,
|
||||||
JmsAutoConfiguration.class));
|
JmsAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void brokerIsEmbeddedByDefault() {
|
public void brokerIsEmbeddedByDefault() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class).run((loaded) -> {
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
assertThat(loaded).getBean(ConnectionFactory.class)
|
.run((context) -> {
|
||||||
|
assertThat(context).getBean(ConnectionFactory.class)
|
||||||
.isInstanceOf(ActiveMQConnectionFactory.class);
|
.isInstanceOf(ActiveMQConnectionFactory.class);
|
||||||
assertThat(loaded.getBean(ActiveMQConnectionFactory.class).getBrokerURL())
|
assertThat(context.getBean(ActiveMQConnectionFactory.class)
|
||||||
|
.getBrokerURL())
|
||||||
.isEqualTo("vm://localhost?broker.persistent=false");
|
.isEqualTo("vm://localhost?broker.persistent=false");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void configurationBacksOffWhenCustomConnectionFactoryExists() {
|
public void configurationBacksOffWhenCustomConnectionFactoryExists() {
|
||||||
this.context.withUserConfiguration(CustomConnectionFactoryConfiguration.class)
|
this.contextRunner
|
||||||
.run((loaded) -> assertThat(
|
.withUserConfiguration(CustomConnectionFactoryConfiguration.class)
|
||||||
mockingDetails(loaded.getBean(ConnectionFactory.class)).isMock())
|
.run((context) -> assertThat(
|
||||||
|
mockingDetails(context.getBean(ConnectionFactory.class)).isMock())
|
||||||
.isTrue());
|
.isTrue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultsConnectionFactoryAreApplied() {
|
public void defaultsConnectionFactoryAreApplied() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.activemq.pool.enabled=false")
|
.withPropertyValues("spring.activemq.pool.enabled=false")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded.getBeansOfType(ActiveMQConnectionFactory.class))
|
assertThat(context.getBeansOfType(ActiveMQConnectionFactory.class))
|
||||||
.hasSize(1);
|
.hasSize(1);
|
||||||
ActiveMQConnectionFactory connectionFactory = loaded
|
ActiveMQConnectionFactory connectionFactory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
ActiveMQConnectionFactory defaultFactory = new ActiveMQConnectionFactory(
|
ActiveMQConnectionFactory defaultFactory = new ActiveMQConnectionFactory(
|
||||||
"vm://localhost?broker.persistent=false");
|
"vm://localhost?broker.persistent=false");
|
||||||
|
|
@ -94,7 +97,7 @@ public class ActiveMQAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customConnectionFactoryAreApplied() {
|
public void customConnectionFactoryAreApplied() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.activemq.pool.enabled=false",
|
.withPropertyValues("spring.activemq.pool.enabled=false",
|
||||||
"spring.activemq.brokerUrl=vm://localhost?useJmx=false&broker.persistent=false",
|
"spring.activemq.brokerUrl=vm://localhost?useJmx=false&broker.persistent=false",
|
||||||
"spring.activemq.user=foo", "spring.activemq.password=bar",
|
"spring.activemq.user=foo", "spring.activemq.password=bar",
|
||||||
|
|
@ -103,10 +106,10 @@ public class ActiveMQAutoConfigurationTests {
|
||||||
"spring.activemq.sendTimeout=1000",
|
"spring.activemq.sendTimeout=1000",
|
||||||
"spring.activemq.packages.trust-all=false",
|
"spring.activemq.packages.trust-all=false",
|
||||||
"spring.activemq.packages.trusted=com.example.acme")
|
"spring.activemq.packages.trusted=com.example.acme")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded.getBeansOfType(ActiveMQConnectionFactory.class))
|
assertThat(context.getBeansOfType(ActiveMQConnectionFactory.class))
|
||||||
.hasSize(1);
|
.hasSize(1);
|
||||||
ActiveMQConnectionFactory connectionFactory = loaded
|
ActiveMQConnectionFactory connectionFactory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
assertThat(connectionFactory.getUserName()).isEqualTo("foo");
|
assertThat(connectionFactory.getUserName()).isEqualTo("foo");
|
||||||
assertThat(connectionFactory.getPassword()).isEqualTo("bar");
|
assertThat(connectionFactory.getPassword()).isEqualTo("bar");
|
||||||
|
|
@ -122,11 +125,12 @@ public class ActiveMQAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultsPooledConnectionFactoryAreApplied() {
|
public void defaultsPooledConnectionFactoryAreApplied() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.activemq.pool.enabled=true").run((loaded) -> {
|
.withPropertyValues("spring.activemq.pool.enabled=true")
|
||||||
assertThat(loaded.getBeansOfType(PooledConnectionFactory.class))
|
.run((context) -> {
|
||||||
|
assertThat(context.getBeansOfType(PooledConnectionFactory.class))
|
||||||
.hasSize(1);
|
.hasSize(1);
|
||||||
PooledConnectionFactory connectionFactory = loaded
|
PooledConnectionFactory connectionFactory = context
|
||||||
.getBean(PooledConnectionFactory.class);
|
.getBean(PooledConnectionFactory.class);
|
||||||
PooledConnectionFactory defaultFactory = new PooledConnectionFactory();
|
PooledConnectionFactory defaultFactory = new PooledConnectionFactory();
|
||||||
assertThat(connectionFactory.isBlockIfSessionPoolIsFull())
|
assertThat(connectionFactory.isBlockIfSessionPoolIsFull())
|
||||||
|
|
@ -157,7 +161,7 @@ public class ActiveMQAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customPooledConnectionFactoryAreApplied() {
|
public void customPooledConnectionFactoryAreApplied() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.activemq.pool.enabled=true",
|
.withPropertyValues("spring.activemq.pool.enabled=true",
|
||||||
"spring.activemq.pool.blockIfFull=false",
|
"spring.activemq.pool.blockIfFull=false",
|
||||||
"spring.activemq.pool.blockIfFullTimeout=64",
|
"spring.activemq.pool.blockIfFullTimeout=64",
|
||||||
|
|
@ -169,10 +173,10 @@ public class ActiveMQAutoConfigurationTests {
|
||||||
"spring.activemq.pool.reconnectOnException=false",
|
"spring.activemq.pool.reconnectOnException=false",
|
||||||
"spring.activemq.pool.timeBetweenExpirationCheck=2048",
|
"spring.activemq.pool.timeBetweenExpirationCheck=2048",
|
||||||
"spring.activemq.pool.useAnonymousProducers=false")
|
"spring.activemq.pool.useAnonymousProducers=false")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded.getBeansOfType(PooledConnectionFactory.class))
|
assertThat(context.getBeansOfType(PooledConnectionFactory.class))
|
||||||
.hasSize(1);
|
.hasSize(1);
|
||||||
PooledConnectionFactory connectionFactory = loaded
|
PooledConnectionFactory connectionFactory = context
|
||||||
.getBean(PooledConnectionFactory.class);
|
.getBean(PooledConnectionFactory.class);
|
||||||
assertThat(connectionFactory.isBlockIfSessionPoolIsFull())
|
assertThat(connectionFactory.isBlockIfSessionPoolIsFull())
|
||||||
.isEqualTo(false);
|
.isEqualTo(false);
|
||||||
|
|
@ -196,11 +200,12 @@ public class ActiveMQAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pooledConnectionFactoryConfiguration() throws JMSException {
|
public void pooledConnectionFactoryConfiguration() throws JMSException {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.activemq.pool.enabled:true").run((loaded) -> {
|
.withPropertyValues("spring.activemq.pool.enabled:true")
|
||||||
ConnectionFactory factory = loaded.getBean(ConnectionFactory.class);
|
.run((context) -> {
|
||||||
|
ConnectionFactory factory = context.getBean(ConnectionFactory.class);
|
||||||
assertThat(factory).isInstanceOf(PooledConnectionFactory.class);
|
assertThat(factory).isInstanceOf(PooledConnectionFactory.class);
|
||||||
loaded.getSourceApplicationContext().close();
|
context.getSourceApplicationContext().close();
|
||||||
assertThat(factory.createConnection()).isNull();
|
assertThat(factory.createConnection()).isNull();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
@ -64,16 +64,16 @@ public class ArtemisAutoConfigurationTests {
|
||||||
@Rule
|
@Rule
|
||||||
public final TemporaryFolder folder = new TemporaryFolder();
|
public final TemporaryFolder folder = new TemporaryFolder();
|
||||||
|
|
||||||
private final ApplicationContextTester context = new ApplicationContextTester()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(ArtemisAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(ArtemisAutoConfiguration.class,
|
||||||
JmsAutoConfiguration.class));
|
JmsAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nativeConnectionFactory() {
|
public void nativeConnectionFactory() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.mode:native").run((loaded) -> {
|
.withPropertyValues("spring.artemis.mode:native").run((context) -> {
|
||||||
JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
ActiveMQConnectionFactory factory = loaded
|
ActiveMQConnectionFactory factory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
assertThat(factory).isEqualTo(jmsTemplate.getConnectionFactory());
|
assertThat(factory).isEqualTo(jmsTemplate.getConnectionFactory());
|
||||||
assertNettyConnectionFactory(factory, "localhost", 61616);
|
assertNettyConnectionFactory(factory, "localhost", 61616);
|
||||||
|
|
@ -84,11 +84,11 @@ public class ArtemisAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nativeConnectionFactoryCustomHost() {
|
public void nativeConnectionFactoryCustomHost() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.mode:native",
|
.withPropertyValues("spring.artemis.mode:native",
|
||||||
"spring.artemis.host:192.168.1.144", "spring.artemis.port:9876")
|
"spring.artemis.host:192.168.1.144", "spring.artemis.port:9876")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
ActiveMQConnectionFactory factory = loaded
|
ActiveMQConnectionFactory factory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
assertNettyConnectionFactory(factory, "192.168.1.144", 9876);
|
assertNettyConnectionFactory(factory, "192.168.1.144", 9876);
|
||||||
});
|
});
|
||||||
|
|
@ -96,12 +96,12 @@ public class ArtemisAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nativeConnectionFactoryCredentials() {
|
public void nativeConnectionFactoryCredentials() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.mode:native",
|
.withPropertyValues("spring.artemis.mode:native",
|
||||||
"spring.artemis.user:user", "spring.artemis.password:secret")
|
"spring.artemis.user:user", "spring.artemis.password:secret")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
JmsTemplate jmsTemplate = loaded.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
ActiveMQConnectionFactory factory = loaded
|
ActiveMQConnectionFactory factory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
assertThat(factory).isEqualTo(jmsTemplate.getConnectionFactory());
|
assertThat(factory).isEqualTo(jmsTemplate.getConnectionFactory());
|
||||||
assertNettyConnectionFactory(factory, "localhost", 61616);
|
assertNettyConnectionFactory(factory, "localhost", 61616);
|
||||||
|
|
@ -112,18 +112,18 @@ public class ArtemisAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void embeddedConnectionFactory() {
|
public void embeddedConnectionFactory() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.mode:embedded").run((loaded) -> {
|
.withPropertyValues("spring.artemis.mode:embedded").run((context) -> {
|
||||||
ArtemisProperties properties = loaded
|
ArtemisProperties properties = context
|
||||||
.getBean(ArtemisProperties.class);
|
.getBean(ArtemisProperties.class);
|
||||||
assertThat(properties.getMode()).isEqualTo(ArtemisMode.EMBEDDED);
|
assertThat(properties.getMode()).isEqualTo(ArtemisMode.EMBEDDED);
|
||||||
assertThat(loaded).hasSingleBean(EmbeddedJMS.class);
|
assertThat(context).hasSingleBean(EmbeddedJMS.class);
|
||||||
org.apache.activemq.artemis.core.config.Configuration configuration = loaded
|
org.apache.activemq.artemis.core.config.Configuration configuration = context
|
||||||
.getBean(
|
.getBean(
|
||||||
org.apache.activemq.artemis.core.config.Configuration.class);
|
org.apache.activemq.artemis.core.config.Configuration.class);
|
||||||
assertThat(configuration.isPersistenceEnabled()).isFalse();
|
assertThat(configuration.isPersistenceEnabled()).isFalse();
|
||||||
assertThat(configuration.isSecurityEnabled()).isFalse();
|
assertThat(configuration.isSecurityEnabled()).isFalse();
|
||||||
ActiveMQConnectionFactory factory = loaded
|
ActiveMQConnectionFactory factory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
assertInVmConnectionFactory(factory);
|
assertInVmConnectionFactory(factory);
|
||||||
});
|
});
|
||||||
|
|
@ -132,13 +132,15 @@ public class ArtemisAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void embeddedConnectionFactoryByDefault() {
|
public void embeddedConnectionFactoryByDefault() {
|
||||||
// No mode is specified
|
// No mode is specified
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class).run((loaded) -> {
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
assertThat(loaded).hasSingleBean(EmbeddedJMS.class);
|
.run((context) -> {
|
||||||
org.apache.activemq.artemis.core.config.Configuration configuration = loaded
|
assertThat(context).hasSingleBean(EmbeddedJMS.class);
|
||||||
.getBean(org.apache.activemq.artemis.core.config.Configuration.class);
|
org.apache.activemq.artemis.core.config.Configuration configuration = context
|
||||||
|
.getBean(
|
||||||
|
org.apache.activemq.artemis.core.config.Configuration.class);
|
||||||
assertThat(configuration.isPersistenceEnabled()).isFalse();
|
assertThat(configuration.isPersistenceEnabled()).isFalse();
|
||||||
assertThat(configuration.isSecurityEnabled()).isFalse();
|
assertThat(configuration.isSecurityEnabled()).isFalse();
|
||||||
ActiveMQConnectionFactory factory = loaded
|
ActiveMQConnectionFactory factory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
assertInVmConnectionFactory(factory);
|
assertInVmConnectionFactory(factory);
|
||||||
});
|
});
|
||||||
|
|
@ -147,11 +149,11 @@ public class ArtemisAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void nativeConnectionFactoryIfEmbeddedServiceDisabledExplicitly() {
|
public void nativeConnectionFactoryIfEmbeddedServiceDisabledExplicitly() {
|
||||||
// No mode is specified
|
// No mode is specified
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.embedded.enabled:false")
|
.withPropertyValues("spring.artemis.embedded.enabled:false")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).doesNotHaveBean(EmbeddedJMS.class);
|
assertThat(context).doesNotHaveBean(EmbeddedJMS.class);
|
||||||
ActiveMQConnectionFactory factory = loaded
|
ActiveMQConnectionFactory factory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
assertNettyConnectionFactory(factory, "localhost", 61616);
|
assertNettyConnectionFactory(factory, "localhost", 61616);
|
||||||
});
|
});
|
||||||
|
|
@ -160,12 +162,12 @@ public class ArtemisAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void embeddedConnectionFactoryEvenIfEmbeddedServiceDisabled() {
|
public void embeddedConnectionFactoryEvenIfEmbeddedServiceDisabled() {
|
||||||
// No mode is specified
|
// No mode is specified
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.mode:embedded",
|
.withPropertyValues("spring.artemis.mode:embedded",
|
||||||
"spring.artemis.embedded.enabled:false")
|
"spring.artemis.embedded.enabled:false")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded.getBeansOfType(EmbeddedJMS.class)).isEmpty();
|
assertThat(context.getBeansOfType(EmbeddedJMS.class)).isEmpty();
|
||||||
ActiveMQConnectionFactory connectionFactory = loaded
|
ActiveMQConnectionFactory connectionFactory = context
|
||||||
.getBean(ActiveMQConnectionFactory.class);
|
.getBean(ActiveMQConnectionFactory.class);
|
||||||
assertInVmConnectionFactory(connectionFactory);
|
assertInVmConnectionFactory(connectionFactory);
|
||||||
});
|
});
|
||||||
|
|
@ -173,11 +175,11 @@ public class ArtemisAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void embeddedServerWithDestinations() {
|
public void embeddedServerWithDestinations() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.embedded.queues=Queue1,Queue2",
|
.withPropertyValues("spring.artemis.embedded.queues=Queue1,Queue2",
|
||||||
"spring.artemis.embedded.topics=Topic1")
|
"spring.artemis.embedded.topics=Topic1")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
DestinationChecker checker = new DestinationChecker(loaded);
|
DestinationChecker checker = new DestinationChecker(context);
|
||||||
checker.checkQueue("Queue1", true);
|
checker.checkQueue("Queue1", true);
|
||||||
checker.checkQueue("Queue2", true);
|
checker.checkQueue("Queue2", true);
|
||||||
checker.checkQueue("QueueWillNotBeAutoCreated", true);
|
checker.checkQueue("QueueWillNotBeAutoCreated", true);
|
||||||
|
|
@ -188,9 +190,9 @@ public class ArtemisAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void embeddedServerWithDestinationConfig() {
|
public void embeddedServerWithDestinationConfig() {
|
||||||
this.context.withUserConfiguration(DestinationConfiguration.class)
|
this.contextRunner.withUserConfiguration(DestinationConfiguration.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
DestinationChecker checker = new DestinationChecker(loaded);
|
DestinationChecker checker = new DestinationChecker(context);
|
||||||
checker.checkQueue("sampleQueue", true);
|
checker.checkQueue("sampleQueue", true);
|
||||||
checker.checkTopic("sampleTopic", true);
|
checker.checkTopic("sampleTopic", true);
|
||||||
});
|
});
|
||||||
|
|
@ -199,10 +201,10 @@ public class ArtemisAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void embeddedServiceWithCustomJmsConfiguration() {
|
public void embeddedServiceWithCustomJmsConfiguration() {
|
||||||
// Ignored with custom config
|
// Ignored with custom config
|
||||||
this.context.withUserConfiguration(CustomJmsConfiguration.class)
|
this.contextRunner.withUserConfiguration(CustomJmsConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.embedded.queues=Queue1,Queue2")
|
.withPropertyValues("spring.artemis.embedded.queues=Queue1,Queue2")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
DestinationChecker checker = new DestinationChecker(loaded);
|
DestinationChecker checker = new DestinationChecker(context);
|
||||||
checker.checkQueue("custom", true); // See CustomJmsConfiguration
|
checker.checkQueue("custom", true); // See CustomJmsConfiguration
|
||||||
checker.checkQueue("Queue1", true);
|
checker.checkQueue("Queue1", true);
|
||||||
checker.checkQueue("Queue2", true);
|
checker.checkQueue("Queue2", true);
|
||||||
|
|
@ -211,8 +213,8 @@ public class ArtemisAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void embeddedServiceWithCustomArtemisConfiguration() {
|
public void embeddedServiceWithCustomArtemisConfiguration() {
|
||||||
this.context.withUserConfiguration(CustomArtemisConfiguration.class)
|
this.contextRunner.withUserConfiguration(CustomArtemisConfiguration.class)
|
||||||
.run((loaded) -> assertThat(loaded
|
.run((context) -> assertThat(context
|
||||||
.getBean(
|
.getBean(
|
||||||
org.apache.activemq.artemis.core.config.Configuration.class)
|
org.apache.activemq.artemis.core.config.Configuration.class)
|
||||||
.getName()).isEqualTo("customFooBar"));
|
.getName()).isEqualTo("customFooBar"));
|
||||||
|
|
@ -223,16 +225,16 @@ public class ArtemisAutoConfigurationTests {
|
||||||
File dataFolder = this.folder.newFolder();
|
File dataFolder = this.folder.newFolder();
|
||||||
final String messageId = UUID.randomUUID().toString();
|
final String messageId = UUID.randomUUID().toString();
|
||||||
// Start the server and post a message to some queue
|
// Start the server and post a message to some queue
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.embedded.queues=TestQueue",
|
.withPropertyValues("spring.artemis.embedded.queues=TestQueue",
|
||||||
"spring.artemis.embedded.persistent:true",
|
"spring.artemis.embedded.persistent:true",
|
||||||
"spring.artemis.embedded.dataDirectory:"
|
"spring.artemis.embedded.dataDirectory:"
|
||||||
+ dataFolder.getAbsolutePath())
|
+ dataFolder.getAbsolutePath())
|
||||||
.run((loaded) -> loaded.getBean(JmsTemplate.class).send("TestQueue",
|
.run((context) -> context.getBean(JmsTemplate.class).send("TestQueue",
|
||||||
(session) -> session.createTextMessage(messageId)));
|
(session) -> session.createTextMessage(messageId)));
|
||||||
// Start the server again and check if our message is still here
|
// Start the server again and check if our message is still here
|
||||||
this.context.run((loaded) -> {
|
this.contextRunner.run((context) -> {
|
||||||
JmsTemplate jmsTemplate2 = loaded.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate2 = context.getBean(JmsTemplate.class);
|
||||||
jmsTemplate2.setReceiveTimeout(1000L);
|
jmsTemplate2.setReceiveTimeout(1000L);
|
||||||
Message message = jmsTemplate2.receive("TestQueue");
|
Message message = jmsTemplate2.receive("TestQueue");
|
||||||
assertThat(message).isNotNull();
|
assertThat(message).isNotNull();
|
||||||
|
|
@ -242,10 +244,10 @@ public class ArtemisAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void severalEmbeddedBrokers() {
|
public void severalEmbeddedBrokers() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.embedded.queues=Queue1")
|
.withPropertyValues("spring.artemis.embedded.queues=Queue1")
|
||||||
.run((first) -> {
|
.run((first) -> {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues("spring.artemis.embedded.queues=Queue2")
|
.withPropertyValues("spring.artemis.embedded.queues=Queue2")
|
||||||
.run((second) -> {
|
.run((second) -> {
|
||||||
ArtemisProperties firstProperties = first
|
ArtemisProperties firstProperties = first
|
||||||
|
|
@ -266,11 +268,11 @@ public class ArtemisAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void connectToASpecificEmbeddedBroker() {
|
public void connectToASpecificEmbeddedBroker() {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.embedded.serverId=93",
|
.withPropertyValues("spring.artemis.embedded.serverId=93",
|
||||||
"spring.artemis.embedded.queues=Queue1")
|
"spring.artemis.embedded.queues=Queue1")
|
||||||
.run((first) -> {
|
.run((first) -> {
|
||||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.mode=embedded",
|
.withPropertyValues("spring.artemis.mode=embedded",
|
||||||
// Connect to the "main" broker
|
// Connect to the "main" broker
|
||||||
"spring.artemis.embedded.serverId=93",
|
"spring.artemis.embedded.serverId=93",
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.web.reactive;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.ReactiveWebApplicationContextTester;
|
import org.springframework.boot.test.context.ReactiveWebApplicationContextRunner;
|
||||||
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.http.server.reactive.HttpHandler;
|
import org.springframework.http.server.reactive.HttpHandler;
|
||||||
|
|
@ -39,24 +39,25 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class HttpHandlerAutoConfigurationTests {
|
public class HttpHandlerAutoConfigurationTests {
|
||||||
|
|
||||||
private final ReactiveWebApplicationContextTester context = new ReactiveWebApplicationContextTester()
|
private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(HttpHandlerAutoConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(HttpHandlerAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotProcessIfExistingHttpHandler() {
|
public void shouldNotProcessIfExistingHttpHandler() {
|
||||||
this.context.withUserConfiguration(CustomHttpHandler.class).run((loaded) -> {
|
this.contextRunner.withUserConfiguration(CustomHttpHandler.class)
|
||||||
assertThat(loaded).hasSingleBean(HttpHandler.class);
|
.run((context) -> {
|
||||||
assertThat(loaded).getBean(HttpHandler.class)
|
assertThat(context).hasSingleBean(HttpHandler.class);
|
||||||
.isSameAs(loaded.getBean("customHttpHandler"));
|
assertThat(context).getBean(HttpHandler.class)
|
||||||
|
.isSameAs(context.getBean("customHttpHandler"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldConfigureHttpHandlerAnnotation() {
|
public void shouldConfigureHttpHandlerAnnotation() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class))
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).hasSingleBean(HttpHandler.class);
|
assertThat(context).hasSingleBean(HttpHandler.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguratio
|
||||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.WelcomePageHandlerMapping;
|
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.WelcomePageHandlerMapping;
|
||||||
import org.springframework.boot.test.context.AssertableWebApplicationContext;
|
import org.springframework.boot.test.context.AssertableWebApplicationContext;
|
||||||
import org.springframework.boot.test.context.ContextConsumer;
|
import org.springframework.boot.test.context.ContextConsumer;
|
||||||
import org.springframework.boot.test.context.WebApplicationContextTester;
|
import org.springframework.boot.test.context.WebApplicationContextRunner;
|
||||||
import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor;
|
import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor;
|
||||||
import org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter;
|
import org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter;
|
||||||
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
||||||
|
|
@ -116,7 +116,7 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
private static final MockServletWebServerFactory webServerFactory = new MockServletWebServerFactory();
|
private static final MockServletWebServerFactory webServerFactory = new MockServletWebServerFactory();
|
||||||
|
|
||||||
private final WebApplicationContextTester context = new WebApplicationContextTester()
|
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(WebMvcAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(WebMvcAutoConfiguration.class,
|
||||||
HttpMessageConvertersAutoConfiguration.class,
|
HttpMessageConvertersAutoConfiguration.class,
|
||||||
PropertyPlaceholderAutoConfiguration.class))
|
PropertyPlaceholderAutoConfiguration.class))
|
||||||
|
|
@ -124,50 +124,50 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlerAdaptersCreated() {
|
public void handlerAdaptersCreated() {
|
||||||
this.context.run((loaded) -> {
|
this.contextRunner.run((context) -> {
|
||||||
assertThat(loaded).getBeans(HandlerAdapter.class).hasSize(3);
|
assertThat(context).getBeans(HandlerAdapter.class).hasSize(3);
|
||||||
assertThat(loaded.getBean(RequestMappingHandlerAdapter.class)
|
assertThat(context.getBean(RequestMappingHandlerAdapter.class)
|
||||||
.getMessageConverters()).isNotEmpty().isEqualTo(
|
.getMessageConverters()).isNotEmpty().isEqualTo(
|
||||||
loaded.getBean(HttpMessageConverters.class).getConverters());
|
context.getBean(HttpMessageConverters.class).getConverters());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlerMappingsCreated() {
|
public void handlerMappingsCreated() {
|
||||||
this.context.run(
|
this.contextRunner.run((context) -> assertThat(context)
|
||||||
(loaded) -> assertThat(loaded).getBeans(HandlerMapping.class).hasSize(7));
|
.getBeans(HandlerMapping.class).hasSize(7));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourceHandlerMapping() {
|
public void resourceHandlerMapping() {
|
||||||
this.context.run((loaded) -> {
|
this.contextRunner.run((context) -> {
|
||||||
Map<String, List<Resource>> locations = getResourceMappingLocations(loaded);
|
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
|
||||||
assertThat(locations.get("/**")).hasSize(5);
|
assertThat(locations.get("/**")).hasSize(5);
|
||||||
assertThat(locations.get("/webjars/**")).hasSize(1);
|
assertThat(locations.get("/webjars/**")).hasSize(1);
|
||||||
assertThat(locations.get("/webjars/**").get(0))
|
assertThat(locations.get("/webjars/**").get(0))
|
||||||
.isEqualTo(new ClassPathResource("/META-INF/resources/webjars/"));
|
.isEqualTo(new ClassPathResource("/META-INF/resources/webjars/"));
|
||||||
assertThat(getResourceResolvers(loaded, "/webjars/**")).hasSize(1);
|
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(1);
|
||||||
assertThat(getResourceTransformers(loaded, "/webjars/**")).hasSize(0);
|
assertThat(getResourceTransformers(context, "/webjars/**")).hasSize(0);
|
||||||
assertThat(getResourceResolvers(loaded, "/**")).hasSize(1);
|
assertThat(getResourceResolvers(context, "/**")).hasSize(1);
|
||||||
assertThat(getResourceTransformers(loaded, "/**")).hasSize(0);
|
assertThat(getResourceTransformers(context, "/**")).hasSize(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customResourceHandlerMapping() {
|
public void customResourceHandlerMapping() {
|
||||||
this.context.withPropertyValues("spring.mvc.static-path-pattern:/static/**")
|
this.contextRunner.withPropertyValues("spring.mvc.static-path-pattern:/static/**")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
Map<String, List<Resource>> locations = getResourceMappingLocations(
|
Map<String, List<Resource>> locations = getResourceMappingLocations(
|
||||||
loaded);
|
context);
|
||||||
assertThat(locations.get("/static/**")).hasSize(5);
|
assertThat(locations.get("/static/**")).hasSize(5);
|
||||||
assertThat(getResourceResolvers(loaded, "/static/**")).hasSize(1);
|
assertThat(getResourceResolvers(context, "/static/**")).hasSize(1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourceHandlerMappingOverrideWebjars() throws Exception {
|
public void resourceHandlerMappingOverrideWebjars() throws Exception {
|
||||||
this.context.withUserConfiguration(WebJars.class).run((loaded) -> {
|
this.contextRunner.withUserConfiguration(WebJars.class).run((context) -> {
|
||||||
Map<String, List<Resource>> locations = getResourceMappingLocations(loaded);
|
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
|
||||||
assertThat(locations.get("/webjars/**")).hasSize(1);
|
assertThat(locations.get("/webjars/**")).hasSize(1);
|
||||||
assertThat(locations.get("/webjars/**").get(0))
|
assertThat(locations.get("/webjars/**").get(0))
|
||||||
.isEqualTo(new ClassPathResource("/foo/"));
|
.isEqualTo(new ClassPathResource("/foo/"));
|
||||||
|
|
@ -176,8 +176,8 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourceHandlerMappingOverrideAll() throws Exception {
|
public void resourceHandlerMappingOverrideAll() throws Exception {
|
||||||
this.context.withUserConfiguration(AllResources.class).run((loaded) -> {
|
this.contextRunner.withUserConfiguration(AllResources.class).run((context) -> {
|
||||||
Map<String, List<Resource>> locations = getResourceMappingLocations(loaded);
|
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
|
||||||
assertThat(locations.get("/**")).hasSize(1);
|
assertThat(locations.get("/**")).hasSize(1);
|
||||||
assertThat(locations.get("/**").get(0))
|
assertThat(locations.get("/**").get(0))
|
||||||
.isEqualTo(new ClassPathResource("/foo/"));
|
.isEqualTo(new ClassPathResource("/foo/"));
|
||||||
|
|
@ -186,25 +186,26 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourceHandlerMappingDisabled() throws Exception {
|
public void resourceHandlerMappingDisabled() throws Exception {
|
||||||
this.context.withPropertyValues("spring.resources.add-mappings:false")
|
this.contextRunner.withPropertyValues("spring.resources.add-mappings:false")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
Map<String, List<Resource>> locations = getResourceMappingLocations(
|
Map<String, List<Resource>> locations = getResourceMappingLocations(
|
||||||
loaded);
|
context);
|
||||||
assertThat(locations.size()).isEqualTo(0);
|
assertThat(locations.size()).isEqualTo(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourceHandlerChainEnabled() throws Exception {
|
public void resourceHandlerChainEnabled() throws Exception {
|
||||||
this.context.withPropertyValues("spring.resources.chain.enabled:true")
|
this.contextRunner.withPropertyValues("spring.resources.chain.enabled:true")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(getResourceResolvers(loaded, "/webjars/**")).hasSize(2);
|
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(2);
|
||||||
assertThat(getResourceTransformers(loaded, "/webjars/**")).hasSize(1);
|
assertThat(getResourceTransformers(context, "/webjars/**"))
|
||||||
assertThat(getResourceResolvers(loaded, "/**"))
|
.hasSize(1);
|
||||||
|
assertThat(getResourceResolvers(context, "/**"))
|
||||||
.extractingResultOf("getClass")
|
.extractingResultOf("getClass")
|
||||||
.containsOnly(CachingResourceResolver.class,
|
.containsOnly(CachingResourceResolver.class,
|
||||||
PathResourceResolver.class);
|
PathResourceResolver.class);
|
||||||
assertThat(getResourceTransformers(loaded, "/**"))
|
assertThat(getResourceTransformers(context, "/**"))
|
||||||
.extractingResultOf("getClass")
|
.extractingResultOf("getClass")
|
||||||
.containsOnly(CachingResourceTransformer.class);
|
.containsOnly(CachingResourceTransformer.class);
|
||||||
});
|
});
|
||||||
|
|
@ -212,24 +213,25 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourceHandlerFixedStrategyEnabled() throws Exception {
|
public void resourceHandlerFixedStrategyEnabled() throws Exception {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues("spring.resources.chain.strategy.fixed.enabled:true",
|
.withPropertyValues("spring.resources.chain.strategy.fixed.enabled:true",
|
||||||
"spring.resources.chain.strategy.fixed.version:test",
|
"spring.resources.chain.strategy.fixed.version:test",
|
||||||
"spring.resources.chain.strategy.fixed.paths:/**/*.js")
|
"spring.resources.chain.strategy.fixed.paths:/**/*.js")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(getResourceResolvers(loaded, "/webjars/**")).hasSize(3);
|
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(3);
|
||||||
assertThat(getResourceTransformers(loaded, "/webjars/**")).hasSize(2);
|
assertThat(getResourceTransformers(context, "/webjars/**"))
|
||||||
assertThat(getResourceResolvers(loaded, "/**"))
|
.hasSize(2);
|
||||||
|
assertThat(getResourceResolvers(context, "/**"))
|
||||||
.extractingResultOf("getClass")
|
.extractingResultOf("getClass")
|
||||||
.containsOnly(CachingResourceResolver.class,
|
.containsOnly(CachingResourceResolver.class,
|
||||||
VersionResourceResolver.class,
|
VersionResourceResolver.class,
|
||||||
PathResourceResolver.class);
|
PathResourceResolver.class);
|
||||||
assertThat(getResourceTransformers(loaded, "/**"))
|
assertThat(getResourceTransformers(context, "/**"))
|
||||||
.extractingResultOf("getClass")
|
.extractingResultOf("getClass")
|
||||||
.containsOnly(CachingResourceTransformer.class,
|
.containsOnly(CachingResourceTransformer.class,
|
||||||
CssLinkResourceTransformer.class);
|
CssLinkResourceTransformer.class);
|
||||||
VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
|
VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
|
||||||
loaded, "/**").get(1);
|
context, "/**").get(1);
|
||||||
assertThat(resolver.getStrategyMap().get("/**/*.js"))
|
assertThat(resolver.getStrategyMap().get("/**/*.js"))
|
||||||
.isInstanceOf(FixedVersionStrategy.class);
|
.isInstanceOf(FixedVersionStrategy.class);
|
||||||
});
|
});
|
||||||
|
|
@ -237,24 +239,25 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourceHandlerContentStrategyEnabled() throws Exception {
|
public void resourceHandlerContentStrategyEnabled() throws Exception {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.resources.chain.strategy.content.enabled:true",
|
"spring.resources.chain.strategy.content.enabled:true",
|
||||||
"spring.resources.chain.strategy.content.paths:/**,/*.png")
|
"spring.resources.chain.strategy.content.paths:/**,/*.png")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(getResourceResolvers(loaded, "/webjars/**")).hasSize(3);
|
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(3);
|
||||||
assertThat(getResourceTransformers(loaded, "/webjars/**")).hasSize(2);
|
assertThat(getResourceTransformers(context, "/webjars/**"))
|
||||||
assertThat(getResourceResolvers(loaded, "/**"))
|
.hasSize(2);
|
||||||
|
assertThat(getResourceResolvers(context, "/**"))
|
||||||
.extractingResultOf("getClass")
|
.extractingResultOf("getClass")
|
||||||
.containsOnly(CachingResourceResolver.class,
|
.containsOnly(CachingResourceResolver.class,
|
||||||
VersionResourceResolver.class,
|
VersionResourceResolver.class,
|
||||||
PathResourceResolver.class);
|
PathResourceResolver.class);
|
||||||
assertThat(getResourceTransformers(loaded, "/**"))
|
assertThat(getResourceTransformers(context, "/**"))
|
||||||
.extractingResultOf("getClass")
|
.extractingResultOf("getClass")
|
||||||
.containsOnly(CachingResourceTransformer.class,
|
.containsOnly(CachingResourceTransformer.class,
|
||||||
CssLinkResourceTransformer.class);
|
CssLinkResourceTransformer.class);
|
||||||
VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
|
VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
|
||||||
loaded, "/**").get(1);
|
context, "/**").get(1);
|
||||||
assertThat(resolver.getStrategyMap().get("/*.png"))
|
assertThat(resolver.getStrategyMap().get("/*.png"))
|
||||||
.isInstanceOf(ContentVersionStrategy.class);
|
.isInstanceOf(ContentVersionStrategy.class);
|
||||||
});
|
});
|
||||||
|
|
@ -262,7 +265,7 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resourceHandlerChainCustomized() {
|
public void resourceHandlerChainCustomized() {
|
||||||
this.context.withPropertyValues("spring.resources.chain.enabled:true",
|
this.contextRunner.withPropertyValues("spring.resources.chain.enabled:true",
|
||||||
"spring.resources.chain.cache:false",
|
"spring.resources.chain.cache:false",
|
||||||
"spring.resources.chain.strategy.content.enabled:true",
|
"spring.resources.chain.strategy.content.enabled:true",
|
||||||
"spring.resources.chain.strategy.content.paths:/**,/*.png",
|
"spring.resources.chain.strategy.content.paths:/**,/*.png",
|
||||||
|
|
@ -270,20 +273,21 @@ public class WebMvcAutoConfigurationTests {
|
||||||
"spring.resources.chain.strategy.fixed.version:test",
|
"spring.resources.chain.strategy.fixed.version:test",
|
||||||
"spring.resources.chain.strategy.fixed.paths:/**/*.js",
|
"spring.resources.chain.strategy.fixed.paths:/**/*.js",
|
||||||
"spring.resources.chain.html-application-cache:true",
|
"spring.resources.chain.html-application-cache:true",
|
||||||
"spring.resources.chain.gzipped:true").run((loaded) -> {
|
"spring.resources.chain.gzipped:true").run((context) -> {
|
||||||
assertThat(getResourceResolvers(loaded, "/webjars/**")).hasSize(3);
|
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(3);
|
||||||
assertThat(getResourceTransformers(loaded, "/webjars/**")).hasSize(2);
|
assertThat(getResourceTransformers(context, "/webjars/**"))
|
||||||
assertThat(getResourceResolvers(loaded, "/**"))
|
.hasSize(2);
|
||||||
|
assertThat(getResourceResolvers(context, "/**"))
|
||||||
.extractingResultOf("getClass")
|
.extractingResultOf("getClass")
|
||||||
.containsOnly(VersionResourceResolver.class,
|
.containsOnly(VersionResourceResolver.class,
|
||||||
GzipResourceResolver.class,
|
GzipResourceResolver.class,
|
||||||
PathResourceResolver.class);
|
PathResourceResolver.class);
|
||||||
assertThat(getResourceTransformers(loaded, "/**"))
|
assertThat(getResourceTransformers(context, "/**"))
|
||||||
.extractingResultOf("getClass")
|
.extractingResultOf("getClass")
|
||||||
.containsOnly(CssLinkResourceTransformer.class,
|
.containsOnly(CssLinkResourceTransformer.class,
|
||||||
AppCacheManifestTransformer.class);
|
AppCacheManifestTransformer.class);
|
||||||
VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
|
VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
|
||||||
loaded, "/**").get(0);
|
context, "/**").get(0);
|
||||||
Map<String, VersionStrategy> strategyMap = resolver.getStrategyMap();
|
Map<String, VersionStrategy> strategyMap = resolver.getStrategyMap();
|
||||||
assertThat(strategyMap.get("/*.png"))
|
assertThat(strategyMap.get("/*.png"))
|
||||||
.isInstanceOf(ContentVersionStrategy.class);
|
.isInstanceOf(ContentVersionStrategy.class);
|
||||||
|
|
@ -294,13 +298,13 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noLocaleResolver() throws Exception {
|
public void noLocaleResolver() throws Exception {
|
||||||
this.context.run(
|
this.contextRunner.run(
|
||||||
(loaded) -> assertThat(loaded).doesNotHaveBean(LocaleResolver.class));
|
(context) -> assertThat(context).doesNotHaveBean(LocaleResolver.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void overrideLocale() throws Exception {
|
public void overrideLocale() throws Exception {
|
||||||
this.context.withPropertyValues("spring.mvc.locale:en_UK",
|
this.contextRunner.withPropertyValues("spring.mvc.locale:en_UK",
|
||||||
"spring.mvc.locale-resolver=fixed").run((loader) -> {
|
"spring.mvc.locale-resolver=fixed").run((loader) -> {
|
||||||
// mock request and set user preferred locale
|
// mock request and set user preferred locale
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
|
@ -317,7 +321,7 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void useAcceptHeaderLocale() {
|
public void useAcceptHeaderLocale() {
|
||||||
this.context.withPropertyValues("spring.mvc.locale:en_UK").run((loader) -> {
|
this.contextRunner.withPropertyValues("spring.mvc.locale:en_UK").run((loader) -> {
|
||||||
// mock request and set user preferred locale
|
// mock request and set user preferred locale
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
request.addPreferredLocale(StringUtils.parseLocaleString("nl_NL"));
|
request.addPreferredLocale(StringUtils.parseLocaleString("nl_NL"));
|
||||||
|
|
@ -332,11 +336,13 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void useDefaultLocaleIfAcceptHeaderNoSet() {
|
public void useDefaultLocaleIfAcceptHeaderNoSet() {
|
||||||
this.context.withPropertyValues("spring.mvc.locale:en_UK").run((loaded) -> {
|
this.contextRunner.withPropertyValues("spring.mvc.locale:en_UK")
|
||||||
|
.run((context) -> {
|
||||||
// mock request and set user preferred locale
|
// mock request and set user preferred locale
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
LocaleResolver localeResolver = loaded.getBean(LocaleResolver.class);
|
LocaleResolver localeResolver = context.getBean(LocaleResolver.class);
|
||||||
assertThat(localeResolver).isInstanceOf(AcceptHeaderLocaleResolver.class);
|
assertThat(localeResolver)
|
||||||
|
.isInstanceOf(AcceptHeaderLocaleResolver.class);
|
||||||
Locale locale = localeResolver.resolveLocale(request);
|
Locale locale = localeResolver.resolveLocale(request);
|
||||||
// test locale resolver uses default locale if no header is set
|
// test locale resolver uses default locale if no header is set
|
||||||
assertThat(locale.toString()).isEqualTo("en_UK");
|
assertThat(locale.toString()).isEqualTo("en_UK");
|
||||||
|
|
@ -345,8 +351,8 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noDateFormat() {
|
public void noDateFormat() {
|
||||||
this.context.run((loaded) -> {
|
this.contextRunner.run((context) -> {
|
||||||
FormattingConversionService conversionService = loaded
|
FormattingConversionService conversionService = context
|
||||||
.getBean(FormattingConversionService.class);
|
.getBean(FormattingConversionService.class);
|
||||||
Date date = new DateTime(1988, 6, 25, 20, 30).toDate();
|
Date date = new DateTime(1988, 6, 25, 20, 30).toDate();
|
||||||
// formatting conversion service should use simple toString()
|
// formatting conversion service should use simple toString()
|
||||||
|
|
@ -357,9 +363,9 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void overrideDateFormat() {
|
public void overrideDateFormat() {
|
||||||
this.context.withPropertyValues("spring.mvc.date-format:dd*MM*yyyy")
|
this.contextRunner.withPropertyValues("spring.mvc.date-format:dd*MM*yyyy")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
FormattingConversionService conversionService = loaded
|
FormattingConversionService conversionService = context
|
||||||
.getBean(FormattingConversionService.class);
|
.getBean(FormattingConversionService.class);
|
||||||
Date date = new DateTime(1988, 6, 25, 20, 30).toDate();
|
Date date = new DateTime(1988, 6, 25, 20, 30).toDate();
|
||||||
assertThat(conversionService.convert(date, String.class))
|
assertThat(conversionService.convert(date, String.class))
|
||||||
|
|
@ -369,106 +375,107 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noMessageCodesResolver() {
|
public void noMessageCodesResolver() {
|
||||||
this.context.run((loaded) -> assertThat(loaded
|
this.contextRunner.run((context) -> assertThat(context
|
||||||
.getBean(WebMvcAutoConfigurationAdapter.class).getMessageCodesResolver())
|
.getBean(WebMvcAutoConfigurationAdapter.class).getMessageCodesResolver())
|
||||||
.isNull());
|
.isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void overrideMessageCodesFormat() {
|
public void overrideMessageCodesFormat() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.mvc.messageCodesResolverFormat:POSTFIX_ERROR_CODE")
|
"spring.mvc.messageCodesResolverFormat:POSTFIX_ERROR_CODE")
|
||||||
.run((loaded) -> assertThat(
|
.run((context) -> assertThat(
|
||||||
loaded.getBean(WebMvcAutoConfigurationAdapter.class)
|
context.getBean(WebMvcAutoConfigurationAdapter.class)
|
||||||
.getMessageCodesResolver()).isNotNull());
|
.getMessageCodesResolver()).isNotNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ignoreDefaultModelOnRedirectIsTrue() {
|
public void ignoreDefaultModelOnRedirectIsTrue() {
|
||||||
this.context.run(
|
this.contextRunner.run((context) -> assertThat(
|
||||||
(loaded) -> assertThat(loaded.getBean(RequestMappingHandlerAdapter.class))
|
context.getBean(RequestMappingHandlerAdapter.class))
|
||||||
.extracting("ignoreDefaultModelOnRedirect")
|
.extracting("ignoreDefaultModelOnRedirect")
|
||||||
.containsExactly(true));
|
.containsExactly(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void overrideIgnoreDefaultModelOnRedirect() {
|
public void overrideIgnoreDefaultModelOnRedirect() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues("spring.mvc.ignore-default-model-on-redirect:false")
|
.withPropertyValues("spring.mvc.ignore-default-model-on-redirect:false")
|
||||||
.run((loaded) -> assertThat(
|
.run((context) -> assertThat(
|
||||||
loaded.getBean(RequestMappingHandlerAdapter.class))
|
context.getBean(RequestMappingHandlerAdapter.class))
|
||||||
.extracting("ignoreDefaultModelOnRedirect")
|
.extracting("ignoreDefaultModelOnRedirect")
|
||||||
.containsExactly(false));
|
.containsExactly(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customViewResolver() {
|
public void customViewResolver() {
|
||||||
this.context.withUserConfiguration(CustomViewResolver.class)
|
this.contextRunner.withUserConfiguration(CustomViewResolver.class)
|
||||||
.run((loaded) -> assertThat(loaded.getBean("viewResolver"))
|
.run((context) -> assertThat(context.getBean("viewResolver"))
|
||||||
.isInstanceOf(MyViewResolver.class));
|
.isInstanceOf(MyViewResolver.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customContentNegotiatingViewResolver() throws Exception {
|
public void customContentNegotiatingViewResolver() throws Exception {
|
||||||
this.context.withUserConfiguration(CustomContentNegotiatingViewResolver.class)
|
this.contextRunner
|
||||||
.run((loaded) -> assertThat(loaded)
|
.withUserConfiguration(CustomContentNegotiatingViewResolver.class)
|
||||||
|
.run((context) -> assertThat(context)
|
||||||
.getBeanNames(ContentNegotiatingViewResolver.class)
|
.getBeanNames(ContentNegotiatingViewResolver.class)
|
||||||
.containsOnly("myViewResolver"));
|
.containsOnly("myViewResolver"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void faviconMapping() {
|
public void faviconMapping() {
|
||||||
this.context.run((loaded) -> {
|
this.contextRunner.run((context) -> {
|
||||||
assertThat(loaded).getBeanNames(ResourceHttpRequestHandler.class)
|
assertThat(context).getBeanNames(ResourceHttpRequestHandler.class)
|
||||||
.contains("faviconRequestHandler");
|
.contains("faviconRequestHandler");
|
||||||
assertThat(loaded).getBeans(SimpleUrlHandlerMapping.class)
|
assertThat(context).getBeans(SimpleUrlHandlerMapping.class)
|
||||||
.containsKey("faviconHandlerMapping");
|
.containsKey("faviconHandlerMapping");
|
||||||
assertThat(getFaviconMappingLocations(loaded).get("/**/favicon.ico"))
|
assertThat(getFaviconMappingLocations(context).get("/**/favicon.ico"))
|
||||||
.hasSize(6);
|
.hasSize(6);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void faviconMappingUsesStaticLocations() {
|
public void faviconMappingUsesStaticLocations() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues("spring.resources.static-locations=classpath:/static")
|
.withPropertyValues("spring.resources.static-locations=classpath:/static")
|
||||||
.run((loaded) -> assertThat(
|
.run((context) -> assertThat(
|
||||||
getFaviconMappingLocations(loaded).get("/**/favicon.ico"))
|
getFaviconMappingLocations(context).get("/**/favicon.ico"))
|
||||||
.hasSize(2));
|
.hasSize(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void faviconMappingDisabled() throws IllegalAccessException {
|
public void faviconMappingDisabled() throws IllegalAccessException {
|
||||||
this.context.withPropertyValues("spring.mvc.favicon.enabled:false")
|
this.contextRunner.withPropertyValues("spring.mvc.favicon.enabled:false")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getBeans(ResourceHttpRequestHandler.class)
|
assertThat(context).getBeans(ResourceHttpRequestHandler.class)
|
||||||
.doesNotContainKey("faviconRequestHandler");
|
.doesNotContainKey("faviconRequestHandler");
|
||||||
assertThat(loaded).getBeans(SimpleUrlHandlerMapping.class)
|
assertThat(context).getBeans(SimpleUrlHandlerMapping.class)
|
||||||
.doesNotContainKey("faviconHandlerMapping");
|
.doesNotContainKey("faviconHandlerMapping");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultAsyncRequestTimeout() throws Exception {
|
public void defaultAsyncRequestTimeout() throws Exception {
|
||||||
this.context.run((loaded) -> assertThat(ReflectionTestUtils.getField(
|
this.contextRunner.run((context) -> assertThat(ReflectionTestUtils.getField(
|
||||||
loaded.getBean(RequestMappingHandlerAdapter.class),
|
context.getBean(RequestMappingHandlerAdapter.class),
|
||||||
"asyncRequestTimeout")).isNull());
|
"asyncRequestTimeout")).isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customAsyncRequestTimeout() throws Exception {
|
public void customAsyncRequestTimeout() throws Exception {
|
||||||
this.context.withPropertyValues("spring.mvc.async.request-timeout:12345")
|
this.contextRunner.withPropertyValues("spring.mvc.async.request-timeout:12345")
|
||||||
.run((loaded) -> assertThat(ReflectionTestUtils.getField(
|
.run((context) -> assertThat(ReflectionTestUtils.getField(
|
||||||
loaded.getBean(RequestMappingHandlerAdapter.class),
|
context.getBean(RequestMappingHandlerAdapter.class),
|
||||||
"asyncRequestTimeout")).isEqualTo(12345L));
|
"asyncRequestTimeout")).isEqualTo(12345L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customMediaTypes() throws Exception {
|
public void customMediaTypes() throws Exception {
|
||||||
this.context.withPropertyValues("spring.mvc.mediaTypes.yaml:text/yaml")
|
this.contextRunner.withPropertyValues("spring.mvc.mediaTypes.yaml:text/yaml")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
RequestMappingHandlerAdapter adapter = loaded
|
RequestMappingHandlerAdapter adapter = context
|
||||||
.getBean(RequestMappingHandlerAdapter.class);
|
.getBean(RequestMappingHandlerAdapter.class);
|
||||||
ContentNegotiationManager contentNegotiationManager = (ContentNegotiationManager) ReflectionTestUtils
|
ContentNegotiationManager contentNegotiationManager = (ContentNegotiationManager) ReflectionTestUtils
|
||||||
.getField(adapter, "contentNegotiationManager");
|
.getField(adapter, "contentNegotiationManager");
|
||||||
|
|
@ -479,80 +486,82 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpPutFormContentFilterIsAutoConfigured() {
|
public void httpPutFormContentFilterIsAutoConfigured() {
|
||||||
this.context.run((loaded) -> assertThat(loaded)
|
this.contextRunner.run((context) -> assertThat(context)
|
||||||
.hasSingleBean(OrderedHttpPutFormContentFilter.class));
|
.hasSingleBean(OrderedHttpPutFormContentFilter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpPutFormContentFilterCanBeOverridden() {
|
public void httpPutFormContentFilterCanBeOverridden() {
|
||||||
this.context.withUserConfiguration(CustomHttpPutFormContentFilter.class)
|
this.contextRunner.withUserConfiguration(CustomHttpPutFormContentFilter.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded)
|
assertThat(context)
|
||||||
.doesNotHaveBean(OrderedHttpPutFormContentFilter.class);
|
.doesNotHaveBean(OrderedHttpPutFormContentFilter.class);
|
||||||
assertThat(loaded).hasSingleBean(HttpPutFormContentFilter.class);
|
assertThat(context).hasSingleBean(HttpPutFormContentFilter.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpPutFormContentFilterCanBeDisabled() throws Exception {
|
public void httpPutFormContentFilterCanBeDisabled() throws Exception {
|
||||||
this.context.withPropertyValues("spring.mvc.formcontent.putfilter.enabled=false")
|
this.contextRunner
|
||||||
.run((loaded) -> assertThat(loaded)
|
.withPropertyValues("spring.mvc.formcontent.putfilter.enabled=false")
|
||||||
|
.run((context) -> assertThat(context)
|
||||||
.doesNotHaveBean(HttpPutFormContentFilter.class));
|
.doesNotHaveBean(HttpPutFormContentFilter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customConfigurableWebBindingInitializer() {
|
public void customConfigurableWebBindingInitializer() {
|
||||||
this.context.withUserConfiguration(CustomConfigurableWebBindingInitializer.class)
|
this.contextRunner
|
||||||
.run((loaded) -> assertThat(
|
.withUserConfiguration(CustomConfigurableWebBindingInitializer.class)
|
||||||
loaded.getBean(RequestMappingHandlerAdapter.class)
|
.run((context) -> assertThat(
|
||||||
|
context.getBean(RequestMappingHandlerAdapter.class)
|
||||||
.getWebBindingInitializer())
|
.getWebBindingInitializer())
|
||||||
.isInstanceOf(CustomWebBindingInitializer.class));
|
.isInstanceOf(CustomWebBindingInitializer.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customRequestMappingHandlerMapping() {
|
public void customRequestMappingHandlerMapping() {
|
||||||
this.context.withUserConfiguration(CustomRequestMappingHandlerMapping.class)
|
this.contextRunner.withUserConfiguration(CustomRequestMappingHandlerMapping.class)
|
||||||
.run((loaded) -> assertThat(loaded)
|
.run((context) -> assertThat(context)
|
||||||
.getBean(RequestMappingHandlerMapping.class)
|
.getBean(RequestMappingHandlerMapping.class)
|
||||||
.isInstanceOf(MyRequestMappingHandlerMapping.class));
|
.isInstanceOf(MyRequestMappingHandlerMapping.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customRequestMappingHandlerAdapter() {
|
public void customRequestMappingHandlerAdapter() {
|
||||||
this.context.withUserConfiguration(CustomRequestMappingHandlerAdapter.class)
|
this.contextRunner.withUserConfiguration(CustomRequestMappingHandlerAdapter.class)
|
||||||
.run((loaded) -> assertThat(loaded)
|
.run((context) -> assertThat(context)
|
||||||
.getBean(RequestMappingHandlerAdapter.class)
|
.getBean(RequestMappingHandlerAdapter.class)
|
||||||
.isInstanceOf(MyRequestMappingHandlerAdapter.class));
|
.isInstanceOf(MyRequestMappingHandlerAdapter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multipleWebMvcRegistrations() {
|
public void multipleWebMvcRegistrations() {
|
||||||
this.context.withUserConfiguration(MultipleWebMvcRegistrations.class)
|
this.contextRunner.withUserConfiguration(MultipleWebMvcRegistrations.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded.getBean(RequestMappingHandlerMapping.class))
|
assertThat(context.getBean(RequestMappingHandlerMapping.class))
|
||||||
.isNotInstanceOf(MyRequestMappingHandlerMapping.class);
|
.isNotInstanceOf(MyRequestMappingHandlerMapping.class);
|
||||||
assertThat(loaded.getBean(RequestMappingHandlerAdapter.class))
|
assertThat(context.getBean(RequestMappingHandlerAdapter.class))
|
||||||
.isNotInstanceOf(MyRequestMappingHandlerAdapter.class);
|
.isNotInstanceOf(MyRequestMappingHandlerAdapter.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultLogResolvedException() {
|
public void defaultLogResolvedException() {
|
||||||
this.context.run(assertExceptionResolverWarnLoggers(
|
this.contextRunner.run(assertExceptionResolverWarnLoggers(
|
||||||
(logger) -> assertThat(logger).isNull()));
|
(logger) -> assertThat(logger).isNull()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customLogResolvedException() {
|
public void customLogResolvedException() {
|
||||||
this.context.withPropertyValues("spring.mvc.log-resolved-exception:true")
|
this.contextRunner.withPropertyValues("spring.mvc.log-resolved-exception:true")
|
||||||
.run(assertExceptionResolverWarnLoggers(
|
.run(assertExceptionResolverWarnLoggers(
|
||||||
(logger) -> assertThat(logger).isNotNull()));
|
(logger) -> assertThat(logger).isNotNull()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContextConsumer<AssertableWebApplicationContext> assertExceptionResolverWarnLoggers(
|
private ContextConsumer<AssertableWebApplicationContext> assertExceptionResolverWarnLoggers(
|
||||||
Consumer<Object> consumer) {
|
Consumer<Object> consumer) {
|
||||||
return (loaded) -> {
|
return (context) -> {
|
||||||
HandlerExceptionResolver resolver = loaded
|
HandlerExceptionResolver resolver = context
|
||||||
.getBean(HandlerExceptionResolver.class);
|
.getBean(HandlerExceptionResolver.class);
|
||||||
assertThat(resolver).isInstanceOf(HandlerExceptionResolverComposite.class);
|
assertThat(resolver).isInstanceOf(HandlerExceptionResolverComposite.class);
|
||||||
List<HandlerExceptionResolver> delegates = ((HandlerExceptionResolverComposite) resolver)
|
List<HandlerExceptionResolver> delegates = ((HandlerExceptionResolverComposite) resolver)
|
||||||
|
|
@ -567,12 +576,12 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void welcomePageMappingProducesNotFoundResponseWhenThereIsNoWelcomePage() {
|
public void welcomePageMappingProducesNotFoundResponseWhenThereIsNoWelcomePage() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.resources.static-locations:classpath:/no-welcome-page/")
|
"spring.resources.static-locations:classpath:/no-welcome-page/")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).hasSingleBean(WelcomePageHandlerMapping.class);
|
assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
|
||||||
MockMvcBuilders.webAppContextSetup(loaded).build()
|
MockMvcBuilders.webAppContextSetup(context).build()
|
||||||
.perform(get("/").accept(MediaType.TEXT_HTML))
|
.perform(get("/").accept(MediaType.TEXT_HTML))
|
||||||
.andExpect(status().isNotFound());
|
.andExpect(status().isNotFound());
|
||||||
});
|
});
|
||||||
|
|
@ -580,23 +589,23 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void welcomePageRootHandlerIsNotRegisteredWhenStaticPathPatternIsNotSlashStarStar() {
|
public void welcomePageRootHandlerIsNotRegisteredWhenStaticPathPatternIsNotSlashStarStar() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.resources.static-locations:classpath:/welcome-page/",
|
"spring.resources.static-locations:classpath:/welcome-page/",
|
||||||
"spring.mvc.static-path-pattern:/foo/**")
|
"spring.mvc.static-path-pattern:/foo/**")
|
||||||
.run((loaded) -> assertThat(
|
.run((context) -> assertThat(
|
||||||
loaded.getBean(WelcomePageHandlerMapping.class).getRootHandler())
|
context.getBean(WelcomePageHandlerMapping.class).getRootHandler())
|
||||||
.isNull());
|
.isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void welcomePageMappingHandlesRequestsThatAcceptTextHtml() {
|
public void welcomePageMappingHandlesRequestsThatAcceptTextHtml() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.resources.static-locations:classpath:/welcome-page/")
|
"spring.resources.static-locations:classpath:/welcome-page/")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).hasSingleBean(WelcomePageHandlerMapping.class);
|
assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(loaded).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
|
||||||
mockMvc.perform(get("/").accept(MediaType.TEXT_HTML))
|
mockMvc.perform(get("/").accept(MediaType.TEXT_HTML))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(forwardedUrl("index.html"));
|
.andExpect(forwardedUrl("index.html"));
|
||||||
|
|
@ -607,12 +616,12 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void welcomePageMappingDoesNotHandleRequestsThatDoNotAcceptTextHtml() {
|
public void welcomePageMappingDoesNotHandleRequestsThatDoNotAcceptTextHtml() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.resources.static-locations:classpath:/welcome-page/")
|
"spring.resources.static-locations:classpath:/welcome-page/")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).hasSingleBean(WelcomePageHandlerMapping.class);
|
assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(loaded).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
|
||||||
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
|
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
|
||||||
.andExpect(status().isNotFound());
|
.andExpect(status().isNotFound());
|
||||||
});
|
});
|
||||||
|
|
@ -620,12 +629,12 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void welcomePageMappingHandlesRequestsWithNoAcceptHeader() {
|
public void welcomePageMappingHandlesRequestsWithNoAcceptHeader() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.resources.static-locations:classpath:/welcome-page/")
|
"spring.resources.static-locations:classpath:/welcome-page/")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).hasSingleBean(WelcomePageHandlerMapping.class);
|
assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(loaded).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
|
||||||
mockMvc.perform(get("/")).andExpect(status().isOk())
|
mockMvc.perform(get("/")).andExpect(status().isOk())
|
||||||
.andExpect(forwardedUrl("index.html"));
|
.andExpect(forwardedUrl("index.html"));
|
||||||
});
|
});
|
||||||
|
|
@ -634,12 +643,12 @@ public class WebMvcAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void welcomePageMappingHandlesRequestsWithEmptyAcceptHeader()
|
public void welcomePageMappingHandlesRequestsWithEmptyAcceptHeader()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.resources.static-locations:classpath:/welcome-page/")
|
"spring.resources.static-locations:classpath:/welcome-page/")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).hasSingleBean(WelcomePageHandlerMapping.class);
|
assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(loaded).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
|
||||||
mockMvc.perform(get("/").header(HttpHeaders.ACCEPT, ""))
|
mockMvc.perform(get("/").header(HttpHeaders.ACCEPT, ""))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(forwardedUrl("index.html"));
|
.andExpect(forwardedUrl("index.html"));
|
||||||
|
|
@ -649,12 +658,12 @@ public class WebMvcAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void welcomePageMappingWorksWithNoTrailingSlashOnResourceLocation()
|
public void welcomePageMappingWorksWithNoTrailingSlashOnResourceLocation()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"spring.resources.static-locations:classpath:/welcome-page")
|
"spring.resources.static-locations:classpath:/welcome-page")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).hasSingleBean(WelcomePageHandlerMapping.class);
|
assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(loaded).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
|
||||||
mockMvc.perform(get("/").accept(MediaType.TEXT_HTML))
|
mockMvc.perform(get("/").accept(MediaType.TEXT_HTML))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(forwardedUrl("index.html"));
|
.andExpect(forwardedUrl("index.html"));
|
||||||
|
|
@ -664,121 +673,128 @@ public class WebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validatorWhenNoValidatorShouldUseDefault() {
|
public void validatorWhenNoValidatorShouldUseDefault() {
|
||||||
this.context.run((loaded) -> {
|
this.contextRunner.run((context) -> {
|
||||||
assertThat(loaded).doesNotHaveBean(ValidatorFactory.class);
|
assertThat(context).doesNotHaveBean(ValidatorFactory.class);
|
||||||
assertThat(loaded).doesNotHaveBean(javax.validation.Validator.class);
|
assertThat(context).doesNotHaveBean(javax.validation.Validator.class);
|
||||||
assertThat(loaded).getBeanNames(Validator.class).containsOnly("mvcValidator");
|
assertThat(context).getBeanNames(Validator.class)
|
||||||
|
.containsOnly("mvcValidator");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validatorWhenNoCustomizationShouldUseAutoConfigured() {
|
public void validatorWhenNoCustomizationShouldUseAutoConfigured() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(ValidationAutoConfiguration.class))
|
AutoConfigurations.of(ValidationAutoConfiguration.class))
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getBeanNames(javax.validation.Validator.class)
|
assertThat(context).getBeanNames(javax.validation.Validator.class)
|
||||||
.containsOnly("defaultValidator");
|
.containsOnly("defaultValidator");
|
||||||
assertThat(loaded).getBeanNames(Validator.class)
|
assertThat(context).getBeanNames(Validator.class)
|
||||||
.containsOnly("defaultValidator", "mvcValidator");
|
.containsOnly("defaultValidator", "mvcValidator");
|
||||||
Validator validator = loaded.getBean("mvcValidator", Validator.class);
|
Validator validator = context.getBean("mvcValidator",
|
||||||
|
Validator.class);
|
||||||
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
|
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
|
||||||
Object defaultValidator = loaded.getBean("defaultValidator");
|
Object defaultValidator = context.getBean("defaultValidator");
|
||||||
assertThat(((ValidatorAdapter) validator).getTarget())
|
assertThat(((ValidatorAdapter) validator).getTarget())
|
||||||
.isSameAs(defaultValidator);
|
.isSameAs(defaultValidator);
|
||||||
// Primary Spring validator is the one used by MVC behind the scenes
|
// Primary Spring validator is the one used by MVC behind the scenes
|
||||||
assertThat(loaded.getBean(Validator.class))
|
assertThat(context.getBean(Validator.class))
|
||||||
.isEqualTo(defaultValidator);
|
.isEqualTo(defaultValidator);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validatorWithConfigurerShouldUseSpringValidator() {
|
public void validatorWithConfigurerShouldUseSpringValidator() {
|
||||||
this.context.withUserConfiguration(MvcValidator.class).run((loaded) -> {
|
this.contextRunner.withUserConfiguration(MvcValidator.class).run((context) -> {
|
||||||
assertThat(loaded).doesNotHaveBean(ValidatorFactory.class);
|
assertThat(context).doesNotHaveBean(ValidatorFactory.class);
|
||||||
assertThat(loaded).doesNotHaveBean(javax.validation.Validator.class);
|
assertThat(context).doesNotHaveBean(javax.validation.Validator.class);
|
||||||
assertThat(loaded).getBeanNames(Validator.class).containsOnly("mvcValidator");
|
assertThat(context).getBeanNames(Validator.class)
|
||||||
assertThat(loaded.getBean("mvcValidator"))
|
.containsOnly("mvcValidator");
|
||||||
.isSameAs(loaded.getBean(MvcValidator.class).validator);
|
assertThat(context.getBean("mvcValidator"))
|
||||||
|
.isSameAs(context.getBean(MvcValidator.class).validator);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validatorWithConfigurerDoesNotExposeJsr303() {
|
public void validatorWithConfigurerDoesNotExposeJsr303() {
|
||||||
this.context.withUserConfiguration(MvcJsr303Validator.class).run((loaded) -> {
|
this.contextRunner.withUserConfiguration(MvcJsr303Validator.class)
|
||||||
assertThat(loaded).doesNotHaveBean(ValidatorFactory.class);
|
.run((context) -> {
|
||||||
assertThat(loaded).doesNotHaveBean(javax.validation.Validator.class);
|
assertThat(context).doesNotHaveBean(ValidatorFactory.class);
|
||||||
assertThat(loaded).getBeanNames(Validator.class).containsOnly("mvcValidator");
|
assertThat(context).doesNotHaveBean(javax.validation.Validator.class);
|
||||||
Validator validator = loaded.getBean("mvcValidator", Validator.class);
|
assertThat(context).getBeanNames(Validator.class)
|
||||||
|
.containsOnly("mvcValidator");
|
||||||
|
Validator validator = context.getBean("mvcValidator",
|
||||||
|
Validator.class);
|
||||||
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
|
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
|
||||||
assertThat(((ValidatorAdapter) validator).getTarget())
|
assertThat(((ValidatorAdapter) validator).getTarget()).isSameAs(
|
||||||
.isSameAs(loaded.getBean(MvcJsr303Validator.class).validator);
|
context.getBean(MvcJsr303Validator.class).validator);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validatorWithConfigurerTakesPrecedence() {
|
public void validatorWithConfigurerTakesPrecedence() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(ValidationAutoConfiguration.class))
|
AutoConfigurations.of(ValidationAutoConfiguration.class))
|
||||||
.withUserConfiguration(MvcValidator.class).run((loaded) -> {
|
.withUserConfiguration(MvcValidator.class).run((context) -> {
|
||||||
assertThat(loaded).hasSingleBean(ValidatorFactory.class);
|
assertThat(context).hasSingleBean(ValidatorFactory.class);
|
||||||
assertThat(loaded).hasSingleBean(javax.validation.Validator.class);
|
assertThat(context).hasSingleBean(javax.validation.Validator.class);
|
||||||
assertThat(loaded).getBeanNames(Validator.class)
|
assertThat(context).getBeanNames(Validator.class)
|
||||||
.containsOnly("defaultValidator", "mvcValidator");
|
.containsOnly("defaultValidator", "mvcValidator");
|
||||||
assertThat(loaded.getBean("mvcValidator"))
|
assertThat(context.getBean("mvcValidator"))
|
||||||
.isSameAs(loaded.getBean(MvcValidator.class).validator);
|
.isSameAs(context.getBean(MvcValidator.class).validator);
|
||||||
// Primary Spring validator is the auto-configured one as the MVC one
|
// Primary Spring validator is the auto-configured one as the MVC one
|
||||||
// has been customized via a WebMvcConfigurer
|
// has been customized via a WebMvcConfigurer
|
||||||
assertThat(loaded.getBean(Validator.class))
|
assertThat(context.getBean(Validator.class))
|
||||||
.isEqualTo(loaded.getBean("defaultValidator"));
|
.isEqualTo(context.getBean("defaultValidator"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validatorWithCustomSpringValidatorIgnored() {
|
public void validatorWithCustomSpringValidatorIgnored() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(ValidationAutoConfiguration.class))
|
AutoConfigurations.of(ValidationAutoConfiguration.class))
|
||||||
.withUserConfiguration(CustomSpringValidator.class).run((loaded) -> {
|
.withUserConfiguration(CustomSpringValidator.class).run((context) -> {
|
||||||
assertThat(loaded).getBeanNames(javax.validation.Validator.class)
|
assertThat(context).getBeanNames(javax.validation.Validator.class)
|
||||||
.containsOnly("defaultValidator");
|
.containsOnly("defaultValidator");
|
||||||
assertThat(loaded).getBeanNames(Validator.class).containsOnly(
|
assertThat(context).getBeanNames(Validator.class).containsOnly(
|
||||||
"customSpringValidator", "defaultValidator", "mvcValidator");
|
"customSpringValidator", "defaultValidator", "mvcValidator");
|
||||||
Validator validator = loaded.getBean("mvcValidator", Validator.class);
|
Validator validator = context.getBean("mvcValidator",
|
||||||
|
Validator.class);
|
||||||
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
|
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
|
||||||
Object defaultValidator = loaded.getBean("defaultValidator");
|
Object defaultValidator = context.getBean("defaultValidator");
|
||||||
assertThat(((ValidatorAdapter) validator).getTarget())
|
assertThat(((ValidatorAdapter) validator).getTarget())
|
||||||
.isSameAs(defaultValidator);
|
.isSameAs(defaultValidator);
|
||||||
// Primary Spring validator is the one used by MVC behind the scenes
|
// Primary Spring validator is the one used by MVC behind the scenes
|
||||||
assertThat(loaded.getBean(Validator.class))
|
assertThat(context.getBean(Validator.class))
|
||||||
.isEqualTo(defaultValidator);
|
.isEqualTo(defaultValidator);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validatorWithCustomJsr303ValidatorExposedAsSpringValidator() {
|
public void validatorWithCustomJsr303ValidatorExposedAsSpringValidator() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(ValidationAutoConfiguration.class))
|
AutoConfigurations.of(ValidationAutoConfiguration.class))
|
||||||
.withUserConfiguration(CustomJsr303Validator.class).run((loaded) -> {
|
.withUserConfiguration(CustomJsr303Validator.class).run((context) -> {
|
||||||
assertThat(loaded).doesNotHaveBean(ValidatorFactory.class);
|
assertThat(context).doesNotHaveBean(ValidatorFactory.class);
|
||||||
assertThat(loaded).getBeanNames(javax.validation.Validator.class)
|
assertThat(context).getBeanNames(javax.validation.Validator.class)
|
||||||
.containsOnly("customJsr303Validator");
|
.containsOnly("customJsr303Validator");
|
||||||
assertThat(loaded).getBeanNames(Validator.class)
|
assertThat(context).getBeanNames(Validator.class)
|
||||||
.containsOnly("mvcValidator");
|
.containsOnly("mvcValidator");
|
||||||
Validator validator = loaded.getBean(Validator.class);
|
Validator validator = context.getBean(Validator.class);
|
||||||
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
|
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
|
||||||
Validator target = ((ValidatorAdapter) validator).getTarget();
|
Validator target = ((ValidatorAdapter) validator).getTarget();
|
||||||
assertThat(ReflectionTestUtils.getField(target, "targetValidator"))
|
assertThat(ReflectionTestUtils.getField(target, "targetValidator"))
|
||||||
.isSameAs(loaded.getBean("customJsr303Validator"));
|
.isSameAs(context.getBean("customJsr303Validator"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpMessageConverterThatUsesConversionServiceDoesNotCreateACycle() {
|
public void httpMessageConverterThatUsesConversionServiceDoesNotCreateACycle() {
|
||||||
this.context.withUserConfiguration(CustomHttpMessageConverter.class)
|
this.contextRunner.withUserConfiguration(CustomHttpMessageConverter.class)
|
||||||
.run((loaded) -> assertThat(loaded).hasNotFailed());
|
.run((context) -> assertThat(context).hasNotFailed());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String, List<Resource>> getFaviconMappingLocations(
|
protected Map<String, List<Resource>> getFaviconMappingLocations(
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.WebApplicationContextTester;
|
import org.springframework.boot.test.context.WebApplicationContextRunner;
|
||||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class WebServicesAutoConfigurationTests {
|
public class WebServicesAutoConfigurationTests {
|
||||||
|
|
||||||
private final WebApplicationContextTester context = new WebApplicationContextTester()
|
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(WebServicesAutoConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(WebServicesAutoConfiguration.class));
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
|
|
@ -48,15 +48,15 @@ public class WebServicesAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultConfiguration() {
|
public void defaultConfiguration() {
|
||||||
this.context.run((loaded) -> assertThat(loaded)
|
this.contextRunner.run((context) -> assertThat(context)
|
||||||
.hasSingleBean(ServletRegistrationBean.class));
|
.hasSingleBean(ServletRegistrationBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customPathMustBeginWithASlash() {
|
public void customPathMustBeginWithASlash() {
|
||||||
this.context.withPropertyValues("spring.webservices.path=invalid")
|
this.contextRunner.withPropertyValues("spring.webservices.path=invalid")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).getFailure()
|
assertThat(context).getFailure()
|
||||||
.isInstanceOf(BeanCreationException.class)
|
.isInstanceOf(BeanCreationException.class)
|
||||||
.hasMessageContaining(
|
.hasMessageContaining(
|
||||||
"Failed to bind properties under 'spring.webservices'");
|
"Failed to bind properties under 'spring.webservices'");
|
||||||
|
|
@ -65,21 +65,22 @@ public class WebServicesAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customPath() {
|
public void customPath() {
|
||||||
this.context.withPropertyValues("spring.webservices.path=/valid")
|
this.contextRunner.withPropertyValues("spring.webservices.path=/valid").run(
|
||||||
.run((loaded) -> assertThat(getUrlMappings(loaded)).contains("/valid/*"));
|
(context) -> assertThat(getUrlMappings(context)).contains("/valid/*"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customPathWithTrailingSlash() {
|
public void customPathWithTrailingSlash() {
|
||||||
this.context.withPropertyValues("spring.webservices.path=/valid/")
|
this.contextRunner.withPropertyValues("spring.webservices.path=/valid/").run(
|
||||||
.run((loaded) -> assertThat(getUrlMappings(loaded)).contains("/valid/*"));
|
(context) -> assertThat(getUrlMappings(context)).contains("/valid/*"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customLoadOnStartup() {
|
public void customLoadOnStartup() {
|
||||||
this.context.withPropertyValues("spring.webservices.servlet.load-on-startup=1")
|
this.contextRunner
|
||||||
.run((loaded) -> {
|
.withPropertyValues("spring.webservices.servlet.load-on-startup=1")
|
||||||
ServletRegistrationBean<?> registrationBean = loaded
|
.run((context) -> {
|
||||||
|
ServletRegistrationBean<?> registrationBean = context
|
||||||
.getBean(ServletRegistrationBean.class);
|
.getBean(ServletRegistrationBean.class);
|
||||||
assertThat(ReflectionTestUtils.getField(registrationBean,
|
assertThat(ReflectionTestUtils.getField(registrationBean,
|
||||||
"loadOnStartup")).isEqualTo(1);
|
"loadOnStartup")).isEqualTo(1);
|
||||||
|
|
@ -88,17 +89,17 @@ public class WebServicesAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customInitParameters() {
|
public void customInitParameters() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.withPropertyValues("spring.webservices.servlet.init.key1=value1",
|
.withPropertyValues("spring.webservices.servlet.init.key1=value1",
|
||||||
"spring.webservices.servlet.init.key2=value2")
|
"spring.webservices.servlet.init.key2=value2")
|
||||||
.run(loaded -> assertThat(
|
.run((context) -> assertThat(
|
||||||
getServletRegistrationBean(loaded).getInitParameters())
|
getServletRegistrationBean(context).getInitParameters())
|
||||||
.containsEntry("key1", "value1")
|
.containsEntry("key1", "value1")
|
||||||
.containsEntry("key2", "value2"));
|
.containsEntry("key2", "value2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<String> getUrlMappings(ApplicationContext loaded) {
|
private Collection<String> getUrlMappings(ApplicationContext context) {
|
||||||
return getServletRegistrationBean(loaded).getUrlMappings();
|
return getServletRegistrationBean(context).getUrlMappings();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServletRegistrationBean<?> getServletRegistrationBean(
|
private ServletRegistrationBean<?> getServletRegistrationBean(
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import javax.sql.DataSource;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
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.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
@ -38,24 +38,24 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class TestDatabaseAutoConfigurationTests {
|
public class TestDatabaseAutoConfigurationTests {
|
||||||
|
|
||||||
private final ApplicationContextTester context = new ApplicationContextTester()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
|
AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void replaceWithNoDataSourceAvailable() {
|
public void replaceWithNoDataSourceAvailable() {
|
||||||
this.context
|
this.contextRunner
|
||||||
.run((loaded) -> assertThat(loaded).doesNotHaveBean(DataSource.class));
|
.run((context) -> assertThat(context).doesNotHaveBean(DataSource.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void replaceWithUniqueDatabase() {
|
public void replaceWithUniqueDatabase() {
|
||||||
this.context.withUserConfiguration(ExistingDataSourceConfiguration.class)
|
this.contextRunner.withUserConfiguration(ExistingDataSourceConfiguration.class)
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
DataSource datasource = loaded.getBean(DataSource.class);
|
DataSource datasource = context.getBean(DataSource.class);
|
||||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
|
JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
|
||||||
jdbcTemplate.execute("create table example (id int, name varchar);");
|
jdbcTemplate.execute("create table example (id int, name varchar);");
|
||||||
this.context.run((secondContext) -> {
|
this.contextRunner.run((secondContext) -> {
|
||||||
DataSource anotherDatasource = secondContext
|
DataSource anotherDatasource = secondContext
|
||||||
.getBean(DataSource.class);
|
.getBean(DataSource.class);
|
||||||
JdbcTemplate anotherJdbcTemplate = new JdbcTemplate(
|
JdbcTemplate anotherJdbcTemplate = new JdbcTemplate(
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration;
|
import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.ApplicationContextTester;
|
import org.springframework.boot.test.context.ApplicationContextRunner;
|
||||||
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
|
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
|
||||||
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
|
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
@ -44,15 +44,15 @@ import static org.mockito.Mockito.mock;
|
||||||
@ClassPathExclusions({ "h2-*.jar", "hsqldb-*.jar", "derby-*.jar" })
|
@ClassPathExclusions({ "h2-*.jar", "hsqldb-*.jar", "derby-*.jar" })
|
||||||
public class TestDatabaseAutoConfigurationNoEmbeddedTests {
|
public class TestDatabaseAutoConfigurationNoEmbeddedTests {
|
||||||
|
|
||||||
private final ApplicationContextTester context = new ApplicationContextTester()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withUserConfiguration(ExistingDataSourceConfiguration.class)
|
.withUserConfiguration(ExistingDataSourceConfiguration.class)
|
||||||
.withConfiguration(
|
.withConfiguration(
|
||||||
AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
|
AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void applyAnyReplace() {
|
public void applyAnyReplace() {
|
||||||
this.context.run((loaded) -> {
|
this.contextRunner.run((context) -> {
|
||||||
assertThat(loaded).getFailure().isInstanceOf(BeanCreationException.class)
|
assertThat(context).getFailure().isInstanceOf(BeanCreationException.class)
|
||||||
.hasMessageContaining(
|
.hasMessageContaining(
|
||||||
"Failed to replace DataSource with an embedded database for tests.")
|
"Failed to replace DataSource with an embedded database for tests.")
|
||||||
.hasMessageContaining(
|
.hasMessageContaining(
|
||||||
|
|
@ -64,11 +64,11 @@ public class TestDatabaseAutoConfigurationNoEmbeddedTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void applyNoReplace() {
|
public void applyNoReplace() {
|
||||||
this.context.withPropertyValues("spring.test.database.replace=NONE")
|
this.contextRunner.withPropertyValues("spring.test.database.replace=NONE")
|
||||||
.run((loaded) -> {
|
.run((context) -> {
|
||||||
assertThat(loaded).hasSingleBean(DataSource.class);
|
assertThat(context).hasSingleBean(DataSource.class);
|
||||||
assertThat(loaded).getBean(DataSource.class)
|
assertThat(context).getBean(DataSource.class)
|
||||||
.isSameAs(loaded.getBean("myCustomDataSource"));
|
.isSameAs(context.getBean("myCustomDataSource"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,13 @@ import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tester utility design to manage the lifecycle of an {@link ApplicationContext} and
|
* Utility design to run and an {@link ApplicationContext} and provide AssertJ style
|
||||||
* provide AssertJ style assertions. The test is best used as a field of a test class,
|
* assertions. The test is best used as a field of a test class, describing the shared
|
||||||
* describing the shared configuration required for the test:
|
* configuration required for the test:
|
||||||
*
|
*
|
||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* public class MyContextTests {
|
* public class MyContextTests {
|
||||||
* private final ApplicationContextTester context = new ApplicationContextTester()
|
* private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
* .withPropertyValues("spring.foo=bar")
|
* .withPropertyValues("spring.foo=bar")
|
||||||
* .withUserConfiguration(MyConfiguration.class);
|
* .withUserConfiguration(MyConfiguration.class);
|
||||||
* }</pre>
|
* }</pre>
|
||||||
|
|
@ -55,8 +55,8 @@ import org.springframework.util.ReflectionUtils;
|
||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* @Test
|
* @Test
|
||||||
* public someTest() {
|
* public someTest() {
|
||||||
* this.context.withPropertyValues("spring.foo=biz").run((loaded) -> {
|
* this.contextRunner.withPropertyValues("spring.foo=biz").run((context) -> {
|
||||||
* assertThat(loaded).containsSingleBean(MyBean.class);
|
* assertThat(context).containsSingleBean(MyBean.class);
|
||||||
* // other assertions
|
* // other assertions
|
||||||
* });
|
* });
|
||||||
* }</pre>
|
* }</pre>
|
||||||
|
|
@ -80,19 +80,19 @@ import org.springframework.util.ReflectionUtils;
|
||||||
* }</pre>
|
* }</pre>
|
||||||
* <p>
|
* <p>
|
||||||
*
|
*
|
||||||
* @param <SELF> The "self" type for this tester
|
* @param <SELF> The "self" type for this runner
|
||||||
* @param <C> The context type
|
* @param <C> The context type
|
||||||
* @param <A> The application context assertion provider
|
* @param <A> The application context assertion provider
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @see ApplicationContextTester
|
* @see ApplicationContextRunner
|
||||||
* @see WebApplicationContextTester
|
* @see WebApplicationContextRunner
|
||||||
* @see ReactiveWebApplicationContextTester
|
* @see ReactiveWebApplicationContextRunner
|
||||||
* @see ApplicationContextAssert
|
* @see ApplicationContextAssert
|
||||||
*/
|
*/
|
||||||
abstract class AbstractApplicationContextTester<SELF extends AbstractApplicationContextTester<SELF, C, A>, C extends ConfigurableApplicationContext, A extends AssertProviderApplicationContext<C>> {
|
abstract class AbstractApplicationContextRunner<SELF extends AbstractApplicationContextRunner<SELF, C, A>, C extends ConfigurableApplicationContext, A extends AssertProviderApplicationContext<C>> {
|
||||||
|
|
||||||
private final Supplier<C> contextFactory;
|
private final Supplier<C> contextFactory;
|
||||||
|
|
||||||
|
|
@ -107,10 +107,10 @@ abstract class AbstractApplicationContextTester<SELF extends AbstractApplication
|
||||||
private final List<Configurations> configurations = new ArrayList<>();
|
private final List<Configurations> configurations = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link AbstractApplicationContextTester} instance.
|
* Create a new {@link AbstractApplicationContextRunner} instance.
|
||||||
* @param contextFactory the factory used to create the actual context
|
* @param contextFactory the factory used to create the actual context
|
||||||
*/
|
*/
|
||||||
protected AbstractApplicationContextTester(Supplier<C> contextFactory) {
|
protected AbstractApplicationContextRunner(Supplier<C> contextFactory) {
|
||||||
Assert.notNull(contextFactory, "ContextFactory must not be null");
|
Assert.notNull(contextFactory, "ContextFactory must not be null");
|
||||||
this.contextFactory = contextFactory;
|
this.contextFactory = contextFactory;
|
||||||
this.environmentProperties = TestPropertyValues.empty();
|
this.environmentProperties = TestPropertyValues.empty();
|
||||||
|
|
@ -243,7 +243,7 @@ abstract class AbstractApplicationContextTester<SELF extends AbstractApplication
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private A createAssertableContext() {
|
private A createAssertableContext() {
|
||||||
ResolvableType resolvableType = ResolvableType
|
ResolvableType resolvableType = ResolvableType
|
||||||
.forClass(AbstractApplicationContextTester.class, getClass());
|
.forClass(AbstractApplicationContextRunner.class, getClass());
|
||||||
Class<A> assertType = (Class<A>) resolvableType.resolveGeneric(1);
|
Class<A> assertType = (Class<A>) resolvableType.resolveGeneric(1);
|
||||||
Class<C> contextType = (Class<C>) resolvableType.resolveGeneric(2);
|
Class<C> contextType = (Class<C>) resolvableType.resolveGeneric(2);
|
||||||
return AssertProviderApplicationContext.get(assertType, contextType,
|
return AssertProviderApplicationContext.get(assertType, contextType,
|
||||||
|
|
@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @param <C> The application context type
|
* @param <C> The application context type
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @see ApplicationContextTester
|
* @see ApplicationContextRunner
|
||||||
* @see AssertableApplicationContext
|
* @see AssertableApplicationContext
|
||||||
*/
|
*/
|
||||||
public class ApplicationContextAssert<C extends ApplicationContext>
|
public class ApplicationContextAssert<C extends ApplicationContext>
|
||||||
|
|
|
||||||
|
|
@ -22,33 +22,33 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link AbstractApplicationContextTester ApplicationContext tester} for a standard,
|
* A {@link AbstractApplicationContextRunner ApplicationContext runner} for a standard,
|
||||||
* non-web environment {@link ConfigurableApplicationContext}.
|
* non-web environment {@link ConfigurableApplicationContext}.
|
||||||
* <p>
|
* <p>
|
||||||
* See {@link AbstractApplicationContextTester} for details.
|
* See {@link AbstractApplicationContextRunner} for details.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public class ApplicationContextTester extends
|
public class ApplicationContextRunner extends
|
||||||
AbstractApplicationContextTester<ApplicationContextTester, ConfigurableApplicationContext, AssertableApplicationContext> {
|
AbstractApplicationContextRunner<ApplicationContextRunner, ConfigurableApplicationContext, AssertableApplicationContext> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link ApplicationContextTester} instance using an
|
* Create a new {@link ApplicationContextRunner} instance using an
|
||||||
* {@link AnnotationConfigApplicationContext} as the underlying source.
|
* {@link AnnotationConfigApplicationContext} as the underlying source.
|
||||||
*/
|
*/
|
||||||
public ApplicationContextTester() {
|
public ApplicationContextRunner() {
|
||||||
this(AnnotationConfigApplicationContext::new);
|
this(AnnotationConfigApplicationContext::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link ApplicationContextTester} instance using the specified
|
* Create a new {@link ApplicationContextRunner} instance using the specified
|
||||||
* {@code contextFactory} as the underlying source.
|
* {@code contextFactory} as the underlying source.
|
||||||
* @param contextFactory a supplier that returns a new instance on each call
|
* @param contextFactory a supplier that returns a new instance on each call
|
||||||
*/
|
*/
|
||||||
public ApplicationContextTester(
|
public ApplicationContextRunner(
|
||||||
Supplier<ConfigurableApplicationContext> contextFactory) {
|
Supplier<ConfigurableApplicationContext> contextFactory) {
|
||||||
super(contextFactory);
|
super(contextFactory);
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +30,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @see ApplicationContextTester
|
* @see ApplicationContextRunner
|
||||||
* @see ApplicationContext
|
* @see ApplicationContext
|
||||||
*/
|
*/
|
||||||
public interface AssertableApplicationContext
|
public interface AssertableApplicationContext
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @see WebApplicationContextTester
|
* @see WebApplicationContextRunner
|
||||||
* @see WebApplicationContext
|
* @see WebApplicationContext
|
||||||
*/
|
*/
|
||||||
public interface AssertableWebApplicationContext
|
public interface AssertableWebApplicationContext
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import org.springframework.context.ApplicationContext;
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @param <C> The application context type
|
* @param <C> The application context type
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @see AbstractApplicationContextTester
|
* @see AbstractApplicationContextRunner
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ContextConsumer<C extends ApplicationContext> {
|
public interface ContextConsumer<C extends ApplicationContext> {
|
||||||
|
|
|
||||||
|
|
@ -22,33 +22,33 @@ import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebAppl
|
||||||
import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext;
|
import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link AbstractApplicationContextTester ApplicationContext tester} for a
|
* A {@link AbstractApplicationContextRunner ApplicationContext runner} for a
|
||||||
* {@link ConfigurableReactiveWebApplicationContext}.
|
* {@link ConfigurableReactiveWebApplicationContext}.
|
||||||
* <p>
|
* <p>
|
||||||
* See {@link AbstractApplicationContextTester} for details.
|
* See {@link AbstractApplicationContextRunner} for details.
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public final class ReactiveWebApplicationContextTester extends
|
public final class ReactiveWebApplicationContextRunner extends
|
||||||
AbstractApplicationContextTester<ReactiveWebApplicationContextTester, ConfigurableReactiveWebApplicationContext, AssertableReactiveWebApplicationContext> {
|
AbstractApplicationContextRunner<ReactiveWebApplicationContextRunner, ConfigurableReactiveWebApplicationContext, AssertableReactiveWebApplicationContext> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link ReactiveWebApplicationContextTester} instance using a
|
* Create a new {@link ReactiveWebApplicationContextRunner} instance using a
|
||||||
* {@link GenericReactiveWebApplicationContext} as the underlying source.
|
* {@link GenericReactiveWebApplicationContext} as the underlying source.
|
||||||
*/
|
*/
|
||||||
public ReactiveWebApplicationContextTester() {
|
public ReactiveWebApplicationContextRunner() {
|
||||||
this(GenericReactiveWebApplicationContext::new);
|
this(GenericReactiveWebApplicationContext::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link ApplicationContextTester} instance using the specified
|
* Create a new {@link ApplicationContextRunner} instance using the specified
|
||||||
* {@code contextFactory} as the underlying source.
|
* {@code contextFactory} as the underlying source.
|
||||||
* @param contextFactory a supplier that returns a new instance on each call
|
* @param contextFactory a supplier that returns a new instance on each call
|
||||||
*/
|
*/
|
||||||
public ReactiveWebApplicationContextTester(
|
public ReactiveWebApplicationContextRunner(
|
||||||
Supplier<ConfigurableReactiveWebApplicationContext> contextFactory) {
|
Supplier<ConfigurableReactiveWebApplicationContext> contextFactory) {
|
||||||
super(contextFactory);
|
super(contextFactory);
|
||||||
}
|
}
|
||||||
|
|
@ -24,35 +24,35 @@ import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link AbstractApplicationContextTester ApplicationContext tester} for a Servlet
|
* A {@link AbstractApplicationContextRunner ApplicationContext runner} for a Servlet
|
||||||
* based {@link ConfigurableWebApplicationContext}.
|
* based {@link ConfigurableWebApplicationContext}.
|
||||||
* <p>
|
* <p>
|
||||||
* See {@link AbstractApplicationContextTester} for details.
|
* See {@link AbstractApplicationContextRunner} for details.
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public final class WebApplicationContextTester extends
|
public final class WebApplicationContextRunner extends
|
||||||
AbstractApplicationContextTester<WebApplicationContextTester, ConfigurableWebApplicationContext, AssertableWebApplicationContext> {
|
AbstractApplicationContextRunner<WebApplicationContextRunner, ConfigurableWebApplicationContext, AssertableWebApplicationContext> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link WebApplicationContextTester} instance using an
|
* Create a new {@link WebApplicationContextRunner} instance using an
|
||||||
* {@link AnnotationConfigWebApplicationContext} with a {@link MockServletContext} as
|
* {@link AnnotationConfigWebApplicationContext} with a {@link MockServletContext} as
|
||||||
* the underlying source.
|
* the underlying source.
|
||||||
* @see #withMockServletContext(Supplier)
|
* @see #withMockServletContext(Supplier)
|
||||||
*/
|
*/
|
||||||
public WebApplicationContextTester() {
|
public WebApplicationContextRunner() {
|
||||||
this(withMockServletContext(AnnotationConfigWebApplicationContext::new));
|
this(withMockServletContext(AnnotationConfigWebApplicationContext::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link WebApplicationContextTester} instance using the specified
|
* Create a new {@link WebApplicationContextRunner} instance using the specified
|
||||||
* {@code contextFactory} as the underlying source.
|
* {@code contextFactory} as the underlying source.
|
||||||
* @param contextFactory a supplier that returns a new instance on each call
|
* @param contextFactory a supplier that returns a new instance on each call
|
||||||
*/
|
*/
|
||||||
public WebApplicationContextTester(
|
public WebApplicationContextRunner(
|
||||||
Supplier<ConfigurableWebApplicationContext> contextFactory) {
|
Supplier<ConfigurableWebApplicationContext> contextFactory) {
|
||||||
super(contextFactory);
|
super(contextFactory);
|
||||||
}
|
}
|
||||||
|
|
@ -34,15 +34,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.fail;
|
import static org.assertj.core.api.Assertions.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract tests for {@link AbstractApplicationContextTester} implementations.
|
* Abstract tests for {@link AbstractApplicationContextRunner} implementations.
|
||||||
*
|
*
|
||||||
* @param <T> The tester type
|
* @param <T> The runner type
|
||||||
* @param <C> the context type
|
* @param <C> the context type
|
||||||
* @param <A> the assertable context type
|
* @param <A> the assertable context type
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractApplicationContextTesterTests<T extends AbstractApplicationContextTester<T, C, A>, C extends ConfigurableApplicationContext, A extends AssertProviderApplicationContext<C>> {
|
public abstract class AbstractApplicationContextRunnerTests<T extends AbstractApplicationContextRunner<T, C, A>, C extends ConfigurableApplicationContext, A extends AssertProviderApplicationContext<C>> {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
@ -19,17 +19,17 @@ package org.springframework.boot.test.context;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ApplicationContextTester}.
|
* Tests for {@link ApplicationContextRunner}.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
*/
|
*/
|
||||||
public class ApplicationContextTesterTests extends
|
public class ApplicationContextRunnerTests extends
|
||||||
AbstractApplicationContextTesterTests<ApplicationContextTester, ConfigurableApplicationContext, AssertableApplicationContext> {
|
AbstractApplicationContextRunnerTests<ApplicationContextRunner, ConfigurableApplicationContext, AssertableApplicationContext> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ApplicationContextTester get() {
|
protected ApplicationContextRunner get() {
|
||||||
return new ApplicationContextTester();
|
return new ApplicationContextRunner();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -19,17 +19,17 @@ package org.springframework.boot.test.context;
|
||||||
import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebApplicationContext;
|
import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ReactiveWebApplicationContextTester}.
|
* Tests for {@link ReactiveWebApplicationContextRunner}.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
*/
|
*/
|
||||||
public class ReactiveWebApplicationContextTesterTests extends
|
public class ReactiveWebApplicationContextRunnerTests extends
|
||||||
AbstractApplicationContextTesterTests<ReactiveWebApplicationContextTester, ConfigurableReactiveWebApplicationContext, AssertableReactiveWebApplicationContext> {
|
AbstractApplicationContextRunnerTests<ReactiveWebApplicationContextRunner, ConfigurableReactiveWebApplicationContext, AssertableReactiveWebApplicationContext> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReactiveWebApplicationContextTester get() {
|
protected ReactiveWebApplicationContextRunner get() {
|
||||||
return new ReactiveWebApplicationContextTester();
|
return new ReactiveWebApplicationContextRunner();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -24,13 +24,13 @@ import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link WebApplicationContextTester}.
|
* Tests for {@link WebApplicationContextRunner}.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
*/
|
*/
|
||||||
public class WebApplicationContextTesterTests extends
|
public class WebApplicationContextRunnerTests extends
|
||||||
AbstractApplicationContextTesterTests<WebApplicationContextTester, ConfigurableWebApplicationContext, AssertableWebApplicationContext> {
|
AbstractApplicationContextRunnerTests<WebApplicationContextRunner, ConfigurableWebApplicationContext, AssertableWebApplicationContext> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextShouldHaveMockServletContext() throws Exception {
|
public void contextShouldHaveMockServletContext() throws Exception {
|
||||||
|
|
@ -39,8 +39,8 @@ public class WebApplicationContextTesterTests extends
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected WebApplicationContextTester get() {
|
protected WebApplicationContextRunner get() {
|
||||||
return new WebApplicationContextTester();
|
return new WebApplicationContextRunner();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue