mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
FIX: NPE in StalarTypeLocalTime and StalarTypeMonthDay (#1479)
This commit is contained in:
committed by
Rob Bygrave
parent
c81d329100
commit
29d88d7de8
@@ -6,10 +6,13 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
import java.nio.file.Path;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.Month;
|
||||
import java.time.MonthDay;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.Period;
|
||||
import java.time.Year;
|
||||
@@ -39,6 +42,9 @@ public class SomeNewTypesBean {
|
||||
@Column(name = "yr_mth")
|
||||
YearMonth yearMonth;
|
||||
|
||||
@Column(name = "month_day")
|
||||
MonthDay monthDay;
|
||||
|
||||
LocalDate localDate;
|
||||
|
||||
LocalDateTime localDateTime;
|
||||
@@ -47,6 +53,8 @@ public class SomeNewTypesBean {
|
||||
|
||||
ZonedDateTime zonedDateTime;
|
||||
|
||||
LocalTime localTime;
|
||||
|
||||
Instant instant;
|
||||
|
||||
ZoneId zoneId;
|
||||
@@ -57,6 +65,8 @@ public class SomeNewTypesBean {
|
||||
|
||||
Period period;
|
||||
|
||||
Duration duration;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -105,6 +115,14 @@ public class SomeNewTypesBean {
|
||||
this.yearMonth = yearMonth;
|
||||
}
|
||||
|
||||
public MonthDay getMonthDay() {
|
||||
return monthDay;
|
||||
}
|
||||
|
||||
public void setMonthDay(MonthDay monthDay) {
|
||||
this.monthDay = monthDay;
|
||||
}
|
||||
|
||||
public LocalDate getLocalDate() {
|
||||
return localDate;
|
||||
}
|
||||
@@ -137,6 +155,14 @@ public class SomeNewTypesBean {
|
||||
this.zonedDateTime = zonedDateTime;
|
||||
}
|
||||
|
||||
public LocalTime getLocalTime() {
|
||||
return localTime;
|
||||
}
|
||||
|
||||
public void setLocalTime(LocalTime localTime) {
|
||||
this.localTime = localTime;
|
||||
}
|
||||
|
||||
public Instant getInstant() {
|
||||
return instant;
|
||||
}
|
||||
@@ -176,4 +202,12 @@ public class SomeNewTypesBean {
|
||||
public void setPeriod(Period period) {
|
||||
this.period = period;
|
||||
}
|
||||
|
||||
public Duration getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(Duration duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,13 @@ import org.tests.model.types.SomeNewTypesBean;
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.Month;
|
||||
import java.time.MonthDay;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.Period;
|
||||
import java.time.Year;
|
||||
@@ -37,6 +40,7 @@ public class TestNewTypes extends BaseTestCase {
|
||||
bean.setLocalDateTime(LocalDateTime.now());
|
||||
bean.setOffsetDateTime(OffsetDateTime.now());
|
||||
bean.setZonedDateTime(ZonedDateTime.now());
|
||||
bean.setLocalTime(LocalTime.now());
|
||||
bean.setInstant(Instant.now());
|
||||
bean.setYear(Year.now());
|
||||
bean.setMonth(Month.APRIL);
|
||||
@@ -44,8 +48,10 @@ public class TestNewTypes extends BaseTestCase {
|
||||
bean.setZoneId(ZoneId.systemDefault());
|
||||
bean.setZoneOffset(ZonedDateTime.now().getOffset());
|
||||
bean.setYearMonth(YearMonth.of(2014, 9));
|
||||
bean.setMonthDay(MonthDay.of(9,22));
|
||||
bean.setPath(Paths.get(TEMP_PATH));
|
||||
bean.setPeriod(Period.of(4,3,2));
|
||||
bean.setDuration(Duration.ofMinutes(5));
|
||||
|
||||
|
||||
Ebean.save(bean);
|
||||
@@ -70,6 +76,9 @@ public class TestNewTypes extends BaseTestCase {
|
||||
list = Ebean.find(SomeNewTypesBean.class).where().lt("zonedDateTime", ZonedDateTime.now()).findList();
|
||||
assertTrue(!list.isEmpty());
|
||||
|
||||
list = Ebean.find(SomeNewTypesBean.class).where().le("localTime", LocalTime.now()).findList();
|
||||
assertTrue(!list.isEmpty());
|
||||
|
||||
list = Ebean.find(SomeNewTypesBean.class).where().eq("zoneId", ZoneId.systemDefault().getId()).findList();
|
||||
assertTrue(!list.isEmpty());
|
||||
|
||||
@@ -79,6 +88,9 @@ public class TestNewTypes extends BaseTestCase {
|
||||
list = Ebean.find(SomeNewTypesBean.class).where().le("yearMonth", YearMonth.of(2014, 9)).findList();
|
||||
assertTrue(!list.isEmpty());
|
||||
|
||||
list = Ebean.find(SomeNewTypesBean.class).where().le("monthDay", MonthDay.of(9,22)).findList();
|
||||
assertTrue(!list.isEmpty());
|
||||
|
||||
list = Ebean.find(SomeNewTypesBean.class).where().le("year", Year.now()).findList();
|
||||
assertTrue(!list.isEmpty());
|
||||
|
||||
@@ -91,6 +103,9 @@ public class TestNewTypes extends BaseTestCase {
|
||||
list = Ebean.find(SomeNewTypesBean.class).where().eq("period", Period.of(4,3,2)).findList();
|
||||
assertTrue(!list.isEmpty());
|
||||
|
||||
list = Ebean.find(SomeNewTypesBean.class).where().eq("duration", Duration.ofMinutes(5)).findList();
|
||||
assertTrue(!list.isEmpty());
|
||||
|
||||
SomeNewTypesBean fetched = Ebean.find(SomeNewTypesBean.class, bean.getId());
|
||||
|
||||
assertEquals(bean.getZoneId(), fetched.getZoneId());
|
||||
@@ -98,12 +113,15 @@ public class TestNewTypes extends BaseTestCase {
|
||||
assertEquals(bean.getMonth(), fetched.getMonth());
|
||||
assertEquals(bean.getYear(), fetched.getYear());
|
||||
assertEquals(bean.getYearMonth(), fetched.getYearMonth());
|
||||
assertEquals(bean.getMonthDay(), fetched.getMonthDay());
|
||||
assertEquals(bean.getLocalDate(), fetched.getLocalDate());
|
||||
assertThat(fetched.getLocalDateTime()).isEqualToIgnoringNanos(bean.getLocalDateTime());
|
||||
assertThat(fetched.getOffsetDateTime()).isEqualToIgnoringNanos(bean.getOffsetDateTime());
|
||||
assertThat(fetched.getLocalTime().toSecondOfDay()).isEqualTo(bean.getLocalTime().toSecondOfDay());
|
||||
assertEquals(bean.getInstant().toEpochMilli() / 1000, fetched.getInstant().toEpochMilli() / 1000);
|
||||
assertEquals(bean.getPath(), fetched.getPath());
|
||||
assertEquals(bean.getPeriod(), fetched.getPeriod());
|
||||
assertEquals(bean.getDuration(), fetched.getDuration());
|
||||
|
||||
|
||||
String asJson = Ebean.json().toJson(fetched);
|
||||
@@ -115,13 +133,16 @@ public class TestNewTypes extends BaseTestCase {
|
||||
assertEquals(bean.getMonth(), toBean.getMonth());
|
||||
assertEquals(bean.getYear(), toBean.getYear());
|
||||
assertEquals(bean.getYearMonth(), toBean.getYearMonth());
|
||||
assertEquals(bean.getMonthDay(), toBean.getMonthDay());
|
||||
assertEquals(bean.getLocalDate(), toBean.getLocalDate());
|
||||
assertThat(toBean.getLocalDateTime()).isEqualToIgnoringNanos(bean.getLocalDateTime());
|
||||
assertThat(toBean.getOffsetDateTime()).isEqualToIgnoringNanos(bean.getOffsetDateTime());
|
||||
assertEquals(bean.getLocalTime().toSecondOfDay(), toBean.getLocalTime().toSecondOfDay());
|
||||
assertEquals(bean.getInstant().toEpochMilli() / 1000, toBean.getInstant().toEpochMilli() / 1000);
|
||||
// FIXME: This test fails on Windows with: expected:<\tmp> but was:<C:\tmp>
|
||||
assertEquals(bean.getPath(), toBean.getPath());
|
||||
assertEquals(bean.getPeriod(), toBean.getPeriod());
|
||||
assertEquals(bean.getDuration(), toBean.getDuration());
|
||||
|
||||
}
|
||||
|
||||
@@ -139,12 +160,15 @@ public class TestNewTypes extends BaseTestCase {
|
||||
assertNull(fetched.getMonth());
|
||||
assertNull(fetched.getYear());
|
||||
assertNull(fetched.getYearMonth());
|
||||
assertNull(fetched.getMonthDay());
|
||||
assertNull(fetched.getLocalDate());
|
||||
assertNull(fetched.getLocalDateTime());
|
||||
assertNull(fetched.getOffsetDateTime());
|
||||
assertNull(fetched.getLocalTime());
|
||||
assertNull(fetched.getInstant());
|
||||
assertNull(fetched.getPath());
|
||||
assertNull(fetched.getPeriod());
|
||||
assertNull(fetched.getDuration());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,6 +178,7 @@ public class TestNewTypes extends BaseTestCase {
|
||||
refBean.setLocalDateTime(LocalDateTime.now());
|
||||
refBean.setOffsetDateTime(OffsetDateTime.now());
|
||||
refBean.setZonedDateTime(ZonedDateTime.now());
|
||||
refBean.setLocalTime(LocalTime.now());
|
||||
refBean.setInstant(Instant.now());
|
||||
refBean.setYear(Year.now());
|
||||
refBean.setMonth(Month.APRIL);
|
||||
@@ -161,8 +186,10 @@ public class TestNewTypes extends BaseTestCase {
|
||||
refBean.setZoneId(ZoneId.systemDefault());
|
||||
refBean.setZoneOffset(ZonedDateTime.now().getOffset());
|
||||
refBean.setYearMonth(YearMonth.of(2014, 9));
|
||||
refBean.setMonthDay(MonthDay.of( 9, 22));
|
||||
refBean.setPath(Paths.get(TEMP_PATH));
|
||||
refBean.setPeriod(Period.of(4,3,2));
|
||||
refBean.setDuration(Duration.ofMinutes(5));
|
||||
|
||||
testSetGetPath(refBean);
|
||||
}
|
||||
@@ -179,6 +206,7 @@ public class TestNewTypes extends BaseTestCase {
|
||||
ExpressionPath localDateTime = beanType.getExpressionPath("localDateTime");
|
||||
ExpressionPath offsetDateTime = beanType.getExpressionPath("offsetDateTime");
|
||||
ExpressionPath zonedDateTime = beanType.getExpressionPath("zonedDateTime");
|
||||
ExpressionPath localTime = beanType.getExpressionPath("localTime");
|
||||
ExpressionPath instant = beanType.getExpressionPath("instant");
|
||||
ExpressionPath year = beanType.getExpressionPath("year");
|
||||
ExpressionPath month = beanType.getExpressionPath("month");
|
||||
@@ -186,8 +214,10 @@ public class TestNewTypes extends BaseTestCase {
|
||||
ExpressionPath zoneId = beanType.getExpressionPath("zoneId");
|
||||
ExpressionPath zoneOffset = beanType.getExpressionPath("zoneOffset");
|
||||
ExpressionPath yearMonth = beanType.getExpressionPath("yearMonth");
|
||||
ExpressionPath monthDay = beanType.getExpressionPath("monthDay");
|
||||
ExpressionPath path = beanType.getExpressionPath("path");
|
||||
ExpressionPath period = beanType.getExpressionPath("period");
|
||||
ExpressionPath duration = beanType.getExpressionPath("duration");
|
||||
|
||||
localDate.pathSet(testBean, refBean.getLocalDate());
|
||||
assertThat(localDate.pathGet(testBean)).isEqualTo(refBean.getLocalDate());
|
||||
@@ -201,6 +231,9 @@ public class TestNewTypes extends BaseTestCase {
|
||||
zonedDateTime.pathSet(testBean, refBean.getZonedDateTime());
|
||||
assertThat(zonedDateTime.pathGet(testBean)).isEqualTo(refBean.getZonedDateTime());
|
||||
|
||||
localTime.pathSet(testBean, refBean.getLocalTime());
|
||||
assertThat(localTime.pathGet(testBean)).isEqualTo(refBean.getLocalTime());
|
||||
|
||||
instant.pathSet(testBean, refBean.getInstant());
|
||||
assertThat(instant.pathGet(testBean)).isEqualTo(refBean.getInstant());
|
||||
|
||||
@@ -222,12 +255,18 @@ public class TestNewTypes extends BaseTestCase {
|
||||
yearMonth.pathSet(testBean, refBean.getYearMonth());
|
||||
assertThat(yearMonth.pathGet(testBean)).isEqualTo(refBean.getYearMonth());
|
||||
|
||||
monthDay.pathSet(testBean, refBean.getMonthDay());
|
||||
assertThat(monthDay.pathGet(testBean)).isEqualTo(refBean.getMonthDay());
|
||||
|
||||
path.pathSet(testBean, refBean.getPath());
|
||||
assertThat(path.pathGet(testBean)).isEqualTo(refBean.getPath());
|
||||
|
||||
period.pathSet(testBean, refBean.getPeriod());
|
||||
assertThat(period.pathGet(testBean)).isEqualTo(refBean.getPeriod());
|
||||
|
||||
duration.pathSet(testBean, refBean.getDuration());
|
||||
assertThat(duration.pathGet(testBean)).isEqualTo(refBean.getDuration());
|
||||
|
||||
Ebean.save(refBean);
|
||||
Ebean.save(testBean);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user