Skip to content
Snippets Groups Projects
Commit 018e3951 authored by Jan Zickermann's avatar Jan Zickermann
Browse files

OZG-4097 send-attachment: End transfer with empty chunk

parent c0ff73a4
No related branches found
No related tags found
1 merge request!15Ozg 4097 senden und empfangen von anhängen
Pipeline #1743 failed
...@@ -18,16 +18,20 @@ public record FileChunkInfo( ...@@ -18,16 +18,20 @@ public record FileChunkInfo(
return new AbstractResource() { return new AbstractResource() {
@Override @Override
public String getDescription() { public String getDescription() {
return FileChunkInfo.this.toString(); return "File chunk " + chunkIndex + " of " + upload.getLoggableString();
} }
@Override @Override
public InputStream getInputStream() { public InputStream getInputStream() {
return new LimitedInputStream(fileInputStream, CHUNK_SIZE); return new LimitedInputStream(fileInputStream, contentLength());
} }
@Override @Override
public long contentLength() { public long contentLength() {
return chunkIndex == upload.numberOfChunks() ? 0 : getChunkContentLength();
}
private long getChunkContentLength() {
return chunkIndex == upload.numberOfChunks() - 1 return chunkIndex == upload.numberOfChunks() - 1
? upload.file().getSize() % CHUNK_SIZE ? upload.file().getSize() % CHUNK_SIZE
: CHUNK_SIZE; : CHUNK_SIZE;
......
...@@ -80,7 +80,7 @@ public class Osi2QuarantineService { ...@@ -80,7 +80,7 @@ public class Osi2QuarantineService {
} }
Stream<FileChunkInfo> streamFileChunkInfos(Osi2FileUpload upload) { Stream<FileChunkInfo> streamFileChunkInfos(Osi2FileUpload upload) {
return LongStream.range(0, upload.numberOfChunks()) return LongStream.range(0, upload.numberOfChunks() + 1)
.mapToObj(chunkIndex -> buildFileChunkInfo(upload, chunkIndex)); .mapToObj(chunkIndex -> buildFileChunkInfo(upload, chunkIndex));
} }
......
...@@ -8,6 +8,7 @@ import static org.assertj.core.api.Assertions.*; ...@@ -8,6 +8,7 @@ import static org.assertj.core.api.Assertions.*;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.function.Function;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
...@@ -115,13 +116,17 @@ class OsiPostfachRemoteServiceITCase { ...@@ -115,13 +116,17 @@ class OsiPostfachRemoteServiceITCase {
osiPostfachRemoteService.sendMessage(postfachNachrichtWithAttachment); osiPostfachRemoteService.sendMessage(postfachNachrichtWithAttachment);
var requests = postfachFacadeMockServer.findAll(
postRequestedFor(urlPathTemplate("/Quarantine/v1/Upload/Chunked")));
assertThat(requests).hasSize(2);
Function<Integer, byte[]> requestBodyBytes = requestIndex -> requests.get(requestIndex).getPart("file").getBody().asBytes();
// should send file in one chunk
assertThat(requestBodyBytes.apply(0)).isEqualTo(AttachmentExampleUploadUtil.EXAMPLE_TEXT_DATA);
// should send empty chunk to complete transfer
assertThat(requestBodyBytes.apply(1)).isEmpty();
postfachFacadeMockServer.verify( postfachFacadeMockServer.verify(
exactly(1), exactly(1),
postRequestedFor(urlPathTemplate("/Quarantine/v1/Upload/Chunked")) getRequestedFor(urlPathTemplate("/Quarantine/v1/Upload/{guid}"))
);
postfachFacadeMockServer.verify(
exactly(1),
postRequestedFor(urlPathTemplate("/Quarantine/v1/Upload/{guid}"))
); );
postfachFacadeMockServer.verify( postfachFacadeMockServer.verify(
exactly(1), exactly(1),
......
...@@ -12,13 +12,15 @@ import lombok.extern.log4j.Log4j2; ...@@ -12,13 +12,15 @@ import lombok.extern.log4j.Log4j2;
@Log4j2 @Log4j2
public class AttachmentExampleUploadUtil { public class AttachmentExampleUploadUtil {
public static final byte[] EXAMPLE_TEXT_DATA = LoremIpsum.getInstance().getParagraphs(5,100).getBytes();
public static String uploadTextFile(Osi2AttachmentFileService remoteService) { public static String uploadTextFile(Osi2AttachmentFileService remoteService) {
return remoteService.uploadFileAndReturnId(AttachmentFile.builder() return remoteService.uploadFileAndReturnId(AttachmentFile.builder()
.contentType("test/plain") .contentType("test/plain")
.name("test.txt") .name("test.txt")
.vorgangId(UUID.randomUUID().toString()) .vorgangId(UUID.randomUUID().toString())
.build(), () -> new ByteArrayInputStream(LoremIpsum.getInstance().getParagraphs(5,100).getBytes())); .build(), () -> new ByteArrayInputStream(EXAMPLE_TEXT_DATA));
} }
} }
...@@ -329,13 +329,17 @@ class Osi2QuarantineServiceTest { ...@@ -329,13 +329,17 @@ class Osi2QuarantineServiceTest {
.upload(upload) .upload(upload)
.chunkIndex(1) .chunkIndex(1)
.build(); .build();
private final FileChunkInfo emptyChunkInfo = FileChunkInfo.builder()
.upload(upload)
.chunkIndex(2)
.build();
@DisplayName("should stream chunk infos") @DisplayName("should stream chunk infos")
@Test @Test
void shouldStreamChunkInfos() { void shouldStreamChunkInfos() {
var result = service.streamFileChunkInfos(upload).toList(); var result = service.streamFileChunkInfos(upload).toList();
assertThat(result).containsExactly(chunkInfo1, chunkInfo2); assertThat(result).containsExactly(chunkInfo1, chunkInfo2, emptyChunkInfo);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment