use of org.bson.BSONObject in project camel by apache.
the class MongoDbConversionsTest method testInsertBsonInputStream.
@Test
public void testInsertBsonInputStream() {
assertEquals(0, testCollection.count());
DefaultDBEncoder encoder = new DefaultDBEncoder();
BSONObject bsonObject = new BasicDBObject();
bsonObject.put("_id", "testInsertBsonString");
Object result = template.requestBody("direct:insertJsonString", new ByteArrayInputStream(encoder.encode(bsonObject)));
DBObject b = testCollection.find(new BasicDBObject("_id", "testInsertBsonString")).first();
assertNotNull("No record with 'testInsertBsonString' _id", b);
}
use of org.bson.BSONObject in project bson4jackson by michel-kraemer.
the class BsonGeneratorTest method writeBigDecimalsAsDecimal128s.
/**
* Test if {@link BigDecimal} objects can be serialized as {@link Decimal128}s
* @throws Exception if something goes wrong
*/
@Test
public void writeBigDecimalsAsDecimal128s() throws Exception {
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("big", new BigDecimal("0.3"));
BSONObject obj = generateAndParse(data);
Double result = (Double) obj.get("big");
// BigDecimal("0.3") does not equal 0.3!
assertEquals(0.3, result, 0.000001);
assertFalse(Double.valueOf(0.3).equals(result));
data = new LinkedHashMap<String, Object>();
data.put("big", new BigDecimal("0.3"));
obj = generateAndParse(data, Feature.WRITE_BIGDECIMALS_AS_DECIMAL128);
org.bson.types.Decimal128 strResult = (org.bson.types.Decimal128) obj.get("big");
assertEquals(new BigDecimal("0.3"), strResult.bigDecimalValue());
}
use of org.bson.BSONObject in project bson4jackson by michel-kraemer.
the class BsonGeneratorTest method timestamps.
/**
* Test if {@link Timestamp} objects can be serialized
* @throws Exception if something goes wrong
*/
@Test
public void timestamps() throws Exception {
Timestamp timestamp = new Timestamp(100, 200);
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("timestamp", timestamp);
BSONObject obj = generateAndParse(data);
BSONTimestamp result = (BSONTimestamp) obj.get("timestamp");
assertNotNull(result);
assertEquals(timestamp.getInc(), result.getInc());
assertEquals(timestamp.getTime(), result.getTime());
}
use of org.bson.BSONObject in project bson4jackson by michel-kraemer.
the class BsonGeneratorTest method javascript.
/**
* Test if {@link JavaScript} objects can be serialized
* @throws Exception if something goes wrong
*/
@Test
public void javascript() throws Exception {
JavaScript javaScript = new JavaScript("a < 100");
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("javaScript", javaScript);
BSONObject obj = generateAndParse(data);
Code result = (Code) obj.get("javaScript");
assertNotNull(result);
assertEquals(javaScript.getCode(), result.getCode());
}
use of org.bson.BSONObject in project bson4jackson by michel-kraemer.
the class BsonGeneratorTest method arrays.
/**
* Test if arrays can be serialized correctly
* @throws Exception if something goes wrong
*/
@Test
@SuppressWarnings("unchecked")
public void arrays() throws Exception {
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("Int32", 5);
data.put("Arr", Arrays.asList("a", "b", "c"));
data.put("Int64", 10L);
List<String> a3 = Arrays.asList("d", "e", "f");
List<String> a4 = Arrays.asList("g", "h", "j");
List<List<String>> a5 = new ArrayList<List<String>>();
a5.add(a3);
a5.add(a4);
data.put("Arr2", a5);
Map<String, Object> data2 = new LinkedHashMap<String, Object>();
data2.put("Str", "Hello");
List<Map<String, Object>> a6 = new ArrayList<Map<String, Object>>();
a6.add(data2);
data.put("Arr3", a6);
BSONObject obj = generateAndParse(data);
assertEquals(5, obj.get("Int32"));
List<String> o = (List<String>) obj.get("Arr");
assertEquals(3, o.size());
assertEquals("a", o.get(0));
assertEquals("b", o.get(1));
assertEquals("c", o.get(2));
assertEquals(10L, obj.get("Int64"));
List<List<String>> o5 = (List<List<String>>) obj.get("Arr2");
assertEquals(a5, o5);
List<BSONObject> o6 = (List<BSONObject>) obj.get("Arr3");
assertEquals(1, o6.size());
BSONObject b6 = o6.get(0);
assertEquals("Hello", b6.get("Str"));
}
Aggregations