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

OZG-4095 receive: Avoid exception on any null value

parent 84d389ec
No related branches found
No related tags found
1 merge request!13Ozg 4095 abrufen stage test
Pipeline #1626 passed
...@@ -51,12 +51,11 @@ public interface Osi2ResponseMapper { ...@@ -51,12 +51,11 @@ public interface Osi2ResponseMapper {
@Named("mapOffsetDateTimeToZoned") @Named("mapOffsetDateTimeToZoned")
default ZonedDateTime mapOffsetDateTimeToZoned(OffsetDateTime offsetDateTime) { default ZonedDateTime mapOffsetDateTimeToZoned(OffsetDateTime offsetDateTime) {
return offsetDateTime.toZonedDateTime(); return offsetDateTime == null ? null : offsetDateTime.toZonedDateTime();
} }
@Named("mapMailBody") @Named("mapMailBody")
default String mapMailBody(V1ReplyMessage message) { default String mapMailBody(V1ReplyMessage message) {
// According to the API spec `body` is nullable
var body = mapNullToEmpty(message.getBody()); var body = mapNullToEmpty(message.getBody());
return Boolean.TRUE.equals(message.getIsHtml()) return Boolean.TRUE.equals(message.getIsHtml())
? Osi2HtmlDocument.renderToPlainText(body) ? Osi2HtmlDocument.renderToPlainText(body)
...@@ -64,7 +63,9 @@ public interface Osi2ResponseMapper { ...@@ -64,7 +63,9 @@ public interface Osi2ResponseMapper {
} }
default PostfachAddress buildPostfachAddressByPostfachId(UUID messageBox) { default PostfachAddress buildPostfachAddressByPostfachId(UUID messageBox) {
return PostfachAddress.builder() return messageBox == null
? null
: PostfachAddress.builder()
.type(POSTFACH_ADDRESS_TYPE) .type(POSTFACH_ADDRESS_TYPE)
.version(POSTFACH_ADDRESS_VERSION) .version(POSTFACH_ADDRESS_VERSION)
.identifier(StringBasedIdentifier.builder() .identifier(StringBasedIdentifier.builder()
...@@ -76,7 +77,9 @@ public interface Osi2ResponseMapper { ...@@ -76,7 +77,9 @@ public interface Osi2ResponseMapper {
} }
default PostfachNachricht.ReplyOption mapReplyAction(V1ReplyBehavior replyOption) { default PostfachNachricht.ReplyOption mapReplyAction(V1ReplyBehavior replyOption) {
return switch (replyOption) { return replyOption == null
? PostfachNachricht.ReplyOption.FORBIDDEN
: switch (replyOption) {
case REPLYFORBIDDEN -> PostfachNachricht.ReplyOption.FORBIDDEN; case REPLYFORBIDDEN -> PostfachNachricht.ReplyOption.FORBIDDEN;
case REPLYPOSSIBLE -> PostfachNachricht.ReplyOption.POSSIBLE; case REPLYPOSSIBLE -> PostfachNachricht.ReplyOption.POSSIBLE;
case REPLYMANDATORY -> PostfachNachricht.ReplyOption.MANDATORY; case REPLYMANDATORY -> PostfachNachricht.ReplyOption.MANDATORY;
......
...@@ -102,7 +102,8 @@ class Osi2ResponseMapperTest { ...@@ -102,7 +102,8 @@ class Osi2ResponseMapperTest {
return Stream.of( return Stream.of(
Arguments.of(V1ReplyBehavior.REPLYPOSSIBLE, PostfachNachricht.ReplyOption.POSSIBLE), Arguments.of(V1ReplyBehavior.REPLYPOSSIBLE, PostfachNachricht.ReplyOption.POSSIBLE),
Arguments.of(V1ReplyBehavior.REPLYMANDATORY, PostfachNachricht.ReplyOption.MANDATORY), Arguments.of(V1ReplyBehavior.REPLYMANDATORY, PostfachNachricht.ReplyOption.MANDATORY),
Arguments.of(V1ReplyBehavior.REPLYFORBIDDEN, PostfachNachricht.ReplyOption.FORBIDDEN) Arguments.of(V1ReplyBehavior.REPLYFORBIDDEN, PostfachNachricht.ReplyOption.FORBIDDEN),
Arguments.of(null, PostfachNachricht.ReplyOption.FORBIDDEN)
); );
} }
...@@ -126,6 +127,25 @@ class Osi2ResponseMapperTest { ...@@ -126,6 +127,25 @@ class Osi2ResponseMapperTest {
assertThat(result.getMessageId()).isEqualTo(MESSAGE_ID); assertThat(result.getMessageId()).isEqualTo(MESSAGE_ID);
} }
@DisplayName("should not fail if all fields are null")
@Test
void shouldNotFailIfAllFieldsAreNull() {
var nullMessage = new V1ReplyMessage();
assertThatCode(() -> mapper.toPostfachNachricht(nullMessage))
.doesNotThrowAnyException();
}
@DisplayName("should not fail if all fields are null and isHtml")
@Test
void shouldNotFailIfAllFieldsAreNullAndIsHtml() {
var nullMessage = new V1ReplyMessage()
.isHtml(true);
assertThatCode(() -> mapper.toPostfachNachricht(nullMessage))
.doesNotThrowAnyException();
}
private PostfachNachricht doMapping() { private PostfachNachricht doMapping() {
return mapper.toPostfachNachricht(message); return mapper.toPostfachNachricht(message);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment