Search in sources :

Example 11 with AllTypesRealmModel

use of io.realm.entities.pojo.AllTypesRealmModel in project realm-java by realm.

the class RealmModelTests method realmObjectWithRealmModelField.

// Tests the behaviour of a RealmObject, containing a RealmModel field.
@Test
public void realmObjectWithRealmModelField() {
    RealmObjectWithRealmModelField realmObjectWithRealmModelField = new RealmObjectWithRealmModelField();
    AllTypesRealmModel allTypePojo = new AllTypesRealmModel();
    allTypePojo.columnLong = 42;
    realmObjectWithRealmModelField.setAllTypesRealmModel(allTypePojo);
    realm.beginTransaction();
    realm.copyToRealm(realmObjectWithRealmModelField);
    realm.commitTransaction();
    RealmResults<RealmObjectWithRealmModelField> all = realm.where(RealmObjectWithRealmModelField.class).findAll();
    assertEquals(1, all.size());
    assertEquals(42, all.first().getAllTypesRealmModel().columnLong);
}
Also used : AllTypesRealmModel(io.realm.entities.pojo.AllTypesRealmModel) RealmObjectWithRealmModelField(io.realm.entities.pojo.RealmObjectWithRealmModelField) Test(org.junit.Test)

Example 12 with AllTypesRealmModel

use of io.realm.entities.pojo.AllTypesRealmModel in project realm-java by realm.

the class RealmModelTests method realmObjectWithRealmListOfRealmModel.

// Tests the behaviour of a RealmObject, containing a RealmList
// of RealmModel, in managed and unmanaged mode.
@Test
public void realmObjectWithRealmListOfRealmModel() {
    RealmList<AllTypesRealmModel> allTypesRealmModel = new RealmList<AllTypesRealmModel>();
    AllTypesRealmModel allTypePojo;
    for (int i = 0; i < 10; i++) {
        allTypePojo = new AllTypesRealmModel();
        allTypePojo.columnLong = i;
        allTypesRealmModel.add(allTypePojo);
    }
    AllTypesRealmModel pojo1 = allTypesRealmModel.get(1);
    assertEquals(1, pojo1.columnLong);
    allTypesRealmModel.move(1, 0);
    assertEquals(0, allTypesRealmModel.indexOf(pojo1));
    RealmObjectWithRealmListOfRealmModel model = new RealmObjectWithRealmListOfRealmModel();
    model.setColumnRealmList(allTypesRealmModel);
    realm.beginTransaction();
    realm.copyToRealm(model);
    realm.commitTransaction();
    RealmResults<RealmObjectWithRealmListOfRealmModel> all = realm.where(RealmObjectWithRealmListOfRealmModel.class).findAll();
    assertEquals(1, all.size());
    assertEquals(10, all.first().getColumnRealmList().size());
    assertEquals(1, all.first().getColumnRealmList().first().columnLong);
}
Also used : AllTypesRealmModel(io.realm.entities.pojo.AllTypesRealmModel) RealmObjectWithRealmListOfRealmModel(io.realm.entities.pojo.RealmObjectWithRealmListOfRealmModel) Test(org.junit.Test)

Aggregations

AllTypesRealmModel (io.realm.entities.pojo.AllTypesRealmModel)12 Test (org.junit.Test)11 Date (java.util.Date)3 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)2 RealmModelWithRealmListOfRealmModel (io.realm.entities.pojo.RealmModelWithRealmListOfRealmModel)1 RealmModelWithRealmModelField (io.realm.entities.pojo.RealmModelWithRealmModelField)1 RealmObjectWithRealmListOfRealmModel (io.realm.entities.pojo.RealmObjectWithRealmListOfRealmModel)1 RealmObjectWithRealmModelField (io.realm.entities.pojo.RealmObjectWithRealmModelField)1