use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateToDefaultValueWithInstanceUpdate.
public void testUpdateToDefaultValueWithInstanceUpdate() {
Student s = new Student();
s.setToDefault("age");
s.setToDefault("name");
s.setToDefault("birthday");
int affectedStudent = s.update(student.getId());
assertEquals(1, affectedStudent);
Student newStudent = DataSupport.find(Student.class, student.getId());
assertNull(newStudent.getBirthday());
assertEquals(null, newStudent.getName());
assertEquals(0, newStudent.getAge());
Teacher t = new Teacher();
t.setAge(45);
t.setTeachYears(5);
t.setTeacherName("John");
t.setToDefault("teacherName");
t.setToDefault("age");
int affectedTeacher = t.update(teacher.getId());
assertEquals(1, affectedTeacher);
Teacher newTeacher = getTeacher(teacher.getId());
assertEquals(22, newTeacher.getAge());
assertEquals("", newTeacher.getTeacherName());
assertEquals(5, newTeacher.getTeachYears());
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class UpdateUsingSaveMethodTest method testUpdateM2OAssociationsOnMSide.
public void testUpdateM2OAssociationsOnMSide() {
init();
s1.setClassroom(c1);
s2.setClassroom(c1);
assertTrue(c1.save());
assertTrue(c2.save());
assertTrue(s1.save());
assertTrue(s2.save());
s1.setClassroom(c2);
s2.setClassroom(c2);
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(1989, 7, 7, 0, 0, 0);
s2.setBirthday(calendar.getTime());
assertTrue(s1.save());
assertTrue(s2.save());
assertEquals(c2.get_id(), getForeignKeyValue(studentTable, classroomTable, s1.getId()));
assertEquals(c2.get_id(), getForeignKeyValue(studentTable, classroomTable, s2.getId()));
Student student2 = DataSupport.find(Student.class, s2.getId());
calendar.clear();
calendar.set(1989, 7, 7, 0, 0, 0);
assertEquals(calendar.getTimeInMillis(), student2.getBirthday().getTime());
}
use of com.litepaltest.model.Student 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.Student in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateAllWithInstanceUpdate.
public void testUpdateAllWithInstanceUpdate() {
Student s;
int[] ids = new int[5];
for (int i = 0; i < 5; i++) {
s = new Student();
s.setName("Jessica");
s.setAge(i + 10);
s.save();
ids[i] = s.getId();
}
Date date = new Date();
Student toUpdate = new Student();
toUpdate.setAge(24);
toUpdate.setBirthday(date);
int affectedRows = toUpdate.updateAll(new String[] { "name = ? and age = ?", "Jessica", "13" });
assertEquals(1, affectedRows);
Student updatedStu = DataSupport.find(Student.class, ids[3]);
assertEquals(24, updatedStu.getAge());
assertEquals(date.getTime(), updatedStu.getBirthday().getTime());
toUpdate.setAge(18);
toUpdate.setName("Jess");
affectedRows = toUpdate.updateAll(new String[] { "name = ?", "Jessica" });
assertEquals(5, affectedRows);
List<Student> students = getStudents(ids);
for (Student updatedStudent : students) {
assertEquals("Jess", updatedStudent.getName());
assertEquals(18, updatedStudent.getAge());
}
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method init.
private void init() {
classroom = new Classroom();
classroom.setName("English room");
classroom.getNews().add("hello");
classroom.getNews().add("world");
classroom.getNumbers().add(123);
classroom.getNumbers().add(456);
teacher = new Teacher();
teacher.setTeacherName("Tony");
teacher.setTeachYears(3);
teacher.setAge(23);
teacher.setSex(false);
student = new Student();
student.setName("Jonny");
student.setAge(13);
student.setClassroom(classroom);
student.setBirthday(new Date());
student.getTeachers().add(teacher);
teacher.getStudents().add(student);
student.save();
teacher.save();
classroom.save();
}
Aggregations