diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/AttachmentService.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/AttachmentService.java index c814a9f095574ffb310aff05fb32ebe3fb581eac..d9b614b2469698f5ef9f6e8ee06baab569e2c64f 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/AttachmentService.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/AttachmentService.java @@ -35,7 +35,7 @@ import org.springframework.util.Base64Utils; import de.itvsh.kop.common.errorhandling.TechnicalException; @Service -class AttachmentService { +public class AttachmentService { @Autowired private PersistPostfachNachrichtService persistPostfachNachrichtService; @@ -43,7 +43,7 @@ class AttachmentService { @Autowired private BinaryFileService binaryFileService; - MessageAttachment getMessageAttachment(FileId fileId) { + public MessageAttachment getMessageAttachment(FileId fileId) { try { return MessageAttachment.builder() .fileName(binaryFileService.getFile(fileId).getMetadata().getString("name")) @@ -64,7 +64,7 @@ class AttachmentService { return Base64Utils.encodeToString(content); } - String persistAttachment(String vorgangId, MessageAttachment attachment) { + public String persistAttachment(String vorgangId, MessageAttachment attachment) { return persistPostfachNachrichtService.persistAttachment(vorgangId, attachment); } diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/NotConfiguredException.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/NotConfiguredException.java index f6650b947fd95c00225a76f498c5cb5234e10721..fae3f2e7d8c36b35c643e604b9664990c7690656 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/NotConfiguredException.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/NotConfiguredException.java @@ -23,13 +23,13 @@ */ package de.itvsh.ozg.mail.postfach; -class NotConfiguredException extends OsiPostfachException { // NOSONAR +public class NotConfiguredException extends PostfachException { // NOSONAR private static final long serialVersionUID = 1L; - public NotConfiguredException() { - super("Osi-Postfach is not completely configured. Sending and receiving of postfach mails is not possible.", - OsiPostfachMessageCode.SERVER_CONNECTION_FAILED_MESSAGE_CODE); + public NotConfiguredException(String postfachIdentifier) { + super(String.format("%s Postfach is not completely configured. Sending and receiving of postfach mails is not possible.", postfachIdentifier), + PostfachMessageCode.SERVER_CONNECTION_FAILED_MESSAGE_CODE); } } diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachAddressIdentifier.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachAddressIdentifier.java index 97880c4f2d51dc2fd6fd8d635f64e7913d08fd7c..05877230cd51878be5d15543613fa0dd541ae0b7 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachAddressIdentifier.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachAddressIdentifier.java @@ -1,5 +1,5 @@ package de.itvsh.ozg.mail.postfach; -interface PostfachAddressIdentifier { +public interface PostfachAddressIdentifier { } diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachServerProcessException.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachBadRequestException.java similarity index 77% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachServerProcessException.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachBadRequestException.java index f3acfe246721ff6f2a92041f789239599f748810..df0c758827dc23f93a4a77bae46332680793d23b 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachServerProcessException.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachBadRequestException.java @@ -23,11 +23,14 @@ */ package de.itvsh.ozg.mail.postfach; -class OsiPostfachServerProcessException extends OsiPostfachException {// NOSONAR +public class PostfachBadRequestException extends PostfachException { private static final long serialVersionUID = 1L; - public OsiPostfachServerProcessException() { - super("Osi-Postfach server returned false", OsiPostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE); + public PostfachBadRequestException(String postfachIdentifier, Throwable cause) { + super( + String.format("Bad-Request Received from %s Postfach Server", postfachIdentifier), + PostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE, cause + ); } } \ No newline at end of file diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachEventListener.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachEventListener.java index 4424845470c6bc640b710d8066853e6bb0b9541e..ab8539abb2bd2b5ebf6e76ededde9e7f41ea3c7f 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachEventListener.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachEventListener.java @@ -36,7 +36,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; -import de.itvsh.ozg.mail.postfach.Message.ReplyOption; import de.itvsh.ozg.mail.postfach.PostfachNachricht.Direction; import de.itvsh.ozg.pluto.command.Command; import de.itvsh.ozg.pluto.command.CommandCreatedEvent; diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachException.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachException.java similarity index 81% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachException.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachException.java index f24953ae69b929d6a13ec251fdf7778fce4058bd..5d578509a930a8af70baea4eb7e4222d322aab11 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachException.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachException.java @@ -26,18 +26,18 @@ package de.itvsh.ozg.mail.postfach; import de.itvsh.ozg.mail.common.errorhandling.TechnicalException; import lombok.Getter; -public class OsiPostfachException extends TechnicalException { +public class PostfachException extends TechnicalException { private static final long serialVersionUID = 1L; @Getter - private final OsiPostfachMessageCode messageCode; + private final PostfachMessageCode messageCode; - public OsiPostfachException(String message, OsiPostfachMessageCode messageCode) { + public PostfachException(String message, PostfachMessageCode messageCode) { super(message); this.messageCode = messageCode; } - public OsiPostfachException(String message, OsiPostfachMessageCode messageCode, Throwable cause) { + public PostfachException(String message, PostfachMessageCode messageCode, Throwable cause) { super(message, cause); this.messageCode = messageCode; diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachMessageCode.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachMessageCode.java similarity index 97% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachMessageCode.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachMessageCode.java index fdd91032b775f033365299e452f5a19d6b5363f6..002de7b355e14a320513cff059c813b7c1cca0d3 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachMessageCode.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachMessageCode.java @@ -28,7 +28,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; @AllArgsConstructor(access = AccessLevel.PRIVATE) -enum OsiPostfachMessageCode { +enum PostfachMessageCode { PROCESS_FAILED_MESSAGE_CODE("postfachnachricht.server.processing_failed"), SERVER_CONNECTION_FAILED_MESSAGE_CODE("postfachnachricht.server.connection_failed"), diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachNachricht.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachNachricht.java index 1991fab631897276bc95474f18d32c2f7a0861ec..f5fb5e9a6d16caeae40446347f503b1f65a250cc 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachNachricht.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachNachricht.java @@ -29,7 +29,6 @@ import java.util.List; import javax.validation.constraints.NotNull; -import de.itvsh.ozg.mail.postfach.Message.ReplyOption; import lombok.Builder; import lombok.Getter; diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtMapper.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtMapper.java index b82128fdf0e34b24cfa1f0564acb659c8c072222..9bf0ff57126580926851d1ffafc8e904b3beb9ee 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtMapper.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtMapper.java @@ -39,7 +39,6 @@ import org.mapstruct.ValueMapping; import org.springframework.beans.factory.annotation.Autowired; import de.itvsh.kop.pluto.common.grpc.GrpcObjectMapper; -import de.itvsh.ozg.mail.postfach.Message.ReplyOption; import de.itvsh.ozg.mail.postfach.PostfachNachricht.Direction; import de.itvsh.ozg.pluto.common.GrpcObject; import de.itvsh.ozg.pluto.vorgang.GrpcPostfachAddress; @@ -47,36 +46,9 @@ import de.itvsh.ozg.pluto.vorgang.GrpcPostfachAddress; @Mapper(unmappedTargetPolicy = ReportingPolicy.WARN) public abstract class PostfachNachrichtMapper { - private static final String POSTFACH_ADDRESS_VERSION = "1.0"; - private static final int POSTFACH_ADDRESS_TYPE = 1; - - @Autowired - private AttachmentService attachmentService; @Autowired private GrpcObjectMapper grpcObjectMapper; - @Mapping(target = "attachment", ignore = true) - @Mapping(target = "messageId", ignore = true) - - @Mapping(target = "isHtml", constant = "false") - @Mapping(target = "rechtsverbindlich", constant = "false") - @Mapping(target = "eidasLevel", constant = "MEDIUM") - @Mapping(target = "postfachId", expression = "java(toPostfachId(nachricht))") - public abstract Message toOsiMessage(PostfachNachricht nachricht); - - List<MessageAttachment> map(List<String> attachedFileIds) { - return attachedFileIds.stream().map(FileId::from).map(fileId -> attachmentService.getMessageAttachment(fileId)).toList(); - } - - String toPostfachId(PostfachNachricht nachricht) { - return Optional.ofNullable(nachricht.getPostfachAddress()) - .map(PostfachAddress::getIdentifier) - .filter(StringBasedIdentifier.class::isInstance) - .map(StringBasedIdentifier.class::cast) - .map(StringBasedIdentifier::getPostfachId) - .orElse(nachricht.getPostfachId()); - } - @Mapping(target = "attachments", source = "attachmentList") @Mapping(target = "createdAt", ignore = true) @Mapping(target = "createdBy", ignore = true) @@ -127,30 +99,6 @@ public abstract class PostfachNachrichtMapper { .build(); } - @Mapping(target = "createdBy", ignore = true) - @Mapping(target = "id", ignore = true) - @Mapping(target = "messageCode", ignore = true) - @Mapping(target = "sentAt", ignore = true) - @Mapping(target = "sentSuccessful", ignore = true) - @Mapping(target = "createdAt", expression = "java(java.time.ZonedDateTime.now())") - @Mapping(target = "direction", constant = "IN") - @Mapping(target = "attachments", expression = "java(persistAttachements(message.getVorgangId() ,message.getAttachments()))") - @Mapping(target = "postfachAddress", expression = "java(buildPostfachAddressByPostfachId(message.getPostfachId()))") - public abstract PostfachNachricht toMail(Message message); - - List<String> persistAttachements(String vorgangId, List<MessageAttachment> attachments) { - return attachments.stream().map(attachment -> attachmentService.persistAttachment(vorgangId, attachment)).toList(); - } - - PostfachAddress buildPostfachAddressByPostfachId(String postfachId) { - return PostfachAddress.builder() - .type(POSTFACH_ADDRESS_TYPE) - .version(POSTFACH_ADDRESS_VERSION) - .identifier(StringBasedIdentifier.builder().postfachId(postfachId).build()) - .build(); - - } - PostfachNachricht fromMapToPostfachMail(Map<String, Object> mailMap) { var postfachMailBuilder = PostfachNachricht.builder() .id(MapUtils.getString(mailMap, PostfachNachricht.FIELD_ID)) diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachRemoteService.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachRemoteService.java index aeaeea055697ed57953e14fe2f6e9ebd8a0a0ae3..db46244f962414999e2c29e7d713720be1aff8d3 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachRemoteService.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachRemoteService.java @@ -7,4 +7,7 @@ public interface PostfachRemoteService { void sendMessage(PostfachNachricht nachricht); Stream<PostfachNachricht> getAllMessages(); + + void deleteMessage(String messageId); + } \ No newline at end of file diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachRuntimeException.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachRuntimeException.java similarity index 77% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachRuntimeException.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachRuntimeException.java index cba2d9267dfff6787f2a4cf3dd507fe8a5d06660..a09557239c05065ea1e721d4021db14490fb97a4 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachRuntimeException.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachRuntimeException.java @@ -23,11 +23,12 @@ */ package de.itvsh.ozg.mail.postfach; -class OsiPostfachRuntimeException extends OsiPostfachException {// NOSONAR +public class PostfachRuntimeException extends PostfachException {// NOSONAR private static final long serialVersionUID = 1L; - public OsiPostfachRuntimeException(Throwable cause) { - super("Error executing Request to OSI Postfach", OsiPostfachMessageCode.SERVER_CONNECTION_FAILED_MESSAGE_CODE, cause); + public PostfachRuntimeException(String postfachIdentifier, Throwable cause) { + super(String.format("Error executing Request to %s Postfach", postfachIdentifier), + PostfachMessageCode.SERVER_CONNECTION_FAILED_MESSAGE_CODE, cause); } } \ No newline at end of file diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachBadRequestException.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachServerProcessException.java similarity index 78% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachBadRequestException.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachServerProcessException.java index 6b54c44f0fbe9a4c9e161001f45074091f0c7c52..9a6a980f0a50c59115e9b81b89944623e7b74396 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachBadRequestException.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachServerProcessException.java @@ -23,11 +23,14 @@ */ package de.itvsh.ozg.mail.postfach; -class OsiPostfachBadRequestException extends OsiPostfachException { +public class PostfachServerProcessException extends PostfachException {// NOSONAR private static final long serialVersionUID = 1L; - public OsiPostfachBadRequestException(Throwable cause) { - super("Bad-Request Received from OSI-Postfach Server", OsiPostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE, cause); + public PostfachServerProcessException(String postfachIdentifier) { + super( + String.format("%s Postfach server returned false", postfachIdentifier), + PostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE + ); } } \ No newline at end of file diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachService.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachService.java index 0e146feb57e868069a4b45d151f89ab87695eae0..13ec8094eb2942b1e9903bd853d099e869dcb7af 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachService.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachService.java @@ -45,12 +45,13 @@ import lombok.extern.log4j.Log4j2; @Log4j2 @Service @Validated -class PostfachService { +public class PostfachService { private static final Predicate<PostfachNachricht> IS_FROM_HUMAN_USER = nachricht -> !StringUtils.startsWith(nachricht.getCreatedBy(), "system"); - @Autowired - private OsiPostfachService osiPostfachService; + @Autowired(required = false) + private PostfachRemoteService postfachRemoteService; + @Autowired private PostfachNachrichtMapper mapper; @@ -90,14 +91,14 @@ class PostfachService { } public void fetchAndPersistReplies() { - osiPostfachService.getAllMessages().map(mapper::toMail).forEach(this::persistReceivedMail); + postfachRemoteService.getAllMessages().forEach(this::persistReceivedMail); } - private void persistReceivedMail(PostfachNachricht mail) { - persistMail(Optional.empty(), mail); - clientAttributeService.setHasNewPostfachNachricht(mail.getVorgangId()); + private void persistReceivedMail(PostfachNachricht nachricht) { + persistMail(Optional.empty(), nachricht); + clientAttributeService.setHasNewPostfachNachricht(nachricht.getVorgangId()); - osiPostfachService.deleteMessage(mail.getMessageId()); + postfachRemoteService.deleteMessage(nachricht.getMessageId()); } void persistMail(Optional<String> userId, PostfachNachricht mail) { @@ -109,10 +110,10 @@ class PostfachService { } public void resendMail(String commandId, String postfachMailId) { - PostfachNachricht mail = mapper.fromMapToPostfachMail(persistingService.getById(postfachMailId)); + PostfachNachricht nachricht = mapper.fromMapToPostfachMail(persistingService.getById(postfachMailId)); - var sendResponse = handleSendMail(commandId, mail); - patchMail(mail.getId(), createResendPatchMap(sendResponse)); + var sendResponse = handleSendMail(commandId, nachricht); + patchMail(nachricht.getId(), createResendPatchMap(sendResponse)); } SendPostfachNachrichtResponse handleSendMail(String commandId, PostfachNachricht mail) { @@ -120,33 +121,33 @@ class PostfachService { doSendMail(mail); publishMailSentEvent(commandId); - return buildSendNachrichtResponse(true, OsiPostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE); - } catch (OsiPostfachServerProcessException e) { + return buildSendNachrichtResponse(true, PostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE); + } catch (PostfachServerProcessException e) { return proceedwithWarnException(commandId, e); - } catch (OsiPostfachException e) { + } catch (PostfachException e) { return proceedWithErrorException(commandId, e); } } - SendPostfachNachrichtResponse proceedwithWarnException(String commandId, OsiPostfachServerProcessException e) { + SendPostfachNachrichtResponse proceedwithWarnException(String commandId, PostfachServerProcessException e) { LOG.warn(e.getMessage(), e); return proceedWithException(commandId, e); } - SendPostfachNachrichtResponse proceedWithErrorException(String commandId, OsiPostfachException e) { + SendPostfachNachrichtResponse proceedWithErrorException(String commandId, PostfachException e) { LOG.error(e.getMessage(), e); return proceedWithException(commandId, e); } - private SendPostfachNachrichtResponse proceedWithException(String commandId, OsiPostfachException e) { + private SendPostfachNachrichtResponse proceedWithException(String commandId, PostfachException e) { publishMailSentFailedEvent(commandId, e.getMessage()); return buildSendNachrichtResponse(false, e.getMessageCode()); } - void doSendMail(PostfachNachricht mail) { - osiPostfachService.sendMessage(mapper.toOsiMessage(mail)); + void doSendMail(PostfachNachricht nachricht) { + postfachRemoteService.sendMessage(nachricht); } private void publishMailSentEvent(String commandId) { @@ -157,7 +158,7 @@ class PostfachService { publisher.publishEvent(new PostfachMailSentFailedEvent(commandId, message)); } - private SendPostfachNachrichtResponse buildSendNachrichtResponse(boolean sentSuccesful, OsiPostfachMessageCode messageCode) { + private SendPostfachNachrichtResponse buildSendNachrichtResponse(boolean sentSuccesful, PostfachMessageCode messageCode) { return SendPostfachNachrichtResponse.builder().sentSuccessful(sentSuccesful).messageCode(messageCode).build(); } @@ -172,7 +173,7 @@ class PostfachService { } public boolean isPostfachConfigured() { - return osiPostfachService.isConfigured(); + return postfachRemoteService != null; } } \ No newline at end of file diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/ReplyOption.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/ReplyOption.java new file mode 100644 index 0000000000000000000000000000000000000000..e719cdbfeea7959b15d3b727e25d4193b1af7786 --- /dev/null +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/ReplyOption.java @@ -0,0 +1,17 @@ +package de.itvsh.ozg.mail.postfach; + +import com.fasterxml.jackson.annotation.JsonValue; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum ReplyOption { + POSSIBLE(0), MANDATORY(1), FORBIDDEN(2); + + private final int numValue; + + @JsonValue + public int toValue() { + return numValue; + } +} \ No newline at end of file diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/SendPostfachNachrichtResponse.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/SendPostfachNachrichtResponse.java index 24e60ff11f7eb78aef73f89f3d2231b15d837665..3ef8121462aff75501f5147697043c8d720f947d 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/SendPostfachNachrichtResponse.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/SendPostfachNachrichtResponse.java @@ -32,5 +32,5 @@ import lombok.Getter; @AllArgsConstructor class SendPostfachNachrichtResponse { private boolean sentSuccessful; - private OsiPostfachMessageCode messageCode; + private PostfachMessageCode messageCode; } \ No newline at end of file diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/bayernid/BayernIdPostfachRemoteService.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/bayernid/BayernIdPostfachRemoteService.java index ec6f92ba68768a0ee7db861f4253d47df2743cad..bae487f75948f1351a3d046b0ab78817e579ef9d 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/bayernid/BayernIdPostfachRemoteService.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/bayernid/BayernIdPostfachRemoteService.java @@ -3,12 +3,20 @@ package de.itvsh.ozg.mail.postfach.bayernid; import java.util.stream.Stream; import org.apache.commons.lang3.NotImplementedException; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Service; import de.itvsh.ozg.mail.postfach.PostfachNachricht; import de.itvsh.ozg.mail.postfach.PostfachRemoteService; +import lombok.extern.log4j.Log4j2; +@Service +@Log4j2 +@ConditionalOnProperty(prefix = "ozgcloud.bayernid", name = { "server" }) public class BayernIdPostfachRemoteService implements PostfachRemoteService { + private static final String POSTFACH_IDENTIFIER = "BayernID"; + @Override public void sendMessage(PostfachNachricht nachricht) { throw new NotImplementedException("Not yet implemented."); @@ -18,4 +26,9 @@ public class BayernIdPostfachRemoteService implements PostfachRemoteService { public Stream<PostfachNachricht> getAllMessages() { throw new NotImplementedException("Not yet implemented."); } + + @Override + public void deleteMessage(String messageId) { + throw new NotImplementedException("Not implemented."); + } } diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/Message.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/Message.java similarity index 89% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/Message.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/Message.java index 005db62121feded0b856e211ad66bb0ffb700ea3..3fed3563f4d2571e3fa6fe9da0353126cf5b5ce5 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/Message.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/Message.java @@ -21,13 +21,15 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; +import de.itvsh.ozg.mail.postfach.MessageAttachment; +import de.itvsh.ozg.mail.postfach.ReplyOption; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -42,19 +44,7 @@ import lombok.ToString; @AllArgsConstructor @ToString @Builder -class Message { - - @RequiredArgsConstructor - public enum ReplyOption { - POSSIBLE(0), MANDATORY(1), FORBIDDEN(2); - - private final int numValue; - - @JsonValue - public int toValue() { - return numValue; - } - } +public class Message { @RequiredArgsConstructor public enum EidasLevel { diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/MockOsiPostfachConfiguration.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/MockOsiPostfachConfiguration.java similarity index 97% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/MockOsiPostfachConfiguration.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/MockOsiPostfachConfiguration.java index 08e8d325f4b1a97380698c87fb219c318bab6018..cc7bb41485fb2717fd9f221ad1d7adabb76a0ce4 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/MockOsiPostfachConfiguration.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/MockOsiPostfachConfiguration.java @@ -21,7 +21,7 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/MockOsiPostfachRestTemplate.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/MockOsiPostfachRestTemplate.java similarity index 97% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/MockOsiPostfachRestTemplate.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/MockOsiPostfachRestTemplate.java index 1f6e9ed356e2b71dfb454e179e386f1b59e317bf..7f2c0b57890eeb93e069b1ebc0173229ef5f1b85 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/MockOsiPostfachRestTemplate.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/MockOsiPostfachRestTemplate.java @@ -21,7 +21,7 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachMessageMapper.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachMessageMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..c8e7c43c68c943417ae29065d28d7b94edffd265 --- /dev/null +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachMessageMapper.java @@ -0,0 +1,72 @@ +package de.itvsh.ozg.mail.postfach.osi; + +import java.util.List; +import java.util.Optional; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.springframework.beans.factory.annotation.Autowired; + +import de.itvsh.ozg.mail.postfach.AttachmentService; +import de.itvsh.ozg.mail.postfach.FileId; +import de.itvsh.ozg.mail.postfach.MessageAttachment; +import de.itvsh.ozg.mail.postfach.PostfachAddress; +import de.itvsh.ozg.mail.postfach.PostfachNachricht; +import de.itvsh.ozg.mail.postfach.StringBasedIdentifier; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.WARN) +public abstract class OsiPostfachMessageMapper { + + private static final String POSTFACH_ADDRESS_VERSION = "1.0"; + private static final int POSTFACH_ADDRESS_TYPE = 1; + + @Autowired + private AttachmentService attachmentService; + + @Mapping(target = "isHtml", constant = "false") + @Mapping(target = "rechtsverbindlich", constant = "false") + @Mapping(target = "eidasLevel", constant = "MEDIUM") + @Mapping(target = "postfachId", expression = "java(toPostfachId(nachricht))") + public abstract Message toOsiMessage(PostfachNachricht nachricht); + + @Mapping(target = "createdBy", ignore = true) + @Mapping(target = "id", ignore = true) + @Mapping(target = "messageCode", ignore = true) + @Mapping(target = "sentAt", ignore = true) + @Mapping(target = "sentSuccessful", ignore = true) + @Mapping(target = "createdAt", expression = "java(java.time.ZonedDateTime.now())") + @Mapping(target = "direction", constant = "IN") + @Mapping(target = "attachments", expression = "java(persistAttachements(message.getVorgangId() ,message.getAttachments()))") + @Mapping(target = "postfachAddress", expression = "java(buildPostfachAddressByPostfachId(message.getPostfachId()))") + public abstract PostfachNachricht toPostfachNachricht(Message message); + + List<MessageAttachment> map(List<String> attachedFileIds) { + return attachedFileIds.stream().map(FileId::from).map(fileId -> attachmentService.getMessageAttachment(fileId)).toList(); + } + + List<String> persistAttachements(String vorgangId, List<MessageAttachment> attachments) { + return attachments.stream().map(attachment -> attachmentService.persistAttachment(vorgangId, attachment)).toList(); + } + + @Mapping(target = "attachment", ignore = true) + @Mapping(target = "messageId", ignore = true) + String toPostfachId(PostfachNachricht nachricht) { + return Optional.ofNullable(nachricht.getPostfachAddress()) + .map(PostfachAddress::getIdentifier) + .filter(StringBasedIdentifier.class::isInstance) + .map(StringBasedIdentifier.class::cast) + .map(StringBasedIdentifier::getPostfachId) + .orElse(nachricht.getPostfachId()); + } + + PostfachAddress buildPostfachAddressByPostfachId(String postfachId) { + return PostfachAddress.builder() + .type(POSTFACH_ADDRESS_TYPE) + .version(POSTFACH_ADDRESS_VERSION) + .identifier(StringBasedIdentifier.builder().postfachId(postfachId).build()) + .build(); + + } + +} diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachProperties.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachProperties.java similarity index 89% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachProperties.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachProperties.java index 09e5a278ff52b22819bb679464c437053b3b3efb..49f99c0569bd8e6fc6847376a9393439de0029d1 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachProperties.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachProperties.java @@ -21,11 +21,14 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; + +import javax.validation.constraints.NotBlank; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import org.springframework.validation.annotation.Validated; import lombok.Getter; import lombok.Setter; @@ -34,13 +37,17 @@ import lombok.Setter; @Setter @Configuration @ConfigurationProperties(prefix = OsiPostfachProperties.PROXY_API_PREFIX) -class OsiPostfachProperties { +@Validated +public class OsiPostfachProperties { static final String PREFIX = "kop.osi.postfach"; static final String PROXY_API_PREFIX = PREFIX + ".proxyapi"; + @NotBlank private String url; + @NotBlank private String key; + @NotBlank private String realm; @Autowired diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachService.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachRemoteService.java similarity index 72% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachService.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachRemoteService.java index 92ef02eb3ef59754cf4593625d14839b7d611e65..838e1d171bfccdb71e66c4d2c40dce3e2b6c3112 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/OsiPostfachService.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachRemoteService.java @@ -21,7 +21,7 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; import java.util.Arrays; import java.util.Objects; @@ -32,6 +32,7 @@ import javax.annotation.PostConstruct; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; @@ -40,12 +41,23 @@ import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; +import de.itvsh.ozg.mail.postfach.NotConfiguredException; +import de.itvsh.ozg.mail.postfach.PostfachBadRequestException; +import de.itvsh.ozg.mail.postfach.PostfachNachricht; +import de.itvsh.ozg.mail.postfach.PostfachRemoteService; +import de.itvsh.ozg.mail.postfach.PostfachRuntimeException; +import de.itvsh.ozg.mail.postfach.PostfachServerProcessException; import lombok.extern.log4j.Log4j2; @Service @Log4j2 -class OsiPostfachService { +@ConditionalOnProperty(prefix = OsiPostfachProperties.PROXY_API_PREFIX, name = { "url", "key", "realm" }) +public class OsiPostfachRemoteService implements PostfachRemoteService { + private static final String POSTFACH_IDENTIFIER = "OSI"; + + @Autowired + private OsiPostfachMessageMapper mapper; @Autowired private OsiPostfachProperties properties; @Autowired(required = false) @@ -58,7 +70,20 @@ class OsiPostfachService { } } - public Stream<Message> getAllMessages() { + @Override + public void sendMessage(PostfachNachricht nachricht) { + checkWhetherIsConfigured(); + + HttpEntity<Message> request = new HttpEntity<>(mapper.toOsiMessage(nachricht)); + + var response = executeHandlingException( + () -> restTemplate.exchange(properties.getUrl(), HttpMethod.POST, request, String.class)); + + sentFailed(response); + } + + @Override + public Stream<PostfachNachricht> getAllMessages() { checkWhetherIsConfigured(); ResponseEntity<Message[]> response = executeHandlingException( @@ -68,23 +93,12 @@ class OsiPostfachService { LOG.warn("OSI Postfach response with an empty body"); return Stream.empty(); } - return Arrays.stream(response.getBody()); - } - - public void sendMessage(Message message) { - checkWhetherIsConfigured(); - - HttpEntity<Message> request = new HttpEntity<>(message); - - var response = executeHandlingException( - () -> restTemplate.exchange(properties.getUrl(), HttpMethod.POST, request, String.class)); - - sentFailed(response); + return Arrays.stream(response.getBody()).map(mapper::toPostfachNachricht); } private void sentFailed(ResponseEntity<String> response) { if (isSentFailed(response)) { - throw new OsiPostfachServerProcessException(); + throw new PostfachServerProcessException(POSTFACH_IDENTIFIER); } } @@ -92,6 +106,7 @@ class OsiPostfachService { return StringUtils.equals(response.getBody(), String.valueOf(false)); } + @Override public void deleteMessage(String messageId) { checkWhetherIsConfigured(); @@ -101,14 +116,10 @@ class OsiPostfachService { private void checkWhetherIsConfigured() { if (isNotConfigured()) { - throw new NotConfiguredException(); + throw new NotConfiguredException(POSTFACH_IDENTIFIER); } } - public boolean isConfigured() { - return !isNotConfigured(); - } - private boolean isNotConfigured() { return Objects.isNull(restTemplate) || Objects.isNull(properties.getUrl()) || Objects.isNull(properties.getKey()); } @@ -117,9 +128,9 @@ class OsiPostfachService { try { return runnable.get(); } catch (HttpClientErrorException e) { - throw new OsiPostfachBadRequestException(e); + throw new PostfachBadRequestException(POSTFACH_IDENTIFIER, e); } catch (RuntimeException e) { - throw new OsiPostfachRuntimeException(e); + throw new PostfachRuntimeException(POSTFACH_IDENTIFIER, e); } } } \ No newline at end of file diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachConfiguration.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/PostfachConfiguration.java similarity index 97% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachConfiguration.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/PostfachConfiguration.java index cf84089d1730df6ea025acfa06c4e67bfbee8d85..e86b93e99274c3cc02ff6cef200668e98b224d91 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachConfiguration.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/PostfachConfiguration.java @@ -21,7 +21,7 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; import java.util.Objects; @@ -83,8 +83,9 @@ public class PostfachConfiguration implements RestTemplateCustomizer { private CredentialsProvider buildCredentialsProvider(HttpHost proxyHost) { var proxyConfig = properties.getProxyConfiguration(); - if (!proxyConfig.isAuthenticationRequired()) + if (!proxyConfig.isAuthenticationRequired()) { return null; + } CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( diff --git a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachScheduler.java b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/PostfachScheduler.java similarity index 95% rename from mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachScheduler.java rename to mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/PostfachScheduler.java index 9ec80e6bad4161dc16baa6a32cde8d25d374d0df..df6c92c3369e28a076c73db36ff6bd8fccf9d3aa 100644 --- a/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/PostfachScheduler.java +++ b/mail-service/src/main/java/de/itvsh/ozg/mail/postfach/osi/PostfachScheduler.java @@ -21,7 +21,7 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -29,6 +29,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import de.itvsh.ozg.mail.postfach.PostfachService; import net.javacrumbs.shedlock.spring.annotation.SchedulerLock; @Component diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/AttachmentServiceTest.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/AttachmentServiceTest.java index 7cd2df66e30b1b0aa4bec866ae5cac71458ba47e..0c53f4f1305a1bf224feef32ef5c596c7cf530b6 100644 --- a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/AttachmentServiceTest.java +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/AttachmentServiceTest.java @@ -36,9 +36,7 @@ import java.time.Instant; import org.bson.BsonObjectId; import org.bson.BsonValue; import org.bson.Document; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.mockito.InjectMocks; import org.mockito.Mock; diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/GrpcPostfachMailTestFactory.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/GrpcPostfachMailTestFactory.java index a784d77f78062111f0838d525ef38b37b4dbcdc3..f8d19cf36abf6d2a3288d46f770ddf15437c5534 100644 --- a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/GrpcPostfachMailTestFactory.java +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/GrpcPostfachMailTestFactory.java @@ -23,8 +23,8 @@ */ package de.itvsh.ozg.mail.postfach; -import static de.itvsh.ozg.mail.postfach.MessageTestFactory.*; import static de.itvsh.ozg.mail.postfach.PostfachNachrichtTestFactory.*; +import static de.itvsh.ozg.mail.postfach.osi.MessageTestFactory.*; public class GrpcPostfachMailTestFactory { diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachAddressTestFactory.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachAddressTestFactory.java index 877f7e40d7b23d69a3d3a7db931ff367562e997e..61cb32fcfba33cc48e5b476b472c770b5c944927 100644 --- a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachAddressTestFactory.java +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachAddressTestFactory.java @@ -1,5 +1,7 @@ package de.itvsh.ozg.mail.postfach; +import de.itvsh.ozg.mail.postfach.osi.MessageTestFactory; + public class PostfachAddressTestFactory { public final static int TYPE = 1; diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachEventListenerTest.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachEventListenerTest.java index 6ec16a4ccad45d1cc8e1d21b6b275b0a38951f26..88240e3743e32704f8fbcf6b29cef5cb5ddf7ca1 100644 --- a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachEventListenerTest.java +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachEventListenerTest.java @@ -40,6 +40,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import de.itvsh.ozg.mail.postfach.PostfachNachricht.Direction; +import de.itvsh.ozg.mail.postfach.osi.MessageTestFactory; import de.itvsh.ozg.pluto.command.Command; import de.itvsh.ozg.pluto.command.CommandCreatedEvent; diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtMapperTest.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtMapperTest.java index 9313ae7ddf5039812ddb4cfc679d3b86ef961db7..00621ece923fed06078662770127e5dc88c622c4 100644 --- a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtMapperTest.java +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtMapperTest.java @@ -28,12 +28,12 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import java.time.ZonedDateTime; -import java.time.temporal.ChronoUnit; -import java.util.List; import java.util.Map; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.mapstruct.factory.Mappers; @@ -41,16 +41,13 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import de.itvsh.kop.pluto.common.grpc.GrpcObjectMapper; -import de.itvsh.ozg.mail.postfach.PostfachNachricht.Direction; import lombok.SneakyThrows; -class PostfachNachrichtMapperTest { +public class PostfachNachrichtMapperTest { @InjectMocks private PostfachNachrichtMapper mapper = Mappers.getMapper(PostfachNachrichtMapper.class); @Mock - private AttachmentService attachmentService; - @Mock private GrpcObjectMapper grpcObjectMapper; @DisplayName("From map") @@ -119,51 +116,6 @@ class PostfachNachrichtMapperTest { } } - @DisplayName("To mail") - @Nested - class TestToMail { - - @Test - void shouldSetDirection() { - var mail = mapper.toMail(MessageTestFactory.create()); - - assertThat(mail.getDirection()).isEqualTo(Direction.IN); - } - - @Test - void shouldSetCreatedAt() { - var mail = mapper.toMail(MessageTestFactory.create()); - - assertThat(mail.getCreatedAt()).isNotNull().isCloseTo(ZonedDateTime.now(), within(2, ChronoUnit.SECONDS)); - } - - @Test - void shouldIgnoreSentInformation() { - var mail = mapper.toMail(MessageTestFactory.create()); - - assertThat(mail.getSentAt()).isNull(); - assertThat(mail.getSentSuccessful()).isNull(); - } - - @Test - void shouldPersistAttachment() { - mapper.toMail(MessageTestFactory.create()); - - verify(attachmentService).persistAttachment(MessageTestFactory.VORGANG_ID, MessageTestFactory.ATTACHMENTS.get(0)); - } - - @Test - void shouldSetPostfachAddress() { - var mail = toMail(); - - assertThat(mail.getPostfachAddress()).usingRecursiveComparison().isEqualTo(PostfachAddressTestFactory.create()); - } - - private PostfachNachricht toMail() { - return mapper.toMail(MessageTestFactory.create()); - } - } - @DisplayName("From map to postfachMail") @Nested class TestFromMapToPostfachMail { @@ -206,85 +158,6 @@ class PostfachNachrichtMapperTest { } } - private Map<String, Object> getMapWithoutProperty(String entryKey) { - var map = PostfachNachrichtTestFactory.asMap(); - map.remove(entryKey); - return map; - } - - private Object getAttributeFromGrpcObject(Object obj, String name) { - return getAttributeFrom(obj, name + "_"); - } - - @SneakyThrows - private Object getAttributeFromObject(Object obj, String name) { - return getAttributeFrom(obj, name); - } - - @SneakyThrows - private Object getAttributeFrom(Object obj, String name) { - var clazz = obj.getClass(); - var field = clazz.getDeclaredField(name); - field.setAccessible(true); - - return field.get(obj); - } - - @DisplayName("To osi message") - @Nested - class TestToOsiMessage { - - @Test - void shouldCallAttachmentService() { - var fileId = FileId.from("42"); - - toOsiMessage(PostfachNachrichtTestFactory.createBuilder().attachments(List.of(fileId.toString())).build()); - - verify(attachmentService).getMessageAttachment(fileId); - } - - @Test - void shouldMapFields() { - var message = toOsiMessage(PostfachNachrichtTestFactory.create()); - - assertThat(message.getSubject()).isEqualTo(MessageTestFactory.SUBJECT); - assertThat(message.getAttachments()).hasSize(1); - } - - @DisplayName("build postfachId") - @Nested - class TestToPostfachId { - - @DisplayName("by existing postfachAddress") - @Nested - class TestWithExistingPostfachAddress { - - @Test - void shouldMapPostfachAddressToPostfachId() { - var message = toOsiMessage(PostfachNachrichtTestFactory.create()); - - assertThat(message.getPostfachId()).isEqualTo(PostfachAddressTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); - } - } - - @DisplayName("by postfachId if postfachAddress not exists") - @Nested - class TestWithoutPostfachAddress { - - @Test - void shouldMapPostfachAddressToPostfachId() { - var message = toOsiMessage(PostfachNachrichtTestFactory.createBuilder().postfachAddress(null).build()); - - assertThat(message.getPostfachId()).isEqualTo(MessageTestFactory.POSTFACH_ID); - } - } - } - - private Message toOsiMessage(PostfachNachricht postfachNachricht) { - return mapper.toOsiMessage(postfachNachricht); - } - } - @DisplayName("From grpc mail") @Nested class TestFromGrpcMail { @@ -309,4 +182,28 @@ class PostfachNachrichtMapperTest { return mapper.fromGrpcMail(postfachMail); } } -} \ No newline at end of file + + private Map<String, Object> getMapWithoutProperty(String entryKey) { + var map = PostfachNachrichtTestFactory.asMap(); + map.remove(entryKey); + return map; + } + + private Object getAttributeFromGrpcObject(Object obj, String name) { + return getAttributeFrom(obj, name + "_"); + } + + @SneakyThrows + private Object getAttributeFromObject(Object obj, String name) { + return getAttributeFrom(obj, name); + } + + @SneakyThrows + private Object getAttributeFrom(Object obj, String name) { + var clazz = obj.getClass(); + var field = clazz.getDeclaredField(name); + field.setAccessible(true); + + return field.get(obj); + } +} diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtTestFactory.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtTestFactory.java index 52637752d848f4882a4539e0d14242bf674be36f..3d4ee4c6b5d1eb8d2641f04e043eab749c011104 100644 --- a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtTestFactory.java +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachNachrichtTestFactory.java @@ -23,7 +23,7 @@ */ package de.itvsh.ozg.mail.postfach; -import static de.itvsh.ozg.mail.postfach.MessageTestFactory.*; +import static de.itvsh.ozg.mail.postfach.osi.MessageTestFactory.*; import java.time.ZonedDateTime; import java.util.HashMap; @@ -43,7 +43,7 @@ public class PostfachNachrichtTestFactory { public static final String SENT_AT_STR = "2020-04-01T11:30:10Z"; public static final ZonedDateTime SENT_AT = ZonedDateTime.parse(SENT_AT_STR); public static final boolean SENT_SUCCESSFUL = true; - public static final String MESSAGE_CODE = OsiPostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE.getMessageCode(); + public static final String MESSAGE_CODE = PostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE.getMessageCode(); public static final PostfachNachricht.Direction DIRECTION = Direction.IN; public static final List<String> ATTACHMENTS = List.of("21"); diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachServiceTest.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachServiceTest.java index 57a0dac22783a3022ea2a31f1e2d880b15ae4133..43a566139f1380cdec61b3fadac025a9e2d26335 100644 --- a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachServiceTest.java +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachServiceTest.java @@ -43,10 +43,10 @@ import org.mockito.Mock; import org.mockito.Spy; import org.springframework.boot.logging.LogLevel; import org.springframework.context.ApplicationEventPublisher; -import org.springframework.test.util.ReflectionTestUtils; import de.itvsh.ozg.mail.attributes.ClientAttributeService; import de.itvsh.ozg.mail.postfach.PostfachNachricht.Direction; +import de.itvsh.ozg.mail.postfach.osi.MessageTestFactory; import nl.altindag.log.LogCaptor; class PostfachServiceTest { @@ -55,7 +55,7 @@ class PostfachServiceTest { @InjectMocks private PostfachService service; @Mock - private OsiPostfachService osiPostfachService; + private PostfachRemoteService postfachRemoteService; @Mock private PersistPostfachNachrichtService persistingService; @@ -75,11 +75,6 @@ class PostfachServiceTest { @Nested class TestSendMail { - @BeforeEach - void init() { - ReflectionTestUtils.setField(mapper, "attachmentService", attachmentService); - } - @Test void shouldCallDoSendMail() { var mail = PostfachNachrichtTestFactory.create(); @@ -207,26 +202,18 @@ class PostfachServiceTest { @Nested class TestFetchAndPersistReplies { - private static final Message message = MessageTestFactory.create(); + private static final PostfachNachricht nachricht = PostfachNachrichtTestFactory.create(); @BeforeEach void initTest() { - when(osiPostfachService.getAllMessages()).thenReturn(Stream.of(message)); - ReflectionTestUtils.setField(mapper, "attachmentService", attachmentService); + when(postfachRemoteService.getAllMessages()).thenReturn(Stream.of(nachricht)); } @Test void shouldCallGetAllMessages() { service.fetchAndPersistReplies(); - verify(osiPostfachService).getAllMessages(); - } - - @Test - void shouldCallMapper() { - service.fetchAndPersistReplies(); - - verify(mapper).toMail(message); + verify(postfachRemoteService).getAllMessages(); } @Test @@ -240,7 +227,7 @@ class PostfachServiceTest { void shouldCallDelete() { service.fetchAndPersistReplies(); - verify(osiPostfachService).deleteMessage(MessageTestFactory.MESSAGE_ID); + verify(postfachRemoteService).deleteMessage(MessageTestFactory.MESSAGE_ID); } @Test @@ -299,7 +286,6 @@ class PostfachServiceTest { void mockService() { when(persistingService.getById(anyString())).thenReturn(PostfachNachrichtTestFactory.asMap()); doReturn(mail).when(mapper).fromMapToPostfachMail(anyMap()); - ReflectionTestUtils.setField(mapper, "attachmentService", attachmentService); } @Test @@ -320,14 +306,7 @@ class PostfachServiceTest { void shouldSendMail() { service.resendMail(COMMAND_ID, PostfachNachrichtTestFactory.ID); - verify(osiPostfachService).sendMessage(any(Message.class)); - } - - @Test - void shouldCallMapper() { - service.resendMail(COMMAND_ID, PostfachNachrichtTestFactory.ID); - - verify(mapper).toOsiMessage(mail); + verify(postfachRemoteService).sendMessage(any(PostfachNachricht.class)); } @Test @@ -380,11 +359,6 @@ class PostfachServiceTest { final String COMMAND_ID = UUID.randomUUID().toString(); final PostfachNachricht mail = PostfachNachrichtTestFactory.create(); - @BeforeEach - void initTest() { - ReflectionTestUtils.setField(mapper, "attachmentService", attachmentService); - } - @Test void shouldDoSendMail() { service.handleSendMail(COMMAND_ID, mail); @@ -418,7 +392,7 @@ class PostfachServiceTest { var response = service.handleSendMail(COMMAND_ID, mail); assertThat(response.isSentSuccessful()).isTrue(); - assertThat(response.getMessageCode()).isEqualTo(OsiPostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE); + assertThat(response.getMessageCode()).isEqualTo(PostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE); } } @@ -437,7 +411,7 @@ class PostfachServiceTest { @BeforeEach void mockService() { - doThrow(new OsiPostfachException(MESSAGE, OsiPostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE)).when(osiPostfachService) + doThrow(new PostfachException(MESSAGE, PostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE)).when(postfachRemoteService) .sendMessage(any()); } @@ -456,7 +430,7 @@ class PostfachServiceTest { service.handleSendMail(COMMAND_ID, mail); - verify(service).proceedWithErrorException(eq(COMMAND_ID), any(OsiPostfachException.class)); + verify(service).proceedWithErrorException(eq(COMMAND_ID), any(PostfachException.class)); assertThat(logCaptor.getLogEvents().get(0).getLevel()).isEqualTo(LogLevel.ERROR.name()); assertThat(logCaptor.getLogEvents().get(0).getMessage()).isEqualTo(MESSAGE); } @@ -466,7 +440,7 @@ class PostfachServiceTest { var response = service.handleSendMail(COMMAND_ID, mail); assertThat(response.isSentSuccessful()).isFalse(); - assertThat(response.getMessageCode()).isEqualTo(OsiPostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE); + assertThat(response.getMessageCode()).isEqualTo(PostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE); } } @@ -474,14 +448,14 @@ class PostfachServiceTest { @Nested class TestOsiPostfachServerProcessException { - private final static String MESSAGE = "Osi-Postfach server returned false"; + private final static String MESSAGE = "OSI Postfach server returned false"; @Mock private Logger logger; @BeforeEach void mockService() { - doThrow(new OsiPostfachServerProcessException()).when(osiPostfachService).sendMessage(any()); + doThrow(new PostfachServerProcessException("OSI")).when(postfachRemoteService).sendMessage(any()); } @Test @@ -499,7 +473,7 @@ class PostfachServiceTest { service.handleSendMail(COMMAND_ID, mail); - verify(service).proceedwithWarnException(eq(COMMAND_ID), any(OsiPostfachServerProcessException.class)); + verify(service).proceedwithWarnException(eq(COMMAND_ID), any(PostfachServerProcessException.class)); assertThat(logCaptor.getLogEvents().get(0).getLevel()).isEqualTo(LogLevel.WARN.name()); assertThat(logCaptor.getLogEvents().get(0).getMessage()).isEqualTo(MESSAGE); } @@ -509,7 +483,7 @@ class PostfachServiceTest { var response = service.handleSendMail(COMMAND_ID, mail); assertThat(response.isSentSuccessful()).isFalse(); - assertThat(response.getMessageCode()).isEqualTo(OsiPostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE); + assertThat(response.getMessageCode()).isEqualTo(PostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE); } } } @@ -518,35 +492,11 @@ class PostfachServiceTest { @Nested class TestDoSendMail { - @Captor - private ArgumentCaptor<Message> messageCaptor; - - @BeforeEach - void initTest() { - ReflectionTestUtils.setField(mapper, "attachmentService", attachmentService); - when(attachmentService.getMessageAttachment(any())).thenReturn(MessageAttachmentTestFactory.create()); - } - @Test - void shouldCallOsiPostfachService() { + void shouldCallPostfachRemoteService() { service.doSendMail(PostfachNachrichtTestFactory.create()); - verify(osiPostfachService).sendMessage(any()); - } - - @Test - void shouldSendFilledMessage() { - var expected = MessageTestFactory.createBuilder() - .messageId(null) - .vorgangId(MessageTestFactory.VORGANG_ID) - .rechtsverbindlich(false) - .build(); - - service.doSendMail(PostfachNachrichtTestFactory.create()); - - verify(osiPostfachService).sendMessage(messageCaptor.capture()); - assertThat(messageCaptor.getValue()).usingRecursiveComparison().isEqualTo(expected); - + verify(postfachRemoteService).sendMessage(any()); } } @@ -554,10 +504,8 @@ class PostfachServiceTest { class TestIsPostfachConfigured { @Test - void shouldCallOsiPostfachService() { - service.isPostfachConfigured(); - - verify(osiPostfachService).isConfigured(); + void shouldReturnTrue() { + assertThat(service.isPostfachConfigured()).isTrue(); } } } \ No newline at end of file diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/SendPostfachNachrichtResponseTestFactory.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/SendPostfachNachrichtResponseTestFactory.java index 9ec6483a3c59fee6ac796c816d87ee4407c83c09..f475a26c68b98926195968e7f80e20e9cdd9d354 100644 --- a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/SendPostfachNachrichtResponseTestFactory.java +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/SendPostfachNachrichtResponseTestFactory.java @@ -26,7 +26,7 @@ package de.itvsh.ozg.mail.postfach; public class SendPostfachNachrichtResponseTestFactory { public static final boolean SENT_SUCCESSFUL = true; - public static final OsiPostfachMessageCode MESSAGE_CODE = OsiPostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE; + public static final PostfachMessageCode MESSAGE_CODE = PostfachMessageCode.SEND_SUCCESSFUL_MESSAGE_CODE; public static SendPostfachNachrichtResponse create() { return createBuilder().build(); diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/MessageTestFactory.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/MessageTestFactory.java similarity index 89% rename from mail-service/src/test/java/de/itvsh/ozg/mail/postfach/MessageTestFactory.java rename to mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/MessageTestFactory.java index 25077cd084eb14b40bb4654146518182cb33c6cd..109042c8370d8b36fb332906127d6b597330c279 100644 --- a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/MessageTestFactory.java +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/MessageTestFactory.java @@ -21,13 +21,15 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; import java.util.List; import java.util.UUID; -import de.itvsh.ozg.mail.postfach.Message.EidasLevel; -import de.itvsh.ozg.mail.postfach.Message.ReplyOption; +import de.itvsh.ozg.mail.postfach.MessageAttachment; +import de.itvsh.ozg.mail.postfach.MessageAttachmentTestFactory; +import de.itvsh.ozg.mail.postfach.ReplyOption; +import de.itvsh.ozg.mail.postfach.osi.Message.EidasLevel; public class MessageTestFactory { diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachNachrichtMapperTest.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachNachrichtMapperTest.java new file mode 100644 index 0000000000000000000000000000000000000000..b52d1468eab673e5330a4b2fbb3d088c27f49097 --- /dev/null +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachNachrichtMapperTest.java @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den + * Ministerpräsidenten des Landes Schleswig-Holstein + * Staatskanzlei + * Abteilung Digitalisierung und zentrales IT-Management der Landesregierung + * + * Lizenziert unter der EUPL, Version 1.2 oder - sobald + * diese von der Europäischen Kommission genehmigt wurden - + * Folgeversionen der EUPL ("Lizenz"); + * Sie dürfen dieses Werk ausschließlich gemäß + * dieser Lizenz nutzen. + * Eine Kopie der Lizenz finden Sie hier: + * + * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 + * + * Sofern nicht durch anwendbare Rechtsvorschriften + * gefordert oder in schriftlicher Form vereinbart, wird + * die unter der Lizenz verbreitete Software "so wie sie + * ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - + * ausdrücklich oder stillschweigend - verbreitet. + * Die sprachspezifischen Genehmigungen und Beschränkungen + * unter der Lizenz sind dem Lizenztext zu entnehmen. + */ +package de.itvsh.ozg.mail.postfach.osi; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; +import java.util.List; + +import org.junit.jupiter.api.*; +import org.mapstruct.factory.Mappers; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +import de.itvsh.kop.pluto.common.grpc.GrpcObjectMapper; +import de.itvsh.ozg.mail.postfach.AttachmentService; +import de.itvsh.ozg.mail.postfach.FileId; +import de.itvsh.ozg.mail.postfach.PostfachAddressTestFactory; +import de.itvsh.ozg.mail.postfach.PostfachNachricht; +import de.itvsh.ozg.mail.postfach.PostfachNachricht.Direction; +import de.itvsh.ozg.mail.postfach.PostfachNachrichtTestFactory; + +class OsiPostfachNachrichtMapperTest { + + @InjectMocks + private OsiPostfachMessageMapper mapper = Mappers.getMapper(OsiPostfachMessageMapper.class); + @Mock + private AttachmentService attachmentService; + @Mock + private GrpcObjectMapper grpcObjectMapper; + + @DisplayName("To mail") + @Nested + class TestToMail { + + @Test + void shouldSetDirection() { + var mail = mapper.toPostfachNachricht(MessageTestFactory.create()); + + assertThat(mail.getDirection()).isEqualTo(Direction.IN); + } + + @Test + void shouldSetCreatedAt() { + var mail = mapper.toPostfachNachricht(MessageTestFactory.create()); + + assertThat(mail.getCreatedAt()).isNotNull().isCloseTo(ZonedDateTime.now(), within(2, ChronoUnit.SECONDS)); + } + + @Test + void shouldIgnoreSentInformation() { + var mail = mapper.toPostfachNachricht(MessageTestFactory.create()); + + assertThat(mail.getSentAt()).isNull(); + assertThat(mail.getSentSuccessful()).isNull(); + } + + @Test + void shouldPersistAttachment() { + mapper.toPostfachNachricht(MessageTestFactory.create()); + + verify(attachmentService).persistAttachment(MessageTestFactory.VORGANG_ID, MessageTestFactory.ATTACHMENTS.get(0)); + } + + @Test + void shouldSetPostfachAddress() { + var mail = toMail(); + + assertThat(mail.getPostfachAddress()).usingRecursiveComparison().isEqualTo(PostfachAddressTestFactory.create()); + } + + private PostfachNachricht toMail() { + return mapper.toPostfachNachricht(MessageTestFactory.create()); + } + } + + @DisplayName("To osi message") + @Nested + class TestToOsiMessage { + + @Test + void shouldCallAttachmentService() { + var fileId = FileId.from("42"); + + toOsiMessage(PostfachNachrichtTestFactory.createBuilder().attachments(List.of(fileId.toString())).build()); + + verify(attachmentService).getMessageAttachment(fileId); + } + + @Test + void shouldMapFields() { + var message = toOsiMessage(PostfachNachrichtTestFactory.create()); + + assertThat(message.getSubject()).isEqualTo(MessageTestFactory.SUBJECT); + assertThat(message.getAttachments()).hasSize(1); + } + + @DisplayName("build postfachId") + @Nested + class TestToPostfachId { + + @DisplayName("by existing postfachAddress") + @Nested + class TestWithExistingPostfachAddress { + + @Test + void shouldMapPostfachAddressToPostfachId() { + var message = toOsiMessage(PostfachNachrichtTestFactory.create()); + + assertThat(message.getPostfachId()).isEqualTo(PostfachAddressTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); + } + } + + @DisplayName("by postfachId if postfachAddress not exists") + @Nested + class TestWithoutPostfachAddress { + + @Test + void shouldMapPostfachAddressToPostfachId() { + var message = toOsiMessage(PostfachNachrichtTestFactory.createBuilder().postfachAddress(null).build()); + + assertThat(message.getPostfachId()).isEqualTo(MessageTestFactory.POSTFACH_ID); + } + } + } + + private Message toOsiMessage(PostfachNachricht postfachNachricht) { + return mapper.toOsiMessage(postfachNachricht); + } + } +} \ No newline at end of file diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/OsiPostfachServiceTest.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachRemoteServiceTest.java similarity index 72% rename from mail-service/src/test/java/de/itvsh/ozg/mail/postfach/OsiPostfachServiceTest.java rename to mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachRemoteServiceTest.java index 7d82d4f554e79aa9663788c0f16d387ce1f39194..1ef22d828326ff4f8160edd20126b4bcb740119e 100644 --- a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/OsiPostfachServiceTest.java +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachRemoteServiceTest.java @@ -21,27 +21,22 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; -import static de.itvsh.ozg.mail.postfach.MessageTestFactory.*; +import static de.itvsh.ozg.mail.postfach.osi.MessageTestFactory.*; import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; import static org.springframework.test.web.client.match.MockRestRequestMatchers.*; import static org.springframework.test.web.client.response.MockRestResponseCreators.*; -import java.util.List; +import java.util.stream.Collectors; -import org.assertj.core.api.InstanceOfAssertFactories; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; +import org.assertj.core.api.*; +import org.junit.jupiter.api.*; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -51,7 +46,16 @@ import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.test.web.client.ResponseActions; import org.springframework.web.client.RestTemplate; -class OsiPostfachServiceTest { +import de.itvsh.ozg.mail.postfach.AttachmentService; +import de.itvsh.ozg.mail.postfach.MessageAttachment; +import de.itvsh.ozg.mail.postfach.MessageAttachmentTestFactory; +import de.itvsh.ozg.mail.postfach.NotConfiguredException; +import de.itvsh.ozg.mail.postfach.PostfachBadRequestException; +import de.itvsh.ozg.mail.postfach.PostfachNachricht; +import de.itvsh.ozg.mail.postfach.PostfachNachrichtTestFactory; +import de.itvsh.ozg.mail.postfach.PostfachServerProcessException; + +public class OsiPostfachRemoteServiceTest { public static final String HEADER_API_KEY = "apikey"; public static final String HEADER_API_REALM = "realm"; @@ -78,15 +82,19 @@ class OsiPostfachServiceTest { }]"""; @InjectMocks - private OsiPostfachService service; + private OsiPostfachRemoteService service; @Mock private AttachmentService attachmentService; + @Mock + private OsiPostfachMessageMapper mapper; + @Spy private RestTemplate restTemplate; @Spy private OsiPostfachProperties properties = new OsiPostfachProperties(); + { properties.setUrl(TEST_URL); properties.setRealm(TEST_API_REALM); @@ -117,9 +125,11 @@ class OsiPostfachServiceTest { @Test void shouldFillMessage() { + when(mapper.toPostfachNachricht(any())).thenReturn(PostfachNachrichtTestFactory.create()); + var messages = service.getAllMessages(); - assertThat(messages).hasSize(1).first().usingRecursiveComparison().isEqualTo(MessageTestFactory.create()); + assertThat(messages).hasSize(1).first().usingRecursiveComparison().isEqualTo(PostfachNachrichtTestFactory.create()); } @Test @@ -131,10 +141,21 @@ class OsiPostfachServiceTest { @Test void shouldHaveAttachment() { + when(mapper.toPostfachNachricht(any())).thenReturn(PostfachNachrichtTestFactory.create()); + var messages = service.getAllMessages(); - assertThat(messages).hasSize(1).first().extracting(Message::getAttachments, InstanceOfAssertFactories.LIST).hasSize(1) - .usingRecursiveComparison().isEqualTo(List.of(MessageAttachmentTestFactory.create())); + assertThat(messages).hasSize(1).first().extracting(PostfachNachricht::getAttachments, InstanceOfAssertFactories.LIST).hasSize(1) + .usingRecursiveComparison().isEqualTo(PostfachNachrichtTestFactory.ATTACHMENTS); + } + + @Test + void shouldCallMapper() { + prepareMockServer(); + + service.getAllMessages().collect(Collectors.toList()); + + verify(mapper).toPostfachNachricht(any()); } private void prepareMockServer() { @@ -148,10 +169,7 @@ class OsiPostfachServiceTest { @Nested class TestSendMessage { - @Captor - private ArgumentCaptor<HttpEntity<Message>> httpEntityCaptor; - - private Message message = MessageTestFactory.create(); + private PostfachNachricht message = PostfachNachrichtTestFactory.create(); @Test void shouldCallRestTemplateExchange() { @@ -191,7 +209,16 @@ class OsiPostfachServiceTest { void shouldThrowBadRequestExceptionOnHttpClientError() { prepareMockServer().andRespond(withStatus(HttpStatus.BAD_REQUEST)); - assertThrows(OsiPostfachBadRequestException.class, () -> service.sendMessage(message)); + assertThrows(PostfachBadRequestException.class, () -> service.sendMessage(message)); + } + + @Test + void shouldCallMapper() { + prepareMockServer(); + + service.sendMessage(message); + + verify(mapper).toOsiMessage(any()); } @Nested @@ -201,7 +228,7 @@ class OsiPostfachServiceTest { void shouldThrowServerProcessExceptionOnResponseBodyFalse() { prepareMockServerWithResponseBody(false); - assertThrows(OsiPostfachServerProcessException.class, () -> service.sendMessage(message)); + assertThrows(PostfachServerProcessException.class, () -> service.sendMessage(message)); mockServer.verify(); } @@ -219,37 +246,47 @@ class OsiPostfachServiceTest { @Test void shouldHaveVorgangIdAsSequenceNumber() { + when(mapper.toOsiMessage(any())).thenReturn(MessageTestFactory.create()); + prepareMockServer().andExpect(jsonPath("$.sequenceNumber").value(VORGANG_ID)); - service.sendMessage(MessageTestFactory.create()); + service.sendMessage(PostfachNachrichtTestFactory.create()); } @Test void shouldHavePostfachIdAsNameIdentifier() { + when(mapper.toOsiMessage(any())).thenReturn(MessageTestFactory.create()); + prepareMockServer().andExpect(jsonPath("$.nameIdentifier").value(POSTFACH_ID)); - service.sendMessage(MessageTestFactory.create()); + service.sendMessage(PostfachNachrichtTestFactory.create()); } @Test void shouldHaveSubject() { + when(mapper.toOsiMessage(any())).thenReturn(MessageTestFactory.create()); + prepareMockServer().andExpect(jsonPath("$.subject").value(SUBJECT)); - service.sendMessage(MessageTestFactory.create()); + service.sendMessage(PostfachNachrichtTestFactory.create()); } @Test void shouldHaveMailBodyAsBody() { + when(mapper.toOsiMessage(any())).thenReturn(MessageTestFactory.create()); + prepareMockServer().andExpect(jsonPath("$.body").value(MAIL_BODY)); - service.sendMessage(MessageTestFactory.create()); + service.sendMessage(PostfachNachrichtTestFactory.create()); } @Test void shouldHaveNumericReplyOptionAsReplyAction() { + when(mapper.toOsiMessage(any())).thenReturn(MessageTestFactory.create()); + prepareMockServer().andExpect(jsonPath("$.replyAction").value(REPLY_OPTION.toValue())); - service.sendMessage(MessageTestFactory.create()); + service.sendMessage(PostfachNachrichtTestFactory.create()); } } @@ -292,11 +329,11 @@ class OsiPostfachServiceTest { } } - static String buildReplyJson() { + public static String buildReplyJson() { return buildReplyJson(MessageTestFactory.create(), MessageAttachmentTestFactory.create()); } - static String buildReplyJson(Message msg, MessageAttachment attachement) { + public static String buildReplyJson(Message msg, MessageAttachment attachement) { return String.format(REPLY_JSON_TMPL, msg.getMessageId(), msg.getPostfachId(), diff --git a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachSchedulerTest.java b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/PostfachSchedulerTest.java similarity index 91% rename from mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachSchedulerTest.java rename to mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/PostfachSchedulerTest.java index 7aba40a44505daee3cd78a119eb373a96a9e9ce8..664e3231d995967d3f1deb275d3c3b3f2af76c3b 100644 --- a/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/PostfachSchedulerTest.java +++ b/mail-service/src/test/java/de/itvsh/ozg/mail/postfach/osi/PostfachSchedulerTest.java @@ -21,15 +21,16 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; import static org.mockito.Mockito.*; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.mockito.InjectMocks; import org.mockito.Mock; +import de.itvsh.ozg.mail.postfach.PostfachService; + public class PostfachSchedulerTest { @InjectMocks // NOSONAR diff --git a/pluto-interface/pom.xml b/pluto-interface/pom.xml index 25857af034ee9d7ee9d15fa436ed475c6c959669..cca7adac859e9d633968525eaf43cf8883f442d3 100644 --- a/pluto-interface/pom.xml +++ b/pluto-interface/pom.xml @@ -24,14 +24,16 @@ unter der Lizenz sind dem Lizenztext zu entnehmen. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>de.itvsh.kop.common</groupId> <artifactId>kop-common-dependencies</artifactId> <version>1.5.0</version> - <relativePath /> + <relativePath/> </parent> <groupId>de.itvsh.ozg.pluto</groupId> diff --git a/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/PostfachMailITCase.java b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/PostfachMailITCase.java index e1059a0e12a0ad8bb298665225df9ed61e2f68aa..7a52b898ab311ff805b102a39db9fcbd2cd21c77 100644 --- a/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/PostfachMailITCase.java +++ b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/PostfachMailITCase.java @@ -33,9 +33,8 @@ import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.*; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -52,6 +51,9 @@ import org.springframework.web.client.RestTemplate; import de.itvsh.kop.common.test.DataITCase; import de.itvsh.ozg.mail.attributes.ClientAttributeService; +import de.itvsh.ozg.mail.postfach.osi.MessageTestFactory; +import de.itvsh.ozg.mail.postfach.osi.OsiPostfachProperties; +import de.itvsh.ozg.mail.postfach.osi.OsiPostfachRemoteServiceTest; import de.itvsh.ozg.pluto.PlutoServerApplication; import de.itvsh.ozg.pluto.attached_item.VorgangAttachedItem; import de.itvsh.ozg.pluto.common.security.PolicyService; @@ -127,12 +129,12 @@ class PostfachMailITCase { callGrpcEndpoint(); var mails = callGrpcListEndpoint(); - assertThat(mails).hasSize(1); - assertThat(mails.get(0).getCreatedAt()).isNotNull(); - assertThat(mails.get(0).getDirection()).isEqualTo(GrpcDirection.OUT); - assertThat(mails.get(0).getSentAt()).isNotNull(); + Assertions.assertThat(mails).hasSize(1); + Assertions.assertThat(mails.get(0).getCreatedAt()).isNotNull(); + Assertions.assertThat(mails.get(0).getDirection()).isEqualTo(GrpcDirection.OUT); + Assertions.assertThat(mails.get(0).getSentAt()).isNotNull(); assertThat(ZonedDateTime.parse(mails.get(0).getSentAt())).isCloseTo(ZonedDateTime.now(), within(2, ChronoUnit.SECONDS)); - assertThat(mails.get(0).getSentSuccessful()).isTrue(); + Assertions.assertThat(mails.get(0).getSentSuccessful()).isTrue(); } } @@ -146,10 +148,10 @@ class PostfachMailITCase { callGrpcEndpoint(); var mails = callGrpcListEndpoint(); - assertThat(mails).hasSize(1); - assertThat(mails.get(0).getSentAt()).isNotNull(); + Assertions.assertThat(mails).hasSize(1); + Assertions.assertThat(mails.get(0).getSentAt()).isNotNull(); assertThat(ZonedDateTime.parse(mails.get(0).getSentAt())).isCloseTo(ZonedDateTime.now(), within(2, ChronoUnit.SECONDS)); - assertThat(mails.get(0).getSentSuccessful()).isFalse(); + Assertions.assertThat(mails.get(0).getSentSuccessful()).isFalse(); } @Test @@ -164,7 +166,7 @@ class PostfachMailITCase { callResendGrpcEndpoint(mailId); mails = callGrpcListEndpoint(); - assertThat(mails.get(0).getSentSuccessful()).isTrue(); + Assertions.assertThat(mails.get(0).getSentSuccessful()).isTrue(); } @Test @@ -179,8 +181,8 @@ class PostfachMailITCase { callResendGrpcEndpoint(mailId); mails = callGrpcListEndpoint(); - assertThat(mails.get(0).getSentSuccessful()).isFalse(); - assertThat(mails.get(0).getMessageCode()).isEqualTo(OsiPostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE.getMessageCode()); + Assertions.assertThat(mails.get(0).getSentSuccessful()).isFalse(); + Assertions.assertThat(mails.get(0).getMessageCode()).isEqualTo(PostfachMessageCode.PROCESS_FAILED_MESSAGE_CODE.getMessageCode()); } } @@ -233,34 +235,34 @@ class PostfachMailITCase { @Test void shouldListNachrichten() { - mockServerReceiveReply(OsiPostfachServiceTest.buildReplyJson()); + mockServerReceiveReply(OsiPostfachRemoteServiceTest.buildReplyJson()); service.fetchAndPersistReplies(); var mails = callGrpcListEndpoint(); - assertThat(mails).hasSize(1); - assertThat(mails.get(0).getCreatedAt()).isNotNull(); - assertThat(mails.get(0).getDirection()).isEqualTo(GrpcDirection.IN); + Assertions.assertThat(mails).hasSize(1); + Assertions.assertThat(mails.get(0).getCreatedAt()).isNotNull(); + Assertions.assertThat(mails.get(0).getDirection()).isEqualTo(GrpcDirection.IN); mockServer.verify(); } @Test void shouldContainAttachment() { - mockServerReceiveReply(OsiPostfachServiceTest.buildReplyJson()); + mockServerReceiveReply(OsiPostfachRemoteServiceTest.buildReplyJson()); service.fetchAndPersistReplies(); var mails = callGrpcListEndpoint(); - assertThat(mails).hasSize(1); - assertThat(mails.get(0).getAttachmentList()).hasSize(1).doesNotContainNull(); + Assertions.assertThat(mails).hasSize(1); + Assertions.assertThat(mails.get(0).getAttachmentList()).hasSize(1).doesNotContainNull(); } @Test void shouldHaveContentTypeDOCX() { var attachment = MessageAttachmentTestFactory.createBuilder().fileName("wort-datei.docx").build(); - mockServerReceiveReply(OsiPostfachServiceTest.buildReplyJson(MessageTestFactory.create(), + mockServerReceiveReply(OsiPostfachRemoteServiceTest.buildReplyJson(MessageTestFactory.create(), attachment)); service.fetchAndPersistReplies(); diff --git a/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/OsiPostfachApiTestCase.java b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachApiTestCase.java similarity index 84% rename from pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/OsiPostfachApiTestCase.java rename to pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachApiTestCase.java index 74011a52e89f5a7e88d3a215e0c90801e8865caf..7f150e2b400a4d34b14938f88d12f2f851a0ae45 100644 --- a/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/OsiPostfachApiTestCase.java +++ b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachApiTestCase.java @@ -21,19 +21,20 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; import java.util.stream.Stream; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import de.itvsh.kop.common.test.ITCase; +import de.itvsh.ozg.mail.postfach.PostfachNachricht; +import de.itvsh.ozg.mail.postfach.PostfachNachrichtTestFactory; import de.itvsh.ozg.pluto.PlutoServerApplication; @Disabled("Echter Test für OSI Postfach mit echtem Zugriff. Unbedingt defaultmäßig deaktivieren!!") @@ -47,11 +48,11 @@ import de.itvsh.ozg.pluto.PlutoServerApplication; class OsiPostfachApiTestCase { @Autowired - private OsiPostfachService service; + private OsiPostfachRemoteService service; @Test void testGetAllMessages() { - Stream<Message> messages = service.getAllMessages(); + Stream<PostfachNachricht> messages = service.getAllMessages(); assertThat(messages).hasSizeGreaterThan(0); } @@ -60,11 +61,11 @@ class OsiPostfachApiTestCase { @Disabled("Echter Test für OSI Postfach mit echtem Zugriff. Unbedingt defaultmäßig deaktivieren!!") void testSendMessage() { - Message message = MessageTestFactory.createBuilder() // + PostfachNachricht nachricht = PostfachNachrichtTestFactory.createBuilder() .postfachId("2f5c78f8-4891-456f-269b-08d937ab9a72").vorgangId("98877665544").build(); assertDoesNotThrow(() -> { - service.sendMessage(message); + service.sendMessage(nachricht); }); } } diff --git a/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/OsiPostfachServiceITCase.java b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachServiceITCase.java similarity index 79% rename from pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/OsiPostfachServiceITCase.java rename to pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachServiceITCase.java index f1e56bfc42bb515532f19dd60d5e7755c2e164d1..aa1866a4c28a63e86c131a9fdc4a072d7e7c59ba 100644 --- a/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/OsiPostfachServiceITCase.java +++ b/pluto-server/src/test/java/de/itvsh/ozg/mail/postfach/osi/OsiPostfachServiceITCase.java @@ -21,15 +21,15 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -package de.itvsh.ozg.mail.postfach; +package de.itvsh.ozg.mail.postfach.osi; import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.client.match.MockRestRequestMatchers.*; import static org.springframework.test.web.client.response.MockRestResponseCreators.*; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import java.util.Collections; + +import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; @@ -37,6 +37,9 @@ import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; import de.itvsh.kop.common.test.ITCase; +import de.itvsh.ozg.mail.postfach.PostfachException; +import de.itvsh.ozg.mail.postfach.PostfachNachricht; +import de.itvsh.ozg.mail.postfach.PostfachNachrichtTestFactory; import de.itvsh.ozg.pluto.PlutoServerApplication; @SpringBootTest(classes = { PlutoServerApplication.class, OsiPostfachProperties.class }) @@ -49,12 +52,15 @@ class OsiPostfachServiceITCase { static final String API_REALM = "test-realm"; @Autowired - private OsiPostfachService service; + private OsiPostfachRemoteService service; @Autowired private RestTemplate restTemplate; private MockRestServiceServer mockServer; + private static final PostfachNachricht POSTFACH_NACHRICHT_WITHOUT_ATTACHMENTS = + PostfachNachrichtTestFactory.createBuilder().attachments(Collections.emptyList()).build(); + @BeforeEach void initMockServer() { mockServer = MockRestServiceServer.createServer(restTemplate); @@ -64,7 +70,7 @@ class OsiPostfachServiceITCase { void shouldCallWithApiKeyHeader() { mockServer.expect(header(PostfachConfiguration.HEADER_API_KEY, API_KEY)).andRespond(withSuccess()); - service.sendMessage(MessageTestFactory.create()); + service.sendMessage(POSTFACH_NACHRICHT_WITHOUT_ATTACHMENTS); mockServer.verify(); } @@ -73,7 +79,7 @@ class OsiPostfachServiceITCase { void shouldCallWithRealmHeader() { mockServer.expect(header(PostfachConfiguration.HEADER_API_REALM, API_REALM)).andRespond(withSuccess()); - service.sendMessage(MessageTestFactory.create()); + service.sendMessage(POSTFACH_NACHRICHT_WITHOUT_ATTACHMENTS); mockServer.verify(); } @@ -82,7 +88,7 @@ class OsiPostfachServiceITCase { void shouldRequestBaseUrl() { mockServer.expect(requestTo(URL)).andRespond(withSuccess()); - service.sendMessage(MessageTestFactory.create()); + service.sendMessage(POSTFACH_NACHRICHT_WITHOUT_ATTACHMENTS); mockServer.verify(); } @@ -95,7 +101,7 @@ class OsiPostfachServiceITCase { mockServer.expect(header(PostfachConfiguration.HEADER_API_REALM, API_REALM)) .andRespond(withSuccess(String.valueOf(true), MediaType.APPLICATION_JSON)); - service.sendMessage(MessageTestFactory.create()); + service.sendMessage(POSTFACH_NACHRICHT_WITHOUT_ATTACHMENTS); mockServer.verify(); } @@ -105,7 +111,8 @@ class OsiPostfachServiceITCase { mockServer.expect(header(PostfachConfiguration.HEADER_API_REALM, API_REALM)) .andRespond(withSuccess(String.valueOf(false), MediaType.APPLICATION_JSON)); - assertThrows(OsiPostfachException.class, () -> service.sendMessage(MessageTestFactory.create()));// NOSONAR + assertThrows(PostfachException.class, + () -> service.sendMessage(POSTFACH_NACHRICHT_WITHOUT_ATTACHMENTS));// NOSONAR mockServer.verify(); } diff --git a/pluto-server/src/test/java/de/itvsh/ozg/pluto/command/PersistPostfachMailByCommandServiceTest.java b/pluto-server/src/test/java/de/itvsh/ozg/pluto/command/PersistPostfachMailByCommandServiceTest.java index 6d118c6658d253b90c93f94aa286e1fedc146933..86abb51570c3bb4f22d60ef6a6bee67834a2c85f 100644 --- a/pluto-server/src/test/java/de/itvsh/ozg/pluto/command/PersistPostfachMailByCommandServiceTest.java +++ b/pluto-server/src/test/java/de/itvsh/ozg/pluto/command/PersistPostfachMailByCommandServiceTest.java @@ -43,8 +43,8 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import de.itvsh.ozg.mail.postfach.MessageAttachmentTestFactory; -import de.itvsh.ozg.mail.postfach.MessageTestFactory; import de.itvsh.ozg.mail.postfach.PostfachNachrichtTestFactory; +import de.itvsh.ozg.mail.postfach.osi.MessageTestFactory; import de.itvsh.ozg.pluto.attached_item.VorgangAttachedItemMapper; import de.itvsh.ozg.pluto.attached_item.VorgangAttachedItemService; import de.itvsh.ozg.pluto.attached_item.VorgangAttachedItemTestFactory;