use of io.realm.entities.PrimaryKeyAsUUID in project realm-java by realm.
the class RealmJsonNullPrimaryKeyTests method createOrUpdateObjectFromJson_primaryKey_isNull_fromJsonObject.
// Tests null primary key value for createOrUpdateObjectFromJson().
@Test
public void createOrUpdateObjectFromJson_primaryKey_isNull_fromJsonObject() throws JSONException {
realm.beginTransaction();
realm.createOrUpdateObjectFromJson(clazz, new JSONObject(jsonString));
realm.commitTransaction();
// PrimaryKeyAsString
if (clazz.equals(PrimaryKeyAsString.class)) {
RealmResults<PrimaryKeyAsString> results = realm.where(PrimaryKeyAsString.class).findAll();
assertEquals(1, results.size());
assertEquals(Long.valueOf(secondaryFieldValue).longValue(), results.first().getId());
assertEquals(null, results.first().getName());
// PrimaryKeyAsUUID
} else if (clazz.equals(PrimaryKeyAsUUID.class)) {
RealmResults<PrimaryKeyAsUUID> results = realm.where(PrimaryKeyAsUUID.class).findAll();
assertEquals(1, results.size());
assertEquals(null, results.first().getId());
assertEquals(secondaryFieldValue, results.first().getName());
// PrimaryKeyAsNumber
} else {
// Other types
RealmResults results = realm.where(clazz).findAll();
assertEquals(1, results.size());
assertEquals(null, ((NullPrimaryKey) results.first()).getId());
assertEquals(secondaryFieldValue, ((NullPrimaryKey) results.first()).getName());
}
}
use of io.realm.entities.PrimaryKeyAsUUID in project realm-java by realm.
the class RealmJsonNullPrimaryKeyTests method createObjectFromJson_primaryKey_isNull_fromJsonObject.
// Tests null primary key value for createObjectFromJson().
@Test
public void createObjectFromJson_primaryKey_isNull_fromJsonObject() throws JSONException {
realm.beginTransaction();
realm.createObjectFromJson(clazz, new JSONObject(jsonString));
realm.commitTransaction();
// PrimaryKeyAsString
if (clazz.equals(PrimaryKeyAsString.class)) {
RealmResults<PrimaryKeyAsString> results = realm.where(PrimaryKeyAsString.class).findAll();
assertEquals(1, results.size());
assertEquals(Long.valueOf(secondaryFieldValue).longValue(), results.first().getId());
assertNull(results.first().getName());
// PrimaryKeyAsObjectId
} else if (clazz.equals(PrimaryKeyAsUUID.class)) {
RealmResults<PrimaryKeyAsUUID> results = realm.where(PrimaryKeyAsUUID.class).findAll();
assertEquals(1, results.size());
assertEquals(null, results.first().getId());
assertEquals(secondaryFieldValue, results.first().getName());
// PrimaryKeyAsNumber
} else {
// Other types
RealmResults results = realm.where(clazz).findAll();
assertEquals(1, results.size());
assertNull(((NullPrimaryKey) results.first()).getId());
assertEquals(secondaryFieldValue, ((NullPrimaryKey) results.first()).getName());
}
}
use of io.realm.entities.PrimaryKeyAsUUID in project realm-java by realm.
the class RealmJsonNullPrimaryKeyTests method createOrUpdateObjectFromJson_primaryKey_isNull_updateFromJsonObject.
// Tests null primary key value for createObject() -> createOrUpdateObjectFromJson().
@Test
public void createOrUpdateObjectFromJson_primaryKey_isNull_updateFromJsonObject() throws JSONException {
realm.beginTransaction();
// name = null, id =null
realm.createObject(clazz, null);
realm.createOrUpdateObjectFromJson(clazz, new JSONObject(jsonString));
realm.commitTransaction();
// PrimaryKeyAsString
if (clazz.equals(PrimaryKeyAsString.class)) {
RealmResults<PrimaryKeyAsString> results = realm.where(PrimaryKeyAsString.class).findAll();
assertEquals(1, results.size());
assertEquals(Long.valueOf(secondaryFieldValue).longValue(), results.first().getId());
assertEquals(null, results.first().getName());
// PrimaryKeyAsUUID
} else if (clazz.equals(PrimaryKeyAsUUID.class)) {
RealmResults<PrimaryKeyAsUUID> results = realm.where(PrimaryKeyAsUUID.class).findAll();
assertEquals(1, results.size());
assertEquals(null, results.first().getId());
assertEquals(secondaryFieldValue, results.first().getName());
// PrimaryKeyAsNumber
} else {
// Other types
RealmResults results = realm.where(clazz).findAll();
assertEquals(1, results.size());
assertEquals(null, ((NullPrimaryKey) results.first()).getId());
assertEquals(secondaryFieldValue, ((NullPrimaryKey) results.first()).getName());
}
}
Aggregations