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.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions;
@ -63,7 +61,7 @@ class CassandraDataAutoConfigurationTests {
@Test
void templateExists() {
load(TestExcludeConfiguration.class);
load(TestConfiguration.class);
assertThat(this.context.getBeanNamesForType(CassandraTemplate.class)).hasSize(1);
}
@ -117,13 +115,6 @@ class CassandraDataAutoConfigurationTests {
this.context = ctx;
}
@Configuration(proxyBeanMethods = false)
@ComponentScan(
excludeFilters = @ComponentScan.Filter(classes = { Session.class }, type = FilterType.ASSIGNABLE_TYPE))
static class TestExcludeConfiguration {
}
@Configuration(proxyBeanMethods = false)
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.context.ApplicationContext;
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.FilterType;
import org.springframework.data.cassandra.ReactiveSession;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories;
import org.springframework.test.util.ReflectionTestUtils;
@ -71,16 +67,15 @@ class CassandraReactiveRepositoriesAutoConfigurationTests {
@Test
void testNoRepositoryConfiguration() {
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, EmptyConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(Cluster.class);
assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class);
});
this.contextRunner.withUserConfiguration(TestConfiguration.class, EmptyConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(Cluster.class);
assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class);
});
}
@Test
void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, CustomizedConfiguration.class)
this.contextRunner.withUserConfiguration(TestConfiguration.class, CustomizedConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(ReactiveCityCassandraRepository.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.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
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.repository.config.EnableCassandraRepositories;
import org.springframework.test.util.ReflectionTestUtils;
@ -58,7 +57,7 @@ class CassandraRepositoriesAutoConfigurationTests {
@Test
void testDefaultRepositoryConfiguration() {
this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> {
this.contextRunner.withUserConfiguration(DefaultConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(CityRepository.class);
assertThat(context).hasSingleBean(Cluster.class);
assertThat(getInitialEntitySet(context)).hasSize(1);
@ -67,32 +66,30 @@ class CassandraRepositoriesAutoConfigurationTests {
@Test
void testNoRepositoryConfiguration() {
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, EmptyConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(Cluster.class);
assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class);
});
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(Cluster.class);
assertThat(getInitialEntitySet(context)).isEmpty();
});
}
@Test
void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, CustomizedConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(CityCassandraRepository.class);
assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class);
});
this.contextRunner.withUserConfiguration(CustomizedConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(CityCassandraRepository.class);
assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class);
});
}
@Test
void enablingReactiveRepositoriesDisablesImperativeRepositories() {
this.contextRunner.withUserConfiguration(TestConfiguration.class)
this.contextRunner.withUserConfiguration(DefaultConfiguration.class)
.withPropertyValues("spring.data.cassandra.repositories.type=reactive")
.run((context) -> assertThat(context).doesNotHaveBean(CityCassandraRepository.class));
}
@Test
void enablingNoRepositoriesDisablesImperativeRepositories() {
this.contextRunner.withUserConfiguration(TestConfiguration.class)
this.contextRunner.withUserConfiguration(DefaultConfiguration.class)
.withPropertyValues("spring.data.cassandra.repositories.type=none")
.run((context) -> assertThat(context).doesNotHaveBean(CityCassandraRepository.class));
}
@ -104,7 +101,6 @@ class CassandraRepositoriesAutoConfigurationTests {
}
@Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(City.class)
static class TestConfiguration {
@Bean
@ -116,21 +112,23 @@ class CassandraRepositoriesAutoConfigurationTests {
@Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(EmptyDataPackage.class)
@Import(TestConfiguration.class)
static class EmptyConfiguration {
}
@Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(CassandraRepositoriesAutoConfigurationTests.class)
@EnableCassandraRepositories(basePackageClasses = CityCassandraRepository.class)
static class CustomizedConfiguration {
@TestAutoConfigurationPackage(City.class)
@Import(TestConfiguration.class)
static class DefaultConfiguration {
}
@Configuration(proxyBeanMethods = false)
@ComponentScan(
excludeFilters = @ComponentScan.Filter(classes = { Session.class }, type = FilterType.ASSIGNABLE_TYPE))
static class TestExcludeConfiguration {
@TestAutoConfigurationPackage(CassandraRepositoriesAutoConfigurationTests.class)
@EnableCassandraRepositories(basePackageClasses = CityCassandraRepository.class)
@Import(TestConfiguration.class)
static class CustomizedConfiguration {
}

Loading…
Cancel
Save