From 387b120dcbf10f5848a7beb9ec8d367df75a4a94 Mon Sep 17 00:00:00 2001 From: John Blum Date: Thu, 14 Dec 2017 18:33:59 -0800 Subject: [PATCH] DATAGEODE-74 - Extend SDG's GemfireSimpleTypeHolder to handle Java 8 Time types. --- .../model/GemfireSimpleTypeHolder.java | 38 ++++++++++++ .../GemfireSimpleTypeHolderUnitTests.java | 58 ++++++++++++++++--- 2 files changed, 88 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/springframework/data/gemfire/mapping/model/GemfireSimpleTypeHolder.java b/src/main/java/org/springframework/data/gemfire/mapping/model/GemfireSimpleTypeHolder.java index b1d3860f..29b2c8f8 100644 --- a/src/main/java/org/springframework/data/gemfire/mapping/model/GemfireSimpleTypeHolder.java +++ b/src/main/java/org/springframework/data/gemfire/mapping/model/GemfireSimpleTypeHolder.java @@ -18,6 +18,25 @@ package org.springframework.data.gemfire.mapping.model; import java.math.BigDecimal; import java.math.BigInteger; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.MonthDay; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.Period; +import java.time.Year; +import java.time.YearMonth; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.chrono.ChronoLocalDate; +import java.time.chrono.ChronoLocalDateTime; +import java.time.chrono.ChronoPeriod; +import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; +import java.time.chrono.Era; import java.util.HashSet; import java.util.Set; @@ -41,6 +60,25 @@ public class GemfireSimpleTypeHolder extends SimpleTypeHolder { static { CUSTOM_SIMPLE_TYPES.add(BigDecimal.class); CUSTOM_SIMPLE_TYPES.add(BigInteger.class); + CUSTOM_SIMPLE_TYPES.add(ChronoLocalDate.class); + CUSTOM_SIMPLE_TYPES.add(ChronoLocalDateTime.class); + CUSTOM_SIMPLE_TYPES.add(Chronology.class); + CUSTOM_SIMPLE_TYPES.add(ChronoPeriod.class); + CUSTOM_SIMPLE_TYPES.add(ChronoZonedDateTime.class); + CUSTOM_SIMPLE_TYPES.add(Duration.class); + CUSTOM_SIMPLE_TYPES.add(Era.class); + CUSTOM_SIMPLE_TYPES.add(Instant.class); + CUSTOM_SIMPLE_TYPES.add(LocalDate.class); + CUSTOM_SIMPLE_TYPES.add(LocalDateTime.class); + CUSTOM_SIMPLE_TYPES.add(LocalTime.class); + CUSTOM_SIMPLE_TYPES.add(MonthDay.class); + CUSTOM_SIMPLE_TYPES.add(OffsetDateTime.class); + CUSTOM_SIMPLE_TYPES.add(OffsetTime.class); + CUSTOM_SIMPLE_TYPES.add(Period.class); + CUSTOM_SIMPLE_TYPES.add(Year.class); + CUSTOM_SIMPLE_TYPES.add(YearMonth.class); + CUSTOM_SIMPLE_TYPES.add(ZonedDateTime.class); + CUSTOM_SIMPLE_TYPES.add(ZoneOffset.class); } /** diff --git a/src/test/java/org/springframework/data/gemfire/mapping/model/GemfireSimpleTypeHolderUnitTests.java b/src/test/java/org/springframework/data/gemfire/mapping/model/GemfireSimpleTypeHolderUnitTests.java index ad67fc49..00a5eeb7 100644 --- a/src/test/java/org/springframework/data/gemfire/mapping/model/GemfireSimpleTypeHolderUnitTests.java +++ b/src/test/java/org/springframework/data/gemfire/mapping/model/GemfireSimpleTypeHolderUnitTests.java @@ -16,13 +16,32 @@ package org.springframework.data.gemfire.mapping.model; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import java.math.BigDecimal; import java.math.BigInteger; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.MonthDay; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.Period; +import java.time.Year; +import java.time.YearMonth; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.chrono.ChronoLocalDate; +import java.time.chrono.ChronoLocalDateTime; +import java.time.chrono.ChronoPeriod; +import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; +import java.time.chrono.Era; import org.junit.Test; +import org.springframework.data.gemfire.test.model.Person; /** * Unit tests for {@link GemfireSimpleTypeHolder} class. @@ -37,17 +56,40 @@ public class GemfireSimpleTypeHolderUnitTests { private final GemfireSimpleTypeHolder holder = new GemfireSimpleTypeHolder(); + @Test + public void javaTimeTypesAreSimpleTypes() { + + assertThat(this.holder.isSimpleType(ChronoLocalDate.class)).isTrue(); + assertThat(this.holder.isSimpleType(ChronoLocalDateTime.class)).isTrue(); + assertThat(this.holder.isSimpleType(Chronology.class)).isTrue(); + assertThat(this.holder.isSimpleType(ChronoPeriod.class)).isTrue(); + assertThat(this.holder.isSimpleType(ChronoPeriod.class)).isTrue(); + assertThat(this.holder.isSimpleType(ChronoZonedDateTime.class)).isTrue(); + assertThat(this.holder.isSimpleType(Duration.class)).isTrue(); + assertThat(this.holder.isSimpleType(Era.class)).isTrue(); + assertThat(this.holder.isSimpleType(Instant.class)).isTrue(); + assertThat(this.holder.isSimpleType(LocalDate.class)).isTrue(); + assertThat(this.holder.isSimpleType(LocalDateTime.class)).isTrue(); + assertThat(this.holder.isSimpleType(LocalTime.class)).isTrue(); + assertThat(this.holder.isSimpleType(MonthDay.class)).isTrue(); + assertThat(this.holder.isSimpleType(OffsetDateTime.class)).isTrue(); + assertThat(this.holder.isSimpleType(OffsetTime.class)).isTrue(); + assertThat(this.holder.isSimpleType(Period.class)).isTrue(); + assertThat(this.holder.isSimpleType(Year.class)).isTrue(); + assertThat(this.holder.isSimpleType(YearMonth.class)).isTrue(); + assertThat(this.holder.isSimpleType(ZonedDateTime.class)).isTrue(); + assertThat(this.holder.isSimpleType(ZoneOffset.class)).isTrue(); + } + @Test public void bigDecimalAndBigIntegerAreSimpleTypes() { - assertThat(holder.isSimpleType(BigDecimal.class), is(true)); - assertThat(holder.isSimpleType(BigInteger.class), is(true)); + + assertThat(this.holder.isSimpleType(BigDecimal.class)).isTrue(); + assertThat(this.holder.isSimpleType(BigInteger.class)).isTrue(); } @Test public void personIsNotASimpleType() { - assertThat(holder.isSimpleType(Person.class), is(false)); + assertThat(this.holder.isSimpleType(Person.class)).isFalse(); } - - class Person { } - }