use of org.bson.types.Decimal128 in project realm-java by realm.
the class RealmJsonTests method createObjectFromJson_streamDecimal128AsLong.
@Test
public void createObjectFromJson_streamDecimal128AsLong() throws IOException {
assumeThat(Build.VERSION.SDK_INT, greaterThanOrEqualTo(Build.VERSION_CODES.HONEYCOMB));
InputStream in = TestHelper.loadJsonFromAssets(context, "decimal128_as_long.json");
realm.beginTransaction();
realm.createObjectFromJson(AllTypes.class, in);
realm.commitTransaction();
in.close();
AllTypes obj = realm.where(AllTypes.class).findFirst();
assertEquals(new Decimal128(-32361122672259149L), obj.getColumnDecimal128());
}
use of org.bson.types.Decimal128 in project realm-java by realm.
the class RealmJsonTests method assertAllTypesPrimaryKeyUpdated.
// Asserts that the list of AllTypesPrimaryKey objects where inserted and updated properly.
private void assertAllTypesPrimaryKeyUpdated() {
assertEquals(1, realm.where(AllTypesPrimaryKey.class).count());
AllTypesPrimaryKey obj = realm.where(AllTypesPrimaryKey.class).findFirst();
assertEquals("Bar", obj.getColumnString());
assertEquals(2.23F, obj.getColumnFloat(), 0F);
assertEquals(2.234D, obj.getColumnDouble(), 0D);
assertEquals(true, obj.isColumnBoolean());
assertArrayEquals(new byte[] { 1, 2, 3 }, obj.getColumnBinary());
assertEquals(new Date(2000), obj.getColumnDate());
assertEquals(new ObjectId("789ABCDEF0123456789ABCDA"), obj.getColumnObjectId());
assertEquals(new Decimal128(-43), obj.getColumnDecimal128());
assertEquals(UUID.fromString("027ba5ca-aa12-4afa-9219-e20cc3018590"), obj.getColumnUUID());
assertEquals(RealmAny.valueOf("hello world"), obj.getColumnRealmAny());
assertEquals("Dog4", obj.getColumnRealmObject().getName());
assertEquals(2, obj.getColumnRealmList().size());
assertEquals("Dog5", obj.getColumnRealmList().get(0).getName());
}
use of org.bson.types.Decimal128 in project realm-java by realm.
the class RealmJsonTests method createObjectFromJson_decimal128.
@Test
public void createObjectFromJson_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());
}
use of org.bson.types.Decimal128 in project morphia by mongodb.
the class TypeExpressionsTest method testToDecimal.
@Test
public void testToDecimal() {
checkMinServerVersion(4.0);
assertAndCheckDocShape("{$toDecimal: true }", toDecimal(value(true)), new Decimal128(1));
}
use of org.bson.types.Decimal128 in project immutables by immutables.
the class NumbersTest method larger_than_decimal128.
/**
* Serializing big numbers which can't be stored in {@link org.bson.types.Decimal128} format.
* They should be serialized as strings (or binary) in mongo.
*/
@Test
public void larger_than_decimal128() {
final AdvancedRepository repo = new AdvancedRepository(context.setup());
final ObjectId id = ObjectId.get();
final BigInteger integer = BigInteger.valueOf(Long.MAX_VALUE).pow(4);
try {
new Decimal128(new BigDecimal(integer));
fail("Should fail for " + integer);
} catch (NumberFormatException ignore) {
// expected
}
final Advanced doc = ImmutableAdvanced.builder().id(id).bigDecimal(// make number big
new BigDecimal(integer)).bigInteger(// make it also big
integer).atomicBoolean(new AtomicBoolean(false)).atomicInteger(new AtomicInteger(1)).atomicLong(new AtomicLong(2)).build();
repo.insert(doc).getUnchecked();
final Advanced doc2 = repo.findById(id).fetchFirst().getUnchecked().get();
check(doc2.bigDecimal().unscaledValue()).is(integer);
check(doc2.bigInteger()).is(integer);
}
Aggregations