From 3392d3ee6151ad76d6a14419e51a43fc8e435fd0 Mon Sep 17 00:00:00 2001 From: leif stawnyczy Date: Fri, 9 Aug 2024 16:47:32 -0400 Subject: [PATCH] fixing tests --- .../uhn/fhir/rest/client/impl/BaseHttpClientInvocation.java | 3 +++ .../fhir/rest/client/method/HttpPatchClientInvocation.java | 4 ++++ .../src/test/java/ca/uhn/fhir/rest/client/ClientR4Test.java | 6 +++++- .../ca/uhn/fhir/rest/client/NonGenericClientR4Test.java | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/BaseHttpClientInvocation.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/BaseHttpClientInvocation.java index 42fd870e3d1..2eccca8821e 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/BaseHttpClientInvocation.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/BaseHttpClientInvocation.java @@ -115,6 +115,9 @@ public abstract class BaseHttpClientInvocation { new HttpClientRequestParameters(theParameters.getUrl(), theParameters.getRequestTypeEnum()); clientRequestParameters.setEncodingEnum(theParameters.getEncodingEnum()); IHttpRequest request = httpClient.createRequest(clientRequestParameters); + for (Header h : getHeaders()) { + request.addHeader(h.getName(), h.getValue()); + } httpClient.addHeadersToRequest(request, theParameters.getEncodingEnum(), getContext()); return request; } diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/HttpPatchClientInvocation.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/HttpPatchClientInvocation.java index 2ac4bccdfa2..c84ddb50ece 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/HttpPatchClientInvocation.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/HttpPatchClientInvocation.java @@ -23,6 +23,7 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.client.api.Header; import ca.uhn.fhir.rest.client.api.IHttpClient; import ca.uhn.fhir.rest.client.api.IHttpRequest; import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; @@ -122,6 +123,9 @@ public class HttpPatchClientInvocation extends BaseHttpClientInvocation { params.setContentType(myContentType); params.setFhirContext(getContext()); IHttpRequest req = client.createRequest(params); + for (Header h : getHeaders()) { + req.addHeader(h.getName(), h.getValue()); + } client.addHeadersToRequest(req, theParameters.getEncodingEnum(), getContext()); req.addHeader(Constants.HEADER_CONTENT_TYPE, params.getContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); return req; diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/ClientR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/ClientR4Test.java index a7f3e58a385..5d8b33f2bfe 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/ClientR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/ClientR4Test.java @@ -19,12 +19,14 @@ import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.client.apache.ApacheHttpRequest; +import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory; import ca.uhn.fhir.rest.client.apache.ResourceEntity; import ca.uhn.fhir.rest.client.api.IBasicClient; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.IRestfulClient; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException; +import ca.uhn.fhir.rest.client.impl.RestfulClientFactory; import ca.uhn.fhir.rest.client.interceptor.CapturingInterceptor; import ca.uhn.fhir.rest.param.CompositeParam; import ca.uhn.fhir.rest.param.DateParam; @@ -108,7 +110,9 @@ public class ClientR4Test { @BeforeEach public void before() { - + // we want to reset the client factory so we aren't handing back previously used + // test clients + ourCtx.setRestfulClientFactory(new ApacheRestfulClientFactory(ourCtx)); myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs()); ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient); ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/NonGenericClientR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/NonGenericClientR4Test.java index 047d03f249c..6f70a548327 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/NonGenericClientR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/NonGenericClientR4Test.java @@ -10,6 +10,7 @@ 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.ValidationModeEnum; +import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory; import ca.uhn.fhir.rest.client.api.IRestfulClient; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.system.HapiSystemProperties; @@ -54,6 +55,8 @@ public class NonGenericClientR4Test { @BeforeEach public void before() { + // reset our client factory so we don't reuse test clients + ourCtx.setRestfulClientFactory(new ApacheRestfulClientFactory(ourCtx)); myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs()); ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient); ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);