Search in sources :

Example 1 with Cellphone

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

the class ColumnTest method testUnique.

public void testUnique() {
    String serial = UUID.randomUUID().toString();
    for (int i = 0; i < 2; i++) {
        Cellphone cellphone = new Cellphone();
        cellphone.setBrand("三星");
        cellphone.setInStock('Y');
        cellphone.setPrice(1949.99);
        cellphone.setSerial(serial);
        if (i == 0) {
            assertTrue(cellphone.save());
        } else if (i == 1) {
            assertFalse(cellphone.save());
        }
    }
}
Also used : Cellphone(com.litepaltest.model.Cellphone)

Example 2 with Cellphone

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

the class SaveTest method testSaveInheritModelsWithAssociations.

public void testSaveInheritModelsWithAssociations() {
    Cellphone cellphone = new Cellphone();
    cellphone.setBrand("iPhone 7");
    cellphone.setInStock('N');
    cellphone.setPrice(6999.99);
    cellphone.setSerial(UUID.randomUUID().toString());
    cellphone.setMac("ff:3d:4a:99:76");
    cellphone.save();
    WeChatMessage weChatMessage = new WeChatMessage();
    weChatMessage.setFriend("Tom");
    weChatMessage.setContent("Hello nice to meet you");
    weChatMessage.setTitle("Greeting message");
    weChatMessage.setType(1);
    assertTrue(weChatMessage.save());
    assertTrue(weChatMessage.getId() > 0);
    WeChatMessage message1 = DataSupport.find(WeChatMessage.class, weChatMessage.getId());
    assertEquals("Tom", message1.getFriend());
    assertEquals("Hello nice to meet you", message1.getContent());
    assertNull(message1.getTitle());
    assertEquals(1, message1.getType());
    WeiboMessage weiboMessage = new WeiboMessage();
    weiboMessage.setType(2);
    weiboMessage.setTitle("Following message");
    weiboMessage.setContent("Something big happens");
    weiboMessage.setFollower("Jimmy");
    weiboMessage.setNumber(123456);
    weiboMessage.setCellphone(cellphone);
    assertTrue(weiboMessage.save());
    assertTrue(weiboMessage.getId() > 0);
    WeiboMessage message2 = DataSupport.find(WeiboMessage.class, weiboMessage.getId(), true);
    Cellphone result = message2.getCellphone();
    assertEquals(cellphone.getId(), result.getId());
    assertEquals(cellphone.getBrand(), result.getBrand());
    assertEquals(cellphone.getInStock(), result.getInStock());
    assertEquals(cellphone.getPrice(), result.getPrice());
    assertEquals(cellphone.getSerial(), result.getSerial());
    assertEquals(cellphone.getMac(), result.getMac());
}
Also used : WeChatMessage(com.litepaltest.model.WeChatMessage) Cellphone(com.litepaltest.model.Cellphone) WeiboMessage(com.litepaltest.model.WeiboMessage)

Example 3 with Cellphone

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

the class SaveTest method testSaveFast.

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

Example 4 with Cellphone

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

the class SaveTest method testSaveFastAfterDelete.

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

Example 5 with Cellphone

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

the class UpdateUsingSaveMethodTest method testUpdateBasicValues.

public void testUpdateBasicValues() {
    Cellphone cell = new Cellphone();
    cell.setBrand("SamSung");
    cell.setPrice(3988.12);
    cell.setInStock('Y');
    cell.setSerial(UUID.randomUUID().toString());
    assertTrue(cell.save());
    assertTrue(isDataExists(getTableName(cell), cell.getId()));
    // reduce price, sold out.
    cell.setPrice(2899.88);
    cell.setInStock('N');
    assertTrue(cell.save());
    Cellphone updatedCell = getCellPhone(cell.getId());
    assertEquals(2899.88, updatedCell.getPrice());
    assertTrue('N' == updatedCell.getInStock());
}
Also used : Cellphone(com.litepaltest.model.Cellphone)

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