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

OZG-4094 osi2: Remove ITCases

parent 9af008a0
Branches
No related tags found
1 merge request!2OZG-4094 osi2 postfach facade
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
<bayernid-proxy-interface.version>0.7.0</bayernid-proxy-interface.version> <bayernid-proxy-interface.version>0.7.0</bayernid-proxy-interface.version>
<vorgang-manager.version>2.17.0</vorgang-manager.version> <vorgang-manager.version>2.17.0</vorgang-manager.version>
<muk-postfach.version>0.1.0</muk-postfach.version> <muk-postfach.version>0.1.0</muk-postfach.version>
<osiv2-postfach.version>0.1.0-SNAPSHOT</osiv2-postfach.version> <osiv2-postfach.version>0.1.0</osiv2-postfach.version>
<api-lib.version>0.16.0</api-lib.version> <api-lib.version>0.16.0</api-lib.version>
</properties> </properties>
......
package de.ozgcloud.nachrichten.postfach;
import static org.assertj.core.api.Assertions.*;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.test.context.ActiveProfiles;
import de.ozgcloud.nachrichten.NachrichtenManagerTestApplication;
import de.ozgcloud.nachrichten.attributes.ClientAttributeService;
import de.ozgcloud.nachrichten.email.EmailGrpcService;
import de.ozgcloud.nachrichten.postfach.osiv2.config.Osi2PostfachProperties;
import de.ozgcloud.nachrichten.postfach.osiv2.transfer.PostfachApiFacadeService;
import de.ozgcloud.vorgang.callcontext.WithMockCustomUser;
@SpringBootTest(classes = NachrichtenManagerTestApplication.class,
properties = {
"ozgcloud.osiv2.enabled=true"
})
@ActiveProfiles({ "itcase", "stage" })
class Osi2PostfachServiceITCase {
@Autowired
private PostfachService postfachService;
@Autowired
private Osi2PostfachProperties.ApiConfiguration osi2ApiConfiguration;
@MockBean
private ApplicationEventPublisher publisher;
@MockBean
private ClientAttributeService clientAttributeRemoteService;
@MockBean
private PostfachApiFacadeService postfachApiFacadeService;
@MockBean
private EmailGrpcService emailGrpcService;
@Autowired
private OsiPostfachServiceITCase.SentEventTestListener sentEventTestListener;
@BeforeEach
void mock() {
sentEventTestListener.reset();
}
@DisplayName("should use stage profile properties")
@Test
void shouldUseStageProfileProperties() {
var url = osi2ApiConfiguration.getUrl();
assertThat(url).isNotEmpty();
}
@DisplayName("should call osi2 postfach send")
@Test
@WithMockCustomUser
void shouldCallOsi2PostfachSend() {
var osiNachricht = PostfachNachrichtTestFactory.createBuilder()
.postfachAddress(PostfachAddressTestFactory.createBuilder()
.serviceKontoType("OSI")
.build()
)
.build();
var commandId = "aaaaa";
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();
}
}
}
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.context.SpringBootTest;
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.ActiveProfiles;
import org.springframework.web.client.RestTemplate;
import de.ozgcloud.nachrichten.NachrichtenManagerTestApplication;
import de.ozgcloud.nachrichten.attributes.ClientAttributeService;
import de.ozgcloud.nachrichten.email.EmailGrpcService;
import de.ozgcloud.nachrichten.postfach.osi.MessageAttachmentService;
import lombok.SneakyThrows;
@SpringBootTest(classes = NachrichtenManagerTestApplication.class,
properties = {
"ozgcloud.osi.postfach.proxyapi.key=key",
"ozgcloud.osi.postfach.proxyapi.realm=realm",
"ozgcloud.osi.postfach.proxyapi.url=url",
})
@ActiveProfiles({ "itcase" })
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();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment