From 27cac16de6e3035d782ce3f184a2e3631bca6b8c Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 1 Mar 2021 13:54:21 -0500 Subject: [PATCH 1/4] Add custom mimetypes to capability statement --- .../java/ca/uhn/fhir/rest/api/Constants.java | 6 +++++ .../ServerCapabilityStatementProvider.java | 2 ++ ...rCapabilityStatementProviderDstu3Test.java | 24 +++++++++++++++++++ .../ServerCapabilityStatementProvider.java | 2 ++ ...rverCapabilityStatementProviderR4Test.java | 24 +++++++++++++++++++ .../ServerCapabilityStatementProvider.java | 2 ++ ...rverCapabilityStatementProviderR5Test.java | 24 +++++++++++++++++++ 7 files changed, 84 insertions(+) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java index 06b3d4b897d..d4adbe611f1 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java @@ -59,6 +59,12 @@ public class Constants { */ public static final String CT_FHIR_JSON_NEW = "application/fhir+json"; public static final String CT_FHIR_XML = "application/xml+fhir"; + + /** + * Special Conformance Formats that don't follow normal mediatype rules + */ + public static final String CT_JSON_RAW = "json"; + public static final String CT_XML_RAW = "xml"; /** * The FHIR MimeType for XML encoding in FHIR DSTU3+ */ diff --git a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProvider.java b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProvider.java index 7860e22528a..e310cbd1afd 100644 --- a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProvider.java +++ b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProvider.java @@ -224,6 +224,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState retVal.getSoftware().setVersion(serverConfiguration.getServerVersion()); retVal.addFormat(Constants.CT_FHIR_XML_NEW); retVal.addFormat(Constants.CT_FHIR_JSON_NEW); + retVal.addFormat(Constants.CT_JSON_RAW); + retVal.addFormat(Constants.CT_XML_RAW); retVal.setStatus(PublicationStatus.ACTIVE); CapabilityStatementRestComponent rest = retVal.addRest(); diff --git a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProviderDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProviderDstu3Test.java index a1d76a9cd76..0e76ea984f2 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProviderDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProviderDstu3Test.java @@ -6,6 +6,7 @@ import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.api.server.IBundleProvider; @@ -47,17 +48,20 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import javax.servlet.ServletConfig; +import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; @@ -172,6 +176,26 @@ public class ServerCapabilityStatementProviderDstu3Test { assertTrue(res.getConditionalUpdate()); } + @Test + public void testFormatIncludesSpecialNonMediaTypeFormats() throws ServletException { + RestfulServer rs = new RestfulServer(ourCtx); + rs.setProviders(new SearchProvider()); + + ServerCapabilityStatementProvider sc = new ServerCapabilityStatementProvider(); + rs.setServerConformanceProvider(sc); + + rs.init(createServletConfig()); + CapabilityStatement serverConformance = sc.getServerConformance(createHttpServletRequest(), createRequestDetails(rs)); + + List formatCodes = serverConformance.getFormat().stream().map(c -> c.asStringValue()).collect(Collectors.toList());; + + assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_JSON_RAW)); + assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_XML_RAW)); + assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_FHIR_JSON_NEW)); + assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW)); + } + + @Test public void testExtendedOperationReturningBundle() throws Exception { diff --git a/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/ServerCapabilityStatementProvider.java b/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/ServerCapabilityStatementProvider.java index d3251d192b9..e2f3e6b75ac 100644 --- a/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/ServerCapabilityStatementProvider.java +++ b/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/ServerCapabilityStatementProvider.java @@ -172,6 +172,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState retVal.getSoftware().setVersion(configuration.getServerVersion()); retVal.addFormat(Constants.CT_FHIR_XML_NEW); retVal.addFormat(Constants.CT_FHIR_JSON_NEW); + retVal.addFormat(Constants.CT_JSON_RAW); + retVal.addFormat(Constants.CT_XML_RAW); retVal.setStatus(PublicationStatus.ACTIVE); CapabilityStatementRestComponent rest = retVal.addRest(); diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR4Test.java index b57ef040bf7..130f936a002 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR4Test.java @@ -20,6 +20,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.annotation.Validate; +import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.api.server.IBundleProvider; @@ -40,6 +41,7 @@ import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.ValidationResult; import com.google.common.collect.Lists; +import org.eclipse.jetty.server.Server; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.hapi.rest.server.ServerCapabilityStatementProvider; import org.hl7.fhir.r4.model.Bundle; @@ -67,6 +69,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; import javax.servlet.ServletConfig; +import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Collection; @@ -79,6 +82,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; @@ -525,6 +529,26 @@ public class ServerCapabilityStatementProviderR4Test { } + + @Test + public void testFormatIncludesSpecialNonMediaTypeFormats() throws ServletException { + RestfulServer rs = new RestfulServer(ourCtx); + rs.setProviders(new SearchProvider()); + + ServerCapabilityStatementProvider sc = new ServerCapabilityStatementProvider(); + rs.setServerConformanceProvider(sc); + + rs.init(createServletConfig()); + CapabilityStatement serverConformance = sc.getServerConformance(createHttpServletRequest(), createRequestDetails(rs)); + + List formatCodes = serverConformance.getFormat().stream().map(c -> c.getCode()).collect(Collectors.toList());; + + assertThat(formatCodes, hasItem(Constants.CT_JSON_RAW)); + assertThat(formatCodes, hasItem(Constants.CT_XML_RAW)); + assertThat(formatCodes, hasItem(Constants.CT_FHIR_JSON_NEW)); + assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW)); + } + /** * See #286 */ diff --git a/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/ServerCapabilityStatementProvider.java b/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/ServerCapabilityStatementProvider.java index 2aef5be2882..bfcebaf073c 100644 --- a/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/ServerCapabilityStatementProvider.java +++ b/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/ServerCapabilityStatementProvider.java @@ -184,6 +184,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState retVal.getSoftware().setVersion(configuration.getServerVersion()); retVal.addFormat(Constants.CT_FHIR_XML_NEW); retVal.addFormat(Constants.CT_FHIR_JSON_NEW); + retVal.addFormat(Constants.CT_JSON_RAW); + retVal.addFormat(Constants.CT_XML_RAW); retVal.setStatus(PublicationStatus.ACTIVE); CapabilityStatementRestComponent rest = retVal.addRest(); diff --git a/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR5Test.java b/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR5Test.java index 758b1361672..08ee00e175f 100644 --- a/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR5Test.java +++ b/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR5Test.java @@ -6,6 +6,7 @@ import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.api.server.IBundleProvider; @@ -42,17 +43,20 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import javax.servlet.ServletConfig; +import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; @@ -197,6 +201,26 @@ public class ServerCapabilityStatementProviderR5Test { assertThat(conf, containsString("")); } + @Test + public void testFormatIncludesSpecialNonMediaTypeFormats() throws ServletException { + RestfulServer rs = new RestfulServer(ourCtx); + rs.setProviders(new SearchProvider()); + + ServerCapabilityStatementProvider sc = new ServerCapabilityStatementProvider(); + rs.setServerConformanceProvider(sc); + + rs.init(createServletConfig()); + CapabilityStatement serverConformance = sc.getServerConformance(createHttpServletRequest(), createRequestDetails(rs)); + + List formatCodes = serverConformance.getFormat().stream().map(c -> c.getCode()).collect(Collectors.toList());; + + assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_JSON_RAW)); + assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_XML_RAW)); + assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_FHIR_JSON_NEW)); + assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW)); + } + + @Test public void testMultiOptionalDocumentation() throws Exception { From 9dd42fa605c569d330304a70fdf24ad1fdd4ce14 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 1 Mar 2021 14:00:20 -0500 Subject: [PATCH 2/4] Remove duplicate constant --- .../src/main/java/ca/uhn/fhir/rest/api/Constants.java | 6 +----- .../hapi/rest/server/ServerCapabilityStatementProvider.java | 4 ++-- .../server/ServerCapabilityStatementProviderDstu3Test.java | 6 +++--- .../hapi/rest/server/ServerCapabilityStatementProvider.java | 4 ++-- .../server/ServerCapabilityStatementProviderR4Test.java | 6 +++--- .../hapi/rest/server/ServerCapabilityStatementProvider.java | 4 ++-- .../server/ServerCapabilityStatementProviderR5Test.java | 6 +++--- 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java index d4adbe611f1..1961ded8c12 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java @@ -60,11 +60,7 @@ public class Constants { public static final String CT_FHIR_JSON_NEW = "application/fhir+json"; public static final String CT_FHIR_XML = "application/xml+fhir"; - /** - * Special Conformance Formats that don't follow normal mediatype rules - */ - public static final String CT_JSON_RAW = "json"; - public static final String CT_XML_RAW = "xml"; + /** * The FHIR MimeType for XML encoding in FHIR DSTU3+ */ diff --git a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProvider.java b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProvider.java index e310cbd1afd..c01caf7a9db 100644 --- a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProvider.java +++ b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProvider.java @@ -224,8 +224,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState retVal.getSoftware().setVersion(serverConfiguration.getServerVersion()); retVal.addFormat(Constants.CT_FHIR_XML_NEW); retVal.addFormat(Constants.CT_FHIR_JSON_NEW); - retVal.addFormat(Constants.CT_JSON_RAW); - retVal.addFormat(Constants.CT_XML_RAW); + retVal.addFormat(Constants.FORMAT_JSON); + retVal.addFormat(Constants.FORMAT_XML); retVal.setStatus(PublicationStatus.ACTIVE); CapabilityStatementRestComponent rest = retVal.addRest(); diff --git a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProviderDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProviderDstu3Test.java index 0e76ea984f2..7de10333d3f 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProviderDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerCapabilityStatementProviderDstu3Test.java @@ -189,9 +189,9 @@ public class ServerCapabilityStatementProviderDstu3Test { List formatCodes = serverConformance.getFormat().stream().map(c -> c.asStringValue()).collect(Collectors.toList());; - assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_JSON_RAW)); - assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_XML_RAW)); - assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_FHIR_JSON_NEW)); + assertThat(formatCodes, hasItem(Constants.FORMAT_XML)); + assertThat(formatCodes, hasItem(Constants.FORMAT_JSON)); + assertThat(formatCodes, hasItem(Constants.CT_FHIR_JSON_NEW)); assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW)); } diff --git a/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/ServerCapabilityStatementProvider.java b/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/ServerCapabilityStatementProvider.java index e2f3e6b75ac..fd72529be18 100644 --- a/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/ServerCapabilityStatementProvider.java +++ b/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/ServerCapabilityStatementProvider.java @@ -172,8 +172,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState retVal.getSoftware().setVersion(configuration.getServerVersion()); retVal.addFormat(Constants.CT_FHIR_XML_NEW); retVal.addFormat(Constants.CT_FHIR_JSON_NEW); - retVal.addFormat(Constants.CT_JSON_RAW); - retVal.addFormat(Constants.CT_XML_RAW); + retVal.addFormat(Constants.FORMAT_JSON); + retVal.addFormat(Constants.FORMAT_XML); retVal.setStatus(PublicationStatus.ACTIVE); CapabilityStatementRestComponent rest = retVal.addRest(); diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR4Test.java index 130f936a002..67aa2155d86 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR4Test.java @@ -541,10 +541,10 @@ public class ServerCapabilityStatementProviderR4Test { rs.init(createServletConfig()); CapabilityStatement serverConformance = sc.getServerConformance(createHttpServletRequest(), createRequestDetails(rs)); - List formatCodes = serverConformance.getFormat().stream().map(c -> c.getCode()).collect(Collectors.toList());; + List formatCodes = serverConformance.getFormat().stream().map(c -> c.getCode()).collect(Collectors.toList()); - assertThat(formatCodes, hasItem(Constants.CT_JSON_RAW)); - assertThat(formatCodes, hasItem(Constants.CT_XML_RAW)); + assertThat(formatCodes, hasItem(Constants.FORMAT_XML)); + assertThat(formatCodes, hasItem(Constants.FORMAT_JSON)); assertThat(formatCodes, hasItem(Constants.CT_FHIR_JSON_NEW)); assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW)); } diff --git a/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/ServerCapabilityStatementProvider.java b/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/ServerCapabilityStatementProvider.java index bfcebaf073c..5fd5eaa56fb 100644 --- a/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/ServerCapabilityStatementProvider.java +++ b/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/rest/server/ServerCapabilityStatementProvider.java @@ -184,8 +184,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState retVal.getSoftware().setVersion(configuration.getServerVersion()); retVal.addFormat(Constants.CT_FHIR_XML_NEW); retVal.addFormat(Constants.CT_FHIR_JSON_NEW); - retVal.addFormat(Constants.CT_JSON_RAW); - retVal.addFormat(Constants.CT_XML_RAW); + retVal.addFormat(Constants.FORMAT_JSON); + retVal.addFormat(Constants.FORMAT_XML); retVal.setStatus(PublicationStatus.ACTIVE); CapabilityStatementRestComponent rest = retVal.addRest(); diff --git a/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR5Test.java b/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR5Test.java index 08ee00e175f..1780bc2df1e 100644 --- a/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR5Test.java +++ b/hapi-fhir-structures-r5/src/test/java/ca/uhn/fhir/rest/server/ServerCapabilityStatementProviderR5Test.java @@ -214,9 +214,9 @@ public class ServerCapabilityStatementProviderR5Test { List formatCodes = serverConformance.getFormat().stream().map(c -> c.getCode()).collect(Collectors.toList());; - assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_JSON_RAW)); - assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_XML_RAW)); - assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_FHIR_JSON_NEW)); + assertThat(formatCodes, hasItem(Constants.FORMAT_XML)); + assertThat(formatCodes, hasItem(Constants.FORMAT_JSON)); + assertThat(formatCodes, hasItem(Constants.CT_FHIR_JSON_NEW)); assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW)); } From 11b413ee9b380de98dcbea5ba37ad5347e7efc5a Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 1 Mar 2021 14:19:20 -0500 Subject: [PATCH 3/4] Rework tests which relied on old behaviour --- .../ca/uhn/fhir/rest/server/ServerMimetypeDstu2_1Test.java | 3 ++- .../java/ca/uhn/fhir/rest/server/ServerMimetypeDstu3Test.java | 3 ++- .../java/ca/uhn/fhir/rest/server/ServerMimetypeR4Test.java | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu2_1Test.java b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu2_1Test.java index d05ff004a33..cc43d3e631d 100644 --- a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu2_1Test.java +++ b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu2_1Test.java @@ -47,6 +47,7 @@ import java.util.concurrent.TimeUnit; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -67,7 +68,7 @@ public class ServerMimetypeDstu2_1Test { ourLog.info(content); Conformance conf = ourCtx.newXmlParser().parseResource(Conformance.class, content); List strings = toStrings(conf.getFormat()); - assertThat(strings, contains(Constants.CT_FHIR_XML, Constants.CT_FHIR_JSON)); + assertThat(strings, hasItems(Constants.CT_FHIR_XML_NEW, Constants.CT_FHIR_JSON_NEW, Constants.FORMAT_XML, Constants.FORMAT_JSON)); } finally { status.close(); } diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu3Test.java index f5521cae112..46dd7e913d9 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu3Test.java @@ -47,6 +47,7 @@ import java.util.concurrent.TimeUnit; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -66,7 +67,7 @@ public class ServerMimetypeDstu3Test { String content = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); CapabilityStatement conf = ourCtx.newXmlParser().parseResource(CapabilityStatement.class, content); List strings = toStrings(conf.getFormat()); - assertThat(strings, contains(Constants.CT_FHIR_XML_NEW, Constants.CT_FHIR_JSON_NEW)); + assertThat(strings, hasItems(Constants.CT_FHIR_XML_NEW, Constants.CT_FHIR_JSON_NEW, Constants.FORMAT_XML, Constants.FORMAT_JSON)); } finally { status.close(); } diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeR4Test.java index 8a6acea2196..7c1406fa6c6 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeR4Test.java @@ -49,6 +49,7 @@ import java.util.concurrent.TimeUnit; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -85,12 +86,13 @@ public class ServerMimetypeR4Test { String content = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); CapabilityStatement conf = ourCtx.newXmlParser().parseResource(CapabilityStatement.class, content); List strings = toStrings(conf.getFormat()); - assertThat(strings, contains(Constants.CT_FHIR_XML_NEW, Constants.CT_FHIR_JSON_NEW)); + assertThat(strings, hasItems(Constants.CT_FHIR_XML_NEW, Constants.CT_FHIR_JSON_NEW, Constants.FORMAT_XML, Constants.FORMAT_JSON)); } finally { status.close(); } } + @Test public void testCreateWithJsonLegacyNoAcceptHeader() throws Exception { Patient p = new Patient(); From 713a526ae3e61ebe095fa1102591760ac0e9b9d9 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 1 Mar 2021 14:58:50 -0500 Subject: [PATCH 4/4] Reset DSTU2 test --- .../ca/uhn/fhir/rest/server/ServerMimetypeDstu2_1Test.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu2_1Test.java b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu2_1Test.java index cc43d3e631d..d05ff004a33 100644 --- a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu2_1Test.java +++ b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu2_1Test.java @@ -47,7 +47,6 @@ import java.util.concurrent.TimeUnit; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -68,7 +67,7 @@ public class ServerMimetypeDstu2_1Test { ourLog.info(content); Conformance conf = ourCtx.newXmlParser().parseResource(Conformance.class, content); List strings = toStrings(conf.getFormat()); - assertThat(strings, hasItems(Constants.CT_FHIR_XML_NEW, Constants.CT_FHIR_JSON_NEW, Constants.FORMAT_XML, Constants.FORMAT_JSON)); + assertThat(strings, contains(Constants.CT_FHIR_XML, Constants.CT_FHIR_JSON)); } finally { status.close(); }