10
10
import com .azure .core .management .profile .AzureProfile ;
11
11
import com .azure .core .test .TestBase ;
12
12
import com .azure .core .test .annotation .DoNotRecord ;
13
+ import com .azure .core .util .Configuration ;
14
+ import com .azure .core .util .CoreUtils ;
13
15
import com .azure .identity .DefaultAzureCredentialBuilder ;
14
16
import com .azure .resourcemanager .mediaservices .models .Asset ;
15
17
import com .azure .resourcemanager .mediaservices .models .BuiltInStandardEncoderPreset ;
@@ -35,10 +37,11 @@ public class MediaServicesTests extends TestBase {
35
37
private static final Random RANDOM = new Random ();
36
38
37
39
private static final Region REGION = Region .US_WEST3 ;
38
- private static final String RESOURCE_GROUP = "rg" + randomPadding ();
39
40
private static final String STORAGE_ACCOUNT = "sa" + randomPadding ();
40
41
private static final String ACCOUNT = "media" + randomPadding ();
41
42
43
+ private String resourceGroup = "rg" + randomPadding ();
44
+
42
45
@ Test
43
46
@ DoNotRecord (skipInPlayback = true )
44
47
public void mediaServicesTest () {
@@ -50,22 +53,28 @@ public void mediaServicesTest() {
50
53
.configure ().withLogOptions (new HttpLogOptions ().setLogLevel (HttpLogDetailLevel .BODY_AND_HEADERS ))
51
54
.authenticate (new DefaultAzureCredentialBuilder ().build (), new AzureProfile (AzureEnvironment .AZURE ));
52
55
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
+ }
56
65
57
66
try {
58
67
// @embedmeStart
59
68
// storage account
60
69
StorageAccount storageAccount = storageManager .storageAccounts ().define (STORAGE_ACCOUNT )
61
70
.withRegion (REGION )
62
- .withExistingResourceGroup (RESOURCE_GROUP )
71
+ .withExistingResourceGroup (resourceGroup )
63
72
.create ();
64
73
65
74
// media service account
66
75
MediaService account = manager .mediaservices ().define (ACCOUNT )
67
76
.withRegion (Region .US_WEST3 )
68
- .withExistingResourceGroup (RESOURCE_GROUP )
77
+ .withExistingResourceGroup (resourceGroup )
69
78
.withStorageAccounts (Collections .singletonList (
70
79
new com .azure .resourcemanager .mediaservices .models .StorageAccount ()
71
80
.withId (storageAccount .id ())
@@ -75,7 +84,7 @@ public void mediaServicesTest() {
75
84
// transform
76
85
Transform transform = manager .transforms ()
77
86
.define ("transform1" )
78
- .withExistingMediaService (RESOURCE_GROUP , ACCOUNT )
87
+ .withExistingMediaService (resourceGroup , ACCOUNT )
79
88
.withOutputs (Collections .singletonList (new TransformOutput ()
80
89
.withPreset (new BuiltInStandardEncoderPreset ()
81
90
.withPresetName (EncoderNamedPreset .CONTENT_AWARE_ENCODING ))))
@@ -84,7 +93,7 @@ public void mediaServicesTest() {
84
93
// output asset
85
94
Asset asset = manager .assets ()
86
95
.define ("output1" )
87
- .withExistingMediaService (RESOURCE_GROUP , ACCOUNT )
96
+ .withExistingMediaService (resourceGroup , ACCOUNT )
88
97
.create ();
89
98
90
99
// input uri
@@ -93,7 +102,7 @@ public void mediaServicesTest() {
93
102
94
103
// job
95
104
Job job = manager .jobs ().define ("job1" )
96
- .withExistingTransform (RESOURCE_GROUP , ACCOUNT , "transform1" )
105
+ .withExistingTransform (resourceGroup , ACCOUNT , "transform1" )
97
106
.withInput (new JobInputHttp ()
98
107
.withFiles (Collections .singletonList (jobFile ))
99
108
.withBaseUri (jobHttpBaseUri )
@@ -115,8 +124,13 @@ public void mediaServicesTest() {
115
124
Assertions .assertEquals (JobState .FINISHED , jobState );
116
125
Assertions .assertEquals (storageAccount .name (), asset .storageAccountName ());
117
126
Assertions .assertNotNull (asset .container ());
127
+
128
+ manager .mediaservices ().deleteById (account .id ());
129
+ storageManager .storageAccounts ().deleteById (storageAccount .id ());
118
130
} finally {
119
- storageManager .resourceManager ().resourceGroups ().beginDeleteByName (RESOURCE_GROUP );
131
+ if (!testEnv ) {
132
+ storageManager .resourceManager ().resourceGroups ().beginDeleteByName (resourceGroup );
133
+ }
120
134
}
121
135
}
122
136
0 commit comments