use of com.amplifyframework.storage.result.StorageTransferProgress in project amplify-android by aws-amplify.
the class RxStorageBindingTest method uploadFileReturnsResult.
/**
* When {@link StorageCategoryBehavior#uploadFile(String, File, Consumer, Consumer)} returns
* a {@link StorageUploadFileResult}, then the {@link Single} returned by
* {@link RxStorageCategoryBehavior#uploadFile(String, File)} should emit that result.
* @throws InterruptedException Not expected.
*/
@Test
public void uploadFileReturnsResult() throws InterruptedException {
StorageUploadFileResult result = StorageUploadFileResult.fromKey(remoteKey);
doAnswer(invocation -> {
// 0 key, 1 local, 2 options, 3 onProgress, 4 onResult, 5 onError
final int indexOfResultConsumer = 4;
final int indexOfProgressConsumer = 3;
Consumer<StorageUploadFileResult> resultConsumer = invocation.getArgument(indexOfResultConsumer);
Consumer<StorageTransferProgress> progressConsumer = invocation.getArgument(indexOfProgressConsumer);
Observable.interval(100, 100, TimeUnit.MILLISECONDS).take(5).doOnNext(aLong -> progressConsumer.accept(new StorageTransferProgress(aLong, 500))).doOnComplete(() -> resultConsumer.accept(result)).subscribe();
return mock(StorageUploadFileOperation.class);
}).when(delegate).uploadFile(eq(remoteKey), eq(localFile), any(StorageUploadFileOptions.class), anyConsumer(), anyConsumer(), anyConsumer());
RxStorageBinding.RxProgressAwareSingleOperation<StorageUploadFileResult> rxOperation = rxStorage.uploadFile(remoteKey, localFile);
TestObserver<StorageUploadFileResult> testObserver = rxOperation.observeResult().test();
TestObserver<StorageTransferProgress> testProgressObserver = rxOperation.observeProgress().test();
testObserver.await(TIMEOUT_MS, TimeUnit.MILLISECONDS);
testObserver.assertValues(result);
testProgressObserver.awaitCount(5);
testProgressObserver.assertValueCount(5);
}
use of com.amplifyframework.storage.result.StorageTransferProgress in project amplify-android by aws-amplify.
the class RxStorageBindingTest method uploadInputStreamReturnsResult.
/**
* When {@link StorageCategoryBehavior#uploadInputStream(String, InputStream, Consumer, Consumer)} returns
* a {@link StorageUploadInputStreamResult}, then the {@link Single} returned by
* {@link RxStorageCategoryBehavior#uploadInputStream(String, InputStream)} should emit that result.
* @throws InterruptedException Not expected.
*/
@Test
public void uploadInputStreamReturnsResult() throws InterruptedException {
StorageUploadInputStreamResult result = StorageUploadInputStreamResult.fromKey(remoteKey);
doAnswer(invocation -> {
// 0 key, 1 local, 2 options, 3 onProgress, 4 onResult, 5 onError
final int indexOfResultConsumer = 4;
final int indexOfProgressConsumer = 3;
Consumer<StorageUploadInputStreamResult> resultConsumer = invocation.getArgument(indexOfResultConsumer);
Consumer<StorageTransferProgress> progressConsumer = invocation.getArgument(indexOfProgressConsumer);
Observable.interval(100, 100, TimeUnit.MILLISECONDS).take(5).doOnNext(aLong -> progressConsumer.accept(new StorageTransferProgress(aLong, 500))).doOnComplete(() -> resultConsumer.accept(result)).subscribe();
return mock(StorageUploadInputStreamOperation.class);
}).when(delegate).uploadInputStream(eq(remoteKey), eq(localInputStream), any(StorageUploadInputStreamOptions.class), anyConsumer(), anyConsumer(), anyConsumer());
RxStorageBinding.RxProgressAwareSingleOperation<StorageUploadInputStreamResult> rxOperation = rxStorage.uploadInputStream(remoteKey, localInputStream);
TestObserver<StorageUploadInputStreamResult> testObserver = rxOperation.observeResult().test();
TestObserver<StorageTransferProgress> testProgressObserver = rxOperation.observeProgress().test();
testObserver.await(TIMEOUT_MS, TimeUnit.MILLISECONDS);
testObserver.assertValues(result);
testProgressObserver.awaitCount(5);
testProgressObserver.assertValueCount(5);
}
use of com.amplifyframework.storage.result.StorageTransferProgress in project amplify-android by aws-amplify.
the class RxStorageBindingTest method downloadFileReturnsResult.
/**
* When {@link StorageCategoryBehavior#downloadFile(String, File, StorageDownloadFileOptions,
* Consumer, Consumer, Consumer)} invokes its success callback, the {@link StorageDownloadFileResult}
* should propagate via the {@link Single} returned by
* {@link RxStorageBinding.RxProgressAwareSingleOperation#observeResult()}.
* @throws InterruptedException not expected.
*/
@Test
public void downloadFileReturnsResult() throws InterruptedException {
StorageDownloadFileResult result = StorageDownloadFileResult.fromFile(mock(File.class));
doAnswer(invocation -> {
// 0 key, 1 local, 2 options, 3 onProgress 4 onResult, 5 onError
final int indexOfProgressConsumer = 3;
final int indexOfResultConsumer = 4;
Consumer<StorageTransferProgress> progressConsumer = invocation.getArgument(indexOfProgressConsumer);
Consumer<StorageDownloadFileResult> resultConsumer = invocation.getArgument(indexOfResultConsumer);
Observable.interval(100, 100, TimeUnit.MILLISECONDS).take(5).doOnNext(aLong -> progressConsumer.accept(new StorageTransferProgress(aLong, 500))).doOnComplete(() -> resultConsumer.accept(result)).subscribe();
return mock(StorageDownloadFileOperation.class);
}).when(delegate).downloadFile(eq(remoteKey), eq(localFile), any(StorageDownloadFileOptions.class), anyConsumer(), anyConsumer(), anyConsumer());
RxStorageBinding.RxProgressAwareSingleOperation<StorageDownloadFileResult> rxOperation = rxStorage.downloadFile(remoteKey, localFile, StorageDownloadFileOptions.defaultInstance());
TestObserver<StorageDownloadFileResult> testObserver = rxOperation.observeResult().test();
TestObserver<StorageTransferProgress> testProgressObserver = rxOperation.observeProgress().test();
testObserver.await(TIMEOUT_MS, TimeUnit.MILLISECONDS);
testObserver.assertValues(result);
testProgressObserver.awaitCount(5);
testProgressObserver.assertValueCount(5);
}
Aggregations