package ca.uhn.hl7v2.util;
import java.io.*;
import junit.framework.*;
/**
* JUnit test cases for EncodedMessageComparator
* @author bryan
*/
public class EncodedMessageComparatorTest extends TestCase {
public EncodedMessageComparatorTest(java.lang.String testName) {
super(testName);
}
public static void main(java.lang.String[] args) {
junit.textui.TestRunner.run(suite());
}
public static Test suite() {
TestSuite suite = new TestSuite(EncodedMessageComparatorTest.class);
return suite;
}
// Add test methods here, they have to start with 'test' name.
// for example:
// public void testHello() {}
public void testStandardizeER7() {
String nonStandard = "MSH|^~\\&|Fake Sending App~&&^^^~~~|Fake Sending Facility||Fake Receiving Facility|200108151718||ACK^A01&&^ACK~|20|P|2.4|||||||||&&&&|&|~|~~~&&\n\n\nMSA|AA\r\n";
String standard = "MSH|^~\\&|Fake Sending App|Fake Sending Facility||Fake Receiving Facility|200108151718||ACK^A01^ACK|20|P|2.4\rMSA|AA\r";
String result = EncodedMessageComparator.standardizeER7(nonStandard);
assertEquals(standard, result);
}
public void testStandardizeXML() throws Exception {
String nonStandard = "\n\r\n \n |\n\n\n ^~\\&\n \n Fake Sending App\n \n \n Fake Sending Facility\n \n \n Fake Receiving Facility\n \n \n 200108151718-0500\n \n \n ACK\n A01\n ACK\n \n 20\n \n P\n \n \n 2.4\n \n \n \n AA\n \n\n";
String standard = "\n\n \n |\n ^~\\&\n \n Fake Sending App\n \n \n Fake Sending Facility\n \n \n Fake Receiving Facility\n \n \n 200108151718-0500\n \n \n ACK\n A01\n ACK\n \n 20\n \n P\n \n \n 2.4\n \n \n \n AA\n \n\n";
String result = EncodedMessageComparator.standardizeXML(nonStandard);
BufferedWriter out = new BufferedWriter(new FileWriter("./standard_xml.txt"));
out.write(standard);
out.flush();
out.close();
out = new BufferedWriter(new FileWriter("./result_xml.txt"));
out.write(result);
out.flush();
out.close();
assertEquals(standard, result);
}
public void testEquivalent() throws Exception {
//should all be equivalent
String ER7A = "MSH|^~\\&|Fake Sending App~&&^^^~~~|Fake Sending Facility||Fake Receiving Facility|200108151718||ACK^A01&&^ACK~|20|P|2.4|||||||||&&&&|&|~|~~~&&\n\n\nMSA|AA\r\n";
String ER7B = "MSH|^~\\&|Fake Sending App|Fake Sending Facility||Fake Receiving Facility|200108151718||ACK^A01^ACK|20|P|2.4\nMSA|AA\n";
String XMLA = "\n\r\n \n |\n\n\n ^~\\&\n \n Fake Sending App\n \n \n Fake Sending Facility\n \n \n Fake Receiving Facility\n \n \n 200108151718\n \n \n ACK\n A01\n ACK\n \n 20\n \n P\n \n \n 2.4\n \n \n \n AA\n \n\n";
String XMLB = "\n\n \n |\n ^~\\&\n \n Fake Sending App\n \n \n Fake Sending Facility\n \n \n Fake Receiving Facility\n \n \n 200108151718\n \n \n ACK\n A01\n ACK\n \n 20\n \n P\n \n \n 2.4\n \n \n \n AA\n \n\n";
String XMLC = "\r\n\r\n\r\n|\r\n^~\\&\r\n\r\nFake Sending App\r\n\r\n\r\nFake Sending Facility\r\n\r\n\r\nFake Receiving Facility\r\n\r\n\r\n200108151718\r\n\r\n\r\nACK\r\nA01\r\nACK\r\n\r\n20\r\n\r\nP\r\n\r\n\r\n2.4\r\n\r\n\r\n\r\nAA\r\n\r\n";
assertTrue(EncodedMessageComparator.equivalent(ER7A, ER7B));
assertTrue(EncodedMessageComparator.equivalent(XMLA, XMLB));
assertTrue(EncodedMessageComparator.equivalent(ER7A, XMLC));
}
}