From 8aba1b4f18f5fbfebdf239b4b4945b628e439905 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Tue, 9 Jul 2019 14:11:47 +0200 Subject: Refactor Needles Interfaces and Rename "process" to "backend" Reason: - Interfaces with a single method can be replaced with interfaces from java.util.function. - Less interfaces = less code = less maintenance! - Spring can inject beans by name so we name dependencies correctly to prevent ambiguity. Others: - Rename process to backend since backend gives a better description of its components. --- .../moazs/SingleThreadedDeliveryPipelineTest.java | 204 --------------------- 1 file changed, 204 deletions(-) delete mode 100644 src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java (limited to 'src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java') diff --git a/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java b/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java deleted file mode 100644 index e245eb1..0000000 --- a/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java +++ /dev/null @@ -1,204 +0,0 @@ -package at.gv.egiz.moazs; - -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.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.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.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; -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(100); - - @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 response = repository.retrieveResponse(getResponseID(appDeliveryID)).get(); - var actualStatus = (DeliveryRequestStatusType) response.getResponse(); - - assertThat(actualStatus).isEqualTo(expectedStatus); - } - - @Test - public void rejectDeliveryWhenReceiverIsNotAddressable() { - var appDeliveryID = "not-addressable"; - setupMocks(appDeliveryID, true); - when(tnvzHelper.performQueryPersonRequest(any(), any(), any())) - .thenThrow(buildMzsException("400", appDeliveryID)); - - pipeline.processRequest(appDeliveryID); - - var responseID = getResponseID(appDeliveryID); - var response = repository.retrieveResponse(responseID).get(); - var status = (DeliveryRequestStatusType) response.getResponse(); - var actualCode = status.getError().getErrorInfo().getCode(); - - 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); - - pipeline.processRequest(appDeliveryID); - var response = repository.retrieveResponse(getResponseID(appDeliveryID)).get(); - var actualStatus = (DeliveryRequestStatusType) response.getResponse(); - - 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 response = repository.retrieveResponse(getResponseID(appDeliveryID)).get(); - var status = (DeliveryRequestStatusType) response.getResponse(); - var actualCode = status.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.store(mzsRequest); - repository.store(getResponseID(appDeliveryId), signedStatus); - - 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, String appDeliveryID) { - return moaZSExceptionBuilder("") - .withErrorCode(code) - .withAppDeliveryID(appDeliveryID) - .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(); - } - -} -- cgit v1.2.3