Skip to content

Commit 25abad9

Browse files
add one test case for batch service (Azure#23235)
* generate code using latest autorest.java for postgresql * add one test case for batch service * modify test case to delete resource group * Remove import * * fix checkstyle error * modify according to comment * update version to fix build failure
1 parent c859ce8 commit 25abad9

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@
5151
<artifactId>azure-core-management</artifactId>
5252
<version>1.3.1</version> <!-- {x-version-update;com.azure:azure-core-management;dependency} -->
5353
</dependency>
54+
<dependency>
55+
<groupId>com.azure</groupId>
56+
<artifactId>azure-identity</artifactId>
57+
<version>1.3.4</version> <!-- {x-version-update;com.azure:azure-identity;dependency} -->
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>com.azure.resourcemanager</groupId>
62+
<artifactId>azure-resourcemanager-storage</artifactId>
63+
<version>2.6.0</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-storage;dependency} -->
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>com.azure</groupId>
68+
<artifactId>azure-core-test</artifactId>
69+
<version>1.6.4</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.slf4j</groupId>
74+
<artifactId>slf4j-simple</artifactId>
75+
<version>1.7.32</version> <!-- {x-version-update;org.slf4j:slf4j-simple;external_dependency} -->
76+
<scope>test</scope>
77+
</dependency>
5478
</dependencies>
5579
<build>
5680
<plugins>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.batch;
5+
6+
import com.azure.core.http.policy.HttpLogDetailLevel;
7+
import com.azure.core.http.policy.HttpLogOptions;
8+
import com.azure.core.management.AzureEnvironment;
9+
import com.azure.core.management.Region;
10+
import com.azure.core.management.profile.AzureProfile;
11+
import com.azure.core.test.TestBase;
12+
import com.azure.core.test.annotation.DoNotRecord;
13+
import com.azure.identity.DefaultAzureCredentialBuilder;
14+
import com.azure.resourcemanager.batch.models.AutoStorageBaseProperties;
15+
import com.azure.resourcemanager.batch.models.BatchAccount;
16+
import com.azure.resourcemanager.storage.StorageManager;
17+
import com.azure.resourcemanager.storage.models.StorageAccount;
18+
import org.junit.jupiter.api.Test;
19+
20+
import java.util.Random;
21+
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
25+
26+
class BatchTests extends TestBase {
27+
28+
private static final Random RANDOM = new Random();
29+
30+
private static final Region REGION = Region.US_WEST2;
31+
private static final String RESOURCE_GROUP = "rg" + randomPadding();
32+
private static final String STORAGE_ACCOUNT = "sa" + randomPadding();
33+
private static final String BATCH_ACCOUNT = "ba" + randomPadding();
34+
35+
@Test
36+
@DoNotRecord(skipInPlayback = true)
37+
public void testCreateBatchAccount() {
38+
39+
BatchManager batchManager = BatchManager
40+
.configure().withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
41+
.authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE));
42+
43+
StorageManager storageManager = StorageManager
44+
.configure().withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
45+
.authenticate(new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE));
46+
47+
try {
48+
// resource group
49+
storageManager.resourceManager().resourceGroups().define(RESOURCE_GROUP)
50+
.withRegion(REGION)
51+
.create();
52+
53+
// storage account
54+
StorageAccount storageAccount = storageManager.storageAccounts().define(STORAGE_ACCOUNT)
55+
.withRegion(REGION)
56+
.withExistingResourceGroup(RESOURCE_GROUP)
57+
.create();
58+
59+
// batch account
60+
BatchAccount account = batchManager
61+
.batchAccounts()
62+
.define(BATCH_ACCOUNT)
63+
.withRegion(REGION)
64+
.withExistingResourceGroup(RESOURCE_GROUP)
65+
.withAutoStorage(
66+
new AutoStorageBaseProperties()
67+
.withStorageAccountId(storageAccount.id()))
68+
.create();
69+
70+
71+
assertNotNull(account);
72+
73+
BatchAccount batchAccount = batchManager.batchAccounts().getByResourceGroup(RESOURCE_GROUP, BATCH_ACCOUNT);
74+
assertEquals(BATCH_ACCOUNT, batchAccount.name());
75+
assertEquals(REGION.toString(), batchAccount.location());
76+
77+
} finally {
78+
storageManager.resourceManager().resourceGroups().beginDeleteByName(RESOURCE_GROUP);
79+
}
80+
81+
}
82+
83+
private static String randomPadding() {
84+
return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000));
85+
}
86+
87+
88+
}

0 commit comments

Comments
 (0)