Utils { public static String getConnectionStringFromProperties(Properties properties) { String sasUri = properties.getProperty(AzureConstants.AZURE_SAS, ""); String blobEndpoint = properties.getProperty(AzureConstants.AZURE_BLOB_ENDPOINT, ""); String connectionString = properties.getProperty(AzureConstants.AZURE_CONNECTION_STRING, ""); if (!connectionString.isEmpty()) { return connectionString; } if (!sasUri.isEmpty()) { return getConnectionStringForSas(sasUri, blobEndpoint); } return getConnectionString( properties.getProperty(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME, ""), properties.getProperty(AzureConstants.AZURE_STORAGE_ACCOUNT_KEY, "")); } private  Utils(); static CloudBlobClient getBlobClient(@NotNull final String connectionString); static CloudBlobClient getBlobClient(@NotNull final String connectionString,
                                                @Nullable final BlobRequestOptions requestOptions); static CloudBlobContainer getBlobContainer(@NotNull final String connectionString,
                                                      @NotNull final String containerName); static CloudBlobContainer getBlobContainer(@NotNull final String connectionString,
                                                      @NotNull final String containerName,
                                                      @Nullable final BlobRequestOptions requestOptions); static void setProxyIfNeeded(final Properties properties); static RetryPolicy getRetryPolicy(final String maxRequestRetry); static String getConnectionStringFromProperties(Properties properties); static String getConnectionString(final String accountName, final String accountKey); static Properties readConfig(String fileName); static final String DEFAULT_CONFIG_FILE; static final String DASH; }
@Test public void testConnectionStringIsBasedOnProperty() { Properties properties = new Properties(); properties.put(AzureConstants.AZURE_CONNECTION_STRING, "DefaultEndpointsProtocol=https;AccountName=accountName;AccountKey=accountKey"); String connectionString = Utils.getConnectionStringFromProperties(properties); assertEquals(connectionString,"DefaultEndpointsProtocol=https;AccountName=accountName;AccountKey=accountKey"); }
@Test public void testConnectionStringIsBasedOnSAS() { Properties properties = new Properties(); properties.put(AzureConstants.AZURE_SAS, "sas"); properties.put(AzureConstants.AZURE_BLOB_ENDPOINT, "endpoint"); String connectionString = Utils.getConnectionStringFromProperties(properties); assertEquals(connectionString, String.format("BlobEndpoint=%s;SharedAccessSignature=%s", "endpoint", "sas")); }
@Test public void testConnectionStringIsBasedOnAccessKeyIfSASMissing() { Properties properties = new Properties(); properties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME, "accessKey"); properties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_KEY, "secretKey"); String connectionString = Utils.getConnectionStringFromProperties(properties); assertEquals(connectionString, String.format("DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s","accessKey","secretKey")); }
@Test public void testConnectionStringSASIsPriority() { Properties properties = new Properties(); properties.put(AzureConstants.AZURE_SAS, "sas"); properties.put(AzureConstants.AZURE_BLOB_ENDPOINT, "endpoint"); properties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME, "accessKey"); properties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_KEY, "secretKey"); String connectionString = Utils.getConnectionStringFromProperties(properties); assertEquals(connectionString, String.format("BlobEndpoint=%s;SharedAccessSignature=%s", "endpoint", "sas")); }