use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class RelationEntityTest method testToOneUpdateKey.
public void testToOneUpdateKey() {
RelationEntity entity = insertEntityWithRelations(42l);
TestEntity testEntity = entity.getTestEntity();
RelationEntity entity2 = insertEntityWithRelations(43l);
TestEntity testEntity2 = entity2.getTestEntity();
entity.setTestId(testEntity2.getId());
assertEquals(testEntity2.getId(), entity.getTestEntity().getId());
entity.setTestId(null);
assertNull(entity.getTestEntity());
entity.setTestId(testEntity.getId());
assertEquals(testEntity.getId(), entity.getTestEntity().getId());
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class RelationEntityTest method insertEntityWithRelations.
protected RelationEntity insertEntityWithRelations(Long testEntityId) {
TestEntity testEntity = daoSession.getTestEntityDao().load(testEntityId);
if (testEntity == null) {
testEntity = new TestEntity(testEntityId);
testEntity.setSimpleStringNotNull("mytest");
daoSession.getTestEntityDao().insert(testEntity);
}
RelationEntity parentEntity = createEntity(null);
parentEntity.setSimpleString("I'm a parent");
parentEntity.setTestNotNull(testEntity);
dao.insert(parentEntity);
RelationEntity entity = createEntity(null);
entity.setTestId(testEntityId);
entity.setParentId(parentEntity.getId());
entity.setSimpleString("findMe");
entity.setTestNotNull(testEntity);
dao.insert(entity);
return entity;
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class RxDaoTest method testDeleteByKeyInTxList.
public void testDeleteByKeyInTxList() {
TestEntity foo = insertEntity("foo");
TestEntity bar = insertEntity("bar");
List<Long> list = new ArrayList<>();
list.add(foo.getId());
list.add(bar.getId());
assertDeleted(rxDao.deleteByKeyInTx(list));
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class TransactionTest method testUpdateTxFailed.
public void testUpdateTxFailed() {
String sql = "CREATE UNIQUE INDEX test_simple_string_unique ON " + TestEntityDao.TABLENAME + "(" + Properties.SimpleString.columnName + ")";
dao.getDatabase().execSQL(sql);
ArrayList<TestEntity> entities = insert(2);
TestEntity entity1 = entities.get(0);
String valueBeforeUpdate = entity1.getSimpleString();
entity1.setSimpleString("unique");
entities.get(1).setSimpleString("unique");
try {
dao.updateInTx(entities);
fail("Should have thrown");
} catch (RuntimeException e) {
// OK
}
dao.refresh(entity1);
assertEquals(valueBeforeUpdate, entity1.getSimpleString());
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class LazyListTest method testIterator.
protected void testIterator(ArrayList<TestEntity> list, LazyList<TestEntity> listLazy, boolean uncached) {
ListIterator<TestEntity> iterator = listLazy.listIterator();
try {
iterator.previous();
fail("previous should throw here");
} catch (NoSuchElementException expected) {
// OK
}
int size = list.size();
for (int i = 0; i < size; i++) {
assertTrue(iterator.hasNext());
assertEquals(i > 0, iterator.hasPrevious());
assertEquals(i, iterator.nextIndex());
assertEquals(i - 1, iterator.previousIndex());
if (i > 0) {
TestEntity entityPrevious = list.get(i - 1);
assertEquals(entityPrevious.getId(), iterator.previous().getId());
iterator.next();
}
TestEntity entity = list.get(i);
assertNull(listLazy.peek(i));
TestEntity lazyEntity = iterator.next();
if (uncached) {
assertNull(listLazy.peek(i));
} else {
assertNotNull(listLazy.peek(i));
}
assertEquals(entity.getId(), lazyEntity.getId());
}
assertFalse(iterator.hasNext());
try {
iterator.next();
fail("next should throw here");
} catch (NoSuchElementException expected) {
// OK
}
}
Aggregations