Skip to content

Commit

Permalink
[Communication - Job] Migrate to Test proxy (#35688)
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity authored Jul 6, 2023
1 parent 7baeb72 commit a09c380
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 1,142 deletions.
6 changes: 6 additions & 0 deletions sdk/communication/azure-communication-jobrouter/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/communication/azure-communication-jobrouter",
"Tag": "java/communication/azure-communication-jobrouter_85c8602573"
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public final class JobRouterAdministrationsImpl {
@ServiceInterface(name = "AzureCommunicationSe")
public interface JobRouterAdministrationsService {
@Patch("/routing/classificationPolicies/{id}")
@ExpectedResponses({200})
@ExpectedResponses({200, 201})
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
Mono<Response<ClassificationPolicy>> upsertClassificationPolicy(
@HostParam("endpoint") String endpoint,
Expand Down Expand Up @@ -110,7 +110,7 @@ Mono<Response<ClassificationPolicyCollection>> listClassificationPolicies(
Context context);

@Patch("/routing/distributionPolicies/{id}")
@ExpectedResponses({200})
@ExpectedResponses({200, 201})
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
Mono<Response<DistributionPolicy>> upsertDistributionPolicy(
@HostParam("endpoint") String endpoint,
Expand Down Expand Up @@ -151,7 +151,7 @@ Mono<Response<DistributionPolicyCollection>> listDistributionPolicies(
Context context);

@Patch("/routing/exceptionPolicies/{id}")
@ExpectedResponses({200})
@ExpectedResponses({200, 201})
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
Mono<Response<ExceptionPolicy>> upsertExceptionPolicy(
@HostParam("endpoint") String endpoint,
Expand Down Expand Up @@ -192,7 +192,7 @@ Mono<Response<ExceptionPolicyCollection>> listExceptionPolicies(
Context context);

@Patch("/routing/queues/{id}")
@ExpectedResponses({200})
@ExpectedResponses({200, 201})
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
Mono<Response<JobQueue>> upsertQueue(
@HostParam("endpoint") String endpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public final class JobRoutersImpl {
@ServiceInterface(name = "AzureCommunicationSe")
public interface JobRoutersService {
@Patch("/routing/jobs/{id}")
@ExpectedResponses({200})
@ExpectedResponses({200, 201})
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
Mono<Response<RouterJob>> upsertJob(
@HostParam("endpoint") String endpoint,
Expand Down Expand Up @@ -215,7 +215,7 @@ Mono<Response<QueueStatistics>> getQueueStatistics(
Context context);

@Patch("/routing/workers/{workerId}")
@ExpectedResponses({200})
@ExpectedResponses({200, 201})
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
Mono<Response<RouterWorker>> upsertWorker(
@HostParam("endpoint") String endpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
import com.azure.communication.common.implementation.HmacAuthenticationPolicy;
import com.azure.communication.jobrouter.models.DistributionPolicy;
import com.azure.communication.jobrouter.models.JobQueue;
import com.azure.communication.jobrouter.models.LabelOperator;
import com.azure.communication.jobrouter.models.LabelValue;
import com.azure.communication.jobrouter.models.LongestIdleMode;
import com.azure.communication.jobrouter.models.RouterJob;
import com.azure.communication.jobrouter.models.WorkerSelector;
import com.azure.communication.jobrouter.models.options.CreateDistributionPolicyOptions;
import com.azure.communication.jobrouter.models.options.CreateJobOptions;
import com.azure.communication.jobrouter.models.options.CreateQueueOptions;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.http.HttpClient;
Expand All @@ -27,17 +23,19 @@
import com.azure.core.http.policy.HttpPolicyProviders;
import com.azure.core.http.policy.RequestIdPolicy;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.test.models.CustomMatcher;
import com.azure.core.util.Configuration;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

class JobRouterTestBase extends TestBase {
class JobRouterTestBase extends TestProxyTestBase {
protected static final String JAVA_LIVE_TESTS = "JAVA_LIVE_TESTS";

protected String getConnectionString() {
Expand Down Expand Up @@ -86,17 +84,25 @@ private HttpPipeline buildHttpPipeline(HttpClient httpClient) {

if (interceptorManager.isPlaybackMode()) {
httpClient = interceptorManager.getPlaybackClient();
addMatchers();
}
if (interceptorManager.isRecordMode()) {
policies.add(interceptorManager.getRecordPolicy());
}
policies.add(interceptorManager.getRecordPolicy());

HttpPipeline pipeline = new HttpPipelineBuilder()
.policies(policies.toArray(new HttpPipelinePolicy[0]))
.httpClient(httpClient)
.httpClient(interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient() : httpClient)
.build();

return pipeline;
}

private void addMatchers() {
interceptorManager.addMatchers(Arrays.asList(new CustomMatcher().setHeadersKeyOnlyMatch(
Arrays.asList("x-ms-hmac-string-to-sign-base64"))));
}

protected JobQueue createQueue(RouterAdministrationClient routerAdminClient, String queueId, String distributionPolicyId) {
String queueName = String.format("%s-Name", queueId);
Map<String, LabelValue> queueLabels = new HashMap<String, LabelValue>() {
Expand Down Expand Up @@ -126,21 +132,4 @@ protected DistributionPolicy createDistributionPolicy(RouterAdministrationClient

return routerAdminClient.createDistributionPolicy(createDistributionPolicyOptions);
}

protected RouterJob createJob(RouterClient routerClient, String queueId) {
CreateJobOptions createJobOptions = new CreateJobOptions("job-id", "chat-channel", queueId)
.setPriority(1)
.setChannelReference("12345")
.setRequestedWorkerSelectors(
new ArrayList<WorkerSelector>() {
{
new WorkerSelector()
.setKey("Some-skill")
.setLabelOperator(LabelOperator.GREATER_THAN)
.setValue(10);
}
}
);
return routerClient.createJob(createJobOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.azure.communication.jobrouter.models.options.CreateWorkerOptions;
import com.azure.communication.jobrouter.models.options.UnassignJobOptions;
import com.azure.core.http.HttpClient;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand All @@ -35,6 +36,7 @@ public class RouterJobLiveTests extends JobRouterTestBase {

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
@Disabled("https://github.com/Azure/azure-sdk-for-java/issues/35706")
public void unassignJob(HttpClient httpClient) {
// Setup
routerClient = getRouterClient(httpClient);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit a09c380

Please sign in to comment.