Exemplo n.º 1
0
 public void testBackupAndRestore() throws IOException {
   dao.deleteAll();
   persistRandomEntities(11);
   SimpleEntity e = newTestEntity();
   dao.insert(e);
   List<SimpleEntity> before = dao.listAll();
   SQLiteDatabase db = dbHelper.getWritableDatabase();
   dbHelper.backupAllTablesToCsv(ctx, db, null);
   dbHelper.dropAndCreate(db);
   assertEquals(0, dao.listAll().size());
   dbHelper.restoreAllTablesFromCsv(ctx, db, null);
   List<SimpleEntity> after = dao.listAll();
   for (int i = 0; i < before.size(); i++) {
     DaoTestCase.assertAllFieldsMatch(before.get(i), after.get(i));
   }
 }
Exemplo n.º 2
0
 public void testRestoreWithDefaultValuesForNewFields() {
   SQLiteDatabase db = dbHelper.getWritableDatabase();
   dbHelper.dropAndCreate(db);
   SimpleEntityTable th = new SimpleEntityTable();
   InputStream csvStream =
       this.getClass().getClassLoader().getResourceAsStream("assets/testDb.v0.SimpleEntity");
   new CsvTableReader(th).importFromCsv(db, csvStream);
   List<SimpleEntity> listAll = dao.listAll();
   assertEquals(1, listAll.size());
   SimpleEntity newEntity = new SimpleEntity();
   newEntity.setId(1);
   DaoTestCase.assertAllFieldsMatch(newEntity, listAll.get(0));
 }
Exemplo n.º 3
0
 /**
  * Read in a CSV file from the prior db version with columns added and dropped. Ensure that the
  * unchanged columns are matched by name and that new columns have the expected default values.
  */
 public void testReadFromCsv() {
   SQLiteDatabase db = dbHelper.getWritableDatabase();
   dbHelper.dropAndCreate(db);
   SimpleEntityTable th = new SimpleEntityTable();
   InputStream csvStream =
       this.getClass().getClassLoader().getResourceAsStream("assets/testDb.v1.SimpleEntity");
   new CsvTableReader(th).importFromCsv(db, csvStream);
   List<SimpleEntity> listAll = dao.listAll();
   assertEquals(2, listAll.size());
   SimpleEntity testEntity = newTestEntity();
   testEntity.setId(1);
   testEntity.setCharField((char) 0); // Expected default value
   DaoTestCase.assertAllFieldsMatch(testEntity, listAll.get(0));
   SimpleEntity newEntity = new SimpleEntity();
   newEntity.setId(2);
   DaoTestCase.assertAllFieldsMatch(newEntity, listAll.get(1));
 }