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] 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)