Search in sources :

Example 1 with LocalDateTimeHolderRepository

use of org.immutables.criteria.typemodel.LocalDateTimeHolderRepository in project immutables by immutables.

the class JavaTimeTypeTest method localDateTime.

@Test
void localDateTime() {
    LocalDateTimeHolderRepository repository = new LocalDateTimeHolderRepository(backend);
    LocalDateTime value = LocalDateTime.now();
    ImmutableLocalDateTimeHolder holder = TypeHolder.LocalDateTimeHolder.generator().get().withValue(value).withOptional(value).withNullable(null);
    repository.insert(holder);
    BsonDocument doc = fetch();
    BsonDateTime expected = new BsonDateTime(value.toInstant(ZoneOffset.UTC).toEpochMilli());
    check(doc.get("value")).is(expected);
    check(doc.get("optional")).is(expected);
    if (doc.containsKey("nullable")) {
        check(doc.get("nullable")).is(BsonNull.VALUE);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) BsonDocument(org.bson.BsonDocument) BsonDateTime(org.bson.BsonDateTime) LocalDateTimeHolderRepository(org.immutables.criteria.typemodel.LocalDateTimeHolderRepository) ImmutableLocalDateTimeHolder(org.immutables.criteria.typemodel.ImmutableLocalDateTimeHolder) Test(org.junit.jupiter.api.Test)

Aggregations

LocalDateTime (java.time.LocalDateTime)1 BsonDateTime (org.bson.BsonDateTime)1 BsonDocument (org.bson.BsonDocument)1 ImmutableLocalDateTimeHolder (org.immutables.criteria.typemodel.ImmutableLocalDateTimeHolder)1 LocalDateTimeHolderRepository (org.immutables.criteria.typemodel.LocalDateTimeHolderRepository)1 Test (org.junit.jupiter.api.Test)1