add a test for selecting a datetime literal

seems to be causing problems in 2 dbs
This commit is contained in:
Gavin King 2022-01-06 21:59:34 +01:00
parent 2c00a647cb
commit b8d26f829e
1 changed files with 39 additions and 0 deletions

View File

@ -15,10 +15,18 @@ import org.junit.jupiter.api.Test;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaTypeDescriptor; import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaTypeDescriptor;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
/** /**
@ -191,6 +199,37 @@ public class LiteralTests {
); );
} }
@Test
public void testSelectDatetimeLiterals(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
assertThat( session.createQuery( "select datetime 1999-07-23 23:59" ).getSingleResult(),
is( instanceOf(LocalDateTime.class) ) );
assertThat( session.createQuery( "select date 1999-07-23" ).getSingleResult(),
is( instanceOf(LocalDate.class) ) );
assertThat( session.createQuery( "select time 23:59" ).getSingleResult(),
is( instanceOf(LocalTime.class) ) );
assertThat( session.createQuery( "select local datetime" ).getSingleResult(),
is( instanceOf(LocalDateTime.class) ) );
assertThat( session.createQuery( "select local date" ).getSingleResult(),
is( instanceOf(LocalDate.class) ) );
assertThat( session.createQuery( "select local time" ).getSingleResult(),
is( instanceOf(LocalTime.class) ) );
assertThat( session.createQuery( "select instant" ).getSingleResult(),
is( instanceOf(Instant.class) ) );
assertThat( session.createQuery( "select current timestamp" ).getSingleResult(),
is( instanceOf(Timestamp.class) ) );
assertThat( session.createQuery( "select current date" ).getSingleResult(),
is( instanceOf(Date.class) ) );
assertThat( session.createQuery( "select current time" ).getSingleResult(),
is( instanceOf(Time.class) ) );
}
);
}
@Test @Test
public void testBooleanLiteral(SessionFactoryScope scope) { public void testBooleanLiteral(SessionFactoryScope scope) {
scope.inTransaction( scope.inTransaction(