Skip to content
Snippets Groups Projects
Commit 4a902725 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-3260 fix/cleanup FormSolutionsZustaendigeStelleMapper

parent 07fc15b0
Branches
Tags
No related merge requests found
......@@ -23,6 +23,7 @@
*/
package de.itvsh.kop.eingangsadapter.semantik.enginebased;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
......@@ -33,20 +34,31 @@ import de.itvsh.kop.eingangsadapter.common.formdata.ZustaendigeStelle;
@Component
public class FormSolutionsZustaendigeStelleMapper implements FormSolutionsEngineBasedMapper {
public static final String ZUSTAENDIGE_STELLE = "zustaendigeStelle";
@Override
public FormData parseFormData(FormData formData) {
var zustaendigeStelle = ZustaendigeStelle.builder().organisationseinheitenId((String) formData.getFormData().get(ZUSTAENDIGE_STELLE)).build();
return formData.toBuilder()
.zustaendigeStelle(buildZustaendigeStelle(formData))
.formData(removeProcessedData(formData))
.build();
}
var cleanData = removeZustaendigeStelle(formData);
ZustaendigeStelle buildZustaendigeStelle(FormData formData) {
return ZustaendigeStelle.builder()
.organisationseinheitenId(getZustaenigeStelle(formData))
.build();
}
return formData.toBuilder().zustaendigeStelle(zustaendigeStelle).formData(cleanData).build();
private String getZustaenigeStelle(FormData formData) {
return (String) formData.getFormData().get(ZUSTAENDIGE_STELLE);
}
private Map<String, Object> removeZustaendigeStelle(FormData formData) {
var cleanedData = new HashMap<>(formData.getFormData());
Map<String, Object> removeProcessedData(FormData formData) {
var cleanedData = new HashMap<String, Object>(formData.getFormData());
cleanedData.remove(ZUSTAENDIGE_STELLE);
return cleanedData;
return Collections.unmodifiableMap(cleanedData);
}
}
}
\ No newline at end of file
......@@ -26,28 +26,73 @@ package de.itvsh.kop.eingangsadapter.semantik.enginebased;
import static de.itvsh.kop.eingangsadapter.common.formdata.ZustaendigsStelleTestFactory.*;
import static de.itvsh.kop.eingangsadapter.semantik.enginebased.FormSolutionsZustaendigeStelleMapper.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.Spy;
import de.itvsh.kop.eingangsadapter.common.formdata.FormData;
class FormSolutionsZustaendigeStelleMapperTest {
private FormSolutionsZustaendigeStelleMapper mapper = new FormSolutionsZustaendigeStelleMapper();
@Spy
private final FormSolutionsZustaendigeStelleMapper mapper = new FormSolutionsZustaendigeStelleMapper();
@DisplayName("Parse formData")
@Nested
class TestZustaendigeStelleMapping {
class TestParseFormData {
private final FormData formData = FormSolutionsZustaendigeStelleTestFactory.create();
@Test
void shouldParseOrgansisationeinheitenId() {
var formData = mapper.parseFormData(FormSolutionsZustaendigeStelleTestFactory.create());
void shouldCallBuildZustaendigeStelle() {
parseFormData();
assertThat(formData.getZustaendigeStelle().getOrganisationseinheitenId())
.isEqualTo(ORGANISATIONSEINHEIT_ID);
verify(mapper).buildZustaendigeStelle(formData);
}
@Test
void shouldRemove() {
var formData = mapper.parseFormData(FormSolutionsZustaendigeStelleTestFactory.create());
void shouldCallRemoveProcessedData() {
parseFormData();
verify(mapper).removeProcessedData(formData);
}
@Test
void shouldReturnValue() {
var result = parseFormData();
assertThat(result).usingRecursiveComparison().ignoringFields("zustaendigeStelle", "formData").isEqualTo(formData);
}
private FormData parseFormData() {
return mapper.parseFormData(formData);
}
@DisplayName("build zustaendigeStelle")
@Nested
class TestBuildZustaendigeStelle {
@Test
void shouldHaveOrganisationseinheitenId() {
var zustaendigeStelle = mapper.buildZustaendigeStelle(formData);
assertThat(zustaendigeStelle.getOrganisationseinheitenId()).isEqualTo(ORGANISATIONSEINHEIT_ID);
}
}
@DisplayName("remove processed data")
@Nested
class TestRemoveProcessedData {
@Test
void shouldRemoveZustaendigeStelle() {
var cleanedFormData = mapper.removeProcessedData(formData);
assertThat(formData.getFormData().get(ZUSTAENDIGE_STELLE)).isNull();
assertThat(cleanedFormData).doesNotContainKey(ZUSTAENDIGE_STELLE);
}
}
}
}
}
\ No newline at end of file
......@@ -30,12 +30,13 @@ import java.util.Map;
import de.itvsh.kop.eingangsadapter.common.formdata.FormData;
public class FormSolutionsZustaendigeStelleTestFactory {
public static FormData create() {
return createBuilder().build();
}
public static FormData.FormDataBuilder createBuilder() {
return FormData.builder().formData(Map.of(FormSolutionsZustaendigeStelleMapper.ZUSTAENDIGE_STELLE, ORGANISATIONSEINHEIT_ID));
return FormData.builder()
.formData(Map.of(FormSolutionsZustaendigeStelleMapper.ZUSTAENDIGE_STELLE, ORGANISATIONSEINHEIT_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