Skip to content
Snippets Groups Projects
Commit 744cd8ac authored by Jörg Bolay's avatar Jörg Bolay
Browse files

Merge pull request 'OZG-5414-Mantelantrag-GetMessages' (#114) from...

Merge pull request 'OZG-5414-Mantelantrag-GetMessages' (#114) from OZG-5412-Mantelantrag-GetMessages into OZG-5412-Dataport-Mantelantrag

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/eingang-manager/pulls/114
parents b864d2dc 27226803
Branches
Tags
No related merge requests found
Showing
with 451 additions and 1 deletion
......@@ -12,6 +12,8 @@
<properties>
<spring-boot.build-image.imageName>docker.ozg-sh.de/xta-adapter:build-latest</spring-boot.build-image.imageName>
<okio.version>3.9.0</okio.version>
<mockwebserver.version>4.12.0</mockwebserver.version>
</properties>
<dependencies>
......@@ -81,6 +83,18 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>${okio.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>${mockwebserver.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
package de.ozgcloud.eingang.xta;
import java.io.IOException;
import java.util.Arrays;
import java.util.Base64;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import de.ozgcloud.common.test.TestUtils;
import okhttp3.mockwebserver.MockResponse;
public class MockResponseTestFactory {
private static final String UUID_BOUNDARY = "uuid:4403149a-87eb-4bb4-b885-472816010e04+id=12707";
// The MIME Multipart/Related Content-type (See https://www.ietf.org/rfc/rfc2387.txt)
private static final String MULTIPART_RELATED_CONTENT_TYPE = "multipart/related; type=\"application/xop+xml\";start=\"<http://tempuri.org/0>\";boundary=\"%s\";start-info=\"application/soap+xml\"".formatted(
UUID_BOUNDARY);
private static final String INCLUDE_URL = "http://tempuri.org/1/638485294711394846";
private static final Map<String, String> ENVELOPE_HEADERS = Map.of(
"Content-ID", "<http://tempuri.org/0>",
"Content-Transfer-Encoding", "8bit",
"Content-Type", "application/xop+xml;charset=utf-8;type=\"application/soap+xml\""
);
public static Map<String, String> MAILBOX_CONTENT = Map.of(
"urn:de:xta:messageid:dataport_xta_210:20eb297a-e224-45a0-9376-5ebd4d9bcc9a", "AFM",
"urn:de:xta:messageid:dataport_xta_210:371ce4e3-44e3-4f9d-8c82-db7f347ae760", "AFM",
"urn:de:xta:messageid:dataport_xta_210:3d280bfa-d790-4865-a6cf-f6656d7be13f", "Versammlungsanzeige",
"urn:de:xta:messageid:dataport_xta_210:749f0375-be76-4928-959d-76d52de906c3", "AFM"
);
private static final Map<String, String> ATTACHMENT_FILENAME = Map.of(
"AFM", "attachment.zip",
"Versammlungsanzeige", "attachment.xml"
);
public static MockResponse create() {
return new MockResponse();
}
public static MockResponse createEmptyGetStatusListResponse() {
var envelopeXMLString = TestUtils.loadTextFile(
"mock-responses/getStatusList/envelope.template.xml",
"0",
""
);
var body = combineParts(
createPart(
ENVELOPE_HEADERS,
envelopeXMLString
)
);
return new MockResponse()
.addHeader("Content-Type", MULTIPART_RELATED_CONTENT_TYPE)
.setBody(body);
}
public static MockResponse createGetStatusListResponse() {
var messageMetaDataEntriesString = MAILBOX_CONTENT.entrySet().stream()
.map(kv -> TestUtils.loadTextFile("mock-responses/getStatusList/MessageMetaData/%s.template.xml".formatted(kv.getValue()),
kv.getKey()))
.collect(Collectors.joining());
var envelopeXMLString = TestUtils.loadTextFile(
"mock-responses/getStatusList/envelope.template.xml",
String.valueOf(MAILBOX_CONTENT.size()),
messageMetaDataEntriesString
);
var body = combineParts(
createPart(
ENVELOPE_HEADERS,
envelopeXMLString
)
);
return new MockResponse()
.addHeader("Content-Type", MULTIPART_RELATED_CONTENT_TYPE)
.setBody(body);
}
public static MockResponse createGetMessageResponse(String messageId) {
var antragType = Objects.requireNonNull(MAILBOX_CONTENT.get(messageId));
var envelopeXMLString = TestUtils.loadTextFile(
"mock-responses/getMessage/%s/envelope.template.xml".formatted(antragType),
messageId, INCLUDE_URL);
String attachmentBase64;
try (var attachmentFile = TestUtils.loadFile(
"mock-responses/getMessage/%s/%s".formatted(antragType, Objects.requireNonNull(ATTACHMENT_FILENAME.get(antragType))))) {
attachmentBase64 = new String(Base64.getEncoder().encode(attachmentFile.readAllBytes()));
} catch (IOException e) {
throw new RuntimeException(e);
}
var body = combineParts(
createPart(
ENVELOPE_HEADERS,
envelopeXMLString
),
createPart(
Map.of(
"Content-ID", "<%s>".formatted(INCLUDE_URL),
"Content-Transfer-Encoding", "base64",
"Content-Type", "application/octet-stream"
),
attachmentBase64
)
);
return new MockResponse()
.addHeader("Content-Type", MULTIPART_RELATED_CONTENT_TYPE)
.setBody(body);
}
private static String combineParts(String... parts) {
return Stream.concat(
Arrays.stream(parts).map(part -> "--%s\n%s\n".formatted(UUID_BOUNDARY, part)),
Stream.of("--%s--".formatted(UUID_BOUNDARY)))
.collect(Collectors.joining());
}
private static String createPart(Map<String, String> headers, String content) {
return String.join("\n",
headers.entrySet().stream().map(kv -> "%s: %s\n".formatted(kv.getKey(), kv.getValue())).collect(Collectors.joining()), content);
}
}
......@@ -54,7 +54,7 @@ class XtaRemoteServiceITCase {
class TestGetMessage {
@Test
void shouldSendRequest() {
var result = remoteService.getMessage("urn:de:xta:messageid:dataport_xta_210:81e40808-91c6-4765-aaf4-1aa62fec8be9");
var result = remoteService.getMessage("urn:de:xta:messageid:dataport_xta_210:20eb297a-e224-45a0-9376-5ebd4d9bcc9a");
assertThat(result).isNotNull();
}
......
package de.ozgcloud.eingang.xta;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;
import java.net.InetAddress;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import de.ozgcloud.eingang.Application;
import de.ozgcloud.eingang.semantik.enginebased.EngineBasedSemantikAdapter;
import de.ozgcloud.eingang.semantik.formbased.FormBasedSemantikAdapter;
import lombok.SneakyThrows;
import okhttp3.mockwebserver.MockWebServer;
@ActiveProfiles({ "itcase", "local" })
@SpringBootTest(classes = Application.class)
class XtaServiceITCase {
private MockWebServer nachrichtenBrokerMock;
private static final List<String> FILTERED_MESSAGE_IDS = MockResponseTestFactory.MAILBOX_CONTENT.entrySet().stream()
.filter(kv -> kv.getValue().equals("AFM"))
.map(Map.Entry::getKey)
.toList();
@Autowired
private XtaService xtaService;
@Autowired
private EngineBasedSemantikAdapter engineBasedAdapter;
@Autowired
private FormBasedSemantikAdapter formBasedAdapter;
@Autowired
private XtaProperties properties;
@DisplayName("get messages")
@Nested
class TestGetMessages {
@BeforeEach
void enqueueResponse() {
startServer();
nachrichtenBrokerMock.enqueue(MockResponseTestFactory.createGetStatusListResponse());
FILTERED_MESSAGE_IDS.forEach(messageId ->
nachrichtenBrokerMock.enqueue(MockResponseTestFactory.createGetMessageResponse(messageId))
);
nachrichtenBrokerMock.enqueue(MockResponseTestFactory.createEmptyGetStatusListResponse());
}
@AfterEach
@SneakyThrows
void verifyRequestCall() {
try {
var expectedCallCount = FILTERED_MESSAGE_IDS.size() + 2;
for (var i = 0; i < expectedCallCount; i++) {
var request = nachrichtenBrokerMock.takeRequest(1, TimeUnit.SECONDS);
assertNotNull(request, "should have request index %d".formatted(i));
assertThat(request.getPath()).isEqualTo("/MB_XTA-WS/XTA210msgBoxPort.svc");
}
} finally {
stopServer();
}
}
@DisplayName("should return form data with filtered message ids")
@Test
void shouldReturnFormDataWithFilteredMessageIds() {
var formDataItems = xtaService.getMessages();
var messageIds = formDataItems.map(item -> item.getHeader().getRequestId()).toList();
assertThat(messageIds).isEqualTo(FILTERED_MESSAGE_IDS);
}
@DisplayName("should unzip correct number of representations")
@Test
void shouldUnzipCorrectNumberOfRepresentations() {
var firstFormData = xtaService.getMessages().toList().getFirst();
assertNotNull(firstFormData);
firstFormData = engineBasedAdapter.parseFormData(firstFormData);
firstFormData = formBasedAdapter.parseFormData(firstFormData);
// Expect that there are 3 files in attachment.zip and that the zip itself is a representation
assertThat(firstFormData.getNumberOfRepresentations()).isEqualTo(4);
}
}
@SneakyThrows
private void startServer() {
nachrichtenBrokerMock = new MockWebServer();
nachrichtenBrokerMock.start(InetAddress.getByName("127.0.0.1"), 0);
var serverProperties = properties.getServer();
serverProperties.setAddress(nachrichtenBrokerMock.getHostName() + ":" + nachrichtenBrokerMock.getPort());
serverProperties.setProtocol("http");
}
@SneakyThrows
private void stopServer() {
nachrichtenBrokerMock.shutdown();
nachrichtenBrokerMock = null;
}
}
File added
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.osci.eu/ws/2008/05/transport/urn/messageTypes/MsgBoxFetchRequest</a:Action>
<h:MsgBoxResponse MsgBoxRequestID="urn:de:xta:messageid:dataport_xta_210:20eb297a-e224-45a0-9376-5ebd4d9bcc9a" xmlns:h="http://www.osci.eu/ws/2008/05/transport" xmlns="http://www.osci.eu/ws/2008/05/transport" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ItemsPending>0</ItemsPending>
</h:MsgBoxResponse>
<h:MessageMetaData xmlns:h="http://www.osci.eu/ws/2014/10/transport" xmlns="http://www.osci.eu/ws/2014/10/transport">
<DeliveryAttributes>
<Origin>2024-04-04T10:24:07.57</Origin>
<Delivery>2024-04-04T10:24:08.723</Delivery>
</DeliveryAttributes>
<Originators>
<Author>
<Identifier type="xoev">afmsh:WebMethod_Online-Dienste</Identifier>
</Author>
</Originators>
<Destinations>
<Reader>
<Identifier type="xoev">afmsh:ozg-cloud-dev001</Identifier>
</Reader>
</Destinations>
<MsgIdentification>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">%s</MessageID>
</MsgIdentification>
<Qualifier>
<Service>urn:xdomea:AFM</Service>
<BusinessScenario>
<Defined listURI="urn:de:dataport:codeliste:business.scenario" listVersionID="1">
<code xmlns="">AFM_DATA</code>
</Defined>
</BusinessScenario>
<MessageType listURI="urn:de:payloadSchema:elementName" listVersionID="1.0" payloadSchema="http://www.xdomea.de/V2.0.1">
<code xmlns="">Geschaeftsgang.Geschaeftsgang.0201</code>
</MessageType>
</Qualifier>
<MsgSize>40142</MsgSize>
</h:MessageMetaData>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GenericContentContainer xmlns="http://xoev.de/transport/xta/211">
<ContentContainer>
<Message contentType="application/zip" filename="9f1b47d4-d6bf-4ec4-b0ff-1e30bee42ef2_Geschaeftsgang.Geschaeftsgang.0201.zip" size="40142">
<xop:Include href="cid:%s" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
</Message>
</ContentContainer>
</GenericContentContainer>
</s:Body>
</s:Envelope>
<fim.S17000652.17000652001004 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:xoev-de:xfall:standard:fim-s17000652_1.4"><G17003529><G05001479><G05001480><F05002750>85ad506f-25a2-4a93-a086-b069784c6d60</F05002750><F05002751>21.03.2024 08:56:33</F05002751><F05002752>fim.S17000652.17000652001004</F05002752><F05002753>urn:fim:Versammlungsanzeige:1.4</F05002753></G05001480><G05001481><F05002754>Fachdienst Sicherheit und Ordnung - Kreis Ostholstein</F05002754><F05002755>vbe:010550120100</F05002755><F05002756>Versammlungsbehörde</F05002756></G05001481><G05001482><F05002754>Dataport</F05002754><F05002755>ehp:010100100000</F05002755><F05002756>Versammlungsbehörde</F05002756></G05001482></G05001479><F17005454>true</F17005454><F17005455>false</F17005455><F17005533>85ad506f-25a2-4a93-a086-b069784c6d60</F17005533></G17003529><F17009191>false</F17009191><G17002112><F60000228>Jörg</F60000228><F60000227>Bolay</F60000227><G60000086><F60000243>Muster</F60000243><F60000244>1</F60000244><F60000246>12345</F60000246><F60000247>Muster</F60000247></G60000086><F60000242>joerg.bolay@dataport.de</F60000242><F17009011>false</F17009011></G17002112><F17003371>Anzeigen einer ortsfesten Versammlung (Kundgebung / Demonstration)</F17003371><G17005404><G17007202><F17003373>fsdf</F17003373><F17003377>sdf</F17003377><G17005406><F60000048>2024-03-21</F60000048><F17001348>13.5</F17001348><F60000049>2024-03-21</F60000049><F17001349>15</F17001349></G17005406></G17007202><G17007205><F17003379>10</F17003379><F17003382>keine</F17003382><G17007234><F17011826>Nein</F17011826></G17007234><G17007235><F17011827>Nein</F17011827></G17007235></G17007205></G17005404></fim.S17000652.17000652001004>
\ No newline at end of file
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.osci.eu/ws/2008/05/transport/urn/messageTypes/MsgBoxFetchRequest</a:Action>
<h:MsgBoxResponse MsgBoxRequestID="urn:de:xta:messageid:dataport_xta_210:3d280bfa-d790-4865-a6cf-f6656d7be13f" xmlns:h="http://www.osci.eu/ws/2008/05/transport" xmlns="http://www.osci.eu/ws/2008/05/transport" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ItemsPending>0</ItemsPending>
</h:MsgBoxResponse>
<h:MessageMetaData xmlns:h="http://www.osci.eu/ws/2014/10/transport" xmlns="http://www.osci.eu/ws/2014/10/transport">
<DeliveryAttributes>
<InitialSend>2024-03-21T08:56:35.214+01:00</InitialSend>
<Delivery>2024-03-21T08:56:38.417</Delivery>
</DeliveryAttributes>
<Originators>
<Author>
<Identifier type="xoev" name="Dataport" category="Engagement- und Hobbyportal">ehp:010100100000</Identifier>
</Author>
</Originators>
<Destinations>
<Reader>
<Identifier type="xoev" name="L100012.OE.279550874" category="Versammlungsbehörde">vbe:010550120100</Identifier>
</Reader>
</Destinations>
<MsgIdentification>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">%s</MessageID>
</MsgIdentification>
<Qualifier>
<Service>urn:fim:Versammlungsanzeige:1.4</Service>
<BusinessScenario>
<Defined listURI="urn:de:dataport:codeliste:business.scenario" listVersionID="1">
<code xmlns="">FIM_DATA</code>
</Defined>
</BusinessScenario>
<MessageType listURI="urn:de:payloadSchema:elementName" listVersionID="1.0" payloadSchema="urn:xoev-de:xfall:standard:fim-s17000652_1.4">
<code xmlns="">fim.S17000652.17000652001004</code>
<name xmlns="">fim.S17000652.17000652001004</name>
</MessageType>
</Qualifier>
<MsgSize>1738</MsgSize>
</h:MessageMetaData>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GenericContentContainer xmlns="http://xoev.de/transport/xta/211">
<ContentContainer>
<Message contentType="application/xml" filename="Antrag.xml" size="1738">
<xop:Include href="cid:%s" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
</Message>
</ContentContainer>
</GenericContentContainer>
</s:Body>
</s:Envelope>
<MessageMetaData xmlns="http://www.osci.eu/ws/2014/10/transport">
<DeliveryAttributes>
<Origin>2024-04-04T10:24:07.57</Origin>
<Delivery>2024-04-04T10:24:08.723</Delivery>
</DeliveryAttributes>
<Originators>
<Author>
<Identifier type="xoev">afmsh:WebMethod_Online-Dienste</Identifier>
</Author>
</Originators>
<Destinations>
<Reader>
<Identifier type="xoev">afmsh:ozg-cloud-dev001</Identifier>
</Reader>
</Destinations>
<MsgIdentification>
<a:MessageID>%s</a:MessageID>
</MsgIdentification>
<Qualifier>
<Service>urn:xdomea:AFM</Service>
<BusinessScenario>
<Defined listURI="urn:de:dataport:codeliste:business.scenario" listVersionID="1">
<code xmlns="">AFM_DATA</code>
</Defined>
</BusinessScenario>
<MessageType listURI="urn:de:payloadSchema:elementName" listVersionID="1.0"
payloadSchema="http://www.xdomea.de/V2.0.1">
<code xmlns="">Geschaeftsgang.Geschaeftsgang.0201</code>
</MessageType>
</Qualifier>
<MsgSize>40142</MsgSize>
</MessageMetaData>
<MessageMetaData xmlns="http://www.osci.eu/ws/2014/10/transport">
<DeliveryAttributes>
<InitialSend>2024-03-21T08:56:35.214+01:00</InitialSend>
<Delivery>2024-03-21T08:56:38.417</Delivery>
</DeliveryAttributes>
<Originators>
<Author>
<Identifier type="xoev" name="Dataport" category="Engagement- und Hobbyportal">
ehp:010100100000
</Identifier>
</Author>
</Originators>
<Destinations>
<Reader>
<Identifier type="xoev" name="L100012.OE.279550874" category="Versammlungsbehörde">
vbe:010550120100
</Identifier>
</Reader>
</Destinations>
<MsgIdentification>
<a:MessageID>%s</a:MessageID>
</MsgIdentification>
<Qualifier>
<Service>urn:fim:Versammlungsanzeige:1.4</Service>
<BusinessScenario>
<Defined listURI="urn:de:dataport:codeliste:business.scenario" listVersionID="1">
<code xmlns="">FIM_DATA</code>
</Defined>
</BusinessScenario>
<MessageType listURI="urn:de:payloadSchema:elementName" listVersionID="1.0"
payloadSchema="urn:xoev-de:xfall:standard:fim-s17000652_1.4">
<code xmlns="">fim.S17000652.17000652001004</code>
<name xmlns="">fim.S17000652.17000652001004</name>
</MessageType>
</Qualifier>
<MsgSize>1738</MsgSize>
</MessageMetaData>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">
http://www.osci.eu/ws/2008/05/transport/urn/messageTypes/MsgBoxStatusListRequest
</a:Action>
<h:MsgBoxResponse MsgBoxRequestID="1" xmlns:h="http://www.osci.eu/ws/2008/05/transport"
xmlns="http://www.osci.eu/ws/2008/05/transport"
>
<ItemsPending>%s</ItemsPending>
</h:MsgBoxResponse>
</s:Header>
<s:Body>
<MsgStatusList xmlns="http://www.osci.eu/ws/2008/05/transport">
%s
</MsgStatusList>
</s:Body>
</s:Envelope>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment