use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class SaveTest method testSaveAfterDelete.
public void testSaveAfterDelete() {
Cellphone cell = new Cellphone();
cell.setBrand("iPhone");
cell.setPrice(4998.01);
cell.setInStock('Y');
cell.setSerial(UUID.randomUUID().toString());
Assert.assertTrue(cell.save());
Assert.assertTrue(isDataExists(getTableName(cell), cell.getId()));
assertTrue(cell.delete() > 0);
assertTrue(cell.save());
Assert.assertTrue(isDataExists(getTableName(cell), cell.getId()));
Student stu = new Student();
stu.setName("Jimmy");
IdCard idcard = new IdCard();
idcard.setAddress("Washington");
idcard.setNumber("123456");
idcard.setStudent(stu);
stu.setIdcard(idcard);
stu.save();
idcard.save();
Assert.assertTrue(isDataExists(getTableName(stu), stu.getId()));
Assert.assertTrue(isDataExists(getTableName(idcard), idcard.getId()));
stu.delete();
Assert.assertFalse(isDataExists(getTableName(stu), stu.getId()));
Assert.assertFalse(isDataExists(getTableName(idcard), idcard.getId()));
stu.save();
idcard.save();
Assert.assertTrue(isDataExists(getTableName(stu), stu.getId()));
Assert.assertTrue(isDataExists(getTableName(idcard), idcard.getId()));
Student danny = new Student();
danny.setName("Danny");
danny.setAge(14);
Teacher cam = new Teacher();
cam.setTeacherName("Cam");
cam.setAge(33);
cam.setSex(true);
cam.setTeachYears(5);
Teacher jack = new Teacher();
jack.setTeacherName("Jack");
jack.setAge(36);
jack.setSex(false);
jack.setTeachYears(11);
danny.getTeachers().add(jack);
danny.getTeachers().add(cam);
cam.getStudents().add(danny);
jack.getStudents().add(danny);
danny.save();
cam.save();
jack.save();
Assert.assertTrue(isDataExists(getTableName(danny), danny.getId()));
Assert.assertTrue(isDataExists(getTableName(cam), cam.getId()));
Assert.assertTrue(isDataExists(getTableName(jack), jack.getId()));
danny.delete();
Assert.assertFalse(isDataExists(getTableName(danny), danny.getId()));
Assert.assertTrue(isDataExists(getTableName(cam), cam.getId()));
Assert.assertTrue(isDataExists(getTableName(jack), jack.getId()));
danny.save();
Assert.assertTrue(isDataExists(getTableName(danny), danny.getId()));
assertEquals(danny.getTeachers().size(), 2);
Classroom c = new Classroom();
c.setName("test classroom");
Student s = new Student();
s.setName("Tom");
s.setClassroom(c);
Student s2 = new Student();
s2.setName("Tom");
s2.setClassroom(c);
assertTrue(c.save());
assertTrue(s.save());
assertTrue(s2.save());
Assert.assertTrue(isDataExists(getTableName(c), c.get_id()));
Assert.assertTrue(isDataExists(getTableName(s), s.getId()));
Assert.assertTrue(isDataExists(getTableName(s), s2.getId()));
c.delete();
Assert.assertFalse(isDataExists(getTableName(c), c.get_id()));
Assert.assertFalse(isDataExists(getTableName(s), s.getId()));
Assert.assertFalse(isDataExists(getTableName(s), s2.getId()));
c.save();
s.save();
s2.save();
Assert.assertTrue(isDataExists(getTableName(c), c.get_id()));
Assert.assertTrue(isDataExists(getTableName(s), s.getId()));
Assert.assertTrue(isDataExists(getTableName(s), s2.getId()));
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class LitePalTestCase method getStudent.
protected Student getStudent(long id) {
Student student = null;
Cursor cursor = Connector.getDatabase().query(getTableName(Student.class), null, "id = ?", new String[] { String.valueOf(id) }, null, null, null);
if (cursor.moveToFirst()) {
student = new Student();
String name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
int age = cursor.getInt(cursor.getColumnIndexOrThrow("age"));
student.setName(name);
student.setAge(age);
}
cursor.close();
return student;
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class QueryEagerTest method testEagerFind.
public void testEagerFind() {
Student s1 = DataSupport.find(Student.class, student1.getId(), true);
Classroom c = s1.getClassroom();
IdCard ic = s1.getIdcard();
List<Teacher> tList = s1.getTeachers();
assertNotNull(c);
assertNotNull(ic);
assertEquals(classroom.get_id(), c.get_id());
assertEquals("Classroom 11", c.getName());
assertEquals(idcard1.getId(), ic.getId());
assertEquals("320311", ic.getNumber());
assertEquals(student1.getTeachers().size(), tList.size());
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(1990, 9, 16, 0, 0, 0);
assertEquals(calendar.getTime().getTime(), s1.getBirthday().getTime());
for (Teacher t : tList) {
if (t.getId() == teacher1.getId()) {
assertEquals("Teacher 1", t.getTeacherName());
assertEquals(teacher1.getTeachYears(), t.getTeachYears());
assertTrue(t.isSex());
continue;
}
if (t.getId() == teacher2.getId()) {
assertEquals("Teacher 2", t.getTeacherName());
assertFalse(t.isSex());
continue;
}
fail();
}
s1 = DataSupport.find(Student.class, student1.getId());
c = s1.getClassroom();
assertNull(c);
assertNull(s1.getIdcard());
assertEquals(0, s1.getTeachers().size());
c = DataSupport.find(Classroom.class, classroom.get_id(), true);
assertEquals(2, c.getStudentCollection().size());
assertEquals(1, c.getTeachers().size());
for (Student s : c.getStudentCollection()) {
if (s.getId() == student1.getId()) {
assertEquals("Student 1", s.getName());
continue;
}
if (s.getId() == student2.getId()) {
assertEquals("Student 2", s.getName());
calendar.clear();
calendar.set(1989, 7, 7, 0, 0, 0);
assertEquals(calendar.getTime().getTime(), s.getBirthday().getTime());
continue;
}
fail();
}
Teacher t1 = DataSupport.find(Teacher.class, teacher2.getId(), true);
List<Student> sList = t1.getStudents();
assertEquals(teacher2.getStudents().size(), sList.size());
for (Student s : sList) {
if (s.getId() == student1.getId()) {
assertEquals("Student 1", s.getName());
calendar.clear();
calendar.set(1990, 9, 16, 0, 0, 0);
assertEquals(calendar.getTime().getTime(), s.getBirthday().getTime());
continue;
}
if (s.getId() == student2.getId()) {
assertEquals("Student 2", s.getName());
continue;
}
fail();
}
Student s3 = DataSupport.find(Student.class, student3.getId());
assertNull(s3.getBirthday());
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class Many2OneBiSaveTest method init.
public void init() {
c1 = new Classroom();
c1.setName("Computer room");
s1 = new Student();
s1.setName("Tom");
s2 = new Student();
s2.setName("Lily");
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class One2OneBiSaveTest method init.
private void init() {
s = new Student();
s.setName("Jimmy");
s.setAge(18);
i = new IdCard();
i.setNumber("9997777112");
i.setAddress("Nanjing road");
}
Aggregations