Merge branch 'master' of github.com:jamesagnew/hapi-fhir

This commit is contained in:
James Agnew 2015-06-04 12:20:17 -04:00
commit f9a9232926
7 changed files with 95 additions and 11 deletions

View File

@ -1054,6 +1054,8 @@ class ParserState<T> {
push(new PreResourceStateHapi(myEntry, myResourceType).setRequireResourceType(false));
} else if ("deleted".equals(theLocalPart)) {
push(new BundleEntryDeletedState(getPreResourceState(), myEntry));
} else if ("link".equals(theLocalPart)) {
push(new BundleLinkState(myEntry));
} else {
throw new DataFormatException("Unexpected element in entry: " + theLocalPart);
}

View File

@ -400,6 +400,8 @@ public class XmlParser extends BaseParser implements IParser {
writeOptionalTagWithValue(theEventWriter, "base", determineResourceBaseUrl(bundleBaseUrl, nextEntry));
writeBundleResourceLink(theEventWriter, "alternate", nextEntry.getLinkAlternate());
IResource resource = nextEntry.getResource();
if (resource != null && !resource.isEmpty() && !deleted) {
theEventWriter.writeStartElement("resource");

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 &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

@ -1744,6 +1744,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>";

View File

@ -1053,6 +1053,7 @@ public class XmlParserDstu2Test {
assertEquals(2, parsed.getEntries().size());
assertEquals("http://foo?search", parsed.getEntries().get(0).getLinkSearch().getValue());
assertEquals("http://example.com/base/MedicationPrescription/3123/_history/1", parsed.getEntries().get(0).getLinkAlternate().getValue());
MedicationPrescription p = (MedicationPrescription) parsed.getEntries().get(0).getResource();
assertEquals("Patient/347", p.getPatient().getReference().getValue());
assertEquals("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
@ -1086,6 +1087,8 @@ public class XmlParserDstu2Test {
assertEquals("https://example.com/base/MedicationPrescription?patient=347&_include=MedicationPrescription.medication", parsed.getLink().get(1).getUrlElement().getValueAsString());
assertEquals(2, parsed.getEntry().size());
assertEquals("alternate", parsed.getEntry().get(0).getLink().get(0).getRelation());
assertEquals("http://example.com/base/MedicationPrescription/3123/_history/1", parsed.getEntry().get(0).getLink().get(0).getUrl());
assertEquals("http://foo?search", parsed.getEntry().get(0).getTransaction().getUrlElement().getValueAsString());
MedicationPrescription p = (MedicationPrescription) parsed.getEntry().get(0).getResource();
@ -1215,6 +1218,41 @@ public class XmlParserDstu2Test {
}
@Test
public void testParseBundleOldStyleWithUnknownLinks() throws Exception {
//@formatter:off
String bundle = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
" <base value=\"http://foo/fhirBase1\"/>\n" +
" <total value=\"1\"/>\n" +
" <link>\n" +
" <relation value=\"foo\"/>\n" +
" <url value=\"http://localhost:52788/Binary?_pretty=true\"/>\n" +
" </link>\n" +
" <entry>\n" +
" <link>\n" +
" <relation value=\"bar\"/>\n" +
" <url value=\"http://localhost:52788/Binary?_pretty=true\"/>\n" +
" </link>\n" +
" <resource>\n" +
" <Patient xmlns=\"http://hl7.org/fhir\">\n" +
" <id value=\"1\"/>\n" +
" <meta>\n" +
" <versionId value=\"2\"/>\n" +
" <lastUpdated value=\"2001-02-22T11:22:33-05:00\"/>\n" +
" </meta>\n" +
" <birthDate value=\"2012-01-02\"/>\n" +
" </Patient>\n" +
" </resource>\n" +
" </entry>\n" +
"</Bundle>";
//@formatter:on
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
assertEquals(1, b.getEntries().size());
}
/**
* See #103
*/

View File

@ -16,6 +16,10 @@
<url value="https://example.com/base/MedicationPrescription?patient=347&amp;_include=MedicationPrescription.medication"/>
</link>
<entry>
<link>
<relation value="alternate"/>
<url value="http://example.com/base/MedicationPrescription/3123/_history/1"/>
</link>
<resource>
<MedicationPrescription>
<id value="3123"/>

View File

@ -55,6 +55,11 @@
<action type="add">
Web tester UI now supports _revinclude
</action>
<action type="fix" issue="178">
Support link elements in Bundle.entry when parsing in DSTU2 mode
using the old (non-resource) Bundle class. Thanks to GitHub user
@joedai for reporting!
</action>
<action type="add">
LoggingInterceptor for server now supports logging DSTU2 extended operations by name
</action>