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());
}
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");
}
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")));
}
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));
}
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();
}
Aggregations