Skip to content

Commit f3c09d6

Browse files
authored
hapi-fhir-storage-cr: Disable conformance validation to speed up storage-cr tests. (hapifhir#6760)
* Disable conformance validation to speed up storage-cr tests. * Code review suggestions.
1 parent 41c2e49 commit f3c09d6

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

hapi-fhir-storage-cr/src/test/java/ca/uhn/fhir/cr/r4/BaseCrR4TestServer.java

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import ca.uhn.fhir.rest.api.EncodingEnum;
2020
import ca.uhn.fhir.rest.api.server.RequestDetails;
2121
import ca.uhn.fhir.rest.client.api.IGenericClient;
22+
import ca.uhn.fhir.rest.client.api.IRestfulClientFactory;
23+
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
24+
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
2225
import ca.uhn.fhir.rest.client.interceptor.SimpleRequestHeaderInterceptor;
2326
import ca.uhn.fhir.rest.server.RestfulServer;
2427
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
@@ -30,15 +33,13 @@
3033
import org.eclipse.jetty.ee10.servlet.ServletHolder;
3134
import org.eclipse.jetty.server.Server;
3235
import org.hl7.fhir.r4.model.Bundle;
33-
import org.hl7.fhir.r4.model.Resource;
3436
import org.junit.jupiter.api.AfterEach;
3537
import org.junit.jupiter.api.BeforeEach;
3638
import org.opencds.cqf.fhir.cql.EvaluationSettings;
3739
import org.springframework.beans.factory.annotation.Autowired;
3840
import org.springframework.mock.web.MockHttpServletRequest;
3941
import org.springframework.test.context.ContextConfiguration;
4042

41-
import java.util.List;
4243
import java.util.concurrent.TimeUnit;
4344

4445

@@ -63,8 +64,6 @@ public abstract class BaseCrR4TestServer extends BaseJpaR4Test implements IResou
6364
public static IParser ourParser;
6465

6566

66-
//@Autowired
67-
//ApplicationContext myApplicationContext;
6867
private SimpleRequestHeaderInterceptor mySimpleHeaderInterceptor;
6968

7069
@Autowired
@@ -108,20 +107,16 @@ public void beforeStartServer() throws Exception {
108107
builder.setConnectionManager(connectionManager);
109108
ourHttpClient = builder.build();
110109

111-
ourCtx.getRestfulClientFactory().setSocketTimeout(600 * 1000);
112-
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
113-
ourClient.setLogRequestAndResponse(true);
114-
115110
ourParser = ourCtx.newJsonParser().setPrettyPrint(true);
116111

117112
ourRestfulServer.setDefaultResponseEncoding(EncodingEnum.XML);
118113
ourPagingProvider = myAppCtx.getBean(DatabaseBackedPagingProvider.class);
119114
ourRestfulServer.setPagingProvider(ourPagingProvider);
120115

121116
mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor();
122-
ourClient.registerInterceptor(mySimpleHeaderInterceptor);
123117
myStorageSettings.setIndexMissingFields(JpaStorageSettings.IndexEnabledEnum.DISABLED);
124118

119+
ourClient = initClient(mySimpleHeaderInterceptor);
125120
}
126121

127122
@Override
@@ -139,23 +134,6 @@ public void loadBundle(String theLocation) {
139134
ourClient.transaction().withBundle(bundy).execute();
140135
}
141136

142-
143-
public Bundle makeBundle(List<? extends Resource> theResources) {
144-
return makeBundle(theResources.toArray(new Resource[theResources.size()]));
145-
}
146-
147-
public Bundle makeBundle(Resource... theResources) {
148-
Bundle bundle = new Bundle();
149-
bundle.setType(Bundle.BundleType.SEARCHSET);
150-
bundle.setTotal(theResources != null ? theResources.length : 0);
151-
if (theResources != null) {
152-
for (Resource l : theResources) {
153-
bundle.addEntry().setResource(l).setFullUrl("/" + l.fhirType() + "/" + l.getId());
154-
}
155-
}
156-
return bundle;
157-
}
158-
159137
protected RequestDetails setupRequestDetails() {
160138
var requestDetails = new ServletRequestDetails();
161139
requestDetails.setServletRequest(new MockHttpServletRequest());
@@ -164,4 +142,21 @@ protected RequestDetails setupRequestDetails() {
164142
return requestDetails;
165143
}
166144

145+
private static IGenericClient initClient(SimpleRequestHeaderInterceptor simpleHeaderInterceptor) {
146+
final IRestfulClientFactory restfulClientFactory = ourCtx.getRestfulClientFactory();
147+
148+
restfulClientFactory.setServerValidationMode(ServerValidationModeEnum.NEVER);
149+
restfulClientFactory.setSocketTimeout(600 * 1000);
150+
151+
final IGenericClient genericClient = restfulClientFactory.newGenericClient(ourServerBase);
152+
153+
var loggingInterceptor = new LoggingInterceptor();
154+
loggingInterceptor.setLogRequestBody(true);
155+
loggingInterceptor.setLogResponseBody(true);
156+
157+
genericClient.registerInterceptor(loggingInterceptor);
158+
genericClient.registerInterceptor(simpleHeaderInterceptor);
159+
160+
return genericClient;
161+
}
167162
}

0 commit comments

Comments
 (0)