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()); + } + +}