Search in sources :

Example 46 with AllTypes

use of io.realm.entities.AllTypes in project realm-java by realm.

the class RealmJsonTests method createObjectFromJson_dateAsString.

@Test
public void createObjectFromJson_dateAsString() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("columnDate", "/Date(1000)/");
    realm.beginTransaction();
    realm.createObjectFromJson(AllTypes.class, json);
    realm.commitTransaction();
    AllTypes obj = realm.where(AllTypes.class).findFirst();
    assertEquals(new Date(1000), obj.getColumnDate());
}
Also used : JSONObject(org.json.JSONObject) AllTypes(io.realm.entities.AllTypes) Date(java.util.Date) Test(org.junit.Test)

Example 47 with AllTypes

use of io.realm.entities.AllTypes in project realm-java by realm.

the class RealmJsonTests method createObjectFromJson_streamDecimal128AsInt.

@Test
public void createObjectFromJson_streamDecimal128AsInt() throws IOException {
    assumeThat(Build.VERSION.SDK_INT, greaterThanOrEqualTo(Build.VERSION_CODES.HONEYCOMB));
    InputStream in = TestHelper.loadJsonFromAssets(context, "decimal128_as_int.json");
    realm.beginTransaction();
    realm.createObjectFromJson(AllTypes.class, in);
    realm.commitTransaction();
    in.close();
    AllTypes obj = realm.where(AllTypes.class).findFirst();
    assertEquals(new Decimal128(-42), obj.getColumnDecimal128());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AllTypes(io.realm.entities.AllTypes) Decimal128(org.bson.types.Decimal128) Test(org.junit.Test)

Example 48 with AllTypes

use of io.realm.entities.AllTypes in project realm-java by realm.

the class RealmJsonTests method createObjectFromJson_realmAnyAsString.

@Test
public void createObjectFromJson_realmAnyAsString() throws JSONException {
    JSONObject json = new JSONObject();
    String aString = "027ba5ca-aa12-4afa-9219-e20cc3018599";
    json.put("columnRealmAny", aString);
    realm.beginTransaction();
    realm.createObjectFromJson(AllTypes.class, json);
    realm.commitTransaction();
    AllTypes obj = realm.where(AllTypes.class).findFirst();
    assertEquals(RealmAny.valueOf(aString), obj.getColumnRealmAny());
}
Also used : JSONObject(org.json.JSONObject) AllTypes(io.realm.entities.AllTypes) Test(org.junit.Test)

Example 49 with AllTypes

use of io.realm.entities.AllTypes in project realm-java by realm.

the class RealmJsonTests method createObjectFromJson_objectIdAsString.

@Test
public void createObjectFromJson_objectIdAsString() throws JSONException {
    JSONObject json = new JSONObject();
    String idHex = TestHelper.generateObjectIdHexString(7);
    json.put("columnObjectId", idHex);
    realm.beginTransaction();
    realm.createObjectFromJson(AllTypes.class, json);
    realm.commitTransaction();
    AllTypes obj = realm.where(AllTypes.class).findFirst();
    assertEquals(new ObjectId(idHex), obj.getColumnObjectId());
}
Also used : JSONObject(org.json.JSONObject) PrimaryKeyAsObjectId(io.realm.entities.PrimaryKeyAsObjectId) ObjectId(org.bson.types.ObjectId) AllTypes(io.realm.entities.AllTypes) Test(org.junit.Test)

Example 50 with AllTypes

use of io.realm.entities.AllTypes in project realm-java by realm.

the class RealmJsonTests method createUsingJsonStream_decimal128.

@Test
public void createUsingJsonStream_decimal128() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("columnDecimal128", new Decimal128(BigDecimal.TEN));
    realm.beginTransaction();
    realm.createObjectFromJson(AllTypes.class, json);
    realm.commitTransaction();
    AllTypes obj = realm.where(AllTypes.class).findFirst();
    assertEquals(new Decimal128(BigDecimal.TEN), obj.getColumnDecimal128());
}
Also used : JSONObject(org.json.JSONObject) AllTypes(io.realm.entities.AllTypes) Decimal128(org.bson.types.Decimal128) Test(org.junit.Test)

Aggregations

AllTypes (io.realm.entities.AllTypes)225 Test (org.junit.Test)210 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)70 UiThreadTest (androidx.test.annotation.UiThreadTest)54 Date (java.util.Date)36 DictionaryAllTypes (io.realm.entities.DictionaryAllTypes)32 Dog (io.realm.entities.Dog)27 JSONObject (org.json.JSONObject)26 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 RunInLooperThread (io.realm.rule.RunInLooperThread)20 InputStream (java.io.InputStream)19 Decimal128 (org.bson.types.Decimal128)19 ByteArrayInputStream (java.io.ByteArrayInputStream)17 ObjectId (org.bson.types.ObjectId)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 UiThreadTest (android.support.test.annotation.UiThreadTest)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 OsSharedRealm (io.realm.internal.OsSharedRealm)9 BigDecimal (java.math.BigDecimal)9 NonLatinFieldNames (io.realm.entities.NonLatinFieldNames)8