Skip to content

Commit

Permalink
Merge pull request jpos#285 from alwyn/master
Browse files Browse the repository at this point in the history
Fixed TestXmlPackager failing on Windows due to line-separator mismat…
  • Loading branch information
ar authored Mar 6, 2020
2 parents b9a75b4 + 3a4b715 commit c998ebd
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions jpos/src/test/java/org/jpos/iso/packagers/PackagerTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void testF64ascii() throws Exception {
}
@Test
public void testXMLPackager () throws Exception {
doTest (xmlPackager, "XMLPackager", "XMLPackager");
doTest (xmlPackager, "XMLPackager", "XMLPackager", true);
}

@Test
Expand Down Expand Up @@ -211,6 +211,11 @@ private ISOMsg updatePackAndUnpack (ISOMsg m, ISOPackager p) throws Exception {
}
private void doTest (ISOPackager packager, String msg, String img)
throws Exception
{
doTest(packager, msg, img, false);
}
private void doTest (ISOPackager packager, String msg, String img, boolean removeCRLF)
throws Exception
{
// Logger logger = new Logger();
// logger.addListener (new SimpleLogListener (System.out));
Expand All @@ -227,19 +232,53 @@ private void doTest (ISOPackager packager, String msg, String img)
writeImage (img, p);

byte[] b = getImage (img);
TestUtils.assertEquals(b, p);
if (removeCRLF) {
TestUtils.assertEquals(removeAllCRLF(b), removeAllCRLF(p));
} else {
TestUtils.assertEquals(b, p);
}

ISOMsg m1 = new ISOMsg ();
// packager.setLogger (logger, msg + "-m1");
m1.setPackager (packager);
m1.unpack (b);
TestUtils.assertEquals(b, m1.pack());
if (removeCRLF) {
TestUtils.assertEquals(removeAllCRLF(b), removeAllCRLF(m1.pack()));
} else {
TestUtils.assertEquals(b, m1.pack());
}

ISOMsg m2 = new ISOMsg ();
m2.setPackager (packager);
// packager.setLogger (logger, msg + "-m2");
m2.unpack (new ByteArrayInputStream (out.toByteArray()));
TestUtils.assertEquals(b, m2.pack());
if (removeCRLF) {
TestUtils.assertEquals(removeAllCRLF(b), removeAllCRLF(m2.pack()));
} else {
TestUtils.assertEquals(b, m2.pack());
}
}

/**
* Used specifically when testing XmlPackager. When messages are generated
* on Windows they include a carriage return (CR) and is then compared against
* a version that was generated on Unix.
*
* This function is used to remove CR and LF before comparison.
*
* @param in Byte array to modify.
* @return Modified byte array.
*/
private byte[] removeAllCRLF(byte[] in) {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(in);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
while (byteArrayInputStream.available() > 0) {
int b = byteArrayInputStream.read();
if (b != 10 && b != 13) {
byteArrayOutputStream.write(b);
}
}
return byteArrayOutputStream.toByteArray();
}

/*
Expand Down

0 comments on commit c998ebd

Please sign in to comment.