use of com.amplifyframework.testutils.random.RandomTempFile in project amplify-android by aws-amplify.
the class AWSS3StorageListAccessLevelTest method uploadTestFiles.
private static void uploadTestFiles() throws Exception {
// Create a temporary file to upload
File uploadFile = new RandomTempFile(UPLOAD_SIZE);
String uploadName = uploadFile.getName();
String uploadPath = uploadFile.getAbsolutePath();
uploadKey = TEST_DIR_NAME + "/" + uploadName;
StorageUploadFileOptions options;
// Upload as GUEST
mobileClient.signOut();
options = StorageUploadFileOptions.builder().accessLevel(StorageAccessLevel.PUBLIC).build();
storage.uploadFile(uploadKey, uploadFile, options);
// Upload as user one
mobileClient.signOut();
mobileClient.signIn(userOne.getUsername(), userOne.getPassword());
options = StorageUploadFileOptions.builder().accessLevel(StorageAccessLevel.PROTECTED).build();
storage.uploadFile(uploadKey, uploadFile, options);
options = StorageUploadFileOptions.builder().accessLevel(StorageAccessLevel.PRIVATE).build();
storage.uploadFile(uploadKey, uploadFile, options);
// Upload as user two
mobileClient.signOut();
mobileClient.signIn(userTwo.getUsername(), userTwo.getPassword());
options = StorageUploadFileOptions.builder().accessLevel(StorageAccessLevel.PROTECTED).build();
storage.uploadFile(uploadKey, uploadFile, options);
options = StorageUploadFileOptions.builder().accessLevel(StorageAccessLevel.PRIVATE).build();
storage.uploadFile(uploadKey, uploadFile, options);
}
use of com.amplifyframework.testutils.random.RandomTempFile in project amplify-android by aws-amplify.
the class AWSS3StorageUploadTest method testUploadSmallFile.
/**
* Tests that small file (single-part) uploads successfully.
*
* @throws Exception if upload fails
*/
@Ignore("Contains test which either hang themselves, or hang the suite overall.")
public void testUploadSmallFile() throws Exception {
File uploadFile = new RandomTempFile(SMALL_FILE_SIZE);
String fileName = uploadFile.getName();
synchronousStorage.uploadFile(fileName, uploadFile, options);
}
use of com.amplifyframework.testutils.random.RandomTempFile in project amplify-android by aws-amplify.
the class AWSS3StorageUploadTest method testUploadLargeFile.
/**
* Tests that large file (multi-part) uploads successfully.
*
* @throws Exception if upload fails
*/
@Ignore("Contains test which either hang themselves, or hang the suite overall.")
public void testUploadLargeFile() throws Exception {
File uploadFile = new RandomTempFile(LARGE_FILE_SIZE);
String fileName = uploadFile.getName();
synchronousStorage.uploadFile(fileName, uploadFile, options, EXTENDED_TIMEOUT_MS);
}
use of com.amplifyframework.testutils.random.RandomTempFile in project amplify-android by aws-amplify.
the class StorageComponentTest method testUploadFileGetsKey.
/**
* Test that calling upload file method from Storage category correctly
* invokes the registered AWSS3StoragePlugin instance and returns a
* {@link StorageUploadFileResult} with correct remote key.
*
* @throws Exception when an error is encountered while uploading
*/
@Test
public void testUploadFileGetsKey() throws Exception {
final String toRemoteKey = RandomString.string();
final File fromLocalFile = new RandomTempFile(FILE_SIZE);
TransferObserver observer = mock(TransferObserver.class);
when(storageService.uploadFile(anyString(), any(File.class), any(ObjectMetadata.class))).thenReturn(observer);
doAnswer(invocation -> {
TransferListener listener = invocation.getArgument(0);
listener.onStateChanged(0, TransferState.COMPLETED);
return null;
}).when(observer).setTransferListener(any(TransferListener.class));
StorageUploadFileResult result = Await.<StorageUploadFileResult, StorageException>result((onResult, onError) -> storage.uploadFile(toRemoteKey, fromLocalFile, onResult, onError));
assertEquals(toRemoteKey, result.getKey());
}
use of com.amplifyframework.testutils.random.RandomTempFile in project amplify-android by aws-amplify.
the class AWSS3StorageDownloadAccessLevelTest method setUp.
/**
* Signs out by default and sets up download file destination.
*
* @throws Exception if an error is encountered while creating file
*/
@Before
public void setUp() throws Exception {
// Start as a GUEST user
mobileClient.signOut();
// Create a new download destination
downloadFile = new RandomTempFile();
// Override this per test-case
downloadOptions = StorageDownloadFileOptions.defaultInstance();
}
Aggregations