Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Communication] - SMS - Fix live tests #19677

Merged
merged 3 commits into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void sendSmsUsingTokenCredential(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendSmsToGroup(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
asyncClient = setupAsyncClient(builder, "sendSmsToGroup");

// Action & Assert
Expand All @@ -73,7 +73,7 @@ public void sendSmsToGroup(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendSmsToGroupWithOptions(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
asyncClient = setupAsyncClient(builder, "sendSmsToGroupWithOptions");
SmsSendOptions options = new SmsSendOptions();
options.setDeliveryReportEnabled(true);
Expand All @@ -93,7 +93,7 @@ public void sendSmsToGroupWithOptions(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendSmsToSingleNumber(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
asyncClient = setupAsyncClient(builder, "sendSmsToSingleNumber");

// Action & Assert
Expand All @@ -109,7 +109,7 @@ public void sendSmsToSingleNumber(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendSmsToSingleNumberWithOptions(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
asyncClient = setupAsyncClient(builder, "sendSmsToSingleNumberWithOptions");
SmsSendOptions options = new SmsSendOptions();
options.setDeliveryReportEnabled(true);
Expand All @@ -127,7 +127,7 @@ public void sendSmsToSingleNumberWithOptions(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendFromFakeNumber(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
asyncClient = setupAsyncClient(builder, "sendFromFakeNumber");
// Action & Assert
Mono<SmsSendResult> response = asyncClient.send("+155512345678", TO_PHONE_NUMBER, MESSAGE);
Expand All @@ -140,7 +140,7 @@ public void sendFromFakeNumber(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendFromUnauthorizedNumber(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
asyncClient = setupAsyncClient(builder, "sendFromUnauthorizedNumber");

// Action & Assert
Expand All @@ -153,16 +153,18 @@ public void sendFromUnauthorizedNumber(HttpClient httpClient) {
@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendToFakePhoneNumber(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
asyncClient = setupAsyncClient(builder, "sendToFakePhoneNumber");
assertNotNull(asyncClient);
Mono<Iterable<SmsSendResult>> response = asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList("+15550000000"), MESSAGE);
assertNotNull(response);

// Action & Assert
StepVerifier.create(response)
.assertNext(item -> {
assertNotNull(item);
})
.verifyComplete();

Iterable<SmsSendResult> smsSendResults = response.block();
for (SmsSendResult result : smsSendResults) {
assertFalse(result.isSuccessful());
Expand All @@ -174,7 +176,7 @@ public void sendToFakePhoneNumber(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendTwoMessages(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
asyncClient = setupAsyncClient(builder, "sendTwoMessages");

// Action & Assert
Expand All @@ -194,7 +196,7 @@ public void sendTwoMessages(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendSmsToNullNumber(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
asyncClient = setupAsyncClient(builder, "sendSmsToSingleNumber");

// Action & Assert
Expand All @@ -207,7 +209,7 @@ public void sendSmsToNullNumber(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendSmsFromNullNumber(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
asyncClient = setupAsyncClient(builder, "sendSmsFromNullNumber");

// Action & Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void sendSmsUsingTokenCredential(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendSmsToGroup(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
client = setupSyncClient(builder, "sendSmsToGroupSync");

// Action & Assert
Expand All @@ -64,7 +64,7 @@ public void sendSmsToGroup(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendSmsToGroupWithOptions(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
client = setupSyncClient(builder, "sendSmsToGroupWithOptionsSync");
SmsSendOptions options = new SmsSendOptions();
options.setDeliveryReportEnabled(true);
Expand All @@ -80,7 +80,7 @@ public void sendSmsToGroupWithOptions(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendSmsToSingleNumber(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
client = setupSyncClient(builder, "sendSmsToSingleNumberSync");

// Action & Assert
Expand All @@ -92,7 +92,7 @@ public void sendSmsToSingleNumber(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendSmsToSingleNumberWithOptions(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
client = setupSyncClient(builder, "sendSmsToSingleNumberWithOptionsSync");
SmsSendOptions options = new SmsSendOptions();
options.setDeliveryReportEnabled(true);
Expand All @@ -107,7 +107,7 @@ public void sendSmsToSingleNumberWithOptions(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendFromFakeNumber(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
client = setupSyncClient(builder, "sendFromFakeNumberSync");

// Action & Assert
Expand All @@ -122,7 +122,7 @@ public void sendFromFakeNumber(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendFromUnauthorizedNumber(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
client = setupSyncClient(builder, "sendFromUnauthorizedNumberSync");

// Action & Assert
Expand Down Expand Up @@ -150,7 +150,7 @@ public void sendToFakePhoneNumber(HttpClient httpClient) {
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void sendTwoMessages(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClient(httpClient);
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
client = setupSyncClient(builder, "sendTwoMessagesSync");

// Action & Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.communication.sms;


import com.azure.communication.common.implementation.CommunicationConnectionString;
import com.azure.core.credential.AccessToken;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.TokenCredential;
Expand Down Expand Up @@ -32,25 +32,21 @@ public class SmsTestBase extends TestBase {
protected static final String ENDPOINT = Configuration.getGlobalConfiguration()
.get("COMMUNICATION_SERVICE_ENDPOINT", "https://REDACTED.communication.azure.com");

protected static final String ENDPOINT_TOKEN = Configuration.getGlobalConfiguration()
.get("COMMUNICATION_TOKEN_ENDPOINT", "https://REDACTED.communication.azure.com");

protected static final String ACCESSKEYRAW = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
protected static final String ACCESSKEYENCODED = Base64.getEncoder().encodeToString(ACCESSKEYRAW.getBytes());
protected static final String ACCESSKEY = Configuration.getGlobalConfiguration()
.get("COMMUNICATION_SERVICE_ACCESS_KEY", ACCESSKEYENCODED);

protected static final String CONNECTION_STRING = Configuration.getGlobalConfiguration()
.get("COMMUNICATION_CONNECTION_STRING", "endpoint=https://REDACTED.communication.azure.com/;accesskey=" + ACCESSKEYENCODED);
.get("COMMUNICATION_LIVETEST_CONNECTION_STRING", "endpoint=https://REDACTED.communication.azure.com/;accesskey=" + ACCESSKEYENCODED);

protected static final String TO_PHONE_NUMBER = Configuration.getGlobalConfiguration()
.get("SMS_SERVICE_PHONE_NUMBER", "+15551234567");

protected static final String FROM_PHONE_NUMBER = Configuration.getGlobalConfiguration()
.get("SMS_SERVICE_PHONE_NUMBER", "+15551234567");

protected static final String MESSAGE = Configuration.getGlobalConfiguration()
.get("MESSAGE", "Hello");
protected static final String MESSAGE = "Hello";

private static final StringJoiner JSON_PROPERTIES_TO_REDACT
= new StringJoiner("\":\"|\"", "\"", "\":\"")
Expand All @@ -63,7 +59,7 @@ public class SmsTestBase extends TestBase {
protected SmsClientBuilder getSmsClient(HttpClient httpClient) {
AzureKeyCredential azureKeyCredential = new AzureKeyCredential(ACCESSKEY);
SmsClientBuilder builder = new SmsClientBuilder();
builder.endpoint(ENDPOINT)
builder.endpoint(new CommunicationConnectionString(CONNECTION_STRING).getEndpoint())
.credential(azureKeyCredential)
.httpClient(httpClient == null ? interceptorManager.getPlaybackClient() : httpClient);
if (getTestMode() == TestMode.RECORD) {
Expand All @@ -79,7 +75,7 @@ protected SmsClientBuilder getSmsClientWithToken(HttpClient httpClient, TokenCre
tokenCredential = new FakeCredentials();
}
SmsClientBuilder builder = new SmsClientBuilder();
builder.endpoint(ENDPOINT_TOKEN)
builder.endpoint(new CommunicationConnectionString(CONNECTION_STRING).getEndpoint())
.credential(tokenCredential)
.httpClient(httpClient == null ? interceptorManager.getPlaybackClient() : httpClient);

Expand Down