use of com.mongodb.client.gridfs.GridFSFindIterable in project spring-data-mongodb by spring-projects.
the class GridFsTemplateIntegrationTests method considersSortWhenQueryingFiles.
// DATAMONGO-534
@Test
public void considersSortWhenQueryingFiles() throws IOException {
ObjectId second = operations.store(resource.getInputStream(), "foo.xml");
ObjectId third = operations.store(resource.getInputStream(), "foobar.xml");
ObjectId first = operations.store(resource.getInputStream(), "bar.xml");
Query query = new Query().with(Sort.by(Direction.ASC, "filename"));
List<com.mongodb.client.gridfs.model.GridFSFile> files = new ArrayList<com.mongodb.client.gridfs.model.GridFSFile>();
GridFSFindIterable result = operations.find(query);
result.into(files);
assertThat(files).hasSize(3).extracting(it -> ((BsonObjectId) it.getId()).getValue()).containsExactly(first, second, third);
}
use of com.mongodb.client.gridfs.GridFSFindIterable in project spring-data-mongodb by spring-projects.
the class GridFsTemplateIntegrationTests method storesContentType.
// DATAMONGO-503
@Test
public void storesContentType() throws IOException {
ObjectId reference = operations.store(resource.getInputStream(), "foo2.xml", "application/xml");
List<com.mongodb.client.gridfs.model.GridFSFile> files = new ArrayList<com.mongodb.client.gridfs.model.GridFSFile>();
GridFSFindIterable result = operations.find(query(whereContentType().is("application/xml")));
result.into(files);
assertThat(files.size()).isEqualTo(1);
assertThat(((BsonObjectId) files.get(0).getId()).getValue()).isEqualTo(reference);
}
use of com.mongodb.client.gridfs.GridFSFindIterable in project spring-data-mongodb by spring-projects.
the class GridFsTemplateIntegrationTests method queryingWithEmptyQueryReturnsAllFiles.
// DATAMONGO-534, DATAMONGO-1762
@Test
public void queryingWithEmptyQueryReturnsAllFiles() throws IOException {
ObjectId reference = operations.store(resource.getInputStream(), "foo.xml");
List<com.mongodb.client.gridfs.model.GridFSFile> files = new ArrayList<>();
GridFSFindIterable result = operations.find(new Query());
result.into(files);
assertThat(files).hasSize(1).extracting(it -> ((BsonObjectId) it.getId()).getValue()).containsExactly(reference);
}
use of com.mongodb.client.gridfs.GridFSFindIterable in project spring-data-mongodb by spring-projects.
the class GridFsTemplateIntegrationTests method storesAndFindsSimpleDocumentWithMetadataDocument.
// DATAMONGO-809
@Test
public void storesAndFindsSimpleDocumentWithMetadataDocument() throws IOException {
Document metadata = new Document("key", "value");
ObjectId reference = operations.store(resource.getInputStream(), "foobar", metadata);
List<com.mongodb.client.gridfs.model.GridFSFile> files = new ArrayList<com.mongodb.client.gridfs.model.GridFSFile>();
GridFSFindIterable result = operations.find(query(whereMetaData("key").is("value")));
result.into(files);
assertThat(files).hasSize(1).extracting(it -> ((BsonObjectId) it.getId()).getValue()).containsExactly(reference);
}
use of com.mongodb.client.gridfs.GridFSFindIterable in project spring-data-mongodb by spring-projects.
the class GridFsTemplateIntegrationTests method marshalsComplexMetadata.
// DATAMONGO-6
@Test
public void marshalsComplexMetadata() throws IOException {
Metadata metadata = new Metadata();
metadata.version = "1.0";
ObjectId reference = operations.store(resource.getInputStream(), "foo.xml", metadata);
List<com.mongodb.client.gridfs.model.GridFSFile> files = new ArrayList<com.mongodb.client.gridfs.model.GridFSFile>();
GridFSFindIterable result = operations.find(query(whereFilename().is("foo.xml")));
result.into(files);
assertThat(files.size()).isEqualTo(1);
assertThat(((BsonObjectId) files.get(0).getId()).getValue()).isEqualTo(reference);
}
Aggregations