From 250c73d024880a82076807ec0ae7e398856605fc Mon Sep 17 00:00:00 2001 From: Xiaolu Dai <31124698+saragluna@users.noreply.github.com> Date: Tue, 20 Sep 2022 15:07:48 +0800 Subject: [PATCH] Fix Spring integration tests for sovereign clouds (#30534) * use AZURE_AUTHORITY_HOST env instead * change to use data owner role * enable cosmos tests * try another region chinanorth3 * remove default amqp transport type * refactor profile * update changelog Co-authored-by: Muyao Co-authored-by: Muyao --- sdk/spring/CHANGELOG.md | 13 +- .../context/AzureGlobalProperties.java | 19 +- ...AzureTokenCredentialAutoConfiguration.java | 4 + ...AzureBlobCheckpointStoreConfiguration.java | 20 +- .../AzureEventHubsCommonProperties.java | 11 +- .../properties/AzureEventHubsProperties.java | 7 +- .../AmqpClientConfigurationProperties.java | 2 +- .../AzureServiceBusCommonProperties.java | 13 +- .../properties/AzureServiceBusProperties.java | 5 + .../AzureStorageBlobProperties.java | 3 + .../AzureProfileConfigurationProperties.java | 4 +- .../AzureServiceConfigurationBaseTests.java | 56 ++++ ...TokenCredentialAutoConfigurationTests.java | 20 ++ ...BlobCheckpointStoreConfigurationTests.java | 7 +- .../AzureEventHubsAutoConfigurationTests.java | 6 +- .../AzureEventHubsPropertiesTest.java | 253 ++++++++++++++++++ .../AzureServiceBusPropertiesTest.java | 190 +++++++++++++ ...AbstractAzureAmqpClientBuilderFactory.java | 4 +- .../util/AzurePropertiesUtils.java | 4 +- .../client/AmqpClientProperties.java | 2 +- .../profile/AzureEnvironmentProperties.java | 2 +- .../profile/AzureProfileOptionsAdapter.java | 9 +- .../profile/AzureProfileProperties.java | 10 +- .../core/util/AzurePropertiesUtilsTests.java | 2 + .../tests/ApplicationConfiguration.java | 4 + .../tests/AzureCloudTypeConfiguration.java | 60 +++++ .../binder/EventHubsBinderBatchModeIT.java | 1 - .../binder/EventHubsBinderConsumeErrorIT.java | 1 - .../binder/EventHubsBinderManualModeIT.java | 1 - .../binder/EventHubsBinderRecordModeIT.java | 1 - .../binder/EventHubsBinderSyncModeIT.java | 1 - .../tests/servicebus/ServiceBusIT.java | 2 +- ...rIT.java => ServiceBusMultiBindersIT.java} | 10 +- ...rIT.java => ServiceBusSingleBinderIT.java} | 10 +- .../application-servicebus-binder-multi.yml | 5 + .../application-servicebus-binder-single.yml | 43 ++- .../src/test/resources/application.yml | 4 + .../appconfiguration/test-resources.json | 15 +- .../test-resources/cosmos/test-resources.json | 6 +- .../keyvault/test-resources.json | 7 +- .../servicebus/test-resources.json | 8 + ...zureAmqpClientBuilderFactoryBaseTests.java | 2 + .../EventHubsConsumerPropertiesTests.java | 70 ++++- .../EventHubsProducerPropertiesTests.java | 37 ++- .../ServiceBusConsumerPropertiesTests.java | 52 ++++ .../ServiceBusProducerPropertiesTests.java | 39 ++- .../core/properties/CommonProperties.java | 13 +- .../core/properties/NamespaceProperties.java | 11 + .../config/EnableAzureMessagingTests.java | 3 +- ...tenerAnnotationBeanPostProcessorTests.java | 5 +- .../ProcessorPropertiesParentMergerTests.java | 22 +- .../ProducerPropertiesParentMergerTests.java | 26 +- .../core/properties/CommonProperties.java | 11 +- .../core/properties/NamespaceProperties.java | 11 + .../ProducerPropertiesParentMergerTests.java | 46 ---- .../ProcessorPropertiesParentMergerTests.java | 27 +- .../ProducerPropertiesParentMergerTests.java | 70 +++++ sdk/spring/tests.yml | 11 +- 58 files changed, 1117 insertions(+), 184 deletions(-) create mode 100644 sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsPropertiesTest.java create mode 100644 sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusPropertiesTest.java create mode 100644 sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/AzureCloudTypeConfiguration.java rename sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/{MultiServiceBusQueueAndTopicBinderIT.java => ServiceBusMultiBindersIT.java} (90%) rename sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/{SingleServiceBusQueueAndTopicBinderIT.java => ServiceBusSingleBinderIT.java} (90%) rename sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/{implementatin => implementation}/core/config/EnableAzureMessagingTests.java (98%) rename sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/{implementatin => implementation}/core/config/EventHubsListenerAnnotationBeanPostProcessorTests.java (97%) rename sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/{core => implementation}/properties/merger/ProcessorPropertiesParentMergerTests.java (63%) rename sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/{core => implementation}/properties/merger/ProducerPropertiesParentMergerTests.java (52%) delete mode 100644 sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/core/properties/merger/ProducerPropertiesParentMergerTests.java rename sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/{core => implementation}/properties/merger/ProcessorPropertiesParentMergerTests.java (51%) create mode 100644 sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/implementation/properties/merger/ProducerPropertiesParentMergerTests.java diff --git a/sdk/spring/CHANGELOG.md b/sdk/spring/CHANGELOG.md index b4eb6450a4c0d..c482bf10ef7ca 100644 --- a/sdk/spring/CHANGELOG.md +++ b/sdk/spring/CHANGELOG.md @@ -10,6 +10,8 @@ This section includes changes in `spring-cloud-azure-autoconfigure` module. #### Bugs Fixed - Fix bug: Cannot configure "azure" authorization client. [#30354](https://github.com/Azure/azure-sdk-for-java/issues/30354). - Fix parameter `requested_token_use` missing when using On behalf of process [#30359](https://github.com/Azure/azure-sdk-for-java/issues/30359). +- Fix Kafka `OAuth2AuthenticateCallbackHandler` cannot work with Kafka refreshing login mechanism [#30719](https://github.com/Azure/azure-sdk-for-java/issues/30719). +- Fix the cloud type cannot be configured for a consumer/producer/processor of Service Bus / Event Hubs bug [#30936](https://github.com/Azure/azure-sdk-for-java/issues/30936). #### Features Added - Support auto start-up for the auto-configured Service Bus Processor Client by enabling a new property of `spring.cloud.azure.servicebus.processor.auto-startup`. [#29997](https://github.com/Azure/azure-sdk-for-java/issues/29997) @@ -17,15 +19,16 @@ This section includes changes in `spring-cloud-azure-autoconfigure` module. - Provide the property of `spring.cloud.azure.eventhubs.kafka.enabled` to turn of/off the OAuth2 support of Spring Cloud Azure for Event Hubs for Kafka [#30574](https://github.com/Azure/azure-sdk-for-java/issues/30574). - Support connecting to Azure AD via proxy. To achieve this, customer need provide a custom `RestTemplateCustomizer` bean. [#26493](https://github.com/Azure/azure-sdk-for-java/issues/26493). -### Spring Cloud Azure Resource Manager +### Spring Cloud Stream Event Hubs Binder +#### Bugs Fixed +- Fix the cloud type cannot be configured for Event Hubs Binder bug [#30936](https://github.com/Azure/azure-sdk-for-java/issues/30936). +### Spring Cloud Stream Service Bus Binder #### Bugs Fixed -- Fix the Service Bus stream binder cannot automatically create Topic/Subscriptions from consumer. [#30722](https://github.com/Azure/azure-sdk-for-java/pull/30722). +- Fix the Service Bus Binder cannot automatically create Topic/Subscriptions from consumer bug. [#30722](https://github.com/Azure/azure-sdk-for-java/pull/30722). +- Fix the cloud type cannot be configured for Service Bus Binder bug [#30936](https://github.com/Azure/azure-sdk-for-java/issues/30936). -### Spring Cloud Azure Service -#### Bugs Fixed -- Fix Kafka OAuth2AuthenticateCallbackHandler cannot work with Kafka refreshing login mechanism [#30719](https://github.com/Azure/azure-sdk-for-java/issues/30719). ## 4.3.0 (2022-06-29) - This release is compatible with Spring Boot 2.5.0-2.5.14, 2.6.0-2.6.9, 2.7.0-2.7.1. (Note: 2.5.x (x>14), 2.6.y (y>9) and 2.7.z (z>1) should be supported, but they aren't tested with this release.) diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalProperties.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalProperties.java index 5fee380bb628f..8433192887296 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalProperties.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalProperties.java @@ -10,9 +10,9 @@ import com.azure.spring.cloud.autoconfigure.properties.core.profile.AzureProfileConfigurationProperties; import com.azure.spring.cloud.autoconfigure.properties.core.proxy.ProxyConfigurationProperties; import com.azure.spring.cloud.autoconfigure.properties.core.retry.RetryConfigurationProperties; -import com.azure.spring.cloud.core.provider.RetryOptionsProvider; import com.azure.spring.cloud.core.properties.AzureProperties; import com.azure.spring.cloud.core.properties.client.HeaderProperties; +import com.azure.spring.cloud.core.provider.RetryOptionsProvider; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; @@ -44,7 +44,7 @@ public class AzureGlobalProperties implements AzureProperties, RetryOptionsProvi private final TokenCredentialConfigurationProperties credential = new TokenCredentialConfigurationProperties(); @NestedConfigurationProperty - private final AzureProfileConfigurationProperties profile = new AzureProfileConfigurationProperties(); + private final GlobalProfileConfigurationProperties profile = new GlobalProfileConfigurationProperties(); @Override public GlobalClientConfigurationProperties getClient() { @@ -422,4 +422,19 @@ public void setTransportType(AmqpTransportType transportType) { this.transportType = transportType; } } + + /** + * Global profile properties. This global profile properties will have a default cloud type of Azure. + */ + public static class GlobalProfileConfigurationProperties extends AzureProfileConfigurationProperties { + + /** + * Construct a default {@link GlobalProfileConfigurationProperties} with default cloud type Azure. + */ + public GlobalProfileConfigurationProperties() { + setCloudType(CloudType.AZURE); + } + + } + } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureTokenCredentialAutoConfiguration.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureTokenCredentialAutoConfiguration.java index 8561a527f3ebc..9c902589153ad 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureTokenCredentialAutoConfiguration.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureTokenCredentialAutoConfiguration.java @@ -251,4 +251,8 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException { static class IdentityClientProperties extends AbstractAzureHttpConfigurationProperties { } + + IdentityClientProperties getIdentityClientProperties() { + return identityClientProperties; + } } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureBlobCheckpointStoreConfiguration.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureBlobCheckpointStoreConfiguration.java index 3bbc2d828e05c..3e3c6556c9641 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureBlobCheckpointStoreConfiguration.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureBlobCheckpointStoreConfiguration.java @@ -6,14 +6,13 @@ import com.azure.messaging.eventhubs.EventHubClientBuilder; import com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore; import com.azure.spring.cloud.autoconfigure.implementation.eventhubs.properties.AzureEventHubsProperties; -import com.azure.spring.cloud.core.implementation.util.AzureSpringIdentifier; import com.azure.spring.cloud.core.customizer.AzureServiceClientBuilderCustomizer; +import com.azure.spring.cloud.core.implementation.util.AzureSpringIdentifier; import com.azure.spring.cloud.service.implementation.storage.blob.BlobServiceClientBuilderFactory; import com.azure.storage.blob.BlobContainerAsyncClient; import com.azure.storage.blob.BlobServiceClientBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -26,7 +25,6 @@ import static com.azure.spring.cloud.autoconfigure.context.AzureContextUtils.EVENT_HUB_PROCESSOR_CHECKPOINT_STORE_STORAGE_CLIENT_BUILDER_BEAN_NAME; import static com.azure.spring.cloud.autoconfigure.context.AzureContextUtils.EVENT_HUB_PROCESSOR_CHECKPOINT_STORE_STORAGE_CLIENT_BUILDER_FACTORY_BEAN_NAME; -import static com.azure.spring.cloud.core.implementation.util.AzurePropertiesUtils.mergeAzureCommonProperties; /** * Configures a {@link BlobCheckpointStore} @@ -83,25 +81,11 @@ BlobServiceClientBuilderFactory eventHubProcessorBlobServiceClientBuilderFactory AzureEventHubsProperties eventHubsProperties, ObjectProvider> customizers) { BlobServiceClientBuilderFactory factory = - new BlobServiceClientBuilderFactory(getCheckpointStoreProperties(eventHubsProperties)); + new BlobServiceClientBuilderFactory(eventHubsProperties.buildProcessorProperties().getCheckpointStore()); factory.setSpringIdentifier(AzureSpringIdentifier.AZURE_SPRING_EVENT_HUBS); customizers.orderedStream().forEach(factory::addBuilderCustomizer); return factory; } - private AzureEventHubsProperties.Processor.BlobCheckpointStore getCheckpointStoreProperties( - AzureEventHubsProperties ehProperties) { - - AzureEventHubsProperties.Processor.BlobCheckpointStore result = new AzureEventHubsProperties.Processor - .BlobCheckpointStore(); - AzureEventHubsProperties.Processor.BlobCheckpointStore csProperties = ehProperties.getProcessor() - .getCheckpointStore(); - - mergeAzureCommonProperties(ehProperties, csProperties, result); - BeanUtils.copyProperties(csProperties, result); - - return result; - } - } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsCommonProperties.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsCommonProperties.java index 662a78a612c0b..811af54627ea0 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsCommonProperties.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsCommonProperties.java @@ -14,7 +14,7 @@ public abstract class AzureEventHubsCommonProperties extends AbstractAzureAmqpCo /** * The domain name of an Event Hub namespace. */ - private String domainName = "servicebus.windows.net"; + private String domainName; /** * The namespace of an event hub, which is the prefix of the FQDN. A FQDN should be composed of <NamespaceName>.<DomainName> */ @@ -54,7 +54,14 @@ protected String extractEventHubNameFromConnectionString() { // Endpoint=sb:///;SharedAccessKeyName=;SharedAccessKey= // https://docs.microsoft.com/azure/event-hubs/event-hubs-get-connection-string public String getFullyQualifiedNamespace() { - return this.namespace == null ? extractFqdnFromConnectionString() : (this.namespace + "." + domainName); + return this.namespace == null ? extractFqdnFromConnectionString() : buildFqdnFromNamespace(); + } + + private String buildFqdnFromNamespace() { + if (namespace == null || domainName == null) { + return null; + } + return this.namespace + "." + domainName; } public String getDomainName() { diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsProperties.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsProperties.java index 307b4165fd769..2a573d9d5535c 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsProperties.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsProperties.java @@ -33,6 +33,7 @@ public class AzureEventHubsProperties extends AzureEventHubsCommonProperties implements EventHubsNamespaceProperties, InitializingBean { public static final String PREFIX = "spring.cloud.azure.eventhubs"; + private static final String DEFAULT_DOMAIN_NAME = "servicebus.windows.net"; private static final Logger LOGGER = LoggerFactory.getLogger(AzureEventHubsProperties.class); /** @@ -43,6 +44,10 @@ public class AzureEventHubsProperties extends AzureEventHubsCommonProperties private final Consumer consumer = new Consumer(); private final Processor processor = new Processor(); + public AzureEventHubsProperties() { + this.setDomainName(DEFAULT_DOMAIN_NAME); + } + public Producer buildProducerProperties() { PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); @@ -121,7 +126,7 @@ public Processor buildProcessorProperties() { propertyMapper.from(this.processor.loadBalancing.getStrategy()).to(properties.loadBalancing::setStrategy); propertyMapper.from(this.processor.loadBalancing.getUpdateInterval()).to(properties.loadBalancing::setUpdateInterval); - AzurePropertiesUtils.copyAzureCommonProperties(this.processor.checkpointStore, properties.checkpointStore); + AzurePropertiesUtils.mergeAzureCommonProperties(properties, this.processor.getCheckpointStore(), properties.checkpointStore); BeanUtils.copyProperties(this.processor.checkpointStore, properties.checkpointStore); return properties; diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/properties/core/client/AmqpClientConfigurationProperties.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/properties/core/client/AmqpClientConfigurationProperties.java index 7c39143aa426b..9ea0c6cdb6219 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/properties/core/client/AmqpClientConfigurationProperties.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/properties/core/client/AmqpClientConfigurationProperties.java @@ -15,7 +15,7 @@ public class AmqpClientConfigurationProperties extends ClientConfigurationProper /** * Transport type for AMQP-based client. */ - private AmqpTransportType transportType = AmqpTransportType.AMQP; + private AmqpTransportType transportType; @Override public AmqpTransportType getTransportType() { diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusCommonProperties.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusCommonProperties.java index 5632a166c4428..c9bec07d4e8aa 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusCommonProperties.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusCommonProperties.java @@ -10,14 +10,14 @@ /** * */ -public abstract class AzureServiceBusCommonProperties extends AbstractAzureAmqpConfigurationProperties { +abstract class AzureServiceBusCommonProperties extends AbstractAzureAmqpConfigurationProperties { // https://help.boomi.com/bundle/connectors/page/r-atm-Microsoft_Azure_Service_Bus_connection.html // https://docs.microsoft.com/rest/api/servicebus/addressing-and-protocol /** * The domain name of a Service Bus namespace. */ - private String domainName = "servicebus.windows.net"; + private String domainName; /** * The namespace of a service bus, which is the prefix of the FQDN. A FQDN should be composed of <NamespaceName>.<DomainName> */ @@ -43,7 +43,14 @@ private String extractFqdnFromConnectionString() { } public String getFullyQualifiedNamespace() { - return this.namespace == null ? extractFqdnFromConnectionString() : (this.namespace + "." + domainName); + return this.namespace == null ? extractFqdnFromConnectionString() : buildFqdnFromNamespace(); + } + + private String buildFqdnFromNamespace() { + if (namespace == null || domainName == null) { + return null; + } + return this.namespace + "." + domainName; } public String getDomainName() { diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusProperties.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusProperties.java index 840c416ea28fb..03e373743d00d 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusProperties.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusProperties.java @@ -27,6 +27,7 @@ public class AzureServiceBusProperties extends AzureServiceBusCommonProperties implements ServiceBusNamespaceProperties, InitializingBean { public static final String PREFIX = "spring.cloud.azure.servicebus"; + private static final String DEFAULT_DOMAIN_NAME = "servicebus.windows.net"; private static final Logger LOGGER = LoggerFactory.getLogger(AzureServiceBusProperties.class); /** * Whether to enable cross entity transaction on the connection to Service bus. @@ -36,6 +37,10 @@ public class AzureServiceBusProperties extends AzureServiceBusCommonProperties private final Consumer consumer = new Consumer(); private final Processor processor = new Processor(); + public AzureServiceBusProperties() { + this.setDomainName(DEFAULT_DOMAIN_NAME); + } + public Boolean getCrossEntityTransactions() { return crossEntityTransactions; } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/storage/blob/properties/AzureStorageBlobProperties.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/storage/blob/properties/AzureStorageBlobProperties.java index 25a4da6d3bbfb..e71c4fb7a97e2 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/storage/blob/properties/AzureStorageBlobProperties.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/storage/blob/properties/AzureStorageBlobProperties.java @@ -43,6 +43,9 @@ public String getEndpoint() { } private String buildEndpointFromAccountName() { + if (accountName == null || profile.getCloudType() == null) { + return null; + } return String.format(BLOB_ENDPOINT_PATTERN, accountName, profile.getEnvironment().getStorageEndpointSuffix()); } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/properties/core/profile/AzureProfileConfigurationProperties.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/properties/core/profile/AzureProfileConfigurationProperties.java index b8a1cbbaf12e6..86df5f78eba1a 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/properties/core/profile/AzureProfileConfigurationProperties.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/properties/core/profile/AzureProfileConfigurationProperties.java @@ -23,9 +23,9 @@ public class AzureProfileConfigurationProperties extends AzureProfileOptionsAdap /** * Name of the Azure cloud to connect to. */ - private AzureProfileOptionsProvider.CloudType cloudType = AzureProfileOptionsProvider.CloudType.AZURE; + private AzureProfileOptionsProvider.CloudType cloudType; - private final AzureEnvironmentConfigurationProperties environment = new AzureEnvironmentConfigurationProperties(AzureEnvironment.AZURE); + private final AzureEnvironmentConfigurationProperties environment = new AzureEnvironmentConfigurationProperties(null); @Override public AzureProfileOptionsProvider.CloudType getCloudType() { diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/AzureServiceConfigurationBaseTests.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/AzureServiceConfigurationBaseTests.java index 5ca7a18306b32..7a02683aa7cae 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/AzureServiceConfigurationBaseTests.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/AzureServiceConfigurationBaseTests.java @@ -5,6 +5,7 @@ import com.azure.core.amqp.AmqpTransportType; import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.management.AzureEnvironment; import com.azure.cosmos.CosmosClientBuilder; import com.azure.security.keyvault.secrets.SecretClientBuilder; import com.azure.spring.cloud.autoconfigure.context.AzureGlobalProperties; @@ -29,6 +30,7 @@ import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE; import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_CHINA; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_US_GOVERNMENT; import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.OTHER; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -291,5 +293,59 @@ void configureGlobalShouldApplyToHttpAzureKeyVaultSecretProperties() { }); } + @Test + void configureGlobalCloudShouldApplyToAzureKeyVaultSecretProperties() { + AzureGlobalProperties azureProperties = new AzureGlobalProperties(); + azureProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + + this.contextRunner + .withBean(AzureGlobalProperties.class, () -> azureProperties) + .withBean(SecretClientBuilder.class, () -> mock(SecretClientBuilder.class)) + .withPropertyValues( + "spring.cloud.azure.keyvault.secret.endpoint=test" + ) + .run(context -> { + assertThat(context).hasSingleBean(AzureKeyVaultSecretProperties.class); + final AzureKeyVaultSecretProperties properties = context.getBean(AzureKeyVaultSecretProperties.class); + assertThat(properties).extracting("profile.cloudType").isEqualTo(AZURE_US_GOVERNMENT); + assertThat(properties).extracting("profile.environment.activeDirectoryEndpoint").isEqualTo(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint()); + }); + } + + @Test + void configureGlobalCloudShouldApplyToAzureEventHubsProperties() { + AzureGlobalProperties azureProperties = new AzureGlobalProperties(); + azureProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + + this.contextRunner + .withBean(AzureGlobalProperties.class, () -> azureProperties) + .withPropertyValues( + "spring.cloud.azure.eventhubs.namespace=test-namespace" + ) + .run(context -> { + assertThat(context).hasSingleBean(AzureEventHubsProperties.class); + final AzureEventHubsProperties properties = context.getBean(AzureEventHubsProperties.class); + assertThat(properties).extracting("profile.cloudType").isEqualTo(AZURE_US_GOVERNMENT); + assertThat(properties).extracting("profile.environment.activeDirectoryEndpoint").isEqualTo(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint()); + }); + } + + @Test + void globalDefaultShouldNotApplyWhenServiceSpecifyCloudType() { + AzureGlobalProperties azureProperties = new AzureGlobalProperties(); + + this.contextRunner + .withBean(AzureGlobalProperties.class, () -> azureProperties) + .withPropertyValues( + "spring.cloud.azure.eventhubs.namespace=test-namespace", + "spring.cloud.azure.eventhubs.profile.cloud-type=AZURE_US_GOVERNMENT" + ) + .run(context -> { + assertThat(context).hasSingleBean(AzureEventHubsProperties.class); + final AzureEventHubsProperties properties = context.getBean(AzureEventHubsProperties.class); + assertThat(properties).extracting("profile.cloudType").isEqualTo(AZURE_US_GOVERNMENT); + assertThat(properties).extracting("profile.environment.activeDirectoryEndpoint").isEqualTo(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint()); + }); + } } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureTokenCredentialAutoConfigurationTests.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureTokenCredentialAutoConfigurationTests.java index b901e2f260fc3..381223da507df 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureTokenCredentialAutoConfigurationTests.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureTokenCredentialAutoConfigurationTests.java @@ -4,6 +4,7 @@ package com.azure.spring.cloud.autoconfigure.context; import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; import com.azure.identity.ClientCertificateCredential; import com.azure.identity.ClientSecretCredential; import com.azure.identity.DefaultAzureCredential; @@ -38,6 +39,7 @@ import java.time.Duration; import static com.azure.spring.cloud.autoconfigure.context.AzureContextUtils.DEFAULT_CREDENTIAL_TASK_EXECUTOR_BEAN_NAME; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_US_GOVERNMENT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -298,6 +300,24 @@ void defaultAzureCredentialResolverSetToBuilderFactories() { }); } + @Test + void globalPropertiesShouldBeHonored() { + AzureGlobalProperties properties = new AzureGlobalProperties(); + properties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + contextRunner + .withBean(AzureGlobalProperties.class, () -> properties) + .run(context -> { + assertThat(context).hasSingleBean(AzureTokenCredentialAutoConfiguration.class); + AzureTokenCredentialAutoConfiguration autoConfiguration = context.getBean(AzureTokenCredentialAutoConfiguration.class); + AzureTokenCredentialAutoConfiguration.IdentityClientProperties identityClientProperties = autoConfiguration.getIdentityClientProperties(); + + assertEquals(AZURE_US_GOVERNMENT, identityClientProperties.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + identityClientProperties.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + }); + + } + @Configuration static class MultiExecutorConfiguration { diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureBlobCheckpointStoreConfigurationTests.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureBlobCheckpointStoreConfigurationTests.java index 8c5dbff72be19..d82e69a4c3c8b 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureBlobCheckpointStoreConfigurationTests.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureBlobCheckpointStoreConfigurationTests.java @@ -6,8 +6,8 @@ import com.azure.messaging.eventhubs.EventHubClientBuilder; import com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore; import com.azure.spring.cloud.autoconfigure.TestBuilderCustomizer; -import com.azure.spring.cloud.autoconfigure.implementation.eventhubs.properties.AzureEventHubsProperties; import com.azure.spring.cloud.autoconfigure.context.AzureGlobalProperties; +import com.azure.spring.cloud.autoconfigure.implementation.eventhubs.properties.AzureEventHubsProperties; import com.azure.spring.cloud.autoconfigure.storage.blob.AzureStorageBlobAutoConfiguration; import com.azure.spring.cloud.service.implementation.storage.blob.BlobServiceClientBuilderFactory; import com.azure.storage.blob.BlobContainerAsyncClient; @@ -144,11 +144,12 @@ void otherCustomizerShouldNotBeCalled() { @Test void blobContainerInitializerShouldNotConfigureByDefault() { this.contextRunner + .withUserConfiguration(AzureEventHubsPropertiesTestConfiguration.class) .withPropertyValues( "spring.cloud.azure.eventhubs.processor.checkpoint-store.container-name=abc", - "spring.cloud.azure.eventhubs.processor.checkpoint-store.account-name=sa" + "spring.cloud.azure.eventhubs.processor.checkpoint-store.account-name=sa", + "spring.cloud.azure.eventhubs.profile.cloud-type=Azure" ) - .withBean(AzureEventHubsProperties.class, AzureEventHubsProperties::new) .run(context -> { assertThat(context).doesNotHaveBean(BlobCheckpointStoreContainerInitializer.class); }); diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureEventHubsAutoConfigurationTests.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureEventHubsAutoConfigurationTests.java index a48dce5e27fac..f95a32f2314fe 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureEventHubsAutoConfigurationTests.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureEventHubsAutoConfigurationTests.java @@ -3,6 +3,7 @@ package com.azure.spring.cloud.autoconfigure.eventhubs; +import com.azure.core.amqp.AmqpTransportType; import com.azure.messaging.eventhubs.EventHubClientBuilder; import com.azure.spring.cloud.autoconfigure.AbstractAzureServiceConfigurationTests; import com.azure.spring.cloud.autoconfigure.context.AzureGlobalProperties; @@ -114,6 +115,7 @@ void configureAzureEventHubsPropertiesWithGlobalDefaults() { assertThat(properties.getCredential().getClientSecret()).isEqualTo("azure-client-secret"); assertThat(properties.getRetry().getExponential().getBaseDelay()).isEqualTo(Duration.ofMinutes(2)); assertThat(properties.getRetry().getFixed().getDelay()).isEqualTo(Duration.ofSeconds(3)); + assertThat(properties.getClient().getTransportType()).isEqualTo(AmqpTransportType.AMQP); assertThat(properties.getConnectionString()).isEqualTo(CONNECTION_STRING); assertThat(azureProperties.getCredential().getClientId()).isEqualTo("azure-client-id"); @@ -146,7 +148,7 @@ void configurationPropertiesShouldBind() { this.contextRunner .withPropertyValues( "spring.cloud.azure.eventhubs.credential.client-id=eventhubs-client-id", - + "spring.cloud.azure.eventhubs.shared-connection=true", "spring.cloud.azure.eventhubs.domain-name=fake-domain", "spring.cloud.azure.eventhubs.namespace=fake-namespace", @@ -191,7 +193,7 @@ void configurationPropertiesShouldBind() { .run(context -> { assertThat(context).hasSingleBean(AzureEventHubsProperties.class); AzureEventHubsProperties properties = context.getBean(AzureEventHubsProperties.class); - + assertTrue(properties.getSharedConnection()); assertEquals("fake-domain", properties.getDomainName()); assertEquals("fake-namespace", properties.getNamespace()); diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsPropertiesTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsPropertiesTest.java new file mode 100644 index 0000000000000..502e5aa3bbd82 --- /dev/null +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsPropertiesTest.java @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.spring.cloud.autoconfigure.implementation.eventhubs.properties; + +import com.azure.core.amqp.AmqpTransportType; +import com.azure.core.management.AzureEnvironment; +import com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider; +import org.junit.jupiter.api.Test; + +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_CHINA; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_US_GOVERNMENT; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +class AzureEventHubsPropertiesTest { + + @Test + void defaultAmqpTransportTypeIsNull() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + + AzureEventHubsProperties.Producer producer = eventHubsProperties.buildProducerProperties(); + AzureEventHubsProperties.Consumer consumer = eventHubsProperties.buildConsumerProperties(); + AzureEventHubsProperties.Processor processor = eventHubsProperties.buildProcessorProperties(); + + assertNull(eventHubsProperties.getClient().getTransportType()); + assertNull(producer.getClient().getTransportType()); + assertNull(consumer.getClient().getTransportType()); + assertNull(processor.getClient().getTransportType()); + } + + @Test + void defaultProfileCloudTypeIsAzure() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + + AzureEventHubsProperties.Producer producer = eventHubsProperties.buildProducerProperties(); + AzureEventHubsProperties.Consumer consumer = eventHubsProperties.buildConsumerProperties(); + AzureEventHubsProperties.Processor processor = eventHubsProperties.buildProcessorProperties(); + AzureEventHubsProperties.Processor.BlobCheckpointStore checkpointStore = processor.getCheckpointStore(); + + assertNull(eventHubsProperties.getProfile().getCloudType()); + assertNull(producer.getProfile().getCloudType()); + assertNull(consumer.getProfile().getCloudType()); + assertNull(processor.getProfile().getCloudType()); + assertNull(checkpointStore.getProfile().getCloudType()); + } + + @Test + void defaultDomainNameIsAzure() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + + AzureEventHubsProperties.Producer producer = eventHubsProperties.buildProducerProperties(); + AzureEventHubsProperties.Consumer consumer = eventHubsProperties.buildConsumerProperties(); + AzureEventHubsProperties.Processor processor = eventHubsProperties.buildProcessorProperties(); + + assertEquals("servicebus.windows.net", eventHubsProperties.getDomainName()); + assertEquals("servicebus.windows.net", producer.getDomainName()); + assertEquals("servicebus.windows.net", consumer.getDomainName()); + assertEquals("servicebus.windows.net", processor.getDomainName()); + } + + @Test + void childrenWillInheritParent() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + + eventHubsProperties.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); + eventHubsProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + + AzureEventHubsProperties.Producer producer = eventHubsProperties.buildProducerProperties(); + AzureEventHubsProperties.Consumer consumer = eventHubsProperties.buildConsumerProperties(); + AzureEventHubsProperties.Processor processor = eventHubsProperties.buildProcessorProperties(); + AzureEventHubsProperties.Processor.BlobCheckpointStore checkpointStore = processor.getCheckpointStore(); + + assertEquals(AZURE_US_GOVERNMENT, producer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + producer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, producer.getClient().getTransportType()); + + assertEquals(AZURE_US_GOVERNMENT, consumer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + consumer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, consumer.getClient().getTransportType()); + + assertEquals(AZURE_US_GOVERNMENT, processor.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + processor.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, processor.getClient().getTransportType()); + + assertEquals(AZURE_US_GOVERNMENT, checkpointStore.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + checkpointStore.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + } + + @Test + void buildProducerPropertiesUseParent() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + eventHubsProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + eventHubsProperties.setDomainName("parent-domain"); + eventHubsProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureEventHubsProperties.Producer producer = eventHubsProperties.buildProducerProperties(); + assertEquals(AZURE_US_GOVERNMENT, producer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + producer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("parent-domain", producer.getDomainName()); + assertEquals(AmqpTransportType.AMQP, producer.getClient().getTransportType()); + } + + @Test + void buildProducerPropertiesUseChild() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + eventHubsProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + eventHubsProperties.setDomainName("parent-domain"); + eventHubsProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureEventHubsProperties.Producer producerProperties = eventHubsProperties.getProducer(); + producerProperties.setDomainName("child-domain"); + producerProperties.getProfile().setCloudType(AZURE_CHINA); + producerProperties.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); + + AzureEventHubsProperties.Producer producer = eventHubsProperties.buildProducerProperties(); + assertEquals(AZURE_CHINA, producer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_CHINA.getActiveDirectoryEndpoint(), + producer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("child-domain", producer.getDomainName()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, producer.getClient().getTransportType()); + } + + @Test + void buildConsumerPropertiesUseParent() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + eventHubsProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + eventHubsProperties.setDomainName("parent-domain"); + eventHubsProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureEventHubsProperties.Consumer consumer = eventHubsProperties.buildConsumerProperties(); + assertEquals(AZURE_US_GOVERNMENT, consumer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + consumer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("parent-domain", consumer.getDomainName()); + assertEquals(AmqpTransportType.AMQP, consumer.getClient().getTransportType()); + } + + @Test + void buildConsumerPropertiesUseChild() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + eventHubsProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + eventHubsProperties.setDomainName("parent-domain"); + eventHubsProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureEventHubsProperties.Consumer consumerProperties = eventHubsProperties.getConsumer(); + consumerProperties.setDomainName("child-domain"); + consumerProperties.getProfile().setCloudType(AZURE_CHINA); + consumerProperties.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); + + AzureEventHubsProperties.Consumer consumer = eventHubsProperties.buildConsumerProperties(); + assertEquals(AzureProfileOptionsProvider.CloudType.AZURE_CHINA, consumer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_CHINA.getActiveDirectoryEndpoint(), + consumer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("child-domain", consumer.getDomainName()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, consumer.getClient().getTransportType()); + } + + @Test + void buildProcessorPropertiesUseParent() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + eventHubsProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + eventHubsProperties.setDomainName("parent-domain"); + eventHubsProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureEventHubsProperties.Processor processor = eventHubsProperties.buildProcessorProperties(); + assertEquals(AZURE_US_GOVERNMENT, processor.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + processor.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("parent-domain", processor.getDomainName()); + + assertEquals(AZURE_US_GOVERNMENT, processor.getCheckpointStore().getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + processor.getCheckpointStore().getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals(AmqpTransportType.AMQP, processor.getClient().getTransportType()); + } + + @Test + void buildProcessorPropertiesUseChild() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + eventHubsProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + eventHubsProperties.setDomainName("parent-domain"); + eventHubsProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureEventHubsProperties.Processor processorProperties = eventHubsProperties.getProcessor(); + processorProperties.getProfile().setCloudType(AZURE_CHINA); + processorProperties.setDomainName("child-domain"); + processorProperties.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); + + AzureEventHubsProperties.Processor processor = eventHubsProperties.buildProcessorProperties(); + assertEquals(AZURE_CHINA, processor.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_CHINA.getActiveDirectoryEndpoint(), + processor.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("child-domain", processor.getDomainName()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, processor.getClient().getTransportType()); + } + + @Test + void buildCheckpointStorePropertiesUseParent() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + eventHubsProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + eventHubsProperties.setDomainName("parent-domain"); + + AzureEventHubsProperties.Processor processor = eventHubsProperties.buildProcessorProperties(); + + assertEquals(AZURE_US_GOVERNMENT, processor.getCheckpointStore().getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + processor.getCheckpointStore().getProfile().getEnvironment().getActiveDirectoryEndpoint()); + } + + @Test + void buildCheckpointStorePropertiesUseChild() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + eventHubsProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + eventHubsProperties.setDomainName("parent-domain"); + + AzureEventHubsProperties.Processor processorProperties = eventHubsProperties.getProcessor(); + processorProperties.getProfile().setCloudType(AZURE_CHINA); + processorProperties.setDomainName("child-domain"); + + AzureEventHubsProperties.Processor processor = eventHubsProperties.buildProcessorProperties(); + + assertEquals(AZURE_CHINA, processor.getCheckpointStore().getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_CHINA.getActiveDirectoryEndpoint(), + processor.getCheckpointStore().getProfile().getEnvironment().getActiveDirectoryEndpoint()); + } + + @Test + void buildCheckpointStorePropertiesUseCheckpointStore() { + AzureEventHubsProperties eventHubsProperties = new AzureEventHubsProperties(); + eventHubsProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + eventHubsProperties.setDomainName("parent-domain"); + + AzureEventHubsProperties.Processor processorProperties = eventHubsProperties.getProcessor(); + processorProperties.getProfile().setCloudType(AZURE_CHINA); + processorProperties.setDomainName("child-domain"); + + AzureEventHubsProperties.Processor.BlobCheckpointStore checkpointStore = processorProperties.getCheckpointStore(); + checkpointStore.getProfile().setCloudType(AZURE); + + AzureEventHubsProperties.Processor processor = eventHubsProperties.buildProcessorProperties(); + + assertEquals(AZURE, processor.getCheckpointStore().getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE.getActiveDirectoryEndpoint(), + processor.getCheckpointStore().getProfile().getEnvironment().getActiveDirectoryEndpoint()); + } +} diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusPropertiesTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusPropertiesTest.java new file mode 100644 index 0000000000000..819af431db328 --- /dev/null +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/servicebus/properties/AzureServiceBusPropertiesTest.java @@ -0,0 +1,190 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.spring.cloud.autoconfigure.implementation.servicebus.properties; + +import com.azure.core.amqp.AmqpTransportType; +import com.azure.core.management.AzureEnvironment; +import com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider; +import org.junit.jupiter.api.Test; + +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_CHINA; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_US_GOVERNMENT; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +class AzureServiceBusPropertiesTest { + + @Test + void defaultAmqpTransportTypeIsNull() { + AzureServiceBusProperties serviceBusProperties = new AzureServiceBusProperties(); + + AzureServiceBusProperties.Producer producer = serviceBusProperties.buildProducerProperties(); + AzureServiceBusProperties.Consumer consumer = serviceBusProperties.buildConsumerProperties(); + AzureServiceBusProperties.Processor processor = serviceBusProperties.buildProcessorProperties(); + + assertNull(serviceBusProperties.getClient().getTransportType()); + assertNull(producer.getClient().getTransportType()); + assertNull(consumer.getClient().getTransportType()); + assertNull(processor.getClient().getTransportType()); + } + + @Test + void defaultProfileCloudTypeIsAzure() { + AzureServiceBusProperties serviceBusProperties = new AzureServiceBusProperties(); + + AzureServiceBusProperties.Producer producer = serviceBusProperties.buildProducerProperties(); + AzureServiceBusProperties.Consumer consumer = serviceBusProperties.buildConsumerProperties(); + AzureServiceBusProperties.Processor processor = serviceBusProperties.buildProcessorProperties(); + + assertNull(serviceBusProperties.getProfile().getCloudType()); + assertNull(producer.getProfile().getCloudType()); + assertNull(consumer.getProfile().getCloudType()); + assertNull(processor.getProfile().getCloudType()); + } + + @Test + void defaultDomainNameIsAzure() { + AzureServiceBusProperties serviceBusProperties = new AzureServiceBusProperties(); + + AzureServiceBusProperties.Producer producer = serviceBusProperties.buildProducerProperties(); + AzureServiceBusProperties.Consumer consumer = serviceBusProperties.buildConsumerProperties(); + AzureServiceBusProperties.Processor processor = serviceBusProperties.buildProcessorProperties(); + + assertEquals("servicebus.windows.net", serviceBusProperties.getDomainName()); + assertEquals("servicebus.windows.net", producer.getDomainName()); + assertEquals("servicebus.windows.net", consumer.getDomainName()); + assertEquals("servicebus.windows.net", processor.getDomainName()); + } + + @Test + void childrenWillInheritParent() { + AzureServiceBusProperties serviceBusProperties = new AzureServiceBusProperties(); + + serviceBusProperties.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); + serviceBusProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + + AzureServiceBusProperties.Producer producer = serviceBusProperties.buildProducerProperties(); + AzureServiceBusProperties.Consumer consumer = serviceBusProperties.buildConsumerProperties(); + AzureServiceBusProperties.Processor processor = serviceBusProperties.buildProcessorProperties(); + + assertEquals(AZURE_US_GOVERNMENT, producer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + producer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, producer.getClient().getTransportType()); + + assertEquals(AZURE_US_GOVERNMENT, consumer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + consumer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, consumer.getClient().getTransportType()); + + assertEquals(AZURE_US_GOVERNMENT, processor.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + processor.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, processor.getClient().getTransportType()); + } + + @Test + void buildProducerPropertiesUseParent() { + AzureServiceBusProperties serviceBusProperties = new AzureServiceBusProperties(); + serviceBusProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + serviceBusProperties.setDomainName("parent-domain"); + serviceBusProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureServiceBusProperties.Producer producer = serviceBusProperties.buildProducerProperties(); + assertEquals(AZURE_US_GOVERNMENT, producer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + producer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("parent-domain", producer.getDomainName()); + assertEquals(AmqpTransportType.AMQP, producer.getClient().getTransportType()); + } + + @Test + void buildProducerPropertiesUseChild() { + AzureServiceBusProperties serviceBusProperties = new AzureServiceBusProperties(); + serviceBusProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + serviceBusProperties.setDomainName("parent-domain"); + serviceBusProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureServiceBusProperties.Producer producerProperties = serviceBusProperties.getProducer(); + producerProperties.setDomainName("child-domain"); + producerProperties.getProfile().setCloudType(AZURE_CHINA); + producerProperties.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); + + AzureServiceBusProperties.Producer producer = serviceBusProperties.buildProducerProperties(); + assertEquals(AZURE_CHINA, producer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_CHINA.getActiveDirectoryEndpoint(), + producer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("child-domain", producer.getDomainName()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, producer.getClient().getTransportType()); + } + + @Test + void buildConsumerPropertiesUseParent() { + AzureServiceBusProperties serviceBusProperties = new AzureServiceBusProperties(); + serviceBusProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + serviceBusProperties.setDomainName("parent-domain"); + serviceBusProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureServiceBusProperties.Consumer consumer = serviceBusProperties.buildConsumerProperties(); + assertEquals(AZURE_US_GOVERNMENT, consumer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + consumer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("parent-domain", consumer.getDomainName()); + assertEquals(AmqpTransportType.AMQP, consumer.getClient().getTransportType()); + } + + @Test + void buildConsumerPropertiesUseChild() { + AzureServiceBusProperties serviceBusProperties = new AzureServiceBusProperties(); + serviceBusProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + serviceBusProperties.setDomainName("parent-domain"); + serviceBusProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureServiceBusProperties.Consumer consumerProperties = serviceBusProperties.getConsumer(); + consumerProperties.setDomainName("child-domain"); + consumerProperties.getProfile().setCloudType(AZURE_CHINA); + consumerProperties.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); + + AzureServiceBusProperties.Consumer consumer = serviceBusProperties.buildConsumerProperties(); + assertEquals(AzureProfileOptionsProvider.CloudType.AZURE_CHINA, consumer.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_CHINA.getActiveDirectoryEndpoint(), + consumer.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("child-domain", consumer.getDomainName()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, consumer.getClient().getTransportType()); + } + + @Test + void buildProcessorPropertiesUseParent() { + AzureServiceBusProperties serviceBusProperties = new AzureServiceBusProperties(); + serviceBusProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + serviceBusProperties.setDomainName("parent-domain"); + serviceBusProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureServiceBusProperties.Processor processor = serviceBusProperties.buildProcessorProperties(); + assertEquals(AZURE_US_GOVERNMENT, processor.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + processor.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("parent-domain", processor.getDomainName()); + } + + @Test + void buildProcessorPropertiesUseChild() { + AzureServiceBusProperties serviceBusProperties = new AzureServiceBusProperties(); + serviceBusProperties.getProfile().setCloudType(AZURE_US_GOVERNMENT); + serviceBusProperties.setDomainName("parent-domain"); + serviceBusProperties.getClient().setTransportType(AmqpTransportType.AMQP); + + AzureServiceBusProperties.Processor processorProperties = serviceBusProperties.getProcessor(); + processorProperties.getProfile().setCloudType(AZURE_CHINA); + processorProperties.setDomainName("child-domain"); + processorProperties.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); + + AzureServiceBusProperties.Processor processor = serviceBusProperties.buildProcessorProperties(); + assertEquals(AZURE_CHINA, processor.getProfile().getCloudType()); + assertEquals(AzureEnvironment.AZURE_CHINA.getActiveDirectoryEndpoint(), + processor.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + assertEquals("child-domain", processor.getDomainName()); + assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, processor.getClient().getTransportType()); + } +} diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/implementation/factory/AbstractAzureAmqpClientBuilderFactory.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/implementation/factory/AbstractAzureAmqpClientBuilderFactory.java index 9bc0e294f2b3b..1f7a02cdddcc0 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/implementation/factory/AbstractAzureAmqpClientBuilderFactory.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/implementation/factory/AbstractAzureAmqpClientBuilderFactory.java @@ -82,7 +82,9 @@ protected void configureAmqpTransportProperties(T builder) { final ClientOptionsProvider.AmqpClientOptions amqpClient; if (client instanceof ClientOptionsProvider.AmqpClientOptions) { amqpClient = (ClientOptionsProvider.AmqpClientOptions) client; - consumeAmqpTransportType().accept(builder, amqpClient.getTransportType()); + if (amqpClient.getTransportType() != null) { + consumeAmqpTransportType().accept(builder, amqpClient.getTransportType()); + } } } diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/implementation/util/AzurePropertiesUtils.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/implementation/util/AzurePropertiesUtils.java index c1e2e19a54f85..dba35bdbe2f27 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/implementation/util/AzurePropertiesUtils.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/implementation/util/AzurePropertiesUtils.java @@ -27,6 +27,8 @@ private AzurePropertiesUtils() { /** * Copy common properties from source {@link AzureProperties} object to target {@link T} object. + * If a field x.y.z exists in both source and target object, the source value will override the target value. + * * @param source The source {@link AzureProperties} object. * @param target The target object. * @param The type of the target that extends AzureProperties. @@ -65,7 +67,7 @@ public static void copyAzureCommonPropertiesIgnoreNu copyPropertiesIgnoreNull(source.getProxy(), target.getProxy()); copyPropertiesIgnoreNull(source.getProfile(), target.getProfile()); - BeanUtils.copyProperties(source.getProfile().getEnvironment(), target.getProfile().getEnvironment()); + copyPropertiesIgnoreNull(source.getProfile().getEnvironment(), target.getProfile().getEnvironment()); copyPropertiesIgnoreNull(source.getCredential(), target.getCredential()); if (source instanceof RetryOptionsProvider && target instanceof RetryOptionsProvider) { diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/client/AmqpClientProperties.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/client/AmqpClientProperties.java index 248151f935e47..65af9595b9246 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/client/AmqpClientProperties.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/client/AmqpClientProperties.java @@ -14,7 +14,7 @@ public final class AmqpClientProperties extends ClientProperties implements Clie /** * Transport type for AMQP-based client. */ - private AmqpTransportType transportType = AmqpTransportType.AMQP; + private AmqpTransportType transportType; /** * Get the transport type. diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureEnvironmentProperties.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureEnvironmentProperties.java index 52ca76cc6cee8..e0eada67a3e96 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureEnvironmentProperties.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureEnvironmentProperties.java @@ -91,7 +91,7 @@ public class AzureEnvironmentProperties implements AzureProfileOptionsProvider.A * Create an {@link AzureEnvironmentProperties} instance with default value. */ public AzureEnvironmentProperties() { - + this(null); } /** diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureProfileOptionsAdapter.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureProfileOptionsAdapter.java index 948be9cd2b778..373db10a08e9f 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureProfileOptionsAdapter.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureProfileOptionsAdapter.java @@ -6,6 +6,7 @@ import com.azure.core.management.AzureEnvironment; import com.azure.spring.cloud.core.implementation.util.AzurePropertiesUtils; import com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider; +import org.springframework.beans.BeanUtils; /** * Skeleton implementation of a {@link AzureProfileOptionsProvider.ProfileOptions}. @@ -16,8 +17,12 @@ public abstract class AzureProfileOptionsAdapter implements AzureProfileOptionsP * Change the environment according to the cloud type set. */ protected void changeEnvironmentAccordingToCloud() { - AzureProfileOptionsProvider.AzureEnvironmentOptions defaultEnvironment = decideAzureEnvironment(this.getCloudType()); - AzurePropertiesUtils.copyPropertiesIgnoreNull(defaultEnvironment, this.getEnvironment()); + if (this.getCloudType() == null) { + BeanUtils.copyProperties(new AzureEnvironmentProperties(), this.getEnvironment()); + } else { + AzureProfileOptionsProvider.AzureEnvironmentOptions defaultEnvironment = decideAzureEnvironment(this.getCloudType()); + AzurePropertiesUtils.copyPropertiesIgnoreNull(defaultEnvironment, this.getEnvironment()); + } } /** diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureProfileProperties.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureProfileProperties.java index 600590882b92b..5101a12e6a370 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureProfileProperties.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/cloud/core/properties/profile/AzureProfileProperties.java @@ -13,15 +13,7 @@ public final class AzureProfileProperties extends AzureProfileOptionsAdapter { private String tenantId; private String subscriptionId; private AzureProfileOptionsProvider.CloudType cloudType; - private final AzureEnvironmentProperties environment; - - /** - * Construct an {@link AzureProfileProperties} instance with default value. - */ - public AzureProfileProperties() { - environment = new AzureEnvironmentProperties(); - setCloudType(AzureProfileOptionsProvider.CloudType.AZURE); - } + private final AzureEnvironmentProperties environment = new AzureEnvironmentProperties(); @Override public String getTenantId() { diff --git a/sdk/spring/spring-cloud-azure-core/src/test/java/com/azure/spring/cloud/core/util/AzurePropertiesUtilsTests.java b/sdk/spring/spring-cloud-azure-core/src/test/java/com/azure/spring/cloud/core/util/AzurePropertiesUtilsTests.java index 52b1b80a43ff6..661467b4dd2c3 100644 --- a/sdk/spring/spring-cloud-azure-core/src/test/java/com/azure/spring/cloud/core/util/AzurePropertiesUtilsTests.java +++ b/sdk/spring/spring-cloud-azure-core/src/test/java/com/azure/spring/cloud/core/util/AzurePropertiesUtilsTests.java @@ -366,6 +366,7 @@ void testMergePropertiesObjectWithSameFieldsSetShouldTakeLater() { void testCopyPropertiesIgnoreNullToObjectWithDifferentFieldsSetShouldMerge() { AzurePropertiesA source = new AzurePropertiesA(); source.credential.setClientId("client-id-A"); + source.getProfile().setCloudType(AZURE); AzurePropertiesB target = new AzurePropertiesB(); target.credential.setClientSecret("client-secret-B"); @@ -400,6 +401,7 @@ void testCopyPropertiesIgnoreNullToObjectWithDifferentFieldsSetShouldMerge() { void testCopyPropertiesSourceNotChanged() { AzurePropertiesA source = new AzurePropertiesA(); source.credential.setClientId("client-id-A"); + source.getProfile().setCloudType(AZURE); AzurePropertiesB target = new AzurePropertiesB(); diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/ApplicationConfiguration.java b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/ApplicationConfiguration.java index d9ed4924e0109..cf2a1f2b3918c 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/ApplicationConfiguration.java +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/ApplicationConfiguration.java @@ -4,6 +4,8 @@ import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Import; + /** * {@link EnableAutoConfiguration} will enable the autoconfiguration classes @@ -13,5 +15,7 @@ */ @EnableAutoConfiguration @SpringBootConfiguration +@Import(AzureCloudTypeConfiguration.class) public class ApplicationConfiguration { + } diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/AzureCloudTypeConfiguration.java b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/AzureCloudTypeConfiguration.java new file mode 100644 index 0000000000000..5c0a3ceba3708 --- /dev/null +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/AzureCloudTypeConfiguration.java @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.spring.cloud.integration.tests; + +import com.azure.spring.cloud.autoconfigure.context.AzureGlobalProperties; +import com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.EnvironmentAware; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; + +@Configuration +public class AzureCloudTypeConfiguration { + @Bean + static AzureGlobalPropertiesBeanPostProcessor azureGlobalPropertiesBeanPostProcessor() { + return new AzureGlobalPropertiesBeanPostProcessor(); + } + + static class AzureGlobalPropertiesBeanPostProcessor implements BeanPostProcessor, EnvironmentAware { + + private static final Logger LOGGER = LoggerFactory.getLogger(AzureGlobalPropertiesBeanPostProcessor.class); + private Environment environment; + + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + if (bean instanceof AzureGlobalProperties) { + AzureGlobalProperties azureGlobalProperties = (AzureGlobalProperties) bean; + + String authorityHost = this.environment.getProperty("AZURE_AUTHORITY_HOST"); + + LOGGER.info("The set AZURE_AUTHORITY_HOST is [{}]", authorityHost); + if (authorityHost.startsWith("https://login.microsoftonline.us")) { + azureGlobalProperties.getProfile().setCloudType(AzureProfileOptionsProvider.CloudType.AZURE_US_GOVERNMENT); + LOGGER.info("US Gov environment set."); + } else if (authorityHost.startsWith("https://login.chinacloudapi.cn")) { + azureGlobalProperties.getProfile().setCloudType(AzureProfileOptionsProvider.CloudType.AZURE_CHINA); + LOGGER.info("China environment set."); + } else if (authorityHost.startsWith("https://login.microsoftonline.com")) { + azureGlobalProperties.getProfile().setCloudType(AzureProfileOptionsProvider.CloudType.AZURE); + LOGGER.info("Azure Cloud environment set."); + } else { + azureGlobalProperties.getProfile().setCloudType(AzureProfileOptionsProvider.CloudType.AZURE); + LOGGER.info("Use Azure Global as the default cloud. "); + } + } + return bean; + } + + @Override + public void setEnvironment(Environment environment) { + this.environment = environment; + } + } +} diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderBatchModeIT.java b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderBatchModeIT.java index 558413acd2487..0c00544f38acb 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderBatchModeIT.java +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderBatchModeIT.java @@ -12,7 +12,6 @@ import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import reactor.core.publisher.Flux; import reactor.core.publisher.Sinks; diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderConsumeErrorIT.java b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderConsumeErrorIT.java index 85074560a20c9..498cb481f0730 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderConsumeErrorIT.java +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderConsumeErrorIT.java @@ -17,7 +17,6 @@ import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderManualModeIT.java b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderManualModeIT.java index da32f820a5fd1..0d531b2bf2005 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderManualModeIT.java +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderManualModeIT.java @@ -15,7 +15,6 @@ import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import reactor.core.publisher.Flux; import reactor.core.publisher.Sinks; diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderRecordModeIT.java b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderRecordModeIT.java index b4d9c05161e48..386a2391be23a 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderRecordModeIT.java +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderRecordModeIT.java @@ -12,7 +12,6 @@ import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import reactor.core.publisher.Flux; import reactor.core.publisher.Sinks; diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderSyncModeIT.java b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderSyncModeIT.java index b724e91df447c..2266cfed07d65 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderSyncModeIT.java +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/eventhubs/binder/EventHubsBinderSyncModeIT.java @@ -12,7 +12,6 @@ import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import reactor.core.publisher.Flux; import reactor.core.publisher.Sinks; diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/ServiceBusIT.java b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/ServiceBusIT.java index 8417f160716b3..5acd956b7710c 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/ServiceBusIT.java +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/ServiceBusIT.java @@ -76,9 +76,9 @@ public void testServiceBusOperation() throws InterruptedException { Assertions.assertEquals(DATA1, message.getBody().toString()); receiverClient.complete(message); } - processorClient.start(); senderClient.sendMessage(new ServiceBusMessage(DATA2)); senderClient.close(); + processorClient.start(); Assertions.assertTrue(processorClient.isRunning()); LATCH.await(15, TimeUnit.SECONDS); Assertions.assertEquals(DATA2, MESSAGE); diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/MultiServiceBusQueueAndTopicBinderIT.java b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/ServiceBusMultiBindersIT.java similarity index 90% rename from sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/MultiServiceBusQueueAndTopicBinderIT.java rename to sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/ServiceBusMultiBindersIT.java index 0dc9c89852651..35513d7d57dc0 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/MultiServiceBusQueueAndTopicBinderIT.java +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/ServiceBusMultiBindersIT.java @@ -25,9 +25,9 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) @ActiveProfiles("servicebus-binder-multi") -class MultiServiceBusQueueAndTopicBinderIT { +class ServiceBusMultiBindersIT { - private static final Logger LOGGER = LoggerFactory.getLogger(MultiServiceBusQueueAndTopicBinderIT.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ServiceBusMultiBindersIT.class); private static String message = UUID.randomUUID().toString(); @@ -58,7 +58,7 @@ Supplier>> queueSupply(Sinks.Many> manyQueu Consumer> queueConsume() { return message -> { LOGGER.info("Test queue new message received: '{}'", message); - if (message.getPayload().equals(MultiServiceBusQueueAndTopicBinderIT.message)) { + if (message.getPayload().equals(ServiceBusMultiBindersIT.message)) { latch.countDown(); } }; @@ -84,7 +84,7 @@ Supplier>> topicSupply(Sinks.Many> manyTopi Consumer> topicConsume() { return message -> { LOGGER.info("Test topic new message received: '{}'", message); - if (message.getPayload().equals(MultiServiceBusQueueAndTopicBinderIT.message)) { + if (message.getPayload().equals(ServiceBusMultiBindersIT.message)) { latch.countDown(); } }; @@ -101,7 +101,7 @@ void testMultiServiceBusSendAndReceiveMessage() throws InterruptedException { LOGGER.info("Send a message:" + message + " to the topic."); manyTopic.emitNext(genericMessage, Sinks.EmitFailureHandler.FAIL_FAST); - assertThat(MultiServiceBusQueueAndTopicBinderIT.latch.await(15, TimeUnit.SECONDS)).isTrue(); + assertThat(ServiceBusMultiBindersIT.latch.await(15, TimeUnit.SECONDS)).isTrue(); LOGGER.info("MultiServiceBusQueueAndTopicBinderIT end."); } diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/SingleServiceBusQueueAndTopicBinderIT.java b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/ServiceBusSingleBinderIT.java similarity index 90% rename from sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/SingleServiceBusQueueAndTopicBinderIT.java rename to sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/ServiceBusSingleBinderIT.java index 9fe8862968fd7..1605b7be2cd4a 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/SingleServiceBusQueueAndTopicBinderIT.java +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/java/com/azure/spring/cloud/integration/tests/servicebus/binder/ServiceBusSingleBinderIT.java @@ -25,9 +25,9 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) @ActiveProfiles("servicebus-binder-single") -class SingleServiceBusQueueAndTopicBinderIT { +class ServiceBusSingleBinderIT { - private static final Logger LOGGER = LoggerFactory.getLogger(SingleServiceBusQueueAndTopicBinderIT.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ServiceBusSingleBinderIT.class); private static final String MESSAGE = UUID.randomUUID().toString(); @@ -58,7 +58,7 @@ Supplier>> queueSupply(Sinks.Many> manyQueu Consumer> queueConsume() { return message -> { LOGGER.info("---Test queue new message received: '{}'", message); - if (message.getPayload().equals(SingleServiceBusQueueAndTopicBinderIT.MESSAGE)) { + if (message.getPayload().equals(ServiceBusSingleBinderIT.MESSAGE)) { LATCH.countDown(); } }; @@ -84,7 +84,7 @@ Supplier>> topicSupply(Sinks.Many> manyTopi Consumer> topicConsume() { return message -> { LOGGER.info("---Test topic new message received: '{}'", message); - if (message.getPayload().equals(SingleServiceBusQueueAndTopicBinderIT.MESSAGE)) { + if (message.getPayload().equals(ServiceBusSingleBinderIT.MESSAGE)) { LATCH.countDown(); } }; @@ -101,7 +101,7 @@ void testSingleServiceBusSendAndReceiveMessage() throws InterruptedException { LOGGER.info("Send a message:" + MESSAGE + " to the topic."); manyTopic.emitNext(genericMessage, Sinks.EmitFailureHandler.FAIL_FAST); - assertThat(SingleServiceBusQueueAndTopicBinderIT.LATCH.await(15, TimeUnit.SECONDS)).isTrue(); + assertThat(ServiceBusSingleBinderIT.LATCH.await(15, TimeUnit.SECONDS)).isTrue(); LOGGER.info("SingleServiceBusQueueAndTopicBinderIT end."); } diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application-servicebus-binder-multi.yml b/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application-servicebus-binder-multi.yml index 332071d9cb8d7..eb1ec67336c0c 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application-servicebus-binder-multi.yml +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application-servicebus-binder-multi.yml @@ -19,8 +19,11 @@ spring: servicebus-1: type: servicebus default-candidate: true + inherit-environment: true environment: spring: + main: + sources: com.azure.spring.cloud.integration.tests.AzureCloudTypeConfiguration cloud: azure: servicebus: @@ -30,6 +33,8 @@ spring: default-candidate: false environment: spring: + main: + sources: com.azure.spring.cloud.integration.tests.AzureCloudTypeConfiguration cloud: azure: servicebus: diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application-servicebus-binder-single.yml b/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application-servicebus-binder-single.yml index 923e963d9a8ca..47e927dfe74a1 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application-servicebus-binder-single.yml +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application-servicebus-binder-single.yml @@ -1,6 +1,10 @@ spring: cloud: + azure: + servicebus: + namespace: ${AZURE_SERVICE_BUS_NAMESPACE1} stream: + default-binder: servicebus function: definition: queueConsume;queueSupply;topicConsume;topicSupply; bindings: @@ -10,29 +14,22 @@ spring: topicSupply-out-0: destination: topic1 queueConsume-in-0: - binder: servicebus-2 destination: queue1 queueSupply-out-0: - binder: servicebus-2 destination: queue1 - binders: - servicebus-1: - type: servicebus - default-candidate: true - environment: - spring: - cloud: - azure: - servicebus: - namespace: ${AZURE_SERVICE_BUS_NAMESPACE1} - entity-type: topic - servicebus-2: - type: servicebus - default-candidate: false - environment: - spring: - cloud: - azure: - servicebus: - namespace: ${AZURE_SERVICE_BUS_NAMESPACE1} - entity-type: queue + servicebus: + bindings: + queueConsume-in-0: + consumer: + entity-type: queue + topicConsume-in-0: + consumer: + entity-type: topic + topicSupply-out-0: + producer: + entity-type: topic + queueSupply-out-0: + producer: + entity-type: queue + + diff --git a/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application.yml b/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application.yml index 88f3ad8aefc00..ac3f8d63753da 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application.yml +++ b/sdk/spring/spring-cloud-azure-integration-tests/src/test/resources/application.yml @@ -11,6 +11,10 @@ spring: client-secret: ${AZURE_SPRING_CLIENT_SECRET} profile: tenant-id: ${AZURE_SPRING_TENANT_ID} + eventhubs: + domain-name: ${AZURE_SERVICE_BUS_DOMAIN_NAME} + servicebus: + domain-name: ${AZURE_SERVICE_BUS_DOMAIN_NAME} logging: level: com.azure: diff --git a/sdk/spring/spring-cloud-azure-integration-tests/test-resources/appconfiguration/test-resources.json b/sdk/spring/spring-cloud-azure-integration-tests/test-resources/appconfiguration/test-resources.json index ee0a9931990b3..a3cfb932f4a20 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/test-resources/appconfiguration/test-resources.json +++ b/sdk/spring/spring-cloud-azure-integration-tests/test-resources/appconfiguration/test-resources.json @@ -12,12 +12,17 @@ "baseName": { "defaultValue": "[resourceGroup().name]", "type": "String" + }, + "azConfigEndpointSuffix": { + "defaultValue": ".azconfig.io", + "type": "string" } }, "variables": { "configurationStoresName": "[concat(parameters('baseName'),'-test-appconfiguration')]", - "azureManagedApplicationContributorRoleRoleId": "/subscriptions/[parameters('subscriptionId')]/providers/Microsoft.Authorization/roleDefinitions/641177b8-a67a-45b9-a033-47bc880bb21e", - "location": "[resourceGroup().location]" + "azureAppConfigurationDataOwnerRoleId": "/subscriptions/[parameters('subscriptionId')]/providers/Microsoft.Authorization/roleDefinitions/5ae67dd6-50cb-40e7-96ff-dc2bfa4b606b", + "location": "[resourceGroup().location]", + "endpointValue": "[concat('https://', variables('configurationStoresName'), parameters('azConfigEndpointSuffix'))]" }, "resources": [ { @@ -37,9 +42,9 @@ { "type": "Microsoft.Authorization/roleAssignments", "apiVersion": "2020-10-01-preview", - "name": "[guid(concat(variables('azureManagedApplicationContributorRoleRoleId'), parameters('baseName')))]", + "name": "[guid(concat(variables('azureAppConfigurationDataOwnerRoleId'), parameters('baseName')))]", "properties": { - "roleDefinitionId": "[variables('azureManagedApplicationContributorRoleRoleId')]", + "roleDefinitionId": "[variables('azureAppConfigurationDataOwnerRoleId')]", "principalId": "[parameters('testApplicationOid')]" } } @@ -47,7 +52,7 @@ "outputs": { "AZURE_APPCONFIGURATION_ENDPOINT": { "type": "string", - "value": "[reference(variables('configurationStoresName')).endpoint]" + "value": "[variables('endpointValue')]" } } } diff --git a/sdk/spring/spring-cloud-azure-integration-tests/test-resources/cosmos/test-resources.json b/sdk/spring/spring-cloud-azure-integration-tests/test-resources/cosmos/test-resources.json index b66a62aad401c..6ae1b93ccb125 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/test-resources/cosmos/test-resources.json +++ b/sdk/spring/spring-cloud-azure-integration-tests/test-resources/cosmos/test-resources.json @@ -5,17 +5,13 @@ "testApplicationOid": { "type": "String" }, - "subscriptionId": { - "defaultValue": "[subscription().subscriptionId]", - "type": "string" - }, "baseName": { "defaultValue": "[resourceGroup().name]", "type": "String" } }, "variables": { - "azureDatabaseAccountsName": "[concat(parameters('baseName'),'-test-cosmos')]", + "azureDatabaseAccountsName": "[concat(parameters('baseName'),'-cosmos')]", "azureCosmosSpringDataDatabaseName": "TestSpringData", "azureCosmosRoleId": "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions', variables('azureDatabaseAccountsName'), '00000000-0000-0000-0000-000000000002')]", "location": "[resourceGroup().location]" diff --git a/sdk/spring/spring-cloud-azure-integration-tests/test-resources/keyvault/test-resources.json b/sdk/spring/spring-cloud-azure-integration-tests/test-resources/keyvault/test-resources.json index b80fcec661c25..0173d68e3ba6a 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/test-resources/keyvault/test-resources.json +++ b/sdk/spring/spring-cloud-azure-integration-tests/test-resources/keyvault/test-resources.json @@ -12,11 +12,15 @@ "baseName": { "defaultValue": "[resourceGroup().name]", "type": "String" + }, + "keyVaultEndpointSuffix": { + "type": "String", + "defaultValue": ".vault.azure.net" } }, "variables": { "azureKeyVaultName": "[parameters('baseName')]", - "azureKeyVaultUri": "[concat('https://', variables('azureKeyVaultName'), '.vault.azure.net/')]", + "azureKeyVaultUri": "[concat('https://', variables('azureKeyVaultName'), parameters('keyVaultEndpointSuffix'), '/')]", "location": "[resourceGroup().location]" }, "resources": [ @@ -51,7 +55,6 @@ "enableSoftDelete": true, "softDeleteRetentionInDays": 90, "enableRbacAuthorization": false, - "vaultUri": "[variables('azureKeyVaultUri')]", "provisioningState": "Succeeded", "publicNetworkAccess": "Enabled" } diff --git a/sdk/spring/spring-cloud-azure-integration-tests/test-resources/servicebus/test-resources.json b/sdk/spring/spring-cloud-azure-integration-tests/test-resources/servicebus/test-resources.json index 920212082c975..3abb26f20c6fd 100644 --- a/sdk/spring/spring-cloud-azure-integration-tests/test-resources/servicebus/test-resources.json +++ b/sdk/spring/spring-cloud-azure-integration-tests/test-resources/servicebus/test-resources.json @@ -22,6 +22,10 @@ "baseName": { "defaultValue": "[resourceGroup().name]", "type": "String" + }, + "serviceBusEndpointSuffix": { + "type": "String", + "defaultValue": ".servicebus.windows.net" } }, "variables": { @@ -423,6 +427,10 @@ "AZURE_SERVICE_BUS_NAMESPACE3": { "type": "string", "value": "[variables('azureServiceBusNamespaceName_3')]" + }, + "AZURE_SERVICE_BUS_DOMAIN_NAME": { + "type": "string", + "value": "[substring(parameters('serviceBusEndpointSuffix'), 1)]" } } } diff --git a/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/cloud/service/implementation/AzureAmqpClientBuilderFactoryBaseTests.java b/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/cloud/service/implementation/AzureAmqpClientBuilderFactoryBaseTests.java index 395d6873398f2..7ec4f6c9374b1 100644 --- a/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/cloud/service/implementation/AzureAmqpClientBuilderFactoryBaseTests.java +++ b/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/cloud/service/implementation/AzureAmqpClientBuilderFactoryBaseTests.java @@ -3,6 +3,7 @@ package com.azure.spring.cloud.service.implementation; +import com.azure.core.amqp.AmqpTransportType; import com.azure.spring.cloud.core.implementation.factory.AbstractAzureAmqpClientBuilderFactory; import com.azure.spring.cloud.core.implementation.properties.AzureAmqpSdkProperties; import com.azure.spring.cloud.core.properties.proxy.AmqpProxyProperties; @@ -70,6 +71,7 @@ void exponentialRetrySettingsCanWork() { @Test void transportTypeConfigured() { P properties = createMinimalServiceProperties(); + properties.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); final F builderFactory = createClientBuilderFactoryWithMockBuilder(properties); final B builder = builderFactory.build(); buildClient(builder); diff --git a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs-core/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/core/properties/EventHubsConsumerPropertiesTests.java b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs-core/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/core/properties/EventHubsConsumerPropertiesTests.java index f4f9c1ab3ea05..9fb9a15176bf8 100644 --- a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs-core/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/core/properties/EventHubsConsumerPropertiesTests.java +++ b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs-core/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/core/properties/EventHubsConsumerPropertiesTests.java @@ -4,12 +4,13 @@ package com.azure.spring.cloud.stream.binder.eventhubs.core.properties; import com.azure.messaging.eventhubs.LoadBalancingStrategy; +import com.azure.spring.cloud.service.eventhubs.properties.LoadBalancingProperties; import com.azure.spring.messaging.eventhubs.core.checkpoint.CheckpointConfig; import com.azure.spring.messaging.eventhubs.core.checkpoint.CheckpointMode; -import com.azure.spring.cloud.service.eventhubs.properties.LoadBalancingProperties; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static com.azure.spring.cloud.stream.binder.eventhubs.core.properties.EventHubsProducerPropertiesTests.CONNECTION_STRING; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -58,4 +59,71 @@ void otherDefaults() { assertNotNull(consumerProperties.getInitialPartitionEventPosition()); assertNotNull(consumerProperties.getBatch()); } + @Test + void domainNameDefaultsToNull() { + assertNull(consumerProperties.getDomainName()); + } + + @Test + void customDomainNameShouldSet() { + consumerProperties.setDomainName("new.servicebus.windows.net"); + assertEquals("new.servicebus.windows.net", consumerProperties.getDomainName()); + } + + @Test + void getFqdnWhenNamespaceIsNullButConnectionStringIsNot() { + consumerProperties.setConnectionString(CONNECTION_STRING); + assertEquals("test.servicebus.windows.net", consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnWhenNamespaceAndDomainNameAreNotNull() { + consumerProperties.setNamespace("dev-namespace"); + consumerProperties.setDomainName("servicebus.windows.net"); + assertEquals("dev-namespace.servicebus.windows.net", consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnWhenNamespaceAndDomainAreNull() { + assertNull(consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnWhenNamespaceIsNullButDomainNameIsNot() { + consumerProperties.setDomainName("servicebus.windows.net"); + assertNull(consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnWhenDomainNameIsNullButNamespaceIsNot() { + consumerProperties.setNamespace("test"); + assertNull(consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnReturnNullWhenNamespaceAndConnectionStringAreNull() { + assertNull(consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void amqpTransportTypeDefaultIsNull() { + assertNull(consumerProperties.getClient().getTransportType()); + } + + @Test + void getEventHubNameWhenNamespaceIsNull() { + consumerProperties.setConnectionString(CONNECTION_STRING); + assertEquals("testeh", consumerProperties.getEventHubName()); + } + + @Test + void getEventHubNameWhenNamespaceIsNotNull() { + consumerProperties.setEventHubName("test"); + assertEquals("test", consumerProperties.getEventHubName()); + } + + @Test + void getEventHubNameReturnNullWhenNamespaceAndConnectionStringAreNull() { + assertNull(consumerProperties.getEventHubName()); + } } diff --git a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs-core/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/core/properties/EventHubsProducerPropertiesTests.java b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs-core/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/core/properties/EventHubsProducerPropertiesTests.java index aac72aaee18b5..6b8adad52e596 100644 --- a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs-core/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/core/properties/EventHubsProducerPropertiesTests.java +++ b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs-core/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/core/properties/EventHubsProducerPropertiesTests.java @@ -13,7 +13,7 @@ class EventHubsProducerPropertiesTests { - private static final String CONNECTION_STRING = "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=test;SharedAccessKey=accessKey;EntityPath=testeh"; + static final String CONNECTION_STRING = "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=test;SharedAccessKey=accessKey;EntityPath=testeh"; private EventHubsProducerProperties producerProperties; @@ -46,33 +46,56 @@ void customSync() { } @Test - void domainNameDefaultsToFalse() { - assertEquals("servicebus.windows.net", producerProperties.getDomainName()); + void domainNameDefaultsToNull() { + assertNull(producerProperties.getDomainName()); } @Test - void customDomainName() { + void customDomainNameShouldSet() { producerProperties.setDomainName("new.servicebus.windows.net"); assertEquals("new.servicebus.windows.net", producerProperties.getDomainName()); } @Test - void getFqnWhenNamespaceIsNull() { + void getFqdnWhenNamespaceIsNullButConnectionStringIsNot() { producerProperties.setConnectionString(CONNECTION_STRING); assertEquals("test.servicebus.windows.net", producerProperties.getFullyQualifiedNamespace()); } @Test - void getFqnWhenNamespaceIsNotNull() { + void getFqdnWhenNamespaceAndDomainNameAreNotNull() { producerProperties.setNamespace("dev-namespace"); + producerProperties.setDomainName("servicebus.windows.net"); assertEquals("dev-namespace.servicebus.windows.net", producerProperties.getFullyQualifiedNamespace()); } @Test - void getFqnReturnNullWhenNamespaceAndConnectionStringAreNull() { + void getFqdnWhenNamespaceAndDomainAreNull() { assertNull(producerProperties.getFullyQualifiedNamespace()); } + @Test + void getFqdnWhenNamespaceIsNullButDomainNameIsNot() { + producerProperties.setDomainName("servicebus.windows.net"); + assertNull(producerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnWhenDomainNameIsNullButNamespaceIsNot() { + producerProperties.setNamespace("test"); + assertNull(producerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnReturnNullWhenNamespaceAndConnectionStringAreNull() { + assertNull(producerProperties.getFullyQualifiedNamespace()); + } + + @Test + void amqpTransportTypeDefaultIsNull() { + assertNull(producerProperties.getClient().getTransportType()); + } + @Test void getEventHubNameWhenNamespaceIsNull() { producerProperties.setConnectionString(CONNECTION_STRING); diff --git a/sdk/spring/spring-cloud-azure-stream-binder-servicebus-core/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/core/properties/ServiceBusConsumerPropertiesTests.java b/sdk/spring/spring-cloud-azure-stream-binder-servicebus-core/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/core/properties/ServiceBusConsumerPropertiesTests.java index 70c250a0176fc..96f7c22ed57a7 100644 --- a/sdk/spring/spring-cloud-azure-stream-binder-servicebus-core/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/core/properties/ServiceBusConsumerPropertiesTests.java +++ b/sdk/spring/spring-cloud-azure-stream-binder-servicebus-core/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/core/properties/ServiceBusConsumerPropertiesTests.java @@ -10,6 +10,7 @@ import java.time.Duration; +import static com.azure.spring.cloud.stream.binder.servicebus.core.properties.ServiceBusProducerPropertiesTests.CONNECTION_STRING_PATTERN; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -102,4 +103,55 @@ void customMaxAutoLockRenewDuration() { consumerProperties.setMaxAutoLockRenewDuration(duration); assertEquals(duration, consumerProperties.getMaxAutoLockRenewDuration()); } + + @Test + void domainNameDefaultsToNull() { + assertNull(consumerProperties.getDomainName()); + } + + @Test + void customDomainNameShouldSet() { + consumerProperties.setDomainName("new.servicebus.windows.net"); + assertEquals("new.servicebus.windows.net", consumerProperties.getDomainName()); + } + + @Test + void getFqdnWhenNamespaceIsNullButConnectionStringIsNot() { + consumerProperties.setConnectionString(String.format(CONNECTION_STRING_PATTERN, "test")); + assertEquals("test.servicebus.windows.net", consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnWhenNamespaceAndDomainNameAreNotNull() { + consumerProperties.setNamespace("dev-namespace"); + consumerProperties.setDomainName("servicebus.windows.net"); + assertEquals("dev-namespace.servicebus.windows.net", consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnWhenNamespaceAndDomainAreNull() { + assertNull(consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnWhenNamespaceIsNullButDomainNameIsNot() { + consumerProperties.setDomainName("servicebus.windows.net"); + assertNull(consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnWhenDomainNameIsNullButNamespaceIsNot() { + consumerProperties.setNamespace("test"); + assertNull(consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnReturnNullWhenNamespaceAndConnectionStringAreNull() { + assertNull(consumerProperties.getFullyQualifiedNamespace()); + } + + @Test + void amqpTransportTypeDefaultIsNull() { + assertNull(consumerProperties.getClient().getTransportType()); + } } diff --git a/sdk/spring/spring-cloud-azure-stream-binder-servicebus-core/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/core/properties/ServiceBusProducerPropertiesTests.java b/sdk/spring/spring-cloud-azure-stream-binder-servicebus-core/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/core/properties/ServiceBusProducerPropertiesTests.java index f804e200d9710..9b1c9990e017b 100644 --- a/sdk/spring/spring-cloud-azure-stream-binder-servicebus-core/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/core/properties/ServiceBusProducerPropertiesTests.java +++ b/sdk/spring/spring-cloud-azure-stream-binder-servicebus-core/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/core/properties/ServiceBusProducerPropertiesTests.java @@ -13,7 +13,7 @@ class ServiceBusProducerPropertiesTests { - static final String CONNECTION_STRING = "Endpoint=sb://%s.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=key"; + static final String CONNECTION_STRING_PATTERN = "Endpoint=sb://%s.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=key"; private ServiceBusProducerProperties producerProperties; @BeforeEach @@ -45,30 +45,53 @@ void customSync() { } @Test - void domainNameDefaultsToFalse() { - assertEquals("servicebus.windows.net", producerProperties.getDomainName()); + void domainNameDefaultsToNull() { + assertNull(producerProperties.getDomainName()); } @Test - void customDomainName() { + void customDomainNameShouldSet() { producerProperties.setDomainName("new.servicebus.windows.net"); assertEquals("new.servicebus.windows.net", producerProperties.getDomainName()); } @Test - void getFqnWhenNamespaceIsNull() { - producerProperties.setConnectionString(String.format(CONNECTION_STRING, "test")); + void getFqdnWhenNamespaceIsNullButConnectionStringIsNot() { + producerProperties.setConnectionString(String.format(CONNECTION_STRING_PATTERN, "test")); assertEquals("test.servicebus.windows.net", producerProperties.getFullyQualifiedNamespace()); } @Test - void getFqnWhenNamespaceIsNotNull() { + void getFqdnWhenNamespaceAndDomainNameAreNotNull() { producerProperties.setNamespace("dev-namespace"); + producerProperties.setDomainName("servicebus.windows.net"); assertEquals("dev-namespace.servicebus.windows.net", producerProperties.getFullyQualifiedNamespace()); } @Test - void getFqnReturnNullWhenNamespaceAndConnectionStringAreNull() { + void getFqdnWhenNamespaceAndDomainAreNull() { assertNull(producerProperties.getFullyQualifiedNamespace()); } + + @Test + void getFqdnWhenNamespaceIsNullButDomainNameIsNot() { + producerProperties.setDomainName("servicebus.windows.net"); + assertNull(producerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnWhenDomainNameIsNullButNamespaceIsNot() { + producerProperties.setNamespace("test"); + assertNull(producerProperties.getFullyQualifiedNamespace()); + } + + @Test + void getFqdnReturnNullWhenNamespaceAndConnectionStringAreNull() { + assertNull(producerProperties.getFullyQualifiedNamespace()); + } + + @Test + void amqpTransportTypeDefaultIsNull() { + assertNull(producerProperties.getClient().getTransportType()); + } } diff --git a/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/messaging/eventhubs/core/properties/CommonProperties.java b/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/messaging/eventhubs/core/properties/CommonProperties.java index b73b6a63f11ae..ee34514a9dd51 100644 --- a/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/messaging/eventhubs/core/properties/CommonProperties.java +++ b/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/messaging/eventhubs/core/properties/CommonProperties.java @@ -3,9 +3,9 @@ package com.azure.spring.messaging.eventhubs.core.properties; -import com.azure.spring.cloud.core.provider.connectionstring.ConnectionStringProvider; import com.azure.spring.cloud.core.implementation.connectionstring.EventHubsConnectionString; import com.azure.spring.cloud.core.implementation.properties.AzureAmqpSdkProperties; +import com.azure.spring.cloud.core.provider.connectionstring.ConnectionStringProvider; import com.azure.spring.cloud.service.implementation.eventhubs.properties.EventHubClientCommonProperties; /** @@ -14,7 +14,7 @@ public abstract class CommonProperties extends AzureAmqpSdkProperties implements EventHubClientCommonProperties, ConnectionStringProvider { - private String domainName = "servicebus.windows.net"; + private String domainName; /** * The namespace of a event hub, which is the prefix of the FQDN. A FQDN should be composed of <NamespaceName>.<DomainName> @@ -45,7 +45,14 @@ private String extractEventHubNameFromConnectionString() { // https://docs.microsoft.com/azure/event-hubs/event-hubs-get-connection-string @Override public String getFullyQualifiedNamespace() { - return this.namespace == null ? extractFqdnFromConnectionString() : (this.namespace + "." + domainName); + return this.namespace == null ? extractFqdnFromConnectionString() : buildFqdnFromNamespace(); + } + + private String buildFqdnFromNamespace() { + if (namespace == null || domainName == null) { + return null; + } + return this.namespace + "." + domainName; } @Override diff --git a/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/messaging/eventhubs/core/properties/NamespaceProperties.java b/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/messaging/eventhubs/core/properties/NamespaceProperties.java index 117a389dcfa8b..268e610d3611e 100644 --- a/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/messaging/eventhubs/core/properties/NamespaceProperties.java +++ b/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/messaging/eventhubs/core/properties/NamespaceProperties.java @@ -12,6 +12,17 @@ public class NamespaceProperties extends CommonProperties implements EventHubsNa private Boolean sharedConnection; + /** + * The default constructor. + * + * The object constructed from this constructor will have a domain name and cloud type default + * to the Azure global cloud. + */ + public NamespaceProperties() { + this.setDomainName("servicebus.windows.net"); + this.getProfile().setCloudType(CloudType.AZURE); + } + @Override public Boolean getSharedConnection() { return sharedConnection; diff --git a/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementatin/core/config/EnableAzureMessagingTests.java b/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/core/config/EnableAzureMessagingTests.java similarity index 98% rename from sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementatin/core/config/EnableAzureMessagingTests.java rename to sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/core/config/EnableAzureMessagingTests.java index da7d6e8ec7351..5703076562b31 100644 --- a/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementatin/core/config/EnableAzureMessagingTests.java +++ b/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/core/config/EnableAzureMessagingTests.java @@ -1,11 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.spring.messaging.eventhubs.implementatin.core.config; +package com.azure.spring.messaging.eventhubs.implementation.core.config; import com.azure.spring.messaging.eventhubs.implementation.core.annotation.EventHubsListener; import com.azure.spring.messaging.eventhubs.implementation.core.annotation.EventHubsListeners; -import com.azure.spring.messaging.eventhubs.implementation.core.config.MethodEventHubsListenerEndpoint; import com.azure.spring.messaging.implementation.annotation.AzureListenerConfigurer; import com.azure.spring.messaging.implementation.annotation.EnableAzureMessaging; import com.azure.spring.messaging.implementation.config.AbstractAzureMessagingAnnotationDrivenTests; diff --git a/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementatin/core/config/EventHubsListenerAnnotationBeanPostProcessorTests.java b/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/core/config/EventHubsListenerAnnotationBeanPostProcessorTests.java similarity index 97% rename from sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementatin/core/config/EventHubsListenerAnnotationBeanPostProcessorTests.java rename to sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/core/config/EventHubsListenerAnnotationBeanPostProcessorTests.java index 34ea7f1850d06..85c00387eaa29 100644 --- a/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementatin/core/config/EventHubsListenerAnnotationBeanPostProcessorTests.java +++ b/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/core/config/EventHubsListenerAnnotationBeanPostProcessorTests.java @@ -1,16 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.spring.messaging.eventhubs.implementatin.core.config; +package com.azure.spring.messaging.eventhubs.implementation.core.config; +import com.azure.spring.messaging.converter.AzureMessageConverter; import com.azure.spring.messaging.eventhubs.implementation.core.annotation.EventHubsListener; import com.azure.spring.messaging.eventhubs.implementation.core.annotation.EventHubsListenerAnnotationBeanPostProcessor; -import com.azure.spring.messaging.eventhubs.implementation.core.config.MethodEventHubsListenerEndpoint; import com.azure.spring.messaging.implementation.config.AbstractAzureListenerEndpoint; import com.azure.spring.messaging.implementation.config.AzureListenerContainerTestFactory; import com.azure.spring.messaging.implementation.config.AzureListenerEndpoint; import com.azure.spring.messaging.implementation.config.AzureListenerEndpointRegistry; -import com.azure.spring.messaging.converter.AzureMessageConverter; import com.azure.spring.messaging.listener.MessageListenerContainer; import com.azure.spring.messaging.listener.MessageListenerTestContainer; import org.junit.jupiter.api.Test; diff --git a/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/core/properties/merger/ProcessorPropertiesParentMergerTests.java b/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/properties/merger/ProcessorPropertiesParentMergerTests.java similarity index 63% rename from sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/core/properties/merger/ProcessorPropertiesParentMergerTests.java rename to sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/properties/merger/ProcessorPropertiesParentMergerTests.java index 9585c2b565de6..c9af707805b21 100644 --- a/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/core/properties/merger/ProcessorPropertiesParentMergerTests.java +++ b/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/properties/merger/ProcessorPropertiesParentMergerTests.java @@ -1,14 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.spring.messaging.eventhubs.core.properties.merger; +package com.azure.spring.messaging.eventhubs.implementation.properties.merger; +import com.azure.core.management.AzureEnvironment; import com.azure.spring.messaging.eventhubs.core.properties.NamespaceProperties; import com.azure.spring.messaging.eventhubs.core.properties.ProcessorProperties; -import com.azure.spring.messaging.eventhubs.implementation.properties.merger.ProcessorPropertiesParentMerger; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_CHINA; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_US_GOVERNMENT; + class ProcessorPropertiesParentMergerTests { private final ProcessorPropertiesParentMerger merger = new ProcessorPropertiesParentMerger(); @@ -21,12 +24,18 @@ void childNotProvidedShouldUseParent() { parent.setEventHubName("parent"); parent.setConnectionString("parent-connection-str"); parent.getProxy().setHostname("parent-hostname"); + parent.getProfile().setCloudType(AZURE_US_GOVERNMENT); + parent.setDomainName("parent-domain"); ProcessorProperties result = merger.merge(child, parent); Assertions.assertEquals("parent", result.getEventHubName()); Assertions.assertEquals("parent-connection-str", result.getConnectionString()); Assertions.assertEquals("parent-hostname", result.getProxy().getHostname()); + Assertions.assertEquals(AZURE_US_GOVERNMENT, result.getProfile().getCloudType()); + Assertions.assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + result.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + Assertions.assertEquals("parent-domain", result.getDomainName()); } @Test @@ -38,11 +47,16 @@ void childProvidedShouldUseChild() { child.setTrackLastEnqueuedEventProperties(true); child.setPrefetchCount(3); child.setConsumerGroup("default"); + child.getProfile().setCloudType(AZURE_CHINA); + child.setDomainName("child-domain"); + NamespaceProperties parent = new NamespaceProperties(); parent.setEventHubName("parent"); parent.setConnectionString("parent-connection-str"); parent.getProxy().setHostname("parent-hostname"); + parent.getProfile().setCloudType(AZURE_US_GOVERNMENT); + parent.setDomainName("parent-domain"); ProcessorProperties result = merger.merge(child, parent); @@ -52,6 +66,10 @@ void childProvidedShouldUseChild() { Assertions.assertEquals(true, result.getTrackLastEnqueuedEventProperties()); Assertions.assertEquals("default", result.getConsumerGroup()); Assertions.assertEquals(3, result.getPrefetchCount()); + Assertions.assertEquals("child-domain", result.getDomainName()); + Assertions.assertEquals(AZURE_CHINA, result.getProfile().getCloudType()); + Assertions.assertEquals(AzureEnvironment.AZURE_CHINA.getActiveDirectoryEndpoint(), + result.getProfile().getEnvironment().getActiveDirectoryEndpoint()); } } diff --git a/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/core/properties/merger/ProducerPropertiesParentMergerTests.java b/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/properties/merger/ProducerPropertiesParentMergerTests.java similarity index 52% rename from sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/core/properties/merger/ProducerPropertiesParentMergerTests.java rename to sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/properties/merger/ProducerPropertiesParentMergerTests.java index bdac22daf2890..4273b11d13e45 100644 --- a/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/core/properties/merger/ProducerPropertiesParentMergerTests.java +++ b/sdk/spring/spring-messaging-azure-eventhubs/src/test/java/com/azure/spring/messaging/eventhubs/implementation/properties/merger/ProducerPropertiesParentMergerTests.java @@ -1,14 +1,18 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.spring.messaging.eventhubs.core.properties.merger; +package com.azure.spring.messaging.eventhubs.implementation.properties.merger; +import com.azure.core.amqp.AmqpTransportType; +import com.azure.core.management.AzureEnvironment; import com.azure.spring.messaging.eventhubs.core.properties.NamespaceProperties; import com.azure.spring.messaging.eventhubs.core.properties.ProducerProperties; -import com.azure.spring.messaging.eventhubs.implementation.properties.merger.ProducerPropertiesParentMerger; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_CHINA; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_US_GOVERNMENT; + class ProducerPropertiesParentMergerTests { private final ProducerPropertiesParentMerger merger = new ProducerPropertiesParentMerger(); @@ -21,12 +25,20 @@ void childNotProvidedShouldUseParent() { parent.setEventHubName("parent"); parent.setConnectionString("parent-connection-str"); parent.getProxy().setHostname("parent-hostname"); + parent.getProfile().setCloudType(AZURE_US_GOVERNMENT); + parent.setDomainName("parent-domain"); + parent.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); ProducerProperties result = merger.merge(child, parent); Assertions.assertEquals("parent", result.getEventHubName()); Assertions.assertEquals("parent-connection-str", result.getConnectionString()); Assertions.assertEquals("parent-hostname", result.getProxy().getHostname()); + Assertions.assertEquals(AZURE_US_GOVERNMENT, result.getProfile().getCloudType()); + Assertions.assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + result.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + Assertions.assertEquals("parent-domain", result.getDomainName()); + Assertions.assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, result.getClient().getTransportType()); } @Test @@ -35,17 +47,27 @@ void childProvidedShouldUseChild() { child.setEventHubName("child"); child.setConnectionString("child-connection-str"); child.getProxy().setHostname("child-hostname"); + child.getProfile().setCloudType(AZURE_CHINA); + child.setDomainName("child-domain"); + child.getClient().setTransportType(AmqpTransportType.AMQP); NamespaceProperties parent = new NamespaceProperties(); parent.setEventHubName("parent"); parent.setConnectionString("parent-connection-str"); parent.getProxy().setHostname("parent-hostname"); + parent.getProfile().setCloudType(AZURE_US_GOVERNMENT); + parent.setDomainName("parent-domain"); + parent.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); ProducerProperties result = merger.merge(child, parent); Assertions.assertEquals("child", result.getEventHubName()); Assertions.assertEquals("child-connection-str", result.getConnectionString()); Assertions.assertEquals("child-hostname", result.getProxy().getHostname()); + Assertions.assertEquals(AZURE_CHINA, result.getProfile().getCloudType()); + Assertions.assertEquals(AzureEnvironment.AZURE_CHINA.getActiveDirectoryEndpoint(), + result.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + Assertions.assertEquals(AmqpTransportType.AMQP, result.getClient().getTransportType()); } } diff --git a/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/messaging/servicebus/core/properties/CommonProperties.java b/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/messaging/servicebus/core/properties/CommonProperties.java index 9e4e18711051f..f4a454151e23e 100644 --- a/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/messaging/servicebus/core/properties/CommonProperties.java +++ b/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/messaging/servicebus/core/properties/CommonProperties.java @@ -13,7 +13,7 @@ */ public class CommonProperties extends AzureAmqpSdkProperties implements ServiceBusClientCommonProperties { - private String domainName = "servicebus.windows.net"; + private String domainName; /** * The namespace of a service bus, which is the prefix of the FQDN. A FQDN should be composed of <NamespaceName>.<DomainName> @@ -30,9 +30,16 @@ private String extractFqdnFromConnectionString() { return new ServiceBusConnectionString(this.connectionString).getFullyQualifiedNamespace(); } + private String buildFqdnFromNamespace() { + if (namespace == null || domainName == null) { + return null; + } + return this.namespace + "." + domainName; + } + @Override public String getFullyQualifiedNamespace() { - return this.namespace == null ? extractFqdnFromConnectionString() : (this.namespace + "." + domainName); + return this.namespace == null ? extractFqdnFromConnectionString() : buildFqdnFromNamespace(); } @Override diff --git a/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/messaging/servicebus/core/properties/NamespaceProperties.java b/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/messaging/servicebus/core/properties/NamespaceProperties.java index a4dd730920621..424ef3efeaf2f 100644 --- a/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/messaging/servicebus/core/properties/NamespaceProperties.java +++ b/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/messaging/servicebus/core/properties/NamespaceProperties.java @@ -12,6 +12,17 @@ public class NamespaceProperties extends CommonProperties implements ServiceBusN private Boolean crossEntityTransactions; + /** + * The default constructor. + * + * The object constructed from this constructor will have a domain name and cloud type default + * to the Azure global cloud. + */ + public NamespaceProperties() { + this.setDomainName("servicebus.windows.net"); + this.getProfile().setCloudType(CloudType.AZURE); + } + @Override public Boolean getCrossEntityTransactions() { return crossEntityTransactions; diff --git a/sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/core/properties/merger/ProducerPropertiesParentMergerTests.java b/sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/core/properties/merger/ProducerPropertiesParentMergerTests.java deleted file mode 100644 index 5c1a09d2755bf..0000000000000 --- a/sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/core/properties/merger/ProducerPropertiesParentMergerTests.java +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.spring.messaging.servicebus.core.properties.merger; - -import com.azure.spring.messaging.servicebus.core.properties.NamespaceProperties; -import com.azure.spring.messaging.servicebus.core.properties.ProducerProperties; -import com.azure.spring.messaging.servicebus.implementation.properties.merger.SenderPropertiesParentMerger; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class ProducerPropertiesParentMergerTests { - private final SenderPropertiesParentMerger merger = new SenderPropertiesParentMerger(); - - @Test - void childNotProvidedShouldUseParent() { - ProducerProperties child = new ProducerProperties(); - - NamespaceProperties parent = new NamespaceProperties(); - parent.setConnectionString("parent-connection-str"); - parent.getProxy().setHostname("parent-hostname"); - - ProducerProperties result = merger.merge(child, parent); - - Assertions.assertEquals("parent-connection-str", result.getConnectionString()); - Assertions.assertEquals("parent-hostname", result.getProxy().getHostname()); - } - - @Test - void childProvidedShouldUseChild() { - ProducerProperties child = new ProducerProperties(); - child.setConnectionString("child-connection-str"); - child.getProxy().setHostname("child-hostname"); - child.setEntityName("test"); - - NamespaceProperties parent = new NamespaceProperties(); - parent.setConnectionString("parent-connection-str"); - parent.getProxy().setHostname("parent-hostname"); - - ProducerProperties result = merger.merge(child, parent); - - Assertions.assertEquals("child-connection-str", result.getConnectionString()); - Assertions.assertEquals("child-hostname", result.getProxy().getHostname()); - Assertions.assertEquals("test", result.getEntityName()); - } -} diff --git a/sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/core/properties/merger/ProcessorPropertiesParentMergerTests.java b/sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/implementation/properties/merger/ProcessorPropertiesParentMergerTests.java similarity index 51% rename from sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/core/properties/merger/ProcessorPropertiesParentMergerTests.java rename to sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/implementation/properties/merger/ProcessorPropertiesParentMergerTests.java index 0bd6306dd2fae..f934e4445d1a4 100644 --- a/sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/core/properties/merger/ProcessorPropertiesParentMergerTests.java +++ b/sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/implementation/properties/merger/ProcessorPropertiesParentMergerTests.java @@ -1,14 +1,18 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.spring.messaging.servicebus.core.properties.merger; +package com.azure.spring.messaging.servicebus.implementation.properties.merger; +import com.azure.core.amqp.AmqpTransportType; +import com.azure.core.management.AzureEnvironment; import com.azure.spring.messaging.servicebus.core.properties.NamespaceProperties; import com.azure.spring.messaging.servicebus.core.properties.ProcessorProperties; -import com.azure.spring.messaging.servicebus.implementation.properties.merger.ProcessorPropertiesParentMerger; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_CHINA; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_US_GOVERNMENT; + public class ProcessorPropertiesParentMergerTests { private final ProcessorPropertiesParentMerger merger = new ProcessorPropertiesParentMerger(); @@ -19,11 +23,19 @@ void childNotProvidedShouldUseParent() { NamespaceProperties parent = new NamespaceProperties(); parent.setConnectionString("parent-connection-str"); parent.getProxy().setHostname("parent-hostname"); + parent.getProfile().setCloudType(AZURE_US_GOVERNMENT); + parent.setDomainName("parent-domain"); + parent.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); ProcessorProperties result = merger.merge(child, parent); Assertions.assertEquals("parent-connection-str", result.getConnectionString()); Assertions.assertEquals("parent-hostname", result.getProxy().getHostname()); + Assertions.assertEquals(AZURE_US_GOVERNMENT, result.getProfile().getCloudType()); + Assertions.assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + result.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + Assertions.assertEquals("parent-domain", result.getDomainName()); + Assertions.assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, result.getClient().getTransportType()); } @Test @@ -33,10 +45,16 @@ void childProvidedShouldUseChild() { child.getProxy().setHostname("child-hostname"); child.setPrefetchCount(3); child.setMaxConcurrentCalls(2); + child.getProfile().setCloudType(AZURE_CHINA); + child.setDomainName("child-domain"); + child.getClient().setTransportType(AmqpTransportType.AMQP); NamespaceProperties parent = new NamespaceProperties(); parent.setConnectionString("parent-connection-str"); parent.getProxy().setHostname("parent-hostname"); + parent.getProfile().setCloudType(AZURE_US_GOVERNMENT); + parent.setDomainName("parent-domain"); + parent.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); ProcessorProperties result = merger.merge(child, parent); @@ -44,6 +62,11 @@ void childProvidedShouldUseChild() { Assertions.assertEquals("child-hostname", result.getProxy().getHostname()); Assertions.assertEquals(3, result.getPrefetchCount()); Assertions.assertEquals(2, result.getMaxConcurrentCalls()); + Assertions.assertEquals("child-domain", result.getDomainName()); + Assertions.assertEquals(AZURE_CHINA, result.getProfile().getCloudType()); + Assertions.assertEquals(AzureEnvironment.AZURE_CHINA.getActiveDirectoryEndpoint(), + result.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + Assertions.assertEquals(AmqpTransportType.AMQP, result.getClient().getTransportType()); } } diff --git a/sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/implementation/properties/merger/ProducerPropertiesParentMergerTests.java b/sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/implementation/properties/merger/ProducerPropertiesParentMergerTests.java new file mode 100644 index 0000000000000..0b03ef262369a --- /dev/null +++ b/sdk/spring/spring-messaging-azure-servicebus/src/test/java/com/azure/spring/messaging/servicebus/implementation/properties/merger/ProducerPropertiesParentMergerTests.java @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.spring.messaging.servicebus.implementation.properties.merger; + +import com.azure.core.amqp.AmqpTransportType; +import com.azure.core.management.AzureEnvironment; +import com.azure.spring.messaging.servicebus.core.properties.NamespaceProperties; +import com.azure.spring.messaging.servicebus.core.properties.ProducerProperties; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_CHINA; +import static com.azure.spring.cloud.core.provider.AzureProfileOptionsProvider.CloudType.AZURE_US_GOVERNMENT; + +public class ProducerPropertiesParentMergerTests { + private final SenderPropertiesParentMerger merger = new SenderPropertiesParentMerger(); + + @Test + void childNotProvidedShouldUseParent() { + ProducerProperties child = new ProducerProperties(); + + NamespaceProperties parent = new NamespaceProperties(); + parent.setConnectionString("parent-connection-str"); + parent.getProxy().setHostname("parent-hostname"); + parent.getProfile().setCloudType(AZURE_US_GOVERNMENT); + parent.setDomainName("parent-domain"); + parent.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); + + ProducerProperties result = merger.merge(child, parent); + + Assertions.assertEquals("parent-connection-str", result.getConnectionString()); + Assertions.assertEquals("parent-hostname", result.getProxy().getHostname()); + Assertions.assertEquals(AZURE_US_GOVERNMENT, result.getProfile().getCloudType()); + Assertions.assertEquals(AzureEnvironment.AZURE_US_GOVERNMENT.getActiveDirectoryEndpoint(), + result.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + Assertions.assertEquals("parent-domain", result.getDomainName()); + Assertions.assertEquals(AmqpTransportType.AMQP_WEB_SOCKETS, result.getClient().getTransportType()); + } + + @Test + void childProvidedShouldUseChild() { + ProducerProperties child = new ProducerProperties(); + child.setConnectionString("child-connection-str"); + child.getProxy().setHostname("child-hostname"); + child.setEntityName("test"); + child.getProfile().setCloudType(AZURE_CHINA); + child.setDomainName("child-domain"); + child.getClient().setTransportType(AmqpTransportType.AMQP); + + NamespaceProperties parent = new NamespaceProperties(); + parent.setConnectionString("parent-connection-str"); + parent.getProxy().setHostname("parent-hostname"); + parent.getProfile().setCloudType(AZURE_US_GOVERNMENT); + parent.setDomainName("parent-domain"); + parent.getClient().setTransportType(AmqpTransportType.AMQP_WEB_SOCKETS); + + ProducerProperties result = merger.merge(child, parent); + + Assertions.assertEquals("child-connection-str", result.getConnectionString()); + Assertions.assertEquals("child-hostname", result.getProxy().getHostname()); + Assertions.assertEquals("test", result.getEntityName()); + Assertions.assertEquals("child-domain", result.getDomainName()); + Assertions.assertEquals(AZURE_CHINA, result.getProfile().getCloudType()); + Assertions.assertEquals(AzureEnvironment.AZURE_CHINA.getActiveDirectoryEndpoint(), + result.getProfile().getEnvironment().getActiveDirectoryEndpoint()); + Assertions.assertEquals(AmqpTransportType.AMQP, result.getClient().getTransportType()); + } + +} diff --git a/sdk/spring/tests.yml b/sdk/spring/tests.yml index 84c10d770cc5c..ba97f60165647 100644 --- a/sdk/spring/tests.yml +++ b/sdk/spring/tests.yml @@ -4,6 +4,15 @@ stages: - template: ../../eng/pipelines/templates/stages/archetype-sdk-tests.yml parameters: SupportedClouds: 'Public,UsGov,China' + Clouds: 'Public,UsGov,China' + CloudConfig: + Public: + SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources) + UsGov: + SubscriptionConfiguration: $(sub-config-gov-test-resources) + China: + SubscriptionConfiguration: $(sub-config-cn-test-resources) + Location: 'chinanorth3' TestResourceDirectories: - spring/spring-cloud-azure-integration-tests/test-resources/appconfiguration - spring/spring-cloud-azure-integration-tests/test-resources/cosmos @@ -17,6 +26,6 @@ stages: safeName: springcloudazureintegrationtests TimeoutInMinutes: 240 ServiceDirectory: spring - TestName: IntegrationTestInAzureGlobal + TestName: SpringIntegrationTests TestGoals: 'verify' TestOptions: '-DskipSpringITs=false'