XmlParser tests for OverrideResourceIdWithBundleEntryFullUrl
This commit is contained in:
parent
7d9883014a
commit
b890bf3c75
|
@ -8,6 +8,7 @@ import static org.hamcrest.Matchers.startsWith;
|
|||
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.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
@ -96,6 +97,7 @@ import org.hl7.fhir.dstu2016may.model.StringType;
|
|||
import org.hl7.fhir.dstu2016may.model.UriType;
|
||||
import org.hl7.fhir.dstu2016may.model.ValueSet;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -128,6 +130,47 @@ public class XmlParserDstu2_1Test {
|
|||
}
|
||||
ourCtx.setNarrativeGenerator(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnFhirContext() {
|
||||
try {
|
||||
String tmp = "<Bundle xmlns=\"http://hl7.org/fhir\"><entry><fullUrl value=\"http://lalaland.org/patient/pat1\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"patxuzos\"/></Patient></resource></entry></Bundle>";
|
||||
ourCtx.getParserOptions().setOverrideResourceIdWithBundleEntryFullUrl(false);
|
||||
Bundle bundle = (Bundle) ourCtx.newXmlParser().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 = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
|
||||
try {
|
||||
String tmp = "<Bundle xmlns=\"http://hl7.org/fhir\"><entry><fullUrl value=\"http://lalaland.org/patient/pat1\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"patxuzos\"/></Patient></resource></entry></Bundle>";
|
||||
Bundle bundle = (Bundle) ourCtx.newXmlParser().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 = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See #414
|
||||
|
|
|
@ -12,6 +12,7 @@ import static org.junit.Assert.assertNull;
|
|||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -30,6 +31,7 @@ import org.hamcrest.collection.IsEmptyCollection;
|
|||
import org.hamcrest.core.StringContains;
|
||||
import org.hamcrest.text.StringContainsInOrder;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -68,6 +70,47 @@ public class XmlParserDstu2Test {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnFhirContext() {
|
||||
try {
|
||||
String tmp = "<Bundle xmlns=\"http://hl7.org/fhir\"><entry><fullUrl value=\"http://lalaland.org/patient/pat1\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"patxuzos\"/></Patient></resource></entry></Bundle>";
|
||||
ourCtx.getParserOptions().setOverrideResourceIdWithBundleEntryFullUrl(false);
|
||||
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = (ca.uhn.fhir.model.dstu2.resource.Bundle) ourCtx.newXmlParser().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 = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
|
||||
try {
|
||||
String tmp = "<Bundle xmlns=\"http://hl7.org/fhir\"><entry><fullUrl value=\"http://lalaland.org/patient/pat1\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"patxuzos\"/></Patient></resource></entry></Bundle>";
|
||||
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = (ca.uhn.fhir.model.dstu2.resource.Bundle) ourCtx.newXmlParser().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 = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See #414
|
||||
*/
|
||||
|
|
|
@ -8,6 +8,7 @@ import static org.hamcrest.Matchers.startsWith;
|
|||
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.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
@ -50,6 +51,7 @@ import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse;
|
|||
import org.hl7.fhir.dstu3.model.Observation.ObservationRelationshipType;
|
||||
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
|
@ -77,6 +79,47 @@ public class XmlParserDstu3Test {
|
|||
}
|
||||
ourCtx.setNarrativeGenerator(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnFhirContext() {
|
||||
try {
|
||||
String tmp = "<Bundle xmlns=\"http://hl7.org/fhir\"><entry><fullUrl value=\"http://lalaland.org/patient/pat1\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"patxuzos\"/></Patient></resource></entry></Bundle>";
|
||||
ourCtx.getParserOptions().setOverrideResourceIdWithBundleEntryFullUrl(false);
|
||||
Bundle bundle = (Bundle) ourCtx.newXmlParser().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 = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
|
||||
try {
|
||||
String tmp = "<Bundle xmlns=\"http://hl7.org/fhir\"><entry><fullUrl value=\"http://lalaland.org/patient/pat1\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"patxuzos\"/></Patient></resource></entry></Bundle>";
|
||||
Bundle bundle = (Bundle) ourCtx.newXmlParser().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 = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See #551
|
||||
|
|
|
@ -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.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
@ -60,6 +61,7 @@ import org.hl7.fhir.instance.model.SimpleQuantity;
|
|||
import org.hl7.fhir.instance.model.Specimen;
|
||||
import org.hl7.fhir.instance.model.StringType;
|
||||
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.junit.After;
|
||||
|
@ -97,6 +99,52 @@ public class XmlParserHl7OrgDstu2Test {
|
|||
private String fixDivNodeTextJson(String htmlNoNs) {
|
||||
return htmlNoNs.replace("<div>", "<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlEnabled() {
|
||||
String tmp = "<Bundle xmlns=\"http://hl7.org/fhir\"><entry><fullUrl value=\"http://lalaland.org/patient/pat1\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"patxuzos\"/></Patient></resource></entry></Bundle>";
|
||||
Bundle bundle = (Bundle) ourCtx.newXmlParser().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());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnFhirContext() {
|
||||
String tmp = "<Bundle xmlns=\"http://hl7.org/fhir\"><entry><fullUrl value=\"http://lalaland.org/patient/pat1\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"patxuzos\"/></Patient></resource></entry></Bundle>";
|
||||
ourCtx.getParserOptions().setOverrideResourceIdWithBundleEntryFullUrl(false);
|
||||
Bundle bundle = (Bundle) ourCtx.newXmlParser().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());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
|
||||
String tmp = "<Bundle xmlns=\"http://hl7.org/fhir\"><entry><fullUrl value=\"http://lalaland.org/patient/pat1\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"patxuzos\"/></Patient></resource></entry></Bundle>";
|
||||
Bundle bundle = (Bundle) ourCtx.newXmlParser().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());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComposition() {
|
||||
|
|
Loading…
Reference in New Issue