aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at/gv/egiz/moazs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/at/gv/egiz/moazs')
-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());
}