Add test for #505
This commit is contained in:
parent
64d12240c0
commit
8ae8f1d8b6
|
@ -15,11 +15,7 @@ import static org.mockito.Mockito.times;
|
|||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hamcrest.Matchers;
|
||||
|
@ -36,30 +32,15 @@ import com.google.common.collect.Sets;
|
|||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.BundleEntry;
|
||||
import ca.uhn.fhir.model.api.ExtensionDt;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||
import ca.uhn.fhir.model.api.Tag;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||
import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
|
||||
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
|
||||
import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
|
||||
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Basic;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Binary;
|
||||
import ca.uhn.fhir.model.dstu2.resource.*;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Condition;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu2.resource.DiagnosticReport;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Medication;
|
||||
import ca.uhn.fhir.model.dstu2.resource.MedicationOrder;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Organization;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu2.resource.QuestionnaireResponse;
|
||||
import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
|
||||
import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum;
|
||||
import ca.uhn.fhir.model.dstu2.valueset.ConditionVerificationStatusEnum;
|
||||
|
@ -227,7 +208,8 @@ public class JsonParserDstu2Test {
|
|||
assertThat(enc, Matchers.stringContainsInOrder("{\"resourceType\":\"Patient\",", "\"extension\":[{\"url\":\"http://example.com/extensions#someext\",\"valueDateTime\":\"2011-01-02T11:13:15\"}",
|
||||
"{\"url\":\"http://example.com#parent\",\"extension\":[{\"url\":\"http://example.com#child\",\"valueString\":\"value1\"},{\"url\":\"http://example.com#child\",\"valueString\":\"value2\"}]}"));
|
||||
assertThat(enc, Matchers.stringContainsInOrder("\"modifierExtension\":[" + "{" + "\"url\":\"http://example.com/extensions#modext\"," + "\"valueDate\":\"1995-01-02\"" + "}" + "],"));
|
||||
assertThat(enc, containsString("\"_given\":[" + "{" + "\"extension\":[" + "{" + "\"url\":\"http://examples.com#givenext\"," + "\"valueString\":\"given\"" + "}" + "]" + "}," + "{" + "\"extension\":[" + "{" + "\"url\":\"http://examples.com#givenext_parent\"," + "\"extension\":[" + "{"
|
||||
assertThat(enc, containsString("\"_given\":[" + "{" + "\"extension\":[" + "{" + "\"url\":\"http://examples.com#givenext\"," + "\"valueString\":\"given\"" + "}" + "]" + "}," + "{"
|
||||
+ "\"extension\":[" + "{" + "\"url\":\"http://examples.com#givenext_parent\"," + "\"extension\":[" + "{"
|
||||
+ "\"url\":\"http://examples.com#givenext_child\"," + "\"valueString\":\"CHILD\"" + "}" + "]" + "}" + "]" + "}"));
|
||||
|
||||
/*
|
||||
|
@ -268,7 +250,6 @@ public class JsonParserDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAndParseLanguage() {
|
||||
Patient p = new Patient();
|
||||
|
@ -384,17 +365,17 @@ public class JsonParserDstu2Test {
|
|||
|
||||
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("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("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("FOOEXT3", ((StringDt) name.getFamily().get(2).getAllUndeclaredExtensions().get(0).getValue()).getValue());
|
||||
assertEquals(null, name.getFamily().get(2).getAllUndeclaredExtensions().get(0).getElementSpecificId());
|
||||
|
||||
}
|
||||
|
@ -484,7 +465,6 @@ public class JsonParserDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBundleOldBundleNoText() {
|
||||
|
||||
|
@ -504,7 +484,6 @@ public class JsonParserDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fixing #89
|
||||
*/
|
||||
|
@ -524,7 +503,6 @@ public class JsonParserDstu2Test {
|
|||
//@formatter:on
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeDoesntIncludeUuidId() {
|
||||
Patient p = new Patient();
|
||||
|
@ -592,7 +570,8 @@ public class JsonParserDstu2Test {
|
|||
ourLog.info("---------------");
|
||||
|
||||
c = new Conformance();
|
||||
c.getAcceptUnknownElement().setValueAsEnum(UnknownContentCodeEnum.UNKNOWN_ELEMENTS);;
|
||||
c.getAcceptUnknownElement().setValueAsEnum(UnknownContentCodeEnum.UNKNOWN_ELEMENTS);
|
||||
;
|
||||
c.getAcceptUnknownElement().addUndeclaredExtension(false, "http://foo", new StringDt("AAA"));
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(c);
|
||||
|
@ -638,7 +617,7 @@ public class JsonParserDstu2Test {
|
|||
obs = parser.parseResource(Observation.class, output);
|
||||
assertEquals(1, obs.getUndeclaredExtensions().size());
|
||||
assertEquals("http://exturl", obs.getUndeclaredExtensions().get(0).getUrl());
|
||||
assertEquals("ext_url_value", ((StringDt)obs.getUndeclaredExtensions().get(0).getValue()).getValue());
|
||||
assertEquals("ext_url_value", ((StringDt) obs.getUndeclaredExtensions().get(0).getValue()).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -682,10 +661,9 @@ public class JsonParserDstu2Test {
|
|||
assertEquals("http://exturl", obs.getUndeclaredExtensions().get(0).getUrl());
|
||||
assertEquals(1, obs.getUndeclaredExtensions().get(0).getExtension().size());
|
||||
assertEquals("http://subext", obs.getUndeclaredExtensions().get(0).getExtension().get(0).getUrl());
|
||||
assertEquals("sub_ext_value", ((StringDt)obs.getUndeclaredExtensions().get(0).getExtension().get(0).getValue()).getValue());
|
||||
assertEquals("sub_ext_value", ((StringDt) obs.getUndeclaredExtensions().get(0).getExtension().get(0).getValue()).getValue());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #428
|
||||
*/
|
||||
|
@ -708,7 +686,6 @@ public class JsonParserDstu2Test {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeForceResourceId() {
|
||||
Patient p = new Patient();
|
||||
|
@ -800,7 +777,8 @@ public class JsonParserDstu2Test {
|
|||
ourLog.info(encoded);
|
||||
|
||||
assertThat(encoded, containsString("Patient"));
|
||||
assertThat(encoded, stringContainsInOrder("\"tag\"", "\"system\": \"foo\",", "\"code\": \"bar\"", "\"system\": \"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\": \"" + Constants.TAG_SUBSETTED_CODE + "\","));
|
||||
assertThat(encoded, stringContainsInOrder("\"tag\"", "\"system\": \"foo\",", "\"code\": \"bar\"", "\"system\": \"" + Constants.TAG_SUBSETTED_SYSTEM + "\",",
|
||||
"\"code\": \"" + Constants.TAG_SUBSETTED_CODE + "\","));
|
||||
assertThat(encoded, not(containsString("THE DIV")));
|
||||
assertThat(encoded, containsString("family"));
|
||||
assertThat(encoded, not(containsString("maritalStatus")));
|
||||
|
@ -1832,4 +1810,38 @@ public class JsonParserDstu2Test {
|
|||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* See #505
|
||||
*/
|
||||
@Test
|
||||
public void testIncludeResourceWhenEncoding() {
|
||||
Condition condition = new Condition();
|
||||
condition.setDateRecorded(new DateDt("2011-01-01"));
|
||||
|
||||
Goal goal = new Goal();
|
||||
goal.setId("Goal1");
|
||||
ResourceReferenceDt resourceReferenceDt = new ResourceReferenceDt(condition);
|
||||
goal.setAddresses(Collections.singletonList(resourceReferenceDt));
|
||||
|
||||
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
||||
Entry entry = bundle.addEntry();
|
||||
entry.setResource(goal);
|
||||
|
||||
IParser parser = ourCtx.newJsonParser();
|
||||
|
||||
String resourceToString = parser.setPrettyPrint(true).encodeResourceToString(bundle);
|
||||
ourLog.info(resourceToString);
|
||||
|
||||
assertThat(resourceToString, containsString("2011-01-01"));
|
||||
|
||||
bundle = parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, resourceToString);
|
||||
assertEquals(1, bundle.getEntry().size());
|
||||
goal = (Goal) bundle.getEntry().get(0).getResource();
|
||||
|
||||
condition = (Condition) goal.getAddresses().get(0).getResource();
|
||||
|
||||
assertEquals("2011-01-01", condition.getDateRecordedElement().getValueAsString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue