Skip to content
Snippets Groups Projects
Commit 4231dc5f authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5651 add tests for firm antragsteller

parent b8e1fa8f
No related branches found
No related tags found
No related merge requests found
...@@ -37,11 +37,9 @@ import org.junit.jupiter.api.Nested; ...@@ -37,11 +37,9 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito;
import de.ozgcloud.eingang.common.formdata.Antragsteller; import de.ozgcloud.eingang.common.formdata.Antragsteller;
import de.ozgcloud.eingang.common.formdata.FormData; import de.ozgcloud.eingang.common.formdata.FormData;
import de.ozgcloud.eingang.semantik.enginebased.afm.AfmAntragstellerMapper;
class AfmAntragstellerMapperTest { class AfmAntragstellerMapperTest {
...@@ -88,7 +86,8 @@ class AfmAntragstellerMapperTest { ...@@ -88,7 +86,8 @@ class AfmAntragstellerMapperTest {
@Test @Test
@DisplayName("should map antragsteller when key starts with an uppercase letter") @DisplayName("should map antragsteller when key starts with an uppercase letter")
void shouldMapAntragstellerUppercase() { void shouldMapAntragstellerUppercase() {
formData = FormData.builder().formData(AfmAntragstellerTestFactory.createFormDataMap(AfmAntragstellerMapper.ANTRAGSTELLER_UPPERCASE)).build(); formData = FormData.builder().formData(AfmAntragstellerTestFactory.createFormDataMap(AfmAntragstellerMapper.ANTRAGSTELLER_UPPERCASE))
.build();
var parsedFormData = parseFormData(formData); var parsedFormData = parseFormData(formData);
...@@ -99,7 +98,8 @@ class AfmAntragstellerMapperTest { ...@@ -99,7 +98,8 @@ class AfmAntragstellerMapperTest {
@Test @Test
@DisplayName("should map only antragsteller key when both present") @DisplayName("should map only antragsteller key when both present")
void shouldMapOnlyOneKey() { void shouldMapOnlyOneKey() {
var expectedAntragsteller = AfmAntragstellerTestFactory.createBuilder().anrede("anrede").vorname("firstName").nachname("lastName").build(); var expectedAntragsteller = AfmAntragstellerTestFactory.createBuilder().anrede("anrede").vorname("firstName").nachname("lastName")
.build();
var parsedFormData = parseFormData(createFormData(expectedAntragsteller)); var parsedFormData = parseFormData(createFormData(expectedAntragsteller));
...@@ -109,7 +109,7 @@ class AfmAntragstellerMapperTest { ...@@ -109,7 +109,7 @@ class AfmAntragstellerMapperTest {
private FormData createFormData(Antragsteller antragsteller) { private FormData createFormData(Antragsteller antragsteller) {
var formDataMap = AfmAntragstellerTestFactory.createMutableFormDataMap(AfmAntragstellerMapper.ANTRAGSTELLER_UPPERCASE); var formDataMap = AfmAntragstellerTestFactory.createMutableFormDataMap(AfmAntragstellerMapper.ANTRAGSTELLER_UPPERCASE);
var antragstelleMap = AfmAntragstellerTestFactory.createAntragstelleMap( var antragstelleMap = AfmAntragstellerTestFactory.createPrivateAntragstelleMap(
MapEntry.entry(AfmAntragstellerMapper.ANREDE, antragsteller.getAnrede()), MapEntry.entry(AfmAntragstellerMapper.ANREDE, antragsteller.getAnrede()),
MapEntry.entry(AfmAntragstellerMapper.VORNAME, antragsteller.getVorname()), MapEntry.entry(AfmAntragstellerMapper.VORNAME, antragsteller.getVorname()),
MapEntry.entry(AfmAntragstellerMapper.NACHNAME, antragsteller.getNachname()) MapEntry.entry(AfmAntragstellerMapper.NACHNAME, antragsteller.getNachname())
...@@ -118,9 +118,9 @@ class AfmAntragstellerMapperTest { ...@@ -118,9 +118,9 @@ class AfmAntragstellerMapperTest {
return FormData.builder().formData(formDataMap).build(); return FormData.builder().formData(formDataMap).build();
} }
@DisplayName("map antragsteller data") @DisplayName("map private antragsteller data")
@Nested @Nested
class TestMapAntragstellerData { class TestMapPrivateAntragstellerData {
@Test @Test
void shouldMapPostfachId() { void shouldMapPostfachId() {
...@@ -140,7 +140,8 @@ class AfmAntragstellerMapperTest { ...@@ -140,7 +140,8 @@ class AfmAntragstellerMapperTest {
@BeforeEach @BeforeEach
void buildFormData() { void buildFormData() {
var antragstellerMap = AfmAntragstellerTestFactory.createAntragstelleMap(MapEntry.entry(NOT_MAPPED_FIELD, NOT_MAPPED_VALUE)); var antragstellerMap = AfmAntragstellerTestFactory.createPrivateAntragstelleMap(
MapEntry.entry(NOT_MAPPED_FIELD, NOT_MAPPED_VALUE));
var formDataMap = new HashMap<String, Object>(); var formDataMap = new HashMap<String, Object>();
formDataMap.put(AfmAntragstellerMapper.ANTRAGSTELLER, antragstellerMap); formDataMap.put(AfmAntragstellerMapper.ANTRAGSTELLER, antragstellerMap);
...@@ -176,9 +177,9 @@ class AfmAntragstellerMapperTest { ...@@ -176,9 +177,9 @@ class AfmAntragstellerMapperTest {
} }
} }
@DisplayName("remove fields") @DisplayName("remove private fields")
@Nested @Nested
class TestRemoveFields { class TestRemovePrivateFields {
@Test @Test
void shouldRemoveAntragsteller() { void shouldRemoveAntragsteller() {
...@@ -190,7 +191,8 @@ class AfmAntragstellerMapperTest { ...@@ -190,7 +191,8 @@ class AfmAntragstellerMapperTest {
@Test @Test
@DisplayName("should remove Antragsteller when key starts with an uppercase latter") @DisplayName("should remove Antragsteller when key starts with an uppercase latter")
void shouldRemoveAntragstellerUppercase() { void shouldRemoveAntragstellerUppercase() {
formData = FormData.builder().formData(AfmAntragstellerTestFactory.createFormDataMap(AfmAntragstellerMapper.ANTRAGSTELLER_UPPERCASE)).build(); formData = FormData.builder().formData(AfmAntragstellerTestFactory.createFormDataMap(AfmAntragstellerMapper.ANTRAGSTELLER_UPPERCASE))
.build();
var parsedFormData = parseFormData(formData); var parsedFormData = parseFormData(formData);
...@@ -207,12 +209,31 @@ class AfmAntragstellerMapperTest { ...@@ -207,12 +209,31 @@ class AfmAntragstellerMapperTest {
private FormData createFormData() { private FormData createFormData() {
var formDataMap = AfmAntragstellerTestFactory.createMutableFormDataMap(AfmAntragstellerMapper.ANTRAGSTELLER_UPPERCASE); var formDataMap = AfmAntragstellerTestFactory.createMutableFormDataMap(AfmAntragstellerMapper.ANTRAGSTELLER_UPPERCASE);
formDataMap.put(AfmAntragstellerMapper.ANTRAGSTELLER, AfmAntragstellerTestFactory.createAntragstelleMap()); formDataMap.put(AfmAntragstellerMapper.ANTRAGSTELLER, AfmAntragstellerTestFactory.createPrivateAntragstelleMap());
return FormData.builder().formData(formDataMap).build(); return FormData.builder().formData(formDataMap).build();
} }
} }
} }
@Nested
class TestMapFirmAntragstellerData {
@Test
void shouldMapFirmAntragstellerData() {
var parsedFormData = parseFormData(createFormData());
assertThat(parsedFormData.getAntragsteller()).usingRecursiveComparison()
.ignoringFields("data")
.isEqualTo(AfmAntragstellerTestFactory.createFirm());
}
private FormData createFormData() {
var formDataMap = AfmAntragstellerTestFactory.createFormDataMap();
formDataMap.put(AfmAntragstellerMapper.ANTRAGSTELLER, AfmAntragstellerTestFactory.createFirmAntragstelleMap());
return FormData.builder().formData(formDataMap).build();
}
}
private FormData parseFormData(FormData formData) { private FormData parseFormData(FormData formData) {
return mapper.parseFormData(formData); return mapper.parseFormData(formData);
} }
......
...@@ -32,11 +32,11 @@ import java.util.UUID; ...@@ -32,11 +32,11 @@ import java.util.UUID;
import org.assertj.core.data.MapEntry; import org.assertj.core.data.MapEntry;
import de.ozgcloud.eingang.common.formdata.Antragsteller; import de.ozgcloud.eingang.common.formdata.Antragsteller;
import de.ozgcloud.eingang.semantik.enginebased.afm.AfmAntragstellerMapper;
public class AfmAntragstellerTestFactory { public class AfmAntragstellerTestFactory {
public static final String ANREDE = "Herr"; public static final String ANREDE = "Herr";
public static final String FIRMA_NAME = "Firma X";
public static final String VORNAME = "Max"; public static final String VORNAME = "Max";
public static final String NACHNAME = "Mustermann"; public static final String NACHNAME = "Mustermann";
public static final String GEBURTSNAME = "Maxi"; public static final String GEBURTSNAME = "Maxi";
...@@ -55,6 +55,15 @@ public class AfmAntragstellerTestFactory { ...@@ -55,6 +55,15 @@ public class AfmAntragstellerTestFactory {
return createBuilder().build(); return createBuilder().build();
} }
public static Antragsteller createFirm() {
return createBuilder()
.firmName(FIRMA_NAME)
.geburtsname(null)
.geburtsdatum(null)
.geburtsort(null)
.build();
}
public static Antragsteller.AntragstellerBuilder createBuilder() { public static Antragsteller.AntragstellerBuilder createBuilder() {
return Antragsteller.builder() return Antragsteller.builder()
.anrede(ANREDE) .anrede(ANREDE)
...@@ -77,18 +86,18 @@ public class AfmAntragstellerTestFactory { ...@@ -77,18 +86,18 @@ public class AfmAntragstellerTestFactory {
} }
public static Map<String, Object> createFormDataMap(String antragstellerKey) { public static Map<String, Object> createFormDataMap(String antragstellerKey) {
return Collections.unmodifiableMap(createMutableFormDataMap(antragstellerKey)); return createMutableFormDataMap(antragstellerKey);
} }
public static Map<String, Object> createMutableFormDataMap(String antragstellerKey) { public static Map<String, Object> createMutableFormDataMap(String antragstellerKey) {
var map = new HashMap<String, Object>(); var map = new HashMap<String, Object>();
map.put(antragstellerKey, createAntragstelleMap()); map.put(antragstellerKey, createPrivateAntragstelleMap());
map.put(AfmAntragstellerMapper.POSTFACH_ID, POSTFACH_ID); map.put(AfmAntragstellerMapper.POSTFACH_ID, POSTFACH_ID);
return map; return map;
} }
@SafeVarargs @SafeVarargs
public static Map<String, Object> createAntragstelleMap(MapEntry<String, Object>... additionalEntries) { public static Map<String, Object> createPrivateAntragstelleMap(MapEntry<String, Object>... additionalEntries) {
var map = new HashMap<String, Object>(); var map = new HashMap<String, Object>();
map.put(AfmAntragstellerMapper.ANREDE, ANREDE); map.put(AfmAntragstellerMapper.ANREDE, ANREDE);
map.put(AfmAntragstellerMapper.VORNAME, VORNAME); map.put(AfmAntragstellerMapper.VORNAME, VORNAME);
...@@ -107,4 +116,23 @@ public class AfmAntragstellerTestFactory { ...@@ -107,4 +116,23 @@ public class AfmAntragstellerTestFactory {
return Collections.unmodifiableMap(map); return Collections.unmodifiableMap(map);
} }
@SafeVarargs
public static Map<String, Object> createFirmAntragstelleMap(MapEntry<String, Object>... additionalEntries) {
var map = new HashMap<String, Object>();
map.put(AfmAntragstellerMapper.FIELD_FIRMA_NAME, FIRMA_NAME);
map.put(AfmAntragstellerMapper.FIELD_ANSPRECHPARTNER_ANREDE, ANREDE);
map.put(AfmAntragstellerMapper.FIELD_ANSPRECHPARTNER_VORNAME, VORNAME);
map.put(AfmAntragstellerMapper.FIELD_ANSPRECHPARTNER_NACHNAME, NACHNAME);
map.put(AfmAntragstellerMapper.EMAIL, EMAIL);
map.put(AfmAntragstellerMapper.TELEFON, TELEFON);
map.put(AfmAntragstellerMapper.FIELD_FIRMA_STRASSE, STRASSE);
map.put(AfmAntragstellerMapper.FIELD_FIRMA_HAUSNUMMER, HAUSNUMMER);
map.put(AfmAntragstellerMapper.FIELD_FIRMA_PLZ, PLZ);
map.put(AfmAntragstellerMapper.FIELD_FIRMA_STADT, ORT);
Arrays.stream(additionalEntries).forEach(entry -> map.put(entry.getKey(), entry.getValue()));
return Collections.unmodifiableMap(map);
}
} }
\ 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