Skip to content
Snippets Groups Projects
Commit e64cde1d authored by Jörg Bolay's avatar Jörg Bolay
Browse files

ResponseMapper um V1ReplyMessage auf Postfach Nachricht zu mappen

parent e0baf89a
No related branches found
No related tags found
1 merge request!6OZG-4095 Testcase deleteMessage implementiert
package de.ozgcloud.nachrichten.postfach.osiv2.transfer;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;
......@@ -8,30 +11,30 @@ import de.ozgcloud.nachrichten.postfach.PostfachAddress;
import de.ozgcloud.nachrichten.postfach.PostfachAddressIdentifier;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.osiv2.OsiPostfachRemoteService;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyBehavior;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyMessage;
import lombok.Builder;
import lombok.Getter;
@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR)
@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR, imports = ZoneOffset.class)
public interface ResponseMapper {
String POSTFACH_ADDRESS_VERSION = "2.0";
int POSTFACH_ADDRESS_TYPE = 2;
@Mapping(target = "id", source = "guid")
@Mapping(target = "postfachAddress", expression = "java(buildPostfachAddressByPostfachId(message.getDisplayName()))")
//@Mapping(target = "postfachAddress", ignore = true)
@Mapping(target = "postfachAddress", expression = "java(buildPostfachAddressByPostfachId(message.getMessageBox().toString()))")
@Mapping(target = "messageId", ignore = true)
@Mapping(target = "createdAt", ignore = true)
@Mapping(target = "createdBy", ignore = true)
@Mapping(target = "sentAt", ignore = true)
@Mapping(target = "createdAt", expression = "java(java.time.ZonedDateTime.now())")
@Mapping(target = "createdBy", source = "displayName")
@Mapping(target = "sentAt", expression = "java(message.getResponseTime().toZonedDateTime())")
@Mapping(target = "sentSuccessful", ignore = true)
@Mapping(target = "messageCode", ignore = true)
@Mapping(target = "direction", constant = "IN")
@Mapping(target = "vorgangId", ignore = true)
@Mapping(target = "vorgangId", source = "sequencenumber")
@Mapping(target = "referencedNachricht", ignore = true)
@Mapping(target = "mailBody", ignore = true)
@Mapping(target = "replyOption", ignore = true)
@Mapping(target = "mailBody", source = "body")
@Mapping(target = "replyOption", source = "replyAction")
@Mapping(target = "attachments", ignore = true)
PostfachNachricht toPostfachNachricht(V1ReplyMessage message);
......@@ -45,6 +48,14 @@ public interface ResponseMapper {
}
default PostfachNachricht.ReplyOption mapReplyAction(V1ReplyBehavior replyOption) {
return switch (replyOption) {
case REPLYFORBIDDEN -> PostfachNachricht.ReplyOption.FORBIDDEN;
case REPLYPOSSIBLE -> PostfachNachricht.ReplyOption.POSSIBLE;
case REPLYMANDATORY -> PostfachNachricht.ReplyOption.MANDATORY;
};
}
@Builder
@Getter
class StringBasedIdentifier implements PostfachAddressIdentifier {
......
......@@ -44,8 +44,8 @@ public static V1ReplyMessageFactory.Builder createBuilder(){
.eidasLevel(EIDAS_LEVEL)
.isObligatory(IS_OLIGATORY)
.isHtml(IS_HTML)
.guid(UUID.fromString(GUID))
.messageBox(UUID.fromString(MESSAGE_BOX))
.guid(UUID.nameUUIDFromBytes(GUID.getBytes()))
.messageBox(UUID.nameUUIDFromBytes(MESSAGE_BOX.getBytes()))
.responseTime(RESPONSE_TIME);
}
......
package de.ozgcloud.nachrichten.postfach.osiv2.transfer;
import static org.assertj.core.api.Assertions.*;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.UUID;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
import org.mockito.InjectMocks;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.osiv2.factory.V1ReplyMessageFactory;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyMessage;
import de.ozgcloud.nachrichten.postfach.osiv2.transfer.ResponseMapper;
class ResponseMapperTest {
@InjectMocks
private ResponseMapper mapper = Mappers.getMapper(ResponseMapper.class);
private V1ReplyMessage message = V1ReplyMessageFactory.create();
@DisplayName("map V1ReplyMessage to PostfachNachricht")
@Nested
class V1ReplyMessageToPostfachNachricht {
@Test
void shouldHaveId(){
// mapper.toPostfachNachricht(V1ReplyMessageFactory.)
var postfachNachricht = mapper.toPostfachNachricht(message);
assertThat(postfachNachricht.getId()).isEqualTo(UUID.nameUUIDFromBytes("123-guid-456".getBytes()).toString());
}
@Test
void shouldHaveVorgangId(){
var postfachNachricht = mapper.toPostfachNachricht(message);
assertThat(postfachNachricht.getVorgangId()).isEqualTo("OZG-Cloud-VorgangId");
}
@Test
void shouldHavePostfachAddress(){
var postfachNachricht = mapper.toPostfachNachricht(message);
assertThat(postfachNachricht.getPostfachAddress().getIdentifier().toString())
.isEqualTo(UUID.nameUUIDFromBytes("Mailbox-Id-Antwortender".getBytes()).toString());
}
@Test
void shouldHaveCreatedAt(){
var postfachNachricht = mapper.toPostfachNachricht(message);
assertThat(postfachNachricht.getCreatedAt()).isNotNull().isCloseTo(ZonedDateTime.now(), within(5, ChronoUnit.SECONDS));
}
@Test
void shouldHaveCreatedBy(){
var postfachNachricht = mapper.toPostfachNachricht(message);
assertThat(postfachNachricht.getCreatedBy()).isEqualTo("Das ist der Absender");
}
@Test
void shouldHaveSentAt(){
var postfachNachricht = mapper.toPostfachNachricht(message);
assertThat(postfachNachricht.getSentAt()).isNotNull().isCloseTo(ZonedDateTime.now(), within(5, ChronoUnit.SECONDS));
}
@Test
void shouldHaveDirection(){
var postfachNachricht = mapper.toPostfachNachricht(message);
assertThat(postfachNachricht.getDirection()).isEqualTo(PostfachNachricht.Direction.IN);
}
@Test
void shouldHaveSubject(){
var postfachNachricht = mapper.toPostfachNachricht(message);
assertThat(postfachNachricht.getSubject()).isEqualTo("Das ist das Subject");
}
@Test
void shouldHaveBody(){
var postfachNachricht = mapper.toPostfachNachricht(message);
assertThat(postfachNachricht.getMailBody()).isEqualTo("""
Das ist das Multiline
Body""");
}
@Test
void shouldHaveReplyOption(){
var postfachNachricht = mapper.toPostfachNachricht(message);
assertThat(postfachNachricht.getReplyOption()).isEqualTo(PostfachNachricht.ReplyOption.POSSIBLE);
}
// 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