/** * Creates a new Blob service client. * * @return A {@link CloudBlobClient} that represents the cloud Blob client. * */ public CloudBlobClient createCloudBlobClient() { if (this.getBlobStorageUri() == null) { throw new IllegalArgumentException(SR.BLOB_ENDPOINT_NOT_CONFIGURED); } if (this.credentials == null) { throw new IllegalArgumentException(SR.MISSING_CREDENTIALS); } return new CloudBlobClient(this.getBlobStorageUri(), this.getCredentials()); }
/** * Creates a new Blob service client. * * @return A {@link CloudBlobClient} that represents the cloud Blob client. * */ public CloudBlobClient createCloudBlobClient() { if (this.getBlobStorageUri() == null) { throw new IllegalArgumentException(SR.BLOB_ENDPOINT_NOT_CONFIGURED); } if (this.credentials == null) { throw new IllegalArgumentException(SR.MISSING_CREDENTIALS); } return new CloudBlobClient(this.getBlobStorageUri(), this.getCredentials()); }
/** * Creates a new Analytics service client. * * @return An analytics client object that uses the Blob and Table service endpoints. */ public CloudAnalyticsClient createCloudAnalyticsClient() { if (this.getBlobStorageUri() == null) { throw new IllegalArgumentException(SR.BLOB_ENDPOINT_NOT_CONFIGURED); } if (this.getTableStorageUri() == null) { throw new IllegalArgumentException(SR.TABLE_ENDPOINT_NOT_CONFIGURED); } if (this.credentials == null) { throw new IllegalArgumentException(SR.MISSING_CREDENTIALS); } return new CloudAnalyticsClient(this.getBlobStorageUri(), this.getTableStorageUri(), this.getCredentials()); }
/** * Creates a new Analytics service client. * * @return An analytics client object that uses the Blob and Table service endpoints. */ public CloudAnalyticsClient createCloudAnalyticsClient() { if (this.getBlobStorageUri() == null) { throw new IllegalArgumentException(SR.BLOB_ENDPOINT_NOT_CONFIGURED); } if (this.getTableStorageUri() == null) { throw new IllegalArgumentException(SR.TABLE_ENDPOINT_NOT_CONFIGURED); } if (this.credentials == null) { throw new IllegalArgumentException(SR.MISSING_CREDENTIALS); } return new CloudAnalyticsClient(this.getBlobStorageUri(), this.getTableStorageUri(), this.getCredentials()); }
if (this.getBlobStorageUri() != null) { if (this.isBlobEndpointDefault) { addDefault = true;
if (this.getBlobStorageUri() != null) { if (this.isBlobEndpointDefault) { addDefault = true;
@Test public void testCloudStorageAccountDefaultEndpointOverride() throws URISyntaxException, InvalidKeyException { CloudStorageAccount account = CloudStorageAccount .parse("DefaultEndpointsProtocol=http;BlobEndpoint=http://customdomain.com/;AccountName=asdf;AccountKey=123="); assertEquals(new URI("http://customdomain.com/"), account.getBlobEndpoint()); assertNull(account.getBlobStorageUri().getSecondaryUri()); }
@Test public void testCloudStorageAccountDefaultStorageAccountWithHttp() throws URISyntaxException, InvalidKeyException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, false); assertEquals(cloudStorageAccount.getBlobEndpoint(), new URI(String.format("http://%s.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueEndpoint(), new URI(String.format("http://%s.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableEndpoint(), new URI(String.format("http://%s.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileEndpoint(), new URI(String.format("http://%s.file.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getBlobStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.file.core.windows.net", ACCOUNT_NAME))); String cloudStorageAccountToStringWithSecrets = cloudStorageAccount.toString(true); CloudStorageAccount testAccount = CloudStorageAccount.parse(cloudStorageAccountToStringWithSecrets); AccountsAreEqual(testAccount, cloudStorageAccount); }
@Test public void testCloudStorageAccountDevStoreProxyUri() throws InvalidKeyException, URISyntaxException { CloudStorageAccount account = CloudStorageAccount .parse("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://ipv4.fiddler"); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); }
@Test public void testCloudStorageAccountDefaultStorageAccountWithHttps() throws URISyntaxException, InvalidKeyException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true); assertEquals(cloudStorageAccount.getBlobEndpoint(), new URI(String.format("https://%s.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueEndpoint(), new URI(String.format("https://%s.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableEndpoint(), new URI(String.format("https://%s.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileEndpoint(), new URI(String.format("https://%s.file.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getBlobStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.file.core.windows.net", ACCOUNT_NAME))); String cloudStorageAccountToStringWithSecrets = cloudStorageAccount.toString(true); CloudStorageAccount testAccount = CloudStorageAccount.parse(cloudStorageAccountToStringWithSecrets); AccountsAreEqual(testAccount, cloudStorageAccount); }
@Test public void testCloudStorageAccountWithStorageUri() throws URISyntaxException, InvalidKeyException { StorageUri blobEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + BLOB_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + BLOB_SERVICE + ENDPOINT_SUFFIX)); StorageUri queueEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + QUEUE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + QUEUE_SERVICE + ENDPOINT_SUFFIX)); StorageUri tableEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + TABLE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + TABLE_SERVICE + ENDPOINT_SUFFIX)); CloudStorageAccount account = CloudStorageAccount.parse(String.format( "DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=dummyKey", ACCOUNT_NAME)); assertEquals(blobEndpoint, account.getBlobStorageUri()); assertEquals(queueEndpoint, account.getQueueStorageUri()); assertEquals(tableEndpoint, account.getTableStorageUri()); assertEquals(blobEndpoint, account.createCloudBlobClient().getStorageUri()); assertEquals(queueEndpoint, account.createCloudQueueClient().getStorageUri()); assertEquals(tableEndpoint, account.createCloudTableClient().getStorageUri()); assertEquals(blobEndpoint.getPrimaryUri(), account.getBlobEndpoint()); assertEquals(queueEndpoint.getPrimaryUri(), account.getQueueEndpoint()); assertEquals(tableEndpoint.getPrimaryUri(), account.getTableEndpoint()); }
@Test public void testCloudStorageAccountDevelopmentStorageAccount() throws InvalidKeyException, URISyntaxException { CloudStorageAccount devstoreAccount = CloudStorageAccount.getDevelopmentStorageAccount(); assertEquals(devstoreAccount.getBlobStorageUri().getPrimaryUri(), new URI( "http://127.0.0.1:10000/devstoreaccount1")); assertEquals(devstoreAccount.getQueueStorageUri().getPrimaryUri(), new URI( "http://127.0.0.1:10001/devstoreaccount1")); assertEquals(devstoreAccount.getTableStorageUri().getPrimaryUri(), new URI( "http://127.0.0.1:10002/devstoreaccount1")); assertEquals(devstoreAccount.getBlobStorageUri().getSecondaryUri(), new URI( "http://127.0.0.1:10000/devstoreaccount1-secondary")); assertEquals(devstoreAccount.getQueueStorageUri().getSecondaryUri(), new URI( "http://127.0.0.1:10001/devstoreaccount1-secondary")); assertEquals(devstoreAccount.getTableStorageUri().getSecondaryUri(), new URI( "http://127.0.0.1:10002/devstoreaccount1-secondary")); String devstoreAccountToStringWithSecrets = devstoreAccount.toString(true); CloudStorageAccount testAccount = CloudStorageAccount.parse(devstoreAccountToStringWithSecrets); AccountsAreEqual(testAccount, devstoreAccount); // Following should not throw exception: CloudStorageAccount.parse(devstoreAccountToStringWithSecrets); }
@Test public void testCloudStorageAccountDevStore() throws URISyntaxException { // default CloudStorageAccount account = CloudStorageAccount.getDevelopmentStorageAccount(); assertEquals(new URI("http://127.0.0.1:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://127.0.0.1:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://127.0.0.1:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://127.0.0.1:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://127.0.0.1:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://127.0.0.1:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); // proxy account = CloudStorageAccount.getDevelopmentStorageAccount(new URI("http://ipv4.fiddler")); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); }
@Test public void testDevelopmentStorageWithTwoUris() throws URISyntaxException { CloudStorageAccount account = CloudStorageAccount.getDevelopmentStorageAccount(); URI primaryClientURI = account.getBlobStorageUri().getPrimaryUri(); URI primaryContainerURI = new URI(primaryClientURI.toString() + "/container"); URI secondaryClientURI = account.getBlobStorageUri().getSecondaryUri(); StorageUri singleURI = new StorageUri(primaryClientURI); assertTrue(primaryClientURI.equals(singleURI.getPrimaryUri())); assertNull(singleURI.getSecondaryUri()); StorageUri singleURI2 = new StorageUri(primaryClientURI); assertTrue(singleURI.equals(singleURI2)); StorageUri singleURI3 = new StorageUri(secondaryClientURI); assertFalse(singleURI.equals(singleURI3)); StorageUri multiURI = new StorageUri(primaryClientURI, secondaryClientURI); assertTrue(primaryClientURI.equals(multiURI.getPrimaryUri())); assertTrue(secondaryClientURI.equals(multiURI.getSecondaryUri())); assertFalse(multiURI.equals(singleURI)); StorageUri multiURI2 = new StorageUri(primaryClientURI, secondaryClientURI); assertTrue(multiURI.equals(multiURI2)); try { new StorageUri(primaryClientURI, primaryContainerURI); fail("StorageUri constructor should fail if both URIs do not point to the same resource"); } catch (IllegalArgumentException e) { assertEquals(SR.STORAGE_URI_MUST_MATCH, e.getMessage()); } StorageUri multiURI3 = new StorageUri(secondaryClientURI, primaryClientURI); assertFalse(multiURI.equals(multiURI3)); }
private void AccountsAreEqual(CloudStorageAccount a, CloudStorageAccount b) { // endpoints are the same assertEquals(a.getBlobEndpoint(), b.getBlobEndpoint()); assertEquals(a.getQueueEndpoint(), b.getQueueEndpoint()); assertEquals(a.getTableEndpoint(), b.getTableEndpoint()); assertEquals(a.getFileEndpoint(), b.getFileEndpoint()); // storage uris are the same assertEquals(a.getBlobStorageUri(), b.getBlobStorageUri()); assertEquals(a.getQueueStorageUri(), b.getQueueStorageUri()); assertEquals(a.getTableStorageUri(), b.getTableStorageUri()); assertEquals(a.getFileStorageUri(), b.getFileStorageUri()); // seralized representatons are the same. String aToStringNoSecrets = a.toString(); String aToStringWithSecrets = a.toString(true); String bToStringNoSecrets = b.toString(false); String bToStringWithSecrets = b.toString(true); assertEquals(aToStringNoSecrets, bToStringNoSecrets); assertEquals(aToStringWithSecrets, bToStringWithSecrets); // credentials are the same if (a.getCredentials() != null && b.getCredentials() != null) { assertEquals(a.getCredentials().getClass(), b.getCredentials().getClass()); } else if (a.getCredentials() == null && b.getCredentials() == null) { return; } else { fail("credentials mismatch"); } }
@Test public void testCloudStorageAccountClientMethods() throws URISyntaxException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount account = new CloudStorageAccount(cred, false); CloudBlobClient blob = account.createCloudBlobClient(); CloudQueueClient queue = account.createCloudQueueClient(); CloudTableClient table = account.createCloudTableClient(); CloudFileClient file = account.createCloudFileClient(); // check endpoints assertEquals("Blob endpoint doesn't match account", account.getBlobEndpoint(), blob.getEndpoint()); assertEquals("Queue endpoint doesn't match account", account.getQueueEndpoint(), queue.getEndpoint()); assertEquals("Table endpoint doesn't match account", account.getTableEndpoint(), table.getEndpoint()); assertEquals("File endpoint doesn't match account", account.getFileEndpoint(), file.getEndpoint()); // check storage uris assertEquals("Blob endpoint doesn't match account", account.getBlobStorageUri(), blob.getStorageUri()); assertEquals("Queue endpoint doesn't match account", account.getQueueStorageUri(), queue.getStorageUri()); assertEquals("Table endpoint doesn't match account", account.getTableStorageUri(), table.getStorageUri()); assertEquals("File endpoint doesn't match account", account.getFileStorageUri(), file.getStorageUri()); // check creds assertEquals("Blob creds don't match account", account.getCredentials(), blob.getCredentials()); assertEquals("Queue creds don't match account", account.getCredentials(), queue.getCredentials()); assertEquals("Table creds don't match account", account.getCredentials(), table.getCredentials()); assertEquals("File creds don't match account", account.getCredentials(), file.getCredentials()); }