String fileName1 = FileTestHelper.generateRandomFileName(); CloudFile fileRef1 = this.share.getRootDirectoryReference().getFileReference(fileName1); fileRef1.upload(FileTestHelper.getRandomDataStream(length), length); FileTestHelper.setFileProperties(fileRef1); FileProperties props1 = fileRef1.getProperties(); fileRef1.uploadProperties(); FileProperties props2 = fileRef1.getProperties(); FileTestHelper.assertAreEqual(props1, props2); fileName1 = FileTestHelper.generateRandomFileName(); fileRef1 = this.share.getRootDirectoryReference().getFileReference(fileName1); FileTestHelper.setFileProperties(fileRef1); props1 = fileRef1.getProperties(); fileRef1.upload(FileTestHelper.getRandomDataStream(length), length); FileTestHelper.assertAreEqual(props1, props2);
@Test public void testFileUploadFromStreamTest() throws URISyntaxException, StorageException, IOException { final String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); int length = 2 * 1024; ByteArrayInputStream srcStream = FileTestHelper.getRandomDataStream(length); fileRef.upload(srcStream, length); ByteArrayOutputStream dstStream = new ByteArrayOutputStream(); fileRef.download(dstStream); FileTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); length = 5 * 1024 * 1024; srcStream = FileTestHelper.getRandomDataStream(length); fileRef.upload(srcStream, length); dstStream = new ByteArrayOutputStream(); fileRef.download(dstStream); FileTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); }
byte[] buffer = FileTestHelper.getRandomBuffer(2 * 1024); FileTestHelper.assertStreamsAreEqualAtIndex(new ByteArrayInputStream(fileStream.toByteArray()), wholeFile, 0, 0, 1024, 2 * 1024); FileTestHelper.assertStreamsAreEqualAtIndex(new ByteArrayInputStream(fileStream2.toByteArray()), wholeFile, 1024, 1024, 1024, 2 * 1024); FileTestHelper.assertAreEqual(file, file2);
@Test public void testCloudFileDownloadRangeToByteArray() throws URISyntaxException, StorageException, IOException { CloudFile file = this.share.getRootDirectoryReference().getFileReference( FileTestHelper.generateRandomFileName()); FileTestHelper.doDownloadRangeToByteArrayTest(file, 8 * 1024 * 1024, 8 * 1024 * 1024, 1 * 1024 * 1024, new Long(1 * 1024 * 1024), new Long(5 * 1024 * 1024)); FileTestHelper.doDownloadRangeToByteArrayTest(file, 8 * 1024 * 1024, 8 * 1024 * 1024, 2 * 1024 * 1024, new Long(2 * 1024 * 1024), new Long(6 * 1024 * 1024)); FileTestHelper.doDownloadRangeToByteArrayTest(file, 8 * 1024 * 1024, 8 * 1024 * 1024, 1 * 1024 * 1024, new Long(4 * 1024 * 1024), new Long(4 * 1024 * 1024)); FileTestHelper.doDownloadRangeToByteArrayTest(file, 2 * 512, 4 * 512, 0, new Long(1 * 512), new Long(1 * 512)); FileTestHelper.doDownloadRangeToByteArrayTest(file, 2 * 512, 4 * 512, 1 * 512, new Long(0), null); FileTestHelper.doDownloadRangeToByteArrayTest(file, 2 * 512, 4 * 512, 1 * 512, new Long(1 * 512), null); FileTestHelper.doDownloadRangeToByteArrayTest(file, 2 * 512, 4 * 512, 1 * 512, new Long(0), new Long(1 * 512)); FileTestHelper.doDownloadRangeToByteArrayTest(file, 2 * 512, 4 * 512, 2 * 512, new Long(1 * 512), new Long( 1 * 512)); FileTestHelper.doDownloadRangeToByteArrayTest(file, 2 * 512, 4 * 512, 2 * 512, new Long(1 * 512), new Long( 2 * 512)); // Edge cases FileTestHelper.doDownloadRangeToByteArrayTest(file, 1024, 1024, 1023, new Long(1023), new Long(1)); FileTestHelper.doDownloadRangeToByteArrayTest(file, 1024, 1024, 0, new Long(1023), new Long(1)); FileTestHelper.doDownloadRangeToByteArrayTest(file, 1024, 1024, 0, new Long(0), new Long(1)); FileTestHelper.doDownloadRangeToByteArrayTest(file, 1024, 1024, 0, new Long(512), new Long(1)); FileTestHelper.doDownloadRangeToByteArrayTest(file, 1024, 1024, 512, new Long(1023), new Long(1)); }
@Test public void testCloudFileDownloadRangeToByteArrayNegativeTest() throws URISyntaxException, StorageException, IOException { CloudFile file = this.share.getRootDirectoryReference().getFileReference( FileTestHelper.generateRandomFileName()); FileTestHelper.doDownloadRangeToByteArrayNegativeTests(file); }
public void testCloudFileDownloadRange() throws StorageException, URISyntaxException, IOException { int fileLengthToUse = 8 * 512; byte[] buffer = FileTestHelper.getRandomBuffer(8 * 512); String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); fileRef.create(fileLengthToUse);
@Test public void testFileEmptyHeaderSigningTest() throws URISyntaxException, StorageException, IOException { final String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); final int length = 2 * 1024; ByteArrayInputStream srcStream = FileTestHelper.getRandomDataStream(length); OperationContext context = new OperationContext(); context.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(SendingRequestEvent eventArg) { HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject(); connection.setRequestProperty("x-ms-foo", ""); } }); fileRef.upload(srcStream, length, null, null, context); fileRef.download(new ByteArrayOutputStream(), null, null, context); }
String data = "String data"; CloudFile source = this.share.getRootDirectoryReference().getFileReference("source"); FileTestHelper.setFileProperties(source); String copyId = copy.startCopy(FileTestHelper.defiddler(source)); FileTestHelper.waitForCopy(copy);
CloudFile sasFile = null; sasFile = sasShare.getRootDirectoryReference().getFileReference(FileTestHelper.generateRandomFileName()); if (policy.getPermissions().contains(SharedAccessAccountPermissions.CREATE) || policy.getPermissions().contains(SharedAccessAccountPermissions.WRITE)) { file = FileTestHelper.uploadNewFile(share, FileTestHelper.getRandomDataStream(0), length, null); sasFile = sasShare.getRootDirectoryReference().getFileReference(file.getName()); final ByteArrayInputStream sourcestream = FileTestHelper.getRandomDataStream(length); if (policy.getPermissions().contains(SharedAccessAccountPermissions.WRITE)) { sasFile.upload(sourcestream, length); FileTestHelper.uploadNewFile(sasShare, FileTestHelper.getRandomDataStream(0), length, null); fail(); FileTestHelper.uploadNewFile(share, FileTestHelper.getRandomDataStream(0), length, null);
String data = "String data"; final CloudFileShare share = FileTestHelper.getRandomShareReference(); try { share.create(); final CloudFile source = share.getRootDirectoryReference().getFileReference("source"); FileTestHelper.setFileProperties(source); FileTestHelper.defiddler(new CloudFile(credentials.transformUri(source.getUri())))); BlobTestHelper.waitForCopy(destination); destination.downloadAttributes();
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; }
/** * Tests doing a listShares to ensure maxResults validation is working. * * @throws StorageException * @throws URISyntaxException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testListSharesMaxResultsValidationTest() throws StorageException, URISyntaxException { CloudFileClient fileClient = FileTestHelper.createCloudFileClient(); String prefix = UUID.randomUUID().toString(); // Validation should cause each of these to fail for (int i = 0; i >= -2; i--) { try{ fileClient.listSharesSegmented( prefix, EnumSet.allOf(ShareListingDetails.class), i, null, null, null); fail(); } catch (IllegalArgumentException e) { assertTrue(String.format(SR.PARAMETER_SHOULD_BE_GREATER_OR_EQUAL, "maxResults", 1) .equals(e.getMessage())); } } assertNotNull(fileClient.listSharesSegmented("thereshouldntbeanyshareswiththisprefix")); }
CloudFile file1 = dir1.getFileReference("file1"); file1.create(1024); ByteArrayInputStream srcStream = FileTestHelper.getRandomDataStream(1024); file1.upload(srcStream, 1024); CloudFileClient client = FileTestHelper.createCloudFileClient(); CloudFileShare snapshotRef = client.getShareReference(snapshot.name, snapshot.snapshotID); assertTrue(snapshotRef.exists());
@Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudFileDeleteIfExistsErrorCode() throws URISyntaxException, StorageException, IOException { CloudFileClient client = FileTestHelper.createCloudFileClient(); CloudFileShare share = client.getShareReference(FileTestHelper.generateRandomShareName()); share.create(); CloudFileDirectory directory = share.getRootDirectoryReference().getDirectoryReference("directory");
public static void assertAreEqual(CloudFile file1, CloudFile file2) { if (file1 == null) { Assert.assertNull(file2); } else { Assert.assertNotNull(file2); Assert.assertEquals(file1.getUri(), file2.getUri()); assertAreEqual(file1.getProperties(), file2.getProperties()); } }
/** * 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())); }
@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); }
public static CloudFile defiddler(CloudFile file) throws URISyntaxException, StorageException { URI oldUri = file.getUri(); URI newUri = defiddler(oldUri); if (newUri != oldUri) { CloudFile newFile = new CloudFile(newUri, file.getServiceClient().getCredentials()); return newFile; } else { return file; } }
public void testCloudFileOpenOutputStream() throws URISyntaxException, StorageException, IOException { int fileLengthToUse = 8 * 512; byte[] buffer = FileTestHelper.getRandomBuffer(8 * 512); String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); fileRef.create(fileLengthToUse);
/** * Create a file and try to download a range of its contents * * @throws StorageException * @throws URISyntaxException * @throws IOException * @throws InterruptedException */ @Test public void testFileDownloadRangeValidationTest() throws StorageException, URISyntaxException, IOException { final int length = 5 * 1024 * 1024; final String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); fileRef.upload(FileTestHelper.getRandomDataStream(length), length); //Download full file fileRef.download(new ByteArrayOutputStream()); assertEquals(length, fileRef.getProperties().getLength()); //Download file range. byte[] downloadBuffer = new byte[100]; int downloadLength = fileRef.downloadRangeToByteArray(0, (long) 100, downloadBuffer, 0); assertEquals(length, fileRef.getProperties().getLength()); assertEquals(100, downloadLength); }