Polish "Add support for CustomConversions with Cassandra"

Closes gh-8534
pull/9556/head
Stephane Nicoll 8 years ago
parent 744a1ed497
commit 49797b1153

@ -46,7 +46,6 @@ import org.springframework.data.cassandra.core.convert.CassandraCustomConversion
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
import org.springframework.data.convert.CustomConversions;
import org.springframework.util.StringUtils;
/**
@ -82,7 +81,8 @@ public class CassandraDataAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public CassandraMappingContext cassandraMapping(CustomConversions conversions) throws ClassNotFoundException {
public CassandraMappingContext cassandraMapping(
CassandraCustomConversions conversions) throws ClassNotFoundException {
CassandraMappingContext context = new CassandraMappingContext();
List<String> packages = EntityScanPackages.get(this.beanFactory)
.getPackageNames();
@ -103,7 +103,7 @@ public class CassandraDataAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public CassandraConverter cassandraConverter(CassandraMappingContext mapping,
CustomConversions conversions) {
CassandraCustomConversions conversions) {
MappingCassandraConverter converter = new MappingCassandraConverter(mapping);
converter.setCustomConversions(conversions);
return converter;
@ -132,7 +132,7 @@ public class CassandraDataAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public CustomConversions cassandraCustomConversions() {
public CassandraCustomConversions cassandraCustomConversions() {
return new CassandraCustomConversions(Collections.emptyList());
}

@ -16,7 +16,7 @@
package org.springframework.boot.autoconfigure.data.cassandra;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import com.datastax.driver.core.Session;
@ -27,7 +27,6 @@ import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfigurati
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.data.cassandra.city.City;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@ -105,11 +104,25 @@ public class CassandraDataAutoConfigurationTests {
.isInstanceOf(SimpleUserTypeResolver.class);
}
@Test
public void defaultConversions() {
this.context = new AnnotationConfigApplicationContext();
TestPropertyValues.of("spring.data.cassandra.keyspaceName:boot_test")
.applyTo(this.context);
this.context.register(TestConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class);
this.context.refresh();
CassandraTemplate template = this.context.getBean(CassandraTemplate.class);
assertThat(template.getConverter().getConversionService().canConvert(Person.class,
String.class)).isFalse();
}
@Test
public void customConversions() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.cassandra.keyspaceName:boot_test");
TestPropertyValues.of("spring.data.cassandra.keyspaceName:boot_test")
.applyTo(this.context);
this.context.register(CustomConversionConfig.class,
TestConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
@ -148,8 +161,9 @@ public class CassandraDataAutoConfigurationTests {
static class CustomConversionConfig {
@Bean
public CassandraCustomConversions cassandraCustomConversions() {
return new CassandraCustomConversions(Arrays.asList(new MyConverter()));
public CassandraCustomConversions myCassandraCustomConversions() {
return new CassandraCustomConversions(Collections.singletonList(
new MyConverter()));
}
}

Loading…
Cancel
Save