aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at/gv
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-04-30 11:00:46 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-04-30 11:00:46 +0200
commit296d842878e530ee819fa2f58012665b76e2e670 (patch)
tree45e0078c39b5cdf4f3e8e412f4813e3bca8bd2d6 /src/test/java/at/gv
parent9a038cf18d6ebd4c68218c20ebc174b779afa7fa (diff)
downloadmoa-zs-296d842878e530ee819fa2f58012665b76e2e670.tar.gz
moa-zs-296d842878e530ee819fa2f58012665b76e2e670.tar.bz2
moa-zs-296d842878e530ee819fa2f58012665b76e2e670.zip
Add Optional mzs:DeliveryRequest/Config & Validate / Augment It
Add Optional "Config" to MZS Schema: - Add mzs:DeliveryRequest/Config Element with a "PerformQueryPersonRequest" node - The config element contains parameters that are interpreted by moa-zs and not forwarded to the ZD - The boolean PerformQueryPersonRequest tells moa-zs if moa-zs should perform a QueryPersonRequest towards the TNVZ. - If config is missing, moa-zs augments the delivery request with parameters from the app's configuartion or the default configuartion Other Changes: - Validate and augment incoming requests with the DeliveryPreprocessor. - Add stub for TlnvzClient. - Remove some leftover ObjectFactory imports (because of the builder they are not needed anymore) Fixes - Fixed incorrect API usage of Messageformat.format: format string needs an index. pom.xml - Add Hamcrest Dependency (for writing more expressive tests) - Add copy constructor to JAXB Builder Testing - Test validation of incoming request - Refactor testcases to improve readability
Diffstat (limited to 'src/test/java/at/gv')
-rw-r--r--src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java b/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java
index 5579f06..03992ae 100644
--- a/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java
+++ b/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java
@@ -6,6 +6,7 @@ import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.D
import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ObjectFactory;
import at.gv.egiz.moazs.pipeline.DeliveryPipeline;
import at.gv.egiz.moazs.repository.DeliveryRepository;
+import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@@ -24,9 +25,12 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Paths;
+import java.util.Arrays;
import static java.net.http.HttpClient.Version;
-import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.text.StringContainsInOrder.stringContainsInOrder;
+import static org.junit.Assert.assertEquals;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@@ -63,42 +67,43 @@ public class App2MzsServiceTest {
}
}
-
@Test
public void acceptValidDeliveryRequest() throws IOException, InterruptedException {
+ var response = sendDeliveryRequestFile("validDeliveryRequest.soap");
+ assertEquals(200, response.statusCode());
+ }
- final String payloadFile = basePath + "validDeliveryRequest.soap";
-
- var client = HttpClient.newBuilder().version(Version.HTTP_1_1).build();
- var request = HttpRequest.newBuilder()
- .uri(URI.create(serviceUri))
- .header("Content-Type", "text/xml;charset=UTF-8")
- .header("SOAPAction", "\"\"")
- .POST(HttpRequest.BodyPublishers.ofFile(Paths.get(payloadFile)))
- .build();
-
- var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- logger.info("response.body was " + response.body());
- logger.info("response.code was " + response.statusCode());
- assertThat(response.statusCode()).isEqualTo(200);
+ @Test
+ public void rejectFormallyIncorrectDeliveryRequest() throws IOException, InterruptedException {
+ var response = sendDeliveryRequestFile("formallyIncorrectDeliveryRequest.soap");
+ assertEquals(500, response.statusCode());
+ }
+ @Test
+ public void rejectRequestWithoutAppDeliveryID() throws IOException, InterruptedException {
+ var response = sendDeliveryRequestFile("missingAppDeliveryId.soap");
+ assertEquals(200, response.statusCode());
+ assertThat(response.body(), stringContainsInOrder(Arrays.asList("Code>", "500", "/", "Code>")));
}
@Test
- public void rejectFormallyIncorrectDeliveryRequest() throws IOException, InterruptedException {
+ public void rejectRequestWithoutMetaData() throws IOException, InterruptedException {
+ var response = sendDeliveryRequestFile("missingMetaData.soap");
+ assertEquals(500, response.statusCode());
+ }
- var invalidDeliveryRequest = basePath + "formallyIncorrectDeliveryRequest.soap";
+ private HttpResponse<String> sendDeliveryRequestFile(String fileName) throws IOException, InterruptedException {
+ var path = basePath + fileName;
var client = HttpClient.newBuilder().version(Version.HTTP_1_1).build();
var request = HttpRequest.newBuilder()
.uri(URI.create(serviceUri))
.header("Content-Type", "text/xml;charset=UTF-8")
.header("SOAPAction", "\"\"")
- .POST(HttpRequest.BodyPublishers.ofFile(Paths.get(invalidDeliveryRequest)))
+ .POST(HttpRequest.BodyPublishers.ofFile(Paths.get(path)))
.build();
- var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertThat(response.statusCode()).isEqualTo(500);
+ return client.send(request, HttpResponse.BodyHandlers.ofString());
}