From 78f0715d86a055aed11138df5f66b0794e72326a Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Wed, 3 Jul 2019 15:27:14 +0200 Subject: Refactor: Restructure Project - Move components that depend on the service contracts into scheme package. - Move cxf related components into util package. - Rename SameThread to SingleThreaded. --- .../gv/egiz/moazs/ConfigProfileGeneratorTest.java | 4 +- .../egiz/moazs/DeliveryRequestAugmenterTest.java | 4 +- .../java/at/gv/egiz/moazs/ITMsgClientTest.java | 2 +- .../egiz/moazs/SameThreadDeliveryPipelineTest.java | 189 --------------------- .../moazs/SingleThreadedDeliveryPipelineTest.java | 188 ++++++++++++++++++++ src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java | 2 +- 6 files changed, 194 insertions(+), 195 deletions(-) delete mode 100644 src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java create mode 100644 src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java (limited to 'src/test/java/at/gv') diff --git a/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java b/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java index 3157447..ff981a9 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.mzs.MzsValidator; +import at.gv.egiz.moazs.scheme.MzsDeliveryRequestValidator; import at.gv.egiz.moazs.preprocess.*; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,7 +25,7 @@ public class ConfigProfileGeneratorTest { private ConfigUtil util; @Mock - private MzsValidator validator; + private MzsDeliveryRequestValidator validator; @Mock private SpringPropertiesFacade properties; diff --git a/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java b/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java index 424dce1..3bc0d3b 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.mzs.MzsValidator; +import at.gv.egiz.moazs.scheme.MzsDeliveryRequestValidator; import at.gv.egiz.moazs.preprocess.ConfigUtil; import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter; import at.gv.zustellung.app2mzs.xsd.ConfigType; @@ -29,7 +29,7 @@ public class DeliveryRequestAugmenterTest { private ConfigUtil configUtil; @Mock - private MzsValidator validator; + private MzsDeliveryRequestValidator validator; @Before public void setupMock() { diff --git a/src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java b/src/test/java/at/gv/egiz/moazs/ITMsgClientTest.java index bb9633e..70e300c 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.msg.ClientFactory; +import at.gv.egiz.moazs.util.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/SameThreadDeliveryPipelineTest.java b/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java deleted file mode 100644 index 74e6157..0000000 --- a/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java +++ /dev/null @@ -1,189 +0,0 @@ -package at.gv.egiz.moazs; - -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.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.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 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.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.MetaData.metaDataBuilder; -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) -public class SameThreadDeliveryPipelineTest { - - private DeliveryRepository repository = new InMemoryDeliveryRepository(); - - @Mock - private TnvzHelper tnvzHelper; - - @Mock - private ClientFactory clientFactory; - - @Mock - private App2ZusePort msgClient; - - @Mock - private TNVZServicePort tnvzClient; - - @Mock - private Mzs2MsgConverter converter; - - @Mock - private MoaSPSSSignatureVerifier verifier; - - - private DeliveryPipeline pipeline; - - @Before - public void setup() { - pipeline = new SameThreadDeliveryPipeline(repository, tnvzHelper, converter, clientFactory, verifier); - } - - @Test - public void executePipelineWithoutTnvzRequest() { - var appDeliveryId = "no-tnvz-request"; - var expectedStatus = setupMocks(appDeliveryId, false); - - pipeline.processRequest(appDeliveryId); - - verifyZeroInteractions(tnvzHelper); - var actualStatus = repository.getDeliveryRequestStatus(appDeliveryId).get(); - - assertThat(actualStatus).isEqualTo(expectedStatus); - } - - @Test - public void rejectDeliveryWhenReceiverIsNotAddressable() { - var appDeliveryId = "not-addressable"; - 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(tnvzHelper).performQueryPersonRequest(any(), any(), any()); - assertThat(actualCode).isEqualTo("400"); - } - - @Test - public void executePipelineWithTnvzRequest() { - var appDeliveryId = "tnvz-request"; - var expectedStatus = setupMocks(appDeliveryId, true); - - pipeline.processRequest(appDeliveryId); - var actualStatus = repository.getDeliveryRequestStatus(appDeliveryId).get(); - - assertThat(actualStatus).isEqualTo(expectedStatus); - } - - @Test - public void rejectInvalidSignature() { - 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(); - - assertThat(actualCode).isEqualTo(MoaZSException.ERROR_MOASP_SIGNATURE_INVALID); - - } - - private DeliveryRequestStatusType setupMocks(String appDeliveryId, boolean tnvzRequest) { - - 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(converter.convert(eq(mzsRequest) )).thenReturn(msgRequest); - when(converter.convert(eq(mzsRequest), any())).thenReturn(msgRequest); - 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 MoaZSException buildMzsException(String code) { - return moaZSExceptionBuilder("").withErrorCode(code).build(); - } - - private DeliveryRequestStatusType setupStatus(String appDeliveryId) { - - var success = successBuilder() - .withAppDeliveryID(appDeliveryId) - .build(); - - return deliveryRequestStatusTypeBuilder() - .withSuccess(success) - .build(); - - } - - private DeliveryRequestType setupMzsRequest(String appDeliveryId, boolean tnvzRequest) { - - var msgClient = clientTypeBuilder() - .withURL("http://zuse") - .build(); - - var config = configTypeBuilder() - .withPerformQueryPersonRequest(tnvzRequest) - .withMSGClient(msgClient) - .build(); - - return deliveryRequestTypeBuilder() - .withMetaData(setupMetaData(appDeliveryId)) - .withConfig(config) - .build(); - } - - private at.gv.zustellung.msg.xsd.DeliveryRequestType setupMsgRequest(String appDeliveryId) { - return at.gv.zustellung.msg.xsd.DeliveryRequestType.deliveryRequestTypeBuilder() - .withMetaData(setupMetaData(appDeliveryId)) - .build(); - } - - private MetaData setupMetaData(String appDeliveryId) { - return metaDataBuilder() - .withAppDeliveryID(appDeliveryId) - .build(); - } - -} diff --git a/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java b/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java new file mode 100644 index 0000000..c08d567 --- /dev/null +++ b/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java @@ -0,0 +1,188 @@ +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.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; +import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; +import at.gv.zustellung.msg.xsd.MetaData; +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.junit.MockitoJUnitRunner; + +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.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.MetaData.metaDataBuilder; +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) +public class SingleThreadedDeliveryPipelineTest { + + private DeliveryRepository repository = new InMemoryDeliveryRepository(); + + @Mock + private TnvzHelper tnvzHelper; + + @Mock + private ClientFactory clientFactory; + + @Mock + private App2ZusePort msgClient; + + @Mock + private TNVZServicePort tnvzClient; + + @Mock + private Mzs2MsgConverter converter; + + @Mock + private MoaSPSSSignatureVerifier verifier; + + + private DeliveryPipeline pipeline; + + @Before + public void setup() { + pipeline = new SingleThreadedDeliveryPipeline(repository, tnvzHelper, converter, clientFactory, verifier); + } + + @Test + public void executePipelineWithoutTnvzRequest() { + var appDeliveryId = "no-tnvz-request"; + var expectedStatus = setupMocks(appDeliveryId, false); + + pipeline.processRequest(appDeliveryId); + + verifyZeroInteractions(tnvzHelper); + var actualStatus = repository.getDeliveryRequestStatus(appDeliveryId).get(); + + assertThat(actualStatus).isEqualTo(expectedStatus); + } + + @Test + public void rejectDeliveryWhenReceiverIsNotAddressable() { + var appDeliveryId = "not-addressable"; + 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(tnvzHelper).performQueryPersonRequest(any(), any(), any()); + assertThat(actualCode).isEqualTo("400"); + } + + @Test + public void executePipelineWithTnvzRequest() { + var appDeliveryId = "tnvz-request"; + var expectedStatus = setupMocks(appDeliveryId, true); + + pipeline.processRequest(appDeliveryId); + var actualStatus = repository.getDeliveryRequestStatus(appDeliveryId).get(); + + assertThat(actualStatus).isEqualTo(expectedStatus); + } + + @Test + public void rejectInvalidSignature() { + 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(); + + assertThat(actualCode).isEqualTo(MoaZSException.ERROR_MOASP_SIGNATURE_INVALID); + + } + + private DeliveryRequestStatusType setupMocks(String appDeliveryId, boolean tnvzRequest) { + + 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(converter.convert(eq(mzsRequest) )).thenReturn(msgRequest); + when(converter.convert(eq(mzsRequest), any())).thenReturn(msgRequest); + 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 MoaZSException buildMzsException(String code) { + return moaZSExceptionBuilder("").withErrorCode(code).build(); + } + + private DeliveryRequestStatusType setupStatus(String appDeliveryId) { + + var success = successBuilder() + .withAppDeliveryID(appDeliveryId) + .build(); + + return deliveryRequestStatusTypeBuilder() + .withSuccess(success) + .build(); + + } + + private DeliveryRequestType setupMzsRequest(String appDeliveryId, boolean tnvzRequest) { + + var msgClient = clientTypeBuilder() + .withURL("http://zuse") + .build(); + + var config = configTypeBuilder() + .withPerformQueryPersonRequest(tnvzRequest) + .withMSGClient(msgClient) + .build(); + + return deliveryRequestTypeBuilder() + .withMetaData(setupMetaData(appDeliveryId)) + .withConfig(config) + .build(); + } + + private at.gv.zustellung.msg.xsd.DeliveryRequestType setupMsgRequest(String appDeliveryId) { + return at.gv.zustellung.msg.xsd.DeliveryRequestType.deliveryRequestTypeBuilder() + .withMetaData(setupMetaData(appDeliveryId)) + .build(); + } + + private MetaData setupMetaData(String appDeliveryId) { + return metaDataBuilder() + .withAppDeliveryID(appDeliveryId) + .build(); + } + +} diff --git a/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java b/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java index 4425297..66873d4 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.tnvz.TnvzHelper; +import at.gv.egiz.moazs.scheme.TnvzHelper; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; import at.gv.zustellung.app2mzs.xsd.persondata.IdentificationType; import at.gv.zustellung.tnvz.xsd.MimeTypeList; -- cgit v1.2.3