From 88e820a7522544ca321d709febf67e173775f2b9 Mon Sep 17 00:00:00 2001 From: Alejandro Revilla Date: Tue, 28 Mar 2017 22:50:41 -0300 Subject: [PATCH] Add ability to ignore response --- doc/src/asciidoc/module_client_simulator.adoc | 7 +++ .../java/org/jpos/simulator/TestRunner.java | 56 +++++++++++-------- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/doc/src/asciidoc/module_client_simulator.adoc b/doc/src/asciidoc/module_client_simulator.adoc index f665a5f6ff..a2c719a6cd 100644 --- a/doc/src/asciidoc/module_client_simulator.adoc +++ b/doc/src/asciidoc/module_client_simulator.adoc @@ -113,6 +113,13 @@ cfg/echo_r: --------------------------------- +[TIP] +===== +If the response template file (i.e. `echo_r` in the previous example) is +not present, client simulator blindly sends the message to the server, +ignoring the response. A _response ignored_ note is added to the test log. +===== + In the previous example, we send a 1800 message with some fixed data, and we expect to receive a 1810 message, with a 00 content in field 39. diff --git a/modules/client-simulator/src/main/java/org/jpos/simulator/TestRunner.java b/modules/client-simulator/src/main/java/org/jpos/simulator/TestRunner.java index 9b86f3169f..6e68a71710 100644 --- a/modules/client-simulator/src/main/java/org/jpos/simulator/TestRunner.java +++ b/modules/client-simulator/src/main/java/org/jpos/simulator/TestRunner.java @@ -78,7 +78,7 @@ public void run () { shutdownQ2(); } private void runSuite (List suite, MUX mux, Interpreter bsh) - throws ISOException, EvalError + throws ISOException, IOException, EvalError { LogEvent evt = getLog().createLogEvent ("results"); LogEvent evt_error = null; @@ -102,17 +102,25 @@ private void runSuite (List suite, MUX mux, Interpreter bsh) } tc.setExpandedRequest (applyRequestProps (m, bsh)); tc.start(); - tc.setResponse (mux.request (m, tc.getTimeout())); - tc.end (); - assertResponse(tc, bsh, evt_error); - evt.addMessage (i + ": " + tc.toString()); - if (evt_error.getPayLoad().size()!=0) { - evt_error.addMessage("filename", tc.getFilename()); - evt.addMessage(NL + evt_error.toString(" ")); + if (tc.getExpectedResponse() != null) { + tc.setResponse(mux.request(m, tc.getTimeout())); + tc.end(); + assertResponse(tc, bsh, evt_error); + evt.addMessage(i + ": " + tc.toString()); + if (evt_error.getPayLoad().size() != 0) { + evt_error.addMessage("filename", tc.getFilename()); + evt.addMessage(NL + evt_error.toString(" ")); + } + serverTime += tc.elapsed(); + if (!tc.ok() && !tc.isContinueOnErrors()) + break; + } else { + // response not expected - fire and forget + mux.send(m); + tc.end(); + tc.setResultCode(TestCase.OK); + evt.addMessage(i + ": " + tc.toString() + " (response ignored)"); } - serverTime += tc.elapsed(); - if (!tc.ok() && !tc.isContinueOnErrors()) - break; } if (!tc.ok()) { getLog().error (tc); @@ -139,10 +147,10 @@ private void runSuite (List suite, MUX mux, Interpreter bsh) Logger.log (evt); } - private List initSuite (Element suite) + private List initSuite (Element suite) throws IOException, ISOException { - List l = new ArrayList(); + List l = new ArrayList<>(); String prefix = suite.getChildTextTrim ("path"); Iterator iter = suite.getChildren ("test").iterator(); while (iter.hasNext ()) { @@ -178,17 +186,17 @@ private ISOMsg getMessage (String filename) throws IOException, ISOException { File f = new File (filename); - FileInputStream fis = new FileInputStream (f); - try { - byte[] b = new byte[fis.available()]; - fis.read (b); - ISOMsg m = new ISOMsg (); - m.setPackager (packager); - m.unpack (b); - return m; - } finally { - fis.close(); - } + ISOMsg m = null; + if (f.canRead()) { + try (FileInputStream fis = new FileInputStream (f)) { + byte[] b = new byte[fis.available()]; + fis.read (b); + m = new ISOMsg (); + m.setPackager (packager); + m.unpack (b); + } + } + return m; } private boolean processResponse (ISOMsg er, ISOMsg m, ISOMsg expected, Interpreter bsh, LogEvent evt)