Search in sources :

Example 11 with GridFSFindIterable

use of com.mongodb.client.gridfs.GridFSFindIterable in project georocket by georocket.

the class MongoDBStoreTest method validateAfterStoreAdd.

@Override
protected void validateAfterStoreAdd(TestContext context, Vertx vertx, String path, Handler<AsyncResult<Void>> handler) {
    vertx.executeBlocking(f -> {
        try (MongoClient client = new MongoClient(mongoConnector.serverAddress)) {
            MongoDatabase db = client.getDatabase(MongoDBTestConnector.MONGODB_DBNAME);
            GridFSBucket gridFS = GridFSBuckets.create(db);
            GridFSFindIterable files = gridFS.find();
            GridFSFile file = files.first();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            gridFS.downloadToStream(file.getFilename(), baos);
            String contents = new String(baos.toByteArray(), StandardCharsets.UTF_8);
            context.assertEquals(CHUNK_CONTENT, contents);
        }
        f.complete();
    }, handler);
}
Also used : GridFSBucket(com.mongodb.client.gridfs.GridFSBucket) MongoClient(com.mongodb.MongoClient) GridFSFile(com.mongodb.client.gridfs.model.GridFSFile) GridFSFindIterable(com.mongodb.client.gridfs.GridFSFindIterable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MongoDatabase(com.mongodb.client.MongoDatabase)

Aggregations

GridFSFindIterable (com.mongodb.client.gridfs.GridFSFindIterable)11 GridFSFile (com.mongodb.client.gridfs.model.GridFSFile)10 ArrayList (java.util.ArrayList)9 BsonObjectId (org.bson.BsonObjectId)8 ObjectId (org.bson.types.ObjectId)8 Test (org.junit.Test)8 Document (org.bson.Document)5 MongoGridFSException (com.mongodb.MongoGridFSException)4 IOException (java.io.IOException)4 List (java.util.List)4 Assertions (org.assertj.core.api.Assertions)4 Before (org.junit.Before)4 RunWith (org.junit.runner.RunWith)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 Resource (org.springframework.core.io.Resource)4 Sort (org.springframework.data.domain.Sort)4 Direction (org.springframework.data.domain.Sort.Direction)4 Criteria.where (org.springframework.data.mongodb.core.query.Criteria.where)4 Query (org.springframework.data.mongodb.core.query.Query)4