Skip to content
Snippets Groups Projects
Commit 75c6c3b8 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4697 parse antragsteller

parent 28370b2c
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ import java.util.Map; ...@@ -9,6 +9,7 @@ import java.util.Map;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import de.ozgcloud.eingang.common.errorhandling.TechnicalException; import de.ozgcloud.eingang.common.errorhandling.TechnicalException;
import de.ozgcloud.eingang.common.formdata.Antragsteller;
import de.ozgcloud.eingang.common.formdata.FormData; import de.ozgcloud.eingang.common.formdata.FormData;
@Component @Component
...@@ -26,7 +27,21 @@ public class AfmAntragstellerHeaderMapper { ...@@ -26,7 +27,21 @@ public class AfmAntragstellerHeaderMapper {
static final String KEY_ORT = "u:saml_localityname"; static final String KEY_ORT = "u:saml_localityname";
public FormData parseAntragstellerData(FormData formData) { public FormData parseAntragstellerData(FormData formData) {
return formData; return formData.toBuilder().antragsteller(buildAntragsteller(getHeaders(formData))).build();
}
Antragsteller buildAntragsteller(Map<String, Object> headers) {
return Antragsteller.builder()
.postfachId((String) headers.get(KEY_POSTFACH_ID))
.vorname((String) headers.get(KEY_VORNAME))
.nachname((String) headers.get(KEY_NACHNAME))
.geburtsort((String) headers.get(KEY_GEBURTSORT))
.email((String) headers.get(KEY_EMAIL))
.telefon((String) headers.get(KEY_TELEFON))
.strasse((String) headers.get(KEY_STRASSE))
.plz((String) headers.get(KEY_PLZ))
.ort((String) headers.get(KEY_ORT))
.build();
} }
public boolean isResponsible(FormData formData) { public boolean isResponsible(FormData formData) {
......
...@@ -9,7 +9,6 @@ import java.util.Collections; ...@@ -9,7 +9,6 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
...@@ -19,6 +18,7 @@ import org.mockito.Mock; ...@@ -19,6 +18,7 @@ import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
import de.ozgcloud.eingang.common.errorhandling.TechnicalException; import de.ozgcloud.eingang.common.errorhandling.TechnicalException;
import de.ozgcloud.eingang.common.formdata.AntragstellerTestFactory;
import de.ozgcloud.eingang.common.formdata.FormData; import de.ozgcloud.eingang.common.formdata.FormData;
class AfmAntragstellerHeaderMapperTest { class AfmAntragstellerHeaderMapperTest {
...@@ -30,19 +30,111 @@ class AfmAntragstellerHeaderMapperTest { ...@@ -30,19 +30,111 @@ class AfmAntragstellerHeaderMapperTest {
@Nested @Nested
class TestParseAntragstellerData { class TestParseAntragstellerData {
@Test
void shouldCallGetHeaders() {
var formData = FormData.builder().build();
doReturn(Collections.emptyMap()).when(mapper).getHeaders(any());
mapper.parseAntragstellerData(formData);
verify(mapper).getHeaders(formData);
}
@Test
void shouldCallBuildAntragsteller() {
var headerMap = AfmHeaderTestFactory.createCustomHeaderMap();
doReturn(headerMap).when(mapper).getHeaders(any());
mapper.parseAntragstellerData(FormData.builder().build());
verify(mapper).buildAntragsteller(headerMap);
}
@Test
void shouldSetAntragsteller() {
var antragsteller = AntragstellerTestFactory.create();
doReturn(antragsteller).when(mapper).buildAntragsteller(any());
var result = mapper.parseAntragstellerData(FormData.builder().build());
assertThat(result.getAntragsteller()).isEqualTo(antragsteller);
} }
@Nested @Nested
class TestIsResponsible { class TestBuildAntragsteller {
@Mock private Map<String, Object> headers = AfmHeaderTestFactory.createCustomHeaderMap();
private FormData formData; @Test
void shouldSetPostfachId() {
var result = mapper.buildAntragsteller(headers);
assertThat(result.getPostfachId()).isEqualTo(AfmHeaderTestFactory.CUSTOM_POSTFACH_ID);
}
@Test
void shouldSetVorname() {
var result = mapper.buildAntragsteller(headers);
assertThat(result.getVorname()).isEqualTo(AfmHeaderTestFactory.CUSTOM_VORNAME);
}
@Test
void shouldSetNachname() {
var result = mapper.buildAntragsteller(headers);
assertThat(result.getNachname()).isEqualTo(AfmHeaderTestFactory.CUSTOM_NACHNAME);
}
@Test
void shouldSetGeburtsort() {
var result = mapper.buildAntragsteller(headers);
assertThat(result.getGeburtsort()).isEqualTo(AfmHeaderTestFactory.CUSTOM_GEBURTSORT);
}
@Test
void shoudlSetEmail() {
var result = mapper.buildAntragsteller(headers);
assertThat(result.getEmail()).isEqualTo(AfmHeaderTestFactory.CUSTOM_EMAIL);
}
@Test
void shouldSetTelefon() {
var result = mapper.buildAntragsteller(headers);
@BeforeEach assertThat(result.getTelefon()).isEqualTo(AfmHeaderTestFactory.CUSTOM_TELEFON);
void setup() { }
@Test
void shouldSetStrasse() {
var result = mapper.buildAntragsteller(headers);
assertThat(result.getStrasse()).isEqualTo(AfmHeaderTestFactory.CUSTOM_STRASSE);
}
@Test
void shouldSetPlz() {
var result = mapper.buildAntragsteller(headers);
assertThat(result.getPlz()).isEqualTo(AfmHeaderTestFactory.CUSTOM_PLZ);
}
@Test
void shouldSetOrt() {
var result = mapper.buildAntragsteller(headers);
assertThat(result.getOrt()).isEqualTo(AfmHeaderTestFactory.CUSTOM_ORT);
}
}
} }
@Nested
class TestIsResponsible {
@Mock
private FormData formData;
@Test @Test
void shouldApproveResponsibility() { void shouldApproveResponsibility() {
doReturn(true).when(mapper).isPostfachIdNotBlank(any()); doReturn(true).when(mapper).isPostfachIdNotBlank(any());
...@@ -83,29 +175,6 @@ class AfmAntragstellerHeaderMapperTest { ...@@ -83,29 +175,6 @@ class AfmAntragstellerHeaderMapperTest {
assertFalse(isResponsible); assertFalse(isResponsible);
} }
@Nested
class TestGetHeaders {
@Test
void shouldReturnHeaders() {
var headers = createHeaders(AfmAntragstellerHeaderMapper.KEY_POSTFACH_ID, "123");
var formData = FormData.builder().formData(createHeaders(AfmHeaderMapper.HEADER_FIELD, headers)).build();
var result = mapper.getHeaders(formData);
assertThat(result).isEqualTo(headers);
}
@Test
void shouldReturnEmptyMapWhenNoHeaders() {
var formData = FormData.builder().build();
var result = mapper.getHeaders(formData);
assertThat(result).isEmpty();
}
}
@Nested @Nested
class TestIsPostfachIdNotBlank { class TestIsPostfachIdNotBlank {
...@@ -134,6 +203,29 @@ class AfmAntragstellerHeaderMapperTest { ...@@ -134,6 +203,29 @@ class AfmAntragstellerHeaderMapperTest {
} }
} }
@Nested
class TestGetHeaders {
@Test
void shouldReturnHeaders() {
var headers = createHeaders(AfmAntragstellerHeaderMapper.KEY_POSTFACH_ID, "123");
var formData = FormData.builder().formData(createHeaders(AfmHeaderMapper.HEADER_FIELD, headers)).build();
var result = mapper.getHeaders(formData);
assertThat(result).isEqualTo(headers);
}
@Test
void shouldReturnEmptyMapWhenNoHeaders() {
var formData = FormData.builder().build();
var result = mapper.getHeaders(formData);
assertThat(result).isEmpty();
}
}
private Map<String, Object> createHeaders(String key, Object value) { private Map<String, Object> createHeaders(String key, Object value) {
var map = new HashMap<String, Object>(); var map = new HashMap<String, Object>();
map.put(key, value); map.put(key, value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment