|
| 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