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