use of io.requery.test.model.Person in project requery by requery.
the class ReactiveTest method testInsertOneToMany.
@Test
public void testInsertOneToMany() throws Exception {
final Person person = randomPerson();
data.insert(person).map(new Function<Person, Phone>() {
@Override
public Phone apply(Person person) {
Phone phone1 = randomPhone();
phone1.setOwner(person);
return phone1;
}
}).flatMap(new Function<Phone, Single<?>>() {
@Override
public Single<?> apply(Phone phone) {
return data.insert(phone);
}
}).blockingGet();
assertTrue(person.getPhoneNumbers().toList().size() == 1);
}
use of io.requery.test.model.Person in project requery by requery.
the class ReactiveTest method testQuerySelfObservable.
@Test
public void testQuerySelfObservable() throws Exception {
final AtomicInteger count = new AtomicInteger();
data.select(Person.class).get().observableResult().subscribe(new Consumer<Result<Person>>() {
@Override
public void accept(Result<Person> persons) {
count.incrementAndGet();
}
});
data.insert(randomPerson()).blockingGet();
data.insert(randomPerson()).blockingGet();
assertEquals(3, count.get());
}
use of io.requery.test.model.Person in project requery by requery.
the class ReactiveTest method testQuerySelfObservableMap.
@Test
public void testQuerySelfObservableMap() throws Exception {
final AtomicInteger count = new AtomicInteger();
Disposable disposable = data.select(Person.class).limit(2).get().observableResult().flatMap(new Function<ReactiveResult<Person>, Observable<Person>>() {
@Override
public Observable<Person> apply(ReactiveResult<Person> persons) {
return persons.observable();
}
}).subscribe(new Consumer<Person>() {
@Override
public void accept(Person persons) {
count.incrementAndGet();
}
});
data.insert(randomPerson()).blockingGet();
data.insert(randomPerson()).blockingGet();
assertEquals(3, count.get());
disposable.dispose();
}
use of io.requery.test.model.Person in project requery by requery.
the class ReactiveTest method testDelete.
@Test
public void testDelete() throws Exception {
Person person = randomPerson();
data.insert(person).blockingGet();
data.delete(person).blockingGet();
Person cached = data.select(Person.class).where(Person.ID.equal(person.getId())).get().firstOrNull();
assertNull(cached);
}
use of io.requery.test.model.Person in project requery by requery.
the class ReactiveTest method testInsert.
@Test
public void testInsert() throws Exception {
Person person = randomPerson();
final CountDownLatch latch = new CountDownLatch(1);
data.insert(person).subscribe(new Consumer<Person>() {
@Override
public void accept(Person person) {
assertTrue(person.getId() > 0);
Person cached = data.select(Person.class).where(Person.ID.equal(person.getId())).get().first();
assertSame(cached, person);
latch.countDown();
}
});
latch.await();
}
Aggregations