/* * Created on Dec 12, 2006 */ package ca.uhn.hl7v2.app; import java.io.IOException; import java.net.Socket; import junit.framework.TestCase; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.llp.LLPException; import ca.uhn.hl7v2.llp.MinLLPReader; import ca.uhn.hl7v2.llp.MinLLPWriter; import ca.uhn.hl7v2.llp.MinLowerLayerProtocol; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.parser.DefaultXMLParser; import ca.uhn.hl7v2.parser.GenericParser; import ca.uhn.hl7v2.parser.PipeParser; import ca.uhn.log.HapiLog; import ca.uhn.log.HapiLogFactory; /** * Test case for responder * * @version $Revision: 1.1 $ updated on $Date: 2007/02/19 02:24:40 $ by $Author: jamesagnew $ */ public class ResponderTest extends TestCase { private static int ourPort = 22222; private SimpleServer server; private Socket socket; private MinLLPWriter writer; private MinLLPReader reader; public void testResponseEncoding() throws HL7Exception, LLPException, IOException { String outMsg = "MSH|^~\\&|||||20061212094425.814-0500||ACK|2059434|P|2.2\r\n" + "MAS|AA|20167098"; writer.writeMessage(outMsg); String inMsg = reader.getMessage(); assertTrue(inMsg.indexOf("MSH|") == 0); } public void testResponseEncodingXml() throws LLPException, IOException { String outMsg = "\r\n" + "\r\n" + " \r\n" + " |\r\n" + " ^~\\&\r\n" + " \r\n" + " 20061212094425.814-0500\r\n" + " \r\n" + " \r\n" + " ACK\r\n" + " \r\n" + " 2059434\r\n" + " P\r\n" + " 2.2\r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " AA\r\n" + " 20167098\r\n" + " \r\n" + ""; writer.writeMessage(outMsg); String inMsg = reader.getMessage(); assertTrue(inMsg.indexOf("James Agnew * @version $Revision: 1.1 $ updated on $Date: 2007/02/19 02:24:40 $ by $Author: jamesagnew $ */ public class DummyApplication implements Application { /** * {@inheritDoc} */ public boolean canProcess(Message theIn) { return true; } /** * {@inheritDoc} */ public Message processMessage(Message theIn) throws ApplicationException, HL7Exception { throw new HL7Exception("Test error"); } } protected void setUp() throws Exception { server = new SimpleServer(ourPort, new MinLowerLayerProtocol(), new GenericParser()); server.registerApplication("*", "*", new DummyApplication()); server.start(); socket = new Socket("localhost", ourPort); writer = new MinLLPWriter(socket.getOutputStream()); reader = new MinLLPReader(socket.getInputStream()); ourPort++; } protected void tearDown() throws Exception { server.stop(); socket.close(); } }