Skip to content

Commit dda23e7

Browse files
authored
Added testcases for Load Test Service management plane (Azure#31738)
* added tests * revamped tests structure * added yml and bicep files * use the resourcegroup in environment * checkstyle fixes
1 parent 7dfeceb commit dda23e7

File tree

6 files changed

+295
-0
lines changed

6 files changed

+295
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,41 @@
5151
<artifactId>azure-core-management</artifactId>
5252
<version>1.8.1</version> <!-- {x-version-update;com.azure:azure-core-management;dependency} -->
5353
</dependency>
54+
<dependency>
55+
<groupId>com.azure</groupId>
56+
<artifactId>azure-core-test</artifactId>
57+
<version>1.12.1</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>com.azure</groupId>
62+
<artifactId>azure-identity</artifactId>
63+
<version>1.6.1</version> <!-- {x-version-update;com.azure:azure-identity;dependency} -->
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>com.azure.resourcemanager</groupId>
68+
<artifactId>azure-resourcemanager-resources</artifactId>
69+
<version>2.19.0</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-resources;dependency} -->
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.junit.jupiter</groupId>
74+
<artifactId>junit-jupiter-engine</artifactId>
75+
<version>5.8.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
76+
<scope>test</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.mockito</groupId>
80+
<artifactId>mockito-core</artifactId>
81+
<version>4.5.1</version> <!-- {x-version-update;org.mockito:mockito-core;external_dependency} -->
82+
<scope>test</scope>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.slf4j</groupId>
86+
<artifactId>slf4j-simple</artifactId>
87+
<version>1.7.36</version> <!-- {x-version-update;org.slf4j:slf4j-simple;external_dependency} -->
88+
<scope>test</scope>
89+
</dependency>
5490
</dependencies>
5591
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.loadtestservice;
5+
6+
import org.junit.jupiter.api.Assertions;
7+
import com.azure.core.http.rest.PagedIterable;
8+
import com.azure.resourcemanager.loadtestservice.models.CheckQuotaAvailabilityResponse;
9+
import com.azure.resourcemanager.loadtestservice.models.QuotaBucketRequest;
10+
import com.azure.resourcemanager.loadtestservice.models.QuotaBucketRequestPropertiesDimensions;
11+
import com.azure.resourcemanager.loadtestservice.models.QuotaResource;
12+
13+
public class QuotaOperations {
14+
15+
private String location;
16+
private String quotaBucketName;
17+
18+
public QuotaOperations(String location, String quotaBucketName) {
19+
this.location = location;
20+
this.quotaBucketName = quotaBucketName;
21+
}
22+
23+
public void listBuckets(LoadTestManager manager) {
24+
PagedIterable<QuotaResource> resource = manager
25+
.quotas()
26+
.list(location);
27+
28+
for (QuotaResource quotaResource : resource) {
29+
Assertions.assertNotNull(quotaResource.id());
30+
Assertions.assertNotNull(quotaResource.name());
31+
Assertions.assertNotNull(quotaResource.type());
32+
Assertions.assertNotNull(quotaResource.limit());
33+
Assertions.assertNotNull(quotaResource.usage());
34+
}
35+
}
36+
37+
public void getBucket(LoadTestManager manager) {
38+
QuotaResource resource = getQuotaBucket(manager);
39+
40+
Assertions.assertNotNull(resource.id());
41+
Assertions.assertEquals(quotaBucketName, resource.name());
42+
Assertions.assertNotNull(resource.type());
43+
Assertions.assertNotNull(resource.limit());
44+
Assertions.assertNotNull(resource.usage());
45+
}
46+
47+
public void checkAvailability(LoadTestManager manager) {
48+
QuotaResource quotaResource = getQuotaBucket(manager);
49+
50+
QuotaBucketRequestPropertiesDimensions dimensions = new QuotaBucketRequestPropertiesDimensions()
51+
.withLocation(location)
52+
.withSubscriptionId(manager.serviceClient().getSubscriptionId());
53+
54+
QuotaBucketRequest request = new QuotaBucketRequest()
55+
.withCurrentQuota(quotaResource.limit())
56+
.withCurrentUsage(quotaResource.usage())
57+
.withNewQuota(quotaResource.limit())
58+
.withDimensions(dimensions);
59+
60+
CheckQuotaAvailabilityResponse resource = manager
61+
.quotas()
62+
.checkAvailability(location, quotaBucketName, request);
63+
64+
Assertions.assertNotNull(resource.id());
65+
Assertions.assertEquals(quotaBucketName, resource.name());
66+
Assertions.assertNotNull(resource.type());
67+
Assertions.assertNotNull(resource.isAvailable());
68+
}
69+
70+
private QuotaResource getQuotaBucket(LoadTestManager manager) {
71+
QuotaResource resource = manager
72+
.quotas()
73+
.get(location, quotaBucketName);
74+
75+
return resource;
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.loadtestservice;
5+
6+
import org.junit.jupiter.api.Assertions;
7+
import com.azure.resourcemanager.loadtestservice.models.LoadTestResource;
8+
import com.azure.resourcemanager.loadtestservice.models.ManagedServiceIdentity;
9+
import com.azure.resourcemanager.loadtestservice.models.ManagedServiceIdentityType;
10+
11+
public class ResourceOperations {
12+
13+
private String location;
14+
private String resourceGroupName;
15+
private String loadTestResourceName;
16+
17+
public ResourceOperations(String location, String resourceGroupName, String loadTestResourceName) {
18+
this.location = location;
19+
this.resourceGroupName = resourceGroupName;
20+
this.loadTestResourceName = loadTestResourceName;
21+
}
22+
23+
public void create(LoadTestManager manager) {
24+
LoadTestResource resource = manager
25+
.loadTests()
26+
.define(loadTestResourceName)
27+
.withRegion(location)
28+
.withExistingResourceGroup(resourceGroupName)
29+
.withDescription("This is new load test resource")
30+
.create();
31+
32+
Assertions.assertEquals(loadTestResourceName, resource.name());
33+
Assertions.assertEquals(location, resource.regionName());
34+
Assertions.assertEquals(resourceGroupName, resource.resourceGroupName());
35+
Assertions.assertEquals("This is new load test resource", resource.description());
36+
Assertions.assertNotNull(resource.id());
37+
Assertions.assertEquals("Succeeded", resource.provisioningState().toString());
38+
}
39+
40+
public void update(LoadTestManager manager) {
41+
LoadTestResource resourcePreUpdate = getResource(manager);
42+
43+
LoadTestResource resourcePostUpdate = resourcePreUpdate
44+
.update()
45+
.withIdentity(new ManagedServiceIdentity().withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED))
46+
.apply();
47+
48+
Assertions.assertEquals(resourcePreUpdate.name(), resourcePostUpdate.name());
49+
Assertions.assertEquals(resourcePreUpdate.regionName(), resourcePostUpdate.regionName());
50+
Assertions.assertEquals(resourcePreUpdate.resourceGroupName(), resourcePostUpdate.resourceGroupName());
51+
Assertions.assertEquals(resourcePreUpdate.description(), resourcePostUpdate.description());
52+
Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED, resourcePostUpdate.identity().type());
53+
Assertions.assertNotNull(resourcePostUpdate.id());
54+
Assertions.assertEquals("Succeeded", resourcePostUpdate.provisioningState().toString());
55+
}
56+
57+
private LoadTestResource getResource(LoadTestManager manager) {
58+
LoadTestResource resource = manager
59+
.loadTests()
60+
.getByResourceGroup(resourceGroupName, loadTestResourceName);
61+
return resource;
62+
}
63+
64+
public void get(LoadTestManager manager) {
65+
LoadTestResource resource = getResource(manager);
66+
67+
Assertions.assertEquals(loadTestResourceName, resource.name());
68+
Assertions.assertEquals(location, resource.regionName());
69+
Assertions.assertEquals(resourceGroupName, resource.resourceGroupName());
70+
Assertions.assertEquals("This is new load test resource", resource.description());
71+
Assertions.assertNotNull(resource.id());
72+
Assertions.assertEquals("Succeeded", resource.provisioningState().toString());
73+
}
74+
75+
public void delete(LoadTestManager manager) {
76+
manager
77+
.loadTests()
78+
.deleteByResourceGroup(resourceGroupName, loadTestResourceName);
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.loadtestservice;
5+
6+
import com.azure.core.management.AzureEnvironment;
7+
import com.azure.core.management.Region;
8+
import com.azure.core.management.profile.AzureProfile;
9+
import com.azure.core.test.TestBase;
10+
import com.azure.core.util.Configuration;
11+
import com.azure.core.test.annotation.DoNotRecord;
12+
import com.azure.identity.DefaultAzureCredential;
13+
import com.azure.identity.DefaultAzureCredentialBuilder;
14+
import java.util.Random;
15+
import org.junit.jupiter.api.Test;
16+
17+
public class TestOrchestrator extends TestBase {
18+
19+
private static final Random RANDOM = new Random();
20+
private static final Region LOCATION = Region.US_WEST2;
21+
private static final String RESOURCE_NAME = "loadtest-resource" + RANDOM.nextInt(1000);
22+
private static final String QUOTA_BUCKET_NAME = "maxEngineInstancesPerTestRun";
23+
24+
private DefaultAzureCredential credential;
25+
private AzureProfile profile;
26+
private LoadTestManager loadTestManager;
27+
private String resourceGroupName;
28+
29+
public void setupCredential() {
30+
credential = new DefaultAzureCredentialBuilder().build();
31+
}
32+
33+
public void setupProfile() {
34+
profile = new AzureProfile(AzureEnvironment.AZURE);
35+
}
36+
37+
public void prepareTests() {
38+
setupCredential();
39+
setupProfile();
40+
resourceGroupName = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME");
41+
loadTestManager = LoadTestManager
42+
.configure()
43+
.authenticate(credential, profile);
44+
}
45+
46+
@Test
47+
@DoNotRecord(skipInPlayback = true)
48+
public void startTest() {
49+
prepareTests();
50+
51+
ResourceOperations resourceOperations = new ResourceOperations(LOCATION.toString(), resourceGroupName, RESOURCE_NAME);
52+
resourceOperations.create(loadTestManager);
53+
resourceOperations.get(loadTestManager);
54+
resourceOperations.update(loadTestManager);
55+
resourceOperations.delete(loadTestManager);
56+
57+
QuotaOperations quotaOperations = new QuotaOperations(LOCATION.toString(), QUOTA_BUCKET_NAME);
58+
quotaOperations.listBuckets(loadTestManager);
59+
quotaOperations.getBucket(loadTestManager);
60+
quotaOperations.checkAvailability(loadTestManager);
61+
}
62+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
@description('The application client secret used to run tests.')
11+
param testApplicationSecret string
12+
13+
var contributorRoleId = '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c'
14+
15+
resource contributorRoleId_name 'Microsoft.Authorization/roleAssignments@2020-08-01-preview' = {
16+
name: guid('contributorRoleId${resourceGroup().name}')
17+
properties: {
18+
roleDefinitionId: contributorRoleId
19+
principalId: testApplicationOid
20+
}
21+
}
22+
23+
output AZURE_TENANT_ID string = tenantId
24+
output AZURE_CLIENT_ID string = testApplicationId
25+
output AZURE_CLIENT_SECRET string = testApplicationSecret
26+
output AZURE_SUBSCRIPTION_ID string = subscription().subscriptionId
27+
output AZURE_RESOURCE_GROUP_NAME string = resourceGroup().name

sdk/loadtestservice/tests.mgmt.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trigger: none
2+
3+
pr: none
4+
5+
stages:
6+
- template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml
7+
parameters:
8+
ServiceDirectory: loadtestservice
9+
Artifacts:
10+
- name: azure-resourcemanager-loadtestservice
11+
groupId: com.azure.resourcemanager
12+
safeName: azureresourcemanagerloadtestservice
13+
Clouds: 'Public'

0 commit comments

Comments
 (0)