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

OZG-4097 send-attachment: Adjust remote itcase

parent 212b3040
Branches
Tags
1 merge request!15Ozg 4097 senden und empfangen von anhängen
Pipeline #1736 failed
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));
}
}
package de.ozgcloud.nachrichten.postfach.osiv2; package de.ozgcloud.nachrichten.postfach.osiv2;
import static de.ozgcloud.nachrichten.NachrichtenManagerConfiguration.*;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import java.util.regex.Matcher; import java.util.Arrays;
import java.util.regex.Pattern; import java.util.Optional;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
...@@ -15,6 +17,9 @@ import org.springframework.test.context.DynamicPropertyRegistry; ...@@ -15,6 +17,9 @@ import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.context.DynamicPropertySource;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht; 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.DummyStringBasedIdentifier;
import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachAddressTestFactory; import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachAddressTestFactory;
import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory; import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory;
...@@ -28,33 +33,39 @@ class OsiPostfachRemoteServiceRemoteITCase { ...@@ -28,33 +33,39 @@ class OsiPostfachRemoteServiceRemoteITCase {
@Autowired @Autowired
private OsiPostfachRemoteService osiPostfachRemoteService; private OsiPostfachRemoteService osiPostfachRemoteService;
@RegisterExtension
static final VorgangManagerServerExtension VORGANG_MANAGER_SERVER_EXTENSION = new VorgangManagerServerExtension();
@DynamicPropertySource @DynamicPropertySource
static void dynamicProperties(DynamicPropertyRegistry registry) { static void dynamicProperties(DynamicPropertyRegistry registry) {
registry.add( registry.add(
"ozgcloud.osiv2.auth.client-secret", "ozgcloud.osiv2.auth.client-secret",
() -> System.getenv("SH_STAGE_CLIENT_SECRET") () -> System.getenv("SH_STAGE_CLIENT_SECRET")
); );
registry.add(
"ozgcloud.osiv2.proxy.enabled",
() -> HttpProxyConfig.fromEnv().map(v -> "true").orElse("false")
);
registry.add( registry.add(
"ozgcloud.osiv2.proxy.host", "ozgcloud.osiv2.proxy.host",
() -> matchProxyRegex(System.getenv("HTTP_PROXY")).group(1) () -> HttpProxyConfig.fromEnv().map(HttpProxyConfig::host).orElse("")
); );
registry.add( registry.add(
"ozgcloud.osiv2.proxy.port", "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() return PostfachNachrichtTestFactory.createBuilder()
.replyOption(PostfachNachricht.ReplyOption.POSSIBLE) .replyOption(PostfachNachricht.ReplyOption.POSSIBLE)
.attachments(Arrays.stream(attachmentIds).toList())
.postfachAddress(PostfachAddressTestFactory.createBuilder() .postfachAddress(PostfachAddressTestFactory.createBuilder()
.identifier(DummyStringBasedIdentifier.builder() .identifier(DummyStringBasedIdentifier.builder()
.mailboxId("49b5a7e2-5e60-4baf-8ccf-1f5b94b570f3") .mailboxId("49b5a7e2-5e60-4baf-8ccf-1f5b94b570f3")
...@@ -73,6 +84,16 @@ class OsiPostfachRemoteServiceRemoteITCase { ...@@ -73,6 +84,16 @@ class OsiPostfachRemoteServiceRemoteITCase {
.doesNotThrowAnyException(); .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") @DisplayName("should receive messages")
@Test @Test
void shouldReceiveMessages() { void shouldReceiveMessages() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment