Search in sources :

Example 1 with Product

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

the class MultiDatabaseTest method testMultiDatabase.

public void testMultiDatabase() {
    LitePal.deleteDatabase("db2");
    SQLiteDatabase db = LitePal.getDatabase();
    assertTrue(DBUtility.isTableExists("Album", db));
    assertTrue(DBUtility.isTableExists("Song", db));
    assertTrue(DBUtility.isTableExists("Singer", db));
    assertTrue(DBUtility.isTableExists("Classroom", db));
    assertTrue(DBUtility.isTableExists("Teacher", db));
    assertTrue(DBUtility.isTableExists("IdCard", db));
    assertTrue(DBUtility.isTableExists("Student", db));
    assertTrue(DBUtility.isTableExists("Cellphone", db));
    assertTrue(DBUtility.isTableExists("Computer", db));
    assertTrue(DBUtility.isTableExists("Book", db));
    assertTrue(DBUtility.isTableExists("Product", db));
    assertTrue(DBUtility.isTableExists("Headset", db));
    assertTrue(DBUtility.isTableExists("WeChatMessage", db));
    assertTrue(DBUtility.isTableExists("WeiboMessage", db));
    LitePalDB litePalDB = new LitePalDB("db2", 1);
    litePalDB.addClassName(Classroom.class.getName());
    litePalDB.addClassName(Product.class.getName());
    litePalDB.setExternalStorage(true);
    LitePal.use(litePalDB);
    db = LitePal.getDatabase();
    assertFalse(DBUtility.isTableExists("Album", db));
    assertFalse(DBUtility.isTableExists("Song", db));
    assertFalse(DBUtility.isTableExists("Singer", db));
    assertTrue(DBUtility.isTableExists("Classroom", db));
    assertFalse(DBUtility.isTableExists("Teacher", db));
    assertFalse(DBUtility.isTableExists("IdCard", db));
    assertFalse(DBUtility.isTableExists("Student", db));
    assertFalse(DBUtility.isTableExists("Cellphone", db));
    assertFalse(DBUtility.isTableExists("Computer", db));
    assertFalse(DBUtility.isTableExists("Book", db));
    assertTrue(DBUtility.isTableExists("Product", db));
    assertFalse(DBUtility.isTableExists("Headset", db));
    assertFalse(DBUtility.isTableExists("WeChatMessage", db));
    assertFalse(DBUtility.isTableExists("WeiboMessage", db));
    litePalDB = new LitePalDB("db2", 2);
    litePalDB.addClassName(Computer.class.getName());
    litePalDB.addClassName(Product.class.getName());
    litePalDB.addClassName(Headset.class.getName());
    litePalDB.setExternalStorage(true);
    LitePal.use(litePalDB);
    db = LitePal.getDatabase();
    assertFalse(DBUtility.isTableExists("Album", db));
    assertFalse(DBUtility.isTableExists("Song", db));
    assertFalse(DBUtility.isTableExists("Singer", db));
    assertFalse(DBUtility.isTableExists("Classroom", db));
    assertFalse(DBUtility.isTableExists("Teacher", db));
    assertFalse(DBUtility.isTableExists("IdCard", db));
    assertFalse(DBUtility.isTableExists("Student", db));
    assertFalse(DBUtility.isTableExists("Cellphone", db));
    assertTrue(DBUtility.isTableExists("Computer", db));
    assertFalse(DBUtility.isTableExists("Book", db));
    assertTrue(DBUtility.isTableExists("Product", db));
    assertTrue(DBUtility.isTableExists("Headset", db));
    assertFalse(DBUtility.isTableExists("WeChatMessage", db));
    assertFalse(DBUtility.isTableExists("WeiboMessage", db));
    LitePal.useDefault();
    db = LitePal.getDatabase();
    assertTrue(DBUtility.isTableExists("Album", db));
    assertTrue(DBUtility.isTableExists("Song", db));
    assertTrue(DBUtility.isTableExists("Singer", db));
    assertTrue(DBUtility.isTableExists("Classroom", db));
    assertTrue(DBUtility.isTableExists("Teacher", db));
    assertTrue(DBUtility.isTableExists("IdCard", db));
    assertTrue(DBUtility.isTableExists("Student", db));
    assertTrue(DBUtility.isTableExists("Cellphone", db));
    assertTrue(DBUtility.isTableExists("Computer", db));
    assertTrue(DBUtility.isTableExists("Book", db));
    assertTrue(DBUtility.isTableExists("Product", db));
    assertTrue(DBUtility.isTableExists("Headset", db));
    assertTrue(DBUtility.isTableExists("WeChatMessage", db));
    assertTrue(DBUtility.isTableExists("WeiboMessage", db));
}
Also used : Headset(com.litepaltest.model.Headset) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) LitePalDB(org.litepal.LitePalDB) Classroom(com.litepaltest.model.Classroom) Computer(com.litepaltest.model.Computer) Product(com.litepaltest.model.Product)

Example 2 with Product

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

the class UpdateUsingSaveMethodTest method testUpdateBlobValues.

public void testUpdateBlobValues() {
    byte[] b = new byte[10];
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte) i;
    }
    Product product = new Product();
    product.setBrand("Android");
    product.setPrice(2899.69);
    product.setPic(b);
    assertTrue(product.saveFast());
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte) (b.length - i);
    }
    product.setPic(b);
    assertTrue(product.saveFast());
    Product p = DataSupport.find(Product.class, product.getId());
    byte[] pic = p.getPic();
    assertEquals(b.length, pic.length);
    for (int i = 0; i < b.length; i++) {
        byte a = (byte) (b.length - i);
        assertEquals(a, pic[i]);
    }
}
Also used : Product(com.litepaltest.model.Product)

Example 3 with Product

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

the class UpdateUsingUpdateMethodTest method testUpdateBlobWithInstanceUpdate.

public void testUpdateBlobWithInstanceUpdate() {
    byte[] b = new byte[10];
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte) i;
    }
    Product product = new Product();
    product.setBrand("Android");
    product.setPrice(2899.69);
    product.setPic(b);
    assertTrue(product.saveFast());
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte) (b.length - i);
    }
    Product pro = new Product();
    pro.setPic(b);
    int rows = pro.update(product.getId());
    assertEquals(1, rows);
    Product p = DataSupport.find(Product.class, product.getId());
    byte[] pic = p.getPic();
    assertEquals(b.length, pic.length);
    for (int i = 0; i < b.length; i++) {
        byte a = (byte) (b.length - i);
        assertEquals(a, pic[i]);
    }
}
Also used : Product(com.litepaltest.model.Product)

Example 4 with Product

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

the class UpdateUsingUpdateMethodTest method testUpdateBlobWithStaticUpdate.

public void testUpdateBlobWithStaticUpdate() {
    byte[] b = new byte[10];
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte) i;
    }
    Product product = new Product();
    product.setBrand("Android");
    product.setPrice(2899.69);
    product.setPic(b);
    assertTrue(product.saveFast());
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte) (b.length - i);
    }
    ContentValues values = new ContentValues();
    values.put("pic", b);
    int rows = DataSupport.update(Product.class, values, product.getId());
    assertEquals(1, rows);
    Product p = DataSupport.find(Product.class, product.getId());
    byte[] pic = p.getPic();
    assertEquals(b.length, pic.length);
    for (int i = 0; i < b.length; i++) {
        byte a = (byte) (b.length - i);
        assertEquals(a, pic[i]);
    }
}
Also used : ContentValues(android.content.ContentValues) Product(com.litepaltest.model.Product)

Example 5 with Product

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

the class SaveTest method testSaveWithConstructors.

public void testSaveWithConstructors() {
    Computer computer = new Computer("asus", 699.00);
    assertTrue(computer.save());
    Assert.assertTrue(isDataExists(getTableName(computer), computer.getId()));
    Computer c = getComputer(computer.getId());
    assertEquals("asus", c.getBrand());
    assertEquals(699.00, c.getPrice());
    Computer cc = DataSupport.find(Computer.class, computer.getId());
    assertEquals("asus", cc.getBrand());
    assertEquals(699.00, cc.getPrice());
    Product p = new Product(null);
    p.setBrand("apple");
    p.setPrice(1222.33);
    p.save();
    Product.find(Product.class, p.getId());
}
Also used : Computer(com.litepaltest.model.Computer) Product(com.litepaltest.model.Product)

Aggregations

Product (com.litepaltest.model.Product)7 Computer (com.litepaltest.model.Computer)3 ContentValues (android.content.ContentValues)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Classroom (com.litepaltest.model.Classroom)1 Headset (com.litepaltest.model.Headset)1 LitePalDB (org.litepal.LitePalDB)1