aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at/gv
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/at/gv')
-rw-r--r--src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java31
-rw-r--r--src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java137
2 files changed, 51 insertions, 117 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java b/src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java
index 2b758a9..bb9633e 100644
--- a/src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java
+++ b/src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java
@@ -1,10 +1,10 @@
package at.gv.egiz.moazs;
-import at.gv.egiz.moazs.msg.MsgClientFactory;
-import at.gv.egiz.moazs.msg.StoreSOAPBodyBinaryInRepositoryInterceptor;
+import at.gv.egiz.moazs.msg.ClientFactory;
import at.gv.egiz.moazs.scheme.Marshaller;
import at.gv.zustellung.app2mzs.xsd.ClientType;
import at.gv.zustellung.app2mzs.xsd.KeyStoreType;
+import at.gv.zustellung.msg.xsd.App2ZusePort;
import at.gv.zustellung.msg.xsd.DeliveryRequestType;
import at.gv.zustellung.msg.xsd.ObjectFactory;
import org.junit.Test;
@@ -36,7 +36,7 @@ public class ITMsgClientTest {
private Marshaller msgMarshaller;
@Autowired
- private MsgClientFactory factory;
+ private ClientFactory factory;
private static final ObjectFactory OF = new ObjectFactory();
@@ -54,13 +54,16 @@ public class ITMsgClientTest {
.withReceiveTimeout(BigInteger.ZERO)
.build();
- var client = factory.create(clientParams);
-
- var status = client.delivery(request);
+ App2ZusePort port = createPort(clientParams);
+ var status = port.delivery(request);
assertThat(status.getPartialSuccess().getAppDeliveryID()).isEqualTo(VALID_MZS_REQUEST_ID);
}
+ private App2ZusePort createPort(ClientType params) {
+ return factory.create(params, App2ZusePort.class);
+ }
+
// Requirements:
// - run zusemsg service under httpsServiceURL
// - server trusts client cert (by trusting CA bundle in ssl/trusted-cas-bundle.pem)
@@ -73,9 +76,9 @@ public class ITMsgClientTest {
var httpsServiceURL = "https://localhost/zusemsg/services/DeliveryRequest";
var clientParams = generateSSLClientParams(httpsServiceURL, false, false);
- var client = factory.create(clientParams);
+ App2ZusePort port = createPort(clientParams);
- var status = client.delivery(request);
+ var status = port.delivery(request);
assertThat(status.getPartialSuccess().getAppDeliveryID()).isEqualTo(VALID_MZS_REQUEST_ID);
}
@@ -91,9 +94,9 @@ public class ITMsgClientTest {
var httpsServiceURL = "https://localhost/zusemsg/services/DeliveryRequest";
var clientParams = generateSSLClientParams(httpsServiceURL, true, false);
- var client = factory.create(clientParams);
+ App2ZusePort port = createPort(clientParams);
- var status = client.delivery(request);
+ var status = port.delivery(request);
assertThat(status.getPartialSuccess().getAppDeliveryID()).isEqualTo(VALID_MZS_REQUEST_ID);
}
@@ -109,9 +112,9 @@ public class ITMsgClientTest {
var httpsServiceURL = "https://notlocalhost/zusemsg/services/DeliveryRequest";
var clientParams = generateSSLClientParams(httpsServiceURL, false, true);
- var client = factory.create(clientParams);
+ App2ZusePort port = createPort(clientParams);
- var status = client.delivery(request);
+ var status = port.delivery(request);
assertThat(status.getPartialSuccess().getAppDeliveryID()).isEqualTo(VALID_MZS_REQUEST_ID);
}
@@ -127,9 +130,9 @@ public class ITMsgClientTest {
var httpsServiceURL = "https://notlocalhost/zusemsg/services/DeliveryRequest";
var clientParams = generateSSLClientParams(httpsServiceURL, false, false);
- var client = factory.create(clientParams);
+ App2ZusePort port = createPort(clientParams);
- client.delivery(request);
+ port.delivery(request);
}
private ClientType generateSSLClientParams(String httpsServiceURL, boolean trustAll, boolean laxHostNameVerification) {
diff --git a/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java b/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java
index e685816..74e6157 100644
--- a/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java
+++ b/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java
@@ -1,45 +1,37 @@
package at.gv.egiz.moazs;
-import at.gv.egiz.moazs.msg.MsgClientFactory;
+import at.gv.egiz.moazs.msg.ClientFactory;
import at.gv.egiz.moazs.pipeline.DeliveryPipeline;
import at.gv.egiz.moazs.pipeline.SameThreadDeliveryPipeline;
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.tnvz.TnvzClient;
-import at.gv.egiz.moazs.tnvz.TnvzResultVerifier;
+import at.gv.egiz.moazs.tnvz.TnvzHelper;
import at.gv.egiz.moazs.verify.MoaSPSSSignatureVerifier;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
import at.gv.zustellung.msg.xsd.App2ZusePort;
import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType;
import at.gv.zustellung.msg.xsd.MetaData;
-import at.gv.zustellung.tnvz.xsd.MimeTypeList;
-import at.gv.zustellung.tnvz.xsd.PersonResultType;
+import at.gv.zustellung.msg.xsd.persondata.IdentificationType;
+import at.gv.zustellung.tnvz.xsd.TNVZServicePort;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
-import java.util.List;
-
import static at.gv.egiz.moazs.MoaZSException.moaZSException;
+import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder;
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.Payload;
-import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Payload.payloadBuilder;
import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.deliveryRequestTypeBuilder;
import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.Success.successBuilder;
import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder;
-import static at.gv.zustellung.msg.xsd.ErrorInfoType.errorInfoTypeBuilder;
import static at.gv.zustellung.msg.xsd.MetaData.metaDataBuilder;
-import static at.gv.zustellung.tnvz.xsd.MimeTypeList.mimeTypeListBuilder;
-import static at.gv.zustellung.tnvz.xsd.PersonResultSuccessType.personResultSuccessTypeBuilder;
-import static at.gv.zustellung.tnvz.xsd.PersonResultType.Error.errorBuilder;
-import static at.gv.zustellung.tnvz.xsd.PersonResultType.personResultTypeBuilder;
-import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
@@ -48,15 +40,18 @@ public class SameThreadDeliveryPipelineTest {
private DeliveryRepository repository = new InMemoryDeliveryRepository();
@Mock
- private TnvzClient tnvzClient;
+ private TnvzHelper tnvzHelper;
@Mock
- private MsgClientFactory msgClientFactory;
+ private ClientFactory clientFactory;
@Mock
private App2ZusePort msgClient;
@Mock
+ private TNVZServicePort tnvzClient;
+
+ @Mock
private Mzs2MsgConverter converter;
@Mock
@@ -67,18 +62,17 @@ public class SameThreadDeliveryPipelineTest {
@Before
public void setup() {
- pipeline = new SameThreadDeliveryPipeline(repository, tnvzClient, new TnvzResultVerifier(),
- converter, msgClientFactory, verifier);
+ pipeline = new SameThreadDeliveryPipeline(repository, tnvzHelper, converter, clientFactory, verifier);
}
@Test
public void executePipelineWithoutTnvzRequest() {
var appDeliveryId = "no-tnvz-request";
- var expectedStatus = setupMocks(appDeliveryId, false, List.of(), List.of("*/*"));
+ var expectedStatus = setupMocks(appDeliveryId, false);
pipeline.processRequest(appDeliveryId);
- verifyZeroInteractions(tnvzClient);
+ verifyZeroInteractions(tnvzHelper);
var actualStatus = repository.getDeliveryRequestStatus(appDeliveryId).get();
assertThat(actualStatus).isEqualTo(expectedStatus);
@@ -87,65 +81,33 @@ public class SameThreadDeliveryPipelineTest {
@Test
public void rejectDeliveryWhenReceiverIsNotAddressable() {
var appDeliveryId = "not-addressable";
- setupMocks(appDeliveryId, true, List.of(), List.of("*/*"));
- when(tnvzClient.query(any(), any())).thenReturn(setupTnvzError("400", "Person not found."));
+ setupMocks(appDeliveryId, true);
+ when(tnvzHelper.performQueryPersonRequest(any(), any(), any()))
+ .thenThrow(buildMzsException("400"));
pipeline.processRequest(appDeliveryId);
var actualCode = repository.getDeliveryRequestStatus(appDeliveryId).get()
.getError().getErrorInfo().getCode();
- verify(tnvzClient).query(any(), any());
+ verify(tnvzHelper).performQueryPersonRequest(any(), any(), any());
assertThat(actualCode).isEqualTo("400");
}
@Test
- public void acceptWildcardMimeType() {
- var appDeliveryId = "wild-card-mimetype";
- List<String> acceptedTypes = List.of("*/*");
- List<String> attachedTypes = List.of("pdf", "xml", "html", "random/attachedtype");
- var expectedStatus = setupMocks(appDeliveryId, true, attachedTypes, acceptedTypes);
+ public void executePipelineWithTnvzRequest() {
+ var appDeliveryId = "tnvz-request";
+ var expectedStatus = setupMocks(appDeliveryId, true);
pipeline.processRequest(appDeliveryId);
var actualStatus = repository.getDeliveryRequestStatus(appDeliveryId).get();
- verify(tnvzClient).query(any(), any());
- assertThat(actualStatus).isEqualTo(expectedStatus);
- }
-
- @Test
- public void rejectMismatchedMimeTypes() {
- var appDeliveryId = "mismatched-mimetype";
- List<String> acceptedTypes = List.of("xml");
- List<String> attachedTypes = List.of("pdf", "xml", "html", "random/attachedtype");
- setupMocks(appDeliveryId, true, attachedTypes, acceptedTypes);
-
- pipeline.processRequest(appDeliveryId);
- var actualCode = repository.getDeliveryRequestStatus(appDeliveryId).get()
- .getError().getErrorInfo().getCode();
-
- verify(tnvzClient).query(any(), any());
- assertThat(actualCode).isEqualTo(MoaZSException.ERROR_MZS_MIMETYPE_MISSMATCH);
-
- }
-
- @Test
- public void acceptSpecificMimeType() {
- var appDeliveryId = "specific-mimetype";
- List<String> acceptedTypes = List.of("pdf", "xml", "html");
- List<String> attachedTypes = List.of("pdf", "xml");
- var expectedStatus = setupMocks(appDeliveryId, true, attachedTypes, acceptedTypes);
-
- pipeline.processRequest(appDeliveryId);
- var actualStatus = repository.getDeliveryRequestStatus(appDeliveryId).get();
-
- verify(tnvzClient).query(any(), any());
assertThat(actualStatus).isEqualTo(expectedStatus);
}
@Test
public void rejectInvalidSignature() {
var appDeliveryId = "invalid-signature";
- setupMocks(appDeliveryId, true, List.of(), List.of("*/*"));
+ setupMocks(appDeliveryId, true);
doThrow(moaZSException("Signature Invalid!")).when(verifier).verify(any());
pipeline.processRequest(appDeliveryId);
@@ -156,51 +118,31 @@ public class SameThreadDeliveryPipelineTest {
}
- private DeliveryRequestStatusType setupMocks(String appDeliveryId, boolean tnvzRequest,
- List<String> attachedTypes, List<String> acceptedTypes) {
+ private DeliveryRequestStatusType setupMocks(String appDeliveryId, boolean tnvzRequest) {
- var mzsRequest = setupMzsRequest(appDeliveryId, tnvzRequest, attachedTypes);
+ var mzsRequest = setupMzsRequest(appDeliveryId, tnvzRequest);
var msgRequest = setupMsgRequest(appDeliveryId);
var status = setupStatus(appDeliveryId);
var signedStatus = new byte[0];
+ var identification = IdentificationType.identificationTypeBuilder().build();
repository.add(mzsRequest);
repository.addSignedDeliveryRequestStatus(signedStatus, appDeliveryId);
- when(tnvzClient.query(any(), any())).thenReturn(setupTnvzSuccess(acceptedTypes));
when(converter.convert(eq(mzsRequest) )).thenReturn(msgRequest);
when(converter.convert(eq(mzsRequest), any())).thenReturn(msgRequest);
- when(msgClientFactory.create(any())).thenReturn(msgClient);
+ when(clientFactory.create(any(), same(App2ZusePort.class))).thenReturn(msgClient);
when(msgClient.delivery(msgRequest)).thenReturn(status);
+ if (tnvzRequest) {
+ when(clientFactory.create(any(), same(TNVZServicePort.class))).thenReturn(tnvzClient);
+ when(tnvzHelper.performQueryPersonRequest(any(), any(), any())).thenReturn(identification);
+ }
return status;
}
- private PersonResultType setupTnvzError(String code, String text) {
-
- var info = errorInfoTypeBuilder()
- .withCode(code)
- .withText(text)
- .build();
-
- var error = errorBuilder()
- .withErrorInfo(info)
- .build();
-
- return personResultTypeBuilder()
- .withError(error)
- .build();
- }
-
- private PersonResultType setupTnvzSuccess(List<String> mimeTypes) {
-
- var success = personResultSuccessTypeBuilder()
- .withMimeTypeList(setupMimeTypeList(mimeTypes))
- .build();
-
- return personResultTypeBuilder()
- .withSuccess(success)
- .build();
+ private MoaZSException buildMzsException(String code) {
+ return moaZSExceptionBuilder("").withErrorCode(code).build();
}
private DeliveryRequestStatusType setupStatus(String appDeliveryId) {
@@ -215,7 +157,7 @@ public class SameThreadDeliveryPipelineTest {
}
- private DeliveryRequestType setupMzsRequest(String appDeliveryId, boolean tnvzRequest, List<String> mimeTypes) {
+ private DeliveryRequestType setupMzsRequest(String appDeliveryId, boolean tnvzRequest) {
var msgClient = clientTypeBuilder()
.withURL("http://zuse")
@@ -229,20 +171,9 @@ public class SameThreadDeliveryPipelineTest {
return deliveryRequestTypeBuilder()
.withMetaData(setupMetaData(appDeliveryId))
.withConfig(config)
- .withPayload(setupPayload(mimeTypes))
.build();
}
- private List<Payload> setupPayload(List<String> mimeTypes) {
- return mimeTypes.stream()
- .map((mtype) -> payloadBuilder().withMIMEType(mtype).build())
- .collect(toList());
- }
-
- private MimeTypeList setupMimeTypeList(List<String> mimeTypes) {
- return mimeTypeListBuilder().withMimeType(mimeTypes).build();
- }
-
private at.gv.zustellung.msg.xsd.DeliveryRequestType setupMsgRequest(String appDeliveryId) {
return at.gv.zustellung.msg.xsd.DeliveryRequestType.deliveryRequestTypeBuilder()
.withMetaData(setupMetaData(appDeliveryId))