diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/XhtmlDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/XhtmlDtTest.java index e0c3328cc31..60cfac54043 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/XhtmlDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/XhtmlDtTest.java @@ -1,9 +1,12 @@ package ca.uhn.fhir.model.primitive; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; import org.junit.Test; +import ca.uhn.fhir.parser.DataFormatException; + public class XhtmlDtTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(XhtmlDtTest.class); @@ -31,10 +34,9 @@ public class XhtmlDtTest { XhtmlDt x = new XhtmlDt(); x.setValueAsString(div); - XhtmlDt x2 = new XhtmlDt(); x2.setValue(x.getValue()); - + String actual = x2.getValueAsString(); ourLog.info("Expected {}", div.replace("\r", "").replace("\n", "\\n")); @@ -47,10 +49,10 @@ public class XhtmlDtTest { @Test public void testBasicCharacterEntity() { String input = "amp &"; - + XhtmlDt x = new XhtmlDt(); x.setValueAsString(input); - + assertEquals("
amp &
", x.getValueAsString()); } @@ -62,24 +64,37 @@ public class XhtmlDtTest { assertEquals("", x.getValueAsString()); } - - @Test public void testCharacterEntities() { String input = "Sect: § uuml: ü Ü"; - + XhtmlDt x = new XhtmlDt(); x.setValueAsString(input); //
Sect: § uuml: ü Ü
//
Sect: § uuml: ü Ü
- assertEquals("
"+input+"
", x.getValueAsString()); - + assertEquals("
" + input + "
", x.getValueAsString()); + XhtmlDt x2 = new XhtmlDt(); x2.setValue(x.getValue()); assertEquals("
Sect: § uuml: ü Ü
", x2.getValueAsString()); } - + + /** + * #175 + */ + @Test + public void testCharacterEntityUnknown() { + String input = "Trade &AAAAA;"; + + XhtmlDt x = new XhtmlDt(); + try { + x.setValueAsString(input); + fail(); + } catch (DataFormatException e) { + assertThat(e.toString(), containsString("AAAA")); + } + } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java index 47d1060ebcc..29439b60652 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java @@ -1719,6 +1719,24 @@ public class XmlParserTest { } + /** + * #175 + */ +// @Test + public void testParseTextWithUnknownEntity() { + String msg = "" + + "
Trade ™
"; + Patient pt = ourCtx.newXmlParser().parseResource(Patient.class, msg); + + ourLog.info(pt.getText().getDiv().getValueAsString()); + assertThat(pt.getText().getDiv().getValueAsString(), containsString("Trade ™")); + + String enc = ourCtx.newXmlParser().encodeResourceToString(pt); + ourLog.info(enc); + assertThat(enc, containsString("Trade ™")); + + } + @Test public void testParseWithIncorrectResourceType() { String input = "";