@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.data.cassandra ;
package org.springframework.boot.autoconfigure.data.cassandra ;
import java.util.Arrays ;
import java.util.Set ;
import java.util.Set ;
import com.datastax.driver.core.Session ;
import com.datastax.driver.core.Session ;
@ -26,13 +27,16 @@ import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfigurati
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration ;
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.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.ComponentScan ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.FilterType ;
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.CassandraTemplate ;
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions ;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext ;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext ;
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver ;
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver ;
import org.springframework.test.util.ReflectionTestUtils ;
import org.springframework.test.util.ReflectionTestUtils ;
@ -101,6 +105,22 @@ public class CassandraDataAutoConfigurationTests {
. isInstanceOf ( SimpleUserTypeResolver . class ) ;
. isInstanceOf ( SimpleUserTypeResolver . class ) ;
}
}
@Test
public void customConversions ( ) {
this . context = new AnnotationConfigApplicationContext ( ) ;
EnvironmentTestUtils . addEnvironment ( this . context ,
"spring.data.cassandra.keyspaceName:boot_test" ) ;
this . context . register ( CustomConversionConfig . class ,
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 ) ) . isTrue ( ) ;
}
@Configuration
@Configuration
@ComponentScan ( excludeFilters = @ComponentScan.Filter ( classes = {
@ComponentScan ( excludeFilters = @ComponentScan.Filter ( classes = {
Session . class } , type = FilterType . ASSIGNABLE_TYPE ) )
Session . class } , type = FilterType . ASSIGNABLE_TYPE ) )
@ -124,4 +144,26 @@ public class CassandraDataAutoConfigurationTests {
}
}
@Configuration
static class CustomConversionConfig {
@Bean
public CassandraCustomConversions cassandraCustomConversions ( ) {
return new CassandraCustomConversions ( Arrays . asList ( new MyConverter ( ) ) ) ;
}
}
private static class MyConverter implements Converter < Person , String > {
@Override
public String convert ( Person o ) {
return null ;
}
}
private static class Person {
}
}
}