Test fixes

This commit is contained in:
jamesagnew 2020-04-22 14:56:13 -04:00
parent af43c4377a
commit 36a7e9c980
5 changed files with 62 additions and 1 deletions

View File

@ -75,6 +75,10 @@ public class UrlTenantSelectionInterceptor {
}
String requestUri = theRequest.getUri();
String serverBase = theClient.getServerBase();
if (serverBase.endsWith("/")) {
serverBase = serverBase.substring(0, serverBase.length() - 1);
}
Validate.isTrue(requestUri.startsWith(serverBase), "Request URI %s does not start with server base %s", requestUri, serverBase);
String newUri = serverBase + "/" + tenantId + requestUri.substring(serverBase.length());

View File

@ -69,7 +69,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
version.onTable("HFJ_RES_VER").dropColumn("20200218.2", "FORCED_ID_PID");
version.onTable("HFJ_RES_VER").addForeignKey("20200218.3", "FK_RESOURCE_HISTORY_RESOURCE").toColumn("RES_ID").references("HFJ_RESOURCE", "RES_ID");
version.onTable("HFJ_RES_VER").modifyColumn("20200220.1", "RES_ID").nonNullable().failureAllowed().withType(BaseTableColumnTypeTask.ColumnTypeEnum.LONG);
// Drop unused column
version.onTable("HFJ_RESOURCE").dropIndex("20200419.1", "IDX_RES_PROFILE");
version.onTable("HFJ_RESOURCE").dropColumn("20200419.2", "RES_PROFILE");

View File

@ -27,6 +27,7 @@ import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu2;
import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu3;
import ca.uhn.fhir.jpa.config.BaseJavaConfigR4;
import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.provider.BaseJpaProvider;
import ca.uhn.fhir.jpa.provider.BaseJpaSystemProvider;
@ -180,6 +181,14 @@ public class FhirAutoConfiguration {
return fhirDaoConfig;
}
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties("hapi.fhir.jpa")
public PartitionSettings partitionSettings() {
return new PartitionSettings();
}
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties("hapi.fhir.jpa")

View File

@ -84,6 +84,22 @@ public abstract class BaseGenericClientR4Test {
return capt;
}
protected ArgumentCaptor<HttpUriRequest> prepareClientForCapabilityStatement() throws IOException {
final String msg = "{\"resourceType\":\"CapabilityStatement\", \"fhirVersion\":\"4.0.1\"}";
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8);
}
});
return capt;
}
protected ArgumentCaptor<HttpUriRequest> prepareClientForCreateResponse() throws IOException {
final String msg = "{\"resourceType\":\"Patient\",\"id\":\"123\",\"active\":true}";

View File

@ -4,6 +4,7 @@ import ca.uhn.fhir.rest.client.BaseGenericClientR4Test;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.CapabilityStatement;
import org.hl7.fhir.r4.model.Patient;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@ -28,6 +29,37 @@ public class UrlTenantSelectionInterceptorTest extends BaseGenericClientR4Test {
assertEquals("http://example.com/fhir/TENANT-A/Patient/_history", capt.getAllValues().get(0).getURI().toString());
}
@Test
public void testAddTenantToGetAtRoot() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = prepareClientForSearchResponse();
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com:8000");
client.registerInterceptor(new UrlTenantSelectionInterceptor("TENANT-A"));
client
.history()
.onType(Patient.class)
.returnBundle(Bundle.class)
.execute();
assertEquals("http://example.com:8000/TENANT-A/Patient/_history", capt.getAllValues().get(0).getURI().toString());
}
@Test
public void testAddTenantToGetMetadataAtRoot() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = prepareClientForCapabilityStatement();
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com:8000/");
client.registerInterceptor(new UrlTenantSelectionInterceptor("TENANT-A"));
client
.capabilities()
.ofType(CapabilityStatement.class)
.execute();
assertEquals("http://example.com:8000/TENANT-A/metadata", capt.getAllValues().get(0).getURI().toString());
}
@Test
public void testAddTenantToPost() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = prepareClientForCreateResponse();