Search in sources :

Example 1 with PersonGenerator

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

the class KeyExtractorTest method immutables.

@Test
void immutables() {
    KeyExtractor extractor = KeyExtractor.defaultFactory().create(Person.class);
    check(extractor.metadata().isKeyDefined());
    check(extractor.metadata().isExpression());
    check(extractor.metadata().keys()).hasSize(1);
    Member member = (Member) Visitors.toPath(extractor.metadata().keys().get(0)).element();
    check(member.getName()).is("id");
    ImmutablePerson person = new PersonGenerator().next();
    check(extractor.extract(person)).is(person.id());
}
Also used : PersonGenerator(org.immutables.criteria.personmodel.PersonGenerator) ImmutablePerson(org.immutables.criteria.personmodel.ImmutablePerson) Member(java.lang.reflect.Member) Test(org.junit.jupiter.api.Test)

Example 2 with PersonGenerator

use of org.immutables.criteria.personmodel.PersonGenerator 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 3 with PersonGenerator

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

the class GeodePersonTest method deleteByKey.

@Test
void deleteByKey() {
    PersonGenerator generator = new PersonGenerator();
    repository().insert(generator.next().withId("id1"));
    repository().insert(generator.next().withId("id2"));
    repository().insert(generator.next().withId("id3"));
    repository().delete(person.id.in("bad1", "bad2"));
    // nothing was deleted (bad ids)
    check(repository().findAll()).toList(Person::id).hasContentInAnyOrder("id1", "id2", "id3");
    repository().delete(person.id.is("id1"));
    check(repository().findAll()).toList(Person::id).hasContentInAnyOrder("id2", "id3");
    repository().delete(person.id.in("id1", "id1"));
    check(repository().findAll()).toList(Person::id).hasContentInAnyOrder("id2", "id3");
    repository().delete(person.id.in("id2", "id2", "id1"));
    check(repository().findAll()).toList(Person::id).hasContentInAnyOrder("id3");
    repository().delete(person.id.in("id2", "id2", "id1", "id3"));
    check(repository().findAll()).toList(Person::id).isEmpty();
}
Also used : PersonGenerator(org.immutables.criteria.personmodel.PersonGenerator) Test(org.junit.jupiter.api.Test) AbstractPersonTest(org.immutables.criteria.personmodel.AbstractPersonTest)

Example 4 with PersonGenerator

use of org.immutables.criteria.personmodel.PersonGenerator 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 5 with PersonGenerator

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

Aggregations

PersonGenerator (org.immutables.criteria.personmodel.PersonGenerator)7 Test (org.junit.jupiter.api.Test)6 Person (org.immutables.criteria.personmodel.Person)4 AbstractPersonTest (org.immutables.criteria.personmodel.AbstractPersonTest)3 ImmutablePerson (org.immutables.criteria.personmodel.ImmutablePerson)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 Flowable (io.reactivex.Flowable)1 TestSubscriber (io.reactivex.subscribers.TestSubscriber)1 IOException (java.io.IOException)1 Member (java.lang.reflect.Member)1 EnumSet (java.util.EnumSet)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Region (org.apache.geode.cache.Region)1