Skip to content

Commit fa3f0e6

Browse files
mgmt, deviceregistry, add live tests (Azure#44383)
* mgmt, deviceregistry, add live tests * fix CredentialBuilder * fix line does not match expected header line * add test case for `assetEndpointProfiles` and `billingContainers` * Update sdk/deviceregistry/azure-resourcemanager-deviceregistry/src/test/java/com/azure/resourcemanager/deviceregistry/DeviceRegistryManagerTests.java --------- Co-authored-by: Weidong Xu <[email protected]>
1 parent 4552204 commit fa3f0e6

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

sdk/deviceregistry/azure-resourcemanager-deviceregistry/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,11 @@
7575
<artifactId>azure-json</artifactId>
7676
<version>1.4.0</version> <!-- {x-version-update;com.azure:azure-json;dependency} -->
7777
</dependency>
78+
<dependency>
79+
<groupId>com.azure.resourcemanager</groupId>
80+
<artifactId>azure-resourcemanager-resources</artifactId>
81+
<version>2.47.0</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-resources;dependency} -->
82+
<scope>test</scope>
83+
</dependency>
7884
</dependencies>
7985
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.deviceregistry;
5+
6+
import com.azure.core.credential.TokenCredential;
7+
import com.azure.core.http.policy.HttpLogDetailLevel;
8+
import com.azure.core.http.policy.HttpLogOptions;
9+
import com.azure.core.management.AzureEnvironment;
10+
import com.azure.core.management.profile.AzureProfile;
11+
import com.azure.core.test.TestProxyTestBase;
12+
import com.azure.core.test.annotation.LiveOnly;
13+
import com.azure.identity.AzurePowerShellCredentialBuilder;
14+
import com.azure.resourcemanager.deviceregistry.models.Asset;
15+
import com.azure.resourcemanager.deviceregistry.models.AssetEndpointProfile;
16+
import com.azure.resourcemanager.deviceregistry.models.BillingContainer;
17+
import com.azure.resourcemanager.resources.ResourceManager;
18+
import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy;
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
21+
22+
import java.util.List;
23+
import java.util.stream.Collectors;
24+
25+
public class DeviceRegistryManagerTests extends TestProxyTestBase {
26+
private DeviceRegistryManager deviceRegistryManager = null;
27+
private ResourceManager resourceManager = null;
28+
29+
@Override
30+
public void beforeTest() {
31+
final TokenCredential credential = new AzurePowerShellCredentialBuilder().build();
32+
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
33+
34+
resourceManager = ResourceManager.configure()
35+
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
36+
.authenticate(credential, profile)
37+
.withDefaultSubscription();
38+
39+
deviceRegistryManager = DeviceRegistryManager.configure()
40+
.withPolicy(new ProviderRegistrationPolicy(resourceManager))
41+
.withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))
42+
.authenticate(credential, profile);
43+
}
44+
45+
@Test
46+
@LiveOnly
47+
public void testList() {
48+
// The AssetEndpointProfile and Assets service must be supported by the service Kubernetes cluster with Azure Arc
49+
// and Microsoft.ExtendedLocation, but Kubernetes cluster with Azure Arc can only be created by script.
50+
// so only add List test
51+
List<Asset> assets = deviceRegistryManager.assets().list().stream().collect(Collectors.toList());
52+
Assertions.assertTrue(assets.isEmpty());
53+
54+
List<AssetEndpointProfile> assetEndpointProfiles
55+
= deviceRegistryManager.assetEndpointProfiles().list().stream().collect(Collectors.toList());
56+
Assertions.assertTrue(assetEndpointProfiles.isEmpty());
57+
58+
// The BillingContainers only supported `get` and `list`.
59+
List<BillingContainer> billingContainers
60+
= deviceRegistryManager.billingContainers().list().stream().collect(Collectors.toList());
61+
Assertions.assertTrue(billingContainers.isEmpty());
62+
}
63+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@description('The tenant id to which the application and resources belong.')
2+
param tenantId string = '72f988bf-86f1-41af-91ab-2d7cd011db47'
3+
4+
@description('The client id of the service principal used to run tests.')
5+
param testApplicationId string
6+
7+
@description('This is the object id of the service principal used to run tests.')
8+
param testApplicationOid string
9+
10+
var contributorRoleId = '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c'
11+
12+
resource contributorRoleId_name 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
13+
name: guid('contributorRoleId${resourceGroup().name}')
14+
properties: {
15+
roleDefinitionId: contributorRoleId
16+
principalId: testApplicationOid
17+
}
18+
}
19+
20+
output AZURE_TENANT_ID string = tenantId
21+
output AZURE_SUBSCRIPTION_ID string = subscription().subscriptionId
22+
output AZURE_RESOURCE_GROUP_NAME string = resourceGroup().name

sdk/deviceregistry/tests.mgmt.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trigger: none
2+
3+
pr: none
4+
5+
extends:
6+
template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml
7+
parameters:
8+
ServiceDirectory: deviceregistry
9+
Artifacts:
10+
- name: azure-resourcemanager-deviceregistry
11+
groupId: com.azure.resourcemanager
12+
safeName: azureresourcemanagerdeviceregistry
13+
# Only run tests on Windows to save cost.
14+
MatrixFilters:
15+
- pool=.*(win).*

0 commit comments

Comments
 (0)