Search in sources :

Example 6 with Classroom

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

the class LitePalTestCase method getClassroom.

protected Classroom getClassroom(long id) {
    Classroom c = null;
    Cursor cursor = Connector.getDatabase().query(getTableName(Classroom.class), null, "id = ?", new String[] { String.valueOf(id) }, null, null, null);
    if (cursor.moveToFirst()) {
        c = new Classroom();
        String name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
        c.setName(name);
    }
    cursor.close();
    return c;
}
Also used : Classroom(com.litepaltest.model.Classroom) Cursor(android.database.Cursor)

Example 7 with Classroom

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

Example 8 with Classroom

use of com.litepaltest.model.Classroom 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();
}
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 9 with Classroom

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

the class SaveTest method testSaveGenericData.

public void testSaveGenericData() {
    Classroom classroom = new Classroom();
    classroom.setName("classroom1");
    classroom.getNews().add("news1");
    classroom.getNews().add("news2");
    classroom.getNews().add("news3");
    List<Integer> numbers = new ArrayList<>();
    numbers.add(1);
    numbers.add(2);
    numbers.add(3);
    numbers.add(4);
    classroom.setNumbers(numbers);
    classroom.save();
    Classroom c = DataSupport.find(Classroom.class, classroom.get_id());
    assertEquals("classroom1", c.getName());
    assertEquals(3, c.getNews().size());
    assertEquals(4, c.getNumbers().size());
    for (String news : c.getNews()) {
        assertTrue(news.equals("news1") || news.equals("news2") || news.equals("news3"));
    }
    for (int number : c.getNumbers()) {
        assertTrue(number == 1 || number == 2 || number == 3 || number == 4);
    }
}
Also used : Classroom(com.litepaltest.model.Classroom) ArrayList(java.util.ArrayList)

Example 10 with Classroom

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

the class UpdateUsingSaveMethodTest method testUpdateGenericData.

public void testUpdateGenericData() {
    Classroom classroom = new Classroom();
    classroom.setName("Classroom origin");
    classroom.getNews().add("n");
    classroom.getNews().add("e");
    classroom.getNews().add("w");
    classroom.getNumbers().add(1);
    classroom.getNumbers().add(2);
    classroom.getNumbers().add(3);
    classroom.save();
    classroom.setName("Classroom update");
    classroom.getNews().add("s");
    classroom.getNumbers().clear();
    classroom.save();
    Classroom c = DataSupport.find(Classroom.class, classroom.get_id());
    assertEquals("Classroom update", c.getName());
    assertEquals(4, classroom.getNews().size());
    assertEquals(0, classroom.getNumbers().size());
    StringBuilder builder = new StringBuilder();
    for (String s : classroom.getNews()) {
        builder.append(s);
    }
    assertEquals("news", builder.toString());
}
Also used : Classroom(com.litepaltest.model.Classroom)

Aggregations

Classroom (com.litepaltest.model.Classroom)20 Student (com.litepaltest.model.Student)11 Teacher (com.litepaltest.model.Teacher)7 IdCard (com.litepaltest.model.IdCard)4 ArrayList (java.util.ArrayList)3 Calendar (java.util.Calendar)3 Cursor (android.database.Cursor)2 Random (java.util.Random)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Cellphone (com.litepaltest.model.Cellphone)1 Computer (com.litepaltest.model.Computer)1 Headset (com.litepaltest.model.Headset)1 Product (com.litepaltest.model.Product)1 Date (java.util.Date)1 LitePalDB (org.litepal.LitePalDB)1