use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class QueryEagerTest method testEagerFindAll.
public void testEagerFindAll() {
resetData();
List<Student> sList = DataSupport.findAll(Student.class);
for (Student s : sList) {
assertNull(s.getClassroom());
assertEquals(0, s.getTeachers().size());
}
sList = DataSupport.findAll(Student.class, true);
for (Student s : sList) {
if (s.getClassroom() == null) {
continue;
}
assertEquals("Classroom 11", s.getClassroom().getName());
assertTrue(s.getTeachers().size() > 0);
List<Teacher> tList = s.getTeachers();
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();
}
}
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class QueryEagerTest method testEagerClusterQuery.
public void testEagerClusterQuery() {
resetData();
List<Student> sList = DataSupport.where("id = ?", String.valueOf(student1.getId())).find(Student.class);
assertEquals(1, sList.size());
Student s = sList.get(0);
assertNull(s.getClassroom());
sList = DataSupport.where("id = ?", String.valueOf(student1.getId())).find(Student.class, true);
assertEquals(1, sList.size());
s = sList.get(0);
assertNotNull(s.getClassroom());
Classroom c = s.getClassroom();
assertEquals("Classroom 11", c.getName());
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class QueryEagerTest method setUp.
@Override
protected void setUp() {
Calendar calendar = Calendar.getInstance();
classroom = new Classroom();
classroom.setName("Classroom 11");
idcard1 = new IdCard();
idcard1.setNumber("320311");
idcard2 = new IdCard();
idcard2.setNumber("320322");
calendar.clear();
calendar.set(1990, 9, 16, 0, 0, 0);
student1 = new Student();
student1.setName("Student 1");
student1.setClassroom(classroom);
student1.setIdcard(idcard1);
student1.setBirthday(calendar.getTime());
calendar.clear();
calendar.set(1989, 7, 7, 0, 0, 0);
student2 = new Student();
student2.setName("Student 2");
student2.setClassroom(classroom);
student2.setBirthday(calendar.getTime());
student3 = new Student();
student3.setName("Student 3");
teacher1 = new Teacher();
teacher1.setTeacherName("Teacher 1");
teacher1.setTeachYears(3);
teacher1.setIdCard(idcard2);
teacher2 = new Teacher();
teacher2.setSex(false);
teacher2.setTeacherName("Teacher 2");
student1.getTeachers().add(teacher1);
student1.getTeachers().add(teacher2);
student2.getTeachers().add(teacher2);
classroom.getTeachers().add(teacher1);
classroom.save();
student1.save();
student2.save();
student3.save();
idcard1.save();
idcard2.save();
teacher1.save();
teacher2.save();
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class Many2ManySaveTest method init.
private void init() {
danny = new Student();
danny.setName("Danny");
danny.setAge(14);
mick = new Student();
mick.setName("Mick");
mick.setAge(13);
cam = new Teacher();
cam.setTeacherName("Cam");
cam.setAge(33);
cam.setSex(true);
cam.setTeachYears(5);
jack = new Teacher();
jack.setTeacherName("Jack");
jack.setAge(36);
jack.setSex(false);
jack.setTeachYears(11);
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateWithDefaultValueWithInstanceUpdate.
public void testUpdateWithDefaultValueWithInstanceUpdate() {
Teacher t = new Teacher();
t.setTeacherName("");
t.setTeachYears(0);
t.setSex(true);
t.setAge(22);
int affectedTeacher = t.update(teacher.getId());
assertEquals(0, affectedTeacher);
Teacher newTeacher = getTeacher(teacher.getId());
assertEquals(teacher.getAge(), newTeacher.getAge());
assertEquals(teacher.getTeacherName(), newTeacher.getTeacherName());
assertEquals(teacher.getTeachYears(), newTeacher.getTeachYears());
assertEquals(teacher.isSex(), newTeacher.isSex());
Student s = new Student();
s.setName(null);
s.setAge(0);
int affectedStudent = s.update(student.getId());
assertEquals(0, affectedStudent);
Student newStudent = getStudent(student.getId());
assertEquals(student.getName(), newStudent.getName());
assertEquals(student.getAge(), newStudent.getAge());
}
Aggregations