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 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).hasSize(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 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<>();
GridFSFindIterable result = operations.find(query(whereContentType().is("application/xml")));
result.into(files);
assertThat(files).hasSize(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 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<>();
GridFSFindIterable result = operations.find(query(whereFilename().is("foo.xml")));
result.into(files);
assertThat(files).hasSize(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 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<>();
GridFSFindIterable result = operations.find(query);
result.into(files);
assertThat(files).hasSize(3).extracting(it -> ((BsonObjectId) it.getId()).getValue()).containsExactly(first, second, third);
}
Aggregations