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
Branches
Tags
No related merge requests found
......@@ -37,11 +37,9 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import de.ozgcloud.eingang.common.formdata.Antragsteller;
import de.ozgcloud.eingang.common.formdata.FormData;
import de.ozgcloud.eingang.semantik.enginebased.afm.AfmAntragstellerMapper;
class AfmAntragstellerMapperTest {
......@@ -52,7 +50,7 @@ class AfmAntragstellerMapperTest {
private AfmAntragstellerHeaderMapper antragstellerHeaderMapper;
private FormData formData = FormData.builder().formData(AfmAntragstellerTestFactory.createFormDataMap()).build();
@DisplayName("Parse form data")
@Nested
class TestParseFormData {
......@@ -88,7 +86,8 @@ class AfmAntragstellerMapperTest {
@Test
@DisplayName("should map antragsteller when key starts with an uppercase letter")
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);
......@@ -99,7 +98,8 @@ class AfmAntragstellerMapperTest {
@Test
@DisplayName("should map only antragsteller key when both present")
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));
......@@ -109,7 +109,7 @@ class AfmAntragstellerMapperTest {
private FormData createFormData(Antragsteller antragsteller) {
var formDataMap = AfmAntragstellerTestFactory.createMutableFormDataMap(AfmAntragstellerMapper.ANTRAGSTELLER_UPPERCASE);
var antragstelleMap = AfmAntragstellerTestFactory.createAntragstelleMap(
var antragstelleMap = AfmAntragstellerTestFactory.createPrivateAntragstelleMap(
MapEntry.entry(AfmAntragstellerMapper.ANREDE, antragsteller.getAnrede()),
MapEntry.entry(AfmAntragstellerMapper.VORNAME, antragsteller.getVorname()),
MapEntry.entry(AfmAntragstellerMapper.NACHNAME, antragsteller.getNachname())
......@@ -118,9 +118,9 @@ class AfmAntragstellerMapperTest {
return FormData.builder().formData(formDataMap).build();
}
@DisplayName("map antragsteller data")
@DisplayName("map private antragsteller data")
@Nested
class TestMapAntragstellerData {
class TestMapPrivateAntragstellerData {
@Test
void shouldMapPostfachId() {
......@@ -140,7 +140,8 @@ class AfmAntragstellerMapperTest {
@BeforeEach
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>();
formDataMap.put(AfmAntragstellerMapper.ANTRAGSTELLER, antragstellerMap);
......@@ -176,9 +177,9 @@ class AfmAntragstellerMapperTest {
}
}
@DisplayName("remove fields")
@DisplayName("remove private fields")
@Nested
class TestRemoveFields {
class TestRemovePrivateFields {
@Test
void shouldRemoveAntragsteller() {
......@@ -190,7 +191,8 @@ class AfmAntragstellerMapperTest {
@Test
@DisplayName("should remove Antragsteller when key starts with an uppercase latter")
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);
......@@ -207,12 +209,31 @@ class AfmAntragstellerMapperTest {
private FormData createFormData() {
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();
}
}
}
@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) {
return mapper.parseFormData(formData);
}
......
......@@ -32,11 +32,11 @@ import java.util.UUID;
import org.assertj.core.data.MapEntry;
import de.ozgcloud.eingang.common.formdata.Antragsteller;
import de.ozgcloud.eingang.semantik.enginebased.afm.AfmAntragstellerMapper;
public class AfmAntragstellerTestFactory {
public static final String ANREDE = "Herr";
public static final String FIRMA_NAME = "Firma X";
public static final String VORNAME = "Max";
public static final String NACHNAME = "Mustermann";
public static final String GEBURTSNAME = "Maxi";
......@@ -55,6 +55,15 @@ public class AfmAntragstellerTestFactory {
return createBuilder().build();
}
public static Antragsteller createFirm() {
return createBuilder()
.firmName(FIRMA_NAME)
.geburtsname(null)
.geburtsdatum(null)
.geburtsort(null)
.build();
}
public static Antragsteller.AntragstellerBuilder createBuilder() {
return Antragsteller.builder()
.anrede(ANREDE)
......@@ -77,18 +86,18 @@ public class AfmAntragstellerTestFactory {
}
public static Map<String, Object> createFormDataMap(String antragstellerKey) {
return Collections.unmodifiableMap(createMutableFormDataMap(antragstellerKey));
return createMutableFormDataMap(antragstellerKey);
}
public static Map<String, Object> createMutableFormDataMap(String antragstellerKey) {
var map = new HashMap<String, Object>();
map.put(antragstellerKey, createAntragstelleMap());
map.put(antragstellerKey, createPrivateAntragstelleMap());
map.put(AfmAntragstellerMapper.POSTFACH_ID, POSTFACH_ID);
return map;
}
@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>();
map.put(AfmAntragstellerMapper.ANREDE, ANREDE);
map.put(AfmAntragstellerMapper.VORNAME, VORNAME);
......@@ -107,4 +116,23 @@ public class AfmAntragstellerTestFactory {
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