/** * Tests directory hierarchy navigation. * * @throws URISyntaxException * @throws StorageException */ public void testCloudFileDirectoryFileParentValidate() throws URISyntaxException, StorageException { CloudFile file = this.share.getRootDirectoryReference().getDirectoryReference("TopDir1") .getDirectoryReference("MidDir1").getDirectoryReference("EndDir1").getFileReference("EndFile1"); CloudFileDirectory directory = file.getParent(); assertEquals(directory.getName(), "EndDir1"); assertEquals(directory.getUri().toString(), this.share.getUri() + "/TopDir1/MidDir1/EndDir1"); }
/** * Tests directory creation with empty names. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryGetEmptySubDirectory() throws URISyntaxException, StorageException { CloudFileDirectory root = this.share.getRootDirectoryReference().getDirectoryReference("TopDir1"); try { root.getDirectoryReference(""); fail("Subdirectory references shouldn't work with empty strings."); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), "The argument must not be null or an empty string. Argument name: itemName."); } }
private boolean doCloudFileDirectorySetup(CloudFileShare share) throws URISyntaxException, StorageException { try { CloudFileDirectory rootDirectory = share.getRootDirectoryReference(); for (int i = 1; i < 3; i++) { CloudFileDirectory topDirectory = rootDirectory.getDirectoryReference("TopDir" + i); topDirectory.create(); for (int j = 1; j < 3; j++) { CloudFileDirectory midDirectory = topDirectory.getDirectoryReference("MidDir" + j); midDirectory.create(); for (int k = 1; k < 3; k++) { CloudFileDirectory endDirectory = midDirectory.getDirectoryReference("EndDir" + k); endDirectory.create(); CloudFile file1 = endDirectory.getFileReference("EndFile" + k); file1.create(0); } } CloudFile file2 = topDirectory.getFileReference("File" + i); file2.create(0); } return true; } catch (StorageException e) { throw e; } }
/** * Tests directory hierarchy navigation. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryHierarchicalTraversal() throws URISyntaxException, StorageException { // Traverse hierarchically starting with length 1 CloudFileDirectory directory1 = this.share.getRootDirectoryReference().getDirectoryReference("Dir1"); CloudFileDirectory subdir1 = directory1.getDirectoryReference("Dir2"); CloudFileDirectory parent1 = subdir1.getParent(); assertEquals(parent1.getName(), directory1.getName()); CloudFileDirectory subdir2 = subdir1.getDirectoryReference("Dir3"); CloudFileDirectory parent2 = subdir2.getParent(); assertEquals(parent2.getName(), subdir1.getName()); CloudFileDirectory subdir3 = subdir2.getDirectoryReference("Dir4"); CloudFileDirectory parent3 = subdir3.getParent(); assertEquals(parent3.getName(), subdir2.getName()); CloudFileDirectory subdir4 = subdir3.getDirectoryReference("Dir5"); CloudFileDirectory parent4 = subdir4.getParent(); assertEquals(parent4.getName(), subdir3.getName()); }
/** * Tests directory hierarchy navigation. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryGetSubdirectoryAndTraverseBackToParent() throws URISyntaxException, StorageException { CloudFileDirectory directory = this.share.getRootDirectoryReference().getDirectoryReference("TopDir1"); CloudFileDirectory subDirectory = directory.getDirectoryReference("MidDir1"); CloudFileDirectory parent = subDirectory.getParent(); assertEquals(parent.getName(), directory.getName()); assertEquals(parent.getUri(), directory.getUri()); }
/** * Tests directory creation with absolute uris. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryAbsoluteUriAppended() throws URISyntaxException, StorageException { CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference( this.share.getUri().toString()); assertEquals(PathUtility.appendPathToUri(this.share.getStorageUri(), this.share.getUri().toString()) .getPrimaryUri(), dir.getUri()); assertEquals(new URI(this.share.getUri() + "/" + this.share.getUri()), dir.getUri()); dir = this.share.getRootDirectoryReference().getDirectoryReference(this.share.getUri() + "/TopDir1"); assertEquals( PathUtility.appendPathToUri(this.share.getStorageUri(), this.share.getUri().toString() + "/TopDir1") .getPrimaryUri(), dir.getUri()); }
@Test public void testDirectorySas() throws InvalidKeyException, IllegalArgumentException, StorageException, URISyntaxException, InterruptedException { CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference("dirFile"); CloudFile file = dir.getFileReference("dirFile"); dir.create(); file.create(512); SharedAccessFilePolicy policy = createSharedAccessPolicy( EnumSet.of(SharedAccessFilePermissions.READ, SharedAccessFilePermissions.LIST, SharedAccessFilePermissions.DELETE), 300); // Test directory SAS with a file SAS token from an identically named file String sas = file.generateSharedAccessSignature(policy, null); CloudFileDirectory sasDir = new CloudFileDirectory(new URI(dir.getUri().toString() + "?" + sas)); try { sasDir.downloadAttributes(); fail("This should result in an authentication error."); } catch (StorageException ex) { assertEquals(HttpURLConnection.HTTP_FORBIDDEN, ex.getHttpStatusCode()); } // Test directory SAS with a share SAS token sas = this.share.generateSharedAccessSignature(policy, null); sasDir = new CloudFileDirectory(new URI(dir.getUri().toString() + "?" + sas)); sasDir.downloadAttributes(); // Test deleting a directory using a SAS token. The directory must be empty for this request to succeed. file.delete(); sasDir.delete(); }
/** * Tests directory hierarchy navigation. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryGetParentOnRoot() throws URISyntaxException, StorageException { CloudFileDirectory root = this.share.getRootDirectoryReference().getDirectoryReference("TopDir1"); CloudFileDirectory parent = root.getParent(); assertNotNull(parent); CloudFileDirectory empty = parent.getParent(); assertNull(empty); }
@Before public void fileEncryptionTestMethodSetup() throws URISyntaxException, StorageException, IOException { this.share = FileTestHelper.getRandomShareReference(); this.share.create(); this.dir = this.share.getRootDirectoryReference().getDirectoryReference("dir"); this.dir.create(); this.file = this.share.getRootDirectoryReference().getFileReference("file"); this.file.uploadText("text"); }
@Test public void testDirectoryAttributesEncryption() throws URISyntaxException, StorageException, IOException { assertFalse(this.dir.getProperties().isServerEncrypted()); CloudFileDirectory testDir = this.share.getRootDirectoryReference().getDirectoryReference("dir"); testDir.downloadAttributes(); assertTrue(testDir.getProperties().isServerEncrypted()); }
/** * Ensures we cannot create a directory without creating its parent directory first. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryCreateDirectoryWithoutParent() throws URISyntaxException, StorageException { CloudFileDirectory dir1 = this.share.getRootDirectoryReference().getDirectoryReference("Dir1"); CloudFileDirectory dir2 = this.share.getRootDirectoryReference().getDirectoryReference("Dir1/Dir2"); try { dir2.create(); fail("Directory shouldn't be created when the parent directory wasn't created."); } catch (StorageException e) { assertEquals(e.getErrorCode(), "ParentNotFound"); assertEquals(e.getHttpStatusCode(), 404); assertEquals(e.getMessage(), "The specified parent path does not exist."); } dir1.create(); dir2.create(); }
@Test public void testSupportedDirectoryApisInShareSnapshot() throws StorageException, URISyntaxException { CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference("dir1"); dir.deleteIfExists(); dir.create(); dir.uploadMetadata(); CloudFileShare snapshot = this.share.createSnapshot(); CloudFileDirectory snapshotDir = snapshot.getRootDirectoryReference().getDirectoryReference("dir1");
/** * Test creation and deletion of a directory. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryCreateAndDelete() throws URISyntaxException, StorageException { CloudFileDirectory directory = this.share.getRootDirectoryReference().getDirectoryReference("directory1"); directory.create(); assertTrue(directory.exists()); directory.delete(); assertFalse(directory.exists()); }
@Test public void testCloudFileDirectoryEncryption() throws URISyntaxException, StorageException, IOException { this.requestFound = false; OperationContext ctxt = new OperationContext(); ctxt.getRequestCompletedEventHandler().addListener(new StorageEvent<RequestCompletedEvent>() { @Override public void eventOccurred(RequestCompletedEvent eventArg) { assertTrue(eventArg.getRequestResult().isRequestServiceEncrypted()); CloudFileServerEncryptionTests.this.requestFound = true; } }); this.dir.uploadMetadata(null, null, ctxt); assertTrue(this.requestFound); this.requestFound = false; CloudFileDirectory dir2 = this.share.getRootDirectoryReference().getDirectoryReference("dir2"); dir2.create(null, ctxt); assertTrue(this.requestFound); } }
/** * Tests deleteIfExists for a directory. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryDeleteIfExists() throws URISyntaxException, StorageException { CloudFileDirectory directory = this.share.getRootDirectoryReference().getDirectoryReference("directory1"); assertFalse(directory.deleteIfExists()); directory.create(); assertTrue(directory.deleteIfExists()); assertFalse(directory.deleteIfExists()); }
/** * Tests createIfNotExists for a directory. * * @throws StorageException * @throws URISyntaxException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryCreateIfNotExists() throws StorageException, URISyntaxException { CloudFileDirectory directory = this.share.getRootDirectoryReference().getDirectoryReference("directory1"); assertTrue(directory.createIfNotExists()); assertFalse(directory.createIfNotExists()); directory.delete(); assertTrue(directory.createIfNotExists()); }
/** * Validate share references * * @throws StorageException * @throws URISyntaxException */ @Test public void testCloudFileShareReference() throws StorageException, URISyntaxException { CloudFileClient client = FileTestHelper.createCloudFileClient(); CloudFileShare share = client.getShareReference("share"); CloudFileDirectory directory = share.getRootDirectoryReference().getDirectoryReference("directory3"); CloudFileDirectory directory2 = directory.getDirectoryReference("directory4"); assertEquals(share.getStorageUri().toString(), directory.getShare().getStorageUri().toString()); assertEquals(share.getStorageUri().toString(), directory2.getShare().getStorageUri().toString()); assertEquals(share.getStorageUri().toString(), directory2.getParent().getShare().getStorageUri().toString()); }
/** * Ensures you cannot create a file without first creating the directory it is located within. * * @throws URISyntaxException * @throws StorageException */ public void testCloudFileDirectoryFileCreateWithoutDirectory() throws URISyntaxException, StorageException { CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference("Dir1"); CloudFile file = dir.getFileReference("file1"); try { file.create(0); fail("File shouldn't be created in a directory that wasn't created."); } catch (StorageException e) { assertEquals(e.getErrorCode(), "ParentNotFound"); assertEquals(e.getHttpStatusCode(), 404); assertEquals(e.getMessage(), "The specified parent path does not exist."); } // File creation directly in the share should pass. CloudFile file2 = this.share.getRootDirectoryReference().getFileReference("file2"); file2.create(0); dir.create(); file.create(0); }
/** * Tests to make sure you can't delete a directory if it is nonempty. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryWithFilesDelete() throws URISyntaxException, StorageException { if (doCloudFileDirectorySetup(this.share)) { CloudFileDirectory dir1 = this.share.getRootDirectoryReference().getDirectoryReference( "TopDir1/MidDir1/EndDir1"); CloudFile file1 = dir1.getFileReference("EndFile1"); try { dir1.delete(); fail("Shouldn't be able to delete directory when files still exist in it."); } catch (StorageException e) { assertEquals(e.getHttpStatusCode(), 409); assertEquals(e.getMessage(), "The specified directory is not empty."); } file1.delete(); dir1.delete(); assertFalse(file1.exists()); assertFalse(dir1.exists()); } }
/** * Tests the CloudFileDirectory constructor. * * @throws URISyntaxException * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testCloudFileDirectoryConstructor() throws URISyntaxException, StorageException { CloudFileDirectory directory = this.share.getRootDirectoryReference().getDirectoryReference("directory1"); CloudFileDirectory directory2 = new CloudFileDirectory(directory.getStorageUri(), this.share.getServiceClient().getCredentials()); assertEquals(directory.getName(), directory2.getName()); assertEquals(directory.getStorageUri(), directory2.getStorageUri()); assertEquals(directory.getShare().getStorageUri(), directory2.getShare().getStorageUri()); assertEquals(FileTestHelper.ensureTrailingSlash(directory.getServiceClient().getStorageUri()), FileTestHelper.ensureTrailingSlash(directory2.getServiceClient().getStorageUri())); }