Search in sources :

Example 6 with PersonGenerator

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

the class GeodePersonTest method deleteByQuery.

@Test
void deleteByQuery() {
    PersonGenerator generator = new PersonGenerator();
    repository().insert(generator.next().withId("id1").withFullName("A").withAge(10));
    repository().insert(generator.next().withId("id2").withFullName("B").withAge(20));
    repository().insert(generator.next().withId("id3").withFullName("C").withAge(30));
    repository().delete(person.age.atMost(9).fullName.is("A"));
    check(repository().findAll()).toList(Person::id).hasContentInAnyOrder("id1", "id2", "id3");
    // delete id1
    repository().delete(person.age.atMost(10).fullName.is("A"));
    check(repository().findAll()).toList(Person::id).hasContentInAnyOrder("id2", "id3");
    // delete id2
    repository().delete(person.age.between(19, 21));
    check(repository().findAll()).toList(Person::id).hasContentInAnyOrder("id3");
    // delete id3
    repository().delete(person.fullName.is("C"));
    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 7 with PersonGenerator

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

the class ElasticPersonTest method regex_forElastic.

/**
 * Elastic has special <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/regexp-syntax.html">regex syntax</a>
 * and not all java patterns are supported. Testing separately here
 */
@Test
public void regex_forElastic() {
    final PersonGenerator generator = new PersonGenerator();
    insert(generator.next().withFullName("John"));
    check(repository().find(person.fullName.matches(Pattern.compile("John")))).hasSize(1);
    check(repository().find(person.fullName.matches(Pattern.compile("J.*n")))).hasSize(1);
    check(repository().find(person.fullName.not(s -> s.matches(Pattern.compile("J.*n"))))).empty();
    check(repository().find(person.fullName.matches(Pattern.compile("J..n")))).hasSize(1);
    check(repository().find(person.fullName.matches(Pattern.compile("J...")))).hasSize(1);
    check(repository().find(person.fullName.matches(Pattern.compile("...n")))).hasSize(1);
    check(repository().find(person.fullName.matches(Pattern.compile(".*")))).hasSize(1);
    insert(generator.next().withFullName("Mary"));
    check(repository().find(person.fullName.matches(Pattern.compile("J.*n")))).hasSize(1);
    check(repository().find(person.fullName.matches(Pattern.compile("M.*ry")))).hasSize(1);
    check(repository().find(person.fullName.matches(Pattern.compile(".*")))).hasSize(2);
}
Also used : RestClient(org.elasticsearch.client.RestClient) Person(org.immutables.criteria.personmodel.Person) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) Backend(org.immutables.criteria.backend.Backend) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) Test(org.junit.jupiter.api.Test) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) ContainerNaming(org.immutables.criteria.backend.ContainerNaming) AbstractPersonTest(org.immutables.criteria.personmodel.AbstractPersonTest) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PersonGenerator(org.immutables.criteria.personmodel.PersonGenerator) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) Pattern(java.util.regex.Pattern) EnumSet(java.util.EnumSet) PersonGenerator(org.immutables.criteria.personmodel.PersonGenerator) Test(org.junit.jupiter.api.Test) AbstractPersonTest(org.immutables.criteria.personmodel.AbstractPersonTest)

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