diff --git a/semantik-adapter/src/main/java/de/ozgcloud/eingang/semantik/enginebased/ServiceKontoBuildHelper.java b/semantik-adapter/src/main/java/de/ozgcloud/eingang/semantik/enginebased/ServiceKontoBuildHelper.java index 2cb43a42151681c158ec08a23e12da10f918cb29..1ec87a0e456865b00b7edbddf0834dad0f8e9948 100644 --- a/semantik-adapter/src/main/java/de/ozgcloud/eingang/semantik/enginebased/ServiceKontoBuildHelper.java +++ b/semantik-adapter/src/main/java/de/ozgcloud/eingang/semantik/enginebased/ServiceKontoBuildHelper.java @@ -18,7 +18,8 @@ import de.ozgcloud.eingang.common.formdata.ServiceKonto.PostfachAddress; public class ServiceKontoBuildHelper { public static final int POSTFACH_ADDRESS_DEFAULT = 1; - public static final String POSTFACH_TYPE = "OSI"; + public static final String POSTFACH_TYPE_OSI = "OSI"; + public static final String POSTFACH_TYPE_BAYERN_ID = "BayernID"; public static final String POSTFACH_VERSION = "1.0"; public static final String REST_RESPONSE_NAME = "rest_response_name"; @@ -37,7 +38,7 @@ public class ServiceKontoBuildHelper { } ServiceKonto buildDefault(String postfachId) { - return ServiceKonto.builder().type(POSTFACH_TYPE).postfachAddress(buildPostfachAddress(postfachId)).build(); + return ServiceKonto.builder().type(POSTFACH_TYPE_OSI).postfachAddress(buildPostfachAddress(postfachId)).build(); } @SuppressWarnings("unchecked") @@ -50,31 +51,27 @@ public class ServiceKontoBuildHelper { ServiceKonto buildWithRestResponseNames(String postfachId, List<Map<String, Object>> restResponseNames) { return ServiceKonto.builder() - .type(POSTFACH_TYPE) + .type(POSTFACH_TYPE_OSI) .postfachAddresses(buildPostfachAddresses(buildIdentifier(postfachId), restResponseNames)) .build(); } - private PostfachAddressIdentifier buildIdentifier(String postfachId) { - return StringBasedIdentifier.builder().postfachId(postfachId).build(); - } - List<PostfachAddress> buildPostfachAddresses(PostfachAddressIdentifier identifier, List<Map<String, Object>> restResponseNames) { return restResponseNames.stream().map(entry -> buildOsiPostfachV1Address(identifier, entry)).toList(); } - private PostfachAddress buildPostfachAddress(String postkorbHandle) { + PostfachAddress buildOsiPostfachV1Address(PostfachAddressIdentifier identifier, Map<String, Object> restResponseName) { + return buildOsiPostfachV1Address(identifier, getPostfachAddressType(restResponseName)); + } + + PostfachAddress buildOsiPostfachV1Address(PostfachAddressIdentifier identifier, int postfachAddressType) { return PostfachAddress.builder() - .type(POSTFACH_ADDRESS_DEFAULT) + .type(postfachAddressType) .version(POSTFACH_VERSION) - .identifier(buildIdentifier(postkorbHandle)) + .identifier(identifier) .build(); } - PostfachAddress buildOsiPostfachV1Address(PostfachAddressIdentifier identifier, Map<String, Object> restResponseName) { - return buildOsiPostfachV1Address(identifier, getPostfachAddressType(restResponseName)); - } - int getPostfachAddressType(Map<String, Object> restResponseName) { return getMailboxType(restResponseName); } @@ -88,11 +85,20 @@ public class ServiceKontoBuildHelper { return ((List<Map<String, Object>>) restResponseName.get(REST_RESPONSE_NAME_MEMBER_SCOPE)).get(0); } - PostfachAddress buildOsiPostfachV1Address(PostfachAddressIdentifier identifier, int postfachAddressType) { + public ServiceKonto buildBayernIdServiceKonto(String postfachId) { + return ServiceKonto.builder().type(POSTFACH_TYPE_BAYERN_ID).postfachAddress(buildPostfachAddress(postfachId)).build(); + } + + PostfachAddress buildPostfachAddress(String postkorbHandle) { return PostfachAddress.builder() - .type(postfachAddressType) + .type(POSTFACH_ADDRESS_DEFAULT) .version(POSTFACH_VERSION) - .identifier(identifier) + .identifier(buildIdentifier(postkorbHandle)) .build(); } + + private PostfachAddressIdentifier buildIdentifier(String postfachId) { + return StringBasedIdentifier.builder().postfachId(postfachId).build(); + } + } \ No newline at end of file diff --git a/semantik-adapter/src/test/java/de/ozgcloud/eingang/semantik/enginebased/ServiceKontoBuildHelperTest.java b/semantik-adapter/src/test/java/de/ozgcloud/eingang/semantik/enginebased/ServiceKontoBuildHelperTest.java index 3f9a6243a7856e2c4abab007c66551c766bd5b40..8d49520d80e2d2ef27042b0dc2399202e44466c9 100644 --- a/semantik-adapter/src/test/java/de/ozgcloud/eingang/semantik/enginebased/ServiceKontoBuildHelperTest.java +++ b/semantik-adapter/src/test/java/de/ozgcloud/eingang/semantik/enginebased/ServiceKontoBuildHelperTest.java @@ -10,6 +10,7 @@ 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.mockito.InjectMocks; import org.mockito.Spy; import de.ozgcloud.eingang.common.formdata.FormData; @@ -23,11 +24,12 @@ import de.ozgcloud.eingang.semantik.enginebased.afm.AfmHeaderTestFactory; class ServiceKontoBuildHelperTest { @Spy - private ServiceKontoBuildHelper helper = new ServiceKontoBuildHelper(); + @InjectMocks + private ServiceKontoBuildHelper helper; - @DisplayName("service konto") + @DisplayName("OSI service konto") @Nested - class TestServiceKonto { + class TestOsiServiceKonto { private static final FormData FORM_DATA = FormData.builder().formData(AfmHeaderTestFactory.createFormDataMap()).build(); @@ -46,7 +48,7 @@ class ServiceKontoBuildHelperTest { void shouldContainsType() { var serviceKonto = getServiceKonto(FORM_DATA); - assertThat(serviceKonto.getType()).isEqualTo(ServiceKontoBuildHelper.POSTFACH_TYPE); + assertThat(serviceKonto.getType()).isEqualTo(ServiceKontoBuildHelper.POSTFACH_TYPE_OSI); } @Test @@ -139,4 +141,31 @@ class ServiceKontoBuildHelperTest { } } } + + @Nested + class TestBayernIdServiceKonto { + + private static final String POSTFACH_ID = "postfach-id"; + private static final PostfachAddress POSTFACH_ADDRESS = PostfachAddressTestFactory.create(); + + @Test + void shouldSetType() { + var serviceKonto = buildBayernIdServiceKonto(); + + assertThat(serviceKonto.getType()).isEqualTo(ServiceKontoBuildHelper.POSTFACH_TYPE_BAYERN_ID); + } + + @Test + void shouldSetPostfachAddress() { + doReturn(POSTFACH_ADDRESS).when(helper).buildPostfachAddress(any()); + + var serviceKonto = buildBayernIdServiceKonto(); + + assertThat(serviceKonto.getPostfachAddresses()).containsOnly(POSTFACH_ADDRESS); + } + + ServiceKonto buildBayernIdServiceKonto() { + return helper.buildBayernIdServiceKonto(POSTFACH_ID); + } + } } \ No newline at end of file