Permalink
Browse files

Merge pull request #12 from edgedalmacio/master

Include ISOHeader when XMLPackager.unpack(ISOComponent, InputStream) is called.
  • Loading branch information...
2 parents e8111e2 + c144c53 commit 5021f4b594e33de1a363873507aae2d89d9f0e94 @ar ar committed Jul 30, 2012
View
4 jpos/src/main/java/org/jpos/iso/packager/XMLPackager.java
@@ -156,7 +156,9 @@ public synchronized void unpack (ISOComponent c, InputStream in)
throw new ISOException ("error parsing");
ISOMsg m = (ISOMsg) c;
- m.merge ((ISOMsg) stk.pop());
+ ISOMsg m1 = (ISOMsg) stk.pop();
+ m.merge (m1);
+ m.setHeader (m1.getHeader());
if (logger != null)
evt.addMessage (m);
View
10 jpos/src/test/java/org/jpos/iso/packager/XMLPackagerTest.java
@@ -181,17 +181,19 @@ public void testPack() throws IOException, ISOException, SAXException {
@Test
public void testUnpackBytes() throws IOException, ISOException {
- String input = "<isomsg><!-- org.jpos.iso.packager.XMLPackager --><field id=\"0\" value=\"0800\"/>"
+ String input = "<isomsg><!-- org.jpos.iso.packager.XMLPackager --><header>686561646572</header><field id=\"0\" value=\"0800\"/>"
+ "<field id=\"7\" value=\"7654321\"/><field id=\"11\" value=\"12345678\"/>"
+ "<field id=\"12\" value=\"20110224112759\"/><field id=\"24\" value=\"831\"/></isomsg>";
+ isoMsg.setHeader("header".getBytes());
isoMsg.setMTI("0800");
isoMsg.set(7, "7654321");
isoMsg.set(11, "12345678");
isoMsg.set(12, "20110224112759");
isoMsg.set(24, "");
ISOMsg result = xMLPackager.createISOMsg();
int consumedBytes = xMLPackager.unpack(result, input.getBytes());
- assertThat(consumedBytes, is(218));
+ assertThat(consumedBytes, is(247));
+ assertThat(result.getHeader(), is("header".getBytes()));
assertThat(result.getMTI(), is("0800"));
assertThat(result.getString(7), is("7654321"));
assertThat(result.getString(11), is("12345678"));
@@ -201,16 +203,18 @@ public void testUnpackBytes() throws IOException, ISOException {
@Test
public void testUnpackStream() throws IOException, ISOException {
- String input = "<isomsg><!-- org.jpos.iso.packager.XMLPackager --><field id=\"0\" value=\"0800\"/>"
+ String input = "<isomsg><!-- org.jpos.iso.packager.XMLPackager --><header>686561646572</header><field id=\"0\" value=\"0800\"/>"
+ "<field id=\"7\" value=\"7654321\"/><field id=\"11\" value=\"12345678\"/>"
+ "<field id=\"12\" value=\"20110224112759\"/><field id=\"24\" value=\"\"/></isomsg>";
+ isoMsg.setHeader("header".getBytes());
isoMsg.setMTI("0800");
isoMsg.set(7, "7654321");
isoMsg.set(11, "12345678");
isoMsg.set(12, "20110224112759");
isoMsg.set(24, "831");
ISOMsg result = xMLPackager.createISOMsg();
xMLPackager.unpack(result, new ByteArrayInputStream(input.getBytes()));
+ assertThat(result.getHeader(), is("header".getBytes()));
assertThat(result.getMTI(), is("0800"));
assertThat(result.getString(7), is("7654321"));
assertThat(result.getString(11), is("12345678"));

0 comments on commit 5021f4b

Please sign in to comment.