From abea538cbaa34f490d8f36bbb9e3cb69adfee286 Mon Sep 17 00:00:00 2001 From: Jan Zickermann <jan.zickermann@dataport.de> Date: Mon, 17 Feb 2025 17:45:00 +0100 Subject: [PATCH] OZG-4097 send-attachment: Adjust remote itcase --- .../postfach/osiv2/HttpProxyConfig.java | 32 +++++++++++++ .../OsiPostfachRemoteServiceRemoteITCase.java | 45 ++++++++++++++----- 2 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/HttpProxyConfig.java diff --git a/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/HttpProxyConfig.java b/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/HttpProxyConfig.java new file mode 100644 index 0000000..6e89c6e --- /dev/null +++ b/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/HttpProxyConfig.java @@ -0,0 +1,32 @@ +package de.ozgcloud.nachrichten.postfach.osiv2; + +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public record HttpProxyConfig( + String host, + String port +) { + + public static Optional<HttpProxyConfig> fromEnv() { + return Optional.ofNullable(System.getenv("HTTP_PROXY")) + .map(HttpProxyConfig::fromEnvVar); + } + + private static HttpProxyConfig fromEnvVar(String httpProxyEnvVar) { + var matcher = matchProxyRegex(httpProxyEnvVar); + return new HttpProxyConfig( + matcher.group(1), + matcher.group(2) + ); + } + + private static Matcher matchProxyRegex(String text) { + var matcher = Pattern.compile("([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+):([0-9]+)").matcher(text); + if (matcher.find()) { + return matcher; + } + throw new IllegalArgumentException("Proxy host and port not found in '%s'".formatted(text)); + } +} diff --git a/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteServiceRemoteITCase.java b/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteServiceRemoteITCase.java index 4bcdb77..2cbc582 100644 --- a/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteServiceRemoteITCase.java +++ b/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteServiceRemoteITCase.java @@ -1,13 +1,15 @@ package de.ozgcloud.nachrichten.postfach.osiv2; +import static de.ozgcloud.nachrichten.NachrichtenManagerConfiguration.*; import static org.assertj.core.api.Assertions.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.Arrays; +import java.util.Optional; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; @@ -15,6 +17,9 @@ import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import de.ozgcloud.nachrichten.postfach.PostfachNachricht; +import de.ozgcloud.nachrichten.postfach.osiv2.attachment.Osi2AttachmentFileService; +import de.ozgcloud.nachrichten.postfach.osiv2.extension.AttachmentExampleUploadUtil; +import de.ozgcloud.nachrichten.postfach.osiv2.extension.VorgangManagerServerExtension; import de.ozgcloud.nachrichten.postfach.osiv2.factory.DummyStringBasedIdentifier; import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachAddressTestFactory; import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory; @@ -28,33 +33,39 @@ class OsiPostfachRemoteServiceRemoteITCase { @Autowired private OsiPostfachRemoteService osiPostfachRemoteService; + @RegisterExtension + static final VorgangManagerServerExtension VORGANG_MANAGER_SERVER_EXTENSION = new VorgangManagerServerExtension(); + @DynamicPropertySource static void dynamicProperties(DynamicPropertyRegistry registry) { registry.add( "ozgcloud.osiv2.auth.client-secret", () -> System.getenv("SH_STAGE_CLIENT_SECRET") ); + registry.add( + "ozgcloud.osiv2.proxy.enabled", + () -> HttpProxyConfig.fromEnv().map(v -> "true").orElse("false") + ); registry.add( "ozgcloud.osiv2.proxy.host", - () -> matchProxyRegex(System.getenv("HTTP_PROXY")).group(1) + () -> HttpProxyConfig.fromEnv().map(HttpProxyConfig::host).orElse("") ); registry.add( "ozgcloud.osiv2.proxy.port", - () -> matchProxyRegex(System.getenv("HTTP_PROXY")).group(2) + () -> HttpProxyConfig.fromEnv().map(HttpProxyConfig::port).orElse("") ); + registry.add("grpc.client." + GRPC_FILE_MANAGER_NAME + ".address", VORGANG_MANAGER_SERVER_EXTENSION::getVorgangManagerAddress); + registry.add("grpc.client." + GRPC_FILE_MANAGER_NAME + ".negotiationType", () -> "PLAINTEXT"); } - private static Matcher matchProxyRegex(String text) { - var matcher = Pattern.compile("([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+):([0-9]+)").matcher(text); - if (matcher.find()) { - return matcher; - } - throw new IllegalArgumentException("Proxy host and port not found in '%s'".formatted(text)); - } - private PostfachNachricht createNachricht() { + @Autowired + protected Osi2AttachmentFileService osi2AttachmentFileService; + + private PostfachNachricht createNachricht(String... attachmentIds) { return PostfachNachrichtTestFactory.createBuilder() .replyOption(PostfachNachricht.ReplyOption.POSSIBLE) + .attachments(Arrays.stream(attachmentIds).toList()) .postfachAddress(PostfachAddressTestFactory.createBuilder() .identifier(DummyStringBasedIdentifier.builder() .mailboxId("49b5a7e2-5e60-4baf-8ccf-1f5b94b570f3") @@ -73,6 +84,16 @@ class OsiPostfachRemoteServiceRemoteITCase { .doesNotThrowAnyException(); } + @DisplayName("should not fail sending message with attachment") + @Test + void shouldNotFailSendingMessageWithAttachment() { + var textFileId = AttachmentExampleUploadUtil.uploadTextFile(osi2AttachmentFileService); + var nachricht = createNachricht(textFileId); + + assertThatCode(() -> osiPostfachRemoteService.sendMessage(nachricht)) + .doesNotThrowAnyException(); + } + @DisplayName("should receive messages") @Test void shouldReceiveMessages() { -- GitLab