|
4 | 4 | package com.azure.health.insights.clinicalmatching; |
5 | 5 |
|
6 | 6 | import com.azure.core.credential.AzureKeyCredential; |
7 | | -import com.azure.core.http.policy.AzureKeyCredentialPolicy; |
8 | 7 | import com.azure.core.test.TestMode; |
9 | 8 | import com.azure.core.test.TestProxyTestBase; |
10 | 9 | import com.azure.core.test.models.CustomMatcher; |
|
15 | 14 | import java.util.Arrays; |
16 | 15 | import java.util.function.Consumer; |
17 | 16 |
|
18 | | - |
19 | 17 | /** |
20 | 18 | * Base class for TM clients test. |
21 | 19 | */ |
22 | 20 | public class ClinicalMatchingClientTestBase extends TestProxyTestBase { |
23 | 21 | private static final String FAKE_API_KEY = "fakeKeyPlaceholder"; |
24 | | - private static final String OCP_APIM_SUBSCRIPTION_KEY = "Ocp-Apim-Subscription-Key"; |
| 22 | + |
25 | 23 | void testTMWithResponse(Consumer<BinaryData> testRunner) { |
26 | 24 | testRunner.accept(getTMRequest()); |
27 | 25 | } |
28 | 26 |
|
29 | 27 | ClinicalMatchingClientBuilder getClientBuilder() { |
| 28 | + String apiKey = Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_API_KEY", FAKE_API_KEY); |
| 29 | + String endpoint = Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_ENDPOINT", "https://localhost:8080"); |
| 30 | + |
30 | 31 | ClinicalMatchingClientBuilder builder = new ClinicalMatchingClientBuilder() |
31 | | - .endpoint(getEndpoint()) |
32 | | - .addPolicy(new AzureKeyCredentialPolicy(OCP_APIM_SUBSCRIPTION_KEY, |
33 | | - new AzureKeyCredential(getKey()))); |
| 32 | + .endpoint(endpoint) |
| 33 | + .credential(new AzureKeyCredential(apiKey)); |
34 | 34 | if (getTestMode() == TestMode.RECORD) { |
35 | 35 | builder.addPolicy(interceptorManager.getRecordPolicy()); |
36 | 36 | } else if (getTestMode() == TestMode.PLAYBACK) { |
37 | 37 | builder.httpClient(interceptorManager.getPlaybackClient()); |
38 | 38 | interceptorManager.addMatchers(Arrays.asList(new CustomMatcher() |
39 | 39 | .setHeadersKeyOnlyMatch(Arrays.asList("repeatability-first-sent", "repeatability-request-id")))); |
40 | 40 | } |
41 | | - |
42 | 41 | return builder; |
43 | 42 | } |
44 | 43 |
|
45 | | - private String getKey() { |
46 | | - if (getTestMode() == TestMode.PLAYBACK) { |
47 | | - return FAKE_API_KEY; |
48 | | - } else { |
49 | | - return Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_API_KEY"); |
50 | | - } |
51 | | - } |
52 | | - |
53 | | - String getEndpoint() { |
54 | | - return interceptorManager.isPlaybackMode() |
55 | | - ? "https://localhost:8080" |
56 | | - : Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_ENDPOINT"); |
57 | | - } |
58 | | - |
59 | 44 | private BinaryData getTMRequest() { |
60 | 45 | File requestFile = new File(ClinicalMatchingClientTestBase.class.getResource("/ClinicalMatchingClientTest.request.json").getPath()); |
61 | 46 | try { |
|
0 commit comments