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

OZG-4095 receive: Test with smocker dev

parent 64ced60e
Branches
Tags
1 merge request!13Ozg 4095 abrufen stage test
Pipeline #1628 passed
......@@ -9,9 +9,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.osiv2.OsiPostfachException;
import de.ozgcloud.nachrichten.postfach.osiv2.config.Osi2PostfachProperties;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.api.MessageExchangeApi;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.MessageExchangeReceiveMessage;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.MessageExchangeReceiveMessagesResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
......@@ -25,7 +27,7 @@ public class PostfachApiFacadeService {
private final Osi2RequestMapper osi2RequestMapper;
private final Osi2ResponseMapper osi2ResponseMapper;
private static final int MAX_NUMBER_RECEIVED_MESSAGES = 100;
static final int MAX_NUMBER_RECEIVED_MESSAGES = 100;
public void sendMessage(PostfachNachricht nachricht) {
messageExchangeApi.sendMessage(
......@@ -35,12 +37,16 @@ public class PostfachApiFacadeService {
}
public Stream<PostfachNachricht> receiveMessages() {
var response = messageExchangeApi.receiveMessages(MAX_NUMBER_RECEIVED_MESSAGES, 0);
return Optional.ofNullable(response.getMessages())
return Optional.ofNullable(receiveMessagesResponse().getMessages())
.stream()
.flatMap(Collection::stream)
.map(this::fetchMessageByGuid);
}
private MessageExchangeReceiveMessagesResponse receiveMessagesResponse() {
return Optional.ofNullable(messageExchangeApi.receiveMessages(MAX_NUMBER_RECEIVED_MESSAGES, 0))
.orElseThrow(() -> new OsiPostfachException("Expect non empty response!", null));
}
PostfachNachricht fetchMessageByGuid(final MessageExchangeReceiveMessage message) {
var messageReply = messageExchangeApi.getMessage(message.getGuid());
......
......@@ -87,7 +87,7 @@ class OsiPostfachRemoteServiceRemoteITCase {
@DisplayName("should delete message")
@Test
void shouldDeleteMessage() {
assertThatCode(() -> osiPostfachRemoteService.deleteMessage("5dd65c1e-bd41-4c3d-bf98-be769ca341dc"))
assertThatCode(() -> osiPostfachRemoteService.deleteMessage("2cec3eac-66d2-4de0-bc6b-652b8e985ceb"))
.doesNotThrowAnyException();
}
}
......@@ -7,6 +7,9 @@ import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.MessageExchangeReceiveMe
public class MessageExchangeReceiveMessagesResponseTestFactory {
public static final String MESSAGE_ID_1 = UUID.randomUUID().toString();
public static final String MESSAGE_ID_2 = UUID.randomUUID().toString();
public static MessageExchangeReceiveMessagesResponse create(String... uuids) {
return new MessageExchangeReceiveMessagesResponse()
.messages(Arrays.stream(uuids)
......
package de.ozgcloud.nachrichten.postfach.osiv2.transfer;
import static de.ozgcloud.nachrichten.postfach.osiv2.factory.MessageExchangeReceiveMessagesResponseTestFactory.*;
import static de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachAddressTestFactory.*;
import static de.ozgcloud.nachrichten.postfach.osiv2.transfer.PostfachApiFacadeService.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
......@@ -12,8 +15,11 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.osiv2.OsiPostfachException;
import de.ozgcloud.nachrichten.postfach.osiv2.factory.MessageExchangeReceiveMessagesResponseTestFactory;
import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.api.MessageExchangeApi;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.MessageExchangeDeleteMessageResponse;
......@@ -26,6 +32,7 @@ import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyMessage;
class PostfachApiFacadeServiceTest {
@InjectMocks
@Spy
PostfachApiFacadeService postfachApiFacadeService;
@Mock
......@@ -68,27 +75,85 @@ class PostfachApiFacadeServiceTest {
@DisplayName("receive messages")
@Nested
class TestReceiveMessage{
class TestReceiveMessage {
@DisplayName("with two pending messages")
@Nested
class TestWithTwoPendingMessages {
private final MessageExchangeReceiveMessagesResponse response = MessageExchangeReceiveMessagesResponseTestFactory.create(
MESSAGE_ID_1, MESSAGE_ID_2
);
@BeforeEach
void mock() {
when(messageExchangeApi.receiveMessages(anyInt(), anyInt())).thenReturn(response);
doReturn(PostfachNachrichtTestFactory.createBuilder().messageId(MESSAGE_ID_1).build())
.when(postfachApiFacadeService).fetchMessageByGuid(response.getMessages().get(0));
doReturn(PostfachNachrichtTestFactory.createBuilder().messageId(MESSAGE_ID_2).build())
.when(postfachApiFacadeService).fetchMessageByGuid(response.getMessages().get(1));
}
@DisplayName("should return")
@Test
void shouldReturn() {
var messages = receiveMessageList();
assertThat(messages)
.extracting(PostfachNachricht::getMessageId)
.containsExactly(MESSAGE_ID_1, MESSAGE_ID_2);
}
@DisplayName("should call receiveMessages api method")
@Test
void shouldCallReceiveMessagesApiMethod() {
receiveMessageList();
verify(messageExchangeApi).receiveMessages(MAX_NUMBER_RECEIVED_MESSAGES, 0);
}
@Mock
MessageExchangeReceiveMessagesResponse messageExchangeReceiveMessagesResponse;
}
@DisplayName("with no pending messages")
@Nested
class TestWithNoPendingMessages {
private final MessageExchangeReceiveMessagesResponse emptyResponse = MessageExchangeReceiveMessagesResponseTestFactory.create();
@BeforeEach
void mock() {
when(messageExchangeApi.receiveMessages(anyInt(), anyInt())).thenReturn(emptyResponse);
}
@DisplayName("should return")
@Test
void shouldReturn() {
var messages = receiveMessageList();
assertThat(messages).isEmpty();
}
@BeforeEach
void mock(){
when(messageExchangeApi.receiveMessages(anyInt(),anyInt())).thenReturn(messageExchangeReceiveMessagesResponse);
}
@Test
void responseShouldNotBeEmpty(){
postfachApiFacadeService.receiveMessages();
@DisplayName("with null response")
@Nested
class TestWithNullResponse {
verify(messageExchangeApi).receiveMessages(anyInt(), anyInt());
@DisplayName("should throw")
@Test
void shouldThrow() {
assertThatThrownBy(TestReceiveMessage.this::receiveMessageList)
.isInstanceOf(OsiPostfachException.class);
}
}
private List<PostfachNachricht> receiveMessageList() {
return postfachApiFacadeService.receiveMessages().toList();
}
}
@DisplayName("fetch Message by guid")
@Nested
class TestFetchMessageByGuid{
class TestFetchMessageByGuid {
@Mock
V1ReplyMessage replyMessage;
......@@ -96,7 +161,7 @@ class PostfachApiFacadeServiceTest {
MessageExchangeReceiveMessage receiveMessage;
@Test
void shouldCallGetMessage(){
void shouldCallGetMessage() {
when(messageExchangeApi.getMessage(any())).thenReturn(replyMessage);
postfachApiFacadeService.fetchMessageByGuid(receiveMessage);
......@@ -105,7 +170,7 @@ class PostfachApiFacadeServiceTest {
}
@Test
void shouldCallResponseMapper(){
void shouldCallResponseMapper() {
when(messageExchangeApi.getMessage(any())).thenReturn(replyMessage);
when(osi2ResponseMapper.toPostfachNachricht(any())).thenReturn(PostfachNachrichtTestFactory.create());
......@@ -115,7 +180,7 @@ class PostfachApiFacadeServiceTest {
}
@Test
void shouldReturnPostfachNachricht(){
void shouldReturnPostfachNachricht() {
when(messageExchangeApi.getMessage(any())).thenReturn(replyMessage);
when(osi2ResponseMapper.toPostfachNachricht(any())).thenReturn(PostfachNachrichtTestFactory.create());
......@@ -127,12 +192,12 @@ class PostfachApiFacadeServiceTest {
@DisplayName("Delete Message")
@Nested
class TestDeleteMessage{
class TestDeleteMessage {
@Mock
MessageExchangeDeleteMessageResponse replyMessage;
@Test
void shouldCallDeleteMessage(){
void shouldCallDeleteMessage() {
when(messageExchangeApi.deleteMessage(any())).thenReturn(replyMessage);
postfachApiFacadeService.deleteMessage(UUID.randomUUID().toString());
......
spring:
security:
oauth2:
client:
registration:
osi2:
client-id: 'OZG-Kopfstelle'
client-secret: 'changeme'
scope: default, access_urn:dataport:osi:sh:stage:ozgkopfstelle
authorization-grant-type: 'client_credentials'
client-authentication-method: client_secret_post
provider:
osi2:
token-uri: 'http://localhost:8080/osi-postfach-v2-token'
ozgcloud:
osiv2:
enabled: false
api:
resource: 'urn:dataport:osi:postfach:rz2:stage:sh'
url: 'http://localhost:8080'
tenant: 'SH'
name-identifier: 'ozgkopfstelle'
proxy:
enabled: false
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment