Skip to content

Commit

Permalink
Register provider via policy Part five
Browse files Browse the repository at this point in the history
  • Loading branch information
v-hongli1 committed Dec 17, 2024
1 parent cc996b6 commit f7785c3
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions sdk/mediaservices/azure-resourcemanager-mediaservices/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,11 @@
<version>2.45.0</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-storage;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-resources</artifactId>
<version>2.45.0</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-resources;dependency} -->
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -127,7 +140,7 @@ public void mediaServicesTest() {
storageManager.storageAccounts().deleteById(storageAccount.id());
} finally {
if (!testEnv) {
storageManager.resourceManager().resourceGroups().beginDeleteByName(resourceGroup);
resourceManager.resourceGroups().beginDeleteByName(resourceGroup);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.azure.resourcemanager.mysql.models.SslEnforcementEnum;
import com.azure.resourcemanager.mysql.models.StorageProfile;
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;
Expand All @@ -47,15 +48,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit f7785c3

Please sign in to comment.