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

OZG-4095 receive: Map messageId to guid

parent 4689bb7e
No related branches found
No related tags found
1 merge request!13Ozg 4095 abrufen stage test
...@@ -21,9 +21,9 @@ public interface Osi2ResponseMapper { ...@@ -21,9 +21,9 @@ public interface Osi2ResponseMapper {
String POSTFACH_ADDRESS_VERSION = "2.0"; String POSTFACH_ADDRESS_VERSION = "2.0";
int POSTFACH_ADDRESS_TYPE = 2; int POSTFACH_ADDRESS_TYPE = 2;
@Mapping(target = "id", source = "guid") @Mapping(target = "id", ignore = true)
@Mapping(target = "postfachAddress", expression = "java(buildPostfachAddressByPostfachId(message.getMessageBox().toString()))") @Mapping(target = "postfachAddress", expression = "java(buildPostfachAddressByPostfachId(message.getMessageBox().toString()))")
@Mapping(target = "messageId", ignore = true) @Mapping(target = "messageId", source = "guid")
@Mapping(target = "createdAt", expression = "java(java.time.ZonedDateTime.now())") @Mapping(target = "createdAt", expression = "java(java.time.ZonedDateTime.now())")
@Mapping(target = "createdBy", source = "displayName") @Mapping(target = "createdBy", source = "displayName")
@Mapping(target = "sentAt", expression = "java(message.getResponseTime().toZonedDateTime())") @Mapping(target = "sentAt", expression = "java(message.getResponseTime().toZonedDateTime())")
......
...@@ -2,12 +2,13 @@ package de.ozgcloud.nachrichten.postfach.osiv2; ...@@ -2,12 +2,13 @@ package de.ozgcloud.nachrichten.postfach.osiv2;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -29,14 +30,7 @@ public class OsiPostfachRemoteServiceRemoteITCase { ...@@ -29,14 +30,7 @@ public class OsiPostfachRemoteServiceRemoteITCase {
@Autowired @Autowired
private OsiPostfachRemoteService osiPostfachRemoteService; private OsiPostfachRemoteService osiPostfachRemoteService;
private final PostfachNachricht nachricht = PostfachNachrichtTestFactory.createBuilder() private List<String> initialMessageIds;
.replyOption(PostfachNachricht.ReplyOption.POSSIBLE)
.postfachAddress(PostfachAddressTestFactory.createBuilder()
.identifier(DummyStringBasedIdentifier.builder()
.mailboxId("49b5a7e2-5e60-4baf-8ccf-1f5b94b570f3")
.build())
.build())
.build();
@DynamicPropertySource @DynamicPropertySource
static void dynamicProperties(DynamicPropertyRegistry registry) { static void dynamicProperties(DynamicPropertyRegistry registry) {
...@@ -62,40 +56,56 @@ public class OsiPostfachRemoteServiceRemoteITCase { ...@@ -62,40 +56,56 @@ public class OsiPostfachRemoteServiceRemoteITCase {
throw new IllegalArgumentException("Proxy host and port not found in '%s'".formatted(text)); throw new IllegalArgumentException("Proxy host and port not found in '%s'".formatted(text));
} }
@DisplayName("send message") List<String> fetchPostfachMessagesIds() {
@Nested return osiPostfachRemoteService.getAllMessages()
class TestSendMessage { .map(PostfachNachricht::getMessageId)
.toList();
}
@DisplayName("should not fail") @BeforeEach
@Test void setup() {
void shouldNotFail() { initialMessageIds = fetchPostfachMessagesIds();
assertThatCode(() -> osiPostfachRemoteService.sendMessage(nachricht)) assertThat(initialMessageIds).doesNotContainNull();
.doesNotThrowAnyException();
} }
@AfterEach
void validateMessagesBackAtOriginalState() {
var currentGuids = fetchPostfachMessagesIds();
assertThat(currentGuids).containsExactlyElementsOf(initialMessageIds);
} }
@DisplayName("receive all messages") private PostfachNachricht createNachricht() {
@Nested return PostfachNachrichtTestFactory.createBuilder()
class TestReceiveAllMessages { .replyOption(PostfachNachricht.ReplyOption.POSSIBLE)
.postfachAddress(PostfachAddressTestFactory.createBuilder()
.identifier(DummyStringBasedIdentifier.builder()
.mailboxId("49b5a7e2-5e60-4baf-8ccf-1f5b94b570f3")
.build())
.build())
.build();
}
@DisplayName("should send and receive message without attachment")
@Test @Test
void shouldReceiveAllMessage() { void shouldSendAndReceiveMessage() {
Stream<PostfachNachricht> allMessages = osiPostfachRemoteService.getAllMessages(); var nachricht = createNachricht();
var messages = allMessages.toList(); osiPostfachRemoteService.sendMessage(nachricht);
var messages = osiPostfachRemoteService.getAllMessages().toList();
assertThat(messages).isNotEmpty(); assertThat(messages).isNotEmpty();
}
}
@DisplayName("delete message") var newMessages = messages.stream()
@Nested .filter(m -> !initialMessageIds.contains(m.getMessageId()))
class TestDeleteMessageById { .toList();
assertThat(newMessages).hasSize(1);
@Test var newMessage = newMessages.getFirst();
void shouldDeleteMessage() { assertThat(newMessage.getSubject()).isEqualTo(nachricht.getSubject());
assertThatCode(() -> osiPostfachRemoteService.deleteMessage("5dd65c1e-bd41-4c3d-bf98-be769ca341dc")) assertThat(newMessage.getMailBody()).isEqualTo(nachricht.getMailBody());
.doesNotThrowAnyException(); assertThat(newMessage.getPostfachAddress())
} .isEqualTo(nachricht.getPostfachAddress());
osiPostfachRemoteService.deleteMessage(newMessage.getMessageId());
} }
} }
package de.ozgcloud.nachrichten.postfach.osiv2.factory; package de.ozgcloud.nachrichten.postfach.osiv2.factory;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.UUID;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht; import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
public class PostfachNachrichtTestFactory { public class PostfachNachrichtTestFactory {
public static final String MAIL_BODY = "mail body"; public static final String MAIL_BODY = "Hallo,\n" + LoremIpsum.getInstance().getParagraphs(1, 4);
public static final String MAIL_SUBJECT = "mail subject"; public static final String MAIL_SUBJECT = "AW: " + LoremIpsum.getInstance().getTitle(2, 6);
public static final String VORGANG_ID = "test-vorgang-id"; public static final String VORGANG_ID = "test-vorgang-id";
public static final String USER_ID = "test-user-id"; public static final String USER_ID = "test-user-id";
......
...@@ -17,13 +17,13 @@ public class V1ReplyMessageTestFactory { ...@@ -17,13 +17,13 @@ public class V1ReplyMessageTestFactory {
public static final String REPLY_BODY = """ public static final String REPLY_BODY = """
Das ist das Multiline&&lt;b&gt;a&lt;/b&gt<br><br/> Das ist das Multiline&&lt;b&gt;a&lt;/b&gt<br><br/>
Body"""; Body""";
public static final String MESSAGE_ID = UUID.randomUUID().toString();
private static final String DISPLAY_NAME = "Das ist der Absender"; private static final String DISPLAY_NAME = "Das ist der Absender";
private static final String ORIGIN_SENDER = "das ist der original Sender"; private static final String ORIGIN_SENDER = "das ist der original Sender";
private static final String REPLAY_ACTION = "Replypossible"; private static final String REPLAY_ACTION = "Replypossible";
private static final String EIDAS_LEVEL = "Low"; private static final String EIDAS_LEVEL = "Low";
private static final Boolean IS_OBLIGATORY = Boolean.FALSE; private static final Boolean IS_OBLIGATORY = Boolean.FALSE;
private static final Boolean IS_HTML = Boolean.FALSE; private static final Boolean IS_HTML = Boolean.FALSE;
private static final String GUID = "123-guid-456";
private static final String MESSAGE_BOX = "Mailbox-Id-Antwortender"; private static final String MESSAGE_BOX = "Mailbox-Id-Antwortender";
private static final OffsetDateTime RESPONSE_TIME = OffsetDateTime.now(); private static final OffsetDateTime RESPONSE_TIME = OffsetDateTime.now();
...@@ -38,7 +38,7 @@ public class V1ReplyMessageTestFactory { ...@@ -38,7 +38,7 @@ public class V1ReplyMessageTestFactory {
.eidasLevel(V1EidasLevel.fromValue(EIDAS_LEVEL)) .eidasLevel(V1EidasLevel.fromValue(EIDAS_LEVEL))
.isObligatory(IS_OBLIGATORY) .isObligatory(IS_OBLIGATORY)
.isHtml(IS_HTML) .isHtml(IS_HTML)
.guid(UUID.nameUUIDFromBytes(GUID.getBytes())) .guid(UUID.fromString(MESSAGE_ID))
.messageBox(UUID.nameUUIDFromBytes(MESSAGE_BOX.getBytes())) .messageBox(UUID.nameUUIDFromBytes(MESSAGE_BOX.getBytes()))
.responseTime(RESPONSE_TIME); .responseTime(RESPONSE_TIME);
} }
......
...@@ -3,13 +3,21 @@ package de.ozgcloud.nachrichten.postfach.osiv2.transfer; ...@@ -3,13 +3,21 @@ package de.ozgcloud.nachrichten.postfach.osiv2.transfer;
import static de.ozgcloud.nachrichten.postfach.osiv2.factory.V1ReplyMessageTestFactory.*; import static de.ozgcloud.nachrichten.postfach.osiv2.factory.V1ReplyMessageTestFactory.*;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
...@@ -26,86 +34,93 @@ class Osi2ResponseMapperTest { ...@@ -26,86 +34,93 @@ class Osi2ResponseMapperTest {
@DisplayName("map V1ReplyMessage to PostfachNachricht") @DisplayName("map V1ReplyMessage to PostfachNachricht")
@Nested @Nested
class V1ReplyMessageToPostfachNachricht { class V1ReplyMessageToPostfachNachricht {
@Test
void shouldHaveId() {
var postfachNachricht = mapper.toPostfachNachricht(message);
assertThat(postfachNachricht.getId()).isEqualTo(UUID.nameUUIDFromBytes("123-guid-456".getBytes()).toString());
}
@Test @Test
void shouldHaveVorgangId() { void shouldHaveVorgangId() {
var postfachNachricht = mapper.toPostfachNachricht(message); var result = doMapping();
assertThat(postfachNachricht.getVorgangId()).isEqualTo("OZG-Cloud-VorgangId"); assertThat(result.getVorgangId()).isEqualTo("OZG-Cloud-VorgangId");
} }
@Test @Test
void shouldHavePostfachAddress() { void shouldHavePostfachAddress() {
var postfachNachricht = mapper.toPostfachNachricht(message); var result = doMapping();
assertThat(postfachNachricht.getPostfachAddress().getIdentifier().toString()) assertThat(result.getPostfachAddress().getIdentifier().toString())
.hasToString(UUID.nameUUIDFromBytes("Mailbox-Id-Antwortender".getBytes()).toString()); .hasToString(UUID.nameUUIDFromBytes("Mailbox-Id-Antwortender".getBytes()).toString());
} }
@Test @Test
void shouldHaveCreatedAt() { void shouldHaveCreatedAt() {
var postfachNachricht = mapper.toPostfachNachricht(message); var result = doMapping();
assertThat(postfachNachricht.getCreatedAt()).isNotNull().isCloseTo(ZonedDateTime.now(), within(5, ChronoUnit.SECONDS)); assertThat(result.getCreatedAt()).isNotNull().isCloseTo(ZonedDateTime.now(), within(5, ChronoUnit.SECONDS));
} }
@Test @Test
void shouldHaveCreatedBy() { void shouldHaveCreatedBy() {
var postfachNachricht = mapper.toPostfachNachricht(message); var result = doMapping();
assertThat(postfachNachricht.getCreatedBy()).isEqualTo("Das ist der Absender"); assertThat(result.getCreatedBy()).isEqualTo("Das ist der Absender");
} }
@Test @Test
void shouldHaveSentAt() { void shouldHaveSentAt() {
var postfachNachricht = mapper.toPostfachNachricht(message); var result = doMapping();
assertThat(postfachNachricht.getSentAt()).isNotNull().isCloseTo(ZonedDateTime.now(), within(5, ChronoUnit.SECONDS)); assertThat(result.getSentAt()).isNotNull().isCloseTo(ZonedDateTime.now(), within(5, ChronoUnit.SECONDS));
} }
@Test @Test
void shouldHaveDirection() { void shouldHaveDirection() {
var postfachNachricht = mapper.toPostfachNachricht(message); var result = doMapping();
assertThat(postfachNachricht.getDirection()).isEqualTo(PostfachNachricht.Direction.IN); assertThat(result.getDirection()).isEqualTo(PostfachNachricht.Direction.IN);
} }
@Test @Test
void shouldHaveSubject() { void shouldHaveSubject() {
var postfachNachricht = mapper.toPostfachNachricht(message); var result = doMapping();
assertThat(postfachNachricht.getSubject()).isEqualTo("Das ist das Subject"); assertThat(result.getSubject()).isEqualTo("Das ist das Subject");
} }
@Test @Test
void shouldHaveBody() { void shouldHaveBody() {
var postfachNachricht = mapper.toPostfachNachricht(message); var result = doMapping();
assertThat(postfachNachricht.getMailBody()).isEqualTo(REPLY_BODY); assertThat(result.getMailBody()).isEqualTo(REPLY_BODY);
} }
@Test @Test
void shouldMapHTMLBody() { void shouldMapHTMLBody() {
var postfachNachricht = mapper.toPostfachNachricht(message var htmlMessage = V1ReplyMessageTestFactory.create()
.body(HTML_REPLY_BODY) .body(HTML_REPLY_BODY)
.isHtml(true)); .isHtml(true);
assertThat(postfachNachricht.getMailBody()).isEqualTo(REPLY_BODY); var result = mapper.toPostfachNachricht(htmlMessage);
assertThat(result.getMailBody()).isEqualTo(REPLY_BODY);
} }
@Test @Test
void shouldHaveReplyOption() { void shouldHaveReplyOption() {
var postfachNachricht = mapper.toPostfachNachricht(message); var result = doMapping();
assertThat(result.getReplyOption()).isEqualTo(PostfachNachricht.ReplyOption.POSSIBLE);
}
@DisplayName("should map messageId")
@Test
void shouldMapMessageId() {
var result = doMapping();
assertThat(result.getMessageId()).isEqualTo(MESSAGE_ID);
}
assertThat(postfachNachricht.getReplyOption()).isEqualTo(PostfachNachricht.ReplyOption.POSSIBLE); private PostfachNachricht doMapping() {
return mapper.toPostfachNachricht(message);
} }
// TODO:prüfen das Attachments in der PostfachNachricht enthalten sind
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment