/** * Deletes the file. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException */ @DoesServiceRequest public final void delete() throws StorageException, URISyntaxException { this.delete(null /* accessCondition */, null /* options */, null /* opContext */); }
file.delete(); fail("File should not already exist.");
/** * Deletes the file. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException */ @DoesServiceRequest public final void delete() throws StorageException, URISyntaxException { this.delete(null /* accessCondition */, null /* options */, null /* opContext */); }
if (exists) { try { this.delete(accessCondition, options, opContext); return true;
if (exists) { try { this.delete(accessCondition, options, opContext); return true;
@Override public void eventOccurred(SendingRequestEvent eventArg) { if (((HttpURLConnection) eventArg.getConnectionObject()).getRequestMethod().equals("DELETE")) { try { file.delete(); assertFalse(file.exists()); } catch (Exception e) { fail("Delete should succeed."); } } } });
/** * Test file creation and deletion. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileCreateAndDelete() throws URISyntaxException, StorageException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); file.create(0); assertTrue(file.exists()); file.delete(); }
@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(); }
fileRef.delete();
file.delete(); fail("Shouldn't get here");
assertFalse(copy.getMetadata().containsKey("Test")); copy.delete();
/** * Test file exits method. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileExists() throws URISyntaxException, StorageException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); CloudFile file2 = this.share.getRootDirectoryReference().getFileReference("file1"); assertFalse(file2.exists()); file.create(2048); assertTrue(file2.exists()); assertEquals(2048, file2.getProperties().getLength()); file.delete(); assertFalse(file2.exists()); }
copySas.delete(); container.delete();
/** * 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()); } }