Search in sources :

Example 1 with DefaultFhirClientBuilder

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

the class FhirClientTimeoutTest method testDefaultFhirClientBuilder_requestTimesOut.

@Test(expected = FhirClientConnectionException.class)
public void testDefaultFhirClientBuilder_requestTimesOut() {
    FhirServerConfig fhirServerConfig = getFhirServerConfig();
    fhirServerConfig.setSocketTimeout(CONFIG_TIMEOUT_MILLIS);
    DefaultFhirClientBuilder builder = new DefaultFhirClientBuilder(fhirContext);
    IGenericClient client = builder.createFhirClient(fhirServerConfig);
    client.read().resource(Patient.class).withId(PATIENT_ID).execute();
}
Also used : DefaultFhirClientBuilder(com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) Test(org.junit.Test)

Example 2 with DefaultFhirClientBuilder

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

the class DefaultVT method cleanUp.

@After
public void cleanUp() {
    // get the fhir client object used to call to FHIR
    FhirContext ctx = FhirContext.forR4();
    DefaultFhirClientBuilder builder = new DefaultFhirClientBuilder(ctx);
    IGenericClient terminologyClient = builder.createFhirClient(dataServerConfig);
    terminologyClient.delete().resourceConditionalByType("ValueSet").where(ValueSet.URL.matches().value("http://cts.nlm.nih.gov/fhir/ValueSet/testValueSet")).execute();
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) DefaultFhirClientBuilder(com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) After(org.junit.After)

Example 3 with DefaultFhirClientBuilder

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

the class FHIRRestUtilsTest method testParseEmptyAuthenticationHeaderInfo.

@PrepareForTest({ FHIRRestUtils.class, DefaultFhirClientBuilder.class })
@Test(expected = IllegalArgumentException.class)
public void testParseEmptyAuthenticationHeaderInfo() throws Exception {
    DefaultFhirClientBuilder mockDefaultFhirClientBuilder = Mockito.mock(DefaultFhirClientBuilder.class);
    PowerMockito.whenNew(DefaultFhirClientBuilder.class).withAnyArguments().thenReturn(mockDefaultFhirClientBuilder);
    when(mockHttpHeaders.getRequestHeader(HttpHeaders.AUTHORIZATION)).thenReturn(emptyHttpHeadersList);
    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 4 with DefaultFhirClientBuilder

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

the class FHIRRestUtilsTest method testParseAuthenticationHeaderInfo.

@PrepareForTest({ FHIRRestUtils.class, DefaultFhirClientBuilder.class })
@Test
public void testParseAuthenticationHeaderInfo() throws Exception {
    DefaultFhirClientBuilder mockDefaultFhirClientBuilder = Mockito.mock(DefaultFhirClientBuilder.class);
    PowerMockito.whenNew(DefaultFhirClientBuilder.class).withAnyArguments().thenReturn(mockDefaultFhirClientBuilder);
    when(mockHttpHeaders.getRequestHeader(HttpHeaders.AUTHORIZATION)).thenReturn(httpHeadersList);
    String[] authParts = FHIRRestUtils.parseAuthenticationHeaderInfo(mockHttpHeaders);
    assertEquals("username", authParts[0]);
    assertEquals("password", authParts[1]);
}
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 5 with DefaultFhirClientBuilder

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

the class FHIRRestUtilsTest method testParseAuthenticationHeaderMissingPasswordInfo.

@PrepareForTest({ FHIRRestUtils.class, DefaultFhirClientBuilder.class })
@Test(expected = IllegalArgumentException.class)
public void testParseAuthenticationHeaderMissingPasswordInfo() throws Exception {
    DefaultFhirClientBuilder mockDefaultFhirClientBuilder = Mockito.mock(DefaultFhirClientBuilder.class);
    PowerMockito.whenNew(DefaultFhirClientBuilder.class).withAnyArguments().thenReturn(mockDefaultFhirClientBuilder);
    when(mockHttpHeaders.getRequestHeader(HttpHeaders.AUTHORIZATION)).thenReturn(justUserNameHttpHeadersList);
    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)

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