Skip to content

Commit 815ca33

Browse files
committed
added test to make sure all types are correctly encoded with BSON to/from db
1 parent 018caec commit 815ca33

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/test/com/mongodb/JavaClientTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,17 @@ public void testBadKey(){
746746
c.update(new BasicDBObject("a", 1), new BasicDBObject("$set", new BasicDBObject("a.b", 1)));
747747
}
748748

749+
@Test
750+
public void testAllTypes(){
751+
DBCollection c = _db.getCollectionFromString( "foo" );
752+
c.drop();
753+
String json = "{ 'str' : 'asdfasd' , 'long' : 5 , 'float' : 0.4 , 'bool' : false , 'date' : { '$date' : '2011-05-18T18:56:00Z'} , 'pat' : { '$regex' : '.*' , '$options' : ''} , 'oid' : { '$oid' : '4d83ab3ea39562db9c1ae2ae'} , 'ref' : { '$ref' : 'test.test' , '$id' : { '$oid' : '4d83ab59a39562db9c1ae2af'}} , 'code' : { '$code' : 'asdfdsa'} , 'codews' : { '$code' : 'ggggg' , '$scope' : { }} , 'ts' : { '$ts' : 1300474885 , '$inc' : 10} , 'null' : null }";
754+
BasicDBObject a = (BasicDBObject) JSON.parse(json);
755+
c.insert(a);
756+
DBObject b = c.findOne();
757+
assertTrue(a.equals(b));
758+
}
759+
749760
final Mongo _mongo;
750761
final DB _db;
751762

0 commit comments

Comments
 (0)