use of org.bson.BsonObjectId in project spring-data-mongodb by spring-projects.
the class GridFsResourceUnitTests method shouldThrowExceptionOnEmptyContentType.
// DATAMONGO-1850
@Test
public void shouldThrowExceptionOnEmptyContentType() {
GridFSFile file = new GridFSFile(new BsonObjectId(), "foo", 0, 0, new Date(), "foo", null);
GridFsResource resource = new GridFsResource(file);
assertThatThrownBy(resource::getContentType).isInstanceOf(MongoGridFSException.class);
}
use of org.bson.BsonObjectId in project spring-data-mongodb by spring-projects.
the class GridFsTemplateIntegrationTests method storesAndFindsSimpleDocumentWithMetadataObject.
// DATAMONGO-809
@Test
public void storesAndFindsSimpleDocumentWithMetadataObject() throws IOException {
Metadata metadata = new Metadata();
metadata.version = "1.0";
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("version").is("1.0")));
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 writesMetadataCorrectly.
// DATAMONGO-6
@Test
public void writesMetadataCorrectly() throws IOException {
Document metadata = new Document("key", "value");
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(whereMetaData("key").is("value")));
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 findsFilesByResourcePattern.
// DATAMONGO-6
@Test
public void findsFilesByResourcePattern() throws IOException {
ObjectId reference = operations.store(resource.getInputStream(), "foo.xml");
GridFsResource[] resources = operations.getResources("*.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 storesAndFindsSimpleDocument.
// DATAMONGO-6
@Test
public void storesAndFindsSimpleDocument() throws IOException {
ObjectId reference = operations.store(resource.getInputStream(), "foo.xml");
List<com.mongodb.client.gridfs.model.GridFSFile> files = new ArrayList<com.mongodb.client.gridfs.model.GridFSFile>();
GridFSFindIterable result = operations.find(query(where("_id").is(reference)));
result.into(files);
assertThat(files.size()).isEqualTo(1);
assertThat(((BsonObjectId) files.get(0).getId()).getValue()).isEqualTo(reference);
}
Aggregations