use of org.immutables.criteria.personmodel.Person 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.Person in project immutables by immutables.
the class ChangeStreamsTest method filter.
/**
* Watch event with filter
*/
@Test
void filter() throws InterruptedException {
PersonCriteria filter = person.age.atLeast(21);
Flowable<WatchEvent<Person>> flowable = Flowable.fromPublisher(repository.watcher(filter).watch());
TestSubscriber<WatchEvent<Person>> test = flowable.test();
repository.insert(generator.next().withId("id1").withAge(18));
test.await(200, TimeUnit.MILLISECONDS);
test.assertEmpty();
repository.insert(generator.next().withId("id2").withAge(19));
test.await(200, TimeUnit.MILLISECONDS);
test.assertEmpty();
repository.insert(generator.next().withId("id3").withAge(21));
test.awaitCount(1).assertValueCount(1);
Person person = test.values().get(0).newValue().get();
check(person.id()).is("id3");
check(person.age()).is(21);
}
use of org.immutables.criteria.personmodel.Person 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.Person 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");
}
use of org.immutables.criteria.personmodel.Person in project immutables by immutables.
the class GeodeCqTest method setUp.
@BeforeEach
public void setUp() throws Exception {
this.clientCache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334).setPdxSerializer(new ReflectionBasedAutoSerializer(Person.class.getPackage().getName())).setPoolSubscriptionEnabled(true).create();
this.region = clientCache.<String, Person>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("persons");
region.clear();
}
Aggregations