use of com.litepaltest.model.Computer in project LitePal by LitePalFramework.
the class MultiDatabaseTest method testMultiDatabase.
public void testMultiDatabase() {
LitePal.deleteDatabase("db2");
SQLiteDatabase db = LitePal.getDatabase();
assertTrue(DBUtility.isTableExists("Album", db));
assertTrue(DBUtility.isTableExists("Song", db));
assertTrue(DBUtility.isTableExists("Singer", db));
assertTrue(DBUtility.isTableExists("Classroom", db));
assertTrue(DBUtility.isTableExists("Teacher", db));
assertTrue(DBUtility.isTableExists("IdCard", db));
assertTrue(DBUtility.isTableExists("Student", db));
assertTrue(DBUtility.isTableExists("Cellphone", db));
assertTrue(DBUtility.isTableExists("Computer", db));
assertTrue(DBUtility.isTableExists("Book", db));
assertTrue(DBUtility.isTableExists("Product", db));
assertTrue(DBUtility.isTableExists("Headset", db));
assertTrue(DBUtility.isTableExists("WeChatMessage", db));
assertTrue(DBUtility.isTableExists("WeiboMessage", db));
LitePalDB litePalDB = new LitePalDB("db2", 1);
litePalDB.addClassName(Classroom.class.getName());
litePalDB.addClassName(Product.class.getName());
litePalDB.setExternalStorage(true);
LitePal.use(litePalDB);
db = LitePal.getDatabase();
assertFalse(DBUtility.isTableExists("Album", db));
assertFalse(DBUtility.isTableExists("Song", db));
assertFalse(DBUtility.isTableExists("Singer", db));
assertTrue(DBUtility.isTableExists("Classroom", db));
assertFalse(DBUtility.isTableExists("Teacher", db));
assertFalse(DBUtility.isTableExists("IdCard", db));
assertFalse(DBUtility.isTableExists("Student", db));
assertFalse(DBUtility.isTableExists("Cellphone", db));
assertFalse(DBUtility.isTableExists("Computer", db));
assertFalse(DBUtility.isTableExists("Book", db));
assertTrue(DBUtility.isTableExists("Product", db));
assertFalse(DBUtility.isTableExists("Headset", db));
assertFalse(DBUtility.isTableExists("WeChatMessage", db));
assertFalse(DBUtility.isTableExists("WeiboMessage", db));
litePalDB = new LitePalDB("db2", 2);
litePalDB.addClassName(Computer.class.getName());
litePalDB.addClassName(Product.class.getName());
litePalDB.addClassName(Headset.class.getName());
litePalDB.setExternalStorage(true);
LitePal.use(litePalDB);
db = LitePal.getDatabase();
assertFalse(DBUtility.isTableExists("Album", db));
assertFalse(DBUtility.isTableExists("Song", db));
assertFalse(DBUtility.isTableExists("Singer", db));
assertFalse(DBUtility.isTableExists("Classroom", db));
assertFalse(DBUtility.isTableExists("Teacher", db));
assertFalse(DBUtility.isTableExists("IdCard", db));
assertFalse(DBUtility.isTableExists("Student", db));
assertFalse(DBUtility.isTableExists("Cellphone", db));
assertTrue(DBUtility.isTableExists("Computer", db));
assertFalse(DBUtility.isTableExists("Book", db));
assertTrue(DBUtility.isTableExists("Product", db));
assertTrue(DBUtility.isTableExists("Headset", db));
assertFalse(DBUtility.isTableExists("WeChatMessage", db));
assertFalse(DBUtility.isTableExists("WeiboMessage", db));
LitePal.useDefault();
db = LitePal.getDatabase();
assertTrue(DBUtility.isTableExists("Album", db));
assertTrue(DBUtility.isTableExists("Song", db));
assertTrue(DBUtility.isTableExists("Singer", db));
assertTrue(DBUtility.isTableExists("Classroom", db));
assertTrue(DBUtility.isTableExists("Teacher", db));
assertTrue(DBUtility.isTableExists("IdCard", db));
assertTrue(DBUtility.isTableExists("Student", db));
assertTrue(DBUtility.isTableExists("Cellphone", db));
assertTrue(DBUtility.isTableExists("Computer", db));
assertTrue(DBUtility.isTableExists("Book", db));
assertTrue(DBUtility.isTableExists("Product", db));
assertTrue(DBUtility.isTableExists("Headset", db));
assertTrue(DBUtility.isTableExists("WeChatMessage", db));
assertTrue(DBUtility.isTableExists("WeiboMessage", db));
}
use of com.litepaltest.model.Computer in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateWithInstanceUpdateWithConstructor.
public void testUpdateWithInstanceUpdateWithConstructor() {
try {
Computer computer = new Computer("ACER", 5444);
computer.save();
computer.update(computer.getId());
fail();
} catch (DataSupportException e) {
assertEquals("com.litepaltest.model.Computer needs a default constructor.", e.getMessage());
}
}
use of com.litepaltest.model.Computer in project LitePal by LitePalFramework.
the class SaveTest method testSaveWithConstructors.
public void testSaveWithConstructors() {
Computer computer = new Computer("asus", 699.00);
assertTrue(computer.save());
Assert.assertTrue(isDataExists(getTableName(computer), computer.getId()));
Computer c = getComputer(computer.getId());
assertEquals("asus", c.getBrand());
assertEquals(699.00, c.getPrice());
Computer cc = DataSupport.find(Computer.class, computer.getId());
assertEquals("asus", cc.getBrand());
assertEquals(699.00, cc.getPrice());
Product p = new Product(null);
p.setBrand("apple");
p.setPrice(1222.33);
p.save();
Product.find(Product.class, p.getId());
}
use of com.litepaltest.model.Computer in project LitePal by LitePalFramework.
the class SaveTest method testSaveFastWithConstructors.
public void testSaveFastWithConstructors() {
Computer computer = new Computer("asus", 699.00);
assertTrue(computer.saveFast());
Assert.assertTrue(isDataExists(getTableName(computer), computer.getId()));
Computer c = getComputer(computer.getId());
assertEquals("asus", c.getBrand());
assertEquals(699.00, c.getPrice());
Computer cc = DataSupport.find(Computer.class, computer.getId());
assertEquals("asus", cc.getBrand());
assertEquals(699.00, cc.getPrice());
Product p = new Product(null);
p.setBrand("apple");
p.setPrice(1222.33);
p.saveFast();
Product.find(Product.class, p.getId());
}
use of com.litepaltest.model.Computer in project LitePal by LitePalFramework.
the class LitePalTestCase method getComputer.
protected Computer getComputer(long id) {
Computer computer = null;
Cursor cursor = Connector.getDatabase().query(getTableName(Computer.class), null, "id = ?", new String[] { String.valueOf(id) }, null, null, null);
if (cursor.moveToFirst()) {
computer = new Computer("", 0);
double newPrice = cursor.getDouble(cursor.getColumnIndexOrThrow("price"));
String brand = cursor.getString(cursor.getColumnIndexOrThrow("brand"));
computer.setBrand(brand);
computer.setPrice(newPrice);
}
cursor.close();
return computer;
}
Aggregations