@Override public String getFilename() { return this.cloudFile.getName(); }
@Override public String getDescription() { return String.format("Azure storage account file resource [container='%s', file='%s']", this.fileShare.getName(), this.cloudFile.getName()); }
assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), httpShare.getServiceClient().getCredentials().getClass().toString()); CloudFile httpFile = httpShare.getRootDirectoryReference().getFileReference(this.file.getName()); httpFile.download(new ByteArrayOutputStream()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), httpsShare.getServiceClient().getCredentials().getClass().toString()); CloudFile httpsFile = httpsShare.getRootDirectoryReference().getFileReference(this.file.getName()); httpsFile.download(new ByteArrayOutputStream()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), httpShare.getServiceClient().getCredentials().getClass().toString()); CloudFile httpFile = httpShare.getRootDirectoryReference().getFileReference(this.file.getName()); httpFile.download(new ByteArrayOutputStream()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), httpsShare.getServiceClient().getCredentials().getClass().toString()); httpsFile = httpsShare.getRootDirectoryReference().getFileReference(this.file.getName()); httpsFile.download(new ByteArrayOutputStream());
noneShare.getServiceClient().getCredentials().getClass().toString()); CloudFile noneFile = noneShare.getRootDirectoryReference().getFileReference(this.file.getName()); noneFile.download(new ByteArrayOutputStream()); fail(); oneShare.getServiceClient().getCredentials().getClass().toString()); CloudFile oneFile = oneShare.getRootDirectoryReference().getFileReference(this.file.getName()); oneFile.download(new ByteArrayOutputStream()); allShare.getServiceClient().getCredentials().getClass().toString()); CloudFile allFile = allShare.getRootDirectoryReference().getFileReference(this.file.getName()); allFile.download(new ByteArrayOutputStream());
@Test public void testFileSAS() throws InvalidKeyException, IllegalArgumentException, StorageException, URISyntaxException, InterruptedException { SharedAccessFilePolicy policy = createSharedAccessPolicy( EnumSet.of(SharedAccessFilePermissions.READ, SharedAccessFilePermissions.LIST), 300); FileSharePermissions perms = new FileSharePermissions(); perms.getSharedAccessPolicies().put("readperm", policy); this.share.uploadPermissions(perms); Thread.sleep(30000); CloudFile sasFile = new CloudFile( new URI(this.file.getUri().toString() + "?" + this.file.generateSharedAccessSignature(null, "readperm"))); sasFile.download(new ByteArrayOutputStream()); // do not give the client and check that the new file's client has the correct permissions CloudFile fileFromUri = new CloudFile(PathUtility.addToQuery(this.file.getStorageUri(), this.file.generateSharedAccessSignature(null, "readperm"))); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), fileFromUri.getServiceClient().getCredentials().getClass().toString()); // create credentials from sas StorageCredentials creds = new StorageCredentialsSharedAccessSignature( this.file.generateSharedAccessSignature(policy, null, null)); CloudFileClient client = new CloudFileClient(sasFile.getServiceClient().getStorageUri(), creds); CloudFile fileFromClient = client.getShareReference(this.file.getShare().getName()).getRootDirectoryReference() .getFileReference(this.file.getName()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), fileFromClient.getServiceClient().getCredentials().getClass().toString()); assertEquals(client, fileFromClient.getServiceClient()); }
readListShare.getServiceClient().getCredentials().getClass().toString()); CloudFile fileFromSasShare = readListShare.getRootDirectoryReference().getFileReference(this.file.getName()); fileFromSasShare.download(new ByteArrayOutputStream());
assertEquals("File1", ((CloudFile) item11).getName());
ListFileItem item = simpleList.get(0); assertEquals(this.share.getUri() + "/TopDir1/File1", item.getUri().toString()); assertEquals("File1", ((CloudFile) item).getName());
/** * Start copying a file and then abort * * @throws StorageException * @throws URISyntaxException * @throws IOException * @throws InterruptedException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCopyFileAbort() throws StorageException, URISyntaxException, IOException { final int length = 128; CloudFile originalFile = FileTestHelper.uploadNewFile(this.share, length, null); CloudFile copyFile = this.share.getRootDirectoryReference().getFileReference(originalFile.getName() + "copyed"); copyFile.startCopy(originalFile); try { copyFile.abortCopy(copyFile.getProperties().getCopyState().getCopyId()); fail(); } catch (StorageException e) { if (!e.getErrorCode().contains("NoPendingCopyOperation")) { throw e; } } }
final CloudBlockBlob destination = this.container.getBlockBlobReference(source.getName() + "copyed"); StorageCredentialsSharedAccessSignature credentials = new StorageCredentialsSharedAccessSignature(sasToken); destination.startCopy(new CloudFile(credentials.transformUri(source.getUri())));
/** * Test file constructor. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileConstructor() throws URISyntaxException, StorageException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); CloudFile file2 = new CloudFile(file.getStorageUri(), file.getServiceClient().getCredentials()); assertEquals(file.getName(), file2.getName()); assertEquals(file.getStorageUri(), file2.getStorageUri()); assertEquals(file.getShare().getStorageUri(), file2.getShare().getStorageUri()); assertEquals(FileTestHelper.ensureTrailingSlash(file.getServiceClient().getStorageUri()), FileTestHelper.ensureTrailingSlash(file2.getServiceClient().getStorageUri())); CloudFile file3 = new CloudFile(file2); assertEquals(file3.getName(), file2.getName()); assertEquals(file3.getStorageUri(), file2.getStorageUri()); assertEquals(file3.getShare().getStorageUri(), file2.getShare().getStorageUri()); assertEquals(FileTestHelper.ensureTrailingSlash(file3.getServiceClient().getStorageUri()), FileTestHelper.ensureTrailingSlash(file2.getServiceClient().getStorageUri())); }
file = share.getRootDirectoryReference().getFileReference(sasFile.getName()); assertMessagesMatch(AccountSasTests.INVALID_PERMISSION_MESSAGE, ex); file = FileTestHelper.uploadNewFile(share, FileTestHelper.getRandomDataStream(0), length, null); sasFile = sasShare.getRootDirectoryReference().getFileReference(file.getName());
if (share != null) { share = new CloudFileShare(credentials.transformUri(share.getUri())); file = share.getRootDirectoryReference().getFileReference(file.getName());
/** * Tests directory hierarchy navigation. * * @throws StorageException * @throws URISyntaxException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryGetParent() throws StorageException, URISyntaxException { CloudFile file = this.share.getRootDirectoryReference().getDirectoryReference("Dir1") .getFileReference("File1"); assertEquals("File1", file.getName()); // get the file's parent CloudFileDirectory parent = file.getParent(); assertEquals(parent.getName(), "Dir1"); // get share as parent CloudFileDirectory root = parent.getParent(); assertEquals(root.getName(), ""); // make sure the parent of the share dir is null CloudFileDirectory empty = root.getParent(); assertNull(empty); // from share, get directory reference to share root = this.share.getRootDirectoryReference(); assertEquals("", root.getName()); assertEquals(this.share.getUri(), root.getUri()); // make sure the parent of the share dir is null empty = root.getParent(); assertNull(empty); }
/** * @throws StorageException * @throws URISyntaxException * @throws IOException * @throws InterruptedException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, SlowTests.class }) public void testFileNamePlusEncoding() throws StorageException, URISyntaxException, IOException, InterruptedException { CloudFile originalFile = FileTestHelper.uploadNewFile(this.share, 1024 /* length */, null); CloudFile copyFile = this.share.getRootDirectoryReference().getFileReference(originalFile.getName() + "copyed"); copyFile.startCopy(originalFile); FileTestHelper.waitForCopy(copyFile); copyFile.downloadAttributes(); originalFile.downloadAttributes(); FileProperties prop1 = copyFile.getProperties(); FileProperties prop2 = originalFile.getProperties(); assertEquals(prop1.getCacheControl(), prop2.getCacheControl()); assertEquals(prop1.getContentEncoding(), prop2.getContentEncoding()); assertEquals(prop1.getContentDisposition(), prop2.getContentDisposition()); assertEquals(prop1.getContentLanguage(), prop2.getContentLanguage()); assertEquals(prop1.getContentMD5(), prop2.getContentMD5()); assertEquals(prop1.getContentType(), prop2.getContentType()); }
assertEquals("myfile", ((CloudFile) listFileItem).getName());