|
|
@ -20,21 +20,15 @@ import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
import com.datastax.driver.core.Session;
|
|
|
|
import com.datastax.driver.core.Session;
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.Before;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.data.cassandra.city.City;
|
|
|
|
import org.springframework.boot.autoconfigure.data.cassandra.city.City;
|
|
|
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
|
|
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
|
|
|
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
|
|
|
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
|
|
|
import org.springframework.cassandra.core.session.ReactiveSession;
|
|
|
|
|
|
|
|
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.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.core.ReactiveCassandraTemplate;
|
|
|
|
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
|
|
|
|
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
|
|
|
|
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
|
|
|
|
import org.springframework.data.cassandra.mapping.SimpleUserTypeResolver;
|
|
|
|
import org.springframework.data.cassandra.mapping.SimpleUserTypeResolver;
|
|
|
@ -44,19 +38,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Tests for {@link ReactiveCassandraDataAutoConfiguration} that require a Cassandra instance.
|
|
|
|
* Tests for {@link ReactiveCassandraDataAutoConfiguration}.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Eddú Meléndez
|
|
|
|
* @author Eddú Meléndez
|
|
|
|
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class ReactiveCassandraDataAutoConfigurationTests {
|
|
|
|
public class ReactiveCassandraDataAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
private AnnotationConfigApplicationContext context;
|
|
|
|
private AnnotationConfigApplicationContext context;
|
|
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
|
|
|
public void setup() {
|
|
|
|
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
@After
|
|
|
|
public void close() {
|
|
|
|
public void close() {
|
|
|
|
if (this.context != null) {
|
|
|
|
if (this.context != null) {
|
|
|
@ -66,27 +56,15 @@ public class ReactiveCassandraDataAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void templateExists() {
|
|
|
|
public void templateExists() {
|
|
|
|
EnvironmentTestUtils.addEnvironment(this.context,
|
|
|
|
load("spring.data.cassandra.keyspaceName:boot_test");
|
|
|
|
"spring.data.cassandra.keyspaceName:boot_test");
|
|
|
|
assertThat(this.context.getBeanNamesForType(ReactiveCassandraTemplate.class))
|
|
|
|
this.context.register(TestExcludeConfiguration.class, TestConfiguration.class,
|
|
|
|
.hasSize(1);
|
|
|
|
PropertyPlaceholderAutoConfiguration.class,
|
|
|
|
|
|
|
|
CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
|
|
|
|
|
|
|
|
ReactiveCassandraDataAutoConfiguration.class);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
|
|
|
assertThat(this.context.getBeanNamesForType(ReactiveCassandraTemplate.class).length)
|
|
|
|
|
|
|
|
.isEqualTo(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void entityScanShouldSetInitialEntitySet() throws Exception {
|
|
|
|
public void entityScanShouldSetInitialEntitySet() throws Exception {
|
|
|
|
EnvironmentTestUtils.addEnvironment(this.context,
|
|
|
|
load(EntityScanConfig.class, "spring.data.cassandra.keyspaceName:boot_test");
|
|
|
|
"spring.data.cassandra.keyspaceName:boot_test");
|
|
|
|
|
|
|
|
this.context.register(TestConfiguration.class, EntityScanConfig.class,
|
|
|
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class,
|
|
|
|
|
|
|
|
CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
|
|
|
|
|
|
|
|
ReactiveCassandraDataAutoConfiguration.class);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
|
|
|
CassandraMappingContext mappingContext = this.context
|
|
|
|
CassandraMappingContext mappingContext = this.context
|
|
|
|
.getBean(CassandraMappingContext.class);
|
|
|
|
.getBean(CassandraMappingContext.class);
|
|
|
|
Set<Class<?>> initialEntitySet = (Set<Class<?>>) ReflectionTestUtils
|
|
|
|
Set<Class<?>> initialEntitySet = (Set<Class<?>>) ReflectionTestUtils
|
|
|
@ -96,24 +74,28 @@ public class ReactiveCassandraDataAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void userTypeResolverShouldBeSet() throws Exception {
|
|
|
|
public void userTypeResolverShouldBeSet() throws Exception {
|
|
|
|
EnvironmentTestUtils.addEnvironment(this.context,
|
|
|
|
load("spring.data.cassandra.keyspaceName:boot_test");
|
|
|
|
"spring.data.cassandra.keyspaceName:boot_test");
|
|
|
|
|
|
|
|
this.context.register(TestConfiguration.class,
|
|
|
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class,
|
|
|
|
|
|
|
|
CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
|
|
|
|
|
|
|
|
ReactiveCassandraDataAutoConfiguration.class);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
|
|
|
CassandraMappingContext mappingContext = this.context
|
|
|
|
CassandraMappingContext mappingContext = this.context
|
|
|
|
.getBean(CassandraMappingContext.class);
|
|
|
|
.getBean(CassandraMappingContext.class);
|
|
|
|
assertThat(ReflectionTestUtils.getField(mappingContext, "userTypeResolver"))
|
|
|
|
assertThat(ReflectionTestUtils.getField(mappingContext, "userTypeResolver"))
|
|
|
|
.isInstanceOf(SimpleUserTypeResolver.class);
|
|
|
|
.isInstanceOf(SimpleUserTypeResolver.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
private void load(String... environment) {
|
|
|
|
@ComponentScan(excludeFilters = @Filter(classes = {
|
|
|
|
load(null, environment);
|
|
|
|
ReactiveSession.class }, type = FilterType.ASSIGNABLE_TYPE))
|
|
|
|
}
|
|
|
|
static class TestExcludeConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void load(Class<?> config, String... environment) {
|
|
|
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
|
|
|
|
|
|
EnvironmentTestUtils.addEnvironment(ctx, environment);
|
|
|
|
|
|
|
|
if (config != null) {
|
|
|
|
|
|
|
|
ctx.register(config);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.register(TestConfiguration.class, CassandraAutoConfiguration.class,
|
|
|
|
|
|
|
|
CassandraDataAutoConfiguration.class,
|
|
|
|
|
|
|
|
ReactiveCassandraDataAutoConfiguration.class);
|
|
|
|
|
|
|
|
ctx.refresh();
|
|
|
|
|
|
|
|
this.context = ctx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|