Polish cassandra tests

See gh-18019
pull/19578/head
Stephane Nicoll 5 years ago
parent 91151e0aac
commit bc066d279b

@ -29,9 +29,7 @@ import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.test.util.TestPropertyValues;
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.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
import org.springframework.data.cassandra.core.CassandraTemplate; import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions; import org.springframework.data.cassandra.core.convert.CassandraCustomConversions;
@ -63,7 +61,7 @@ class CassandraDataAutoConfigurationTests {
@Test @Test
void templateExists() { void templateExists() {
load(TestExcludeConfiguration.class); load(TestConfiguration.class);
assertThat(this.context.getBeanNamesForType(CassandraTemplate.class)).hasSize(1); assertThat(this.context.getBeanNamesForType(CassandraTemplate.class)).hasSize(1);
} }
@ -117,13 +115,6 @@ class CassandraDataAutoConfigurationTests {
this.context = ctx; this.context = ctx;
} }
@Configuration(proxyBeanMethods = false)
@ComponentScan(
excludeFilters = @ComponentScan.Filter(classes = { Session.class }, type = FilterType.ASSIGNABLE_TYPE))
static class TestExcludeConfiguration {
}
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
static class TestConfiguration { static class TestConfiguration {

@ -33,11 +33,7 @@ import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.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.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.cassandra.ReactiveSession;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext; import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories; import org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
@ -71,16 +67,15 @@ class CassandraReactiveRepositoriesAutoConfigurationTests {
@Test @Test
void testNoRepositoryConfiguration() { void testNoRepositoryConfiguration() {
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, EmptyConfiguration.class) this.contextRunner.withUserConfiguration(TestConfiguration.class, EmptyConfiguration.class).run((context) -> {
.run((context) -> { assertThat(context).hasSingleBean(Cluster.class);
assertThat(context).hasSingleBean(Cluster.class); assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class);
assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class); });
});
} }
@Test @Test
void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, CustomizedConfiguration.class) this.contextRunner.withUserConfiguration(TestConfiguration.class, CustomizedConfiguration.class)
.run((context) -> { .run((context) -> {
assertThat(context).hasSingleBean(ReactiveCityCassandraRepository.class); assertThat(context).hasSingleBean(ReactiveCityCassandraRepository.class);
assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class); assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class);
@ -131,10 +126,4 @@ class CassandraReactiveRepositoriesAutoConfigurationTests {
} }
@Configuration(proxyBeanMethods = false)
@ComponentScan(excludeFilters = @Filter(classes = { ReactiveSession.class }, type = FilterType.ASSIGNABLE_TYPE))
static class TestExcludeConfiguration {
}
} }

@ -33,9 +33,8 @@ import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType; import org.springframework.context.annotation.Import;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext; import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
@ -58,7 +57,7 @@ class CassandraRepositoriesAutoConfigurationTests {
@Test @Test
void testDefaultRepositoryConfiguration() { void testDefaultRepositoryConfiguration() {
this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(DefaultConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(CityRepository.class); assertThat(context).hasSingleBean(CityRepository.class);
assertThat(context).hasSingleBean(Cluster.class); assertThat(context).hasSingleBean(Cluster.class);
assertThat(getInitialEntitySet(context)).hasSize(1); assertThat(getInitialEntitySet(context)).hasSize(1);
@ -67,32 +66,30 @@ class CassandraRepositoriesAutoConfigurationTests {
@Test @Test
void testNoRepositoryConfiguration() { void testNoRepositoryConfiguration() {
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, EmptyConfiguration.class) this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> {
.run((context) -> { assertThat(context).hasSingleBean(Cluster.class);
assertThat(context).hasSingleBean(Cluster.class); assertThat(getInitialEntitySet(context)).isEmpty();
assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class); });
});
} }
@Test @Test
void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, CustomizedConfiguration.class) this.contextRunner.withUserConfiguration(CustomizedConfiguration.class).run((context) -> {
.run((context) -> { assertThat(context).hasSingleBean(CityCassandraRepository.class);
assertThat(context).hasSingleBean(CityCassandraRepository.class); assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class);
assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class); });
});
} }
@Test @Test
void enablingReactiveRepositoriesDisablesImperativeRepositories() { void enablingReactiveRepositoriesDisablesImperativeRepositories() {
this.contextRunner.withUserConfiguration(TestConfiguration.class) this.contextRunner.withUserConfiguration(DefaultConfiguration.class)
.withPropertyValues("spring.data.cassandra.repositories.type=reactive") .withPropertyValues("spring.data.cassandra.repositories.type=reactive")
.run((context) -> assertThat(context).doesNotHaveBean(CityCassandraRepository.class)); .run((context) -> assertThat(context).doesNotHaveBean(CityCassandraRepository.class));
} }
@Test @Test
void enablingNoRepositoriesDisablesImperativeRepositories() { void enablingNoRepositoriesDisablesImperativeRepositories() {
this.contextRunner.withUserConfiguration(TestConfiguration.class) this.contextRunner.withUserConfiguration(DefaultConfiguration.class)
.withPropertyValues("spring.data.cassandra.repositories.type=none") .withPropertyValues("spring.data.cassandra.repositories.type=none")
.run((context) -> assertThat(context).doesNotHaveBean(CityCassandraRepository.class)); .run((context) -> assertThat(context).doesNotHaveBean(CityCassandraRepository.class));
} }
@ -104,7 +101,6 @@ class CassandraRepositoriesAutoConfigurationTests {
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(City.class)
static class TestConfiguration { static class TestConfiguration {
@Bean @Bean
@ -116,21 +112,23 @@ class CassandraRepositoriesAutoConfigurationTests {
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(EmptyDataPackage.class) @TestAutoConfigurationPackage(EmptyDataPackage.class)
@Import(TestConfiguration.class)
static class EmptyConfiguration { static class EmptyConfiguration {
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(CassandraRepositoriesAutoConfigurationTests.class) @TestAutoConfigurationPackage(City.class)
@EnableCassandraRepositories(basePackageClasses = CityCassandraRepository.class) @Import(TestConfiguration.class)
static class CustomizedConfiguration { static class DefaultConfiguration {
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ComponentScan( @TestAutoConfigurationPackage(CassandraRepositoriesAutoConfigurationTests.class)
excludeFilters = @ComponentScan.Filter(classes = { Session.class }, type = FilterType.ASSIGNABLE_TYPE)) @EnableCassandraRepositories(basePackageClasses = CityCassandraRepository.class)
static class TestExcludeConfiguration { @Import(TestConfiguration.class)
static class CustomizedConfiguration {
} }

Loading…
Cancel
Save