Search in sources :

Example 21 with Teacher

use of com.litepaltest.model.Teacher 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());
}
Also used : Calendar(java.util.Calendar) Classroom(com.litepaltest.model.Classroom) Teacher(com.litepaltest.model.Teacher) IdCard(com.litepaltest.model.IdCard) Student(com.litepaltest.model.Student)

Example 22 with Teacher

use of com.litepaltest.model.Teacher in project LitePal by LitePalFramework.

the class Many2OneUniSaveTest method init.

public void init() {
    c1 = new Classroom();
    c1.setName("Music room");
    t1 = new Teacher();
    t1.setTeacherName("John");
    t1.setAge(25);
    t2 = new Teacher();
    t2.setTeacherName("Sean");
    t2.setAge(35);
}
Also used : Classroom(com.litepaltest.model.Classroom) Teacher(com.litepaltest.model.Teacher)

Example 23 with Teacher

use of com.litepaltest.model.Teacher in project LitePal by LitePalFramework.

the class UpdateUsingUpdateMethodTest method testUpdateToDefaultValueWithInstanceUpdateButWrongField.

public void testUpdateToDefaultValueWithInstanceUpdateButWrongField() {
    try {
        Teacher t = new Teacher();
        t.setToDefault("name");
        t.update(t.getId());
        fail();
    } catch (DataSupportException e) {
        assertEquals("The name field in com.litepaltest.model.Teacher class is necessary which does not exist.", e.getMessage());
    }
}
Also used : DataSupportException(org.litepal.exceptions.DataSupportException) Teacher(com.litepaltest.model.Teacher)

Aggregations

Teacher (com.litepaltest.model.Teacher)23 Student (com.litepaltest.model.Student)11 Classroom (com.litepaltest.model.Classroom)7 IdCard (com.litepaltest.model.IdCard)7 Cursor (android.database.Cursor)3 Calendar (java.util.Calendar)3 ArrayList (java.util.ArrayList)2 DataSupportException (org.litepal.exceptions.DataSupportException)2 Cellphone (com.litepaltest.model.Cellphone)1 Date (java.util.Date)1 Random (java.util.Random)1