Search in sources :

Example 6 with BsonInput

use of org.bson.io.BsonInput in project mongo-java-driver by mongodb.

the class DocumentCodecTest method testIterableContainingDocumentsEncoding.

@Test
public void testIterableContainingDocumentsEncoding() throws IOException {
    DocumentCodec documentCodec = new DocumentCodec();
    Document doc = new Document();
    List<Document> listOfDocuments = asList(new Document("intVal", 1), new Document("anotherInt", 2));
    doc.put("array", listOfDocuments);
    documentCodec.encode(writer, doc, EncoderContext.builder().build());
    BsonInput bsonInput = createInputBuffer();
    Document decodedDocument = documentCodec.decode(new BsonBinaryReader(bsonInput), DecoderContext.builder().build());
    assertEquals(doc, decodedDocument);
}
Also used : BsonInput(org.bson.io.BsonInput) ByteBufferBsonInput(org.bson.io.ByteBufferBsonInput) BsonBinaryReader(org.bson.BsonBinaryReader) Document(org.bson.Document) Test(org.junit.Test)

Aggregations

BsonInput (org.bson.io.BsonInput)6 BsonBinaryReader (org.bson.BsonBinaryReader)5 Document (org.bson.Document)5 ByteBufferBsonInput (org.bson.io.ByteBufferBsonInput)5 Test (org.junit.Test)5 Arrays.asList (java.util.Arrays.asList)1 Date (java.util.Date)1 List (java.util.List)1 BsonObjectId (org.bson.BsonObjectId)1 Binary (org.bson.types.Binary)1 Code (org.bson.types.Code)1 MaxKey (org.bson.types.MaxKey)1 MinKey (org.bson.types.MinKey)1 ObjectId (org.bson.types.ObjectId)1