Skip to content
Snippets Groups Projects
Commit 6fcd324f authored by OZGCloud's avatar OZGCloud
Browse files

Merge pull request 'OZG-5666-FixAttachmentMapping' (#11) from...

Merge pull request 'OZG-5666-FixAttachmentMapping' (#11) from OZG-5666-FixAttachmentMapping into master

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/nachrichten-manager/pulls/11


Reviewed-by: default avatarOZGCloud <ozgcloud@mgm-tp.com>
parents b30289af 7e594fe5
No related branches found
No related tags found
No related merge requests found
......@@ -87,7 +87,7 @@ public abstract class PostfachNachrichtMapper {
.setSubject(MapUtils.getString(mailMap, PostfachNachricht.FIELD_SUBJECT))
.setMailBody(MapUtils.getString(mailMap, PostfachNachricht.FIELD_MAIL_BODY))
.setReplyOption(MapUtils.getString(mailMap, PostfachNachricht.FIELD_REPLY_OPTION))
.addAllAttachment((Iterable<String>) mailMap.getOrDefault(PostfachNachricht.FIELD_ATTACHMENTS, Collections.emptyList()));
.addAllAttachment(getAttachments(mailMap));
Optional.ofNullable(getAsMap(mailMap, PostfachNachricht.POSTFACH_ADDRESS_FIELD))
.filter(MapUtils::isNotEmpty)
......@@ -97,6 +97,15 @@ public abstract class PostfachNachrichtMapper {
return postfachMailBuilder.build();
}
private Iterable<String> getAttachments(Map<String, Object> map) {
var attachments = map.getOrDefault(PostfachNachricht.FIELD_ATTACHMENTS, Collections.emptyList());
if (attachments instanceof String attachment) {
return Collections.singletonList(attachment);
}
return (Iterable<String>) attachments;
}
GrpcPostfachAddress buildGrpcPostfachAddress(Map<String, Object> postfachAddressMap) {
var postfachAddressBuilder = GrpcPostfachAddress.newBuilder()
.setType(MapUtils.getIntValue(postfachAddressMap, PostfachAddress.TYPE_FIELD))
......
......@@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.Map;
import java.util.UUID;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
......@@ -115,6 +116,15 @@ class PostfachNachrichtMapperTest {
var fieldValue = getAttributeFromGrpcObject(mapped, fieldName);
assertThat((String) fieldValue).isEmpty();
}
@Test
void shouldProceedWithSingleAttachment() {
var postfachNachrichtMap = PostfachNachrichtTestFactory.asMap();
postfachNachrichtMap.put(PostfachNachricht.FIELD_ATTACHMENTS, UUID.randomUUID().toString());
assertDoesNotThrow(() -> fromMap(postfachNachrichtMap));
}
}
@DisplayName("with missing postfachAddress")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment