use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class DeleteTest method testDeleteById.
public void testDeleteById() {
initJude();
jude.save();
int rowsAffected = DataSupport.delete(Student.class, jude.getId());
assertEquals(1, rowsAffected);
Student s = getStudent(jude.getId());
assertNull(s);
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class DeleteTest method testDeleteNoSavedModelWithNoParameter.
public void testDeleteNoSavedModelWithNoParameter() {
Student tony = new Student();
tony.setName("Tony");
tony.setAge(23);
int rowsAffected = tony.delete();
assertEquals(0, rowsAffected);
}
use of com.litepaltest.model.Student 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.Student in project LitePal by LitePalFramework.
the class DeleteTest method initJude.
private void initJude() {
jude = new Student();
jude.setName("Jude");
jude.setAge(13);
judeCard = new IdCard();
judeCard.setAddress("Jude Street");
judeCard.setNumber("123456");
jude.setIdcard(judeCard);
judeCard.setStudent(jude);
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class LitePalTestCase method getStudents.
protected List<Student> getStudents(int[] ids) {
List<Student> students = new ArrayList<Student>();
Cursor cursor = Connector.getDatabase().query(getTableName(Student.class), null, getWhere(ids), null, null, null, null);
if (cursor.moveToFirst()) {
Student s = new Student();
String name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
int age = cursor.getInt(cursor.getColumnIndexOrThrow("age"));
s.setName(name);
s.setAge(age);
students.add(s);
}
cursor.close();
return students;
}
Aggregations