public static CloudFile uploadNewFile(CloudFileShare share, int length, OperationContext context) throws StorageException, IOException, URISyntaxException { return uploadNewFile(share, getRandomDataStream(length), length, context); }
@Before public void fileSASTestMethodSetUp() throws URISyntaxException, StorageException, IOException { if (fileClient == null) { fileClient = TestHelper.createCloudFileClient(); } this.share = FileTestHelper.getRandomShareReference(); this.share.create(); this.file = (CloudFile) FileTestHelper.uploadNewFile(this.share, 100, null); }
@Test @Category({ SlowTests.class }) public void testShareSASCombinations() throws StorageException, URISyntaxException, IOException, InvalidKeyException, InterruptedException { EnumSet<SharedAccessFilePermissions> permissionSet = null; Map<Integer, CloudFileShare> shares = new HashMap<Integer, CloudFileShare>(); try { for (int bits = 0x1; bits < 0x40; bits++) { shares.put(bits, FileTestHelper.getRandomShareReference()); shares.get(bits).createIfNotExists(); permissionSet = getPermissions(bits); FileSharePermissions perms = new FileSharePermissions(); perms.getSharedAccessPolicies().put("readwrite" + bits, createSharedAccessPolicy(permissionSet, 300)); shares.get(bits).uploadPermissions(perms); } Thread.sleep(30000); for (int bits = 0x1; bits < 0x20; bits++) { permissionSet = getPermissions(bits); String sasToken = shares.get(bits).generateSharedAccessSignature(null, "readwrite" + bits); CloudFile testFile = FileTestHelper.uploadNewFile(shares.get(bits), 64, null); testAccess(sasToken, permissionSet, shares.get(bits), testFile); } } finally { for (int bits = 0x1; bits < shares.size(); bits++) { shares.get(bits).deleteIfExists(); } } }
@Test public void testFileSASCombinations() throws URISyntaxException, StorageException, InvalidKeyException, IOException { EnumSet<SharedAccessFilePermissions> permissionSet = null; for (int bits = 0x1; bits < 0x10; bits++) { permissionSet = getPermissions(bits); SharedAccessFilePolicy policy = createSharedAccessPolicy(permissionSet, 300); CloudFile testFile = FileTestHelper.uploadNewFile(this.share, 512, null); String sasToken = testFile.generateSharedAccessSignature(policy, null, null); testAccess(sasToken, permissionSet, null, testFile); } }
CloudFile file = FileTestHelper.uploadNewFile(this.share, 64, null); testAccess(sasToken, EnumSet.of(SharedAccessFilePermissions.READ, SharedAccessFilePermissions.WRITE), this.share, file); FileTestHelper.uploadNewFile(sasShare, 64, null); Assert.fail();
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testFileGetRangeContentMD5Bounds() throws StorageException, IOException, URISyntaxException { { CloudFile file = FileTestHelper.uploadNewFile(this.share, 5 * Constants.MB, null); FileRequestOptions options = new FileRequestOptions(); OperationContext opContext = new OperationContext(); try { FileRequest.getFile(file.getUri(), options, opContext, null, null, 0L, 4L * Constants.MB, true); FileRequest.getFile(file.getUri(), options, opContext, null, null, 0L, 4L * Constants.MB + 1, true); fail("The request for range ContentMD5 should have thrown an Exception for exceeding the limit."); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), String.format("The value of the parameter 'count' should be between 1 and %1d.", Constants.MAX_BLOCK_SIZE)); } } }
/** * 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 CloudFileShare share = FileTestHelper.getRandomShareReference(); share.create(); final CloudFile source = FileTestHelper.uploadNewFile(share, length, null);
/** * Tests whether Share Stats can be updated and downloaded. * * @throws StorageException * @throws IOException * @throws URISyntaxException */ @Test @Category({ CloudTests.class }) public void testGetShareStats() throws StorageException, IOException, URISyntaxException { share.createIfNotExists(); ShareStats stats = share.getStats(); assertNotNull(stats); assertEquals(0, stats.getUsage()); FileTestHelper.uploadNewFile(share, 512, null); stats = share.getStats(); assertNotNull(stats); assertEquals(1, stats.getUsage()); }
file = FileTestHelper.uploadNewFile(share, FileTestHelper.getRandomDataStream(0), length, null); sasFile = sasShare.getRootDirectoryReference().getFileReference(file.getName()); FileTestHelper.uploadNewFile(sasShare, FileTestHelper.getRandomDataStream(0), length, null); fail(); FileTestHelper.uploadNewFile(share, FileTestHelper.getRandomDataStream(0), length, null);
/** * @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()); }