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());
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmJsonTests method createObjectFromJson_streamDateAsISO8601String.
@Test
public void createObjectFromJson_streamDateAsISO8601String() throws IOException {
assumeThat(Build.VERSION.SDK_INT, greaterThanOrEqualTo(Build.VERSION_CODES.HONEYCOMB));
InputStream in = TestHelper.loadJsonFromAssets(context, "date_as_iso8601_string.json");
realm.beginTransaction();
realm.createObjectFromJson(AllTypes.class, in);
realm.commitTransaction();
in.close();
Calendar cal = new GregorianCalendar(2007, 8 - 1, 13, 19, 51, 23);
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
cal.set(Calendar.MILLISECOND, 789);
Date date = cal.getTime();
// Checks that all primitive types are imported correctly.
AllTypes obj = realm.where(AllTypes.class).findFirst();
assertEquals(date, obj.getColumnDate());
}
use of io.realm.entities.AllTypes in project realm-java by realm.
the class RealmJsonTests method createObjectFromJson_noValues.
// Tests if Json object doesn't have the field, then the field should have default value.
@Test
public void createObjectFromJson_noValues() throws JSONException {
JSONObject json = new JSONObject();
json.put("noThingHere", JSONObject.NULL);
realm.beginTransaction();
realm.createObjectFromJson(AllTypes.class, json);
realm.commitTransaction();
// Checks that all primitive types are imported correctly.
AllTypes obj = realm.where(AllTypes.class).findFirst();
assertEquals("", obj.getColumnString());
assertEquals(0L, obj.getColumnLong());
assertEquals(0F, obj.getColumnFloat(), 0F);
assertEquals(0D, obj.getColumnDouble(), 0D);
assertEquals(false, obj.isColumnBoolean());
assertEquals(new Date(0), obj.getColumnDate());
assertArrayEquals(new byte[0], obj.getColumnBinary());
assertNull(obj.getColumnRealmObject());
assertEquals(0, obj.getColumnRealmList().size());
}
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());
}
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());
}
Aggregations