From b7d8dbb301c1bab38aeb11f7dd8a0696d108401b Mon Sep 17 00:00:00 2001 From: "Hong Li(MSFT)" <74638143+v-hongli1@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:44:39 +0800 Subject: [PATCH 1/7] Register provider via policy Part One (#43422) * Register provider via policy Part One --- .../apicenter/ApiCenterManagerTests.java | 10 ++++--- .../ApiManagementManagerTest.java | 10 ++++--- .../ApplicationInsightsManagerTests.java | 13 ++++++---- .../resourcemanager/avs/AvsManagerTests.java | 10 ++++--- .../resourcemanager/batch/BatchTests.java | 26 ++++++++++++++----- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/sdk/apicenter/azure-resourcemanager-apicenter/src/test/java/com/azure/resourcemanager/apicenter/ApiCenterManagerTests.java b/sdk/apicenter/azure-resourcemanager-apicenter/src/test/java/com/azure/resourcemanager/apicenter/ApiCenterManagerTests.java index faa8b1fa334ae..e866b6d0eb80f 100644 --- a/sdk/apicenter/azure-resourcemanager-apicenter/src/test/java/com/azure/resourcemanager/apicenter/ApiCenterManagerTests.java +++ b/sdk/apicenter/azure-resourcemanager-apicenter/src/test/java/com/azure/resourcemanager/apicenter/ApiCenterManagerTests.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.apicenter.models.Service; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - apiCenterManager = ApiCenterManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + apiCenterManager = ApiCenterManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/apimanagement/azure-resourcemanager-apimanagement/src/test/java/com/azure/resourcemanager/apimanagement/ApiManagementManagerTest.java b/sdk/apimanagement/azure-resourcemanager-apimanagement/src/test/java/com/azure/resourcemanager/apimanagement/ApiManagementManagerTest.java index 727e720c918d3..e67d0d740105a 100644 --- a/sdk/apimanagement/azure-resourcemanager-apimanagement/src/test/java/com/azure/resourcemanager/apimanagement/ApiManagementManagerTest.java +++ b/sdk/apimanagement/azure-resourcemanager-apimanagement/src/test/java/com/azure/resourcemanager/apimanagement/ApiManagementManagerTest.java @@ -20,6 +20,7 @@ import com.azure.resourcemanager.apimanagement.models.ApimIdentityType; import com.azure.resourcemanager.apimanagement.models.SkuType; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -38,15 +39,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - apiManagementManager = ApiManagementManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + apiManagementManager = ApiManagementManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/applicationinsights/azure-resourcemanager-applicationinsights/src/test/java/com/azure/resourcemanager/applicationinsights/ApplicationInsightsManagerTests.java b/sdk/applicationinsights/azure-resourcemanager-applicationinsights/src/test/java/com/azure/resourcemanager/applicationinsights/ApplicationInsightsManagerTests.java index d1f9810b8e9c1..fc1d3ac70b76f 100644 --- a/sdk/applicationinsights/azure-resourcemanager-applicationinsights/src/test/java/com/azure/resourcemanager/applicationinsights/ApplicationInsightsManagerTests.java +++ b/sdk/applicationinsights/azure-resourcemanager-applicationinsights/src/test/java/com/azure/resourcemanager/applicationinsights/ApplicationInsightsManagerTests.java @@ -20,6 +20,7 @@ import com.azure.resourcemanager.loganalytics.LogAnalyticsManager; import com.azure.resourcemanager.loganalytics.models.Workspace; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -39,19 +40,21 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + resourceManager = ResourceManager.configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile) + .withDefaultSubscription(); + applicationInsightsManager = ApplicationInsightsManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); logAnalyticsManager = LogAnalyticsManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); - resourceManager = ResourceManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile) - .withDefaultSubscription(); - // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/avs/azure-resourcemanager-avs/src/test/java/com/azure/resourcemanager/avs/AvsManagerTests.java b/sdk/avs/azure-resourcemanager-avs/src/test/java/com/azure/resourcemanager/avs/AvsManagerTests.java index 9d672f0b74d50..0ee52d7ca4af3 100644 --- a/sdk/avs/azure-resourcemanager-avs/src/test/java/com/azure/resourcemanager/avs/AvsManagerTests.java +++ b/sdk/avs/azure-resourcemanager-avs/src/test/java/com/azure/resourcemanager/avs/AvsManagerTests.java @@ -20,6 +20,7 @@ import com.azure.resourcemanager.avs.models.ResourceIdentityType; import com.azure.resourcemanager.avs.models.Sku; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -39,15 +40,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - avsManager = AvsManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + avsManager = AvsManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/batch/azure-resourcemanager-batch/src/test/java/com/azure/resourcemanager/batch/BatchTests.java b/sdk/batch/azure-resourcemanager-batch/src/test/java/com/azure/resourcemanager/batch/BatchTests.java index 01f0d912c59d3..c93f9d934ad8a 100644 --- a/sdk/batch/azure-resourcemanager-batch/src/test/java/com/azure/resourcemanager/batch/BatchTests.java +++ b/sdk/batch/azure-resourcemanager-batch/src/test/java/com/azure/resourcemanager/batch/BatchTests.java @@ -3,6 +3,7 @@ package com.azure.resourcemanager.batch; +import com.azure.core.credential.TokenCredential; import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.management.AzureEnvironment; @@ -27,6 +28,8 @@ import com.azure.resourcemanager.batch.models.Pool; import com.azure.resourcemanager.batch.models.ScaleSettings; import com.azure.resourcemanager.batch.models.VirtualMachineConfiguration; +import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.storage.StorageManager; import com.azure.resourcemanager.storage.models.StorageAccount; import org.junit.jupiter.api.Assertions; @@ -45,33 +48,44 @@ public class BatchTests extends TestProxyTestBase { private static final Region REGION = Region.US_WEST2; private String resourceGroup = "rg" + randomPadding(); + private ResourceManager resourceManager; private BatchManager batchManager; private StorageManager storageManager; private boolean testEnv; @Override public void beforeTest() { + TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + + resourceManager = ResourceManager.configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile) + .withDefaultSubscription(); + batchManager = BatchManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(new AzurePowerShellCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)); + .authenticate(credential, profile); storageManager = StorageManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(new AzurePowerShellCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)); + .authenticate(credential, profile); String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); if (testEnv) { resourceGroup = testResourceGroup; } else { - storageManager.resourceManager().resourceGroups().define(resourceGroup).withRegion(REGION).create(); + resourceManager.resourceGroups().define(resourceGroup).withRegion(REGION).create(); } } @Override protected void afterTest() { if (!testEnv) { - storageManager.resourceManager().resourceGroups().beginDeleteByName(resourceGroup); + resourceManager.resourceGroups().beginDeleteByName(resourceGroup); } } @@ -188,7 +202,7 @@ public void testCRUDBatchApplication() { .withExistingResourceGroup(resourceGroup) .create(); // batch account - batchAccountName = "sa" + randomPadding(); + batchAccountName = "ba" + randomPadding(); account = batchManager.batchAccounts() .define(batchAccountName) .withRegion(REGION) @@ -197,7 +211,7 @@ public void testCRUDBatchApplication() { .create(); // create application with batch account - applicationName = "ba" + randomPadding(); + applicationName = "baa" + randomPadding(); String displayName = "badn" + randomPadding(); application = batchManager.applications() .define(applicationName) From 4e30c65fbff20c5c08ab0439da78958dcc3f1d74 Mon Sep 17 00:00:00 2001 From: "Hong Li(MSFT)" <74638143+v-hongli1@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:45:02 +0800 Subject: [PATCH 2/7] Register provider via policy Part Two (#43423) Register provider via policy Part Two (#43423) --- .../AzureChangeAnalysisManagerTest.java | 10 ++++++---- .../resourcemanager/chaos/ChaosManagerTests.java | 13 ++++++++----- .../CognitiveServicesManagerTests.java | 10 ++++++---- .../computefleet/ComputeFleetManagerTests.java | 13 +++++++++++-- .../ContainerServiceFleetManagerTests.java | 10 ++++++---- .../CosmosDBForPostgreSqlManagerTests.java | 10 ++++++---- 6 files changed, 43 insertions(+), 23 deletions(-) diff --git a/sdk/changeanalysis/azure-resourcemanager-changeanalysis/src/test/java/com/azure/resourcemanager/changeanalysis/AzureChangeAnalysisManagerTest.java b/sdk/changeanalysis/azure-resourcemanager-changeanalysis/src/test/java/com/azure/resourcemanager/changeanalysis/AzureChangeAnalysisManagerTest.java index 54f52fd6015a0..6085399a883d5 100644 --- a/sdk/changeanalysis/azure-resourcemanager-changeanalysis/src/test/java/com/azure/resourcemanager/changeanalysis/AzureChangeAnalysisManagerTest.java +++ b/sdk/changeanalysis/azure-resourcemanager-changeanalysis/src/test/java/com/azure/resourcemanager/changeanalysis/AzureChangeAnalysisManagerTest.java @@ -15,6 +15,7 @@ import com.azure.core.util.CoreUtils; import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -35,15 +36,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - azureChangeAnalysisManager = AzureChangeAnalysisManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + azureChangeAnalysisManager = AzureChangeAnalysisManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/chaos/azure-resourcemanager-chaos/src/test/java/com/azure/resourcemanager/chaos/ChaosManagerTests.java b/sdk/chaos/azure-resourcemanager-chaos/src/test/java/com/azure/resourcemanager/chaos/ChaosManagerTests.java index fcd22c7a7b19f..7e7a6ea1bdb86 100644 --- a/sdk/chaos/azure-resourcemanager-chaos/src/test/java/com/azure/resourcemanager/chaos/ChaosManagerTests.java +++ b/sdk/chaos/azure-resourcemanager-chaos/src/test/java/com/azure/resourcemanager/chaos/ChaosManagerTests.java @@ -19,6 +19,7 @@ import com.azure.resourcemanager.keyvault.KeyVaultManager; import com.azure.resourcemanager.keyvault.models.SkuName; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -40,19 +41,21 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + resourceManager = ResourceManager.configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile) + .withDefaultSubscription(); + chaosManager = ChaosManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) .authenticate(credential, profile); keyVaultManager = KeyVaultManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); - resourceManager = ResourceManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile) - .withDefaultSubscription(); - // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/cognitiveservices/azure-resourcemanager-cognitiveservices/src/test/java/com/azure/resourcemanager/cognitiveservices/CognitiveServicesManagerTests.java b/sdk/cognitiveservices/azure-resourcemanager-cognitiveservices/src/test/java/com/azure/resourcemanager/cognitiveservices/CognitiveServicesManagerTests.java index c43a1e4e5168e..70bd4fbef7584 100644 --- a/sdk/cognitiveservices/azure-resourcemanager-cognitiveservices/src/test/java/com/azure/resourcemanager/cognitiveservices/CognitiveServicesManagerTests.java +++ b/sdk/cognitiveservices/azure-resourcemanager-cognitiveservices/src/test/java/com/azure/resourcemanager/cognitiveservices/CognitiveServicesManagerTests.java @@ -17,6 +17,7 @@ import com.azure.resourcemanager.cognitiveservices.models.Account; import com.azure.resourcemanager.cognitiveservices.models.Sku; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -35,15 +36,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - cognitiveServicesManager = CognitiveServicesManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + cognitiveServicesManager = CognitiveServicesManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java index a14a2b427aa19..ed9f209aee3a9 100644 --- a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java +++ b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java @@ -49,6 +49,7 @@ import com.azure.resourcemanager.network.models.LoadBalancerSkuType; import com.azure.resourcemanager.network.models.Network; import com.azure.resourcemanager.network.models.TransportProtocol; +import com.azure.resourcemanager.resources.ResourceManager; import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -61,6 +62,7 @@ public class ComputeFleetManagerTests extends TestProxyTestBase { private static final Random RANDOM = new Random(); private static final Region REGION = Region.US_WEST2; private String resourceGroupName = "rg" + randomPadding(); + private ResourceManager resourceManager = null; private ComputeFleetManager computeFleetManager = null; private NetworkManager networkManager = null; private boolean testEnv; @@ -70,11 +72,18 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + resourceManager = ResourceManager.configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile) + .withDefaultSubscription(); + networkManager = NetworkManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); computeFleetManager = ComputeFleetManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .withPolicy(new ProviderRegistrationPolicy(networkManager.resourceManager())) .authenticate(credential, profile); @@ -85,14 +94,14 @@ public void beforeTest() { if (testEnv) { resourceGroupName = testResourceGroup; } else { - networkManager.resourceManager().resourceGroups().define(resourceGroupName).withRegion(REGION).create(); + resourceManager.resourceGroups().define(resourceGroupName).withRegion(REGION).create(); } } @Override protected void afterTest() { if (!testEnv) { - networkManager.resourceManager().resourceGroups().beginDeleteByName(resourceGroupName); + resourceManager.resourceGroups().beginDeleteByName(resourceGroupName); } } diff --git a/sdk/containerservicefleet/azure-resourcemanager-containerservicefleet/src/test/java/com/azure/resourcemanager/containerservicefleet/ContainerServiceFleetManagerTests.java b/sdk/containerservicefleet/azure-resourcemanager-containerservicefleet/src/test/java/com/azure/resourcemanager/containerservicefleet/ContainerServiceFleetManagerTests.java index cb9b2f9543405..a533e723e0579 100644 --- a/sdk/containerservicefleet/azure-resourcemanager-containerservicefleet/src/test/java/com/azure/resourcemanager/containerservicefleet/ContainerServiceFleetManagerTests.java +++ b/sdk/containerservicefleet/azure-resourcemanager-containerservicefleet/src/test/java/com/azure/resourcemanager/containerservicefleet/ContainerServiceFleetManagerTests.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.containerservicefleet.models.Fleet; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - containerServiceFleetManager = ContainerServiceFleetManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + containerServiceFleetManager = ContainerServiceFleetManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/cosmosdbforpostgresql/azure-resourcemanager-cosmosdbforpostgresql/src/test/java/com/azure/resourcemanager/cosmosdbforpostgresql/CosmosDBForPostgreSqlManagerTests.java b/sdk/cosmosdbforpostgresql/azure-resourcemanager-cosmosdbforpostgresql/src/test/java/com/azure/resourcemanager/cosmosdbforpostgresql/CosmosDBForPostgreSqlManagerTests.java index f68394a3b0cd1..67e4d5a5e3c0b 100644 --- a/sdk/cosmosdbforpostgresql/azure-resourcemanager-cosmosdbforpostgresql/src/test/java/com/azure/resourcemanager/cosmosdbforpostgresql/CosmosDBForPostgreSqlManagerTests.java +++ b/sdk/cosmosdbforpostgresql/azure-resourcemanager-cosmosdbforpostgresql/src/test/java/com/azure/resourcemanager/cosmosdbforpostgresql/CosmosDBForPostgreSqlManagerTests.java @@ -17,6 +17,7 @@ import com.azure.resourcemanager.cosmosdbforpostgresql.models.Cluster; import com.azure.resourcemanager.cosmosdbforpostgresql.models.MaintenanceWindow; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -35,15 +36,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - cosmosDBForPostgreSqlManager = CosmosDBForPostgreSqlManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + cosmosDBForPostgreSqlManager = CosmosDBForPostgreSqlManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); From 40a909ab96a1dbb90dd69bcb2d87ba91102c372b Mon Sep 17 00:00:00 2001 From: "Hong Li(MSFT)" <74638143+v-hongli1@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:45:21 +0800 Subject: [PATCH 3/7] Register provider via policy Part Three (#43424) Register provider via policy Part Three (#43424) --- .../dashboard/DashboardManagerTests.java | 10 ++++---- .../datafactory/DataFactoryTests.java | 23 +++++++++++++++---- .../DataProtectionManagerTest.java | 10 ++++---- .../DeviceUpdateManagerTests.java | 10 ++++---- .../devtestlabs/DevTestLabsManagerTests.java | 10 ++++---- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/sdk/dashboard/azure-resourcemanager-dashboard/src/test/java/com/azure/resourcemanager/dashboard/DashboardManagerTests.java b/sdk/dashboard/azure-resourcemanager-dashboard/src/test/java/com/azure/resourcemanager/dashboard/DashboardManagerTests.java index a2e3786debf24..d950c2b3406ab 100644 --- a/sdk/dashboard/azure-resourcemanager-dashboard/src/test/java/com/azure/resourcemanager/dashboard/DashboardManagerTests.java +++ b/sdk/dashboard/azure-resourcemanager-dashboard/src/test/java/com/azure/resourcemanager/dashboard/DashboardManagerTests.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.dashboard.models.*; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - dashboardManager = DashboardManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + dashboardManager = DashboardManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/datafactory/azure-resourcemanager-datafactory/src/test/java/com/azure/resourcemanager/datafactory/DataFactoryTests.java b/sdk/datafactory/azure-resourcemanager-datafactory/src/test/java/com/azure/resourcemanager/datafactory/DataFactoryTests.java index be9a16e19130b..b9e541b805bb5 100644 --- a/sdk/datafactory/azure-resourcemanager-datafactory/src/test/java/com/azure/resourcemanager/datafactory/DataFactoryTests.java +++ b/sdk/datafactory/azure-resourcemanager-datafactory/src/test/java/com/azure/resourcemanager/datafactory/DataFactoryTests.java @@ -3,6 +3,7 @@ package com.azure.resourcemanager.datafactory; +import com.azure.core.credential.TokenCredential; import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.management.AzureEnvironment; @@ -26,6 +27,8 @@ import com.azure.resourcemanager.datafactory.models.PipelineResource; import com.azure.resourcemanager.datafactory.models.PipelineRun; import com.azure.resourcemanager.datafactory.models.TextFormat; +import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.storage.StorageManager; import com.azure.resourcemanager.storage.models.PublicAccess; import com.azure.resourcemanager.storage.models.StorageAccount; @@ -50,19 +53,29 @@ public class DataFactoryTests extends TestProxyTestBase { @Test @LiveOnly public void dataFactoryTest() { - StorageManager storageManager = StorageManager.authenticate(new AzurePowerShellCredentialBuilder().build(), - new AzureProfile(AzureEnvironment.AZURE)); + TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + + ResourceManager resourceManager = ResourceManager.configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile) + .withDefaultSubscription(); + + StorageManager storageManager = StorageManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .authenticate(credential, profile); DataFactoryManager manager = DataFactoryManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(new AzurePowerShellCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)); + .authenticate(credential, profile); String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); boolean testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); if (testEnv) { resourceGroup = testResourceGroup; } else { - storageManager.resourceManager().resourceGroups().define(resourceGroup).withRegion(REGION).create(); + resourceManager.resourceGroups().define(resourceGroup).withRegion(REGION).create(); } try { @@ -169,7 +182,7 @@ public void dataFactoryTest() { storageManager.storageAccounts().deleteById(storageAccount.id()); } finally { if (!testEnv) { - storageManager.resourceManager().resourceGroups().beginDeleteByName(resourceGroup); + resourceManager.resourceGroups().beginDeleteByName(resourceGroup); } } } diff --git a/sdk/dataprotection/azure-resourcemanager-dataprotection/src/test/java/com/azure/resourcemanager/dataprotection/DataProtectionManagerTest.java b/sdk/dataprotection/azure-resourcemanager-dataprotection/src/test/java/com/azure/resourcemanager/dataprotection/DataProtectionManagerTest.java index 7adc04bab04de..698513a0066b7 100644 --- a/sdk/dataprotection/azure-resourcemanager-dataprotection/src/test/java/com/azure/resourcemanager/dataprotection/DataProtectionManagerTest.java +++ b/sdk/dataprotection/azure-resourcemanager-dataprotection/src/test/java/com/azure/resourcemanager/dataprotection/DataProtectionManagerTest.java @@ -39,6 +39,7 @@ import com.azure.resourcemanager.dataprotection.models.StorageSettingStoreTypes; import com.azure.resourcemanager.dataprotection.models.StorageSettingTypes; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -58,15 +59,16 @@ public void beforeTest() { final TokenCredential credential = getIdentityTestCredential(super.interceptorManager); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - dataProtectionManager = DataProtectionManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + dataProtectionManager = DataProtectionManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/deviceupdate/azure-resourcemanager-deviceupdate/src/test/java/com/azure/resourcemanager/deviceupdate/DeviceUpdateManagerTests.java b/sdk/deviceupdate/azure-resourcemanager-deviceupdate/src/test/java/com/azure/resourcemanager/deviceupdate/DeviceUpdateManagerTests.java index d771f498a6aae..45310bf90fd38 100644 --- a/sdk/deviceupdate/azure-resourcemanager-deviceupdate/src/test/java/com/azure/resourcemanager/deviceupdate/DeviceUpdateManagerTests.java +++ b/sdk/deviceupdate/azure-resourcemanager-deviceupdate/src/test/java/com/azure/resourcemanager/deviceupdate/DeviceUpdateManagerTests.java @@ -17,6 +17,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.deviceupdate.models.Account; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -35,15 +36,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - deviceUpdateManager = DeviceUpdateManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + deviceUpdateManager = DeviceUpdateManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/devtestlabs/azure-resourcemanager-devtestlabs/src/test/java/com/azure/resourcemanager/devtestlabs/DevTestLabsManagerTests.java b/sdk/devtestlabs/azure-resourcemanager-devtestlabs/src/test/java/com/azure/resourcemanager/devtestlabs/DevTestLabsManagerTests.java index ca3ef88d23004..e6727a04dfab2 100644 --- a/sdk/devtestlabs/azure-resourcemanager-devtestlabs/src/test/java/com/azure/resourcemanager/devtestlabs/DevTestLabsManagerTests.java +++ b/sdk/devtestlabs/azure-resourcemanager-devtestlabs/src/test/java/com/azure/resourcemanager/devtestlabs/DevTestLabsManagerTests.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.devtestlabs.models.Lab; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - devTestLabsManager = DevTestLabsManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + devTestLabsManager = DevTestLabsManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); From cce5336cc114e07efd1c34d27fb38ffef57270b3 Mon Sep 17 00:00:00 2001 From: "Hong Li(MSFT)" <74638143+v-hongli1@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:46:00 +0800 Subject: [PATCH 4/7] Register provider via policy Part Six (#43440) Register provider via policy Part Six (#43440) --- .../PaloAltoNetworksNgfwManagerTests.java | 10 +++++---- .../postgresql/PostgreSqlManagerTests.java | 10 +++++---- .../PostgreSqlManagerTests.java | 12 ++++++----- .../providerhub/ProviderHubManagerTests.java | 10 +++++---- .../RecoveryServicesManagerTests.java | 10 +++++---- .../RecoveryServicesBackupManagerTests.java | 13 +++++++----- .../resourcehealth/ResourceHealthTests.java | 21 +++++++++++++++---- .../ResourceMoverManagerTests.java | 10 +++++---- 8 files changed, 62 insertions(+), 34 deletions(-) diff --git a/sdk/paloaltonetworks/azure-resourcemanager-paloaltonetworks-ngfw/src/test/java/com/azure/resourcemanager/paloaltonetworks/ngfw/PaloAltoNetworksNgfwManagerTests.java b/sdk/paloaltonetworks/azure-resourcemanager-paloaltonetworks-ngfw/src/test/java/com/azure/resourcemanager/paloaltonetworks/ngfw/PaloAltoNetworksNgfwManagerTests.java index 35df74a5c2a06..078d5b5555586 100644 --- a/sdk/paloaltonetworks/azure-resourcemanager-paloaltonetworks-ngfw/src/test/java/com/azure/resourcemanager/paloaltonetworks/ngfw/PaloAltoNetworksNgfwManagerTests.java +++ b/sdk/paloaltonetworks/azure-resourcemanager-paloaltonetworks-ngfw/src/test/java/com/azure/resourcemanager/paloaltonetworks/ngfw/PaloAltoNetworksNgfwManagerTests.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.paloaltonetworks.ngfw.models.*; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - paloAltoNetworksNgfwManager = PaloAltoNetworksNgfwManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + paloAltoNetworksNgfwManager = PaloAltoNetworksNgfwManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/postgresql/azure-resourcemanager-postgresql/src/test/java/com/azure/resourcemanager/postgresql/PostgreSqlManagerTests.java b/sdk/postgresql/azure-resourcemanager-postgresql/src/test/java/com/azure/resourcemanager/postgresql/PostgreSqlManagerTests.java index 9d553ae8944a4..a71c03538cfa3 100644 --- a/sdk/postgresql/azure-resourcemanager-postgresql/src/test/java/com/azure/resourcemanager/postgresql/PostgreSqlManagerTests.java +++ b/sdk/postgresql/azure-resourcemanager-postgresql/src/test/java/com/azure/resourcemanager/postgresql/PostgreSqlManagerTests.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.postgresql.models.*; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import io.netty.util.internal.StringUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -36,15 +37,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - postgreSqlManager = PostgreSqlManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + postgreSqlManager = PostgreSqlManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/postgresqlflexibleserver/azure-resourcemanager-postgresqlflexibleserver/src/test/java/com/azure/resourcemanager/postgresqlflexibleserver/PostgreSqlManagerTests.java b/sdk/postgresqlflexibleserver/azure-resourcemanager-postgresqlflexibleserver/src/test/java/com/azure/resourcemanager/postgresqlflexibleserver/PostgreSqlManagerTests.java index d4d24324b23f8..2c044e4915547 100644 --- a/sdk/postgresqlflexibleserver/azure-resourcemanager-postgresqlflexibleserver/src/test/java/com/azure/resourcemanager/postgresqlflexibleserver/PostgreSqlManagerTests.java +++ b/sdk/postgresqlflexibleserver/azure-resourcemanager-postgresqlflexibleserver/src/test/java/com/azure/resourcemanager/postgresqlflexibleserver/PostgreSqlManagerTests.java @@ -32,6 +32,7 @@ import com.azure.resourcemanager.postgresqlflexibleserver.models.Storage; import com.azure.resourcemanager.postgresqlflexibleserver.models.UserAssignedIdentity; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import io.netty.util.internal.StringUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -41,7 +42,7 @@ public class PostgreSqlManagerTests extends TestProxyTestBase { private static final Random RANDOM = new Random(); - private static final Region REGION = Region.US_WEST; + private static final Region REGION = Region.US_WEST3; private String resourceGroupName = "rg" + randomPadding(); private PostgreSqlManager postgreSqlManager; private ResourceManager resourceManager; @@ -52,15 +53,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - postgreSqlManager = PostgreSqlManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + postgreSqlManager = PostgreSqlManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/providerhub/azure-resourcemanager-providerhub/src/test/java/com/azure/resourcemanager/providerhub/ProviderHubManagerTests.java b/sdk/providerhub/azure-resourcemanager-providerhub/src/test/java/com/azure/resourcemanager/providerhub/ProviderHubManagerTests.java index 60c1c307715b5..98276136aabbb 100644 --- a/sdk/providerhub/azure-resourcemanager-providerhub/src/test/java/com/azure/resourcemanager/providerhub/ProviderHubManagerTests.java +++ b/sdk/providerhub/azure-resourcemanager-providerhub/src/test/java/com/azure/resourcemanager/providerhub/ProviderHubManagerTests.java @@ -19,6 +19,7 @@ import com.azure.resourcemanager.providerhub.models.OperationsDefinitionDisplay; import com.azure.resourcemanager.providerhub.models.OperationsPutContent; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -38,15 +39,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - providerHubManager = ProviderHubManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + providerHubManager = ProviderHubManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/recoveryservices/azure-resourcemanager-recoveryservices/src/test/java/com/azure/resourcemanager/recoveryservices/RecoveryServicesManagerTests.java b/sdk/recoveryservices/azure-resourcemanager-recoveryservices/src/test/java/com/azure/resourcemanager/recoveryservices/RecoveryServicesManagerTests.java index b262eeefd962b..02dbb47bfb2e4 100644 --- a/sdk/recoveryservices/azure-resourcemanager-recoveryservices/src/test/java/com/azure/resourcemanager/recoveryservices/RecoveryServicesManagerTests.java +++ b/sdk/recoveryservices/azure-resourcemanager-recoveryservices/src/test/java/com/azure/resourcemanager/recoveryservices/RecoveryServicesManagerTests.java @@ -26,6 +26,7 @@ import com.azure.resourcemanager.recoveryservices.models.Vault; import com.azure.resourcemanager.recoveryservices.models.VaultProperties; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -44,15 +45,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - recoveryServicesManager = RecoveryServicesManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + recoveryServicesManager = RecoveryServicesManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/recoveryservicesbackup/azure-resourcemanager-recoveryservicesbackup/src/test/java/com/azure/resourcemanager/recoveryservicesbackup/RecoveryServicesBackupManagerTests.java b/sdk/recoveryservicesbackup/azure-resourcemanager-recoveryservicesbackup/src/test/java/com/azure/resourcemanager/recoveryservicesbackup/RecoveryServicesBackupManagerTests.java index 3cf1124dacacb..c8b41d4d79725 100644 --- a/sdk/recoveryservicesbackup/azure-resourcemanager-recoveryservicesbackup/src/test/java/com/azure/resourcemanager/recoveryservicesbackup/RecoveryServicesBackupManagerTests.java +++ b/sdk/recoveryservicesbackup/azure-resourcemanager-recoveryservicesbackup/src/test/java/com/azure/resourcemanager/recoveryservicesbackup/RecoveryServicesBackupManagerTests.java @@ -45,6 +45,7 @@ import com.azure.resourcemanager.recoveryservicesbackup.models.WorkloadType; import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -69,19 +70,21 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + resourceManager = ResourceManager.configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile) + .withDefaultSubscription(); + recoveryServicesManager = RecoveryServicesManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); recoveryServicesBackupManager = RecoveryServicesBackupManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); - resourceManager = ResourceManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile) - .withDefaultSubscription(); - // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/resourcehealth/azure-resourcemanager-resourcehealth/src/test/java/com/azure/resourcemanager/resourcehealth/ResourceHealthTests.java b/sdk/resourcehealth/azure-resourcemanager-resourcehealth/src/test/java/com/azure/resourcemanager/resourcehealth/ResourceHealthTests.java index 6fbe0c18c2c6b..e0265bf01c1a2 100644 --- a/sdk/resourcehealth/azure-resourcemanager-resourcehealth/src/test/java/com/azure/resourcemanager/resourcehealth/ResourceHealthTests.java +++ b/sdk/resourcehealth/azure-resourcemanager-resourcehealth/src/test/java/com/azure/resourcemanager/resourcehealth/ResourceHealthTests.java @@ -3,6 +3,7 @@ package com.azure.resourcemanager.resourcehealth; +import com.azure.core.credential.TokenCredential; import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.rest.PagedIterable; @@ -21,6 +22,8 @@ import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes; import com.azure.resourcemanager.resourcehealth.models.AvailabilityStateValues; import com.azure.resourcemanager.resourcehealth.models.AvailabilityStatus; +import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -41,20 +44,30 @@ private static String randomPadding() { @Test @LiveOnly public void resourceHealthTest() { + TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + + ResourceManager resourceManager = ResourceManager.configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile) + .withDefaultSubscription(); + ComputeManager computeManager = ComputeManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(new AzurePowerShellCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)); + .authenticate(credential, profile); ResourceHealthManager resourceHealthManager = ResourceHealthManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) - .authenticate(new AzurePowerShellCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)); + .authenticate(credential, profile); String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); boolean testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); if (testEnv) { resourceGroup = testResourceGroup; } else { - computeManager.resourceManager().resourceGroups().define(resourceGroup).withRegion(REGION).create(); + resourceManager.resourceGroups().define(resourceGroup).withRegion(REGION).create(); } try { @@ -115,7 +128,7 @@ public void resourceHealthTest() { // && AvailabilityStateValues.AVAILABLE.equals(status.properties().availabilityState()))); } finally { if (!testEnv) { - computeManager.resourceManager().resourceGroups().beginDeleteByName(resourceGroup); + resourceManager.resourceGroups().beginDeleteByName(resourceGroup); } } } diff --git a/sdk/resourcemover/azure-resourcemanager-resourcemover/src/test/java/com/azure/resourcemanager/resourcemover/ResourceMoverManagerTests.java b/sdk/resourcemover/azure-resourcemanager-resourcemover/src/test/java/com/azure/resourcemanager/resourcemover/ResourceMoverManagerTests.java index abbb90fd50be9..f90e730ace8ba 100644 --- a/sdk/resourcemover/azure-resourcemanager-resourcemover/src/test/java/com/azure/resourcemanager/resourcemover/ResourceMoverManagerTests.java +++ b/sdk/resourcemover/azure-resourcemanager-resourcemover/src/test/java/com/azure/resourcemanager/resourcemover/ResourceMoverManagerTests.java @@ -17,6 +17,7 @@ import com.azure.resourcemanager.resourcemover.models.MoveCollection; import com.azure.resourcemanager.resourcemover.models.MoveCollectionProperties; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -35,15 +36,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - resourceMoverManager = ResourceMoverManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + resourceMoverManager = ResourceMoverManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); From 35e589b574dd8bcc469d5c2a3e5a3f955c3ef6a5 Mon Sep 17 00:00:00 2001 From: "Hong Li(MSFT)" <74638143+v-hongli1@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:46:18 +0800 Subject: [PATCH 5/7] Register provider via policy Part seven (#43441) Register provider via policy Part seven (#43441) --- ...viceFabricManagedClustersManagerTests.java | 34 +++---------------- .../TrafficControllerManagerTests.java | 10 +++--- .../sphere/AzureSphereManagerTests.java | 10 +++--- .../StorageMoverManagerTests.java | 12 ++++--- .../webpubsub/WebPubSubManagerTests.java | 10 +++--- 5 files changed, 30 insertions(+), 46 deletions(-) diff --git a/sdk/servicefabricmanagedclusters/azure-resourcemanager-servicefabricmanagedclusters/src/test/java/com/azure/resourcemanager/servicefabricmanagedclusters/ServiceFabricManagedClustersManagerTests.java b/sdk/servicefabricmanagedclusters/azure-resourcemanager-servicefabricmanagedclusters/src/test/java/com/azure/resourcemanager/servicefabricmanagedclusters/ServiceFabricManagedClustersManagerTests.java index cb6bd4dc5ebe9..e662038f54915 100644 --- a/sdk/servicefabricmanagedclusters/azure-resourcemanager-servicefabricmanagedclusters/src/test/java/com/azure/resourcemanager/servicefabricmanagedclusters/ServiceFabricManagedClustersManagerTests.java +++ b/sdk/servicefabricmanagedclusters/azure-resourcemanager-servicefabricmanagedclusters/src/test/java/com/azure/resourcemanager/servicefabricmanagedclusters/ServiceFabricManagedClustersManagerTests.java @@ -15,17 +15,13 @@ import com.azure.core.util.CoreUtils; import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.resources.ResourceManager; -import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils; -import com.azure.resourcemanager.resources.models.Provider; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.servicefabricmanagedclusters.models.ManagedCluster; import com.azure.resourcemanager.servicefabricmanagedclusters.models.Sku; import com.azure.resourcemanager.servicefabricmanagedclusters.models.SkuName; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.time.Duration; -import java.util.Arrays; -import java.util.List; import java.util.Random; import java.util.UUID; @@ -42,16 +38,15 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - serviceFabricManagedClustersManager = ServiceFabricManagedClustersManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); - canRegisterProviders(Arrays.asList("Microsoft.ServiceFabric")); + serviceFabricManagedClustersManager = ServiceFabricManagedClustersManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); @@ -110,23 +105,4 @@ public void testCreateManagedCluster() { private static String randomPadding() { return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000)); } - - /** - * Check and register service resources - * - * @param providerNamespaces the resource provider names - */ - private void canRegisterProviders(List providerNamespaces) { - providerNamespaces.forEach(providerNamespace -> { - Provider provider = resourceManager.providers().getByName(providerNamespace); - if (!"Registered".equalsIgnoreCase(provider.registrationState()) - && !"Registering".equalsIgnoreCase(provider.registrationState())) { - provider = resourceManager.providers().register(providerNamespace); - } - while (!"Registered".equalsIgnoreCase(provider.registrationState())) { - ResourceManagerUtils.sleep(Duration.ofSeconds(5)); - provider = resourceManager.providers().getByName(provider.namespace()); - } - }); - } } diff --git a/sdk/servicenetworking/azure-resourcemanager-servicenetworking/src/test/java/com/azure/resourcemanager/servicenetworking/TrafficControllerManagerTests.java b/sdk/servicenetworking/azure-resourcemanager-servicenetworking/src/test/java/com/azure/resourcemanager/servicenetworking/TrafficControllerManagerTests.java index 5214c6be6228a..68b15e8267fa3 100644 --- a/sdk/servicenetworking/azure-resourcemanager-servicenetworking/src/test/java/com/azure/resourcemanager/servicenetworking/TrafficControllerManagerTests.java +++ b/sdk/servicenetworking/azure-resourcemanager-servicenetworking/src/test/java/com/azure/resourcemanager/servicenetworking/TrafficControllerManagerTests.java @@ -15,6 +15,7 @@ import com.azure.core.util.CoreUtils; import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.servicenetworking.models.TrafficController; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - trafficControllerManager = TrafficControllerManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + trafficControllerManager = TrafficControllerManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/sphere/azure-resourcemanager-sphere/src/test/java/com/azure/resourcemanager/sphere/AzureSphereManagerTests.java b/sdk/sphere/azure-resourcemanager-sphere/src/test/java/com/azure/resourcemanager/sphere/AzureSphereManagerTests.java index ad1deba3c3b57..a18645c49e9cc 100644 --- a/sdk/sphere/azure-resourcemanager-sphere/src/test/java/com/azure/resourcemanager/sphere/AzureSphereManagerTests.java +++ b/sdk/sphere/azure-resourcemanager-sphere/src/test/java/com/azure/resourcemanager/sphere/AzureSphereManagerTests.java @@ -15,6 +15,7 @@ import com.azure.core.util.CoreUtils; import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.sphere.models.Catalog; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -35,15 +36,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - azureSphereManager = AzureSphereManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + azureSphereManager = AzureSphereManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/storagemover/azure-resourcemanager-storagemover/src/test/java/com/azure/resourcemanager/storagemover/StorageMoverManagerTests.java b/sdk/storagemover/azure-resourcemanager-storagemover/src/test/java/com/azure/resourcemanager/storagemover/StorageMoverManagerTests.java index 08e641677dcd0..8211480ee8e3a 100644 --- a/sdk/storagemover/azure-resourcemanager-storagemover/src/test/java/com/azure/resourcemanager/storagemover/StorageMoverManagerTests.java +++ b/sdk/storagemover/azure-resourcemanager-storagemover/src/test/java/com/azure/resourcemanager/storagemover/StorageMoverManagerTests.java @@ -15,6 +15,7 @@ import com.azure.core.util.CoreUtils; import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.storagemover.models.StorageMover; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -23,7 +24,7 @@ public class StorageMoverManagerTests extends TestProxyTestBase { private static final Random RANDOM = new Random(); - private static final Region REGION = Region.create("eastus2euap", "East US 2 EUAP"); + private static final Region REGION = Region.US_EAST2; private String resourceGroupName = "rg" + randomPadding(); private StorageMoverManager storageMoverManager; private ResourceManager resourceManager; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - storageMoverManager = StorageMoverManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + storageMoverManager = StorageMoverManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/webpubsub/azure-resourcemanager-webpubsub/src/test/java/com/azure/resourcemanager/webpubsub/WebPubSubManagerTests.java b/sdk/webpubsub/azure-resourcemanager-webpubsub/src/test/java/com/azure/resourcemanager/webpubsub/WebPubSubManagerTests.java index cade90cba06d7..d0305fa4c0f15 100644 --- a/sdk/webpubsub/azure-resourcemanager-webpubsub/src/test/java/com/azure/resourcemanager/webpubsub/WebPubSubManagerTests.java +++ b/sdk/webpubsub/azure-resourcemanager-webpubsub/src/test/java/com/azure/resourcemanager/webpubsub/WebPubSubManagerTests.java @@ -15,6 +15,7 @@ import com.azure.core.util.CoreUtils; import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.webpubsub.models.ResourceSku; import com.azure.resourcemanager.webpubsub.models.WebPubSubResource; import com.azure.resourcemanager.webpubsub.models.WebPubSubSkuTier; @@ -37,15 +38,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - webPubSubManager = WebPubSubManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + webPubSubManager = WebPubSubManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); From ccbd991486ae0e41984471740ae821e87a6225ab Mon Sep 17 00:00:00 2001 From: "Hong Li(MSFT)" <74638143+v-hongli1@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:05:52 +0800 Subject: [PATCH 6/7] Register provider via policy Part five (#43439) --- .../loadtesting/TestOrchestratorTests.java | 10 +++++---- .../LogAnalyticsManagerTests.java | 10 +++++---- .../MachineLearningManagerTests.java | 15 ++++++++----- .../ManagedNetworkFabricManagerTest.java | 10 +++++---- .../pom.xml | 6 ++++++ .../mediaservices/MediaServicesTests.java | 21 +++++++++++++++---- .../MongoClusterManagerTests.java | 10 +++++---- .../mysql/MySqlManagerTests.java | 2 ++ .../mysqlflexibleserver/MySqlManagerTest.java | 10 +++++---- 9 files changed, 65 insertions(+), 29 deletions(-) diff --git a/sdk/loadtesting/azure-resourcemanager-loadtesting/src/test/java/com/azure/resourcemanager/loadtesting/TestOrchestratorTests.java b/sdk/loadtesting/azure-resourcemanager-loadtesting/src/test/java/com/azure/resourcemanager/loadtesting/TestOrchestratorTests.java index f91ac22f6e9d2..41964dd39cc39 100644 --- a/sdk/loadtesting/azure-resourcemanager-loadtesting/src/test/java/com/azure/resourcemanager/loadtesting/TestOrchestratorTests.java +++ b/sdk/loadtesting/azure-resourcemanager-loadtesting/src/test/java/com/azure/resourcemanager/loadtesting/TestOrchestratorTests.java @@ -17,6 +17,7 @@ import java.util.Random; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Test; public class TestOrchestratorTests extends TestProxyTestBase { @@ -35,15 +36,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - loadTestManager = LoadTestManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + loadTestManager = LoadTestManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); if (testEnv) { diff --git a/sdk/loganalytics/azure-resourcemanager-loganalytics/src/test/java/com/azure/resourcemanager/loganalytics/LogAnalyticsManagerTests.java b/sdk/loganalytics/azure-resourcemanager-loganalytics/src/test/java/com/azure/resourcemanager/loganalytics/LogAnalyticsManagerTests.java index 45de8ad1887fb..374d5b25afdeb 100644 --- a/sdk/loganalytics/azure-resourcemanager-loganalytics/src/test/java/com/azure/resourcemanager/loganalytics/LogAnalyticsManagerTests.java +++ b/sdk/loganalytics/azure-resourcemanager-loganalytics/src/test/java/com/azure/resourcemanager/loganalytics/LogAnalyticsManagerTests.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.loganalytics.models.Workspace; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - logAnalyticsManager = LogAnalyticsManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + logAnalyticsManager = LogAnalyticsManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/machinelearning/azure-resourcemanager-machinelearning/src/test/java/com/azure/resourcemanager/machinelearning/MachineLearningManagerTests.java b/sdk/machinelearning/azure-resourcemanager-machinelearning/src/test/java/com/azure/resourcemanager/machinelearning/MachineLearningManagerTests.java index f4d7e69aea6ca..66afd7bc79ad2 100644 --- a/sdk/machinelearning/azure-resourcemanager-machinelearning/src/test/java/com/azure/resourcemanager/machinelearning/MachineLearningManagerTests.java +++ b/sdk/machinelearning/azure-resourcemanager-machinelearning/src/test/java/com/azure/resourcemanager/machinelearning/MachineLearningManagerTests.java @@ -24,6 +24,7 @@ import com.azure.resourcemanager.machinelearning.models.SkuTier; import com.azure.resourcemanager.machinelearning.models.Workspace; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.storage.StorageManager; import com.azure.resourcemanager.storage.models.AccessTier; import com.azure.resourcemanager.storage.models.MinimumTlsVersion; @@ -49,27 +50,31 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + resourceManager = ResourceManager.configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile) + .withDefaultSubscription(); + machineLearningManager = MachineLearningManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); storageManager = StorageManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); keyVaultManager = KeyVaultManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); applicationInsightsManager = ApplicationInsightsManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); - resourceManager = ResourceManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile) - .withDefaultSubscription(); - // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/managednetworkfabric/azure-resourcemanager-managednetworkfabric/src/test/java/com/azure/resourcemanager/managednetworkfabric/ManagedNetworkFabricManagerTest.java b/sdk/managednetworkfabric/azure-resourcemanager-managednetworkfabric/src/test/java/com/azure/resourcemanager/managednetworkfabric/ManagedNetworkFabricManagerTest.java index 6c6e5a35e39c8..7aef196dbc23f 100644 --- a/sdk/managednetworkfabric/azure-resourcemanager-managednetworkfabric/src/test/java/com/azure/resourcemanager/managednetworkfabric/ManagedNetworkFabricManagerTest.java +++ b/sdk/managednetworkfabric/azure-resourcemanager-managednetworkfabric/src/test/java/com/azure/resourcemanager/managednetworkfabric/ManagedNetworkFabricManagerTest.java @@ -33,6 +33,7 @@ import com.azure.resourcemanager.managednetworkfabric.models.VlanGroupProperties; import com.azure.resourcemanager.managednetworkfabric.models.VlanMatchCondition; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -52,15 +53,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - managedNetworkFabricManager = ManagedNetworkFabricManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + managedNetworkFabricManager = ManagedNetworkFabricManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/mediaservices/azure-resourcemanager-mediaservices/pom.xml b/sdk/mediaservices/azure-resourcemanager-mediaservices/pom.xml index a6db1f20f6aaa..ccdca013faf7b 100644 --- a/sdk/mediaservices/azure-resourcemanager-mediaservices/pom.xml +++ b/sdk/mediaservices/azure-resourcemanager-mediaservices/pom.xml @@ -95,5 +95,11 @@ 2.45.0 test + + com.azure.resourcemanager + azure-resourcemanager-resources + 2.45.0 + test + diff --git a/sdk/mediaservices/azure-resourcemanager-mediaservices/src/test/java/com/azure/resourcemanager/mediaservices/MediaServicesTests.java b/sdk/mediaservices/azure-resourcemanager-mediaservices/src/test/java/com/azure/resourcemanager/mediaservices/MediaServicesTests.java index d5fcc6e670d06..0812ed383768b 100644 --- a/sdk/mediaservices/azure-resourcemanager-mediaservices/src/test/java/com/azure/resourcemanager/mediaservices/MediaServicesTests.java +++ b/sdk/mediaservices/azure-resourcemanager-mediaservices/src/test/java/com/azure/resourcemanager/mediaservices/MediaServicesTests.java @@ -3,6 +3,7 @@ package com.azure.resourcemanager.mediaservices; +import com.azure.core.credential.TokenCredential; import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.management.AzureEnvironment; @@ -24,6 +25,8 @@ import com.azure.resourcemanager.mediaservices.models.StorageAccountType; import com.azure.resourcemanager.mediaservices.models.Transform; import com.azure.resourcemanager.mediaservices.models.TransformOutput; +import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import com.azure.resourcemanager.storage.StorageManager; import com.azure.resourcemanager.storage.models.StorageAccount; import org.junit.jupiter.api.Assertions; @@ -47,20 +50,30 @@ public class MediaServicesTests extends TestProxyTestBase { @Test @LiveOnly public void mediaServicesTest() { + TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + + ResourceManager resourceManager = ResourceManager.configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile) + .withDefaultSubscription(); + StorageManager storageManager = StorageManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(new AzurePowerShellCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)); + .authenticate(credential, profile); MediaServicesManager manager = MediaServicesManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(new AzurePowerShellCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)); + .authenticate(credential, profile); String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); boolean testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); if (testEnv) { resourceGroup = testResourceGroup; } else { - storageManager.resourceManager().resourceGroups().define(resourceGroup).withRegion(REGION).create(); + resourceManager.resourceGroups().define(resourceGroup).withRegion(REGION).create(); } try { @@ -127,7 +140,7 @@ public void mediaServicesTest() { storageManager.storageAccounts().deleteById(storageAccount.id()); } finally { if (!testEnv) { - storageManager.resourceManager().resourceGroups().beginDeleteByName(resourceGroup); + resourceManager.resourceGroups().beginDeleteByName(resourceGroup); } } } diff --git a/sdk/mongocluster/azure-resourcemanager-mongocluster/src/test/java/com/azure/resourcemanager/mongocluster/MongoClusterManagerTests.java b/sdk/mongocluster/azure-resourcemanager-mongocluster/src/test/java/com/azure/resourcemanager/mongocluster/MongoClusterManagerTests.java index d5b883eaab82c..c3349a5bb4366 100644 --- a/sdk/mongocluster/azure-resourcemanager-mongocluster/src/test/java/com/azure/resourcemanager/mongocluster/MongoClusterManagerTests.java +++ b/sdk/mongocluster/azure-resourcemanager-mongocluster/src/test/java/com/azure/resourcemanager/mongocluster/MongoClusterManagerTests.java @@ -24,6 +24,7 @@ import com.azure.resourcemanager.mongocluster.models.ShardingProperties; import com.azure.resourcemanager.mongocluster.models.StorageProperties; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -43,15 +44,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - mongoClusterManager = MongoClusterManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + mongoClusterManager = MongoClusterManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/mysql/azure-resourcemanager-mysql/src/test/java/com/azure/resourcemanager/mysql/MySqlManagerTests.java b/sdk/mysql/azure-resourcemanager-mysql/src/test/java/com/azure/resourcemanager/mysql/MySqlManagerTests.java index aa4fb5ac890f6..0cb313b8a8e70 100644 --- a/sdk/mysql/azure-resourcemanager-mysql/src/test/java/com/azure/resourcemanager/mysql/MySqlManagerTests.java +++ b/sdk/mysql/azure-resourcemanager-mysql/src/test/java/com/azure/resourcemanager/mysql/MySqlManagerTests.java @@ -29,11 +29,13 @@ import com.azure.resourcemanager.resources.ResourceManager; import io.netty.util.internal.StringUtil; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.util.Random; import java.util.UUID; +@Disabled("Azure Database for MySQL - Single Server retired on September 16, 2024.") public class MySqlManagerTests extends TestProxyTestBase { private static final Random RANDOM = new Random(); private static final Region REGION = Region.EUROPE_WEST; diff --git a/sdk/mysqlflexibleserver/azure-resourcemanager-mysqlflexibleserver/src/test/java/com/azure/resourcemanager/mysqlflexibleserver/MySqlManagerTest.java b/sdk/mysqlflexibleserver/azure-resourcemanager-mysqlflexibleserver/src/test/java/com/azure/resourcemanager/mysqlflexibleserver/MySqlManagerTest.java index abc833ccf6357..801e24e8bd141 100644 --- a/sdk/mysqlflexibleserver/azure-resourcemanager-mysqlflexibleserver/src/test/java/com/azure/resourcemanager/mysqlflexibleserver/MySqlManagerTest.java +++ b/sdk/mysqlflexibleserver/azure-resourcemanager-mysqlflexibleserver/src/test/java/com/azure/resourcemanager/mysqlflexibleserver/MySqlManagerTest.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.mysqlflexibleserver.models.Server; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import io.netty.util.internal.StringUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -36,15 +37,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - mysqlManager = MySqlManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + mysqlManager = MySqlManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); From 3957be7ab963fa324d2c4d8ecffed9ac5fd2c6d0 Mon Sep 17 00:00:00 2001 From: "Hong Li(MSFT)" <74638143+v-hongli1@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:06:06 +0800 Subject: [PATCH 7/7] Register provider via policy Part Four (#43425) --- .../fluidrelay/FluidRelayManagerTests.java | 10 ++++++---- .../frontdoor/FrontDoorManagerTests.java | 10 ++++++---- .../healthcareapis/HealthcareApisManagerTests.java | 10 ++++++---- .../imagebuilder/ImageBuilderManagerTests.java | 13 ++++++++----- .../iotcentral/IotCentralManagerTests.java | 10 ++++++---- .../IoTFirmwareDefenseManagerTests.java | 10 ++++++---- .../resourcemanager/iothub/IotHubManagerTests.java | 10 ++++++---- .../resourcemanager/kusto/KustoManagerTests.java | 10 ++++++---- 8 files changed, 50 insertions(+), 33 deletions(-) diff --git a/sdk/fluidrelay/azure-resourcemanager-fluidrelay/src/test/java/com/azure/resourcemanager/fluidrelay/FluidRelayManagerTests.java b/sdk/fluidrelay/azure-resourcemanager-fluidrelay/src/test/java/com/azure/resourcemanager/fluidrelay/FluidRelayManagerTests.java index 78ba328ec3a02..c34a141c99caf 100644 --- a/sdk/fluidrelay/azure-resourcemanager-fluidrelay/src/test/java/com/azure/resourcemanager/fluidrelay/FluidRelayManagerTests.java +++ b/sdk/fluidrelay/azure-resourcemanager-fluidrelay/src/test/java/com/azure/resourcemanager/fluidrelay/FluidRelayManagerTests.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.fluidrelay.models.FluidRelayServer; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - fluidRelayManager = FluidRelayManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + fluidRelayManager = FluidRelayManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/frontdoor/azure-resourcemanager-frontdoor/src/test/java/com/azure/resourcemanager/frontdoor/FrontDoorManagerTests.java b/sdk/frontdoor/azure-resourcemanager-frontdoor/src/test/java/com/azure/resourcemanager/frontdoor/FrontDoorManagerTests.java index 2a268993cf1e5..ec3bf55422ddf 100644 --- a/sdk/frontdoor/azure-resourcemanager-frontdoor/src/test/java/com/azure/resourcemanager/frontdoor/FrontDoorManagerTests.java +++ b/sdk/frontdoor/azure-resourcemanager-frontdoor/src/test/java/com/azure/resourcemanager/frontdoor/FrontDoorManagerTests.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.frontdoor.models.WebApplicationFirewallPolicy; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - frontDoorManager = FrontDoorManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + frontDoorManager = FrontDoorManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/healthcareapis/azure-resourcemanager-healthcareapis/src/test/java/com/azure/resourcemanager/healthcareapis/HealthcareApisManagerTests.java b/sdk/healthcareapis/azure-resourcemanager-healthcareapis/src/test/java/com/azure/resourcemanager/healthcareapis/HealthcareApisManagerTests.java index 7e074dbbdea8c..52a90b518e779 100644 --- a/sdk/healthcareapis/azure-resourcemanager-healthcareapis/src/test/java/com/azure/resourcemanager/healthcareapis/HealthcareApisManagerTests.java +++ b/sdk/healthcareapis/azure-resourcemanager-healthcareapis/src/test/java/com/azure/resourcemanager/healthcareapis/HealthcareApisManagerTests.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.healthcareapis.models.*; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - healthcareApisManager = HealthcareApisManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + healthcareApisManager = HealthcareApisManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/imagebuilder/azure-resourcemanager-imagebuilder/src/test/java/com/azure/resourcemanager/imagebuilder/ImageBuilderManagerTests.java b/sdk/imagebuilder/azure-resourcemanager-imagebuilder/src/test/java/com/azure/resourcemanager/imagebuilder/ImageBuilderManagerTests.java index 380dc052f0a2e..95d82fb588fdb 100644 --- a/sdk/imagebuilder/azure-resourcemanager-imagebuilder/src/test/java/com/azure/resourcemanager/imagebuilder/ImageBuilderManagerTests.java +++ b/sdk/imagebuilder/azure-resourcemanager-imagebuilder/src/test/java/com/azure/resourcemanager/imagebuilder/ImageBuilderManagerTests.java @@ -25,6 +25,7 @@ import com.azure.resourcemanager.msi.MsiManager; import com.azure.resourcemanager.msi.models.Identity; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -47,19 +48,21 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + resourceManager = ResourceManager.configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile) + .withDefaultSubscription(); + imageBuilderManager = ImageBuilderManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); msiManager = MsiManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); - resourceManager = ResourceManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile) - .withDefaultSubscription(); - // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/iotcentral/azure-resourcemanager-iotcentral/src/test/java/com/azure/resourcemanager/iotcentral/IotCentralManagerTests.java b/sdk/iotcentral/azure-resourcemanager-iotcentral/src/test/java/com/azure/resourcemanager/iotcentral/IotCentralManagerTests.java index 5f326702fdfea..d249730ebb177 100644 --- a/sdk/iotcentral/azure-resourcemanager-iotcentral/src/test/java/com/azure/resourcemanager/iotcentral/IotCentralManagerTests.java +++ b/sdk/iotcentral/azure-resourcemanager-iotcentral/src/test/java/com/azure/resourcemanager/iotcentral/IotCentralManagerTests.java @@ -23,6 +23,7 @@ import com.azure.resourcemanager.iotcentral.models.SystemAssignedServiceIdentity; import com.azure.resourcemanager.iotcentral.models.SystemAssignedServiceIdentityType; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -42,15 +43,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - iotCentralManager = IotCentralManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + iotCentralManager = IotCentralManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/iotfirmwaredefense/azure-resourcemanager-iotfirmwaredefense/src/test/java/com/azure/resourcemanager/iotfirmwaredefense/IoTFirmwareDefenseManagerTests.java b/sdk/iotfirmwaredefense/azure-resourcemanager-iotfirmwaredefense/src/test/java/com/azure/resourcemanager/iotfirmwaredefense/IoTFirmwareDefenseManagerTests.java index b21f21cf34943..e6c67960f5e10 100644 --- a/sdk/iotfirmwaredefense/azure-resourcemanager-iotfirmwaredefense/src/test/java/com/azure/resourcemanager/iotfirmwaredefense/IoTFirmwareDefenseManagerTests.java +++ b/sdk/iotfirmwaredefense/azure-resourcemanager-iotfirmwaredefense/src/test/java/com/azure/resourcemanager/iotfirmwaredefense/IoTFirmwareDefenseManagerTests.java @@ -16,6 +16,7 @@ import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.iotfirmwaredefense.models.Workspace; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,15 +35,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - ioTFirmwareDefenseManager = IoTFirmwareDefenseManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + ioTFirmwareDefenseManager = IoTFirmwareDefenseManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/iothub/azure-resourcemanager-iothub/src/test/java/com/azure/resourcemanager/iothub/IotHubManagerTests.java b/sdk/iothub/azure-resourcemanager-iothub/src/test/java/com/azure/resourcemanager/iothub/IotHubManagerTests.java index bd55047f74ee5..038bf020ec195 100644 --- a/sdk/iothub/azure-resourcemanager-iothub/src/test/java/com/azure/resourcemanager/iothub/IotHubManagerTests.java +++ b/sdk/iothub/azure-resourcemanager-iothub/src/test/java/com/azure/resourcemanager/iothub/IotHubManagerTests.java @@ -30,6 +30,7 @@ import com.azure.resourcemanager.iothub.models.ResourceIdentityType; import com.azure.resourcemanager.iothub.models.StorageEndpointProperties; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import io.netty.util.internal.StringUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -54,15 +55,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - iotHubManager = IotHubManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + iotHubManager = IotHubManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); diff --git a/sdk/kusto/azure-resourcemanager-kusto/src/test/java/com/azure/resourcemanager/kusto/KustoManagerTests.java b/sdk/kusto/azure-resourcemanager-kusto/src/test/java/com/azure/resourcemanager/kusto/KustoManagerTests.java index 214a7afe1697e..6457afbb1bc34 100644 --- a/sdk/kusto/azure-resourcemanager-kusto/src/test/java/com/azure/resourcemanager/kusto/KustoManagerTests.java +++ b/sdk/kusto/azure-resourcemanager-kusto/src/test/java/com/azure/resourcemanager/kusto/KustoManagerTests.java @@ -19,6 +19,7 @@ import com.azure.resourcemanager.kusto.models.AzureSkuTier; import com.azure.resourcemanager.kusto.models.Cluster; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -37,15 +38,16 @@ public void beforeTest() { final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); - kustoManager = KustoManager.configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) - .authenticate(credential, profile); - resourceManager = ResourceManager.configure() .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); + kustoManager = KustoManager.configure() + .withPolicy(new ProviderRegistrationPolicy(resourceManager)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup);