use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class RxDaoTest method testInsertInTxList.
public void testInsertInTxList() {
TestEntity foo = RxTestHelper.createEntity("foo");
TestEntity bar = RxTestHelper.createEntity("bar");
List<TestEntity> list = new ArrayList<>();
list.add(foo);
list.add(bar);
TestSubscriber<List<TestEntity>> testSubscriber = RxTestHelper.awaitTestSubscriber(rxDao.insertInTx(list));
assertEquals(1, testSubscriber.getValueCount());
List<TestEntity> result = testSubscriber.getOnNextEvents().get(0);
assertSame(foo, result.get(0));
assertSame(bar, result.get(1));
List<TestEntity> all = dao.loadAll();
assertEquals(2, all.size());
assertEquals(foo.getSimpleStringNotNull(), all.get(0).getSimpleStringNotNull());
assertEquals(bar.getSimpleStringNotNull(), all.get(1).getSimpleStringNotNull());
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class RxQueryTest method testOneByOne.
public void testOneByOne() {
insertEntities(15);
TestSubscriber<TestEntity> testSubscriber = RxTestHelper.awaitTestSubscriber(rxQuery.oneByOne());
assertEquals(10, testSubscriber.getValueCount());
for (int i = 0; i < 10; i++) {
TestEntity entity = testSubscriber.getOnNextEvents().get(i);
assertEquals(i, entity.getSimpleInt());
}
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class RxQueryTest method testOneByOneUnsubscribe.
public void testOneByOneUnsubscribe() {
insertEntities(1000);
RxQuery<TestEntity> bigQuery = daoSession.getTestEntityDao().queryBuilder().rx();
TestSubscriber<TestEntity> testSubscriber = new TestSubscriber<>();
Observable<TestEntity> observable = bigQuery.oneByOne();
Subscription subscription = observable.subscribe(testSubscriber);
subscription.unsubscribe();
testSubscriber.assertUnsubscribed();
int count = testSubscriber.getValueCount();
testSubscriber.awaitTerminalEvent(100, TimeUnit.MILLISECONDS);
int count2 = testSubscriber.getValueCount();
DaoLog.d("Count 1: " + count + " vs. count 2: " + count2);
// Not strictly multi-threading correct, but anyway:
assertTrue(count2 < 1000);
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class RxQueryTest method testUnique.
public void testUnique() {
insertEntities(1);
TestSubscriber<TestEntity> testSubscriber = RxTestHelper.awaitTestSubscriber(rxQuery.unique());
assertEquals(1, testSubscriber.getValueCount());
TestEntity entityRead = testSubscriber.getOnNextEvents().get(0);
assertNotNull(entityRead);
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class RxQueryTest method insertEntities.
protected List<TestEntity> insertEntities(int count) {
List<TestEntity> entities = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
TestEntity entity = RxTestHelper.createEntity("My entity ");
entity.setSimpleInt(i);
entities.add(entity);
}
daoSession.getTestEntityDao().insertInTx(entities);
return entities;
}
Aggregations