use of com.azure.core.management.exception.ManagementError in project terra-workspace-manager by DataBiosphere.
the class CreateAzureStorageStepTest method setup.
@BeforeEach
public void setup() {
when(mockAzureCloudContext.getAzureResourceGroupId()).thenReturn(STUB_STRING_RETURN);
when(mockCrlService.getStorageManager(mockAzureCloudContext, mockAzureConfig)).thenReturn(mockStorageManager);
when(mockStorageManager.storageAccounts()).thenReturn(mockStorageAccounts);
resourceNotFoundException = new ManagementException("Resource was not found.", /*response=*/
null, new ManagementError("ResourceNotFound", "Resource was not found."));
// Creation stages mocks
when(mockStorageAccounts.define(anyString())).thenReturn(mockStorageBlankStage);
when(mockStorageBlankStage.withRegion(anyString())).thenReturn(mockStorageGroupStage);
when(mockStorageGroupStage.withExistingResourceGroup(anyString())).thenReturn(mockStorageCreateStage);
when(mockStorageCreateStage.withHnsEnabled(true)).thenReturn(mockStorageCreateStage);
when(mockStorageCreateStage.withTag(anyString(), anyString())).thenReturn(mockStorageCreateStage);
when(mockStorageCreateStage.create(any(Context.class))).thenReturn(mockStorageAccount);
when(mockStorageAccount.id()).thenReturn(STUB_STRING_RETURN);
creationParameters = ControlledResourceFixtures.getAzureStorageCreationParameters();
// Exception mock
when(mockFlightContext.getWorkingMap()).thenReturn(mockWorkingMap);
when(mockWorkingMap.get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class)).thenReturn(mockAzureCloudContext);
}
use of com.azure.core.management.exception.ManagementError in project terra-workspace-manager by DataBiosphere.
the class CreateAzureVmStepTest method setup.
@BeforeEach
public void setup() {
when(mockCrlService.getComputeManager(any(AzureCloudContext.class), any(AzureConfiguration.class))).thenReturn(mockComputeManager);
when(mockAzureCloudContext.getAzureResourceGroupId()).thenReturn(STUB_STRING_RETURN);
when(mockAzureCloudContext.getAzureTenantId()).thenReturn(STUB_STRING_RETURN);
when(mockAzureCloudContext.getAzureSubscriptionId()).thenReturn(STUB_STRING_RETURN);
when(mockComputeManager.virtualMachines()).thenReturn(mockVms);
// get disk mocks
when(mockComputeManager.disks()).thenReturn(mockDisks);
when(mockDisks.getByResourceGroup(anyString(), anyString())).thenReturn(mockDisk);
// get ip mocks
when(mockComputeManager.networkManager()).thenReturn(mockNetworkManager);
when(mockNetworkManager.publicIpAddresses()).thenReturn(mockPublicIpAddresses);
when(mockPublicIpAddresses.getByResourceGroup(anyString(), anyString())).thenReturn(mockPublicIpAddress);
// get network mocks
when(mockNetworkManager.networks()).thenReturn(mockNetworks);
when(mockNetworks.getByResourceGroup(anyString(), anyString())).thenReturn(mockNetwork);
when(mockNetworkManager.networkInterfaces()).thenReturn(mockNis);
when(mockNis.define(anyString())).thenReturn(mockNicDefine);
when(mockNicDefine.withRegion(anyString())).thenReturn(mockNicWithRegion);
when(mockNicWithRegion.withExistingResourceGroup(anyString())).thenReturn(mockNicWithExistingRg);
when(mockNicWithExistingRg.withExistingPrimaryNetwork(mockNetwork)).thenReturn(mockNicWithExistingPrimaryNetwork);
when(mockNicWithExistingPrimaryNetwork.withSubnet(anyString())).thenReturn(mockNicWithPrivateIp);
when(mockNicWithPrivateIp.withPrimaryPrivateIPAddressDynamic()).thenReturn(mockNicWithCreate);
when(mockNicWithCreate.withExistingPrimaryPublicIPAddress(mockPublicIpAddress)).thenReturn(mockNicWithCreate);
when(mockNicWithCreate.create()).thenReturn(mockNi);
// create network security group mocks
when(mockNetworkManager.networkSecurityGroups()).thenReturn(mockNsgs);
when(mockNsgs.define(anyString())).thenReturn(mockNetworkStage1);
when(mockNetworkStage1.withRegion(anyString())).thenReturn(mockNetworkStage1a);
when(mockNetworkStage1a.withExistingResourceGroup(anyString())).thenReturn(mockNetworkStage2);
when(mockNetworkStage2.withTag(anyString(), anyString())).thenReturn(mockNetworkStage2);
when(mockNetworkStage2.defineRule(anyString())).thenReturn(mockNetworkStage3);
when(mockNetworkStage3.allowInbound()).thenReturn(mockNetworkStage4);
when(mockNetworkStage3.denyOutbound()).thenReturn(mockNetworkStage4);
when(mockNetworkStage4.fromAddress(anyString())).thenReturn(mockNetworkStage5);
when(mockNetworkStage4.fromAnyAddress()).thenReturn(mockNetworkStage5);
when(mockNetworkStage5.fromAnyPort()).thenReturn(mockNetworkStage6);
when(mockNetworkStage6.toAnyAddress()).thenReturn(mockNetworkStage7);
when(mockNetworkStage6.toAddress(anyString())).thenReturn(mockNetworkStage7);
when(mockNetworkStage7.toPort(anyInt())).thenReturn(mockNetworkStage8);
when(mockNetworkStage7.toAnyPort()).thenReturn(mockNetworkStage8);
when(mockNetworkStage8.withProtocol(any(SecurityRuleProtocol.class))).thenReturn(mockNetworkStage9);
when(mockNetworkStage8.withAnyProtocol()).thenReturn(mockNetworkStage9);
when(mockNetworkStage9.attach()).thenReturn(mockNetworkStage2);
when(mockNetworkStage2.create(any(Context.class))).thenReturn(mockNsg);
// create network mocks
when(mockNetworks.define(anyString())).thenReturn(mockNetworkStage10);
when(mockNetworkStage10.withRegion(anyString())).thenReturn(mockNetworkStage11);
when(mockNetworkStage11.withExistingResourceGroup(anyString())).thenReturn(mockNetworkStage12);
when(mockNetworkStage12.withTag(anyString(), anyString())).thenReturn(mockNetworkStage12);
when(mockNetworkStage12.withAddressSpace(anyString())).thenReturn(mockNetworkStage13);
when(mockNetworkStage13.defineSubnet(anyString())).thenReturn(mockNetworkStage14);
when(mockNetworkStage14.withAddressPrefix(anyString())).thenReturn(mockNetworkStage15);
when(mockNetworkStage15.withExistingNetworkSecurityGroup(any(NetworkSecurityGroup.class))).thenReturn(mockNetworkStage15);
when(mockNetworkStage15.attach()).thenReturn(mockNetworkStage13);
when(mockNetworkStage13.create(any(Context.class))).thenReturn(mockNetwork);
// Creation vm stages mocks
when(mockVms.define(anyString())).thenReturn(mockVmStage1);
when(mockVmStage1.withRegion(anyString())).thenReturn(mockVmStage2);
when(mockVmStage2.withExistingResourceGroup(anyString())).thenReturn(mockVmStage3);
when(mockVmStage3.withExistingPrimaryNetworkInterface(mockNi)).thenReturn(mockVmStage7);
when(mockVmStage7.withSpecializedLinuxCustomImage(anyString())).thenReturn(mockVmStage10);
when(mockVmStage10.withExistingDataDisk(any(Disk.class))).thenReturn(mockVmStage11);
when(mockVmStage11.withTag(anyString(), anyString())).thenReturn(mockVmStage11a);
when(mockVmStage11a.withTag(anyString(), anyString())).thenReturn(mockVmStage12);
when(mockVmStage12.withSize(any(VirtualMachineSizeTypes.class))).thenReturn(mockVmStage12);
when(mockVmStage12.defineNewExtension(anyString())).thenReturn(mockVmStage13);
when(mockVmStage13.withPublisher(anyString())).thenReturn(mockVmStage14);
when(mockVmStage14.withType(anyString())).thenReturn(mockVmStage15);
when(mockVmStage15.withVersion(anyString())).thenReturn(mockVmStage16);
when(mockVmStage16.withPublicSettings(any())).thenReturn(mockVmStage16);
when(mockVmStage16.withProtectedSettings(any())).thenReturn(mockVmStage16);
when(mockVmStage16.withTags(any())).thenReturn(mockVmStage16);
when(mockVmStage16.withoutMinorVersionAutoUpgrade()).thenReturn(mockVmStage16);
when(mockVmStage16.attach()).thenReturn(mockVmStage12);
when(mockVmStage12.create(any(Context.class))).thenReturn(mockVm);
// Resource dao mocks
when(mockResourceDao.getResource(any(UUID.class), any(UUID.class))).thenReturn(mockWsmResource);
when(mockWsmResource.castByEnum(WsmResourceType.CONTROLLED_AZURE_DISK)).thenReturn(mockAzureDiskResource);
when(mockWsmResource.castByEnum(WsmResourceType.CONTROLLED_AZURE_IP)).thenReturn(mockAzureIpResource);
when(mockWsmResource.castByEnum(WsmResourceType.CONTROLLED_AZURE_NETWORK)).thenReturn(mockAzureNetworkResource);
// Resource mocks
when(mockAzureDiskResource.getDiskName()).thenReturn(STUB_DISK_NAME);
when(mockAzureIpResource.getIpName()).thenReturn(STUB_IP_NAME);
when(mockAzureNetworkResource.getNetworkName()).thenReturn(STUB_NETWORK_NAME);
when(mockAzureNetworkResource.getSubnetName()).thenReturn(STUB_SUBNET_NAME);
// Exception mock
when(mockException.getValue()).thenReturn(new ManagementError("Conflict", "Resource already exists."));
when(mockFlightContext.getWorkingMap()).thenReturn(mockWorkingMap);
when(mockWorkingMap.get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class)).thenReturn(mockAzureCloudContext);
}
Aggregations