Search in sources :

Example 51 with AllTypes

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

the class RealmJsonTests method createObjectFromJson_streamDateAsLong.

@Test
public void createObjectFromJson_streamDateAsLong() throws IOException {
    assumeThat(Build.VERSION.SDK_INT, greaterThanOrEqualTo(Build.VERSION_CODES.HONEYCOMB));
    InputStream in = TestHelper.loadJsonFromAssets(context, "date_as_long.json");
    realm.beginTransaction();
    realm.createObjectFromJson(AllTypes.class, in);
    realm.commitTransaction();
    in.close();
    // Checks that all primitive types are imported correctly.
    AllTypes obj = realm.where(AllTypes.class).findFirst();
    assertEquals(new Date(1000), obj.getColumnDate());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AllTypes(io.realm.entities.AllTypes) Date(java.util.Date) Test(org.junit.Test)

Example 52 with AllTypes

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

the class RealmJsonTests method createObjectFromJson_streamDateAsString.

@Test
public void createObjectFromJson_streamDateAsString() throws IOException {
    assumeThat(Build.VERSION.SDK_INT, greaterThanOrEqualTo(Build.VERSION_CODES.HONEYCOMB));
    InputStream in = TestHelper.loadJsonFromAssets(context, "date_as_string.json");
    realm.beginTransaction();
    realm.createObjectFromJson(AllTypes.class, in);
    realm.commitTransaction();
    in.close();
    // Checks that all primitive types are imported correctly.
    AllTypes obj = realm.where(AllTypes.class).findFirst();
    assertEquals(new Date(1000), obj.getColumnDate());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AllTypes(io.realm.entities.AllTypes) Date(java.util.Date) Test(org.junit.Test)

Example 53 with AllTypes

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

the class RealmJsonTests method createObjectFromJson_decimal128AsLong.

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

Example 54 with AllTypes

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

the class RealmJsonTests method createObjectFromJson_childObject.

@Test
public void createObjectFromJson_childObject() throws JSONException {
    JSONObject allTypesObject = new JSONObject();
    JSONObject dogObject = new JSONObject();
    dogObject.put("name", "Fido");
    allTypesObject.put("columnRealmObject", dogObject);
    realm.beginTransaction();
    realm.createObjectFromJson(AllTypes.class, allTypesObject);
    realm.commitTransaction();
    AllTypes obj = realm.where(AllTypes.class).findFirst();
    assertEquals("Fido", obj.getColumnRealmObject().getName());
}
Also used : JSONObject(org.json.JSONObject) AllTypes(io.realm.entities.AllTypes) Test(org.junit.Test)

Example 55 with AllTypes

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

the class RealmJsonTests method createObjectFromJson_streamObjectIdAsString.

@Test
public void createObjectFromJson_streamObjectIdAsString() throws IOException {
    assumeThat(Build.VERSION.SDK_INT, greaterThanOrEqualTo(Build.VERSION_CODES.HONEYCOMB));
    InputStream in = TestHelper.loadJsonFromAssets(context, "objectid_as_string.json");
    realm.beginTransaction();
    realm.createObjectFromJson(AllTypes.class, in);
    realm.commitTransaction();
    in.close();
    AllTypes obj = realm.where(AllTypes.class).findFirst();
    assertEquals(new ObjectId("789ABCDEF0123456789ABCDE"), obj.getColumnObjectId());
}
Also used : PrimaryKeyAsObjectId(io.realm.entities.PrimaryKeyAsObjectId) ObjectId(org.bson.types.ObjectId) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AllTypes(io.realm.entities.AllTypes) 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