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

OZG-4097 send-attachment: Cleanup

parent 16053079
No related branches found
No related tags found
1 merge request!15Ozg 4097 senden und empfangen von anhängen
Pipeline #1733 failed
package de.ozgcloud.nachrichten.postfach.osiv2.model;
public record BinaryFileUpload(
String name,
String contentType,
long size
) {
}
package de.ozgcloud.nachrichten.postfach.osiv2.model;
import java.io.InputStream;
import java.nio.ByteBuffer;
import org.springframework.core.io.AbstractResource;
import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
@Builder
@RequiredArgsConstructor
public class FileChunkResource extends AbstractResource {
private final Integer chunkSize;
private final ByteBuffer content;
@Override
public String getDescription() {
return "Chunk of a file";
}
@Override
public InputStream getInputStream() {
return new ByteBufferBackedInputStream(content);
}
}
...@@ -49,7 +49,6 @@ public class Osi2AttachmentFileService { ...@@ -49,7 +49,6 @@ public class Osi2AttachmentFileService {
} }
public String uploadFileAndReturnId(AttachmentFile attachmentFile, Supplier<InputStream> fileInputStream) { public String uploadFileAndReturnId(AttachmentFile attachmentFile, Supplier<InputStream> fileInputStream) {
// TODO KOP-3008 use revised (nachrichten-manager) AttachmentFileService
var attachmentFileId = ozgCloudFileService.uploadFile( var attachmentFileId = ozgCloudFileService.uploadFile(
attachmentFileMapper.toOzgCloudUploadFile(attachmentFile), attachmentFileMapper.toOzgCloudUploadFile(attachmentFile),
fileInputStream.get() fileInputStream.get()
......
...@@ -74,7 +74,6 @@ class OsiPostfachRemoteServiceITCase { ...@@ -74,7 +74,6 @@ class OsiPostfachRemoteServiceITCase {
@SneakyThrows @SneakyThrows
public void setup() { public void setup() {
postfachFacadeMockServer = OSI_MOCK_SERVER_EXTENSION.getPostfachFacadeMockServer(); postfachFacadeMockServer = OSI_MOCK_SERVER_EXTENSION.getPostfachFacadeMockServer();
} }
@DisplayName("should send request with jwt") @DisplayName("should send request with jwt")
...@@ -138,6 +137,58 @@ class OsiPostfachRemoteServiceITCase { ...@@ -138,6 +137,58 @@ class OsiPostfachRemoteServiceITCase {
); );
} }
@DisplayName("should delete attachments on upload exception")
@Test
void shouldDeleteAttachmentsOnUploadException() {
var textFileId = AttachmentExampleUploadUtil.uploadTextFile(osi2AttachmentFileService);
postfachFacadeMockServer.stubFor(post(urlPathTemplate("/Quarantine/v1/Upload/Chunked"))
.willReturn(okJsonObj(QuarantineFileResult.builder()
.success(false)
.error("Upload failure")
.build()))
);
postfachFacadeMockServer.stubFor(delete(urlPathTemplate("/Quarantine/v1/Upload/{guid}"))
.willReturn(ok())
);
var postfachNachrichtWithAttachment = PostfachNachrichtTestFactory.createBuilder()
.attachments(List.of(textFileId))
.build();
osiPostfachRemoteService.sendMessage(postfachNachrichtWithAttachment);
postfachFacadeMockServer.verify(
exactly(1),
deleteRequestedFor(urlPathTemplate("/Quarantine/v1/Upload/{guid}"))
);
}
@DisplayName("should delete attachments on scan exception")
@Test
void shouldDeleteAttachmentsOnScanException() {
var textFileId = AttachmentExampleUploadUtil.uploadTextFile(osi2AttachmentFileService);
postfachFacadeMockServer.stubFor(post(urlPathTemplate("/Quarantine/v1/Upload/Chunked"))
.willReturn(okJsonObj(QuarantineFileResult.builder()
.success(true)
.build()))
);
postfachFacadeMockServer.stubFor(get(urlPathTemplate("/Quarantine/v1/Upload/{guid}"))
.willReturn(okJsonObj(QuarantineStatus.UNSAFE))
);
postfachFacadeMockServer.stubFor(delete(urlPathTemplate("/Quarantine/v1/Upload/{guid}"))
.willReturn(ok())
);
var postfachNachrichtWithAttachment = PostfachNachrichtTestFactory.createBuilder()
.attachments(List.of(textFileId))
.build();
osiPostfachRemoteService.sendMessage(postfachNachrichtWithAttachment);
postfachFacadeMockServer.verify(
exactly(1),
deleteRequestedFor(urlPathTemplate("/Quarantine/v1/Upload/{guid}"))
);
}
private void mockSendResponse() { private void mockSendResponse() {
// Stub message send response (MessageExchangeApi::sendMessage) // Stub message send response (MessageExchangeApi::sendMessage)
postfachFacadeMockServer.stubFor(post(urlPathTemplate("/MessageExchange/v1/Send/{mailboxId}")) postfachFacadeMockServer.stubFor(post(urlPathTemplate("/MessageExchange/v1/Send/{mailboxId}"))
......
...@@ -5,7 +5,6 @@ import java.util.Map; ...@@ -5,7 +5,6 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.ExtensionContext;
import org.testcontainers.containers.MongoDBContainer; import org.testcontainers.containers.MongoDBContainer;
...@@ -21,7 +20,7 @@ import lombok.extern.log4j.Log4j2; ...@@ -21,7 +20,7 @@ import lombok.extern.log4j.Log4j2;
@Log4j2 @Log4j2
@Getter @Getter
@RequiredArgsConstructor @RequiredArgsConstructor
public class VorgangManagerServerExtension implements BeforeAllCallback, AfterAllCallback, AfterEachCallback { public class VorgangManagerServerExtension implements BeforeAllCallback, AfterAllCallback {
static final String VORGANG_MANAGER_NETWORK_ALIAS = "vorgang-manager"; static final String VORGANG_MANAGER_NETWORK_ALIAS = "vorgang-manager";
static final String MONGODB_NETWORK_ALIAS = "mongodb"; static final String MONGODB_NETWORK_ALIAS = "mongodb";
...@@ -77,8 +76,4 @@ public class VorgangManagerServerExtension implements BeforeAllCallback, AfterAl ...@@ -77,8 +76,4 @@ public class VorgangManagerServerExtension implements BeforeAllCallback, AfterAl
.orElse("missing"); .orElse("missing");
} }
@Override
public void afterEach(ExtensionContext context) {
// Consider clearing mongodb (uploaded files)
}
} }
...@@ -16,6 +16,7 @@ import org.junit.jupiter.api.Test; ...@@ -16,6 +16,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
import org.springframework.core.io.AbstractResource;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht; import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.osiv2.config.Osi2PostfachProperties; import de.ozgcloud.nachrichten.postfach.osiv2.config.Osi2PostfachProperties;
...@@ -32,7 +33,6 @@ import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.OutSendMessageRequestV2; ...@@ -32,7 +33,6 @@ import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.OutSendMessageRequestV2;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.QuarantineStatus; import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.QuarantineStatus;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyMessage; import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyMessage;
import de.ozgcloud.nachrichten.postfach.osiv2.model.FileChunkInfo; import de.ozgcloud.nachrichten.postfach.osiv2.model.FileChunkInfo;
import de.ozgcloud.nachrichten.postfach.osiv2.model.FileChunkResource;
import de.ozgcloud.nachrichten.postfach.osiv2.model.Osi2FileUpload; import de.ozgcloud.nachrichten.postfach.osiv2.model.Osi2FileUpload;
import lombok.SneakyThrows; import lombok.SneakyThrows;
...@@ -214,7 +214,7 @@ class PostfachApiFacadeServiceTest { ...@@ -214,7 +214,7 @@ class PostfachApiFacadeServiceTest {
@Nested @Nested
class TestUploadChunk { class TestUploadChunk {
@Mock @Mock
FileChunkResource chunkResource; AbstractResource chunkResource;
@Mock @Mock
DomainChunkMetaData domainChunkMetaData; DomainChunkMetaData domainChunkMetaData;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment