use of com.litepaltest.model.IdCard in project LitePal by LitePalFramework.
the class UpdateUsingSaveMethodTest method init.
private void init() {
Calendar calendar = Calendar.getInstance();
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");
calendar.clear();
calendar.set(1990, 9, 16, 0, 0, 0);
s2.setBirthday(calendar.getTime());
s2.setAge(19);
s3 = new Student();
s3.setName("Miley");
s3.setAge(16);
id1 = new IdCard();
id1.setNumber("999777123");
id1.setAddress("Zhushan road");
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.IdCard in project LitePal by LitePalFramework.
the class SaveAllTest method testSaveAllWithO2O.
public void testSaveAllWithO2O() {
List<IdCard> idcardList = new ArrayList<IdCard>();
List<Student> studentList = new ArrayList<Student>();
for (int i = 0; i < 50; i++) {
IdCard idcard = new IdCard();
idcard.setNumber(String.valueOf(new Random().nextInt(2000000)));
Student student = new Student();
student.setName("Jim");
student.setAge(new Random().nextInt(20));
student.setIdcard(idcard);
idcardList.add(idcard);
studentList.add(student);
}
DataSupport.saveAll(idcardList);
DataSupport.saveAll(studentList);
for (Student student : studentList) {
List<IdCard> result = DataSupport.where(studentTable + "_id=?", String.valueOf(student.getId())).find(IdCard.class);
assertEquals(1, result.size());
}
}
use of com.litepaltest.model.IdCard 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.IdCard in project LitePal by LitePalFramework.
the class LitePalTestCase method getIdCard.
protected IdCard getIdCard(long id) {
IdCard card = null;
Cursor cursor = Connector.getDatabase().query(getTableName(IdCard.class), null, "id = ?", new String[] { String.valueOf(id) }, null, null, null);
if (cursor.moveToFirst()) {
card = new IdCard();
String address = cursor.getString(cursor.getColumnIndexOrThrow("address"));
String number = cursor.getString(cursor.getColumnIndexOrThrow("number"));
card.setAddress(address);
card.setNumber(number);
}
cursor.close();
return card;
}
use of com.litepaltest.model.IdCard 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());
}
Aggregations