Skip to content
Snippets Groups Projects
Commit 841df6d7 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5323 set default for missing nachrichtSubject/nachrichtText

parent 32e7012f
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
package de.ozgcloud.document; package de.ozgcloud.document;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
...@@ -32,6 +33,7 @@ import de.ozgcloud.bescheid.attacheditem.AttachedItem; ...@@ -32,6 +33,7 @@ import de.ozgcloud.bescheid.attacheditem.AttachedItem;
@Mapper @Mapper
interface DocumentMapper { interface DocumentMapper {
@Mapping(target = "allFields", ignore = true)
@Mapping(target = "unknownFields", ignore = true) @Mapping(target = "unknownFields", ignore = true)
@Mapping(target = "typeBytes", ignore = true) @Mapping(target = "typeBytes", ignore = true)
@Mapping(target = "nachrichtTextBytes", ignore = true) @Mapping(target = "nachrichtTextBytes", ignore = true)
...@@ -49,8 +51,8 @@ interface DocumentMapper { ...@@ -49,8 +51,8 @@ interface DocumentMapper {
.id(attachedItem.getId()) .id(attachedItem.getId())
.type(MapUtils.getString(attachedItem.getItem(), Document.FIELD_DOCUMENT_TYPE)) .type(MapUtils.getString(attachedItem.getItem(), Document.FIELD_DOCUMENT_TYPE))
.fileId(MapUtils.getString(attachedItem.getItem(), Document.FIELD_DOCUMENT_FILE)) .fileId(MapUtils.getString(attachedItem.getItem(), Document.FIELD_DOCUMENT_FILE))
.nachrichtText(MapUtils.getString(attachedItem.getItem(), Document.FIELD_NACHRICHT_TEXT)) .nachrichtText(MapUtils.getString(attachedItem.getItem(), Document.FIELD_NACHRICHT_TEXT, StringUtils.EMPTY))
.nachrichtSubject(MapUtils.getString(attachedItem.getItem(), Document.FIELD_NACHRICHT_SUBJECT)) .nachrichtSubject(MapUtils.getString(attachedItem.getItem(), Document.FIELD_NACHRICHT_SUBJECT, StringUtils.EMPTY))
.build(); .build();
} }
} }
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
package de.ozgcloud.bescheid.attacheditem; package de.ozgcloud.bescheid.attacheditem;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -65,19 +66,22 @@ public class AttachedItemTestFactory { ...@@ -65,19 +66,22 @@ public class AttachedItemTestFactory {
} }
public static AttachedItem createDocument() { public static AttachedItem createDocument() {
return createDocumentBuilder().build();
}
public static AttachedItem.AttachedItemBuilder createDocumentBuilder() {
return createBuilder() return createBuilder()
.itemName(DocumentService.DOCUMENT_ITEM_NAME) .itemName(DocumentService.DOCUMENT_ITEM_NAME)
.item(createDocumentItem()) .item(createDocumentItem());
.build();
} }
public static Map<String, Object> createDocumentItem() { public static HashMap<String, Object> createDocumentItem() {
return Map.of( var map = new HashMap<String, Object>();
Document.FIELD_DOCUMENT_TYPE, DocumentService.DOCUMENT_TYPE, map.put(Document.FIELD_DOCUMENT_TYPE, DocumentService.DOCUMENT_TYPE);
Document.FIELD_DOCUMENT_FILE, DocumentTestFactory.DOCUMENT_FILE, map.put(Document.FIELD_DOCUMENT_FILE, DocumentTestFactory.DOCUMENT_FILE);
Document.FIELD_NACHRICHT_TEXT, DocumentTestFactory.NACHRICHT_TEXT, map.put(Document.FIELD_NACHRICHT_TEXT, DocumentTestFactory.NACHRICHT_TEXT);
Document.FIELD_NACHRICHT_SUBJECT, DocumentTestFactory.NACHRICHT_SUBJECT map.put(Document.FIELD_NACHRICHT_SUBJECT, DocumentTestFactory.NACHRICHT_SUBJECT);
); return map;
} }
public static AttachedItemBuilder createBuilder() { public static AttachedItemBuilder createBuilder() {
......
...@@ -25,13 +25,22 @@ package de.ozgcloud.document; ...@@ -25,13 +25,22 @@ package de.ozgcloud.document;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import org.apache.commons.lang3.StringUtils;
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.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import de.ozgcloud.bescheid.attacheditem.AttachedItemTestFactory;
class DocumentMapperTest { class DocumentMapperTest {
private DocumentMapper mapper = Mappers.getMapper(DocumentMapper.class); private DocumentMapper mapper = Mappers.getMapper(DocumentMapper.class);
@DisplayName("To grpc document")
@Nested
class TestToGrpcDocument {
@Test @Test
void shouldMapDocument() { void shouldMapDocument() {
var result = mapper.toGrpcDocument(DocumentTestFactory.create()); var result = mapper.toGrpcDocument(DocumentTestFactory.create());
...@@ -40,3 +49,31 @@ class DocumentMapperTest { ...@@ -40,3 +49,31 @@ class DocumentMapperTest {
} }
} }
@DisplayName("From attached item")
@Nested
class TestFromAttachedItem {
@Test
void shouldMapMissingNachrichtSubjectToEmptyString() {
var documentItem = AttachedItemTestFactory.createDocumentItem();
documentItem.remove(Document.FIELD_NACHRICHT_SUBJECT);
var document = AttachedItemTestFactory.createDocumentBuilder().item(documentItem).build();
var result = mapper.fromAttacheItem(document);
assertThat(result.getNachrichtSubject()).isEqualTo(StringUtils.EMPTY);
}
@Test
void shouldMapMissingNachrichtTextToEmptyString() {
var documentItem = AttachedItemTestFactory.createDocumentItem();
documentItem.remove(Document.FIELD_NACHRICHT_TEXT);
var document = AttachedItemTestFactory.createDocumentBuilder().item(documentItem).build();
var result = mapper.fromAttacheItem(document);
assertThat(result.getNachrichtText()).isEqualTo(StringUtils.EMPTY);
}
}
}
\ 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