From eafb1770a01bd34c0aedee9f371b24434cc55032 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Thu, 30 May 2024 09:47:52 +0800 Subject: [PATCH 1/8] mgmt, NetworkAnalytics, add live tests --- .../pom.xml | 6 ++ .../NetworkAnalyticsManagerTests.java | 102 ++++++++++++++++++ sdk/networkanalytics/test-resources.bicep | 27 +++++ sdk/networkanalytics/tests.mgmt.yml | 16 +++ 4 files changed, 151 insertions(+) create mode 100644 sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java create mode 100644 sdk/networkanalytics/test-resources.bicep create mode 100644 sdk/networkanalytics/tests.mgmt.yml diff --git a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/pom.xml b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/pom.xml index b14bfd833ecbb..90119846fed50 100644 --- a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/pom.xml +++ b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/pom.xml @@ -69,6 +69,12 @@ 1.12.1 test + + com.azure.resourcemanager + azure-resourcemanager-resources + 2.39.0 + test + org.junit.jupiter junit-jupiter-api diff --git a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java new file mode 100644 index 0000000000000..fc241c8749646 --- /dev/null +++ b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.networkanalytics; + +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; +import com.azure.core.management.Region; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.test.TestBase; +import com.azure.core.test.annotation.DoNotRecord; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.identity.DefaultAzureCredentialBuilder; +import com.azure.resourcemanager.networkanalytics.models.DataProduct; +import com.azure.resourcemanager.networkanalytics.models.DataProductProperties; +import com.azure.resourcemanager.networkanalytics.models.ManagedServiceIdentity; +import com.azure.resourcemanager.networkanalytics.models.ManagedServiceIdentityType; +import com.azure.resourcemanager.resources.ResourceManager; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import java.util.Random; + +public class NetworkAnalyticsManagerTests extends TestBase { + private static final Random RANDOM = new Random(); + private static final Region REGION = Region.create("centraluseuap", "Central US EUAP"); + private String resourceGroupName = "rg" + randomPadding(); + private NetworkAnalyticsManager networkAnalyticsManager = null; + private ResourceManager resourceManager; + private boolean testEnv; + + @Override + public void beforeTest() { + final TokenCredential credential = new DefaultAzureCredentialBuilder().build(); + final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + + networkAnalyticsManager = NetworkAnalyticsManager + .configure() + .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); + if (testEnv) { + resourceGroupName = testResourceGroup; + } else { + resourceManager.resourceGroups() + .define(resourceGroupName) + .withRegion(REGION) + .create(); + } + } + + @Override + protected void afterTest() { + if (!testEnv) { + resourceManager.resourceGroups().beginDeleteByName(resourceGroupName); + } + } + + @Test + @DoNotRecord(skipInPlayback = true) + @Disabled("Missing required property: workload. Paths in payload: '$.properties.workload'") + public void testCreateDataProduct() { + DataProduct dataProduct = null; + try { + String dataProductName = "product" + randomPadding(); + // @embedStart + dataProduct = networkAnalyticsManager.dataProducts() + .define(dataProductName) + .withRegion(REGION) + .withExistingResourceGroup(resourceGroupName) + .withProperties(new DataProductProperties().withPublisher("Microsoft").withProduct("MCC").withMajorVersion("1")) + .withIdentity(new ManagedServiceIdentity().withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED)) + .create(); + // @embedEnd + dataProduct.refresh(); + Assertions.assertEquals(dataProduct.name(), dataProductName); + Assertions.assertEquals(dataProductName, networkAnalyticsManager.dataProducts().getById(dataProduct.id()).name()); + Assertions.assertTrue(networkAnalyticsManager.dataProducts().listByResourceGroup(resourceGroupName).stream().findAny().isPresent()); + } finally { + if (dataProduct != null) { + networkAnalyticsManager.dataProducts().deleteById(dataProduct.id()); + } + } + } + + private static String randomPadding() { + return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000)); + } +} diff --git a/sdk/networkanalytics/test-resources.bicep b/sdk/networkanalytics/test-resources.bicep new file mode 100644 index 0000000000000..2250946806c02 --- /dev/null +++ b/sdk/networkanalytics/test-resources.bicep @@ -0,0 +1,27 @@ +@description('The tenant id to which the application and resources belong.') +param tenantId string = '72f988bf-86f1-41af-91ab-2d7cd011db47' + +@description('The client id of the service principal used to run tests.') +param testApplicationId string + +@description('This is the object id of the service principal used to run tests.') +param testApplicationOid string + +@description('The application client secret used to run tests.') +param testApplicationSecret string + +var contributorRoleId = '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c' + +resource contributorRoleId_name 'Microsoft.Authorization/roleAssignments@2022-04-01' = { + name: guid('contributorRoleId${resourceGroup().name}') + properties: { + roleDefinitionId: contributorRoleId + principalId: testApplicationOid + } +} + +output AZURE_TENANT_ID string = tenantId +output AZURE_CLIENT_ID string = testApplicationId +output AZURE_CLIENT_SECRET string = testApplicationSecret +output AZURE_SUBSCRIPTION_ID string = subscription().subscriptionId +output AZURE_RESOURCE_GROUP_NAME string = resourceGroup().name diff --git a/sdk/networkanalytics/tests.mgmt.yml b/sdk/networkanalytics/tests.mgmt.yml new file mode 100644 index 0000000000000..1bd91b1193f05 --- /dev/null +++ b/sdk/networkanalytics/tests.mgmt.yml @@ -0,0 +1,16 @@ +trigger: none + +pr: none + +extends: + template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml + parameters: + ServiceDirectory: networkanalytics + Artifacts: + - name: azure-resourcemanager-networkanalytics + groupId: com.azure.resourcemanager + safeName: azureresourcemanagernetworkanalytics + Clouds: 'Public' + # Only run tests on Windows to save cost. + MatrixFilters: + - pool=.*(win).* From 89e5ef06b498bfdc25f07cb19d6064ccc247c83a Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Fri, 31 May 2024 13:08:05 +0800 Subject: [PATCH 2/8] mgmt, networkanalytics, add live tests --- .../NetworkAnalyticsManagerTests.java | 75 ++----------------- 1 file changed, 5 insertions(+), 70 deletions(-) diff --git a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java index fc241c8749646..b2a73c53ff538 100644 --- a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java +++ b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java @@ -7,31 +7,14 @@ import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.management.AzureEnvironment; -import com.azure.core.management.Region; import com.azure.core.management.profile.AzureProfile; import com.azure.core.test.TestBase; import com.azure.core.test.annotation.DoNotRecord; -import com.azure.core.util.Configuration; -import com.azure.core.util.CoreUtils; import com.azure.identity.DefaultAzureCredentialBuilder; -import com.azure.resourcemanager.networkanalytics.models.DataProduct; -import com.azure.resourcemanager.networkanalytics.models.DataProductProperties; -import com.azure.resourcemanager.networkanalytics.models.ManagedServiceIdentity; -import com.azure.resourcemanager.networkanalytics.models.ManagedServiceIdentityType; -import com.azure.resourcemanager.resources.ResourceManager; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import java.util.Random; - public class NetworkAnalyticsManagerTests extends TestBase { - private static final Random RANDOM = new Random(); - private static final Region REGION = Region.create("centraluseuap", "Central US EUAP"); - private String resourceGroupName = "rg" + randomPadding(); private NetworkAnalyticsManager networkAnalyticsManager = null; - private ResourceManager resourceManager; - private boolean testEnv; @Override public void beforeTest() { @@ -40,63 +23,15 @@ public void beforeTest() { networkAnalyticsManager = NetworkAnalyticsManager .configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) .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); - if (testEnv) { - resourceGroupName = testResourceGroup; - } else { - resourceManager.resourceGroups() - .define(resourceGroupName) - .withRegion(REGION) - .create(); - } - } - - @Override - protected void afterTest() { - if (!testEnv) { - resourceManager.resourceGroups().beginDeleteByName(resourceGroupName); - } } @Test @DoNotRecord(skipInPlayback = true) - @Disabled("Missing required property: workload. Paths in payload: '$.properties.workload'") - public void testCreateDataProduct() { - DataProduct dataProduct = null; - try { - String dataProductName = "product" + randomPadding(); - // @embedStart - dataProduct = networkAnalyticsManager.dataProducts() - .define(dataProductName) - .withRegion(REGION) - .withExistingResourceGroup(resourceGroupName) - .withProperties(new DataProductProperties().withPublisher("Microsoft").withProduct("MCC").withMajorVersion("1")) - .withIdentity(new ManagedServiceIdentity().withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED)) - .create(); - // @embedEnd - dataProduct.refresh(); - Assertions.assertEquals(dataProduct.name(), dataProductName); - Assertions.assertEquals(dataProductName, networkAnalyticsManager.dataProducts().getById(dataProduct.id()).name()); - Assertions.assertTrue(networkAnalyticsManager.dataProducts().listByResourceGroup(resourceGroupName).stream().findAny().isPresent()); - } finally { - if (dataProduct != null) { - networkAnalyticsManager.dataProducts().deleteById(dataProduct.id()); - } - } - } - - private static String randomPadding() { - return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000)); + public void testListDataProducts() { + // @embedStart + networkAnalyticsManager.dataProducts().list(); + // @embedEd } } From 4f77084942046fa457386a47b184f9920b1333c6 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Fri, 31 May 2024 13:30:17 +0800 Subject: [PATCH 3/8] mgmt, networkanalytics, add live tests --- .../networkanalytics/NetworkAnalyticsManagerTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java index b2a73c53ff538..5693892844319 100644 --- a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java +++ b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java @@ -23,7 +23,7 @@ public void beforeTest() { networkAnalyticsManager = NetworkAnalyticsManager .configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); } From 8783b78f1672c3f66c49edf413fe7a71b44f9b01 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Fri, 31 May 2024 13:32:26 +0800 Subject: [PATCH 4/8] mgmt, networkanalytics, add live tests --- .../networkanalytics/NetworkAnalyticsManagerTests.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java index 5693892844319..0bc155f5c0155 100644 --- a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java +++ b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java @@ -30,8 +30,6 @@ public void beforeTest() { @Test @DoNotRecord(skipInPlayback = true) public void testListDataProducts() { - // @embedStart networkAnalyticsManager.dataProducts().list(); - // @embedEd } } From 4951fe1d98cc99ae3941c2c1efbd07d1d6e03f39 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Fri, 31 May 2024 13:47:40 +0800 Subject: [PATCH 5/8] mgmt, networkanalytics, add live tests --- .../networkanalytics/NetworkAnalyticsManagerTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java index 0bc155f5c0155..1509e92933314 100644 --- a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java +++ b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/src/test/java/com/azure/resourcemanager/networkanalytics/NetworkAnalyticsManagerTests.java @@ -9,7 +9,7 @@ import com.azure.core.management.AzureEnvironment; import com.azure.core.management.profile.AzureProfile; import com.azure.core.test.TestBase; -import com.azure.core.test.annotation.DoNotRecord; +import com.azure.core.test.annotation.LiveOnly; import com.azure.identity.DefaultAzureCredentialBuilder; import org.junit.jupiter.api.Test; @@ -28,7 +28,7 @@ public void beforeTest() { } @Test - @DoNotRecord(skipInPlayback = true) + @LiveOnly public void testListDataProducts() { networkAnalyticsManager.dataProducts().list(); } From d16c5235363483d6c84915cd5685e33e67465cc9 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Fri, 31 May 2024 13:55:39 +0800 Subject: [PATCH 6/8] Remove unused dependency. --- .../azure-resourcemanager-networkanalytics/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/pom.xml b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/pom.xml index 90119846fed50..b14bfd833ecbb 100644 --- a/sdk/networkanalytics/azure-resourcemanager-networkanalytics/pom.xml +++ b/sdk/networkanalytics/azure-resourcemanager-networkanalytics/pom.xml @@ -69,12 +69,6 @@ 1.12.1 test - - com.azure.resourcemanager - azure-resourcemanager-resources - 2.39.0 - test - org.junit.jupiter junit-jupiter-api From 505571b803eb96f79ce41edfea7ca4f10b116486 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Fri, 31 May 2024 14:28:14 +0800 Subject: [PATCH 7/8] Fixed for azp run test --- sdk/networkanalytics/tests.mgmt.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sdk/networkanalytics/tests.mgmt.yml b/sdk/networkanalytics/tests.mgmt.yml index 1bd91b1193f05..216a080039f33 100644 --- a/sdk/networkanalytics/tests.mgmt.yml +++ b/sdk/networkanalytics/tests.mgmt.yml @@ -2,15 +2,15 @@ trigger: none pr: none -extends: - template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml - parameters: - ServiceDirectory: networkanalytics - Artifacts: - - name: azure-resourcemanager-networkanalytics - groupId: com.azure.resourcemanager - safeName: azureresourcemanagernetworkanalytics - Clouds: 'Public' - # Only run tests on Windows to save cost. - MatrixFilters: - - pool=.*(win).* +stages: + - template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml + parameters: + ServiceDirectory: networkanalytics + Artifacts: + - name: azure-resourcemanager-networkanalytics + groupId: com.azure.resourcemanager + safeName: azureresourcemanagernetworkanalytics + Clouds: 'Public' + # Only run tests on Windows to save cost. + MatrixFilters: + - pool=.*(win).* From cb092f53cbcbff8bf69a23783aba1a710c5ac2aa Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Fri, 31 May 2024 15:50:20 +0800 Subject: [PATCH 8/8] Fixed for azp run test --- sdk/networkanalytics/tests.mgmt.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sdk/networkanalytics/tests.mgmt.yml b/sdk/networkanalytics/tests.mgmt.yml index 216a080039f33..1bd91b1193f05 100644 --- a/sdk/networkanalytics/tests.mgmt.yml +++ b/sdk/networkanalytics/tests.mgmt.yml @@ -2,15 +2,15 @@ trigger: none pr: none -stages: - - template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml - parameters: - ServiceDirectory: networkanalytics - Artifacts: - - name: azure-resourcemanager-networkanalytics - groupId: com.azure.resourcemanager - safeName: azureresourcemanagernetworkanalytics - Clouds: 'Public' - # Only run tests on Windows to save cost. - MatrixFilters: - - pool=.*(win).* +extends: + template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml + parameters: + ServiceDirectory: networkanalytics + Artifacts: + - name: azure-resourcemanager-networkanalytics + groupId: com.azure.resourcemanager + safeName: azureresourcemanagernetworkanalytics + Clouds: 'Public' + # Only run tests on Windows to save cost. + MatrixFilters: + - pool=.*(win).*