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

OZG-4097 send-attachment: Setup upload of file

parent 57950e92
No related branches found
No related tags found
No related merge requests found
Showing
with 313 additions and 58 deletions
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<properties> <properties>
<api-lib.version>0.16.0</api-lib.version> <api-lib.version>0.16.0</api-lib.version>
<nachrichten-manager.version>2.17.0-SNAPSHOT</nachrichten-manager.version> <nachrichten-manager.version>2.17.0-SNAPSHOT</nachrichten-manager.version>
<openapi-generator.version>7.10.0</openapi-generator.version> <openapi-generator.version>7.11.0</openapi-generator.version>
<swagger-parser.version>2.1.23</swagger-parser.version> <swagger-parser.version>2.1.23</swagger-parser.version>
<wiremock-spring-boot.version>3.6.0</wiremock-spring-boot.version> <wiremock-spring-boot.version>3.6.0</wiremock-spring-boot.version>
</properties> </properties>
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId> <artifactId>spring-boot-starter-validation</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId> <artifactId>spring-boot-starter-oauth2-client</artifactId>
...@@ -139,7 +143,10 @@ ...@@ -139,7 +143,10 @@
<configuration> <configuration>
<inputSpec>${project.basedir}/spec/postfach-api-facade.yaml</inputSpec> <inputSpec>${project.basedir}/spec/postfach-api-facade.yaml</inputSpec>
<generatorName>java</generatorName> <generatorName>java</generatorName>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<configOptions> <configOptions>
<!-- https://openapi-generator.tech/docs/generators/java/#config-options -->
<sourceFolder>src/gen/java/main</sourceFolder> <sourceFolder>src/gen/java/main</sourceFolder>
<serializationLibrary>jackson</serializationLibrary> <serializationLibrary>jackson</serializationLibrary>
<library>restclient</library> <library>restclient</library>
...@@ -147,6 +154,8 @@ ...@@ -147,6 +154,8 @@
<apiPackage>de.ozgcloud.nachrichten.postfach.osiv2.gen.api</apiPackage> <apiPackage>de.ozgcloud.nachrichten.postfach.osiv2.gen.api</apiPackage>
<modelPackage>de.ozgcloud.nachrichten.postfach.osiv2.gen.model</modelPackage> <modelPackage>de.ozgcloud.nachrichten.postfach.osiv2.gen.model</modelPackage>
<openApiNullable>false</openApiNullable> <openApiNullable>false</openApiNullable>
<generateBuilders>true</generateBuilders>
<useAbstractionForFiles>true</useAbstractionForFiles>
</configOptions> </configOptions>
</configuration> </configuration>
</execution> </execution>
......
...@@ -844,7 +844,7 @@ paths: ...@@ -844,7 +844,7 @@ paths:
detail: Der Dienst ist zurzeit nicht verfügbar. detail: Der Dienst ist zurzeit nicht verfügbar.
/MessageExchange/v1/Send/{mailboxId}: /MessageExchange/v1/Send/{mailboxId}:
post: post:
operationId: SendMessage operationId: sendMessage
tags: tags:
- MessageExchange - MessageExchange
summary: Sendet eine Nachricht an ein externes oder internes Postfach. summary: Sendet eine Nachricht an ein externes oder internes Postfach.
...@@ -1733,6 +1733,7 @@ paths: ...@@ -1733,6 +1733,7 @@ paths:
description: OK description: OK
/Quarantine/v1/Upload/{guid}: /Quarantine/v1/Upload/{guid}:
get: get:
operationId: getUploadStatus
tags: tags:
- Quarantine - Quarantine
summary: Liefert den Status der Virenprüfung. summary: Liefert den Status der Virenprüfung.
...@@ -1819,6 +1820,7 @@ paths: ...@@ -1819,6 +1820,7 @@ paths:
status: 503 status: 503
detail: Der Dienst ist zurzeit nicht verfügbar. detail: Der Dienst ist zurzeit nicht verfügbar.
delete: delete:
operationId: deleteUpload
tags: tags:
- Quarantine - Quarantine
summary: Markiert die Datei zum Löschen summary: Markiert die Datei zum Löschen
...@@ -1905,6 +1907,7 @@ paths: ...@@ -1905,6 +1907,7 @@ paths:
detail: Der Dienst ist zurzeit nicht verfügbar. detail: Der Dienst ist zurzeit nicht verfügbar.
/Quarantine/v1/Upload/Chunked: /Quarantine/v1/Upload/Chunked:
post: post:
operationId: uploadChunk
tags: tags:
- Quarantine - Quarantine
summary: Lädt ein Dateistück in die Quarantäne hoch summary: Lädt ein Dateistück in die Quarantäne hoch
......
...@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service; ...@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht; import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.PostfachRemoteService; import de.ozgcloud.nachrichten.postfach.PostfachRemoteService;
import de.ozgcloud.nachrichten.postfach.osiv2.config.Osi2PostfachProperties; import de.ozgcloud.nachrichten.postfach.osiv2.config.Osi2PostfachProperties;
import de.ozgcloud.nachrichten.postfach.osiv2.transfer.Osi2PostfachService;
import de.ozgcloud.nachrichten.postfach.osiv2.transfer.PostfachApiFacadeService; import de.ozgcloud.nachrichten.postfach.osiv2.transfer.PostfachApiFacadeService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
...@@ -17,14 +18,14 @@ import lombok.extern.log4j.Log4j2; ...@@ -17,14 +18,14 @@ import lombok.extern.log4j.Log4j2;
@Log4j2 @Log4j2
@RequiredArgsConstructor @RequiredArgsConstructor
public class OsiPostfachRemoteService implements PostfachRemoteService { public class OsiPostfachRemoteService implements PostfachRemoteService {
private final PostfachApiFacadeService postfachApiFacadeService; private final Osi2PostfachService osi2PostfachService;
public static final String POSTFACH_TYPE_OSI = "OSI"; public static final String POSTFACH_TYPE_OSI = "OSI";
@Override @Override
public void sendMessage(PostfachNachricht nachricht) { public void sendMessage(PostfachNachricht nachricht) {
try { try {
postfachApiFacadeService.sendMessage(nachricht); osi2PostfachService.sendMessage(nachricht);
} catch (RuntimeException e) { } catch (RuntimeException e) {
throw new OsiPostfachException("Failed to send message", e); throw new OsiPostfachException("Failed to send message", e);
} }
...@@ -33,7 +34,7 @@ public class OsiPostfachRemoteService implements PostfachRemoteService { ...@@ -33,7 +34,7 @@ public class OsiPostfachRemoteService implements PostfachRemoteService {
@Override @Override
public Stream<PostfachNachricht> getAllMessages() { public Stream<PostfachNachricht> getAllMessages() {
try { try {
return postfachApiFacadeService.receiveMessages(); return osi2PostfachService.receiveMessages();
} catch (RuntimeException e) { } catch (RuntimeException e) {
throw new OsiPostfachException("Failed to get messages", e); throw new OsiPostfachException("Failed to get messages", e);
} }
...@@ -42,7 +43,7 @@ public class OsiPostfachRemoteService implements PostfachRemoteService { ...@@ -42,7 +43,7 @@ public class OsiPostfachRemoteService implements PostfachRemoteService {
@Override @Override
public void deleteMessage(String messageId) { public void deleteMessage(String messageId) {
try { try {
postfachApiFacadeService.deleteMessage(messageId); osi2PostfachService.deleteMessage(messageId);
} catch (RuntimeException e) { } catch (RuntimeException e) {
throw new OsiPostfachException("Failed to delete message", e); throw new OsiPostfachException("Failed to delete message", e);
} }
......
package de.ozgcloud.nachrichten.postfach.osiv2.model;
import lombok.Builder;
@Builder
public record UploadFileMetadata(
String guid,
String name,
String contentType,
Long size
) {
}
package de.ozgcloud.nachrichten.postfach.osiv2.transfer;
import java.util.stream.Stream;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.osiv2.config.Osi2PostfachProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
@Log4j2
@Service
@ConditionalOnProperty(prefix = Osi2PostfachProperties.PREFIX, name = "enabled", havingValue = "true")
@RequiredArgsConstructor
public class Osi2PostfachService {
private final PostfachApiFacadeService postfachApiFacadeService;
private final Osi2QuarantineService quarantineService;
public void sendMessage(PostfachNachricht nachricht) {
postfachApiFacadeService.sendMessage(
nachricht,
quarantineService.uploadAttachments(nachricht.getAttachments())
);
}
public Stream<PostfachNachricht> receiveMessages() {
return postfachApiFacadeService.fetchPendingMessageIds()
.stream()
.map(postfachApiFacadeService::fetchMessageById);
}
public void deleteMessage(final String messageId) {
postfachApiFacadeService.deleteMessage(messageId);
}
}
package de.ozgcloud.nachrichten.postfach.osiv2.transfer;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import de.ozgcloud.nachrichten.postfach.osiv2.config.Osi2PostfachProperties;
import de.ozgcloud.nachrichten.postfach.osiv2.model.UploadFileMetadata;
import de.ozgcloud.vorgang.grpc.binaryFile.BinaryFileServiceGrpc;
import de.ozgcloud.vorgang.grpc.binaryFile.GrpcGetBinaryFileDataRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
@Log4j2
@Service
@ConditionalOnProperty(prefix = Osi2PostfachProperties.PREFIX, name = "enabled", havingValue = "true")
@RequiredArgsConstructor
public class Osi2QuarantineService {
private final PostfachApiFacadeService postfachApiFacadeService;
private final BinaryFileServiceGrpc.BinaryFileServiceBlockingStub binaryFileService;
public List<UploadFileMetadata> uploadAttachments(List<String> attachmentIds) {
var uploadFileMetadata = attachmentIds.stream()
.map(this::uploadFileByAttachmentId)
.toList();
waitForVirusScan(uploadFileMetadata);
return uploadFileMetadata;
}
void waitForVirusScan(List<UploadFileMetadata> uploadFileMetadata) {
// TODO
}
void checkVirusScanCompleted(List<UploadFileMetadata> uploadFileMetadata) {
// TODO
}
UploadFileMetadata uploadFileByAttachmentId(String attachmentId) {
// TODO
// var request = createRequestWithFileId(attachmentId);
// var metadata = binaryFileService.findBinaryFilesMetaData(GrpcBinaryFilesRequest.newBuilder().)
// var content = binaryFileService.getBinaryFileContent(request);
//
// content.next().getFileContent().writeTo();
return null;
}
private GrpcGetBinaryFileDataRequest createRequestWithFileId(String fileId) {
return GrpcGetBinaryFileDataRequest.newBuilder().setFileId(fileId).build();
}
public void deleteAttachments(List<UploadFileMetadata> uploadFileMetadata) {
// TODO delete on exception
}
}
...@@ -2,38 +2,47 @@ package de.ozgcloud.nachrichten.postfach.osiv2.transfer; ...@@ -2,38 +2,47 @@ package de.ozgcloud.nachrichten.postfach.osiv2.transfer;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import org.mapstruct.BeforeMapping;
import org.mapstruct.Context;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.ReportingPolicy; import org.mapstruct.ReportingPolicy;
import de.ozgcloud.nachrichten.postfach.PostfachAddress; import de.ozgcloud.nachrichten.postfach.PostfachAddress;
import de.ozgcloud.nachrichten.postfach.PostfachAddressIdentifier; import de.ozgcloud.nachrichten.postfach.PostfachAddressIdentifier;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht; import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.DomainChunkMetaData;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.MessageExchangeFiles; import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.MessageExchangeFiles;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.OutSendMessageRequestV2; import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.OutSendMessageRequestV2;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1References; import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1References;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyBehavior; import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyBehavior;
import de.ozgcloud.nachrichten.postfach.osiv2.model.UploadFileMetadata;
@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) @Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR)
public interface Osi2RequestMapper { public interface Osi2RequestMapper {
@Mapping(target = "sequencenumber", source = "vorgangId") int MAX_NUMBER_RECEIVED_MESSAGES = 100;
@Mapping(target = "body", source = "mailBody")
@Mapping(target = "sequencenumber", source = "nachricht.vorgangId")
@Mapping(target = "body", source = "nachricht.mailBody")
@Mapping(target = "displayName", ignore = true) @Mapping(target = "displayName", ignore = true)
@Mapping(target = "originSender", ignore = true) @Mapping(target = "originSender", ignore = true)
@Mapping(target = "replyAction", source = "replyOption") @Mapping(target = "replyAction", source = "nachricht.replyOption")
@Mapping(target = "eidasLevel", constant = "LOW") @Mapping(target = "eidasLevel", constant = "LOW")
@Mapping(target = "isObligatory", expression = "java( false )") @Mapping(target = "isObligatory", expression = "java( false )")
@Mapping(target = "isHtml", expression = "java( false )") @Mapping(target = "isHtml", expression = "java( false )")
@Mapping(target = "files", expression = "java( mapMessageExchangeFiles() )") @Mapping(target = "files", source = "files")
@Mapping(target = "references", expression = "java( mapReferences() )") @Mapping(target = "references", expression = "java( mapReferences() )")
OutSendMessageRequestV2 mapOutSendMessageRequestV2(PostfachNachricht nachricht); OutSendMessageRequestV2 mapOutSendMessageRequestV2(PostfachNachricht nachricht, List<UploadFileMetadata> files);
default List<MessageExchangeFiles> mapMessageExchangeFiles() {
return Collections.emptyList(); @Mapping(target = "mimeType", source = "contentType")
} @Mapping(target = "isOriginalMessage", expression = "java( false )")
MessageExchangeFiles mapMessageExchangeFile(UploadFileMetadata attachmentMetadata);
default List<V1References> mapReferences() { default List<V1References> mapReferences() {
return Collections.emptyList(); return Collections.emptyList();
...@@ -47,6 +56,9 @@ public interface Osi2RequestMapper { ...@@ -47,6 +56,9 @@ public interface Osi2RequestMapper {
}; };
} }
DomainChunkMetaData mapDomainChunkMetaData(UploadFileMetadata attachmentMetadata);
default String mapMailboxId(PostfachNachricht nachricht) { default String mapMailboxId(PostfachNachricht nachricht) {
return Optional.ofNullable(nachricht.getPostfachAddress()) return Optional.ofNullable(nachricht.getPostfachAddress())
.map(PostfachAddress::getIdentifier) .map(PostfachAddress::getIdentifier)
......
...@@ -2,6 +2,10 @@ package de.ozgcloud.nachrichten.postfach.osiv2.transfer; ...@@ -2,6 +2,10 @@ package de.ozgcloud.nachrichten.postfach.osiv2.transfer;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
...@@ -12,7 +16,10 @@ import org.mapstruct.ReportingPolicy; ...@@ -12,7 +16,10 @@ import org.mapstruct.ReportingPolicy;
import de.ozgcloud.nachrichten.postfach.PostfachAddress; import de.ozgcloud.nachrichten.postfach.PostfachAddress;
import de.ozgcloud.nachrichten.postfach.PostfachAddressIdentifier; import de.ozgcloud.nachrichten.postfach.PostfachAddressIdentifier;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht; import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.osiv2.OsiPostfachException;
import de.ozgcloud.nachrichten.postfach.osiv2.OsiPostfachRemoteService; import de.ozgcloud.nachrichten.postfach.osiv2.OsiPostfachRemoteService;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.MessageExchangeReceiveMessage;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.MessageExchangeReceiveMessagesResponse;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyBehavior; import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyBehavior;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyMessage; import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyMessage;
import lombok.Builder; import lombok.Builder;
...@@ -86,6 +93,20 @@ public interface Osi2ResponseMapper { ...@@ -86,6 +93,20 @@ public interface Osi2ResponseMapper {
}; };
} }
default List<String> toMessageIds(MessageExchangeReceiveMessagesResponse response) {
if (response == null) {
throw new OsiPostfachException("Expect non empty response!", null);
}
return Optional.ofNullable(response.getMessages())
.stream()
.flatMap(Collection::stream)
.map(MessageExchangeReceiveMessage::getGuid)
.filter(Objects::nonNull)
.map(UUID::toString)
.toList();
}
@Builder @Builder
@Getter @Getter
class StringBasedIdentifier implements PostfachAddressIdentifier { class StringBasedIdentifier implements PostfachAddressIdentifier {
......
package de.ozgcloud.nachrichten.postfach.osiv2.transfer; package de.ozgcloud.nachrichten.postfach.osiv2.transfer;
import java.util.Collection; import static de.ozgcloud.nachrichten.postfach.osiv2.transfer.Osi2RequestMapper.*;
import java.util.Optional;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Stream;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht; import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.osiv2.OsiPostfachException;
import de.ozgcloud.nachrichten.postfach.osiv2.config.Osi2PostfachProperties; import de.ozgcloud.nachrichten.postfach.osiv2.config.Osi2PostfachProperties;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.api.MessageExchangeApi; import de.ozgcloud.nachrichten.postfach.osiv2.gen.api.MessageExchangeApi;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.MessageExchangeReceiveMessage; import de.ozgcloud.nachrichten.postfach.osiv2.gen.api.QuarantineApi;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.MessageExchangeReceiveMessagesResponse; import de.ozgcloud.nachrichten.postfach.osiv2.model.UploadFileMetadata;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
...@@ -24,33 +23,37 @@ import lombok.extern.log4j.Log4j2; ...@@ -24,33 +23,37 @@ import lombok.extern.log4j.Log4j2;
public class PostfachApiFacadeService { public class PostfachApiFacadeService {
private final MessageExchangeApi messageExchangeApi; private final MessageExchangeApi messageExchangeApi;
private final Osi2RequestMapper osi2RequestMapper; private final QuarantineApi quarantineApi;
private final Osi2ResponseMapper osi2ResponseMapper; private final Osi2RequestMapper requestMapper;
private final Osi2ResponseMapper responseMapper;
static final int MAX_NUMBER_RECEIVED_MESSAGES = 100; private final Osi2PostfachProperties.ApiConfiguration apiConfiguration;
public void sendMessage(PostfachNachricht nachricht) { public void sendMessage(PostfachNachricht nachricht, List<UploadFileMetadata> attachments) {
messageExchangeApi.sendMessage( messageExchangeApi.sendMessage(
osi2RequestMapper.mapMailboxId(nachricht), requestMapper.mapMailboxId(nachricht),
osi2RequestMapper.mapOutSendMessageRequestV2(nachricht) requestMapper.mapOutSendMessageRequestV2(nachricht, attachments)
); );
} }
public Stream<PostfachNachricht> receiveMessages() { public void uploadChunk(String uploadId, byte[] chunk) {
return Optional.ofNullable(receiveMessagesResponse().getMessages()) // TODO
.stream() // quarantineApi.uploadChunk(
.flatMap(Collection::stream) // requestMapper.mapDomainChunkMetaData(null),
.map(this::fetchMessageByGuid); // apiConfiguration.getTenant(),
// apiConfiguration.getNameIdentifier(),
// new ByteArrayResource(chunk)
// );
} }
private MessageExchangeReceiveMessagesResponse receiveMessagesResponse() { public List<String> fetchPendingMessageIds() {
return Optional.ofNullable(messageExchangeApi.receiveMessages(MAX_NUMBER_RECEIVED_MESSAGES, 0)) return responseMapper.toMessageIds(
.orElseThrow(() -> new OsiPostfachException("Expect non empty response!", null)); messageExchangeApi.receiveMessages(MAX_NUMBER_RECEIVED_MESSAGES, 0)
);
} }
PostfachNachricht fetchMessageByGuid(final MessageExchangeReceiveMessage message) { public PostfachNachricht fetchMessageById(final String messageId) {
var messageReply = messageExchangeApi.getMessage(message.getGuid()); var messageReply = messageExchangeApi.getMessage(UUID.fromString(messageId));
return osi2ResponseMapper.toPostfachNachricht(messageReply); return responseMapper.toPostfachNachricht(messageReply);
} }
public void deleteMessage(final String messageId) { public void deleteMessage(final String messageId) {
......
...@@ -15,7 +15,7 @@ import org.mockito.Spy; ...@@ -15,7 +15,7 @@ import org.mockito.Spy;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht; import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory; import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory;
import de.ozgcloud.nachrichten.postfach.osiv2.transfer.PostfachApiFacadeService; import de.ozgcloud.nachrichten.postfach.osiv2.transfer.Osi2PostfachService;
class OsiPostfachRemoteServiceTest { class OsiPostfachRemoteServiceTest {
...@@ -24,7 +24,7 @@ class OsiPostfachRemoteServiceTest { ...@@ -24,7 +24,7 @@ class OsiPostfachRemoteServiceTest {
private OsiPostfachRemoteService osiPostfachRemoteService; private OsiPostfachRemoteService osiPostfachRemoteService;
@Mock @Mock
private PostfachApiFacadeService postfachApiFacadeService; private Osi2PostfachService osi2PostfachService;
private final PostfachNachricht nachricht1 = PostfachNachrichtTestFactory.createBuilder() private final PostfachNachricht nachricht1 = PostfachNachrichtTestFactory.createBuilder()
.subject("Nachricht 1") .subject("Nachricht 1")
...@@ -40,15 +40,15 @@ class OsiPostfachRemoteServiceTest { ...@@ -40,15 +40,15 @@ class OsiPostfachRemoteServiceTest {
@DisplayName("should call send message") @DisplayName("should call send message")
@Test @Test
void shouldCallSendMessage() { void shouldCallSendMessage() {
postfachApiFacadeService.sendMessage(nachricht1); osi2PostfachService.sendMessage(nachricht1);
verify(postfachApiFacadeService).sendMessage(nachricht1); verify(osi2PostfachService).sendMessage(nachricht1);
} }
@DisplayName("should throw osi postfach exception on runtime exception") @DisplayName("should throw osi postfach exception on runtime exception")
@Test @Test
void shouldThrowOsiPostfachExceptionOnRuntimeException() { void shouldThrowOsiPostfachExceptionOnRuntimeException() {
doThrow(new RuntimeException()).when(postfachApiFacadeService).sendMessage(nachricht1); doThrow(new RuntimeException()).when(osi2PostfachService).sendMessage(nachricht1);
assertThatThrownBy(() -> osiPostfachRemoteService.sendMessage(nachricht1)) assertThatThrownBy(() -> osiPostfachRemoteService.sendMessage(nachricht1))
.isInstanceOf(OsiPostfachException.class); .isInstanceOf(OsiPostfachException.class);
...@@ -62,7 +62,7 @@ class OsiPostfachRemoteServiceTest { ...@@ -62,7 +62,7 @@ class OsiPostfachRemoteServiceTest {
@DisplayName("should return postfach messages") @DisplayName("should return postfach messages")
@Test @Test
void shouldReturnPostfachMessages() { void shouldReturnPostfachMessages() {
when(postfachApiFacadeService.receiveMessages()).thenReturn(Stream.of(nachricht1, nachricht2)); when(osi2PostfachService.receiveMessages()).thenReturn(Stream.of(nachricht1, nachricht2));
var result = osiPostfachRemoteService.getAllMessages(); var result = osiPostfachRemoteService.getAllMessages();
...@@ -77,15 +77,15 @@ class OsiPostfachRemoteServiceTest { ...@@ -77,15 +77,15 @@ class OsiPostfachRemoteServiceTest {
@DisplayName("should call deleteMessage") @DisplayName("should call deleteMessage")
@Test @Test
void shouldCallDeleteMessage() { void shouldCallDeleteMessage() {
postfachApiFacadeService.deleteMessage(UUID.randomUUID().toString()); osi2PostfachService.deleteMessage(UUID.randomUUID().toString());
verify(postfachApiFacadeService).deleteMessage(any()); verify(osi2PostfachService).deleteMessage(any());
} }
@DisplayName("should throw osi postfach exception on runtime exception") @DisplayName("should throw osi postfach exception on runtime exception")
@Test @Test
void shouldThrowOsiPostfachExceptionOnRuntimeException() { void shouldThrowOsiPostfachExceptionOnRuntimeException() {
doThrow(new RuntimeException()).when(postfachApiFacadeService).deleteMessage(UUID.randomUUID().toString()); doThrow(new RuntimeException()).when(osi2PostfachService).deleteMessage(UUID.randomUUID().toString());
assertThatThrownBy(() -> osiPostfachRemoteService.deleteMessage(anyString())).isInstanceOf(OsiPostfachException.class); assertThatThrownBy(() -> osiPostfachRemoteService.deleteMessage(anyString())).isInstanceOf(OsiPostfachException.class);
} }
......
...@@ -2,8 +2,12 @@ package de.ozgcloud.nachrichten.postfach.osiv2.transfer; ...@@ -2,8 +2,12 @@ package de.ozgcloud.nachrichten.postfach.osiv2.transfer;
import static de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachAddressTestFactory.*; import static de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachAddressTestFactory.*;
import static de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory.*; import static de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory.*;
import static de.ozgcloud.nachrichten.postfach.osiv2.transfer.UploadFileMetadataTestFactory.*;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import java.util.List;
import java.util.UUID;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
...@@ -19,6 +23,7 @@ import de.ozgcloud.nachrichten.postfach.PostfachAddressIdentifier; ...@@ -19,6 +23,7 @@ import de.ozgcloud.nachrichten.postfach.PostfachAddressIdentifier;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht; import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachAddressTestFactory; import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachAddressTestFactory;
import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory; import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.MessageExchangeFiles;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.OutSendMessageRequestV2; import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.OutSendMessageRequestV2;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1EidasLevel; import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1EidasLevel;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyBehavior; import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyBehavior;
...@@ -117,7 +122,7 @@ class Osi2RequestMapperTest { ...@@ -117,7 +122,7 @@ class Osi2RequestMapperTest {
.replyOption(PostfachNachricht.ReplyOption.POSSIBLE) .replyOption(PostfachNachricht.ReplyOption.POSSIBLE)
.build(); .build();
var result = mapper.mapOutSendMessageRequestV2(nachricht); var result = mapper.mapOutSendMessageRequestV2(nachricht, emptyList());
assertThat(result.getReplyAction()).isEqualTo(V1ReplyBehavior.REPLYPOSSIBLE); assertThat(result.getReplyAction()).isEqualTo(V1ReplyBehavior.REPLYPOSSIBLE);
} }
...@@ -129,7 +134,7 @@ class Osi2RequestMapperTest { ...@@ -129,7 +134,7 @@ class Osi2RequestMapperTest {
.replyOption(PostfachNachricht.ReplyOption.MANDATORY) .replyOption(PostfachNachricht.ReplyOption.MANDATORY)
.build(); .build();
var result = mapper.mapOutSendMessageRequestV2(nachricht); var result = mapper.mapOutSendMessageRequestV2(nachricht, emptyList());
assertThat(result.getReplyAction()).isEqualTo(V1ReplyBehavior.REPLYMANDATORY); assertThat(result.getReplyAction()).isEqualTo(V1ReplyBehavior.REPLYMANDATORY);
} }
...@@ -158,10 +163,38 @@ class Osi2RequestMapperTest { ...@@ -158,10 +163,38 @@ class Osi2RequestMapperTest {
assertThat(result.getIsHtml()).isFalse(); assertThat(result.getIsHtml()).isFalse();
} }
@DisplayName("should map files if empty")
@Test
void shouldMapFilesIfEmpty() {
var result = doMapping();
assertThat(result.getFiles()).isEmpty();
}
@DisplayName("should map two files")
@Test
void shouldMapTwoFiles() {
var files = List.of(
UploadFileMetadataTestFactory.create(),
UploadFileMetadataTestFactory.createBuilder()
.guid(UPLOAD_GUID2)
.build()
);
var result = mapper.mapOutSendMessageRequestV2(PostfachNachrichtTestFactory.create(), files);
assertThat(result.getFiles())
.usingRecursiveComparison()
.isEqualTo(files.stream().map(mapper::mapMessageExchangeFile).toList());
}
@DisplayName("should map files") @DisplayName("should map files")
@Test @Test
void shouldMapFiles() { void shouldMapFiles() {
var result = doMapping(); var result = mapper.mapOutSendMessageRequestV2(
PostfachNachrichtTestFactory.create(),
List.of(UploadFileMetadataTestFactory.create())
);
assertThat(result.getFiles()).isEmpty(); assertThat(result.getFiles()).isEmpty();
} }
...@@ -175,7 +208,47 @@ class Osi2RequestMapperTest { ...@@ -175,7 +208,47 @@ class Osi2RequestMapperTest {
} }
private OutSendMessageRequestV2 doMapping() { private OutSendMessageRequestV2 doMapping() {
return mapper.mapOutSendMessageRequestV2(PostfachNachrichtTestFactory.create()); return mapper.mapOutSendMessageRequestV2(PostfachNachrichtTestFactory.create(), emptyList());
}
}
@DisplayName("map message exchange file")
@Nested
class TestMapMessageExchangeFile {
@DisplayName("should map guid")
@Test
void shouldMapGuid() {
var result = mapFile();
assertThat(result.getGuid()).isEqualTo(UPLOAD_GUID);
}
@DisplayName("should map mimeType")
@Test
void shouldMapMimeType() {
var result = mapFile();
assertThat(result.getMimeType()).isEqualTo(UPLOAD_CONTENT_TYPE);
}
@DisplayName("should map name")
@Test
void shouldMapName() {
var result = mapFile();
assertThat(result.getName()).isEqualTo(UPLOAD_NAME);
}
@DisplayName("should map size")
@Test
void shouldMapSize() {
var result = mapFile();
assertThat(result.getSize()).isEqualTo(UPLOAD_SIZE);
}
private MessageExchangeFiles mapFile() {
return mapper.mapMessageExchangeFile(UploadFileMetadataTestFactory.create());
} }
} }
......
...@@ -88,9 +88,9 @@ class PostfachApiFacadeServiceTest { ...@@ -88,9 +88,9 @@ class PostfachApiFacadeServiceTest {
void mock() { void mock() {
when(messageExchangeApi.receiveMessages(anyInt(), anyInt())).thenReturn(response); when(messageExchangeApi.receiveMessages(anyInt(), anyInt())).thenReturn(response);
doReturn(PostfachNachrichtTestFactory.createBuilder().messageId(MESSAGE_ID_1).build()) doReturn(PostfachNachrichtTestFactory.createBuilder().messageId(MESSAGE_ID_1).build())
.when(postfachApiFacadeService).fetchMessageByGuid(response.getMessages().get(0)); .when(postfachApiFacadeService).fetchMessageById(response.getMessages().get(0));
doReturn(PostfachNachrichtTestFactory.createBuilder().messageId(MESSAGE_ID_2).build()) doReturn(PostfachNachrichtTestFactory.createBuilder().messageId(MESSAGE_ID_2).build())
.when(postfachApiFacadeService).fetchMessageByGuid(response.getMessages().get(1)); .when(postfachApiFacadeService).fetchMessageById(response.getMessages().get(1));
} }
@DisplayName("should return") @DisplayName("should return")
...@@ -146,7 +146,7 @@ class PostfachApiFacadeServiceTest { ...@@ -146,7 +146,7 @@ class PostfachApiFacadeServiceTest {
} }
private List<PostfachNachricht> receiveMessageList() { private List<PostfachNachricht> receiveMessageList() {
return postfachApiFacadeService.receiveMessages().toList(); return postfachApiFacadeService.fetchPendingMessageIds().toList();
} }
} }
...@@ -164,7 +164,7 @@ class PostfachApiFacadeServiceTest { ...@@ -164,7 +164,7 @@ class PostfachApiFacadeServiceTest {
void shouldCallGetMessage() { void shouldCallGetMessage() {
when(messageExchangeApi.getMessage(any())).thenReturn(replyMessage); when(messageExchangeApi.getMessage(any())).thenReturn(replyMessage);
postfachApiFacadeService.fetchMessageByGuid(receiveMessage); postfachApiFacadeService.fetchMessageById(receiveMessage);
verify(messageExchangeApi).getMessage(any()); verify(messageExchangeApi).getMessage(any());
} }
...@@ -174,7 +174,7 @@ class PostfachApiFacadeServiceTest { ...@@ -174,7 +174,7 @@ class PostfachApiFacadeServiceTest {
when(messageExchangeApi.getMessage(any())).thenReturn(replyMessage); when(messageExchangeApi.getMessage(any())).thenReturn(replyMessage);
when(osi2ResponseMapper.toPostfachNachricht(any())).thenReturn(PostfachNachrichtTestFactory.create()); when(osi2ResponseMapper.toPostfachNachricht(any())).thenReturn(PostfachNachrichtTestFactory.create());
postfachApiFacadeService.fetchMessageByGuid(receiveMessage); postfachApiFacadeService.fetchMessageById(receiveMessage);
verify(osi2ResponseMapper).toPostfachNachricht(any()); verify(osi2ResponseMapper).toPostfachNachricht(any());
} }
...@@ -184,7 +184,7 @@ class PostfachApiFacadeServiceTest { ...@@ -184,7 +184,7 @@ class PostfachApiFacadeServiceTest {
when(messageExchangeApi.getMessage(any())).thenReturn(replyMessage); when(messageExchangeApi.getMessage(any())).thenReturn(replyMessage);
when(osi2ResponseMapper.toPostfachNachricht(any())).thenReturn(PostfachNachrichtTestFactory.create()); when(osi2ResponseMapper.toPostfachNachricht(any())).thenReturn(PostfachNachrichtTestFactory.create());
var postfachNachricht = postfachApiFacadeService.fetchMessageByGuid(receiveMessage); var postfachNachricht = postfachApiFacadeService.fetchMessageById(receiveMessage);
assertThat(postfachNachricht).isInstanceOf(PostfachNachricht.class); assertThat(postfachNachricht).isInstanceOf(PostfachNachricht.class);
} }
......
package de.ozgcloud.nachrichten.postfach.osiv2.transfer;
import java.util.UUID;
import de.ozgcloud.nachrichten.postfach.osiv2.model.UploadFileMetadata;
public class UploadFileMetadataTestFactory {
public static final String UPLOAD_GUID = UUID.randomUUID().toString();
public static final String UPLOAD_GUID2 = UUID.randomUUID().toString();
public static final String UPLOAD_NAME = "upload.txt";
public static final String UPLOAD_CONTENT_TYPE = "text/plain";
public static final Long UPLOAD_SIZE = 1001L;
public static UploadFileMetadata create() {
return createBuilder().build();
}
public static UploadFileMetadata.UploadFileMetadataBuilder createBuilder() {
return UploadFileMetadata.builder()
.guid(UPLOAD_GUID)
.name(UPLOAD_NAME)
.contentType(UPLOAD_CONTENT_TYPE)
.size(UPLOAD_SIZE);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment