Skip to content

Commit

Permalink
Migrate Health Insights libraries to test proxy (#35703)
Browse files Browse the repository at this point in the history
* Migrate Health Insights libraries to test proxy

* refactor test base
  • Loading branch information
srnagar authored Jul 11, 2023
1 parent e6ed3b0 commit e1b23ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.azure.health.insights.cancerprofiling;

import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.http.policy.AzureKeyCredentialPolicy;
import com.azure.core.test.TestMode;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.test.models.CustomMatcher;
Expand All @@ -21,17 +20,18 @@
*/
public class CancerProfilingClientTestBase extends TestProxyTestBase {
private static final String FAKE_API_KEY = "fakeKeyPlaceholder";
private static final String OCP_APIM_SUBSCRIPTION_KEY = "Ocp-Apim-Subscription-Key";

void testCancerProfilingWithResponse(Consumer<BinaryData> testRunner) {
testRunner.accept(getOncoPhenotypeRequest());
}

CancerProfilingClientBuilder getClientBuilder() {
String apiKey = Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_API_KEY", FAKE_API_KEY);
String endpoint = Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_ENDPOINT", "https://localhost:8080");

CancerProfilingClientBuilder builder = new CancerProfilingClientBuilder()
.endpoint(getEndpoint())
.addPolicy(new AzureKeyCredentialPolicy(OCP_APIM_SUBSCRIPTION_KEY,
new AzureKeyCredential(getKey())));
.endpoint(endpoint)
.credential(new AzureKeyCredential(apiKey));

if (getTestMode() == TestMode.RECORD) {
builder.addPolicy(interceptorManager.getRecordPolicy());
Expand All @@ -43,20 +43,6 @@ CancerProfilingClientBuilder getClientBuilder() {
return builder;
}

private String getKey() {
if (getTestMode() == TestMode.PLAYBACK) {
return FAKE_API_KEY;
} else {
return Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_API_KEY");
}
}

String getEndpoint() {
return interceptorManager.isPlaybackMode()
? "https://localhost:8080"
: Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_ENDPOINT");
}

private BinaryData getOncoPhenotypeRequest() {
File requestFile = new File(CancerProfilingClientTestBase.class.getResource("/CancerProfilingClientTest.request.json").getPath());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.azure.health.insights.clinicalmatching;

import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.http.policy.AzureKeyCredentialPolicy;
import com.azure.core.test.TestMode;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.test.models.CustomMatcher;
Expand All @@ -15,47 +14,33 @@
import java.util.Arrays;
import java.util.function.Consumer;


/**
* Base class for TM clients test.
*/
public class ClinicalMatchingClientTestBase extends TestProxyTestBase {
private static final String FAKE_API_KEY = "fakeKeyPlaceholder";
private static final String OCP_APIM_SUBSCRIPTION_KEY = "Ocp-Apim-Subscription-Key";

void testTMWithResponse(Consumer<BinaryData> testRunner) {
testRunner.accept(getTMRequest());
}

ClinicalMatchingClientBuilder getClientBuilder() {
String apiKey = Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_API_KEY", FAKE_API_KEY);
String endpoint = Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_ENDPOINT", "https://localhost:8080");

ClinicalMatchingClientBuilder builder = new ClinicalMatchingClientBuilder()
.endpoint(getEndpoint())
.addPolicy(new AzureKeyCredentialPolicy(OCP_APIM_SUBSCRIPTION_KEY,
new AzureKeyCredential(getKey())));
.endpoint(endpoint)
.credential(new AzureKeyCredential(apiKey));
if (getTestMode() == TestMode.RECORD) {
builder.addPolicy(interceptorManager.getRecordPolicy());
} else if (getTestMode() == TestMode.PLAYBACK) {
builder.httpClient(interceptorManager.getPlaybackClient());
interceptorManager.addMatchers(Arrays.asList(new CustomMatcher()
.setHeadersKeyOnlyMatch(Arrays.asList("repeatability-first-sent", "repeatability-request-id"))));
}

return builder;
}

private String getKey() {
if (getTestMode() == TestMode.PLAYBACK) {
return FAKE_API_KEY;
} else {
return Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_API_KEY");
}
}

String getEndpoint() {
return interceptorManager.isPlaybackMode()
? "https://localhost:8080"
: Configuration.getGlobalConfiguration().get("AZURE_HEALTHINSIGHTS_ENDPOINT");
}

private BinaryData getTMRequest() {
File requestFile = new File(ClinicalMatchingClientTestBase.class.getResource("/ClinicalMatchingClientTest.request.json").getPath());
try {
Expand Down

0 comments on commit e1b23ad

Please sign in to comment.