JdbcOperationsSessionRepository uses ConversionService

Issue gh-364
This commit is contained in:
Rob Winch
2016-03-07 08:59:11 -06:00
parent cd38e307e0
commit 8f8cfe5d79
4 changed files with 46 additions and 71 deletions

View File

@@ -129,19 +129,11 @@ public class JdbcOperationsSessionRepositoryTests {
}
@Test
public void setSerializingConverterNull() {
public void setConversionServiceNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("SerializingConverter must not be null");
this.thrown.expectMessage("conversionService must not be null");
this.repository.setSerializingConverter(null);
}
@Test
public void setDeserializingConverterNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("DeserializingConverter must not be null");
this.repository.setDeserializingConverter(null);
this.repository.setConversionService(null);
}
@Test

View File

@@ -27,6 +27,7 @@ import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
import org.springframework.jdbc.support.lob.LobHandler;
import org.springframework.session.jdbc.JdbcOperationsSessionRepository;
@@ -123,33 +124,15 @@ public class JdbcHttpSessionConfigurationTests {
}
@Test
@SuppressWarnings("unchecked")
public void customSerializingConverterConfiguration() {
registerAndRefresh(CustomSerializingConverterConfiguration.class);
JdbcOperationsSessionRepository repository = this.context.getBean(JdbcOperationsSessionRepository.class);
Converter<Object, byte[]> serializingConverter =
(Converter<Object, byte[]>) this.context.getBean("springSessionSerializingConverter");
assertThat(repository).isNotNull();
assertThat(serializingConverter).isNotNull();
Converter<Object, byte[]> sc =
(Converter<Object, byte[]>) ReflectionTestUtils.getField(repository, "serializingConverter");
assertThat(sc).isEqualTo(serializingConverter);
}
@Test
@SuppressWarnings("unchecked")
public void customDeserializingConverterConfiguration() {
public void customConversionServiceConfiguration() {
registerAndRefresh(CustomDeserializingConverterConfiguration.class);
JdbcOperationsSessionRepository repository = this.context.getBean(JdbcOperationsSessionRepository.class);
Converter<byte[], Object> deserializingConverter =
(Converter<byte[], Object>) this.context.getBean("springSessionDeserializingConverter");
ConversionService conversionService = this.context.getBean("springSessionConversionService", ConversionService.class);
assertThat(repository).isNotNull();
assertThat(deserializingConverter).isNotNull();
Converter<byte[], Object> dc =
(Converter<byte[], Object>) ReflectionTestUtils.getField(repository, "deserializingConverter");
assertThat(dc).isEqualTo(deserializingConverter);
assertThat(conversionService).isNotNull();
Object repositoryConversionService = ReflectionTestUtils.getField(repository, "conversionService");
assertThat(repositoryConversionService).isEqualTo(conversionService);
}
private void registerAndRefresh(Class<?>... annotatedClasses) {
@@ -214,9 +197,8 @@ public class JdbcHttpSessionConfigurationTests {
static class CustomDeserializingConverterConfiguration extends BaseConfiguration {
@Bean
@SuppressWarnings("unchecked")
public Converter<byte[], Object> springSessionDeserializingConverter() {
return mock(Converter.class);
public ConversionService springSessionConversionService() {
return mock(ConversionService.class);
}
}