Skip to content

Commit e192eb9

Browse files
mgmt, enable live tests for mediaservices (Azure#26697)
* init tests config * fix * put junit engine * rename yaml to yml * convert to bicep
1 parent 92e7569 commit e192eb9

File tree

4 files changed

+70
-10
lines changed

4 files changed

+70
-10
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
<artifactId>azure-core-management</artifactId>
5353
<version>1.5.1</version> <!-- {x-version-update;com.azure:azure-core-management;dependency} -->
5454
</dependency>
55+
<dependency>
56+
<groupId>org.junit.jupiter</groupId>
57+
<artifactId>junit-jupiter-engine</artifactId>
58+
<version>5.8.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
59+
<scope>test</scope>
60+
</dependency>
5561
<dependency>
5662
<groupId>com.azure</groupId>
5763
<artifactId>azure-identity</artifactId>

sdk/mediaservices/azure-resourcemanager-mediaservices/src/test/java/com/azure/resourcemanager/mediaservices/MediaServicesTests.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.azure.core.management.profile.AzureProfile;
1111
import com.azure.core.test.TestBase;
1212
import com.azure.core.test.annotation.DoNotRecord;
13+
import com.azure.core.util.Configuration;
14+
import com.azure.core.util.CoreUtils;
1315
import com.azure.identity.DefaultAzureCredentialBuilder;
1416
import com.azure.resourcemanager.mediaservices.models.Asset;
1517
import com.azure.resourcemanager.mediaservices.models.BuiltInStandardEncoderPreset;
@@ -35,10 +37,11 @@ public class MediaServicesTests extends TestBase {
3537
private static final Random RANDOM = new Random();
3638

3739
private static final Region REGION = Region.US_WEST3;
38-
private static final String RESOURCE_GROUP = "rg" + randomPadding();
3940
private static final String STORAGE_ACCOUNT = "sa" + randomPadding();
4041
private static final String ACCOUNT = "media" + randomPadding();
4142

43+
private String resourceGroup = "rg" + randomPadding();
44+
4245
@Test
4346
@DoNotRecord(skipInPlayback = true)
4447
public void mediaServicesTest() {
@@ -50,22 +53,28 @@ public void mediaServicesTest() {
5053
.configure().withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
5154
.authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE));
5255

53-
storageManager.resourceManager().resourceGroups().define(RESOURCE_GROUP)
54-
.withRegion(REGION)
55-
.create();
56+
String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME");
57+
boolean testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup);
58+
if (testEnv) {
59+
resourceGroup = testResourceGroup;
60+
} else {
61+
storageManager.resourceManager().resourceGroups().define(resourceGroup)
62+
.withRegion(REGION)
63+
.create();
64+
}
5665

5766
try {
5867
// @embedmeStart
5968
// storage account
6069
StorageAccount storageAccount = storageManager.storageAccounts().define(STORAGE_ACCOUNT)
6170
.withRegion(REGION)
62-
.withExistingResourceGroup(RESOURCE_GROUP)
71+
.withExistingResourceGroup(resourceGroup)
6372
.create();
6473

6574
// media service account
6675
MediaService account = manager.mediaservices().define(ACCOUNT)
6776
.withRegion(Region.US_WEST3)
68-
.withExistingResourceGroup(RESOURCE_GROUP)
77+
.withExistingResourceGroup(resourceGroup)
6978
.withStorageAccounts(Collections.singletonList(
7079
new com.azure.resourcemanager.mediaservices.models.StorageAccount()
7180
.withId(storageAccount.id())
@@ -75,7 +84,7 @@ public void mediaServicesTest() {
7584
// transform
7685
Transform transform = manager.transforms()
7786
.define("transform1")
78-
.withExistingMediaService(RESOURCE_GROUP, ACCOUNT)
87+
.withExistingMediaService(resourceGroup, ACCOUNT)
7988
.withOutputs(Collections.singletonList(new TransformOutput()
8089
.withPreset(new BuiltInStandardEncoderPreset()
8190
.withPresetName(EncoderNamedPreset.CONTENT_AWARE_ENCODING))))
@@ -84,7 +93,7 @@ public void mediaServicesTest() {
8493
// output asset
8594
Asset asset = manager.assets()
8695
.define("output1")
87-
.withExistingMediaService(RESOURCE_GROUP, ACCOUNT)
96+
.withExistingMediaService(resourceGroup, ACCOUNT)
8897
.create();
8998

9099
// input uri
@@ -93,7 +102,7 @@ public void mediaServicesTest() {
93102

94103
// job
95104
Job job = manager.jobs().define("job1")
96-
.withExistingTransform(RESOURCE_GROUP, ACCOUNT, "transform1")
105+
.withExistingTransform(resourceGroup, ACCOUNT, "transform1")
97106
.withInput(new JobInputHttp()
98107
.withFiles(Collections.singletonList(jobFile))
99108
.withBaseUri(jobHttpBaseUri)
@@ -115,8 +124,13 @@ public void mediaServicesTest() {
115124
Assertions.assertEquals(JobState.FINISHED, jobState);
116125
Assertions.assertEquals(storageAccount.name(), asset.storageAccountName());
117126
Assertions.assertNotNull(asset.container());
127+
128+
manager.mediaservices().deleteById(account.id());
129+
storageManager.storageAccounts().deleteById(storageAccount.id());
118130
} finally {
119-
storageManager.resourceManager().resourceGroups().beginDeleteByName(RESOURCE_GROUP);
131+
if (!testEnv) {
132+
storageManager.resourceManager().resourceGroups().beginDeleteByName(resourceGroup);
133+
}
120134
}
121135
}
122136

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/mediaservices/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: mediaservices
9+
Artifacts:
10+
- name: azure-resourcemanager-mediaservices
11+
groupId: com.azure.resourcemanager
12+
safeName: azureresourcemanagermediaservices
13+
Clouds: 'Public'

0 commit comments

Comments
 (0)