use of io.requery.test.model.Person in project requery by requery.
the class RxTest method testRunInTransaction.
@Test
public void testRunInTransaction() {
final Person person = randomPerson();
data.runInTransaction(data.insert(person), data.update(person), data.delete(person)).toBlocking().forEach(new Action1<Object>() {
@Override
public void call(Object o) {
}
});
assertEquals(0, data.count(Person.class).get().value().intValue());
final Person person2 = randomPerson();
data.runInTransaction(data.insert(person2)).toBlocking().forEach(new Action1<Person>() {
@Override
public void call(Person person) {
}
});
assertEquals(1, data.count(Person.class).get().value().intValue());
}
use of io.requery.test.model.Person in project requery by requery.
the class RxTest method testQueryObservable.
@Test
public void testQueryObservable() throws Exception {
for (int i = 0; i < 30; i++) {
Person person = randomPerson();
data.insert(person).toBlocking().value();
}
final List<Person> people = new ArrayList<>();
data.select(Person.class).limit(50).get().toObservable().subscribe(new Action1<Person>() {
@Override
public void call(Person person) {
people.add(person);
}
});
assertEquals(30, people.size());
}
use of io.requery.test.model.Person in project requery by requery.
the class ReactiveTest method testSelfObservableDeleteQuery.
@Test
public void testSelfObservableDeleteQuery() throws Exception {
final AtomicInteger count = new AtomicInteger();
Disposable disposable = data.select(Person.class).get().observableResult().subscribe(new Consumer<Result<Person>>() {
@Override
public void accept(Result<Person> persons) {
count.incrementAndGet();
}
});
Person person = randomPerson();
data.insert(person).blockingGet();
assertEquals(2, count.get());
int rows = data.delete(Person.class).get().value();
assertEquals(3, count.get());
disposable.dispose();
assertEquals(rows, 1);
}
use of io.requery.test.model.Person in project requery by requery.
the class ReactiveTest method testRunInTransaction.
@Test
public void testRunInTransaction() {
final Person person = randomPerson();
data.runInTransaction(data.insert(person), data.update(person)).subscribe(new Consumer<Object>() {
@Override
public void accept(Object o) {
}
});
assertEquals(1, data.count(Person.class).get().value().intValue());
}
use of io.requery.test.model.Person in project requery by requery.
the class ReactiveTest method testQueryEmpty.
@Test
public void testQueryEmpty() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
data.select(Person.class).get().observable().subscribe(new Consumer<Person>() {
@Override
public void accept(Person person) throws Exception {
Assert.fail();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Assert.fail();
}
}, new Action() {
@Override
public void run() throws Exception {
latch.countDown();
}
});
if (!latch.await(1, TimeUnit.SECONDS)) {
Assert.fail();
}
}
Aggregations