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

OZG-4097 send-attachment: Adjust remote itcase

parent 6f975cee
No related branches found
No related tags found
No related merge requests found
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;
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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment