diff --git a/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachAddress.java b/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachAddress.java index 1329a831bbc96ab171741d1e4a1c250a366b4af8..e9831aa79397ce0ec67c0207b0640d9eee159343 100644 --- a/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachAddress.java +++ b/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachAddress.java @@ -23,6 +23,9 @@ */ package de.ozgcloud.nachrichten.postfach; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; + import lombok.Builder; import lombok.Getter; import lombok.ToString; @@ -40,6 +43,8 @@ public class PostfachAddress { private String version; private int type; + @Valid private PostfachAddressIdentifier identifier; + @NotBlank private String serviceKontoType; } \ No newline at end of file diff --git a/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachNachricht.java b/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachNachricht.java index d896f46d57e8ab15d055efe5c74204fa5dddcf29..50642691db98a1d81b8fc99f14babdbaa2254b49 100644 --- a/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachNachricht.java +++ b/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachNachricht.java @@ -27,6 +27,7 @@ import java.time.ZonedDateTime; import java.util.Collections; import java.util.List; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import lombok.Builder; @@ -67,6 +68,7 @@ public class PostfachNachricht { private String id; private String vorgangId; + @Valid private PostfachAddress postfachAddress; private String messageId; private String referencedNachricht; diff --git a/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachRemoteService.java b/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachRemoteService.java index c4e2d19ecdd2ce9cb9380bd8cd2d291b61da8801..170bd4da6d5ca305f7bf39c971d2bc45fd408a44 100644 --- a/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachRemoteService.java +++ b/nachrichten-manager-postfach-interface/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachRemoteService.java @@ -25,9 +25,14 @@ package de.ozgcloud.nachrichten.postfach; import java.util.stream.Stream; +import jakarta.validation.Valid; + +import org.springframework.validation.annotation.Validated; + +@Validated public interface PostfachRemoteService { - void sendMessage(PostfachNachricht nachricht); + void sendMessage(@Valid PostfachNachricht nachricht); Stream<PostfachNachricht> getAllMessages(); diff --git a/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java b/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java index e4f61633b748919139154bf8e4008171129c10d8..a6e8b081fe836a1bcb6d56867ec9fc267b7cd1c7 100644 --- a/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java +++ b/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/PostfachService.java @@ -276,25 +276,19 @@ class PostfachService { } Optional<PostfachRemoteService> findPostfachRemoteService(String postfachType) { - var remoteServices = getPostfachRemoteServices().toList(); - if (Objects.isNull(postfachType) && remoteServices.size() != 1) { - throw new TechnicalException("PostfachType is null and no distinct PostfachService is configured."); + if (Objects.isNull(postfachType)) { + throw new TechnicalException("PostfachType is null."); } - return remoteServices.stream() + return getPostfachRemoteServices() .filter(remoteService -> hasPostfachType(remoteService, postfachType)) .findFirst(); } - private boolean hasPostfachType(PostfachRemoteService postfachRemoteService, String postfachType) { - if (Objects.isNull(postfachType)) { - LOG.error("PostfachType is null - use existing PostfachService with type %s.".formatted(postfachRemoteService.getPostfachType())); - return true; - } - return StringUtils.equals(postfachRemoteService.getPostfachType(), postfachType); - } - Stream<PostfachRemoteService> getPostfachRemoteServices() { return postfachRemoteServices.map(Collection::stream).orElseThrow(() -> new NotConfiguredException("No postfach configured")); } + private boolean hasPostfachType(PostfachRemoteService postfachRemoteService, String postfachType) { + return StringUtils.equals(postfachRemoteService.getPostfachType(), postfachType); + } } \ No newline at end of file diff --git a/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/StringBasedIdentifier.java b/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/StringBasedIdentifier.java index 5be71d52deac519a2ae87ec1a95772dc214c7325..5724f8624648d2b5deb69a838aeefc51b8123bc9 100644 --- a/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/StringBasedIdentifier.java +++ b/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/StringBasedIdentifier.java @@ -23,6 +23,8 @@ */ package de.ozgcloud.nachrichten.postfach; +import jakarta.validation.constraints.NotBlank; + import lombok.Builder; import lombok.Getter; @@ -30,6 +32,7 @@ import lombok.Getter; @Getter public class StringBasedIdentifier implements PostfachAddressIdentifier { + @NotBlank private String postfachId; @Override diff --git a/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/bayernid/BayernIdPostfachRemoteService.java b/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/bayernid/BayernIdPostfachRemoteService.java index 7a89c7d752e9f97642a240af2ff4fc26965d8fd1..c961f3159274e3e8e29cbbd5a472df1c9a6d3ae9 100644 --- a/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/bayernid/BayernIdPostfachRemoteService.java +++ b/nachrichten-manager-server/src/main/java/de/ozgcloud/nachrichten/postfach/bayernid/BayernIdPostfachRemoteService.java @@ -101,8 +101,8 @@ class BayernIdPostfachRemoteService implements PostfachRemoteService { } Function<StreamObserver<GrpcSendBayernIdMessageResponse>, CallStreamObserver<GrpcSendBayernIdMessageRequest>> buildCallStreamObserverBuilder() { - return responseObserver -> - (CallStreamObserver<GrpcSendBayernIdMessageRequest>) bayernIdProxyServiceStub.sendMessageAsStream(responseObserver); + return responseObserver -> (CallStreamObserver<GrpcSendBayernIdMessageRequest>) bayernIdProxyServiceStub + .sendMessageAsStream(responseObserver); } Function<String, BayernIdAttachment> buildAttachmentBuilder() { diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/info/InfoManagerServiceTest.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/info/InfoManagerServiceTest.java index 87daf339100ab4960c2bf96c7180bdf907765fc8..55f8368dacd8eae7220957419bee650dec58fb33 100644 --- a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/info/InfoManagerServiceTest.java +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/info/InfoManagerServiceTest.java @@ -41,6 +41,7 @@ import de.ozgcloud.nachrichten.postfach.PostfachException; import de.ozgcloud.nachrichten.postfach.PostfachMessageCode; import de.ozgcloud.nachrichten.postfach.PostfachNachricht; import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory; +import de.ozgcloud.nachrichten.postfach.StringBasedIdentifierTestFactory; import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory; class InfoManagerServiceTest { @@ -134,7 +135,7 @@ class InfoManagerServiceTest { var id = service.getPostfachId(address); - assertThat(id).isEqualTo(PostfachAddressTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); + assertThat(id).isEqualTo(StringBasedIdentifierTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); } @Test diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PersistPostfachNachrichtServiceImplTest.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PersistPostfachNachrichtServiceImplTest.java index d80fe364dae457b76bf9ce0fa82460f0d7076fe8..9a652531f5953acf294461fd3051296dac655826 100644 --- a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PersistPostfachNachrichtServiceImplTest.java +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PersistPostfachNachrichtServiceImplTest.java @@ -467,7 +467,7 @@ class PersistPostfachNachrichtServiceImplTest { void shouldCallVorgangRemoteService() { doFindAnswers().toList(); - verify(vorgangService).findVorgangIds(serviceKontoType, PostfachAddressTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); + verify(vorgangService).findVorgangIds(serviceKontoType, StringBasedIdentifierTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); } @Test @@ -485,7 +485,7 @@ class PersistPostfachNachrichtServiceImplTest { } private Stream<PostfachNachricht> doFindAnswers() { - return service.findAnswers(serviceKontoType, PostfachAddressTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE, + return service.findAnswers(serviceKontoType, StringBasedIdentifierTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE, GrpcPostfachMailTestFactory.REFERENCED_NACHRICHT_ID); } } diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachAddressTestFactory.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachAddressTestFactory.java index 572b41d8e42e75401ac97d5b61c31b259cdd4b45..e3458bb83e5a4a48d7dc3e264d414c0fe084471b 100644 --- a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachAddressTestFactory.java +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachAddressTestFactory.java @@ -23,14 +23,10 @@ */ package de.ozgcloud.nachrichten.postfach; -import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory; - public class PostfachAddressTestFactory { public final static int TYPE = 1; - public static final String STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE = MessageTestFactory.POSTFACH_ID; - public final static StringBasedIdentifier IDENTIFIER = StringBasedIdentifier.builder().postfachId(STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE) - .build(); + public final static StringBasedIdentifier IDENTIFIER = StringBasedIdentifierTestFactory.create(); public static final String VERSION = "1.0"; public static PostfachAddress create() { diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachEventListenerTest.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachEventListenerTest.java index 46a2e817bef81fad7213bc3ced02bba1ccac22b0..b38987c546ab6e67ccac383ad59e292decdcd379 100644 --- a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachEventListenerTest.java +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachEventListenerTest.java @@ -146,7 +146,7 @@ class PostfachEventListenerTest { PostfachAddress.TYPE_FIELD, PostfachAddressTestFactory.TYPE, PostfachAddress.SERVICEKONTO_TYPE_FIELD, PostfachTestFactory.POSTFACH_TYPE, PostfachAddress.IDENTIFIER_FIELD, // - Map.of(PostfachAddress.FIELD_POSTFACH_ID, PostfachAddressTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE)), + Map.of(PostfachAddress.FIELD_POSTFACH_ID, StringBasedIdentifierTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE)), PostfachNachricht.FIELD_SUBJECT, MessageTestFactory.SUBJECT, PostfachNachricht.FIELD_MAIL_BODY, PostfachNachrichtTestFactory.MAIL_BODY, PostfachNachricht.FIELD_REPLY_OPTION, PostfachNachrichtTestFactory.REPLY_OPTION.name(), diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachNachrichtTestFactory.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachNachrichtTestFactory.java index aec4cf7b58accc613a8164dc55c92c9803c6be5b..6c4e1e5fc114db3bbab34738d4d4ad6ee1106dad 100644 --- a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachNachrichtTestFactory.java +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachNachrichtTestFactory.java @@ -104,6 +104,6 @@ public class PostfachNachrichtTestFactory { } private static Map<String, Object> getPostfachAddressIdentifierAsMap() { - return Map.of(PostfachAddress.FIELD_POSTFACH_ID, PostfachAddressTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); + return Map.of(PostfachAddress.FIELD_POSTFACH_ID, StringBasedIdentifierTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); } } diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java index cab1ec99ea6c1110930b2e78543c201a62fc5403..627383a227ebb654edcd5adcbf81f939cb51f98a 100644 --- a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/PostfachServiceTest.java @@ -884,19 +884,7 @@ class PostfachServiceTest { class TestOnPostfachTypeNull { @Test - void shouldReturnRemoteService() { - when(remoteService.getPostfachType()).thenReturn("BAYERN_ID"); - doReturn(Stream.of(remoteService)).when(service).getPostfachRemoteServices(); - - var foundRemoteService = service.findPostfachRemoteService(null); - - assertThat(foundRemoteService).hasValue(remoteService); - } - - @Test - void shouldThrowExceptionMultipleConfiguredRemoteServices() { - doReturn(Stream.of(anotherRemoteService, remoteService)).when(service).getPostfachRemoteServices(); - + void shouldThrowException() { assertThatThrownBy(() -> service.findPostfachRemoteService(null)) .isInstanceOf(TechnicalException.class); } diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/StringBasedIdentifierTestFactory.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/StringBasedIdentifierTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..7404e001413533580fb2ce6071cf56e1dd68b4b2 --- /dev/null +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/StringBasedIdentifierTestFactory.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2025 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.ozgcloud.nachrichten.postfach; + +import de.ozgcloud.nachrichten.postfach.StringBasedIdentifier.StringBasedIdentifierBuilder; +import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory; + +public class StringBasedIdentifierTestFactory { + + public static final String STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE = MessageTestFactory.POSTFACH_ID; + + public static StringBasedIdentifier create() { + return createBuilder().build(); + } + + public static StringBasedIdentifierBuilder createBuilder() { + return StringBasedIdentifier.builder().postfachId(STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); + } +} diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/bayernid/BayernIdPostfachRemoteServiceITCase.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/bayernid/BayernIdPostfachRemoteServiceITCase.java new file mode 100644 index 0000000000000000000000000000000000000000..6b64dbce6cfee0f3b5624eaeb2a74d839b4006e2 --- /dev/null +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/bayernid/BayernIdPostfachRemoteServiceITCase.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2024 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.ozgcloud.nachrichten.postfach.bayernid; + +import static org.junit.jupiter.api.Assertions.*; + +import jakarta.validation.ConstraintViolationException; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +import de.ozgcloud.common.test.ITCase; +import de.ozgcloud.nachrichten.email.EmailGrpcService; +import de.ozgcloud.nachrichten.postfach.PostfachAddressTestFactory; +import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory; +import de.ozgcloud.nachrichten.postfach.StringBasedIdentifierTestFactory; + +@ITCase +@SpringBootTest(properties = { "ozgcloud.bayernid.enabled = true" }) +class BayernIdPostfachRemoteServiceITCase { + + @Autowired + private BayernIdPostfachRemoteService service; + + @MockBean + private EmailGrpcService emailGrpcService; + @MockBean + private BayernIdProperties bayernIdProperties; + + @Nested + class TestSendMessage { + + @ParameterizedTest + @NullAndEmptySource + void shouldThrowConstraintViolationExceptionOnMissingKontoType(String serviceKontoType) { + var nachricht = PostfachNachrichtTestFactory.createBuilder() + .postfachAddress(PostfachAddressTestFactory.createBuilder().serviceKontoType(serviceKontoType).build()) + .build(); + + assertThrows(ConstraintViolationException.class, () -> service.sendMessage(nachricht)); + } + + @ParameterizedTest + @NullAndEmptySource + void shouldThrowConstraintViolationExceptionOnMissingIdentifier(String postfachId) { + var postfachAddress = PostfachAddressTestFactory.createBuilder() + .identifier(StringBasedIdentifierTestFactory.createBuilder().postfachId(postfachId).build()) + .build(); + var nachricht = PostfachNachrichtTestFactory.createBuilder() + .postfachAddress(postfachAddress) + .build(); + + assertThrows(ConstraintViolationException.class, () -> service.sendMessage(nachricht)); + } + } +} \ No newline at end of file diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/osi/OsiPostfachMessageMapperTest.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/osi/OsiPostfachMessageMapperTest.java index 29255fb6e8902a95f18d0a6fae97db6a89ffbcf4..48ff7d0f2654c5793b3823df1e8ca4a6c21d8bd6 100644 --- a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/osi/OsiPostfachMessageMapperTest.java +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/osi/OsiPostfachMessageMapperTest.java @@ -42,6 +42,7 @@ import de.ozgcloud.nachrichten.postfach.PostfachAddressTestFactory; import de.ozgcloud.nachrichten.postfach.PostfachNachricht; import de.ozgcloud.nachrichten.postfach.PostfachNachricht.Direction; import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory; +import de.ozgcloud.nachrichten.postfach.StringBasedIdentifierTestFactory; import de.ozgcloud.vorgang.common.grpc.GrpcObjectMapper; class OsiPostfachMessageMapperTest { @@ -163,7 +164,7 @@ class OsiPostfachMessageMapperTest { void shouldMapPostfachAddressToPostfachId() { var message = toOsiMessage(PostfachNachrichtTestFactory.create()); - assertThat(message.getPostfachId()).isEqualTo(PostfachAddressTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); + assertThat(message.getPostfachId()).isEqualTo(StringBasedIdentifierTestFactory.STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE); } } diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/osi/OsiPostfachRemoteServiceITCase.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/osi/OsiPostfachRemoteServiceITCase.java new file mode 100644 index 0000000000000000000000000000000000000000..2ddd91cc5646af5e2d48403189b638a59701b134 --- /dev/null +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/osi/OsiPostfachRemoteServiceITCase.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2024 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.ozgcloud.nachrichten.postfach.osi; + +import static org.junit.jupiter.api.Assertions.*; + +import jakarta.validation.ConstraintViolationException; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.web.client.RestTemplate; + +import de.ozgcloud.common.test.ITCase; +import de.ozgcloud.nachrichten.email.EmailGrpcService; +import de.ozgcloud.nachrichten.postfach.PostfachAddressTestFactory; +import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory; +import de.ozgcloud.nachrichten.postfach.StringBasedIdentifierTestFactory; + +@ITCase +@SpringBootTest(properties = { + "ozgcloud.osi.postfach.proxyapi.url = foo", + "ozgcloud.osi.postfach.proxyapi.key = bar", + "ozgcloud.osi.postfach.proxyapi.realm = foobar" +}) +class OsiPostfachRemoteServiceITCase { + + @Autowired + private OsiPostfachRemoteService service; + + @MockBean + private EmailGrpcService emailGrpcService; + @MockBean + private OsiPostfachProperties properties; + @MockBean + private RestTemplate restTemplate; + + @Nested + class TestSendMessage { + + @ParameterizedTest + @NullAndEmptySource + void shouldThrowConstraintViolationExceptionOnMissingKontoType(String serviceKontoType) { + var nachricht = PostfachNachrichtTestFactory.createBuilder() + .postfachAddress(PostfachAddressTestFactory.createBuilder().serviceKontoType(serviceKontoType).build()) + .build(); + + assertThrows(ConstraintViolationException.class, () -> service.sendMessage(nachricht)); + } + + @ParameterizedTest + @NullAndEmptySource + void shouldThrowConstraintViolationExceptionOnMissingIdentifier(String postfachId) { + var postfachAddress = PostfachAddressTestFactory.createBuilder() + .identifier(StringBasedIdentifierTestFactory.createBuilder().postfachId(postfachId).build()) + .build(); + var nachricht = PostfachNachrichtTestFactory.createBuilder() + .postfachAddress(postfachAddress) + .build(); + + assertThrows(ConstraintViolationException.class, () -> service.sendMessage(nachricht)); + } + } +} \ No newline at end of file