DATACMNS-1336 - Avoid warning logs for JodaTime and ThreeTenBP converter registrations.

Removed the explicit registration for JodaTime and ThreeTenBP to JSR-310 converters (originally introduced to support the unifying lookup of the last modified date in the auditing subsystem) as reading converters. This avoids the warning reporting that the source types (JodaTime and ThreeTenBP LocalDateTime) not being store-native types (which usually indicates a superfluous converter registration).

Updated the test cases to make sure these warnings aren't trigger due to test setups causing the same issue.
This commit is contained in:
Oliver Gierke
2018-06-06 13:07:38 +02:00
parent 5f87c67668
commit 0341f60c7c
3 changed files with 21 additions and 19 deletions

View File

@@ -37,6 +37,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.convert.ConverterBuilder.ConverterAware;
import org.springframework.data.convert.CustomConversions.StoreConversions;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.threeten.bp.LocalDateTime;
/**
@@ -166,7 +167,9 @@ public class CustomConversionsUnitTests {
@Test // DATAMONGO-1302, DATACMNS-1035
public void registersConverterFactoryCorrectly() {
CustomConversions customConversions = new CustomConversions(StoreConversions.NONE,
StoreConversions conversions = StoreConversions.of(new SimpleTypeHolder(Collections.singleton(Format.class), true));
CustomConversions customConversions = new CustomConversions(conversions,
Collections.singletonList(new FormatConverterFactory()));
assertThat(customConversions.getCustomWriteTarget(String.class, SimpleDateFormat.class)).isPresent();
@@ -175,19 +178,20 @@ public class CustomConversionsUnitTests {
@Test // DATACMNS-1034
public void registersConverterFromConverterAware() {
ConverterAware converters = ConverterBuilder.reading(Left.class, Right.class, left -> new Right())
.andWriting(right -> new Left());
ConverterAware converters = ConverterBuilder //
.reading(Locale.class, CustomType.class, left -> new CustomType()) //
.andWriting(right -> Locale.GERMAN);
CustomConversions conversions = new CustomConversions(StoreConversions.NONE, Collections.singletonList(converters));
assertThat(conversions.hasCustomWriteTarget(Right.class)).isTrue();
assertThat(conversions.hasCustomReadTarget(Left.class, Right.class)).isTrue();
assertThat(conversions.hasCustomWriteTarget(CustomType.class)).isTrue();
assertThat(conversions.hasCustomReadTarget(Locale.class, CustomType.class)).isTrue();
ConfigurableConversionService conversionService = new GenericConversionService();
conversions.registerConvertersIn(conversionService);
assertThat(conversionService.canConvert(Left.class, Right.class)).isTrue();
assertThat(conversionService.canConvert(Right.class, Left.class)).isTrue();
assertThat(conversionService.canConvert(CustomType.class, Locale.class)).isTrue();
assertThat(conversionService.canConvert(Locale.class, CustomType.class)).isTrue();
}
private static Class<?> createProxyTypeFor(Class<?> type) {
@@ -307,7 +311,5 @@ public class CustomConversionsUnitTests {
}
}
static class Left {}
static class Right {}
static class CustomType {}
}