Skip to content

Commit

Permalink
Add test case which illustrates issue with XmlParser being unable t…
Browse files Browse the repository at this point in the history
…o parse a `Document` that it creates.
  • Loading branch information
kbalthaser committed Jun 11, 2018
1 parent 809516e commit 42e13d8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions hapi-test/src/test/java/ca/uhn/hl7v2/parser/XMLParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.junit.Test;
import org.w3c.dom.Document;

import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.Segment;
import ca.uhn.hl7v2.model.Type;
Expand All @@ -32,6 +34,7 @@
import ca.uhn.hl7v2.model.v25.message.ORU_R01;
import ca.uhn.hl7v2.model.v25.segment.OBX;
import ca.uhn.hl7v2.model.v251.message.ERP_R09;
import ca.uhn.hl7v2.util.Hl7InputStreamMessageIterator;
import ca.uhn.hl7v2.util.Terser;

/**
Expand Down Expand Up @@ -431,6 +434,36 @@ public void testMessageParseMethodAndEncodeMethodWithEscapes() throws HL7Excepti

}


/**
* <p>
* Test to ensure that we can parse an XML document that we ourselves have encoded. Starting with a known Pipe message,
* parse it, encode it to XML, and then attempt to parse that resultant XML back to a {@link Message}. The expectation is that we
* can parse our own XML.
* </p>
*/
@Test
public void test_ParseEncodedXml() throws Exception {

// Create a context
HapiContext context = new DefaultHapiContext();
context.getParserConfiguration().setValidating(false);

XMLParser xp = context.getXMLParser();

InputStream str = getClass().getClassLoader().getResourceAsStream("ca/uhn/hl7v2/parser/adt_a03.txt");
Hl7InputStreamMessageIterator iter = new Hl7InputStreamMessageIterator(str, context);
while (iter.hasNext()) {

Message msg = iter.next();
Document dom = xp.encodeDocument(msg);

// We would expect to be able to parse this document back to a Message, as we encoded it.
Message outmsg = xp.parseDocument(dom, msg.getVersion());
outmsg.printStructure();
}
}

private String loadFile(String name) throws IOException {
return loadFile(name, '\n');
}
Expand Down

0 comments on commit 42e13d8

Please sign in to comment.