Skip to content

Commit

Permalink
Fix phonenumbers pipeline (Azure#34252)
Browse files Browse the repository at this point in the history
  • Loading branch information
jannovak-msft authored Mar 29, 2023
1 parent ffdee7e commit 20df5af
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions sdk/communication/azure-communication-phonenumbers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<configuration>
<includes>
<include>com/azure/communication/phonenumbers/*.class</include>
<include>com/azure/communication/phonenumbers/siprouting/*.class</include>
</includes>
</configuration>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelinePosition;
import com.azure.core.http.policy.*;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -17,6 +19,8 @@
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -115,6 +119,69 @@ public void buildClientWithServiceVersion() {
assertNotNull(sipRoutingClient);
}

@Test
public void buildClientWithRetryPolicy() {
SipRoutingClient sipRoutingClient = this.setupBuilderWithHttpClientWithCredential(this.clientBuilder)
.retryPolicy(new RetryPolicy("1", ChronoUnit.SECONDS))
.buildClient();
assertNotNull(sipRoutingClient);
}

@Test
public void buildClientWithRetryOptions() {
SipRoutingClient sipRoutingClient = this.setupBuilderWithHttpClientWithCredential(this.clientBuilder)
.retryOptions(new RetryOptions(new FixedDelayOptions(3, Duration.ZERO)))
.buildClient();
assertNotNull(sipRoutingClient);
}

@Test
public void buildClientWithClientOptions() {
SipRoutingClient sipRoutingClient = this.setupBuilderWithHttpClientWithCredential(this.clientBuilder)
.clientOptions(new ClientOptions())
.buildClient();
assertNotNull(sipRoutingClient);
}

@Test
public void buildClientByReplacingHttpClient() {
SipRoutingClient sipRoutingClient = this.setupBuilderWithHttpClientWithCredential(this.clientBuilder)
.httpClient(this.httpClient)
.httpClient(this.httpClient)
.buildClient();
assertNotNull(sipRoutingClient);
}

@Test
public void buildClientByReplacingPipeline() {
HttpPipeline httpPipeline = mock(HttpPipeline.class);
SipRoutingClient sipRoutingClient = this.setupBuilderWithHttpClientWithCredential(this.clientBuilder)
.pipeline(httpPipeline)
.pipeline(httpPipeline)
.buildClient();
assertNotNull(sipRoutingClient);
}

@Test
public void buildClientWithPolicyPerCall() {
HttpPipelinePolicy policy = mock(HttpPipelinePolicy.class);
doAnswer(invocation -> HttpPipelinePosition.PER_CALL).when(policy).getPipelinePosition();
SipRoutingClient sipRoutingClient = this.setupBuilderWithHttpClientWithCredential(this.clientBuilder)
.addPolicy(policy)
.buildClient();
assertNotNull(sipRoutingClient);
}

@Test
public void buildClientWithPolicyPerRetry() {
HttpPipelinePolicy policy = mock(HttpPipelinePolicy.class);
doAnswer(invocation -> HttpPipelinePosition.PER_RETRY).when(policy).getPipelinePosition();
SipRoutingClient sipRoutingClient = this.setupBuilderWithHttpClientWithCredential(this.clientBuilder)
.addPolicy(policy)
.buildClient();
assertNotNull(sipRoutingClient);
}

@Test
public void buildClientWithOneAdditionalPolicy() {
ClientBuilderSpyHelper spyHelper = new ClientBuilderSpyHelper(this.clientBuilder);
Expand Down

0 comments on commit 20df5af

Please sign in to comment.