Skip to content
Snippets Groups Projects
Commit 2fee98f5 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6735 extract testdata

parent ec8381ab
Branches
Tags
1 merge request!2Ozg 6735 fim metadata
package de.ozgcloud.eingang.fim;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class FimDocumentTestHelper {
private static final String RESOURCE_PATH = "src/test/resources/";
public static Document getTest1Document() throws ParserConfigurationException, IOException, SAXException {
return loadDocument("test1.xml");
}
public static Document getTest2Document() throws ParserConfigurationException, IOException, SAXException {
return loadDocument("test2.xml");
}
public static Map<String, Object> getTest2AsMap() {
return Map.of(
"fim.S1235", Map.of("label", "Testkey", "value", "Testvalue"),
"fim.S1236", Map.of("label", "fim.S1236", "value", "Testvalue 2"));
}
public static Document getTest3Document() throws ParserConfigurationException, IOException, SAXException {
return loadDocument("test3.xml");
}
public static Map<String, Object> getTest3AsMap() {
return Map.of(
"fim.S1235", Map.of("label", "Testkey", "value", "Testvalue"),
"fim.S1236", Map.of("label", "fim.S1236", "value", "Testvalue 2"));
}
public static Document getVersammlungsAnzeigeDocument() throws ParserConfigurationException, IOException, SAXException {
return loadDocument("S17000652V1.4_test01.xml");
}
public static Map<String, Object> getVersammlungsAnzeigeAsMap() {
return Map.of(
"G17003529", Map.of(
"label", "EfA|SH Standard",
"value", Map.of(
"G05001479", Map.of(
"label", "nachrichtenkopf",
"value", Map.of(
"G05001480", Map.of(
"label", "identifikation.nachricht",
"value", Map.of(
"F05002750",
Map.of("label", "nachrichtenUUID", "value", "d447e43a-5723-4821-a170-cb44d2dbf143"),
"F05002751",
Map.of("label", "erstellungszeitpunkt", "value", "2022-08-15T09:30:47"),
"F05002752",
Map.of("label", "nachrichtentyp", "value", "fim.S17000652.17000652001004"),
"F05002753",
Map.of("label", "dienstname", "value", "urn:fim:Versammlungsanzeige:1.4"))),
"G05001481", Map.of(
"label", "Leser",
"value", Map.of(
"F05002754", Map.of("label", "Organisationsname", "value", "Celle"),
"F05002755",
Map.of("label", "Organisationsschlüssel", "value", "vbe:010550120100"),
"F05002756", Map.of("label", "Kategorie", "value", "Versammlungsbehörde"))),
"G05001482", Map.of(
"label", "Autor",
"value", Map.of(
"F05002754",
Map.of("label", "Organisationsname", "value",
"OSI-Onlinedienst Niedersachsen Versammlungsanzeige"),
"F05002755",
Map.of("label", "Organisationsschlüssel", "value", "vbe:010550120100"),
"F05002756",
Map.of("label", "Kategorie", "value", "Engagement- und Hobbyportal"))))),
"F17005454", Map.of("label", "Datenschutzhinweis DSGVO", "value", "true"),
"F17005455", Map.of("label", "Zustimmung zu einem digitalen Bescheid", "value", "true"),
"F17005533", Map.of("label", "UUID", "value", "String"))),
"F17009191", Map.of("label", "Anzeige durch Person", "value", "true"),
"F17003371", Map.of("label", "Anzeigenart", "value", "String"));
}
public static Document getAntragDocument() throws ParserConfigurationException, IOException, SAXException {
return loadDocument("antrag.xml");
}
private static Document loadDocument(String fileName) throws ParserConfigurationException, IOException, SAXException {
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(RESOURCE_PATH + fileName));
}
}
\ No newline at end of file
package de.ozgcloud.eingang.fim;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.assertj.core.api.Assertions.*;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.junit.jupiter.api.Test;
......@@ -15,7 +11,6 @@ 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 org.w3c.dom.Document;
import org.xml.sax.SAXException;
import de.ozgcloud.common.test.ITCase;
......@@ -31,117 +26,63 @@ class FimServiceITCase {
@Autowired
private FimService fimService;
private final FormData emptyFormData = FormData.builder().build();
@Test
void shouldFailOnEmptyScheme() {
assertThatThrownBy(() -> {
final Document document = loadDocument("src/test/resources/test1.xml");
fimService.transformDocument(document, FormData.builder().build());
}).isInstanceOf(FimException.class).hasMessage("XML Document does not provide a scheme.");
void shouldFailOnEmptyScheme() throws ParserConfigurationException, IOException, SAXException {
var document = FimDocumentTestHelper.getTest1Document();
var formData = emptyFormData;
assertThatThrownBy(() -> fimService.transformDocument(document, formData)).isInstanceOf(FimException.class)
.hasMessage("XML Document does not provide a scheme.");
}
@Test
void shouldNoFindInvalidScheme() {
final FimScheme scheme = fimService.getSchemeForIdentifier("test");
var scheme = fimService.getSchemeForIdentifier("test");
assertThat(FimSchemeIdentifier.fromString("unknown")).isEqualTo(scheme.getIdentifier());
}
@Test
void shouldFindVersammlungsScheme() {
final FimScheme scheme = fimService.getSchemeForIdentifier("urn:xoev-de:xfall:standard:fim-s17000652_1.4");
var scheme = fimService.getSchemeForIdentifier("urn:xoev-de:xfall:standard:fim-s17000652_1.4");
assertThat(scheme).isNotNull();
}
@Test
void shouldFindTest2Scheme() {
final FimScheme scheme = fimService.getSchemeForIdentifier("test2");
var 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());
var formData = fimService.transformDocument(FimDocumentTestHelper.getTest2Document(), emptyFormData);
final Map<String, Object> expected = Map.of(
"fim.S1235", Map.of("label", "Testkey", "value", "Testvalue"),
"fim.S1236", Map.of("label", "fim.S1236", "value", "Testvalue 2"));
assertThat(expected).isEqualTo(formData.getFormData());
assertThat(FimDocumentTestHelper.getTest2AsMap()).isEqualTo(formData.getFormData());
}
@Test
void shouldTransformSimpleDocumentWithoutNamespace() throws ParserConfigurationException, IOException, SAXException {
final Document document = loadDocument("src/test/resources/test3.xml");
var formData = fimService.transformDocument(FimDocumentTestHelper.getTest3Document(), emptyFormData);
final FormData formData = fimService.transformDocument(document, FormData.builder().build());
final Map<String, Object> expected = Map.of(
"fim.S1235", Map.of("label", "Testkey", "value", "Testvalue"),
"fim.S1236", Map.of("label", "fim.S1236", "value", "Testvalue 2"));
assertThat(expected).isEqualTo(formData.getFormData());
assertThat(FimDocumentTestHelper.getTest3AsMap()).isEqualTo(formData.getFormData());
}
@Test
void shouldTransformDocument() throws ParserConfigurationException, IOException, SAXException {
final Document document = loadDocument("src/test/resources/S17000652V1.4_test01.xml");
var formData = fimService.transformDocument(document, FormData.builder().build());
var formData = fimService.transformDocument(FimDocumentTestHelper.getVersammlungsAnzeigeDocument(), emptyFormData);
assertThat(formData).isNotNull();
assertThat(formData.getFormData()).isEqualTo(getTransformedDocumentMap());
}
private Map<String, Object> getTransformedDocumentMap() {
return Map.of(
"G17003529", Map.of(
"label", "EfA|SH Standard",
"value", Map.of(
"G05001479", Map.of(
"label", "nachrichtenkopf",
"value", Map.of(
"G05001480", Map.of(
"label", "identifikation.nachricht",
"value", Map.of(
"F05002750",
Map.of("label", "nachrichtenUUID", "value", "d447e43a-5723-4821-a170-cb44d2dbf143"),
"F05002751",
Map.of("label", "erstellungszeitpunkt", "value", "2022-08-15T09:30:47"),
"F05002752",
Map.of("label", "nachrichtentyp", "value", "fim.S17000652.17000652001004"),
"F05002753",
Map.of("label", "dienstname", "value", "urn:fim:Versammlungsanzeige:1.4"))),
"G05001481", Map.of(
"label", "Leser",
"value", Map.of(
"F05002754", Map.of("label", "Organisationsname", "value", "Celle"),
"F05002755",
Map.of("label", "Organisationsschlüssel", "value", "vbe:010550120100"),
"F05002756", Map.of("label", "Kategorie", "value", "Versammlungsbehörde"))),
"G05001482", Map.of(
"label", "Autor",
"value", Map.of(
"F05002754",
Map.of("label", "Organisationsname", "value",
"OSI-Onlinedienst Niedersachsen Versammlungsanzeige"),
"F05002755",
Map.of("label", "Organisationsschlüssel", "value", "vbe:010550120100"),
"F05002756",
Map.of("label", "Kategorie", "value", "Engagement- und Hobbyportal"))))),
"F17005454", Map.of("label", "Datenschutzhinweis DSGVO", "value", "true"),
"F17005455", Map.of("label", "Zustimmung zu einem digitalen Bescheid", "value", "true"),
"F17005533", Map.of("label", "UUID", "value", "String"))),
"F17009191", Map.of("label", "Anzeige durch Person", "value", "true"),
"F17003371", Map.of("label", "Anzeigenart", "value", "String"));
assertThat(formData.getFormData()).isEqualTo(FimDocumentTestHelper.getVersammlungsAnzeigeAsMap());
}
@Test
void shouldHaveNameInHeader() throws ParserConfigurationException, IOException, SAXException {
final Document document = loadDocument("src/test/resources/antrag.xml");
FormData formData = fimService.transformDocument(document, FormData.builder().build());
var formData = fimService.transformDocument(FimDocumentTestHelper.getAntragDocument(), emptyFormData);
assertThat(formData).isNotNull();
assertThat(formData.getHeader().getFormName()).isEqualTo("urn:fim:Versammlungsanzeige:1.4");
......@@ -149,9 +90,7 @@ class FimServiceITCase {
@Test
void shouldHaveAntragsteller() throws ParserConfigurationException, IOException, SAXException {
final Document document = loadDocument("src/test/resources/antrag.xml");
FormData formData = fimService.transformDocument(document, FormData.builder().build());
var formData = fimService.transformDocument(FimDocumentTestHelper.getAntragDocument(), emptyFormData);
assertThat(formData).isNotNull();
assertThat(formData.getAntragsteller()).isNotNull();
......@@ -159,9 +98,7 @@ class FimServiceITCase {
@Test
void shouldHaveAntragstellerAntragstellerData() throws ParserConfigurationException, IOException, SAXException {
final Document document = loadDocument("src/test/resources/antrag.xml");
FormData formData = fimService.transformDocument(document, FormData.builder().build());
var formData = fimService.transformDocument(FimDocumentTestHelper.getAntragDocument(), emptyFormData);
assertThat(formData).isNotNull();
assertThat(formData.getAntragsteller().getVorname()).isEqualTo("Jörg");
......@@ -171,8 +108,4 @@ class FimServiceITCase {
assertThat(formData.getAntragsteller().getPlz()).isEqualTo("12345");
assertThat(formData.getAntragsteller().getOrt()).isEqualTo("Muster");
}
private Document loadDocument(final String path) throws ParserConfigurationException, IOException, SAXException {
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(path));
}
}
\ 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