use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class QueryEagerTest method testEagerFindFirst.
public void testEagerFindFirst() {
resetData();
Student s1 = DataSupport.findFirst(Student.class);
assertNull(s1.getClassroom());
s1 = DataSupport.findFirst(Student.class, true);
assertNotNull(s1);
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateAllRowsWithInstanceUpdate.
public void testUpdateAllRowsWithInstanceUpdate() {
Cursor c = Connector.getDatabase().query(studentTable, null, null, null, null, null, null);
int allRows = c.getCount();
c.close();
Student student = new Student();
student.setName("Zuckerburg");
int affectedRows = student.updateAll();
assertEquals(allRows, affectedRows);
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method initForAssociations.
private void initForAssociations() {
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");
s2.setAge(19);
s3 = new Student();
s3.setName("Miley");
s3.setAge(16);
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 testUpdateAllWithInstanceUpdateButWrongConditions.
public void testUpdateAllWithInstanceUpdateButWrongConditions() {
Student student = new Student();
student.setName("Dustee");
try {
student.updateAll(new String[] { "name = 'Dustin'", "aaa" });
fail();
} catch (DataSupportException e) {
assertEquals("The parameters in conditions are incorrect.", e.getMessage());
}
try {
student.updateAll(new String[] { null, null });
fail();
} catch (DataSupportException e) {
assertEquals("The parameters in conditions are incorrect.", e.getMessage());
}
try {
student.updateAll(new String[] { "address = ?", "HK" });
fail();
} catch (Exception e) {
}
}
use of com.litepaltest.model.Student in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateAllToDefaultValueWithInstanceUpdate.
public void testUpdateAllToDefaultValueWithInstanceUpdate() {
Student stu;
int[] ids = new int[5];
for (int i = 0; i < 5; i++) {
stu = new Student();
stu.setName("Michael Jackson");
stu.setAge(18);
stu.save();
ids[i] = stu.getId();
}
Student s = new Student();
s.setToDefault("age");
s.setToDefault("name");
int affectedStudent = s.updateAll(new String[] { "name = 'Michael Jackson'" });
assertEquals(5, affectedStudent);
List<Student> students = getStudents(ids);
for (Student updatedStudent : students) {
assertEquals(null, updatedStudent.getName());
assertEquals(0, updatedStudent.getAge());
}
}
Aggregations