forked from hibernate/hibernate-ogm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OGM-1519 Test mapping java.time to Infinispan embedded
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...va/org/hibernate/ogm/datastore/infinispan/test/cachemapping/LocalDateTimeMappingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Hibernate OGM, Domain model persistence for NoSQL datastores | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.ogm.datastore.infinispan.test.cachemapping; | ||
|
||
|
||
import static org.hibernate.ogm.datastore.infinispan.utils.InfinispanTestHelper.fetchPropertyMap; | ||
import static org.hibernate.ogm.utils.OgmAssertions.assertThat; | ||
|
||
import java.sql.Time; | ||
import java.time.LocalDateTime; | ||
import java.time.Month; | ||
|
||
import org.hibernate.ogm.backendtck.type.datetime.LocalDateEntity; | ||
import org.hibernate.ogm.backendtck.type.datetime.LocalTimeEntity; | ||
import org.hibernate.ogm.utils.OgmTestCase; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import org.infinispan.atomic.FineGrainedAtomicMap; | ||
|
||
/** | ||
* Tests for the mappings of Date types into Infinispan. | ||
* | ||
* @author Fabio Massimo Ercoli | ||
*/ | ||
public class LocalDateTimeMappingTest extends OgmTestCase { | ||
|
||
private LocalDateEntity dateEntity; | ||
private LocalTimeEntity timeEntity; | ||
|
||
@Before | ||
public void persistEntities() { | ||
LocalDateTime moment = LocalDateTime.of( 2018, Month.AUGUST, 7, 12, 41, 50, 0 ); | ||
dateEntity = new LocalDateEntity( 7, "A entity using Java8 local date", moment ); | ||
timeEntity = new LocalTimeEntity( 3, "A entity using Java8 local time", moment.toLocalTime() ); | ||
|
||
inTransaction( session -> { | ||
session.persist( dateEntity ); | ||
session.persist( timeEntity ); | ||
} ); | ||
} | ||
|
||
@After | ||
public void deleteEntities() { | ||
inTransaction( session -> { | ||
session.delete( dateEntity ); | ||
session.delete( timeEntity ); | ||
} ); | ||
} | ||
|
||
@Test | ||
public void testLocalDateMapping() { | ||
FineGrainedAtomicMap<String, Object> propertyMap = fetchPropertyMap( sessionFactory, "LocalDateEntity", "id", dateEntity.getId() ); | ||
assertThat( propertyMap.get( "day" ) ).isEqualTo( dateEntity.getDay() ); | ||
} | ||
|
||
@Test | ||
public void testLocalDateTimeMapping() { | ||
FineGrainedAtomicMap<String, Object> propertyMap = fetchPropertyMap( sessionFactory, "LocalDateEntity", "id", dateEntity.getId() ); | ||
assertThat( propertyMap.get( "moment" ) ).isEqualTo( dateEntity.getMoment() ); | ||
} | ||
|
||
@Test | ||
public void testLocalTimeMapping() { | ||
FineGrainedAtomicMap<String, Object> propertyMap = fetchPropertyMap( sessionFactory, "LocalTimeEntity", "id", timeEntity.getId() ); | ||
|
||
// At the time of writing Hibernate ORM convert a LocalTime field into a java.sql.Time | ||
// see org.hibernate.type.LocalTimeType, then compare it with *.LocalDateType and *.LocalDateTimeType. | ||
// In OGM we haven't overridden this behavior. | ||
Time expected = Time.valueOf( timeEntity.getTime() ); | ||
|
||
assertThat( propertyMap.get( "time" ) ).isEqualTo( expected ); | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class[] { LocalDateEntity.class, LocalTimeEntity.class }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters