diff --git a/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/OsiPostfachServiceITCase.java b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/OsiPostfachServiceITCase.java new file mode 100644 index 0000000000000000000000000000000000000000..55bf5fd61e145251a134e8596aa10a657c996bdc --- /dev/null +++ b/nachrichten-manager-server/src/test/java/de/ozgcloud/nachrichten/postfach/OsiPostfachServiceITCase.java @@ -0,0 +1,94 @@ +package de.ozgcloud.nachrichten.postfach; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.event.EventListener; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.test.context.TestPropertySource; +import org.springframework.web.client.RestTemplate; + +import de.ozgcloud.common.test.ITCase; +import de.ozgcloud.nachrichten.attributes.ClientAttributeService; +import de.ozgcloud.nachrichten.email.EmailGrpcService; +import de.ozgcloud.nachrichten.postfach.osi.MessageAttachmentService; +import lombok.SneakyThrows; + +@ITCase +@TestPropertySource(properties = { + "ozgcloud.osi.postfach.proxyapi.key=key", + "ozgcloud.osi.postfach.proxyapi.realm=realm", + "ozgcloud.osi.postfach.proxyapi.url=url", +}) +class OsiPostfachServiceITCase { + + @Autowired + private PostfachService postfachService; + + @MockBean + private ClientAttributeService clientAttributeRemoteService; + + @MockBean + private MessageAttachmentService messageAttachmentService; + + @MockBean + private EmailGrpcService emailGrpcService; + + @MockBean + private RestTemplate restTemplate; + + @Autowired + private SentEventTestListener sentEventTestListener; + + @BeforeEach + void mock() { + sentEventTestListener.reset(); + } + + @DisplayName("should call osi postfach send") + @Test + @SneakyThrows + void shouldCallOsiPostfachSend() { + var osiNachricht = PostfachNachrichtTestFactory.createBuilder() + .postfachAddress(PostfachAddressTestFactory.createBuilder() + .serviceKontoType("OSI") + .build() + ) + .build(); + var commandId = "aaaaa"; + when(restTemplate.exchange(eq("url"), eq(HttpMethod.POST), any(), Mockito.<Class<String>>any())).thenReturn(ResponseEntity.ok("true")); + + + postfachService.sendMail(commandId, "userId", osiNachricht); + + assertThat(sentEventTestListener.events) + .extracting(PostfachMailSentEvent::getSource) + .containsExactly(commandId); + } + + @Component + static class SentEventTestListener { + final List<PostfachMailSentEvent> events = new ArrayList<>(); + + @EventListener + void onEvent(PostfachMailSentEvent event) { + events.add(event); + } + + void reset() { + events.clear(); + } + } + +}