001package ca.uhn.hl7v2.hoh.encoder;
002
003import static org.junit.Assert.*;
004
005import org.junit.Test;
006
007import ca.uhn.hl7v2.AcknowledgmentCode;
008import ca.uhn.hl7v2.hoh.encoder.ResponseCode;
009import ca.uhn.hl7v2.model.Message;
010import ca.uhn.hl7v2.model.v25.message.ADT_A05;
011import ca.uhn.hl7v2.parser.DefaultXMLParser;
012
013public class ResponseCodeTest {
014
015        @Test
016        public void testDetectEr7() throws Exception {
017                
018                String message = "MSH|^~\\&|||||200803051508||ADT^A31|2|P|2.5\r"
019                                + "EVN||200803051509\r"
020                                + "PID|||ZZZZZZ83M64Z148R^^^SSN^SSN^^20070103\r";
021                ADT_A05 a05 = new ADT_A05();
022                a05.parse(message);
023                
024                Message ack = a05.generateACK(AcknowledgmentCode.AA, null);
025                String ackString = ack.encode();
026                assertEquals(ResponseCode.HTTP_200_OK, ResponseCode.detect(ackString));
027                
028                ack = a05.generateACK(AcknowledgmentCode.AE, null);
029                ackString = ack.encode();
030                assertEquals(ResponseCode.HTTP_200_OK, ResponseCode.detect(ackString));
031                
032                ack = a05.generateACK(AcknowledgmentCode.AR, null);
033                ackString = ack.encode();
034                assertEquals(ResponseCode.HTTP_200_OK, ResponseCode.detect(ackString));
035
036        }
037
038        @Test
039        public void testDetectXml() throws Exception {
040                
041                String message = "MSH|^~\\&|||||200803051508||ADT^A31|2|P|2.5\r"
042                                + "EVN||200803051509\r"
043                                + "PID|||ZZZZZZ83M64Z148R^^^SSN^SSN^^20070103\r";
044                ADT_A05 a05 = new ADT_A05();
045                a05.parse(message);
046                a05.setParser(new DefaultXMLParser());
047
048                String encoded = a05.encode();
049                assertTrue(encoded, encoded.contains("<MSH"));
050
051                Message ack = a05.generateACK(AcknowledgmentCode.AA, null);
052                String ackString = ack.encode();
053                assertTrue(ackString, ackString.contains("<MSH"));
054                assertEquals(ResponseCode.HTTP_200_OK, ResponseCode.detect(ackString));
055                
056                ack = a05.generateACK(AcknowledgmentCode.AE, null);
057                ackString = ack.encode();
058                assertEquals(ResponseCode.HTTP_200_OK, ResponseCode.detect(ackString));
059                
060                ack = a05.generateACK(AcknowledgmentCode.AR, null);
061                ackString = ack.encode();
062                assertEquals(ResponseCode.HTTP_200_OK, ResponseCode.detect(ackString));
063
064        }
065
066}