use of org.immutables.criteria.personmodel.PersonCriteria in project immutables by immutables.
the class ExpressionAsStringTest method or.
@Test
void or() {
PersonCriteria other = person.or(person.age.atMost(1)).or(person.age.atLeast(2));
assertExpressional(other, "call op=OR", " call op=LESS_THAN_OR_EQUAL path=age constant=1", " call op=GREATER_THAN_OR_EQUAL path=age constant=2");
assertExpressional(other.or(person.age.is(3)), "call op=OR", " call op=LESS_THAN_OR_EQUAL path=age constant=1", " call op=GREATER_THAN_OR_EQUAL path=age constant=2", " call op=EQUAL path=age constant=3");
assertExpressional(person.or(person.age.atMost(1)).or(person.age.atLeast(2)).or(person.age.is(3)), "call op=OR", " call op=LESS_THAN_OR_EQUAL path=age constant=1", " call op=GREATER_THAN_OR_EQUAL path=age constant=2", " call op=EQUAL path=age constant=3");
}
use of org.immutables.criteria.personmodel.PersonCriteria in project immutables by immutables.
the class ChangeStreamsTest method multiFilter.
@Test
void multiFilter() throws InterruptedException {
PersonCriteria filter = person.age.atLeast(21).isActive.isTrue();
Flowable<WatchEvent<Person>> flowable = Flowable.fromPublisher(repository.watcher(filter).watch());
TestSubscriber<WatchEvent<Person>> test = flowable.test();
repository.insert(generator.next().withId("id1").withAge(19));
test.await(200, TimeUnit.MILLISECONDS);
test.assertEmpty();
repository.insert(generator.next().withId("id2").withAge(21).withIsActive(false));
test.await(200, TimeUnit.MILLISECONDS);
test.assertEmpty();
repository.insert(generator.next().withId("id3").withAge(21).withIsActive(true));
test.awaitCount(1).assertValueCount(1);
Person person = test.values().get(0).newValue().get();
check(person.id()).is("id3");
}
use of org.immutables.criteria.personmodel.PersonCriteria in project immutables by immutables.
the class ExpressionInterpreterTest method reflection.
@Test
public void reflection() {
final PersonCriteria crit = PersonCriteria.person;
final ImmutablePerson person = example.withFullName("John");
check(!evaluate(crit.age.is(11), person));
check(evaluate(crit.age.isNot(11), person));
check(evaluate(crit.age.is(11), person.withAge(11)));
check(evaluate(crit.age.is(22).fullName.is("John"), person));
check(!evaluate(crit.age.is(22).fullName.is("Mary"), person));
check(!evaluate(crit.age.in(1, 2, 3), person));
check(evaluate(crit.age.notIn(1, 2, 3), person));
check(evaluate(crit.age.in(22, 23, 24), person));
check(!evaluate(crit.age.notIn(22, 23, 24), person));
check(!evaluate(crit.isActive.isTrue(), person));
check(evaluate(crit.isActive.isFalse(), person));
check(evaluate(crit.isActive.isTrue().or().isActive.isFalse(), person));
check(evaluate(crit.isActive.isFalse().or().isActive.isTrue().nickName.isAbsent(), person));
check(!evaluate(crit.age.atLeast(23), person));
check(evaluate(crit.age.atMost(22), person));
check(!evaluate(crit.age.lessThan(22), person));
check(!evaluate(crit.age.greaterThan(22), person));
check(!evaluate(crit.age.atLeast(23), person));
// optionals
check(evaluate(crit.nickName.isPresent(), person));
check(!evaluate(crit.nickName.isAbsent(), person));
check(!evaluate(crit.nickName.isPresent(), person.withNickName(Optional.empty())));
check(evaluate(crit.nickName.isAbsent(), person.withNickName(Optional.empty())));
// == value().$expr
check(!evaluate(crit.nickName.isNot("Smith"), person.withNickName("Smith")));
check(evaluate(crit.nickName.in("Smith", "Nobody"), person.withNickName("Smith")));
check(!evaluate(crit.nickName.in("Nobody", "Sky"), person.withNickName("Smith")));
check(evaluate(crit.nickName.notIn("Nobody", "Sky"), person.withNickName("Smith")));
// == value($expr)
check(evaluate(crit.nickName.with(v -> v.is("Smith")), person.withNickName("Smith")));
check(!evaluate(crit.nickName.with(v -> v.isNot("Smith")), person.withNickName("Smith")));
check(evaluate(crit.nickName.with(v -> v.in("Smith", "Nobody")), person.withNickName("Smith")));
check(!evaluate(crit.nickName.with(v -> v.in("Nobody", "Sky")), person.withNickName("Smith")));
check(evaluate(crit.nickName.with(v -> v.notIn("Nobody", "Sky")), person.withNickName("Smith")));
}
use of org.immutables.criteria.personmodel.PersonCriteria in project immutables by immutables.
the class AggregateQueryBuilderTest method agg1.
@Test
void agg1() {
PersonCriteria person = PersonCriteria.person;
// select nickName, sum(age), max(dateOfBirth) from person
// where age >= 30
// group by nickName
// order by nickName
// limit 11
Query query = Query.of(Person.class).addGroupBy(Matchers.toExpression(person.nickName)).addCollations(Collections.singleton(Collation.of(Matchers.toExpression(person.nickName)))).addProjections(Matchers.toExpression(person.nickName), Matchers.toExpression(person.age.sum()), Matchers.toExpression(person.dateOfBirth.max())).withFilter(Criterias.toQuery(person.age.atLeast(30)).filter().get()).withLimit(11);
AggregateQueryBuilder builder = new AggregateQueryBuilder(query, MAPPER, mapping, pathNaming, idPredicate);
ObjectNode json = builder.jsonQuery();
JsonChecker.of(json).is("{'_source':false,", "size:0,", "'stored_fields':'_none_',", "'query.constant_score.filter.range.age.gte' : 30,", "aggregations:{expr0:{terms:{field:'nickName',missing:'__MISSING__',size:11," + " order:{'_key':'asc'}},", "aggregations:{expr1:{sum:{field:'age'}},expr2:{max:{field:'dateOfBirth'}}}}}}");
}
Aggregations