Add test for #449
This commit is contained in:
parent
d159e44e52
commit
89e3021588
|
@ -0,0 +1,44 @@
|
|||
package ca.uhn.fhir.parser;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.Child;
|
||||
import ca.uhn.fhir.model.api.annotation.Extension;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Device;
|
||||
|
||||
@ResourceDef(name="Device", id="ExtendedDevice")
|
||||
public class ExtendedDevice extends Device {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Child(name="someOrg")
|
||||
@Extension(url="http://extensionsBaseUrl/Device#someOrg", definedLocally=true, isModifier = false)
|
||||
private ResourceReferenceDt someOrg;
|
||||
|
||||
@Child(name="someOtherOrg")
|
||||
@Extension(url="http://extensionsBaseUrl/Device#someOtherOrg", definedLocally=true, isModifier = false)
|
||||
private ResourceReferenceDt someOtherOrg;
|
||||
|
||||
public ResourceReferenceDt getSomeOrg() {
|
||||
if (someOrg == null) {
|
||||
someOrg = new ResourceReferenceDt();
|
||||
}
|
||||
return someOrg;
|
||||
}
|
||||
|
||||
public void setSomeOrg(ResourceReferenceDt someOrg) {
|
||||
this.someOrg = someOrg;
|
||||
}
|
||||
|
||||
public ResourceReferenceDt getSomeOtherOrg() {
|
||||
if (someOtherOrg == null) {
|
||||
someOtherOrg = new ResourceReferenceDt();
|
||||
}
|
||||
return someOtherOrg;
|
||||
}
|
||||
|
||||
public void setSomeOtherOrg(ResourceReferenceDt someOtherOrg) {
|
||||
this.someOtherOrg = someOtherOrg;
|
||||
}
|
||||
|
||||
}
|
|
@ -125,7 +125,7 @@ public class JsonParserDstu2Test {
|
|||
obs = p.parseResource(ReportObservation.class, encoded);
|
||||
assertEquals(true, obs.getReadOnly().getValue().booleanValue());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #390
|
||||
*/
|
||||
|
@ -143,8 +143,7 @@ public class JsonParserDstu2Test {
|
|||
assertEquals("123", b.getId().getIdPart());
|
||||
assertEquals(0, b.getEntry().size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseExtensions() throws Exception {
|
||||
|
||||
|
@ -230,6 +229,7 @@ public class JsonParserDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseLanguage() {
|
||||
Patient p = new Patient();
|
||||
|
@ -359,7 +359,7 @@ public class JsonParserDstu2Test {
|
|||
assertEquals(null, name.getFamily().get(2).getAllUndeclaredExtensions().get(0).getElementSpecificId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseSecurityLabels() {
|
||||
Patient p = new Patient();
|
||||
|
@ -424,7 +424,6 @@ public class JsonParserDstu2Test {
|
|||
assertEquals("VERSION2", label.getVersion());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBundleNewBundleNoText() {
|
||||
|
||||
|
@ -446,7 +445,7 @@ public class JsonParserDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBundleOldBundleNoText() {
|
||||
|
||||
|
@ -466,7 +465,7 @@ public class JsonParserDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fixing #89
|
||||
*/
|
||||
|
@ -485,6 +484,7 @@ public class JsonParserDstu2Test {
|
|||
"}"));
|
||||
//@formatter:on
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeDoesntIncludeUuidId() {
|
||||
|
@ -501,7 +501,7 @@ public class JsonParserDstu2Test {
|
|||
String output = ourCtx.newJsonParser().encodeResourceToString(new Binary());
|
||||
assertEquals("{\"resourceType\":\"Binary\"}", output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* #158
|
||||
*/
|
||||
|
@ -602,7 +602,6 @@ public class JsonParserDstu2Test {
|
|||
assertEquals("ext_url_value", ((StringDt)obs.getUndeclaredExtensions().get(0).getValue()).getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeExtensionUndeclaredNonModifierWithChildExtension() {
|
||||
Observation obs = new Observation();
|
||||
|
@ -647,7 +646,7 @@ public class JsonParserDstu2Test {
|
|||
assertEquals("sub_ext_value", ((StringDt)obs.getUndeclaredExtensions().get(0).getExtension().get(0).getValue()).getValue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* See #428
|
||||
*/
|
||||
|
@ -670,6 +669,7 @@ public class JsonParserDstu2Test {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeForceResourceId() {
|
||||
Patient p = new Patient();
|
||||
|
@ -1703,6 +1703,46 @@ public class JsonParserDstu2Test {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See #449
|
||||
*/
|
||||
@Test
|
||||
public void testReferenceEncodingOnCustomType() {
|
||||
Organization org = new Organization();
|
||||
org.setId("000111");
|
||||
org.setName("Owner institution");
|
||||
|
||||
ExtendedDevice dev = new ExtendedDevice();
|
||||
dev.setId("000222");
|
||||
CodingDt devType = new CodingDt();
|
||||
|
||||
devType.setSystem("http://devTypeSystem");
|
||||
devType.setCode("0");
|
||||
dev.getType().addCoding(devType);
|
||||
|
||||
ExtensionDt someExt = new ExtensionDt();
|
||||
someExt.setUrl("http://extensionsBaseUrl/Device#someExt");
|
||||
ResourceReferenceDt orgRef = new ResourceReferenceDt();
|
||||
orgRef.setResource(org);
|
||||
someExt.setValue(orgRef); //this works
|
||||
dev.addUndeclaredExtension(someExt);
|
||||
|
||||
dev.getSomeOrg().setResource(org); //this doesn't work
|
||||
dev.setSomeOtherOrg(new ResourceReferenceDt(org)); //this almost works, the Organization/ prefix is missing
|
||||
|
||||
dev.getOwner().setResource(org); //this works
|
||||
|
||||
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
||||
bundle.setId(new IdDt("000333"));
|
||||
bundle.addEntry().setResource(dev);
|
||||
bundle.addEntry().setResource(org);
|
||||
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
|
||||
ourLog.info(encoded);
|
||||
|
||||
assertThat(encoded, containsString("reference\": \"Organization/000111\""));
|
||||
}
|
||||
|
||||
/**
|
||||
* See #144 and #146
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue