Search in sources :

Example 1 with PersonCriteria

use of org.immutables.criteria.personmodel.PersonCriteria in project immutables by immutables.

the class ExpressionAsStringTest method and.

@Test
void and() {
    PersonCriteria other = PersonCriteria.person.and(person.age.atMost(1)).and(person.age.atLeast(2));
    assertExpressional(other, "call op=AND", "  call op=LESS_THAN_OR_EQUAL path=age constant=1", "  call op=GREATER_THAN_OR_EQUAL path=age constant=2");
    assertExpressional(other.and(person.age.is(3)), "call op=AND", "  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(other.and(person.age.is(3)), "call op=AND", "  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");
}
Also used : PersonCriteria(org.immutables.criteria.personmodel.PersonCriteria) Test(org.junit.jupiter.api.Test)

Example 2 with PersonCriteria

use of org.immutables.criteria.personmodel.PersonCriteria in project immutables by immutables.

the class ChangeStreamsTest method filter.

/**
 * Watch event with filter
 */
@Test
void filter() throws InterruptedException {
    PersonCriteria filter = person.age.atLeast(21);
    Flowable<WatchEvent<Person>> flowable = Flowable.fromPublisher(repository.watcher(filter).watch());
    TestSubscriber<WatchEvent<Person>> test = flowable.test();
    repository.insert(generator.next().withId("id1").withAge(18));
    test.await(200, TimeUnit.MILLISECONDS);
    test.assertEmpty();
    repository.insert(generator.next().withId("id2").withAge(19));
    test.await(200, TimeUnit.MILLISECONDS);
    test.assertEmpty();
    repository.insert(generator.next().withId("id3").withAge(21));
    test.awaitCount(1).assertValueCount(1);
    Person person = test.values().get(0).newValue().get();
    check(person.id()).is("id3");
    check(person.age()).is(21);
}
Also used : PersonCriteria(org.immutables.criteria.personmodel.PersonCriteria) WatchEvent(org.immutables.criteria.backend.WatchEvent) Person(org.immutables.criteria.personmodel.Person) Test(org.junit.jupiter.api.Test)

Example 3 with PersonCriteria

use of org.immutables.criteria.personmodel.PersonCriteria in project immutables by immutables.

the class ExpressionInterpreterTest method booleans.

@Test
public void booleans() {
    final PersonCriteria crit = PersonCriteria.person;
    final ImmutablePerson person = example.withFullName("A");
    check(evaluate(crit.nickName.isAbsent().or().nickName.isPresent(), person));
    check(!evaluate(crit.nickName.isAbsent().nickName.isPresent(), person));
    check(!evaluate(crit.fullName.is("A").fullName.is("B"), person));
    check(evaluate(crit.fullName.is("B").or().fullName.is("A"), person));
    check(!evaluate(crit.fullName.is("B").or().fullName.is("C"), person));
    check(!evaluate(crit.fullName.is("A").fullName.is("C"), person));
}
Also used : PersonCriteria(org.immutables.criteria.personmodel.PersonCriteria) ImmutablePerson(org.immutables.criteria.personmodel.ImmutablePerson) Test(org.junit.jupiter.api.Test)

Example 4 with PersonCriteria

use of org.immutables.criteria.personmodel.PersonCriteria in project immutables by immutables.

the class AggregationExpressionTest method aggregation.

@Test
public void aggregation() {
    PersonCriteria person = PersonCriteria.person;
    assertProjection(person.age.count(), "call op=COUNT path=age");
    assertProjection(person.age.sum(), "call op=SUM path=age");
    assertProjection(person.age.avg(), "call op=AVG path=age");
    assertProjection(person.age.min(), "call op=MIN path=age");
    assertProjection(person.age.max(), "call op=MAX path=age");
    assertProjection(person.bestFriend.value().hobby.max(), "call op=MAX path=bestFriend.hobby");
    assertProjection(person.bestFriend.value().hobby.count(), "call op=COUNT path=bestFriend.hobby");
    assertProjection(person.nickName.max(), "call op=MAX path=nickName");
}
Also used : PersonCriteria(org.immutables.criteria.personmodel.PersonCriteria) Test(org.junit.jupiter.api.Test)

Example 5 with PersonCriteria

use of org.immutables.criteria.personmodel.PersonCriteria in project immutables by immutables.

the class UpdatableTest method name.

@Test
@Disabled("compile-time only")
void name() {
    PersonCriteria person = PersonCriteria.person;
    Updater<Person, Single<WriteResult>> updater = null;
    updater.set(person.nickName, Optional.of("aaa")).set(person, // instead of replace ?
    ImmutablePerson.builder().build()).set(person.fullName, "John").set(person.isActive, true).execute();
    updater.replace(ImmutablePerson.builder().build()).execute();
}
Also used : Single(io.reactivex.Single) PersonCriteria(org.immutables.criteria.personmodel.PersonCriteria) Person(org.immutables.criteria.personmodel.Person) ImmutablePerson(org.immutables.criteria.personmodel.ImmutablePerson) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

PersonCriteria (org.immutables.criteria.personmodel.PersonCriteria)9 Test (org.junit.jupiter.api.Test)9 Person (org.immutables.criteria.personmodel.Person)5 ImmutablePerson (org.immutables.criteria.personmodel.ImmutablePerson)3 WatchEvent (org.immutables.criteria.backend.WatchEvent)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Single (io.reactivex.Single)1 LocalDate (java.time.LocalDate)1 Optional (java.util.Optional)1 Checkers.check (org.immutables.check.Checkers.check)1 Criterias (org.immutables.criteria.Criterias)1 Query (org.immutables.criteria.expression.Query)1 Address (org.immutables.criteria.personmodel.Address)1 ImmutableAddress (org.immutables.criteria.personmodel.ImmutableAddress)1 Disabled (org.junit.jupiter.api.Disabled)1