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

OZG-4094 postfach-nachricht: Fix reading PostfachAddress

parent 3c2bbafc
No related branches found
No related tags found
1 merge request!2OZG-4094 osi2 postfach facade
...@@ -239,7 +239,7 @@ public abstract class PostfachNachrichtMapper { ...@@ -239,7 +239,7 @@ public abstract class PostfachNachrichtMapper {
} }
private Map<String, Object> buildPostfachAddressIdentifierMap(PostfachAddress postfachAddress) { private Map<String, Object> buildPostfachAddressIdentifierMap(PostfachAddress postfachAddress) {
var identifier = (StringBasedIdentifier) postfachAddress.getIdentifier(); var identifier = postfachAddress.getIdentifier();
return Map.of(PostfachAddress.FIELD_POSTFACH_ID, identifier.getPostfachId()); return Map.of(PostfachAddress.FIELD_POSTFACH_ID, identifier.isStringBasedIdentifier() ? identifier.toString() : "");
} }
} }
\ No newline at end of file
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
package de.ozgcloud.nachrichten.postfach; package de.ozgcloud.nachrichten.postfach;
import static de.ozgcloud.nachrichten.postfach.StringBasedIdentifierTestFactory.*;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
...@@ -338,6 +339,40 @@ class PostfachNachrichtMapperTest { ...@@ -338,6 +339,40 @@ class PostfachNachrichtMapperTest {
assertDoesNotThrow(() -> mapper.mapToMap(postfachMail)); assertDoesNotThrow(() -> mapper.mapToMap(postfachMail));
} }
@DisplayName("should map non string based identifier to empty")
@Test
void shouldMapNonStringBasedIdentifierToEmpty() {
var postfachMail = PostfachNachrichtTestFactory.createBuilder()
.postfachAddress(PostfachAddressTestFactory.createBuilder()
.identifier(new PostfachAddressIdentifier() {
})
.build()
).build();
var postfachId = mapPostfachId(postfachMail);
assertThat(postfachId).isEmpty();
}
@DisplayName("should map string based identifier")
@Test
void shouldMapStringBasedIdentifier() {
var postfachMail = PostfachNachrichtTestFactory.create();
var postfachId = mapPostfachId(postfachMail);
assertThat(postfachId).isEqualTo(STRING_BASED_IDENTIFIER_POSTFACH_ID_VALUE);
}
@SuppressWarnings("unchecked")
private String mapPostfachId(PostfachNachricht nachricht) {
var result = mapper.mapToMap(nachricht);
var postfachAddress = (Map<String, Object>) result.get(PostfachNachricht.POSTFACH_ADDRESS_FIELD);
var postfachIdentifier = (Map<String, Object>) postfachAddress.get(PostfachAddress.IDENTIFIER_FIELD);
return (String) postfachIdentifier.get(PostfachAddress.FIELD_POSTFACH_ID);
}
@Test @Test
void shouldProceedWithEmptyPostfachAddress() { void shouldProceedWithEmptyPostfachAddress() {
var postfachMail = PostfachNachrichtTestFactory.createBuilder().postfachAddress(null).build(); var postfachMail = PostfachNachrichtTestFactory.createBuilder().postfachAddress(null).build();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment