JsonParser tests for OverrideResourceIdWithBundleEntryFullUrl

This commit is contained in:
michael.i.calderero 2017-04-13 13:37:02 -05:00
parent b890bf3c75
commit 125f9b4fed
4 changed files with 190 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
@ -36,6 +37,7 @@ import org.hl7.fhir.dstu2016may.model.Enumeration;
import org.hl7.fhir.dstu2016may.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.dstu2016may.model.Identifier.IdentifierUse;
import org.hl7.fhir.dstu2016may.model.Observation.ObservationStatus;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.*;
import org.mockito.ArgumentCaptor;
@ -62,7 +64,46 @@ public class JsonParserDstu2_1Test {
ourCtx.setNarrativeGenerator(null);
}
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnFhirContext() {
try {
String tmp = "{\"resourceType\":\"Bundle\",\"entry\":[{\"fullUrl\":\"http://lalaland.org/patient/pat1\",\"resource\":{\"resourceType\":\"Patient\",\"id\":\"patxuzos\"}}]}";
ourCtx.getParserOptions().setOverrideResourceIdWithBundleEntryFullUrl(false);
Bundle bundle = (Bundle) ourCtx.newJsonParser().parseResource(tmp);
assertEquals(1, bundle.getEntry().size());
{
Patient o1 = (Patient) bundle.getEntry().get(0).getResource();
IIdType o1Id = o1.getIdElement();
assertFalse(o1Id.hasBaseUrl());
assertEquals("Patient", o1Id.getResourceType());
assertEquals("patxuzos", o1Id.getIdPart());
assertFalse(o1Id.hasVersionIdPart());
}
} finally {
// ensure we cleanup ourCtx so other tests continue to work
ourCtx = FhirContext.forDstu2_1();
}
}
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
try {
String tmp = "{\"resourceType\":\"Bundle\",\"entry\":[{\"fullUrl\":\"http://lalaland.org/patient/pat1\",\"resource\":{\"resourceType\":\"Patient\",\"id\":\"patxuzos\"}}]}";
Bundle bundle = (Bundle) ourCtx.newJsonParser().setOverrideResourceIdWithBundleEntryFullUrl(false).parseResource(tmp);
assertEquals(1, bundle.getEntry().size());
{
Patient o1 = (Patient) bundle.getEntry().get(0).getResource();
IIdType o1Id = o1.getIdElement();
assertFalse(o1Id.hasBaseUrl());
assertEquals("Patient", o1Id.getResourceType());
assertEquals("patxuzos", o1Id.getIdPart());
assertFalse(o1Id.hasVersionIdPart());
}
} finally {
// ensure we cleanup ourCtx so other tests continue to work
ourCtx = FhirContext.forDstu2_1();
}
}
/**
* #480

View File

@ -5,6 +5,7 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
@ -22,6 +23,7 @@ import java.util.*;
import org.apache.commons.io.IOUtils;
import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
@ -70,6 +72,47 @@ public class JsonParserDstu2Test {
private static FhirContext ourCtx = FhirContext.forDstu2();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserDstu2Test.class);
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnFhirContext() {
try {
String tmp = "{\"resourceType\":\"Bundle\",\"entry\":[{\"fullUrl\":\"http://lalaland.org/patient/pat1\",\"resource\":{\"resourceType\":\"Patient\",\"id\":\"patxuzos\"}}]}";
ourCtx.getParserOptions().setOverrideResourceIdWithBundleEntryFullUrl(false);
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = (ca.uhn.fhir.model.dstu2.resource.Bundle) ourCtx.newJsonParser().parseResource(tmp);
assertEquals(1, bundle.getEntry().size());
{
Patient o1 = (Patient) bundle.getEntry().get(0).getResource();
IIdType o1Id = o1.getIdElement();
assertFalse(o1Id.hasBaseUrl());
assertEquals("Patient", o1Id.getResourceType());
assertEquals("patxuzos", o1Id.getIdPart());
assertFalse(o1Id.hasVersionIdPart());
}
} finally {
// ensure we cleanup ourCtx so other tests continue to work
ourCtx = FhirContext.forDstu2();
}
}
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
try {
String tmp = "{\"resourceType\":\"Bundle\",\"entry\":[{\"fullUrl\":\"http://lalaland.org/patient/pat1\",\"resource\":{\"resourceType\":\"Patient\",\"id\":\"patxuzos\"}}]}";
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = (ca.uhn.fhir.model.dstu2.resource.Bundle) ourCtx.newJsonParser().setOverrideResourceIdWithBundleEntryFullUrl(false).parseResource(tmp);
assertEquals(1, bundle.getEntry().size());
{
Patient o1 = (Patient) bundle.getEntry().get(0).getResource();
IIdType o1Id = o1.getIdElement();
assertFalse(o1Id.hasBaseUrl());
assertEquals("Patient", o1Id.getResourceType());
assertEquals("patxuzos", o1Id.getIdPart());
assertFalse(o1Id.hasVersionIdPart());
}
} finally {
// ensure we cleanup ourCtx so other tests continue to work
ourCtx = FhirContext.forDstu2();
}
}
/**
* See #544
*/

View File

@ -7,6 +7,7 @@ import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
@ -45,6 +46,7 @@ import org.hl7.fhir.dstu3.model.CapabilityStatement.UnknownContentCode;
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.After;
import org.junit.AfterClass;
@ -79,6 +81,47 @@ public class JsonParserDstu3Test {
public void after() {
ourCtx.setNarrativeGenerator(null);
}
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnFhirContext() {
try {
String tmp = "{\"resourceType\":\"Bundle\",\"entry\":[{\"fullUrl\":\"http://lalaland.org/patient/pat1\",\"resource\":{\"resourceType\":\"Patient\",\"id\":\"patxuzos\"}}]}";
ourCtx.getParserOptions().setOverrideResourceIdWithBundleEntryFullUrl(false);
Bundle bundle = (Bundle) ourCtx.newJsonParser().parseResource(tmp);
assertEquals(1, bundle.getEntry().size());
{
Patient o1 = (Patient) bundle.getEntry().get(0).getResource();
IIdType o1Id = o1.getIdElement();
assertFalse(o1Id.hasBaseUrl());
assertEquals("Patient", o1Id.getResourceType());
assertEquals("patxuzos", o1Id.getIdPart());
assertFalse(o1Id.hasVersionIdPart());
}
} finally {
// ensure we cleanup ourCtx so other tests continue to work
ourCtx = FhirContext.forDstu3();
}
}
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
try {
String tmp = "{\"resourceType\":\"Bundle\",\"entry\":[{\"fullUrl\":\"http://lalaland.org/patient/pat1\",\"resource\":{\"resourceType\":\"Patient\",\"id\":\"patxuzos\"}}]}";
Bundle bundle = (Bundle) ourCtx.newJsonParser().setOverrideResourceIdWithBundleEntryFullUrl(false).parseResource(tmp);
assertEquals(1, bundle.getEntry().size());
{
Patient o1 = (Patient) bundle.getEntry().get(0).getResource();
IIdType o1Id = o1.getIdElement();
assertFalse(o1Id.hasBaseUrl());
assertEquals("Patient", o1Id.getResourceType());
assertEquals("patxuzos", o1Id.getIdPart());
assertFalse(o1Id.hasVersionIdPart());
}
} finally {
// ensure we cleanup ourCtx so other tests continue to work
ourCtx = FhirContext.forDstu3();
}
}
/**
* See #544

View File

@ -5,6 +5,7 @@ import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@ -56,6 +57,7 @@ import org.hl7.fhir.instance.model.ValueSet;
import org.hl7.fhir.instance.model.ValueSet.ConceptDefinitionComponent;
import org.hl7.fhir.instance.model.ValueSet.ValueSetCodeSystemComponent;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.INarrative;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
@ -88,6 +90,67 @@ public class JsonParserHl7OrgDstu2Test {
public static void afterClassClearContext() {
TestUtil.clearAllStaticFieldsForUnitTest();
}
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlEnabled() {
try {
String tmp = "{\"resourceType\":\"Bundle\",\"entry\":[{\"fullUrl\":\"http://lalaland.org/patient/pat1\",\"resource\":{\"resourceType\":\"Patient\",\"id\":\"patxuzos\"}}]}";
Bundle bundle = (Bundle) ourCtx.newJsonParser().parseResource(tmp);
assertEquals(1, bundle.getEntry().size());
{
Patient o1 = (Patient) bundle.getEntry().get(0).getResource();
IIdType o1Id = o1.getIdElement();
assertEquals("http://lalaland.org", o1Id.getBaseUrl());
assertEquals("patient", o1Id.getResourceType());
assertEquals("pat1", o1Id.getIdPart());
assertFalse(o1Id.hasVersionIdPart());
}
} finally {
// ensure we cleanup ourCtx so other tests continue to work
ourCtx = FhirContext.forDstu2Hl7Org();
}
}
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnFhirContext() {
try {
String tmp = "{\"resourceType\":\"Bundle\",\"entry\":[{\"fullUrl\":\"http://lalaland.org/patient/pat1\",\"resource\":{\"resourceType\":\"Patient\",\"id\":\"patxuzos\"}}]}";
ourCtx.getParserOptions().setOverrideResourceIdWithBundleEntryFullUrl(false);
Bundle bundle = (Bundle) ourCtx.newJsonParser().parseResource(tmp);
assertEquals(1, bundle.getEntry().size());
{
Patient o1 = (Patient) bundle.getEntry().get(0).getResource();
IIdType o1Id = o1.getIdElement();
assertFalse(o1Id.hasBaseUrl());
assertEquals("Patient", o1Id.getResourceType());
assertEquals("patxuzos", o1Id.getIdPart());
assertFalse(o1Id.hasVersionIdPart());
}
} finally {
// ensure we cleanup ourCtx so other tests continue to work
ourCtx = FhirContext.forDstu2Hl7Org();
}
}
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
try {
String tmp = "{\"resourceType\":\"Bundle\",\"entry\":[{\"fullUrl\":\"http://lalaland.org/patient/pat1\",\"resource\":{\"resourceType\":\"Patient\",\"id\":\"patxuzos\"}}]}";
Bundle bundle = (Bundle) ourCtx.newJsonParser().setOverrideResourceIdWithBundleEntryFullUrl(false).parseResource(tmp);
assertEquals(1, bundle.getEntry().size());
{
Patient o1 = (Patient) bundle.getEntry().get(0).getResource();
IIdType o1Id = o1.getIdElement();
assertFalse(o1Id.hasBaseUrl());
assertEquals("Patient", o1Id.getResourceType());
assertEquals("patxuzos", o1Id.getIdPart());
assertFalse(o1Id.hasVersionIdPart());
}
} finally {
// ensure we cleanup ourCtx so other tests continue to work
ourCtx = FhirContext.forDstu2Hl7Org();
}
}
@Test
public void testEncodeUndeclaredExtensionWithEnumerationContent() {