Search in sources :

Example 6 with Cellphone

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

the class SaveAllTest method testSaveAll.

public void testSaveAll() {
    List<Cellphone> cellList = new ArrayList<Cellphone>();
    for (int i = 0; i < 50; i++) {
        Cellphone cellPhone = new Cellphone();
        cellPhone.setBrand("Samsung unique");
        cellPhone.setPrice(Math.random());
        cellPhone.setSerial(UUID.randomUUID().toString());
        cellList.add(cellPhone);
    }
    DataSupport.saveAll(cellList);
    for (Cellphone cell : cellList) {
        assertTrue(cell.isSaved());
    }
}
Also used : ArrayList(java.util.ArrayList) Cellphone(com.litepaltest.model.Cellphone)

Example 7 with Cellphone

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

the class SaveTest method testSaveAfterDelete.

public void testSaveAfterDelete() {
    Cellphone cell = new Cellphone();
    cell.setBrand("iPhone");
    cell.setPrice(4998.01);
    cell.setInStock('Y');
    cell.setSerial(UUID.randomUUID().toString());
    Assert.assertTrue(cell.save());
    Assert.assertTrue(isDataExists(getTableName(cell), cell.getId()));
    assertTrue(cell.delete() > 0);
    assertTrue(cell.save());
    Assert.assertTrue(isDataExists(getTableName(cell), cell.getId()));
    Student stu = new Student();
    stu.setName("Jimmy");
    IdCard idcard = new IdCard();
    idcard.setAddress("Washington");
    idcard.setNumber("123456");
    idcard.setStudent(stu);
    stu.setIdcard(idcard);
    stu.save();
    idcard.save();
    Assert.assertTrue(isDataExists(getTableName(stu), stu.getId()));
    Assert.assertTrue(isDataExists(getTableName(idcard), idcard.getId()));
    stu.delete();
    Assert.assertFalse(isDataExists(getTableName(stu), stu.getId()));
    Assert.assertFalse(isDataExists(getTableName(idcard), idcard.getId()));
    stu.save();
    idcard.save();
    Assert.assertTrue(isDataExists(getTableName(stu), stu.getId()));
    Assert.assertTrue(isDataExists(getTableName(idcard), idcard.getId()));
    Student danny = new Student();
    danny.setName("Danny");
    danny.setAge(14);
    Teacher cam = new Teacher();
    cam.setTeacherName("Cam");
    cam.setAge(33);
    cam.setSex(true);
    cam.setTeachYears(5);
    Teacher jack = new Teacher();
    jack.setTeacherName("Jack");
    jack.setAge(36);
    jack.setSex(false);
    jack.setTeachYears(11);
    danny.getTeachers().add(jack);
    danny.getTeachers().add(cam);
    cam.getStudents().add(danny);
    jack.getStudents().add(danny);
    danny.save();
    cam.save();
    jack.save();
    Assert.assertTrue(isDataExists(getTableName(danny), danny.getId()));
    Assert.assertTrue(isDataExists(getTableName(cam), cam.getId()));
    Assert.assertTrue(isDataExists(getTableName(jack), jack.getId()));
    danny.delete();
    Assert.assertFalse(isDataExists(getTableName(danny), danny.getId()));
    Assert.assertTrue(isDataExists(getTableName(cam), cam.getId()));
    Assert.assertTrue(isDataExists(getTableName(jack), jack.getId()));
    danny.save();
    Assert.assertTrue(isDataExists(getTableName(danny), danny.getId()));
    assertEquals(danny.getTeachers().size(), 2);
    Classroom c = new Classroom();
    c.setName("test classroom");
    Student s = new Student();
    s.setName("Tom");
    s.setClassroom(c);
    Student s2 = new Student();
    s2.setName("Tom");
    s2.setClassroom(c);
    assertTrue(c.save());
    assertTrue(s.save());
    assertTrue(s2.save());
    Assert.assertTrue(isDataExists(getTableName(c), c.get_id()));
    Assert.assertTrue(isDataExists(getTableName(s), s.getId()));
    Assert.assertTrue(isDataExists(getTableName(s), s2.getId()));
    c.delete();
    Assert.assertFalse(isDataExists(getTableName(c), c.get_id()));
    Assert.assertFalse(isDataExists(getTableName(s), s.getId()));
    Assert.assertFalse(isDataExists(getTableName(s), s2.getId()));
    c.save();
    s.save();
    s2.save();
    Assert.assertTrue(isDataExists(getTableName(c), c.get_id()));
    Assert.assertTrue(isDataExists(getTableName(s), s.getId()));
    Assert.assertTrue(isDataExists(getTableName(s), s2.getId()));
}
Also used : Teacher(com.litepaltest.model.Teacher) Classroom(com.litepaltest.model.Classroom) IdCard(com.litepaltest.model.IdCard) Cellphone(com.litepaltest.model.Cellphone) Student(com.litepaltest.model.Student)

Example 8 with Cellphone

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

the class SaveTest method testSaveIfExists.

public void testSaveIfExists() {
    String serial = UUID.randomUUID().toString();
    Cellphone cell = new Cellphone();
    cell.setBrand("iPhone");
    cell.setPrice(4998.01);
    cell.setInStock('Y');
    cell.setSerial(serial);
    assertTrue(cell.saveIfNotExist("serial = ?", serial));
    Cellphone cell2 = new Cellphone();
    cell2.setBrand("Android");
    cell2.setPrice(1998.01);
    cell2.setInStock('Y');
    cell2.setSerial(serial);
    assertFalse(cell.saveIfNotExist("serial = ?", serial));
    List<Cellphone> cellphoneList = DataSupport.where("serial = ?", serial).find(Cellphone.class);
    assertEquals(1, cellphoneList.size());
}
Also used : Cellphone(com.litepaltest.model.Cellphone)

Example 9 with Cellphone

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

the class SaveTest method testSave.

public void testSave() {
    Cellphone cell = new Cellphone();
    cell.setBrand("iPhone");
    cell.setPrice(4998.01);
    cell.setInStock('Y');
    cell.setSerial(UUID.randomUUID().toString());
    Assert.assertTrue(cell.save());
    Assert.assertTrue(isDataExists(getTableName(cell), cell.getId()));
}
Also used : Cellphone(com.litepaltest.model.Cellphone)

Example 10 with Cellphone

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

the class LitePalTestCase method getCellPhone.

protected Cellphone getCellPhone(long id) {
    Cellphone cellPhone = null;
    Cursor cursor = Connector.getDatabase().query(getTableName(Cellphone.class), null, "id = ?", new String[] { String.valueOf(id) }, null, null, null);
    if (cursor.moveToFirst()) {
        cellPhone = new Cellphone();
        double newPrice = cursor.getDouble(cursor.getColumnIndexOrThrow("price"));
        char inStock = cursor.getString(cursor.getColumnIndexOrThrow("instock")).charAt(0);
        String brand = cursor.getString(cursor.getColumnIndexOrThrow("brand"));
        cellPhone.setBrand(brand);
        cellPhone.setInStock(inStock);
        cellPhone.setPrice(newPrice);
    }
    cursor.close();
    return cellPhone;
}
Also used : Cellphone(com.litepaltest.model.Cellphone) Cursor(android.database.Cursor)

Aggregations

Cellphone (com.litepaltest.model.Cellphone)12 Cursor (android.database.Cursor)1 Classroom (com.litepaltest.model.Classroom)1 IdCard (com.litepaltest.model.IdCard)1 Student (com.litepaltest.model.Student)1 Teacher (com.litepaltest.model.Teacher)1 WeChatMessage (com.litepaltest.model.WeChatMessage)1 WeiboMessage (com.litepaltest.model.WeiboMessage)1 ArrayList (java.util.ArrayList)1