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