Search in sources :

Example 1 with Person

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

the class IdAnnotationModuleTest method immutable.

@ParameterizedTest
@MethodSource("mappers")
void immutable(ObjectMapper mapper) throws JsonProcessingException {
    // write
    ImmutablePerson person = new PersonGenerator().next().withId("id123");
    ObjectNode node = mapper.valueToTree(person);
    check(node.get("_id").asText()).is("id123");
    check(ImmutableList.copyOf(node.fieldNames())).not().has("id");
    check(mapper.treeToValue(node, Person.class).id()).is("id123");
    check(mapper.treeToValue(node, ImmutablePerson.class).id()).is("id123");
}
Also used : PersonGenerator(org.immutables.criteria.personmodel.PersonGenerator) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ImmutablePerson(org.immutables.criteria.personmodel.ImmutablePerson) Person(org.immutables.criteria.personmodel.Person) ImmutablePerson(org.immutables.criteria.personmodel.ImmutablePerson) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with Person

use of org.immutables.criteria.personmodel.Person 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 Person

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

the class InMemoryTest method predicate.

@Test
void predicate() {
    Predicate<Person> predicate = InMemory.toPredicate(PersonCriteria.person.age.is(22));
    PersonGenerator generator = new PersonGenerator();
    check(predicate.test(generator.next().withAge(22)));
    check(!predicate.test(generator.next().withAge(23)));
}
Also used : PersonGenerator(org.immutables.criteria.personmodel.PersonGenerator) Person(org.immutables.criteria.personmodel.Person) Test(org.junit.jupiter.api.Test)

Example 4 with Person

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

the class GeodeCqTest method pubsub.

@Test
public void pubsub() throws Exception {
    PersonRepository repository = new PersonRepository(new GeodeBackend(GeodeSetup.of(x -> region)));
    TestSubscriber<WatchEvent<Person>> events = Flowable.fromPublisher(repository.watcher(PersonCriteria.person).watch()).test();
    final PersonGenerator generator = new PersonGenerator();
    final int count = 4;
    for (int i = 0; i < count; i++) {
        repository.insert(generator.next().withId("id" + i));
    }
    check(region.keySet()).notEmpty();
    // ensure (de)serialization is successful
    check(region.query("true")).hasSize(count);
    events.awaitCount(count);
    events.assertNoErrors();
    events.assertValueCount(count);
    check(events.values().stream().map(e -> e.newValue().get().id()).collect(Collectors.toList())).hasContentInAnyOrder("id0", "id1", "id2", "id3");
}
Also used : WatchEvent(org.immutables.criteria.backend.WatchEvent) PersonRepository(org.immutables.criteria.personmodel.PersonRepository) BeforeEach(org.junit.jupiter.api.BeforeEach) Person(org.immutables.criteria.personmodel.Person) ClientRegionShortcut(org.apache.geode.cache.client.ClientRegionShortcut) Disabled(org.junit.jupiter.api.Disabled) Collectors(java.util.stream.Collectors) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) Flowable(io.reactivex.Flowable) Checkers.check(org.immutables.check.Checkers.check) PersonGenerator(org.immutables.criteria.personmodel.PersonGenerator) Region(org.apache.geode.cache.Region) PersonCriteria(org.immutables.criteria.personmodel.PersonCriteria) TestSubscriber(io.reactivex.subscribers.TestSubscriber) ClientCache(org.apache.geode.cache.client.ClientCache) PersonGenerator(org.immutables.criteria.personmodel.PersonGenerator) PersonRepository(org.immutables.criteria.personmodel.PersonRepository) WatchEvent(org.immutables.criteria.backend.WatchEvent) Test(org.junit.jupiter.api.Test)

Example 5 with Person

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

the class GeodeCqTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    this.clientCache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334).setPdxSerializer(new ReflectionBasedAutoSerializer(Person.class.getPackage().getName())).setPoolSubscriptionEnabled(true).create();
    this.region = clientCache.<String, Person>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("persons");
    region.clear();
}
Also used : ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) Person(org.immutables.criteria.personmodel.Person) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Person (org.immutables.criteria.personmodel.Person)10 Test (org.junit.jupiter.api.Test)8 PersonCriteria (org.immutables.criteria.personmodel.PersonCriteria)6 WatchEvent (org.immutables.criteria.backend.WatchEvent)3 ImmutablePerson (org.immutables.criteria.personmodel.ImmutablePerson)3 PersonGenerator (org.immutables.criteria.personmodel.PersonGenerator)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)2 ReflectionBasedAutoSerializer (org.apache.geode.pdx.ReflectionBasedAutoSerializer)2 Checkers.check (org.immutables.check.Checkers.check)2 PersonRepository (org.immutables.criteria.personmodel.PersonRepository)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Disabled (org.junit.jupiter.api.Disabled)2 Flowable (io.reactivex.Flowable)1 Single (io.reactivex.Single)1 TestSubscriber (io.reactivex.subscribers.TestSubscriber)1 LocalDate (java.time.LocalDate)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Region (org.apache.geode.cache.Region)1