Skip to content
Snippets Groups Projects
Commit a53fc2c1 authored by Evgeny Bardin's avatar Evgeny Bardin
Browse files

OZG-7426 handle empty file

parent 3942d612
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@
<parent>
<groupId>de.ozgcloud.common</groupId>
<artifactId>ozgcloud-common-parent</artifactId>
<version>4.8.0</version>
<version>4.9.0-SNAPSHOT</version>
<relativePath />
</parent>
......
......@@ -89,6 +89,9 @@ class OzgCloudFileRepository {
}
private long getContentSize(String contentId) {
if (Objects.isNull(contentId)) {
return 0;
}
var contentGridFsFile = gridFsTemplate.find(queryByObjectId(contentId)).first();
if (Objects.isNull(contentGridFsFile)) {
throw new NotFoundException(GridFSFile.class, contentId);
......
......@@ -100,6 +100,15 @@ class OzgCloudFileRepositoryITCase {
assertThat(result.getSize()).isEqualTo(OzgCloudFileTestFactory.SIZE);
}
@Test
void shouldSetContentSizeToZero() {
var ozgCloudFile = OzgCloudFileTestFactory.createBuilder().id(null).version(0).contentId(null).build();
var result = repository.save(ozgCloudFile);
assertThat(result.getSize()).isZero();
}
@Test
void shouldFailIfContentMissing() {
var ozgCloudFile = OzgCloudFileTestFactory.createBuilder().id(null).version(0).contentId("missing").build();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment