DATACMNS-1676 - Create shared conversion service for AuditableBeanWrapper.

Prevent performance penalty in creating conversion service each time a domain object is being persisted.

Original pull request: #432.
This commit is contained in:
Pavel Horal
2020-02-28 16:42:41 +01:00
committed by Mark Paluch
parent d9a1f65f05
commit f2f7886105
3 changed files with 45 additions and 30 deletions

View File

@@ -23,6 +23,7 @@ import java.time.ZoneOffset;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.auditing.DefaultAuditableBeanWrapperFactory.ReflectionAuditingBeanWrapper;
@@ -36,6 +37,7 @@ import org.springframework.data.convert.Jsr310Converters.LocalDateTimeToDateConv
*/
class ReflectionAuditingBeanWrapperUnitTests {
ConversionService conversionService;
AnnotationAuditingMetadata metadata;
AnnotatedUser user;
AuditableBeanWrapper wrapper;
@@ -44,9 +46,9 @@ class ReflectionAuditingBeanWrapperUnitTests {
@BeforeEach
void setUp() {
this.conversionService = DefaultAuditableBeanWrapperFactory.getDateConversionService();
this.user = new AnnotatedUser();
this.wrapper = new ReflectionAuditingBeanWrapper(user);
this.wrapper = new ReflectionAuditingBeanWrapper(conversionService, user);
}
@Test
@@ -74,7 +76,7 @@ class ReflectionAuditingBeanWrapperUnitTests {
}
Sample sample = new Sample();
AuditableBeanWrapper wrapper = new ReflectionAuditingBeanWrapper(sample);
AuditableBeanWrapper wrapper = new ReflectionAuditingBeanWrapper(conversionService, sample);
wrapper.setCreatedDate(time);
assertThat(sample.createdDate).isEqualTo(time.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli());