Skip to content
Snippets Groups Projects
Commit 03ff2d12 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4797 build bayernId service konto

(cherry picked from commit 94d8f7dc75294b42d2828cf40fbd774aa15746ee)
parent e88f438a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment