From 59a13bea5783aa666bcbcec793df19f129965ff3 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Tue, 21 May 2019 13:47:34 +0200 Subject: WIP: SSL Client Auth - Refactor MsgClient: Not a Singleton anymore. Use MsgClientFactory to make a client. Make request and config private fields. - Add configuration parameters to application.yaml. - Init SSL client auth testcase, but dont include in testsuite because it aint working yet. --- src/test/java/at/gv/egiz/moazs/MsgClientTest.java | 31 +++++++++++++++++----- .../egiz/moazs/SameThreadDeliveryPipelineTest.java | 9 +++++-- 2 files changed, 31 insertions(+), 9 deletions(-) (limited to 'src/test/java/at/gv') diff --git a/src/test/java/at/gv/egiz/moazs/MsgClientTest.java b/src/test/java/at/gv/egiz/moazs/MsgClientTest.java index 6dc94e0..5b6419f 100644 --- a/src/test/java/at/gv/egiz/moazs/MsgClientTest.java +++ b/src/test/java/at/gv/egiz/moazs/MsgClientTest.java @@ -1,6 +1,7 @@ package at.gv.egiz.moazs; import at.gv.egiz.moazs.msg.MsgClient; +import at.gv.egiz.moazs.msg.MsgClientFactory; import at.gv.egiz.moazs.scheme.Marshaller; import at.gv.zustellung.app2mzs.xsd.ConfigType; import at.gv.zustellung.msg.xsd.DeliveryRequestType; @@ -28,25 +29,41 @@ public class MsgClientTest { private final static Logger logger = LoggerFactory.getLogger(MsgClient.class); - private final String serviceUri = "http://localhost:8081/services/DeliveryRequest"; + private String httpServiceUri = "http://localhost:8081/services/DeliveryRequest"; + private String sslServiceUri = "https://localhost/zusemsg/services/DeliveryRequest"; + private final String basePath = "src/test/resources/at/gv/egiz/moazs/MsgClientTest/"; + private MsgClientFactory factory = new MsgClientFactory(); + @Autowired private Marshaller msgMarshaller; private static final ObjectFactory OF = new ObjectFactory(); - // this test requires that a zusemsg service runs under serviceUri! + // this test requires that a zusemsg service runs under httpServiceUri! @Test public void sendValidMessage() throws IOException { var request = loadFromFile("validDeliveryRequest.xml"); - var config = generateConfig(); - var client = new MsgClient(); + var config = generateConfig(httpServiceUri); + var client = factory.create(request, config); + + var status = client.send(); + + logger.info("status: " + msgMarshaller.marshallXml(OF.createDeliveryRequestStatus(status))); + } + + //@Test + public void sendValidMessageToSSL() throws IOException { + + var request = loadFromFile("validDeliveryRequest.xml"); + var config = generateConfig(sslServiceUri); + var client = factory.create(request, config); - var status = client.send(request, config); + var status = client.send(); logger.info("status: " + msgMarshaller.marshallXml(OF.createDeliveryRequestStatus(status))); } @@ -58,10 +75,10 @@ public class MsgClientTest { } } - private ConfigType generateConfig() { + private ConfigType generateConfig(String zuseUrl) { var server = serverTypeBuilder() - .withZUSEUrlID(serviceUri) + .withZUSEUrlID(zuseUrl) .build(); return configTypeBuilder() diff --git a/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java b/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java index 9ee3ceb..5e4b9b0 100644 --- a/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java +++ b/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java @@ -1,6 +1,7 @@ package at.gv.egiz.moazs; import at.gv.egiz.moazs.msg.MsgClient; +import at.gv.egiz.moazs.msg.MsgClientFactory; import at.gv.egiz.moazs.pipeline.DeliveryPipeline; import at.gv.egiz.moazs.pipeline.SameThreadDeliveryPipeline; import at.gv.egiz.moazs.repository.DeliveryRepository; @@ -45,6 +46,9 @@ public class SameThreadDeliveryPipelineTest { @Mock private TnvzClient tnvzClient; + @Mock + private MsgClientFactory msgClientFactory; + @Mock private MsgClient msgClient; @@ -56,7 +60,7 @@ public class SameThreadDeliveryPipelineTest { @Before public void setup() { - pipeline = new SameThreadDeliveryPipeline(repository, tnvzClient, converter, msgClient); + pipeline = new SameThreadDeliveryPipeline(repository, tnvzClient, converter, msgClientFactory); } @Test @@ -129,7 +133,8 @@ public class SameThreadDeliveryPipelineTest { when(tnvzClient.queryPerson(any(), any())).thenReturn(setupTnvzSuccess(acceptedTypes)); when(converter.convert(eq(mzsRequest) )).thenReturn(msgRequest); when(converter.convert(eq(mzsRequest), any())).thenReturn(msgRequest); - when(msgClient.send(msgRequest, mzsRequest.getConfig())).thenReturn(status); + when(msgClientFactory.create(msgRequest, mzsRequest.getConfig())).thenReturn(msgClient); + when(msgClient.send()).thenReturn(status); return status; -- cgit v1.2.3