FIx tests
This commit is contained in:
parent
1af65ff5a8
commit
5a818a38e8
|
@ -667,7 +667,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
} else if (nextChild instanceof RuntimeChildNarrativeDefinition && theContainedResource) {
|
||||
// suppress narratives from contained resources
|
||||
} else {
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, childName, theContainedResource, nextChildElem, force);
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, childName, theContainedResource, nextChildElem, false);
|
||||
}
|
||||
currentChildName = childName;
|
||||
} else {
|
||||
|
|
|
@ -62,6 +62,7 @@ import ca.uhn.fhir.model.dstu2.valueset.ConditionVerificationStatusEnum;
|
|||
import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
|
||||
import ca.uhn.fhir.model.dstu2.valueset.MaritalStatusCodesEnum;
|
||||
import ca.uhn.fhir.model.dstu2.valueset.ObservationStatusEnum;
|
||||
import ca.uhn.fhir.model.dstu2.valueset.UnknownContentCodeEnum;
|
||||
import ca.uhn.fhir.model.primitive.DateDt;
|
||||
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
|
@ -78,69 +79,6 @@ public class JsonParserDstu2Test {
|
|||
private static final FhirContext ourCtx = FhirContext.forDstu2();
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserDstu2Test.class);
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* See #336
|
||||
*/
|
||||
@Test
|
||||
public void testEncodeAndParseNullPrimitiveWithExtensions() {
|
||||
|
||||
Patient p = new Patient();
|
||||
p.setId("patid");
|
||||
HumanNameDt name = p.addName();
|
||||
name.addFamily().setValue(null).addUndeclaredExtension(new ExtensionDt(false, "http://foo", new StringDt("FOOEXT0")));
|
||||
name.getFamily().get(0).setElementSpecificId("f0");
|
||||
name.addFamily().setValue("V1").addUndeclaredExtension((ExtensionDt) new ExtensionDt(false, "http://foo", new StringDt("FOOEXT1")));
|
||||
name.getFamily().get(1).setElementSpecificId("f1");
|
||||
name.getFamily().get(1).getUndeclaredExtensions().get(0).setElementSpecificId("ext1id");
|
||||
name.addFamily(); // this one shouldn't get encoded
|
||||
name.addFamily().setValue(null).addUndeclaredExtension(new ExtensionDt(false, "http://foo", new StringDt("FOOEXT3")));
|
||||
name.setElementSpecificId("nameid");
|
||||
|
||||
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
|
||||
ourLog.info(output);
|
||||
|
||||
output = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(p);
|
||||
String expected = "{\"resourceType\":\"Patient\",\"id\":\"patid\",\"name\":[{\"id\":\"nameid\",\"family\":[null,\"V1\",null],\"_family\":[{\"id\":\"f0\",\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT0\"}]},{\"id\":\"f1\",\"extension\":[{\"id\":\"ext1id\",\"url\":\"http://foo\",\"valueString\":\"FOOEXT1\"}]},{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT3\"}]}]}]}";
|
||||
assertEquals(expected, output);
|
||||
|
||||
p = ourCtx.newJsonParser().parseResource(Patient.class, output);
|
||||
assertEquals("patid", p.getIdElement().getIdPart());
|
||||
|
||||
name = p.getName().get(0);
|
||||
assertEquals("nameid", name.getElementSpecificId());
|
||||
assertEquals(3, name.getFamily().size());
|
||||
|
||||
assertEquals(null, name.getFamily().get(0).getValue());
|
||||
assertEquals("V1", name.getFamily().get(1).getValue());
|
||||
assertEquals(null, name.getFamily().get(2).getValue());
|
||||
|
||||
assertEquals("f0", name.getFamily().get(0).getElementSpecificId());
|
||||
assertEquals("f1", name.getFamily().get(1).getElementSpecificId());
|
||||
assertEquals(null, name.getFamily().get(2).getElementSpecificId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(0).getAllUndeclaredExtensions().size());
|
||||
assertEquals("http://foo", name.getFamily().get(0).getAllUndeclaredExtensions().get(0).getUrl());
|
||||
assertEquals("FOOEXT0", ((StringDt)name.getFamily().get(0).getAllUndeclaredExtensions().get(0).getValue()).getValue());
|
||||
assertEquals(null, name.getFamily().get(0).getAllUndeclaredExtensions().get(0).getElementSpecificId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(1).getAllUndeclaredExtensions().size());
|
||||
assertEquals("http://foo", name.getFamily().get(1).getAllUndeclaredExtensions().get(0).getUrl());
|
||||
assertEquals("FOOEXT1", ((StringDt)name.getFamily().get(1).getAllUndeclaredExtensions().get(0).getValue()).getValue());
|
||||
assertEquals("ext1id", name.getFamily().get(1).getAllUndeclaredExtensions().get(0).getElementSpecificId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(2).getAllUndeclaredExtensions().size());
|
||||
assertEquals("http://foo", name.getFamily().get(2).getAllUndeclaredExtensions().get(0).getUrl());
|
||||
assertEquals("FOOEXT3", ((StringDt)name.getFamily().get(2).getAllUndeclaredExtensions().get(0).getValue()).getValue());
|
||||
assertEquals(null, name.getFamily().get(2).getAllUndeclaredExtensions().get(0).getElementSpecificId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testContainedResourceInExtensionUndeclared() {
|
||||
Patient p = new Patient();
|
||||
|
@ -163,7 +101,6 @@ public class JsonParserDstu2Test {
|
|||
assertEquals("ORG", o.getName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #308
|
||||
*/
|
||||
|
@ -181,6 +118,7 @@ public class JsonParserDstu2Test {
|
|||
obs = p.parseResource(ReportObservation.class, encoded);
|
||||
assertEquals(true, obs.getReadOnly().getValue().booleanValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseExtensions() throws Exception {
|
||||
|
@ -267,6 +205,7 @@ public class JsonParserDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseMetaProfileAndTags() {
|
||||
Patient p = new Patient();
|
||||
|
@ -324,6 +263,63 @@ public class JsonParserDstu2Test {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #336
|
||||
*/
|
||||
@Test
|
||||
public void testEncodeAndParseNullPrimitiveWithExtensions() {
|
||||
|
||||
Patient p = new Patient();
|
||||
p.setId("patid");
|
||||
HumanNameDt name = p.addName();
|
||||
name.addFamily().setValue(null).addUndeclaredExtension(new ExtensionDt(false, "http://foo", new StringDt("FOOEXT0")));
|
||||
name.getFamily().get(0).setElementSpecificId("f0");
|
||||
name.addFamily().setValue("V1").addUndeclaredExtension((ExtensionDt) new ExtensionDt(false, "http://foo", new StringDt("FOOEXT1")));
|
||||
name.getFamily().get(1).setElementSpecificId("f1");
|
||||
name.getFamily().get(1).getUndeclaredExtensions().get(0).setElementSpecificId("ext1id");
|
||||
name.addFamily(); // this one shouldn't get encoded
|
||||
name.addFamily().setValue(null).addUndeclaredExtension(new ExtensionDt(false, "http://foo", new StringDt("FOOEXT3")));
|
||||
name.setElementSpecificId("nameid");
|
||||
|
||||
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
|
||||
ourLog.info(output);
|
||||
|
||||
output = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(p);
|
||||
String expected = "{\"resourceType\":\"Patient\",\"id\":\"patid\",\"name\":[{\"id\":\"nameid\",\"family\":[null,\"V1\",null],\"_family\":[{\"id\":\"f0\",\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT0\"}]},{\"id\":\"f1\",\"extension\":[{\"id\":\"ext1id\",\"url\":\"http://foo\",\"valueString\":\"FOOEXT1\"}]},{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT3\"}]}]}]}";
|
||||
assertEquals(expected, output);
|
||||
|
||||
p = ourCtx.newJsonParser().parseResource(Patient.class, output);
|
||||
assertEquals("patid", p.getIdElement().getIdPart());
|
||||
|
||||
name = p.getName().get(0);
|
||||
assertEquals("nameid", name.getElementSpecificId());
|
||||
assertEquals(3, name.getFamily().size());
|
||||
|
||||
assertEquals(null, name.getFamily().get(0).getValue());
|
||||
assertEquals("V1", name.getFamily().get(1).getValue());
|
||||
assertEquals(null, name.getFamily().get(2).getValue());
|
||||
|
||||
assertEquals("f0", name.getFamily().get(0).getElementSpecificId());
|
||||
assertEquals("f1", name.getFamily().get(1).getElementSpecificId());
|
||||
assertEquals(null, name.getFamily().get(2).getElementSpecificId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(0).getAllUndeclaredExtensions().size());
|
||||
assertEquals("http://foo", name.getFamily().get(0).getAllUndeclaredExtensions().get(0).getUrl());
|
||||
assertEquals("FOOEXT0", ((StringDt)name.getFamily().get(0).getAllUndeclaredExtensions().get(0).getValue()).getValue());
|
||||
assertEquals(null, name.getFamily().get(0).getAllUndeclaredExtensions().get(0).getElementSpecificId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(1).getAllUndeclaredExtensions().size());
|
||||
assertEquals("http://foo", name.getFamily().get(1).getAllUndeclaredExtensions().get(0).getUrl());
|
||||
assertEquals("FOOEXT1", ((StringDt)name.getFamily().get(1).getAllUndeclaredExtensions().get(0).getValue()).getValue());
|
||||
assertEquals("ext1id", name.getFamily().get(1).getAllUndeclaredExtensions().get(0).getElementSpecificId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(2).getAllUndeclaredExtensions().size());
|
||||
assertEquals("http://foo", name.getFamily().get(2).getAllUndeclaredExtensions().get(0).getUrl());
|
||||
assertEquals("FOOEXT3", ((StringDt)name.getFamily().get(2).getAllUndeclaredExtensions().get(0).getValue()).getValue());
|
||||
assertEquals(null, name.getFamily().get(2).getAllUndeclaredExtensions().get(0).getElementSpecificId());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseSecurityLabels() {
|
||||
Patient p = new Patient();
|
||||
|
@ -385,7 +381,6 @@ public class JsonParserDstu2Test {
|
|||
assertEquals("VERSION2", label.getVersion());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBundleNewBundleNoText() {
|
||||
|
||||
|
@ -407,6 +402,7 @@ public class JsonParserDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBundleOldBundleNoText() {
|
||||
|
||||
|
@ -426,6 +422,7 @@ public class JsonParserDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fixing #89
|
||||
*/
|
||||
|
@ -495,6 +492,35 @@ public class JsonParserDstu2Test {
|
|||
assertThat(encoded, not(containsString("Label")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeExtensionInPrimitiveElement() {
|
||||
|
||||
Conformance c = new Conformance();
|
||||
c.getAcceptUnknownElement().addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
assertEquals(encoded, "{\"resourceType\":\"Conformance\",\"_acceptUnknown\":{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"AAA\"}]}}");
|
||||
|
||||
// Now with a value
|
||||
ourLog.info("---------------");
|
||||
|
||||
c = new Conformance();
|
||||
c.getAcceptUnknownElement().setValueAsEnum(UnknownContentCodeEnum.UNKNOWN_ELEMENTS);;
|
||||
c.getAcceptUnknownElement().addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
assertEquals(encoded, "{\"resourceType\":\"Conformance\",\"acceptUnknown\":\"elements\",\"_acceptUnknown\":{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"AAA\"}]}}");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeExtensionUndeclaredNonModifier() {
|
||||
Observation obs = new Observation();
|
||||
|
@ -1431,7 +1457,7 @@ public class JsonParserDstu2Test {
|
|||
ourLog.info(message);
|
||||
Assert.assertThat(message, containsString("contained"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #144 and #146
|
||||
*/
|
||||
|
@ -1455,4 +1481,9 @@ public class JsonParserDstu2Test {
|
|||
ourLog.info(message);
|
||||
Assert.assertThat(message, containsString("contained"));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ public class XmlParserDstu2Test {
|
|||
public void testEncodeExtensionWithContainedResource() {
|
||||
|
||||
TestPatientFor327 patient = new TestPatientFor327();
|
||||
patient.setBirthDate(new Date(), TemporalPrecisionEnum.DAY);
|
||||
patient.setBirthDate(new DateDt("2016-04-17"));
|
||||
|
||||
List<ResourceReferenceDt> conditions = new ArrayList<ResourceReferenceDt>();
|
||||
Condition condition = new Condition();
|
||||
|
@ -220,11 +220,11 @@ public class XmlParserDstu2Test {
|
|||
"</Condition>",
|
||||
"</contained>",
|
||||
"<extension url=\"testCondition\">",
|
||||
"<valueReference>",
|
||||
"<reference value=\"#1\"/>",
|
||||
"</valueReference>",
|
||||
"</extension>",
|
||||
"<birthDate value=\"2016-04-14\"/>",
|
||||
"<valueReference>",
|
||||
"<reference value=\"#1\"/>",
|
||||
"</valueReference>",
|
||||
"</extension>",
|
||||
"<birthDate value=\"2016-04-17\"/>",
|
||||
"</Patient>"
|
||||
));
|
||||
//@formatter:on
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.hl7.fhir.dstu3.model.Coding;
|
|||
import org.hl7.fhir.dstu3.model.Condition;
|
||||
import org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus;
|
||||
import org.hl7.fhir.dstu3.model.Conformance;
|
||||
import org.hl7.fhir.dstu3.model.Conformance.UnknownContentCode;
|
||||
import org.hl7.fhir.dstu3.model.DateTimeType;
|
||||
import org.hl7.fhir.dstu3.model.DateType;
|
||||
import org.hl7.fhir.dstu3.model.DecimalType;
|
||||
|
@ -82,80 +83,6 @@ public class JsonParserDstu3Test {
|
|||
ourCtx.setNarrativeGenerator(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* See #336
|
||||
*/
|
||||
@Test
|
||||
public void testEncodeAndParseNullPrimitiveWithExtensions() {
|
||||
|
||||
Patient p = new Patient();
|
||||
p.setId("patid");
|
||||
HumanName name = p.addName();
|
||||
name.addFamilyElement().setValue(null).setId("f0").addExtension(new Extension("http://foo", new StringType("FOOEXT0")));
|
||||
name.addFamilyElement().setValue("V1").setId("f1").addExtension((Extension) new Extension("http://foo", new StringType("FOOEXT1")).setId("ext1id"));
|
||||
name.addFamilyElement(); // this one shouldn't get encoded
|
||||
name.addFamilyElement().setValue(null).addExtension(new Extension("http://foo", new StringType("FOOEXT3")));
|
||||
name.setId("nameid");
|
||||
|
||||
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
|
||||
ourLog.info(output);
|
||||
|
||||
output = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(p);
|
||||
String expected = "{\"resourceType\":\"Patient\",\"id\":\"patid\",\"name\":[{\"id\":\"nameid\",\"family\":[null,\"V1\",null],\"_family\":[{\"id\":\"f0\",\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT0\"}]},{\"id\":\"f1\",\"extension\":[{\"id\":\"ext1id\",\"url\":\"http://foo\",\"valueString\":\"FOOEXT1\"}]},{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT3\"}]}]}]}";
|
||||
assertEquals(expected, output);
|
||||
|
||||
p = ourCtx.newJsonParser().parseResource(Patient.class, output);
|
||||
assertEquals("patid", p.getIdElement().getIdPart());
|
||||
|
||||
name = p.getName().get(0);
|
||||
assertEquals("nameid", name.getId());
|
||||
assertEquals(3, name.getFamily().size());
|
||||
|
||||
assertEquals(null, name.getFamily().get(0).getValue());
|
||||
assertEquals("V1", name.getFamily().get(1).getValue());
|
||||
assertEquals(null, name.getFamily().get(2).getValue());
|
||||
|
||||
assertEquals("f0", name.getFamily().get(0).getId());
|
||||
assertEquals("f1", name.getFamily().get(1).getId());
|
||||
assertEquals(null, name.getFamily().get(2).getId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(0).getExtension().size());
|
||||
assertEquals("http://foo", name.getFamily().get(0).getExtension().get(0).getUrl());
|
||||
assertEquals("FOOEXT0", ((StringType)name.getFamily().get(0).getExtension().get(0).getValue()).getValue());
|
||||
assertEquals(null, name.getFamily().get(0).getExtension().get(0).getId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(1).getExtension().size());
|
||||
assertEquals("http://foo", name.getFamily().get(1).getExtension().get(0).getUrl());
|
||||
assertEquals("FOOEXT1", ((StringType)name.getFamily().get(1).getExtension().get(0).getValue()).getValue());
|
||||
assertEquals("ext1id", name.getFamily().get(1).getExtension().get(0).getId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(2).getExtension().size());
|
||||
assertEquals("http://foo", name.getFamily().get(2).getExtension().get(0).getUrl());
|
||||
assertEquals("FOOEXT3", ((StringType)name.getFamily().get(2).getExtension().get(0).getValue()).getValue());
|
||||
assertEquals(null, name.getFamily().get(2).getExtension().get(0).getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* See #335
|
||||
*/
|
||||
@Test
|
||||
public void testParseExtensionWithId() throws Exception {
|
||||
String input = IOUtils.toString(getClass().getResourceAsStream("/json-edge-case-modified-335.json"));
|
||||
|
||||
Patient p = ourCtx.newJsonParser().parseResource(Patient.class, input);
|
||||
StringType family1 = p.getContact().get(0).getName().getFamily().get(1);
|
||||
assertEquals("du", family1.getValue());
|
||||
assertEquals("a2", family1.getId());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseExtensions() throws Exception {
|
||||
|
||||
|
@ -240,6 +167,7 @@ public class JsonParserDstu3Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseMetaProfileAndTags() {
|
||||
Patient p = new Patient();
|
||||
|
@ -318,7 +246,60 @@ public class JsonParserDstu3Test {
|
|||
assertEquals("sec_label2", tagList.get(1).getDisplay());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #336
|
||||
*/
|
||||
@Test
|
||||
public void testEncodeAndParseNullPrimitiveWithExtensions() {
|
||||
|
||||
Patient p = new Patient();
|
||||
p.setId("patid");
|
||||
HumanName name = p.addName();
|
||||
name.addFamilyElement().setValue(null).setId("f0").addExtension(new Extension("http://foo", new StringType("FOOEXT0")));
|
||||
name.addFamilyElement().setValue("V1").setId("f1").addExtension((Extension) new Extension("http://foo", new StringType("FOOEXT1")).setId("ext1id"));
|
||||
name.addFamilyElement(); // this one shouldn't get encoded
|
||||
name.addFamilyElement().setValue(null).addExtension(new Extension("http://foo", new StringType("FOOEXT3")));
|
||||
name.setId("nameid");
|
||||
|
||||
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
|
||||
ourLog.info(output);
|
||||
|
||||
output = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(p);
|
||||
String expected = "{\"resourceType\":\"Patient\",\"id\":\"patid\",\"name\":[{\"id\":\"nameid\",\"family\":[null,\"V1\",null],\"_family\":[{\"id\":\"f0\",\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT0\"}]},{\"id\":\"f1\",\"extension\":[{\"id\":\"ext1id\",\"url\":\"http://foo\",\"valueString\":\"FOOEXT1\"}]},{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT3\"}]}]}]}";
|
||||
assertEquals(expected, output);
|
||||
|
||||
p = ourCtx.newJsonParser().parseResource(Patient.class, output);
|
||||
assertEquals("patid", p.getIdElement().getIdPart());
|
||||
|
||||
name = p.getName().get(0);
|
||||
assertEquals("nameid", name.getId());
|
||||
assertEquals(3, name.getFamily().size());
|
||||
|
||||
assertEquals(null, name.getFamily().get(0).getValue());
|
||||
assertEquals("V1", name.getFamily().get(1).getValue());
|
||||
assertEquals(null, name.getFamily().get(2).getValue());
|
||||
|
||||
assertEquals("f0", name.getFamily().get(0).getId());
|
||||
assertEquals("f1", name.getFamily().get(1).getId());
|
||||
assertEquals(null, name.getFamily().get(2).getId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(0).getExtension().size());
|
||||
assertEquals("http://foo", name.getFamily().get(0).getExtension().get(0).getUrl());
|
||||
assertEquals("FOOEXT0", ((StringType)name.getFamily().get(0).getExtension().get(0).getValue()).getValue());
|
||||
assertEquals(null, name.getFamily().get(0).getExtension().get(0).getId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(1).getExtension().size());
|
||||
assertEquals("http://foo", name.getFamily().get(1).getExtension().get(0).getUrl());
|
||||
assertEquals("FOOEXT1", ((StringType)name.getFamily().get(1).getExtension().get(0).getValue()).getValue());
|
||||
assertEquals("ext1id", name.getFamily().get(1).getExtension().get(0).getId());
|
||||
|
||||
assertEquals(1, name.getFamily().get(2).getExtension().size());
|
||||
assertEquals("http://foo", name.getFamily().get(2).getExtension().get(0).getUrl());
|
||||
assertEquals("FOOEXT3", ((StringType)name.getFamily().get(2).getExtension().get(0).getValue()).getValue());
|
||||
assertEquals(null, name.getFamily().get(2).getExtension().get(0).getId());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseSecurityLabels() {
|
||||
Patient p = new Patient();
|
||||
|
@ -378,7 +359,7 @@ public class JsonParserDstu3Test {
|
|||
assertEquals("DISPLAY2", label.getDisplay());
|
||||
assertEquals("VERSION2", label.getVersion());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBundleNewBundleNoText() {
|
||||
|
@ -444,13 +425,14 @@ public class JsonParserDstu3Test {
|
|||
String actual = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
|
||||
assertThat(actual, not(containsString("78ef6f64c2f2")));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeEmptyBinary() {
|
||||
String output = ourCtx.newJsonParser().encodeResourceToString(new Binary());
|
||||
assertEquals("{\"resourceType\":\"Binary\"}", output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* #158
|
||||
*/
|
||||
|
@ -467,6 +449,7 @@ public class JsonParserDstu3Test {
|
|||
assertThat(encoded, not(containsString("tag")));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* #158
|
||||
*/
|
||||
|
@ -484,6 +467,35 @@ public class JsonParserDstu3Test {
|
|||
assertThat(encoded, containsString("scheme"));
|
||||
assertThat(encoded, not(containsString("Label")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeExtensionInPrimitiveElement() {
|
||||
|
||||
Conformance c = new Conformance();
|
||||
c.getAcceptUnknownElement().addExtension().setUrl("http://foo").setValue(new StringType("AAA"));
|
||||
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
assertEquals(encoded, "{\"resourceType\":\"Conformance\",\"_acceptUnknown\":{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"AAA\"}]}}");
|
||||
|
||||
// Now with a value
|
||||
ourLog.info("---------------");
|
||||
|
||||
c = new Conformance();
|
||||
c.getAcceptUnknownElement().setValue(UnknownContentCode.ELEMENTS);
|
||||
c.getAcceptUnknownElement().addExtension().setUrl("http://foo").setValue(new StringType("AAA"));
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(c);
|
||||
ourLog.info(encoded);
|
||||
assertEquals(encoded, "{\"resourceType\":\"Conformance\",\"acceptUnknown\":\"elements\",\"_acceptUnknown\":{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"AAA\"}]}}");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeExtensionUndeclaredNonModifier() {
|
||||
|
@ -565,7 +577,7 @@ public class JsonParserDstu3Test {
|
|||
assertEquals("http://subext", obs.getExtension().get(0).getExtension().get(0).getUrl());
|
||||
assertEquals("sub_ext_value", ((StringType)obs.getExtension().get(0).getExtension().get(0).getValue()).getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeNarrativeSuppressed() throws Exception {
|
||||
Patient patient = new Patient();
|
||||
|
@ -585,7 +597,6 @@ public class JsonParserDstu3Test {
|
|||
assertThat(encoded, containsString("maritalStatus"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeParametersWithId() {
|
||||
Parameters reqParms = new Parameters();
|
||||
|
@ -597,7 +608,7 @@ public class JsonParserDstu3Test {
|
|||
|
||||
assertThat(enc, containsString("\"valueId\":\"1\""));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeSummary() {
|
||||
Patient patient = new Patient();
|
||||
|
@ -619,6 +630,7 @@ public class JsonParserDstu3Test {
|
|||
assertThat(encoded, not(containsString("maritalStatus")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeSummary2() {
|
||||
Patient patient = new Patient();
|
||||
|
@ -656,20 +668,26 @@ public class JsonParserDstu3Test {
|
|||
|
||||
}
|
||||
|
||||
// see #241
|
||||
/**
|
||||
* See #241
|
||||
*/
|
||||
@Test
|
||||
public void testEncodeThenParseShouldNotAddSpuriousId() throws Exception {
|
||||
Condition condition = new Condition().setVerificationStatus(ConditionVerificationStatus.CONFIRMED);
|
||||
Bundle bundle = new Bundle();
|
||||
BundleEntryComponent entry = new Bundle.BundleEntryComponent();
|
||||
entry.setIdElement(IdType.newRandomUuid());
|
||||
entry.setId("123");
|
||||
entry.setResource(condition);
|
||||
bundle.getEntry().add(entry);
|
||||
IParser parser = ourCtx.newJsonParser();
|
||||
String json = parser.encodeResourceToString(bundle);
|
||||
ourLog.info(json);
|
||||
bundle = (Bundle) parser.parseResource(json);
|
||||
assertThat(json, not(containsString("\"id\"")));
|
||||
|
||||
assertEquals("123", bundle.getEntry().get(0).getId());
|
||||
|
||||
condition = (Condition) bundle.getEntry().get(0).getResource();
|
||||
assertEquals(null, condition.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1218,6 +1236,19 @@ public class JsonParserDstu3Test {
|
|||
assertEquals("patient family", p.getName().get(0).getFamily().get(0).getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* See #335
|
||||
*/
|
||||
@Test
|
||||
public void testParseExtensionWithId() throws Exception {
|
||||
String input = IOUtils.toString(getClass().getResourceAsStream("/json-edge-case-modified-335.json"));
|
||||
|
||||
Patient p = ourCtx.newJsonParser().parseResource(Patient.class, input);
|
||||
StringType family1 = p.getContact().get(0).getName().getFamily().get(1);
|
||||
assertEquals("du", family1.getValue());
|
||||
assertEquals("a2", family1.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseMetadata() throws Exception {
|
||||
//@formatter:off
|
||||
|
@ -1397,4 +1428,9 @@ public class JsonParserDstu3Test {
|
|||
ourLog.info(message);
|
||||
Assert.assertThat(message, containsString("contained"));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue