diff --git a/semantik-adapter/src/main/java/de/ozgcloud/eingang/semantik/common/ServiceKontoFactory.java b/semantik-adapter/src/main/java/de/ozgcloud/eingang/semantik/common/ServiceKontoFactory.java index f41a76e44d5fc4c10f798ec3769425e08ab79d3a..8f9aa3d8b072f4a71c6f8a21c6d65716a19565b1 100644 --- a/semantik-adapter/src/main/java/de/ozgcloud/eingang/semantik/common/ServiceKontoFactory.java +++ b/semantik-adapter/src/main/java/de/ozgcloud/eingang/semantik/common/ServiceKontoFactory.java @@ -102,7 +102,12 @@ public class ServiceKontoFactory { } int getPostfachAddressType(Map<String, Object> restResponseName) { - return getMailboxType(restResponseName); + try { + return getMailboxType(restResponseName); + } catch (RuntimeException e) { + LOG.error("Error while getting mailbox type from rest response name", e); + return POSTFACH_ADDRESS_DEFAULT; + } } private Integer getMailboxType(Map<String, Object> restResponseName) { diff --git a/semantik-adapter/src/test/java/de/ozgcloud/eingang/semantik/common/ServiceKontoFactoryTest.java b/semantik-adapter/src/test/java/de/ozgcloud/eingang/semantik/common/ServiceKontoFactoryTest.java index 5f9fba08b38624af36a6c29a89c07020233b54e4..c62d3cd37b1d709b2c0e07a5f221733b8a2a03df 100644 --- a/semantik-adapter/src/test/java/de/ozgcloud/eingang/semantik/common/ServiceKontoFactoryTest.java +++ b/semantik-adapter/src/test/java/de/ozgcloud/eingang/semantik/common/ServiceKontoFactoryTest.java @@ -23,6 +23,7 @@ */ package de.ozgcloud.eingang.semantik.common; +import static de.ozgcloud.eingang.semantik.common.ServiceKontoFactory.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -34,6 +35,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.InjectMocks; import org.mockito.Spy; @@ -41,10 +44,10 @@ import de.ozgcloud.eingang.common.formdata.FormData; import de.ozgcloud.eingang.common.formdata.FormDataUtils; import de.ozgcloud.eingang.common.formdata.PostfachAddressTestFactory; import de.ozgcloud.eingang.common.formdata.ServiceKonto; +import de.ozgcloud.eingang.common.formdata.ServiceKonto.PostfachAddress; import de.ozgcloud.eingang.common.formdata.ServiceKonto.TrustLevel; import de.ozgcloud.eingang.common.formdata.ServiceKontoTestFactory; import de.ozgcloud.eingang.common.formdata.StringBasedIdentifier; -import de.ozgcloud.eingang.common.formdata.ServiceKonto.PostfachAddress; class ServiceKontoFactoryTest { @@ -104,8 +107,9 @@ class ServiceKontoFactoryTest { @Nested class TestWithRestResponseName { + @DisplayName("should call buildOsiPostfachV1Address") @Test - void shouldCallBuildAddresses() { + void shouldCallBuildOsiPostfachV1Address() { getPostfachAddresses(); verify(factory).buildOsiPostfachV1Address(any(), anyInt()); @@ -123,11 +127,62 @@ class ServiceKontoFactoryTest { assertThat(addresses.get(0).getType()).isEqualTo(PostfachAddressTestFactory.POSTFACH_ADDRESS_TYPE); } + @DisplayName("should return with postfach address type") + @ParameterizedTest + @ValueSource(ints = { 1, 2, 3 }) + void shouldReturnWithPostfachAddressType(int postfachAddressType) { + var formDataWithPostfachAddressType = FormDataUtils.from(FORM_DATA) + .put(ServiceKontoFactory.REST_RESPONSE_NAME, List.of(Map.of( + ServiceKontoFactory.REST_RESPONSE_NAME_MEMBER_SCOPE, + List.of(Map.of(ServiceKontoFactory.REST_RESPONSE_NAME_MEMBER_SCOPE_MAILBOX_TYPE, + postfachAddressType)))) + ) + .build(); + + var addresses = buildServiceKonto(formDataWithPostfachAddressType); + + var types = addresses.getPostfachAddresses() + .stream() + .map(PostfachAddress::getType) + .toList(); + assertThat(types).containsExactly(postfachAddressType); + } + private List<PostfachAddress> getPostfachAddresses() { return buildServiceKonto(FORM_DATA).getPostfachAddresses(); } } + @DisplayName("with bad rest_response_name") + @Nested + class TestWithBadRestResponseName { + + private final FormData formDataWithBadRestResponseName = FormDataUtils.from(FORM_DATA) + .put(ServiceKontoFactory.REST_RESPONSE_NAME, List.of(Map.of())).build(); + + @DisplayName("should call buildOsiPostfachV1Address") + @Test + void shouldCallBuildOsiPostfachV1Address() { + getPostfachAddresses(); + + verify(factory).buildOsiPostfachV1Address(any(), anyInt()); + } + + @DisplayName("should return postfach address with default type") + @Test + void shouldReturnPostfachAddressWithDefaultType() { + var addresses = getPostfachAddresses(); + + assertThat(addresses) + .extracting("type") + .containsExactly(POSTFACH_ADDRESS_DEFAULT); + } + + private List<PostfachAddress> getPostfachAddresses() { + return buildServiceKonto(formDataWithBadRestResponseName).getPostfachAddresses(); + } + } + @DisplayName("without rest_response_name") @Nested class TestWithoutRestResponseName {