diff --git a/fim-adapter/src/test/java/de/ozgcloud/eingang/fim/FimBasedAdapterITCase.java b/fim-adapter/src/test/java/de/ozgcloud/eingang/fim/FimBasedAdapterITCase.java new file mode 100644 index 0000000000000000000000000000000000000000..348acd4003c8f0cfd9cd6d2b5c766451df4e7cf1 --- /dev/null +++ b/fim-adapter/src/test/java/de/ozgcloud/eingang/fim/FimBasedAdapterITCase.java @@ -0,0 +1,81 @@ +package de.ozgcloud.eingang.fim; + +import static org.assertj.core.api.Assertions.*; + +import java.io.File; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +import de.ozgcloud.common.test.ITCase; +import de.ozgcloud.eingang.common.formdata.FormData; +import de.ozgcloud.eingang.common.formdata.FormHeader; +import de.ozgcloud.eingang.common.formdata.IncomingFile; + +@ITCase +@ActiveProfiles({ "itcase", "test" }) +@ImportAutoConfiguration +@SpringBootTest(classes = FimTestConfig.class) +class FimBasedAdapterITCase { + + @Autowired + private FimBasedAdapter fimBasedAdapter; + + @Test + void shouldFallbackUnknownScheme() { + var incomingFile = IncomingFile.builder().name("src/test/resources/test3/Antrag.xml").file(new File("src/test/resources/test3/Antrag.xml")) + .build(); + var incomingFile2 = IncomingFile.builder().name("src/test/resources/test3/fim_xtaMetadata.xml").build(); + var initialFormData = FormData.builder() + .header(FormHeader.builder().channel("XTA").formEngineName("FIM").build()) + .representations(List.of(incomingFile, incomingFile2)).build(); + + var formData = fimBasedAdapter.parseFormData(initialFormData); + + assertThat(formData).isNotNull(); + assertThat(formData.getFormData()).isEqualTo(getParsedDocumentMap()); + } + + private Map<String, Object> getParsedDocumentMap() { + return Map.of( + "G17003529", Map.of( + "label", "G17003529", + "value", Map.of( + "G05001479", Map.of( + "label", "G05001479", + "value", Map.of( + "G05001480", Map.of( + "label", "G05001480", + "value", Map.of( + "F05002750", + Map.of("label", "F05002750", "value", "d447e43a-5723-4821-a170-cb44d2dbf143"), + "F05002751", Map.of("label", "F05002751", "value", "2022-08-15T09:30:47"), + "F05002752", Map.of("label", "F05002752", "value", "fim.S17000652.17000652001004"), + "F05002753", + Map.of("label", "F05002753", "value", "urn:fim:Versammlungsanzeige:1.4"))), + "G05001481", Map.of( + "label", "G05001481", + "value", Map.of( + "F05002754", Map.of("label", "F05002754", "value", "Celle"), + "F05002755", Map.of("label", "F05002755", "value", "vbe:010550120100"), + "F05002756", Map.of("label", "F05002756", "value", "Versammlungsbehörde"))), + "G05001482", Map.of( + "label", "G05001482", + "value", Map.of( + "F05002754", + Map.of("label", "F05002754", "value", + "OSI-Onlinedienst Niedersachsen Versammlungsanzeige"), + "F05002755", Map.of("label", "F05002755", "value", "vbe:010550120100"), + "F05002756", Map.of("label", "F05002756", "value", "Engagement- und Hobbyportal"))))), + "F17005454", Map.of("label", "F17005454", "value", "true"), + "F17005455", Map.of("label", "F17005455", "value", "true"), + "F17005533", Map.of("label", "F17005533", "value", "String"))), + "F17009191", Map.of("label", "F17009191", "value", "true"), + "F17003371", Map.of("label", "F17003371", "value", "String")); + } +} \ No newline at end of file diff --git a/fim-adapter/src/test/java/de/ozgcloud/eingang/fim/FimServiceITCase.java b/fim-adapter/src/test/java/de/ozgcloud/eingang/fim/FimServiceITCase.java index 76c88666f608eae6d831ca7234ae002f3376c7ff..f54b961ef805c945f1416cc9292855d314c95c1c 100644 --- a/fim-adapter/src/test/java/de/ozgcloud/eingang/fim/FimServiceITCase.java +++ b/fim-adapter/src/test/java/de/ozgcloud/eingang/fim/FimServiceITCase.java @@ -5,7 +5,6 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import java.io.File; import java.io.IOException; -import java.util.List; import java.util.Map; import javax.xml.parsers.DocumentBuilderFactory; @@ -21,8 +20,6 @@ import org.xml.sax.SAXException; import de.ozgcloud.common.test.ITCase; import de.ozgcloud.eingang.common.formdata.FormData; -import de.ozgcloud.eingang.common.formdata.FormHeader; -import de.ozgcloud.eingang.common.formdata.IncomingFile; import de.ozgcloud.eingang.fim.common.errorhandling.FimException; @ITCase @@ -34,9 +31,6 @@ class FimServiceITCase { @Autowired private FimService fimService; - @Autowired - private FimBasedAdapter fimBasedAdapter; - @Test void shouldFailOnEmptyScheme() { assertThatThrownBy(() -> { @@ -55,18 +49,21 @@ class FimServiceITCase { @Test void shouldFindVersammlungsScheme() { final FimScheme scheme = fimService.getSchemeForIdentifier("urn:xoev-de:xfall:standard:fim-s17000652_1.4"); + assertThat(scheme).isNotNull(); } @Test void shouldFindTest2Scheme() { final FimScheme scheme = fimService.getSchemeForIdentifier("test2"); + assertThat(scheme).isNotNull(); } @Test void shouldTransformSimpleDocument() throws ParserConfigurationException, IOException, SAXException { final Document document = loadDocument("src/test/resources/test2.xml"); + final FormData formData = fimService.transformDocument(document, FormData.builder().build()); final Map<String, Object> expected = Map.of( @@ -78,6 +75,7 @@ class FimServiceITCase { @Test void shouldTransformSimpleDocumentWithoutNamespace() throws ParserConfigurationException, IOException, SAXException { final Document document = loadDocument("src/test/resources/test3.xml"); + final FormData formData = fimService.transformDocument(document, FormData.builder().build()); final Map<String, Object> expected = Map.of( @@ -89,11 +87,15 @@ class FimServiceITCase { @Test void shouldTransformDocument() throws ParserConfigurationException, IOException, SAXException { final Document document = loadDocument("src/test/resources/S17000652V1.4_test01.xml"); - FormData formData = fimService.transformDocument(document, FormData.builder().build()); + + var formData = fimService.transformDocument(document, FormData.builder().build()); assertThat(formData).isNotNull(); + assertThat(formData.getFormData()).isEqualTo(getTransformedDocumentMap()); + } - final Map<String, Object> expected = Map.of( + private Map<String, Object> getTransformedDocumentMap() { + return Map.of( "G17003529", Map.of( "label", "EfA|SH Standard", "value", Map.of( @@ -133,37 +135,35 @@ class FimServiceITCase { "F17005533", Map.of("label", "UUID", "value", "String"))), "F17009191", Map.of("label", "Anzeige durch Person", "value", "true"), "F17003371", Map.of("label", "Anzeigenart", "value", "String")); - - assertThat(expected).isEqualTo(formData.getFormData()); } @Test void shouldHaveNameInHeader() throws ParserConfigurationException, IOException, SAXException { final Document document = loadDocument("src/test/resources/antrag.xml"); + FormData formData = fimService.transformDocument(document, FormData.builder().build()); assertThat(formData).isNotNull(); - assertThat(formData.getHeader().getFormName()).isEqualTo("urn:fim:Versammlungsanzeige:1.4"); } @Test void shouldHaveAntragsteller() throws ParserConfigurationException, IOException, SAXException { final Document document = loadDocument("src/test/resources/antrag.xml"); + FormData formData = fimService.transformDocument(document, FormData.builder().build()); assertThat(formData).isNotNull(); - assertThat(formData.getAntragsteller()).isNotNull(); } @Test void shouldHaveAntragstellerAntragstellerData() throws ParserConfigurationException, IOException, SAXException { final Document document = loadDocument("src/test/resources/antrag.xml"); + FormData formData = fimService.transformDocument(document, FormData.builder().build()); assertThat(formData).isNotNull(); - assertThat(formData.getAntragsteller().getVorname()).isEqualTo("Jörg"); assertThat(formData.getAntragsteller().getNachname()).isEqualTo("Bolay"); assertThat(formData.getAntragsteller().getStrasse()).isEqualTo("Muster"); @@ -172,58 +172,6 @@ class FimServiceITCase { assertThat(formData.getAntragsteller().getOrt()).isEqualTo("Muster"); } - @Test - void shouldFallbackUnknownScheme() { - IncomingFile r1 = IncomingFile.builder().name("src/test/resources/test3/Antrag.xml").file(new File("src/test/resources/test3/Antrag.xml")) - .build(); - IncomingFile r2 = IncomingFile.builder().name("src/test/resources/test3/fim_xtaMetadata.xml").build(); - final FormData initialFormData = FormData.builder() - .header(FormHeader.builder().channel("XTA").formEngineName("FIM").build()) - .representations(List.of(r1, r2)).build(); - - FormData formData = fimBasedAdapter.parseFormData(initialFormData); - - assertThat(formData).isNotNull(); - - final Map<String, Object> expected = Map.of( - "G17003529", Map.of( - "label", "G17003529", - "value", Map.of( - "G05001479", Map.of( - "label", "G05001479", - "value", Map.of( - "G05001480", Map.of( - "label", "G05001480", - "value", Map.of( - "F05002750", - Map.of("label", "F05002750", "value", "d447e43a-5723-4821-a170-cb44d2dbf143"), - "F05002751", Map.of("label", "F05002751", "value", "2022-08-15T09:30:47"), - "F05002752", Map.of("label", "F05002752", "value", "fim.S17000652.17000652001004"), - "F05002753", - Map.of("label", "F05002753", "value", "urn:fim:Versammlungsanzeige:1.4"))), - "G05001481", Map.of( - "label", "G05001481", - "value", Map.of( - "F05002754", Map.of("label", "F05002754", "value", "Celle"), - "F05002755", Map.of("label", "F05002755", "value", "vbe:010550120100"), - "F05002756", Map.of("label", "F05002756", "value", "Versammlungsbehörde"))), - "G05001482", Map.of( - "label", "G05001482", - "value", Map.of( - "F05002754", - Map.of("label", "F05002754", "value", - "OSI-Onlinedienst Niedersachsen Versammlungsanzeige"), - "F05002755", Map.of("label", "F05002755", "value", "vbe:010550120100"), - "F05002756", Map.of("label", "F05002756", "value", "Engagement- und Hobbyportal"))))), - "F17005454", Map.of("label", "F17005454", "value", "true"), - "F17005455", Map.of("label", "F17005455", "value", "true"), - "F17005533", Map.of("label", "F17005533", "value", "String"))), - "F17009191", Map.of("label", "F17009191", "value", "true"), - "F17003371", Map.of("label", "F17003371", "value", "String")); - - assertThat(expected).isEqualTo(formData.getFormData()); - } - private Document loadDocument(final String path) throws ParserConfigurationException, IOException, SAXException { return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(path)); }