Search in sources :

Example 6 with DefaultFhirClientBuilder

use of com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder in project quality-measure-and-cohort-service by Alvearie.

the class FHIRRestUtilsTest method testParseNoUserPassAuthenticationHeaderStrInfo.

@PrepareForTest({ FHIRRestUtils.class, DefaultFhirClientBuilder.class })
@Test(expected = IllegalArgumentException.class)
public void testParseNoUserPassAuthenticationHeaderStrInfo() throws Exception {
    DefaultFhirClientBuilder mockDefaultFhirClientBuilder = Mockito.mock(DefaultFhirClientBuilder.class);
    PowerMockito.whenNew(DefaultFhirClientBuilder.class).withAnyArguments().thenReturn(mockDefaultFhirClientBuilder);
    when(mockHttpHeaders.getRequestHeader(HttpHeaders.AUTHORIZATION)).thenReturn(noUserPassHttpHeadersList);
    FHIRRestUtils.parseAuthenticationHeaderInfo(mockHttpHeaders);
}
Also used : DefaultFhirClientBuilder(com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with DefaultFhirClientBuilder

use of com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder in project quality-measure-and-cohort-service by Alvearie.

the class FHIRRestUtilsTest method testParseNUllAuthenticationHeaderInfo.

@PrepareForTest({ FHIRRestUtils.class, DefaultFhirClientBuilder.class })
@Test(expected = IllegalArgumentException.class)
public void testParseNUllAuthenticationHeaderInfo() throws Exception {
    DefaultFhirClientBuilder mockDefaultFhirClientBuilder = Mockito.mock(DefaultFhirClientBuilder.class);
    PowerMockito.whenNew(DefaultFhirClientBuilder.class).withAnyArguments().thenReturn(mockDefaultFhirClientBuilder);
    when(mockHttpHeaders.getRequestHeader(HttpHeaders.AUTHORIZATION)).thenReturn(nullHttpHeadersList);
    FHIRRestUtils.parseAuthenticationHeaderInfo(mockHttpHeaders);
}
Also used : DefaultFhirClientBuilder(com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with DefaultFhirClientBuilder

use of com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder in project quality-measure-and-cohort-service by Alvearie.

the class FHIRRestUtilsTest method testParseEmptyAuthenticationHeaderStrInfo.

@PrepareForTest({ FHIRRestUtils.class, DefaultFhirClientBuilder.class })
@Test(expected = IllegalArgumentException.class)
public void testParseEmptyAuthenticationHeaderStrInfo() throws Exception {
    DefaultFhirClientBuilder mockDefaultFhirClientBuilder = Mockito.mock(DefaultFhirClientBuilder.class);
    PowerMockito.whenNew(DefaultFhirClientBuilder.class).withAnyArguments().thenReturn(mockDefaultFhirClientBuilder);
    when(mockHttpHeaders.getRequestHeader(HttpHeaders.AUTHORIZATION)).thenReturn(emptyStrHttpHeadersList);
    FHIRRestUtils.parseAuthenticationHeaderInfo(mockHttpHeaders);
}
Also used : DefaultFhirClientBuilder(com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with DefaultFhirClientBuilder

use of com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder in project quality-measure-and-cohort-service by Alvearie.

the class FHIRRestUtilsTest method testParseAuthenticationHeaderBadPasswordInfo.

@PrepareForTest({ FHIRRestUtils.class, DefaultFhirClientBuilder.class })
@Test(expected = IllegalArgumentException.class)
public void testParseAuthenticationHeaderBadPasswordInfo() throws Exception {
    DefaultFhirClientBuilder mockDefaultFhirClientBuilder = Mockito.mock(DefaultFhirClientBuilder.class);
    PowerMockito.whenNew(DefaultFhirClientBuilder.class).withAnyArguments().thenReturn(mockDefaultFhirClientBuilder);
    when(mockHttpHeaders.getRequestHeader(HttpHeaders.AUTHORIZATION)).thenReturn(badHttpHeadersList);
    FHIRRestUtils.parseAuthenticationHeaderInfo(mockHttpHeaders);
}
Also used : DefaultFhirClientBuilder(com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with DefaultFhirClientBuilder

use of com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder in project quality-measure-and-cohort-service by Alvearie.

the class FHIRRestUtils method getFHIRClient.

/**
 * @param fhirEndpoint The REST endpoint for the FHIR server
 * @param bearerToken OAuth token value
 * @param fhirTenantIdHeader the header used by FHIR to identify the tenant
 * @param fhirTenantId the actual FHIR tenant id
 * @param fhirDataSourceIdHeader The header used by FHIR to identify the datasource
 * @param fhirDataSourceId the actual FHIR datasource name
 * @return IGenericClient A client that can be used to make calls to the FHIR server
 *
 * Convenience method to get a FHIR client
 */
public static IGenericClient getFHIRClient(String fhirEndpoint, String bearerToken, String fhirTenantIdHeader, String fhirTenantId, String fhirDataSourceIdHeader, String fhirDataSourceId) {
    IBMFhirServerConfig config = getPartialFHIRConfig(fhirEndpoint, fhirTenantIdHeader, fhirTenantId, fhirDataSourceIdHeader, fhirDataSourceId);
    config.setToken(bearerToken);
    FhirContext ctx = FhirContext.forR4();
    DefaultFhirClientBuilder builder = new DefaultFhirClientBuilder(ctx);
    return builder.createFhirClient(config);
}
Also used : IBMFhirServerConfig(com.ibm.cohort.fhir.client.config.IBMFhirServerConfig) FhirContext(ca.uhn.fhir.context.FhirContext) DefaultFhirClientBuilder(com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder)

Aggregations

DefaultFhirClientBuilder (com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder)12 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)4 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 Enumerations (org.hl7.fhir.r4.model.Enumerations)2 Patient (org.hl7.fhir.r4.model.Patient)2 IBMFhirServerConfig (com.ibm.cohort.fhir.client.config.IBMFhirServerConfig)1 After (org.junit.After)1