@Test public void testFindStorageAccountIdInVisibleSubscriptionsWhenPresentInAnotherSubscription() { AzureClient client = mock(AzureClient.class); StorageAccountInner storageAccount = mock(StorageAccountInner.class); when(storageAccount.id()).thenReturn(STORAGE_ACCOUNT_IN_ANOTHER_SUBSCRIPTION); when(client.getStorageAccount(STORAGE_ACCOUNT_IN_CURRENT_SUBSCRIPTION, Kind.STORAGE_V2)).thenReturn(Optional.empty()); setupSubscriptions(client); when(client.getStorageAccountBySubscription(STORAGE_ACCOUNT_IN_ANOTHER_SUBSCRIPTION, SUBSCRIPTION_ONE, Kind.STORAGE_V2)) .thenReturn(Optional.empty()); when(client.getStorageAccountBySubscription(STORAGE_ACCOUNT_IN_ANOTHER_SUBSCRIPTION, SUBSCRIPTION_ANOTHER, Kind.STORAGE_V2)) .thenReturn(Optional.of(storageAccount)); Optional<String> storageAccountId = underTest.findStorageAccountIdInVisibleSubscriptions(client, "storageAccountAnother"); assertTrue(storageAccountId.isPresent()); assertEquals(STORAGE_ACCOUNT_IN_ANOTHER_SUBSCRIPTION, storageAccountId.get()); verify(client).getStorageAccount(STORAGE_ACCOUNT_IN_ANOTHER_SUBSCRIPTION, Kind.STORAGE_V2); verify(client).listSubscriptions(); }
public Optional<String> findStorageAccountIdInVisibleSubscriptions(AzureClient client, String account) { Optional<StorageAccount> storageAccount = client.getStorageAccount(account, Kind.STORAGE_V2); LOGGER.debug("checking current subscription for storage account"); if (storageAccount.isPresent()) { return storageAccount.map(HasId::id); } List<String> subscriptionIds = client.listSubscriptions().stream().map(Subscription::subscriptionId).collect(Collectors.toList()); LOGGER.debug("Checking other subscriptions for storage account: {}", String.join(",", subscriptionIds)); for (String subscriptionId : subscriptionIds) { Optional<StorageAccountInner> storageAccountInner = client.getStorageAccountBySubscription(account, subscriptionId, Kind.STORAGE_V2); if (storageAccountInner.isPresent()) { return storageAccountInner.map(s -> s.id()); } } return Optional.empty(); }
AzureStorage { public Optional<String> findStorageAccountIdInVisibleSubscriptions(AzureClient client, String account) { Optional<StorageAccount> storageAccount = client.getStorageAccount(account, Kind.STORAGE_V2); LOGGER.debug("checking current subscription for storage account"); if (storageAccount.isPresent()) { return storageAccount.map(HasId::id); } List<String> subscriptionIds = client.listSubscriptions().stream().map(Subscription::subscriptionId).collect(Collectors.toList()); LOGGER.debug("Checking other subscriptions for storage account: {}", String.join(",", subscriptionIds)); for (String subscriptionId : subscriptionIds) { Optional<StorageAccountInner> storageAccountInner = client.getStorageAccountBySubscription(account, subscriptionId, Kind.STORAGE_V2); if (storageAccountInner.isPresent()) { return storageAccountInner.map(s -> s.id()); } } return Optional.empty(); } }
AzureStorage { public Optional<String> findStorageAccountIdInVisibleSubscriptions(AzureClient client, String account) { Optional<StorageAccount> storageAccount = client.getStorageAccount(account, Kind.STORAGE_V2); LOGGER.debug("checking current subscription for storage account"); if (storageAccount.isPresent()) { return storageAccount.map(HasId::id); } List<String> subscriptionIds = client.listSubscriptions().stream().map(Subscription::subscriptionId).collect(Collectors.toList()); LOGGER.debug("Checking other subscriptions for storage account: {}", String.join(",", subscriptionIds)); for (String subscriptionId : subscriptionIds) { Optional<StorageAccountInner> storageAccountInner = client.getStorageAccountBySubscription(account, subscriptionId, Kind.STORAGE_V2); if (storageAccountInner.isPresent()) { return storageAccountInner.map(s -> s.id()); } } return Optional.empty(); }  }
AzureStorage { public Optional<String> findStorageAccountIdInVisibleSubscriptions(AzureClient client, String account) { Optional<StorageAccount> storageAccount = client.getStorageAccount(account, Kind.STORAGE_V2); LOGGER.debug("checking current subscription for storage account"); if (storageAccount.isPresent()) { return storageAccount.map(HasId::id); } List<String> subscriptionIds = client.listSubscriptions().stream().map(Subscription::subscriptionId).collect(Collectors.toList()); LOGGER.debug("Checking other subscriptions for storage account: {}", String.join(",", subscriptionIds)); for (String subscriptionId : subscriptionIds) { Optional<StorageAccountInner> storageAccountInner = client.getStorageAccountBySubscription(account, subscriptionId, Kind.STORAGE_V2); if (storageAccountInner.isPresent()) { return storageAccountInner.map(s -> s.id()); } } return Optional.empty(); }  ArmAttachedStorageOption getArmAttachedStorageOption(Map<String, String> parameters); AzureImage getCustomImage(AzureClient client, AuthenticatedContext ac, CloudStack stack); AzureImage getCustomImage(AzureClient client, AuthenticatedContext ac, CloudStack stack, String imageName); String getImageStorageName(AzureCredentialView acv, CloudContext cloudContext, CloudStack cloudStack); String getAttachedDiskStorageName(ArmAttachedStorageOption armAttachedStorageOption, AzureCredentialView acv, Long vmId, CloudContext cloudContext,
            AzureDiskType storageType); StorageAccount createStorage(AzureClient client, String osStorageName, AzureDiskType storageType, String storageGroup,
            String region, Boolean encrypted, Map<String, String> tags); void deleteStorage(AzureClient client, String osStorageName, String storageGroup); String getDiskContainerName(CloudContext cloudContext); String getPersistentStorageName(CloudStack stack); Boolean isEncrytionNeeded(Map<String, String> parameters); boolean isPersistentStorage(String persistentStorageName); Optional<String> findStorageAccountIdInVisibleSubscriptions(AzureClient client, String account); }
AzureStorage { public Optional<String> findStorageAccountIdInVisibleSubscriptions(AzureClient client, String account) { Optional<StorageAccount> storageAccount = client.getStorageAccount(account, Kind.STORAGE_V2); LOGGER.debug("checking current subscription for storage account"); if (storageAccount.isPresent()) { return storageAccount.map(HasId::id); } List<String> subscriptionIds = client.listSubscriptions().stream().map(Subscription::subscriptionId).collect(Collectors.toList()); LOGGER.debug("Checking other subscriptions for storage account: {}", String.join(",", subscriptionIds)); for (String subscriptionId : subscriptionIds) { Optional<StorageAccountInner> storageAccountInner = client.getStorageAccountBySubscription(account, subscriptionId, Kind.STORAGE_V2); if (storageAccountInner.isPresent()) { return storageAccountInner.map(s -> s.id()); } } return Optional.empty(); }  ArmAttachedStorageOption getArmAttachedStorageOption(Map<String, String> parameters); AzureImage getCustomImage(AzureClient client, AuthenticatedContext ac, CloudStack stack); AzureImage getCustomImage(AzureClient client, AuthenticatedContext ac, CloudStack stack, String imageName); String getImageStorageName(AzureCredentialView acv, CloudContext cloudContext, CloudStack cloudStack); String getAttachedDiskStorageName(ArmAttachedStorageOption armAttachedStorageOption, AzureCredentialView acv, Long vmId, CloudContext cloudContext,
            AzureDiskType storageType); StorageAccount createStorage(AzureClient client, String osStorageName, AzureDiskType storageType, String storageGroup,
            String region, Boolean encrypted, Map<String, String> tags); void deleteStorage(AzureClient client, String osStorageName, String storageGroup); String getDiskContainerName(CloudContext cloudContext); String getPersistentStorageName(CloudStack stack); Boolean isEncrytionNeeded(Map<String, String> parameters); boolean isPersistentStorage(String persistentStorageName); Optional<String> findStorageAccountIdInVisibleSubscriptions(AzureClient client, String account); static final String IMAGES_CONTAINER; static final String STORAGE_BLOB_PATTERN; }