FileStorageResource(CloudFileClient fileClient, String location, boolean autoCreateFiles) { assertIsAzureStorageLocation(location); this.autoCreateFiles = autoCreateFiles; this.fileClient = fileClient; this.location = location; try { this.fileShare = fileClient.getShareReference(getContainerName(location)); this.cloudFile = fileShare.getRootDirectoryReference().getFileReference(getFileName(location)); } catch (URISyntaxException | StorageException e) { log.error(MSG_FAIL_GET, e); throw new RuntimeException(MSG_FAIL_GET, e); } }
public static CloudFile uploadNewFile( CloudFileShare share, InputStream stream, int length, OperationContext context) throws StorageException, IOException, URISyntaxException { String name = generateRandomFileName(); CloudFile file = null; file = share.getRootDirectoryReference().getFileReference(name); file.upload(stream, length, null, null, context); return file; }
@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 testFileContentMD5NewFileTest() throws URISyntaxException, StorageException, IOException { final String fileName = FileTestHelper.generateRandomFileName(); final CloudFile file = this.share.getRootDirectoryReference().getFileReference(fileName); FileRequestOptions options = new FileRequestOptions(); options.setStoreFileContentMD5(true); options.setDisableContentMD5Validation(false); File tempFile = File.createTempFile("sourceFile", ".tmp"); file.uploadFromFile(tempFile.getAbsolutePath(), null, options, null); }
@Test public void testCloudFileDownloadRangeToByteArrayNegativeTest() throws URISyntaxException, StorageException, IOException { CloudFile file = this.share.getRootDirectoryReference().getFileReference( FileTestHelper.generateRandomFileName()); FileTestHelper.doDownloadRangeToByteArrayNegativeTests(file); }
/** * 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 file upload and download using text. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileUploadDownloadFromText() throws IOException, StorageException, URISyntaxException { String fileName = FileTestHelper.generateRandomFileName(); final CloudFile file = this.share.getRootDirectoryReference().getFileReference(fileName); String textFile = "string of text to upload to a file. The_quick_brown_fox_jumps_over_the_lazy_dog. 1!\". "."; file.uploadText(textFile); String result = file.downloadText(); assertEquals(textFile, result); }
@Test public void testCloudFileDownloadToByteArray() throws URISyntaxException, StorageException, IOException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); FileTestHelper.doDownloadTest(file, 1 * 512, 2 * 512, 0); FileTestHelper.doDownloadTest(file, 1 * 512, 2 * 512, 1 * 512); FileTestHelper.doDownloadTest(file, 2 * 512, 4 * 512, 1 * 512); FileTestHelper.doDownloadTest(file, 5 * 1024 * 1024, 5 * 1024 * 1024, 0); FileTestHelper.doDownloadTest(file, 5 * 1024 * 1024, 6 * 1024 * 1024, 512); }
/** * 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 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); }
/** * Test file uploading from byte arrays. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileUploadFromByteArray() throws Exception { String fileName = FileTestHelper.generateRandomFileName(); final CloudFile file = this.share.getRootDirectoryReference().getFileReference(fileName); this.doUploadFromByteArrayTest(file, 4 * 512, 0, 4 * 512); this.doUploadFromByteArrayTest(file, 4 * 512, 0, 2 * 512); this.doUploadFromByteArrayTest(file, 4 * 512, 1 * 512, 2 * 512); this.doUploadFromByteArrayTest(file, 4 * 512, 2 * 512, 2 * 512); }
/** * Test file upload and download using io files. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileUploadDownloadFromFile() throws IOException, StorageException, URISyntaxException { String fileName = FileTestHelper.generateRandomFileName(); final CloudFile file = this.share.getRootDirectoryReference().getFileReference(fileName); this.doUploadDownloadFileTest(file, 512); this.doUploadDownloadFileTest(file, 4096); this.doUploadDownloadFileTest(file, 5 * 1024 * 1024); this.doUploadDownloadFileTest(file, 11 * 1024 * 1024); }
@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()); }
/** * Test file deleteIfExists. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileDeleteIfExists() throws URISyntaxException, StorageException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); assertFalse(file.deleteIfExists()); file.create(0); assertTrue(file.deleteIfExists()); assertFalse(file.deleteIfExists()); }
@Test public void testFileAttributesEncryption() throws URISyntaxException, StorageException, IOException { this.file.downloadAttributes(); assertTrue(this.file.getProperties().isServerEncrypted()); CloudFile testFile = this.share.getRootDirectoryReference().getFileReference("file"); testFile.downloadText(); assertTrue(testFile.getProperties().isServerEncrypted()); }
@Test public void testCloudFileCreate() throws StorageException, URISyntaxException { CloudFile file = this.share.getRootDirectoryReference().getFileReference("file1"); assertFalse(file.exists()); // Create file.create(512); assertTrue(file.exists()); // Create again (should succeed) file.create(128); assertTrue(file.exists()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }