Skip to content
Snippets Groups Projects
Commit 2f3bf4e6 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4109 [fix] don't set empty service konto

parent e49f3531
No related branches found
No related tags found
No related merge requests found
......@@ -151,30 +151,25 @@ class FormDataController {
}
FormData addServiceKonto(FormCycleFormData formData, FormData mappedFormData) {
mappedFormData.getHeader().setServiceKonto(buildServiceKonto(formData.getServiceKonto()));
if (formData.hasServiceKonto()) {
mappedFormData.getHeader().setServiceKonto(buildServiceKonto(formData.getServiceKonto()));
}
return mappedFormData;
}
private ServiceKonto buildServiceKonto(FormCycleServiceKonto formCycleServiceKonto) {
return Optional.ofNullable(formCycleServiceKonto)
.map(sk -> ServiceKonto.builder()
.type(sk.getType())
.postfachAddress(buildPostfachAddress(sk))
.build())
.orElse(null);
ServiceKonto buildServiceKonto(FormCycleServiceKonto formCycleServiceKonto) {
return ServiceKonto.builder()
.type(formCycleServiceKonto.getType())
.postfachAddress(buildPostfachAddress(formCycleServiceKonto))
.build();
}
PostfachAddress buildPostfachAddress(FormCycleServiceKonto formCycleServiceKonto) {
return Optional.ofNullable(formCycleServiceKonto.getAddress())
.map(address -> PostfachAddress.builder()
.identifier(Optional.ofNullable(address)
.map(FormCyclePostfachAddress::getIdentifier)
.map(this::buildPostfachId)
.orElse(null))
.version(address.getVersion())
.build())
.orElse(null);
if (!formCycleServiceKonto.hasAddress()) {
return null;
}
var address = formCycleServiceKonto.getAddress();
return PostfachAddress.builder().identifier(buildPostfachId(address.getIdentifier())).version(address.getVersion()).build();
}
private StringBasedIdentifier buildPostfachId(String identifier) {
......
......@@ -41,6 +41,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
......@@ -59,6 +60,7 @@ import lombok.SneakyThrows;
class FormDataControllerTest {
@Spy
@InjectMocks
private FormDataController controller;
......@@ -293,6 +295,13 @@ class FormDataControllerTest {
assertThat(getServiceKontoType(formData)).isEqualTo(FormCycleServiceKontoTestFactory.TYPE);
}
@Test
void shouldNotMapEmptyServiceKonto() {
controller.addServiceKonto(FormCycleFormData.newBuilder().build(), buildEmptyFormDataWithHeader());
verify(controller, never()).buildServiceKonto(any());
}
String getServiceKontoType(FormData formData) {
return formData.getHeader().getServiceKonto().getType();
}
......@@ -309,9 +318,9 @@ class FormDataControllerTest {
@Test
void shouldNotMapEmptyPostkorbId() {
var formData = controller.addServiceKonto(FormCycleFormData.newBuilder().build(), buildEmptyFormDataWithHeader());
var postfachAddress = controller.buildPostfachAddress(FormCycleServiceKonto.newBuilder().build());
assertThat(getPostfachIdFormData(formData)).isBlank();
assertThat(postfachAddress).isNull();
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment