Unit tests for #175

This commit is contained in:
jamesagnew 2015-06-04 07:59:20 -04:00
parent e5b402cb14
commit 177afd9f4d
2 changed files with 44 additions and 11 deletions

View File

@ -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("<div>amp &amp;</div>", x.getValueAsString());
}
@ -62,24 +64,37 @@ public class XhtmlDtTest {
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", x.getValueAsString());
}
@Test
public void testCharacterEntities() {
String input = "Sect: &sect; uuml: &uuml; &Uuml;";
XhtmlDt x = new XhtmlDt();
x.setValueAsString(input);
// <div>Sect: § uuml: ü Ü</div>
// <div>Sect: &sect; uuml: &uuml; &Uuml;</div>
assertEquals("<div>"+input+"</div>", x.getValueAsString());
assertEquals("<div>" + input + "</div>", x.getValueAsString());
XhtmlDt x2 = new XhtmlDt();
x2.setValue(x.getValue());
assertEquals("<div>Sect: § uuml: ü Ü</div>", 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"));
}
}
}

View File

@ -1719,6 +1719,24 @@ public class XmlParserTest {
}
/**
* #175
*/
// @Test
public void testParseTextWithUnknownEntity() {
String msg = "<Patient xmlns=\"http://hl7.org/fhir\"><text><status value=\"generated\"/>"
+ "<div xmlns=\"http://www.w3.org/1999/xhtml\">Trade &trade;</div></text></Patient>";
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 = "<Patient><foo><bar/></foo><name><family value=\"AAA\"/></name></Patient>";