Search in sources :

Example 1 with LocalDateHolderCriteria

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

the class ComponentTypeTest method localDate.

@Test
void localDate() {
    final LocalDateHolderCriteria criteria = LocalDateHolderCriteria.localDateHolder;
    check(argumentOf(criteria.array)).is(LocalDate.class);
    check(argumentOf(criteria.list)).is(LocalDate.class);
}
Also used : LocalDateHolderCriteria(org.immutables.criteria.typemodel.LocalDateHolderCriteria) Test(org.junit.jupiter.api.Test)

Example 2 with LocalDateHolderCriteria

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

the class ReturnTypeTest method localDate.

@Test
void localDate() {
    final LocalDateHolderCriteria criteria = LocalDateHolderCriteria.localDateHolder;
    check(Matchers.toExpression(criteria.value.min()).returnType()).is(LocalDate.class);
    check(Matchers.toExpression(criteria.value.max()).returnType()).is(LocalDate.class);
    check(Matchers.toExpression(criteria.value.count()).returnType()).is(Long.class);
    check(Matchers.toExpression(criteria.value).returnType()).is(LocalDate.class);
    check(Matchers.toExpression(criteria.optional).returnType()).is(new TypeToken<Optional<LocalDate>>() {
    }.getType());
    check(Matchers.toExpression(criteria.nullable).returnType()).is(LocalDate.class);
}
Also used : LocalDateHolderCriteria(org.immutables.criteria.typemodel.LocalDateHolderCriteria) TypeToken(com.google.common.reflect.TypeToken) LocalDate(java.time.LocalDate) Test(org.junit.jupiter.api.Test)

Example 3 with LocalDateHolderCriteria

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

the class TupleCodecProviderTest method localDate.

@Test
void localDate() {
    LocalDateHolderCriteria criteria = LocalDateHolderCriteria.localDateHolder;
    Query query = Query.of(TypeHolder.LocalDateHolder.class).addProjections(Matchers.toExpression(criteria.value), Matchers.toExpression(criteria.nullable), Matchers.toExpression(criteria.optional));
    Path idPath = Visitors.toPath(KeyExtractor.defaultFactory().create(TypeHolder.LocalDateHolder.class).metadata().keys().get(0));
    TupleCodecProvider provider = new TupleCodecProvider(query, new MongoPathNaming(idPath, PathNaming.defaultNaming()).toExpression());
    Codec<ProjectedTuple> codec = provider.get(ProjectedTuple.class, registry);
    LocalDate now = LocalDate.now();
    final long millisEpoch = now.atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli();
    BsonDocument doc = new BsonDocument().append("id", new BsonString("id1")).append("value", new BsonDateTime(millisEpoch)).append("nullable", BsonNull.VALUE).append("optional", BsonNull.VALUE).append("array", new BsonArray()).append("list", new BsonArray());
    ProjectedTuple tuple = codec.decode(new BsonDocumentReader(doc), DecoderContext.builder().build());
    check(tuple.get(Matchers.toExpression(criteria.value))).is(now);
    check(tuple.get(Matchers.toExpression(criteria.nullable))).isNull();
    check(tuple.get(Matchers.toExpression(criteria.optional))).is(Optional.empty());
}
Also used : Path(org.immutables.criteria.expression.Path) Query(org.immutables.criteria.expression.Query) BsonDocumentReader(org.bson.BsonDocumentReader) LocalDate(java.time.LocalDate) TypeHolder(org.immutables.criteria.typemodel.TypeHolder) LocalDateHolderCriteria(org.immutables.criteria.typemodel.LocalDateHolderCriteria) BsonDocument(org.bson.BsonDocument) BsonDateTime(org.bson.BsonDateTime) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) ProjectedTuple(org.immutables.criteria.backend.ProjectedTuple) Test(org.junit.jupiter.api.Test)

Aggregations

LocalDateHolderCriteria (org.immutables.criteria.typemodel.LocalDateHolderCriteria)3 Test (org.junit.jupiter.api.Test)3 LocalDate (java.time.LocalDate)2 TypeToken (com.google.common.reflect.TypeToken)1 BsonArray (org.bson.BsonArray)1 BsonDateTime (org.bson.BsonDateTime)1 BsonDocument (org.bson.BsonDocument)1 BsonDocumentReader (org.bson.BsonDocumentReader)1 BsonString (org.bson.BsonString)1 ProjectedTuple (org.immutables.criteria.backend.ProjectedTuple)1 Path (org.immutables.criteria.expression.Path)1 Query (org.immutables.criteria.expression.Query)1 TypeHolder (org.immutables.criteria.typemodel.TypeHolder)1