Search in sources :

Example 31 with RealmException

use of io.realm.exceptions.RealmException in project realm-java by realm.

the class LinkingObjectsManagedTests method json_updateObject.

// Fields annotated with @LinkingObjects should not be affected by JSON updates
@Test
public void json_updateObject() {
    realm.beginTransaction();
    AllJavaTypes child = realm.createObject(AllJavaTypes.class, 1);
    AllJavaTypes parent = realm.createObject(AllJavaTypes.class, 2);
    parent.setFieldObject(child);
    realm.commitTransaction();
    RealmResults<AllJavaTypes> parents = child.getObjectParents();
    assertNotNull(parents);
    assertEquals(1, parents.size());
    assertTrue(parents.contains(parent));
    realm.beginTransaction();
    try {
        realm.createOrUpdateAllFromJson(AllJavaTypes.class, "[{ \"fieldId\" : 1, \"objectParents\" : null }]");
    } catch (RealmException e) {
        fail("Failed loading JSON" + e);
    }
    realm.commitTransaction();
    parents = child.getObjectParents();
    assertNotNull(parents);
    assertEquals(1, parents.size());
    assertTrue(parents.contains(parent));
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) RealmException(io.realm.exceptions.RealmException) Test(org.junit.Test)

Aggregations

RealmException (io.realm.exceptions.RealmException)31 Test (org.junit.Test)10 JSONException (org.json.JSONException)9 AllJavaTypes (io.realm.entities.AllJavaTypes)5 JSONObject (org.json.JSONObject)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 TargetApi (android.annotation.TargetApi)3 RealmConfiguration (io.realm.RealmConfiguration)3 AllTypesPrimaryKey (io.realm.entities.AllTypesPrimaryKey)3 Table (io.realm.internal.Table)3 Date (java.util.Date)3 Scanner (java.util.Scanner)3 JSONArray (org.json.JSONArray)3 Realm (io.realm.Realm)2 AllTypes (io.realm.entities.AllTypes)2 RealmPrimaryKeyConstraintException (io.realm.exceptions.RealmPrimaryKeyConstraintException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Method (java.lang.reflect.Method)2 ParseException (java.text.ParseException)2