Search in sources :

Example 1 with Student

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

Example 2 with Student

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);
}
Also used : Cursor(android.database.Cursor) Student(com.litepaltest.model.Student)

Example 3 with Student

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

Example 4 with Student

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) {
    }
}
Also used : DataSupportException(org.litepal.exceptions.DataSupportException) Student(com.litepaltest.model.Student) DataSupportException(org.litepal.exceptions.DataSupportException) SQLiteException(android.database.sqlite.SQLiteException)

Example 5 with Student

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

Aggregations

Student (com.litepaltest.model.Student)34 Classroom (com.litepaltest.model.Classroom)11 Teacher (com.litepaltest.model.Teacher)11 IdCard (com.litepaltest.model.IdCard)8 ArrayList (java.util.ArrayList)5 Cursor (android.database.Cursor)4 Calendar (java.util.Calendar)4 Random (java.util.Random)4 Date (java.util.Date)2 ContentValues (android.content.ContentValues)1 SQLiteException (android.database.sqlite.SQLiteException)1 Cellphone (com.litepaltest.model.Cellphone)1 DataSupportException (org.litepal.exceptions.DataSupportException)1