aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at/gv/egiz/moazs
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-08 18:02:37 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-08 18:02:37 +0200
commitc1a1a5130a4ecf755da72941ad3525beb919447f (patch)
treeecaca5da80571e10f25186402ee73d8e062d4544 /src/test/java/at/gv/egiz/moazs
parent78f0715d86a055aed11138df5f66b0794e72326a (diff)
downloadmoa-zs-c1a1a5130a4ecf755da72941ad3525beb919447f.tar.gz
moa-zs-c1a1a5130a4ecf755da72941ad3525beb919447f.tar.bz2
moa-zs-c1a1a5130a4ecf755da72941ad3525beb919447f.zip
Implement Zuse2App Services
- Add zuse2app.wsdl contract. - Add MsgResponse as an type-agnostic view for DeliveryRequestStatus and DeliveryNotification messages. Reason: Both DeliveryNotification and DeliveryRequestStatus messages have similar fields and need to be treated similarly (e.g.: receive from msg service, store to repository, verify signature, store to file...). In order to prevent duplicated code, the wrapper interface provides a type-agnostic view onto these messages for depending components to operate on. - Add MsgResponseHandler interface; decides how to process MsgResponse. Also implement this handler with a multi-threaded single-node implementation. - Add MsgResponseSink interface; decides how to archive MsgResponse. - Implement and test SafeResponseToFileSink. Change Identifier for MsgResponses: - Before, DeliveryRequestStatus and DeliveryNotifications had their own repositories. Now, both types are stored in the same repository (the MsgResponse repository) to streamline the handling of MsgResponses. We need to change the identification of MsgReponses, otherwise the identifiers (AppDeliveryID) clash. - MsgResponses are not identified by: <AppDeliveryId>+<typeSpecificSuffix> - Rewrite StoreSOAPInterceptor to accommodate fact that, both DeliveryRequestStatus and DeliveryNotification messages have different IDs upon storage / retrieval. Restructure packages and components as follows: - client: All components that are involved when consuming a web service. - process: "fabric" of MoaZS; contains business logic that orchestrates back-end tasks of MoaZS's operational services, e.g.: by processing a delivery request. - service: Implementation of MoaZS's front-end services. Refactoring: - MoaZSException: Remove unused fields. Before: Store mzsrequest, tnvzresult, msgrequest and msgresult as members. Now: Only keep the fields that are needed later, e.g for generating a msg:DeliveryRequestStatus element. Add copy constructor to Builder. - Put storage of byte[] into a dedicated "BinaryRepository". Reason: This was useful in a former design. Now it's not really needed anymore. - Put "create Endpoint" code into EndpointFactory. Reason: Eliminate duplicated code when configuring a service. Testing: - Activate Stacktraces in surefire.
Diffstat (limited to 'src/test/java/at/gv/egiz/moazs')
-rw-r--r--src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java2
-rw-r--r--src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java2
-rw-r--r--src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java2
-rw-r--r--src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java5
-rw-r--r--src/test/java/at/gv/egiz/moazs/SafeResponseToFileSinkTest.java113
-rw-r--r--src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java78
-rw-r--r--src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java2
7 files changed, 169 insertions, 35 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java b/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java
index ff981a9..f408c3b 100644
--- a/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java
+++ b/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java
@@ -1,6 +1,6 @@
package at.gv.egiz.moazs;
-import at.gv.egiz.moazs.scheme.MzsDeliveryRequestValidator;
+import at.gv.egiz.moazs.preprocess.MzsDeliveryRequestValidator;
import at.gv.egiz.moazs.preprocess.*;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java b/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java
index 3bc0d3b..12f1dea 100644
--- a/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java
+++ b/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java
@@ -1,6 +1,6 @@
package at.gv.egiz.moazs;
-import at.gv.egiz.moazs.scheme.MzsDeliveryRequestValidator;
+import at.gv.egiz.moazs.preprocess.MzsDeliveryRequestValidator;
import at.gv.egiz.moazs.preprocess.ConfigUtil;
import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter;
import at.gv.zustellung.app2mzs.xsd.ConfigType;
diff --git a/src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java b/src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java
index 70e300c..0f87dd6 100644
--- a/src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java
+++ b/src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java
@@ -1,6 +1,6 @@
package at.gv.egiz.moazs;
-import at.gv.egiz.moazs.util.ClientFactory;
+import at.gv.egiz.moazs.client.ClientFactory;
import at.gv.egiz.moazs.scheme.Marshaller;
import at.gv.zustellung.app2mzs.xsd.ClientType;
import at.gv.zustellung.app2mzs.xsd.KeyStoreType;
diff --git a/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java b/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java
index 4f24518..22aa03f 100644
--- a/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java
+++ b/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java
@@ -1,7 +1,8 @@
package at.gv.egiz.moazs;
-import at.gv.egiz.moazs.pipeline.DeliveryPipeline;
+import at.gv.egiz.moazs.process.DeliveryPipeline;
import at.gv.egiz.moazs.repository.DeliveryRepository;
+import at.gv.egiz.moazs.scheme.RequestStatusResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@@ -63,7 +64,7 @@ public class ITMzsServiceTest {
.withSuccess(success)
.build();
- repository.add(status);
+ repository.add(new RequestStatusResponse(status));
};
}
diff --git a/src/test/java/at/gv/egiz/moazs/SafeResponseToFileSinkTest.java b/src/test/java/at/gv/egiz/moazs/SafeResponseToFileSinkTest.java
new file mode 100644
index 0000000..9092dfb
--- /dev/null
+++ b/src/test/java/at/gv/egiz/moazs/SafeResponseToFileSinkTest.java
@@ -0,0 +1,113 @@
+package at.gv.egiz.moazs;
+
+import at.gv.egiz.moazs.process.SafeResponseToFileSink;
+import at.gv.egiz.moazs.repository.BinaryRepository;
+import at.gv.egiz.moazs.scheme.Marshaller;
+import at.gv.egiz.moazs.scheme.RequestStatusResponse;
+import org.apache.commons.io.FileUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+
+import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.Success.successBuilder;
+import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder;
+import static java.util.Optional.of;
+import static org.apache.commons.io.FileUtils.readFileToString;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class SafeResponseToFileSinkTest {
+
+ private static final Logger log = LoggerFactory.getLogger(SafeResponseToFileSinkTest.class);
+
+ private SafeResponseToFileSink sink;
+
+ private final String root = "./target/tmp/SafeResponseToFileSinkTestOut";
+
+ @Mock
+ private BinaryRepository repository;
+
+ @Mock
+ private Marshaller marshaller;
+
+
+ @Before
+ public void setup() {
+ sink = new SafeResponseToFileSink(marshaller, repository, root);
+ deleteRoot();
+
+ }
+
+ private void deleteRoot() {
+ try {
+ FileUtils.deleteDirectory(new File(root));
+ } catch (IOException e) {
+ log.warn("Could not delete {}", root);
+ }
+ }
+
+ @Test
+ public void safeRequestToFiles() {
+
+ var fileContent = "<xml>some content</xml>";
+ var status = setupMocks(fileContent);
+
+ sink.handle(status)
+ .thenRun(() -> assertFilesCreatedAndContentMatches(fileContent));
+ }
+
+ private void assertFilesCreatedAndContentMatches(String fileContent) {
+ var rootFolder = new File(root);
+ Collection<File> files = FileUtils.listFiles(rootFolder, null, true);
+
+ assertThat(rootFolder.exists()).isTrue();
+ assertThat(rootFolder.isDirectory()).isTrue();
+ assertThat(files).isNotEmpty();
+
+ files.stream()
+ .map(file -> readFile(file))
+ .forEach(content -> assertThat(content).isEqualTo(fileContent));
+ }
+
+ private String readFile(File file) {
+ try {
+ return readFileToString(file, StandardCharsets.UTF_8);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private RequestStatusResponse setupMocks(String fileContent) {
+
+ var appDeliveryId = "app-delivery-id";
+ var responseId = RequestStatusResponse.getResponseID(appDeliveryId);
+
+ when(repository.get(responseId))
+ .thenReturn(of(fileContent.getBytes(StandardCharsets.UTF_8)));
+ when(marshaller.marshallXml(any())).thenReturn(fileContent);
+
+ var success = successBuilder()
+ .withAppDeliveryID(appDeliveryId)
+ .build();
+
+ var status = deliveryRequestStatusTypeBuilder()
+ .withSuccess(success)
+ .build();
+
+ return new RequestStatusResponse(status);
+
+
+ }
+
+}
diff --git a/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java b/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java
index c08d567..e145cd9 100644
--- a/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java
+++ b/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java
@@ -1,12 +1,14 @@
package at.gv.egiz.moazs;
-import at.gv.egiz.moazs.util.ClientFactory;
-import at.gv.egiz.moazs.pipeline.DeliveryPipeline;
-import at.gv.egiz.moazs.pipeline.SingleThreadedDeliveryPipeline;
+import at.gv.egiz.moazs.process.DeliveryPipeline;
+import at.gv.egiz.moazs.process.SingleThreadedDeliveryPipeline;
+import at.gv.egiz.moazs.client.TnvzHelper;
+import at.gv.egiz.moazs.repository.BinaryRepository;
+import at.gv.egiz.moazs.repository.InMemoryBinaryRepository;
+import at.gv.egiz.moazs.scheme.*;
+import at.gv.egiz.moazs.client.ClientFactory;
import at.gv.egiz.moazs.repository.DeliveryRepository;
import at.gv.egiz.moazs.repository.InMemoryDeliveryRepository;
-import at.gv.egiz.moazs.scheme.Mzs2MsgConverter;
-import at.gv.egiz.moazs.scheme.TnvzHelper;
import at.gv.egiz.moazs.verify.MoaSPSSSignatureVerifier;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
import at.gv.zustellung.msg.xsd.App2ZusePort;
@@ -22,6 +24,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import static at.gv.egiz.moazs.MoaZSException.moaZSException;
import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder;
+import static at.gv.egiz.moazs.scheme.RequestStatusResponse.getResponseID;
import static at.gv.zustellung.app2mzs.xsd.ClientType.clientTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.deliveryRequestTypeBuilder;
@@ -37,6 +40,7 @@ import static org.mockito.Mockito.*;
public class SingleThreadedDeliveryPipelineTest {
private DeliveryRepository repository = new InMemoryDeliveryRepository();
+ private BinaryRepository binaryRepository = new InMemoryBinaryRepository(30);
@Mock
private TnvzHelper tnvzHelper;
@@ -61,57 +65,70 @@ public class SingleThreadedDeliveryPipelineTest {
@Before
public void setup() {
- pipeline = new SingleThreadedDeliveryPipeline(repository, tnvzHelper, converter, clientFactory, verifier);
+ pipeline = new SingleThreadedDeliveryPipeline(
+ repository,
+ binaryRepository,
+ tnvzHelper,
+ converter,
+ clientFactory,
+ verifier);
}
@Test
public void executePipelineWithoutTnvzRequest() {
- var appDeliveryId = "no-tnvz-request";
- var expectedStatus = setupMocks(appDeliveryId, false);
+ var appDeliveryID = "no-tnvz-request";
+ var expectedStatus = setupMocks(appDeliveryID, false);
- pipeline.processRequest(appDeliveryId);
+ pipeline.processRequest(appDeliveryID);
verifyZeroInteractions(tnvzHelper);
- var actualStatus = repository.getDeliveryRequestStatus(appDeliveryId).get();
+ var response = repository.getResponse(getResponseID(appDeliveryID)).get();
+ var actualStatus = (DeliveryRequestStatusType) response.getResponse();
assertThat(actualStatus).isEqualTo(expectedStatus);
}
@Test
public void rejectDeliveryWhenReceiverIsNotAddressable() {
- var appDeliveryId = "not-addressable";
- setupMocks(appDeliveryId, true);
+ var appDeliveryID = "not-addressable";
+ setupMocks(appDeliveryID, true);
when(tnvzHelper.performQueryPersonRequest(any(), any(), any()))
- .thenThrow(buildMzsException("400"));
+ .thenThrow(buildMzsException("400", appDeliveryID));
- pipeline.processRequest(appDeliveryId);
- var actualCode = repository.getDeliveryRequestStatus(appDeliveryId).get()
- .getError().getErrorInfo().getCode();
+ pipeline.processRequest(appDeliveryID);
+
+ var responseId = getResponseID(appDeliveryID);
+ var response = repository.getResponse(responseId).get();
+ var status = (DeliveryRequestStatusType) response.getResponse();
+ var actualCode = status.getError().getErrorInfo().getCode();
- verify(tnvzHelper).performQueryPersonRequest(any(), any(), any());
assertThat(actualCode).isEqualTo("400");
+ verifyZeroInteractions(converter);
+ verify(tnvzHelper).performQueryPersonRequest(any(), any(), any());
}
@Test
public void executePipelineWithTnvzRequest() {
- var appDeliveryId = "tnvz-request";
- var expectedStatus = setupMocks(appDeliveryId, true);
+ var appDeliveryID = "tnvz-request";
+ var expectedStatus = setupMocks(appDeliveryID, true);
- pipeline.processRequest(appDeliveryId);
- var actualStatus = repository.getDeliveryRequestStatus(appDeliveryId).get();
+ pipeline.processRequest(appDeliveryID);
+ var response = repository.getResponse(getResponseID(appDeliveryID)).get();
+ var actualStatus = (DeliveryRequestStatusType) response.getResponse();
assertThat(actualStatus).isEqualTo(expectedStatus);
}
@Test
public void rejectInvalidSignature() {
- var appDeliveryId = "invalid-signature";
- setupMocks(appDeliveryId, true);
+ var appDeliveryID = "invalid-signature";
+ setupMocks(appDeliveryID, true);
doThrow(moaZSException("Signature Invalid!")).when(verifier).verify(any());
- pipeline.processRequest(appDeliveryId);
- var actualCode = repository.getDeliveryRequestStatus(appDeliveryId).get()
- .getError().getErrorInfo().getCode();
+ pipeline.processRequest(appDeliveryID);
+ var response = repository.getResponse(getResponseID(appDeliveryID)).get();
+ var status = (DeliveryRequestStatusType) response.getResponse();
+ var actualCode = status.getError().getErrorInfo().getCode();
assertThat(actualCode).isEqualTo(MoaZSException.ERROR_MOASP_SIGNATURE_INVALID);
@@ -125,7 +142,7 @@ public class SingleThreadedDeliveryPipelineTest {
var signedStatus = new byte[0];
var identification = IdentificationType.identificationTypeBuilder().build();
repository.add(mzsRequest);
- repository.addSignedDeliveryRequestStatus(signedStatus, appDeliveryId);
+ binaryRepository.add(getResponseID(appDeliveryId), signedStatus);
when(converter.convert(eq(mzsRequest) )).thenReturn(msgRequest);
when(converter.convert(eq(mzsRequest), any())).thenReturn(msgRequest);
@@ -140,8 +157,11 @@ public class SingleThreadedDeliveryPipelineTest {
}
- private MoaZSException buildMzsException(String code) {
- return moaZSExceptionBuilder("").withErrorCode(code).build();
+ private MoaZSException buildMzsException(String code, String appDeliveryID) {
+ return moaZSExceptionBuilder("")
+ .withErrorCode(code)
+ .withAppDeliveryID(appDeliveryID)
+ .build();
}
private DeliveryRequestStatusType setupStatus(String appDeliveryId) {
diff --git a/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java b/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java
index 66873d4..b58002b 100644
--- a/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java
+++ b/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java
@@ -2,7 +2,7 @@ package at.gv.egiz.moazs;
import at.gv.egiz.moazs.scheme.Mzs2MsgConverter;
-import at.gv.egiz.moazs.scheme.TnvzHelper;
+import at.gv.egiz.moazs.client.TnvzHelper;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
import at.gv.zustellung.app2mzs.xsd.persondata.IdentificationType;
import at.gv.zustellung.tnvz.xsd.MimeTypeList;