Search in sources :

Example 51 with TestEntity

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());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 52 with TestEntity

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());
    }
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 53 with TestEntity

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);
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) TestSubscriber(rx.observers.TestSubscriber) Subscription(rx.Subscription)

Example 54 with TestEntity

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);
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 55 with TestEntity

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;
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) ArrayList(java.util.ArrayList)

Aggregations

TestEntity (org.greenrobot.greendao.daotest.TestEntity)72 ArrayList (java.util.ArrayList)16 RelationEntity (org.greenrobot.greendao.daotest.RelationEntity)4 List (java.util.List)3 DaoException (org.greenrobot.greendao.DaoException)2 TestSubscriber (rx.observers.TestSubscriber)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 WhereCondition (org.greenrobot.greendao.query.WhereCondition)1 Subscription (rx.Subscription)1