fixing tests

This commit is contained in:
leif stawnyczy 2024-08-09 16:47:32 -04:00
parent abb3d40576
commit 3392d3ee61
4 changed files with 15 additions and 1 deletions

View File

@ -115,6 +115,9 @@ public abstract class BaseHttpClientInvocation {
new HttpClientRequestParameters(theParameters.getUrl(), theParameters.getRequestTypeEnum()); new HttpClientRequestParameters(theParameters.getUrl(), theParameters.getRequestTypeEnum());
clientRequestParameters.setEncodingEnum(theParameters.getEncodingEnum()); clientRequestParameters.setEncodingEnum(theParameters.getEncodingEnum());
IHttpRequest request = httpClient.createRequest(clientRequestParameters); IHttpRequest request = httpClient.createRequest(clientRequestParameters);
for (Header h : getHeaders()) {
request.addHeader(h.getName(), h.getValue());
}
httpClient.addHeadersToRequest(request, theParameters.getEncodingEnum(), getContext()); httpClient.addHeadersToRequest(request, theParameters.getEncodingEnum(), getContext());
return request; return request;
} }

View File

@ -23,6 +23,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.api.RequestTypeEnum; 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.IHttpClient;
import ca.uhn.fhir.rest.client.api.IHttpRequest; import ca.uhn.fhir.rest.client.api.IHttpRequest;
import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation;
@ -122,6 +123,9 @@ public class HttpPatchClientInvocation extends BaseHttpClientInvocation {
params.setContentType(myContentType); params.setContentType(myContentType);
params.setFhirContext(getContext()); params.setFhirContext(getContext());
IHttpRequest req = client.createRequest(params); IHttpRequest req = client.createRequest(params);
for (Header h : getHeaders()) {
req.addHeader(h.getName(), h.getValue());
}
client.addHeadersToRequest(req, theParameters.getEncodingEnum(), getContext()); client.addHeadersToRequest(req, theParameters.getEncodingEnum(), getContext());
req.addHeader(Constants.HEADER_CONTENT_TYPE, params.getContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); req.addHeader(Constants.HEADER_CONTENT_TYPE, params.getContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
return req; return req;

View File

@ -19,12 +19,14 @@ import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.SummaryEnum;
import ca.uhn.fhir.rest.client.apache.ApacheHttpRequest; 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.apache.ResourceEntity;
import ca.uhn.fhir.rest.client.api.IBasicClient; import ca.uhn.fhir.rest.client.api.IBasicClient;
import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.api.IRestfulClient; import ca.uhn.fhir.rest.client.api.IRestfulClient;
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException; 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.client.interceptor.CapturingInterceptor;
import ca.uhn.fhir.rest.param.CompositeParam; import ca.uhn.fhir.rest.param.CompositeParam;
import ca.uhn.fhir.rest.param.DateParam; import ca.uhn.fhir.rest.param.DateParam;
@ -108,7 +110,9 @@ public class ClientR4Test {
@BeforeEach @BeforeEach
public void before() { 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()); myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs());
ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient); ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient);
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);

View File

@ -10,6 +10,7 @@ import ca.uhn.fhir.rest.annotation.Validate;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.ValidationModeEnum; 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.IRestfulClient;
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
import ca.uhn.fhir.system.HapiSystemProperties; import ca.uhn.fhir.system.HapiSystemProperties;
@ -54,6 +55,8 @@ public class NonGenericClientR4Test {
@BeforeEach @BeforeEach
public void before() { 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()); myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs());
ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient); ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient);
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);