use of org.bson.BsonObjectId 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 org.bson.BsonObjectId 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 org.bson.BsonObjectId in project spring-data-mongodb by spring-projects.
the class GridFsTemplateIntegrationTests method findsFilesByResourceLocation.
// DATAMONGO-6
@Test
public void findsFilesByResourceLocation() throws IOException {
ObjectId reference = operations.store(resource.getInputStream(), "foo.xml");
GridFsResource[] resources = operations.getResources("foo.xml");
assertThat(resources.length).isEqualTo(1);
assertThat(((BsonObjectId) resources[0].getId()).getValue()).isEqualTo(reference);
assertThat(resources[0].contentLength()).isEqualTo(resource.contentLength());
}
use of org.bson.BsonObjectId 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 org.bson.BsonObjectId 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);
}
Aggregations