Search in sources :

Example 1 with ImmutablePerson

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

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

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

the class ExpressionInterpreterTest method empty.

@Test
public void empty() {
    final ImmutablePerson person = example;
    check(evaluate(PersonCriteria.person, person));
    check(evaluate(PersonCriteria.person, person.withFullName("llll")));
}
Also used : ImmutablePerson(org.immutables.criteria.personmodel.ImmutablePerson) Test(org.junit.jupiter.api.Test)

Example 4 with ImmutablePerson

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

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

the class GenericKeyTest method select.

@Test
void select() {
    ImmutablePerson p1 = generator.next().withId("id1").withAge(11);
    repository.insert(p1);
    // see extractor() defined as $id_$age
    check(region.keySet()).isOf("id1_11");
    // was inserted with different id
    check(region.get("id1_11").id()).is("id1");
    check(region.get("id1_11")).is(p1);
    check(repository.find(person.id.is("id1")).fetch()).hasSize(1);
    check(repository.find(person.id.in("id1", "id2")).fetch()).hasSize(1);
    check(repository.find(person.id.is("id1_11")).fetch()).isEmpty();
    check(repository.find(person.id.is("id2")).fetch()).isEmpty();
    check(repository.find(person.id.isNot("id1")).fetch()).isEmpty();
}
Also used : ImmutablePerson(org.immutables.criteria.personmodel.ImmutablePerson) Test(org.junit.jupiter.api.Test)

Aggregations

ImmutablePerson (org.immutables.criteria.personmodel.ImmutablePerson)6 Test (org.junit.jupiter.api.Test)5 Person (org.immutables.criteria.personmodel.Person)2 PersonCriteria (org.immutables.criteria.personmodel.PersonCriteria)2 PersonGenerator (org.immutables.criteria.personmodel.PersonGenerator)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Member (java.lang.reflect.Member)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 Address (org.immutables.criteria.personmodel.Address)1 ImmutableAddress (org.immutables.criteria.personmodel.ImmutableAddress)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1