Skip to content
Snippets Groups Projects
Commit 6319c072 authored by OZG-Cloud Team's avatar OZG-Cloud Team
Browse files

OZG-6636 set serviceKonto to null if no postfachAddress exists

parent a8652d25
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,8 @@ public class FormHeaderTestFactory {
public static final String CREATED_AT_STR = "2024-04-01T01:00:30Z";
public static final ZonedDateTime CREATED_AT = ZonedDateTime.parse(CREATED_AT_STR);
public static final ServiceKonto SERVICE_KONTO = ServiceKontoTestFactory.create();
public static FormHeader create() {
return createBuilder().build();
}
......@@ -53,7 +55,7 @@ public class FormHeaderTestFactory {
.formId(FORM_ID)
.formName(FORM_NAME)
.sender(SENDER)
.serviceKonto(ServiceKontoTestFactory.create());
.serviceKonto(SERVICE_KONTO);
}
}
......@@ -48,6 +48,17 @@ public class VorgangService {
}
FormData preserveConsistency(FormData formData) {
return null;
if (hasNoPostfachAddress(formData)) {
return clearServiceKonto(formData);
}
return formData;
}
private boolean hasNoPostfachAddress(FormData formData) {
return formData.getHeader().getServiceKonto().getPostfachAddresses().isEmpty();
}
private FormData clearServiceKonto(FormData formData) {
return formData.toBuilder().header(formData.getHeader().toBuilder().serviceKonto(null).build()).build();
}
}
\ No newline at end of file
......@@ -23,6 +23,7 @@
*/
package de.ozgcloud.eingang.router;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Optional;
......@@ -37,6 +38,10 @@ import org.mockito.Spy;
import de.ozgcloud.eingang.common.formdata.FormData;
import de.ozgcloud.eingang.common.formdata.FormDataTestFactory;
import de.ozgcloud.eingang.common.formdata.FormHeader;
import de.ozgcloud.eingang.common.formdata.FormHeaderTestFactory;
import de.ozgcloud.eingang.common.formdata.ServiceKonto;
import de.ozgcloud.eingang.common.formdata.ServiceKontoTestFactory;
import de.ozgcloud.eingang.common.formdata.ZustaendigeStelleTestFactory;
class VorgangServiceTest {
......@@ -84,10 +89,24 @@ class VorgangServiceTest {
@Nested
class TestPreserveConsistency {
private final ServiceKonto serviceKonto = ServiceKontoTestFactory.createBuilder().clearPostfachAddresses().build();
private final FormHeader header = FormHeaderTestFactory.createBuilder().serviceKonto(serviceKonto).build();
private final FormData formData = FormDataTestFactory.createBuilder().header(header).build();
@DisplayName("should set serviceKonto to null if no postfachAddress exists")
@Test
void shouldSetServiceKontoToNull() {
var consistentFormData = service.preserveConsistency(formData);
assertThat(consistentFormData.getHeader().getServiceKonto()).isNull();
}
@DisplayName("should keep serviceKonto if postfachAddress eixsts")
@Test
void shouldKeepServiceKonto() {
var consistentFormData = service.preserveConsistency(FormDataTestFactory.create());
assertThat(consistentFormData.getHeader().getServiceKonto()).isEqualTo(FormHeaderTestFactory.SERVICE_KONTO);
}
}
}
\ 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