use of com.litepaltest.model.Classroom in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method initForAssociations.
private void initForAssociations() {
c1 = new Classroom();
c1.setName("Working room");
c2 = new Classroom();
c2.setName("Resting room");
s1 = new Student();
s1.setName("Parker");
s1.setAge(18);
s2 = new Student();
s2.setName("Peter");
s2.setAge(19);
s3 = new Student();
s3.setName("Miley");
s3.setAge(16);
t1 = new Teacher();
t1.setTeacherName("Jackson");
t1.setTeachYears(3);
t1.setAge(28);
t2 = new Teacher();
t2.setTeacherName("Rose");
t2.setTeachYears(12);
t2.setAge(34);
}
use of com.litepaltest.model.Classroom 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.Classroom in project LitePal by LitePalFramework.
the class DeleteTest method initGameRoom.
private void initGameRoom() {
gameRoom = new Classroom();
gameRoom.setName("Game room");
}
use of com.litepaltest.model.Classroom in project LitePal by LitePalFramework.
the class DeleteTest method testDeleteAllCascadeWithConditions.
public void testDeleteAllCascadeWithConditions() {
Classroom classroom = new Classroom();
classroom.setName("1" + System.currentTimeMillis());
classroom.save();
Classroom classroom2 = new Classroom();
classroom2.setName("2" + System.currentTimeMillis());
classroom2.save();
Student s1 = new Student();
s1.setClassroom(classroom);
s1.save();
Student s2 = new Student();
s2.setClassroom(classroom);
s2.save();
Student s3 = new Student();
s3.setClassroom(classroom2);
s3.save();
int rows = DataSupport.deleteAll(Classroom.class, "name = ?", classroom.getName());
assertEquals(3, rows);
assertNull(getClassroom(classroom.get_id()));
assertNull(getStudent(s1.getId()));
assertNull(getStudent(s2.getId()));
assertNotNull(getClassroom(classroom2.get_id()));
assertNotNull(getStudent(s3.getId()));
rows = DataSupport.deleteAll(Classroom.class, "name = ?", classroom2.getName());
assertEquals(2, rows);
assertNull(getClassroom(classroom2.get_id()));
assertNull(getStudent(s3.getId()));
}
use of com.litepaltest.model.Classroom in project LitePal by LitePalFramework.
the class DeleteTest method testDeleteWithGenericData.
public void testDeleteWithGenericData() {
Classroom classroom = new Classroom();
classroom.setName("classroom1");
classroom.getNews().add("news1");
classroom.getNews().add("news2");
classroom.getNews().add("news3");
classroom.save();
int id = classroom.get_id();
String tableName = DBUtility.getGenericTableName(Classroom.class.getName(), "news");
String column = DBUtility.getGenericValueIdColumnName(Classroom.class.getName());
Cursor c = DataSupport.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(id));
assertEquals(3, c.getCount());
c.close();
classroom.delete();
c = DataSupport.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(id));
assertEquals(0, c.getCount());
c.close();
assertFalse(classroom.isSaved());
classroom.save();
assertTrue(classroom.isSaved());
c = DataSupport.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(classroom.get_id()));
assertEquals(3, c.getCount());
c.close();
DataSupport.deleteAll(Classroom.class, "id = ?", String.valueOf(classroom.get_id()));
c = DataSupport.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(classroom.get_id()));
assertEquals(0, c.getCount());
c.close();
}
Aggregations