From bf35f7e4b29a181d6779bb70eac1e17a15dfa2d1 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Mon, 21 Nov 2016 13:44:54 +0100 Subject: [PATCH] Fix #495 - Auto-detect DSTU3 mode when those resources are on classpath --- .../java/ca/uhn/fhir/context/FhirContext.java | 2 ++ .../uhn/fhir/context/FhirContextDstu1Test.java | 7 +++++++ .../ca/uhn/fhir/ctx/FhirContextDstu2Test.java | 8 ++++++++ .../uhn/fhir/context/FhirContextDstu3Test.java | 7 +++++++ .../fhir/context/FhirContextDstu2Hl7OrgTest.java | 16 ++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/context/FhirContextDstu2Hl7OrgTest.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java index 1f174e3d857..82b8bcdbf54 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java @@ -188,6 +188,8 @@ public class FhirContext { myVersion = FhirVersionEnum.DSTU2.getVersionImplementation(); } else if (FhirVersionEnum.DSTU2_HL7ORG.isPresentOnClasspath()) { myVersion = FhirVersionEnum.DSTU2_HL7ORG.getVersionImplementation(); + } else if (FhirVersionEnum.DSTU3.isPresentOnClasspath()) { + myVersion = FhirVersionEnum.DSTU3.getVersionImplementation(); } else { throw new IllegalStateException(getLocalizer().getMessage(FhirContext.class, "noStructures")); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextDstu1Test.java index 28dceb55bcd..8589b682011 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextDstu1Test.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextDstu1Test.java @@ -13,6 +13,13 @@ import ca.uhn.fhir.util.TestUtil; public class FhirContextDstu1Test { + @SuppressWarnings("deprecation") + @Test + public void testAutoDetectVersion() { + FhirContext ctx = new FhirContext(); + assertEquals(FhirVersionEnum.DSTU1, ctx.getVersion().getVersion()); + } + @Test public void testIncrementalScan() { FhirContext ctx = FhirContext.forDstu1(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java index a5032c6a712..dcfc551c580 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java @@ -7,6 +7,7 @@ import org.junit.Test; import ca.uhn.fhir.context.BaseRuntimeChildDatatypeDefinition; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum; @@ -30,7 +31,14 @@ public class FhirContextDstu2Test { ctx.getResourceDefinition("InvalidResource"); } + @SuppressWarnings("deprecation") + @Test + public void testAutoDetectVersion() { + FhirContext ctx = new FhirContext(); + assertEquals(FhirVersionEnum.DSTU2, ctx.getVersion().getVersion()); + } + @Test public void testQueryBoundCode() { RuntimeResourceDefinition patientType = ourCtx.getResourceDefinition(Patient.class); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/FhirContextDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/FhirContextDstu3Test.java index a0ba08c9dc4..243d6a0924f 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/FhirContextDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/FhirContextDstu3Test.java @@ -22,6 +22,13 @@ public class FhirContextDstu3Test { TestUtil.clearAllStaticFieldsForUnitTest(); } + @SuppressWarnings("deprecation") + @Test + public void testAutoDetectVersion() { + FhirContext ctx = new FhirContext(); + assertEquals(FhirVersionEnum.DSTU3, ctx.getVersion().getVersion()); + } + /** * See #344 */ diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/context/FhirContextDstu2Hl7OrgTest.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/context/FhirContextDstu2Hl7OrgTest.java new file mode 100644 index 00000000000..b09a9c637e0 --- /dev/null +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/context/FhirContextDstu2Hl7OrgTest.java @@ -0,0 +1,16 @@ +package ca.uhn.fhir.context; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class FhirContextDstu2Hl7OrgTest { + + @SuppressWarnings("deprecation") + @Test + public void testAutoDetectVersion() { + FhirContext ctx = new FhirContext(); + assertEquals(FhirVersionEnum.DSTU2_HL7ORG, ctx.getVersion().getVersion()); + } + +}