Skip to content

Commit

Permalink
Fixes/Updates Service Bus administration tests (#35523)
Browse files Browse the repository at this point in the history
* Replace explicit usage of client secret with DefaultAzureCredential.

* Fix SQL test for sync

* Make getting topic, subscription, session names easier.

* Update recordings.

* Remove old recordings. (Ones with no class name.)

* Remove extra usages of new RetryPolicy()

* Use mocked AccessToken.
  • Loading branch information
conniey authored Jun 20, 2023
1 parent f13725b commit faa5819
Show file tree
Hide file tree
Showing 105 changed files with 1,137 additions and 1,332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.core.amqp.ProxyOptions;
import com.azure.core.amqp.implementation.ConnectionStringProperties;
import com.azure.core.amqp.models.AmqpMessageBody;
import com.azure.core.credential.TokenCredential;
import com.azure.core.experimental.util.tracing.LoggingTracerProvider;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestMode;
Expand All @@ -17,8 +18,7 @@
import com.azure.core.util.CoreUtils;
import com.azure.core.util.IterableStream;
import com.azure.core.util.logging.ClientLogger;
import com.azure.identity.ClientSecretCredential;
import com.azure.identity.ClientSecretCredentialBuilder;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.messaging.servicebus.ServiceBusClientBuilder.ServiceBusReceiverClientBuilder;
import com.azure.messaging.servicebus.ServiceBusClientBuilder.ServiceBusSenderClientBuilder;
import com.azure.messaging.servicebus.ServiceBusClientBuilder.ServiceBusSessionReceiverClientBuilder;
Expand Down Expand Up @@ -243,13 +243,9 @@ protected ServiceBusClientBuilder getBuilder(boolean useCredentials) {
assumeTrue(fullyQualifiedDomainName != null && !fullyQualifiedDomainName.isEmpty(),
"AZURE_SERVICEBUS_FULLY_QUALIFIED_DOMAIN_NAME variable needs to be set when using credentials.");

final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(TestUtils.getPropertyValue("AZURE_CLIENT_ID"))
.clientSecret(TestUtils.getPropertyValue("AZURE_CLIENT_SECRET"))
.tenantId(TestUtils.getPropertyValue("AZURE_TENANT_ID"))
.build();
final TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();

return builder.credential(fullyQualifiedDomainName, clientSecretCredential);
return builder.credential(fullyQualifiedDomainName, tokenCredential);
} else {
return builder.connectionString(getConnectionString());
}
Expand Down Expand Up @@ -287,7 +283,7 @@ protected ServiceBusReceiverClientBuilder getReceiverBuilder(boolean useCredenti
return builder.receiver().receiveMode(ServiceBusReceiveMode.PEEK_LOCK).queueName(queueName);
case SUBSCRIPTION:
final String topicName = getTopicName(entityIndex);
final String subscriptionName = getSubscriptionBaseName();
final String subscriptionName = getEntityName(getSubscriptionBaseName(), 2);
assertNotNull(topicName, "'topicName' cannot be null.");
assertNotNull(subscriptionName, "'subscriptionName' cannot be null.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import static com.azure.messaging.servicebus.TestUtils.getEntityName;
import static com.azure.messaging.servicebus.TestUtils.getServiceBusMessage;
import static com.azure.messaging.servicebus.TestUtils.getSessionSubscriptionBaseName;
import static com.azure.messaging.servicebus.TestUtils.getSubscriptionBaseName;
Expand Down Expand Up @@ -209,7 +210,7 @@ private ServiceBusClientBuilder.ServiceBusProcessorClientBuilder getProcessorBui
return builder.processor().queueName(queueName);
case SUBSCRIPTION:
final String topicName = getTopicName(entityIndex);
final String subscriptionName = getSubscriptionBaseName();
final String subscriptionName = getEntityName(getSubscriptionBaseName(), 2);
assertNotNull(topicName, "'topicName' cannot be null.");
assertNotNull(subscriptionName, "'subscriptionName' cannot be null.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.Collections;
import java.util.Base64;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -96,6 +96,11 @@ public class TestUtils {
APPLICATION_PROPERTIES.put("status-code", AmqpResponseCode.OK.getValue());
}

/**
* Namespace used to record tests.
*/
public static final String TEST_NAMESPACE = "sb-java-conniey-sbd";

/**
* Gets the namespace connection string.
*
Expand Down Expand Up @@ -152,7 +157,7 @@ public static String getConnectionString(boolean withSas) {
* @return The fully qualified domain name for the service bus resource.
*/
public static String getFullyQualifiedDomainName() {
return getPropertyValue("AZURE_SERVICEBUS_FULLY_QUALIFIED_DOMAIN_NAME");
return getPropertyValue("AZURE_SERVICEBUS_FULLY_QUALIFIED_DOMAIN_NAME", "REDACTED.servicebus.windows.net");
}

public static String getEndpoint() {
Expand All @@ -165,7 +170,7 @@ public static String getEndpoint() {
* @return The Service Bus queue name.
*/
public static String getQueueBaseName() {
return getPropertyValue("AZURE_SERVICEBUS_QUEUE_NAME");
return getPropertyValue("AZURE_SERVICEBUS_QUEUE_NAME", "queue");
}

/**
Expand All @@ -174,7 +179,7 @@ public static String getQueueBaseName() {
* @return The Service Bus rule name.
*/
public static String getRuleBaseName() {
return getPropertyValue("AZURE_SERVICEBUS_RULE_NAME");
return getPropertyValue("AZURE_SERVICEBUS_RULE_NAME", "rule");
}

/**
Expand All @@ -183,7 +188,7 @@ public static String getRuleBaseName() {
* @return The Service Bus queue name.
*/
public static String getSessionQueueBaseName() {
return getPropertyValue("AZURE_SERVICEBUS_SESSION_QUEUE_NAME");
return getPropertyValue("AZURE_SERVICEBUS_SESSION_QUEUE_NAME", "queue-session");
}

/**
Expand All @@ -192,7 +197,7 @@ public static String getSessionQueueBaseName() {
* @return The Service Bus subscription name.
*/
public static String getSubscriptionBaseName() {
return getPropertyValue("AZURE_SERVICEBUS_SUBSCRIPTION_NAME");
return getPropertyValue("AZURE_SERVICEBUS_SUBSCRIPTION_NAME", "subscription");
}

/**
Expand All @@ -201,7 +206,7 @@ public static String getSubscriptionBaseName() {
* @return The Service Bus subscription name.
*/
public static String getTopicBaseName() {
return getPropertyValue("AZURE_SERVICEBUS_TOPIC_NAME");
return getPropertyValue("AZURE_SERVICEBUS_TOPIC_NAME", "topic");
}

/**
Expand All @@ -210,7 +215,7 @@ public static String getTopicBaseName() {
* @return The Service Bus subscription name.
*/
public static String getSessionSubscriptionBaseName() {
return getPropertyValue("AZURE_SERVICEBUS_SESSION_SUBSCRIPTION_NAME");
return getPropertyValue("AZURE_SERVICEBUS_SESSION_SUBSCRIPTION_NAME", "subscription-session");
}

/**
Expand All @@ -225,33 +230,6 @@ public static String getEntityName(String baseName, int index) {
return String.join("-", baseName, String.valueOf(index));
}

/**
* The azure application client id
*
* @return The application client id.
*/
public static String getAzureClientId() {
return getPropertyValue("AZURE_CLIENT_ID");
}

/**
* The azure application client secret
*
* @return The application client secret.
*/
public static String getAzureClientSecret() {
return getPropertyValue("AZURE_CLIENT_SECRET");
}

/**
* The azure application tenant id
*
* @return The application tenant id.
*/
public static String getAzureTenantId() {
return getPropertyValue("AZURE_TENANT_ID");
}

public static Configuration getGlobalConfiguration() {
return GLOBAL_CONFIGURATION;
}
Expand Down Expand Up @@ -387,7 +365,6 @@ public static void assertAuthorizationRules(List<AuthorizationRule> expected, Li
}
}


public static String getPropertyValue(String propertyName) {
return GLOBAL_CONFIGURATION.get(propertyName, System.getenv(propertyName));
}
Expand Down
Loading

0 comments on commit faa5819

Please sign in to comment.