Search in sources :

Example 1 with StorageTransferProgress

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);
}
Also used : StorageUploadFileResult(com.amplifyframework.storage.result.StorageUploadFileResult) StorageUploadFileOptions(com.amplifyframework.storage.options.StorageUploadFileOptions) StorageTransferProgress(com.amplifyframework.storage.result.StorageTransferProgress) Test(org.junit.Test)

Example 2 with StorageTransferProgress

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);
}
Also used : StorageUploadInputStreamResult(com.amplifyframework.storage.result.StorageUploadInputStreamResult) StorageUploadInputStreamOptions(com.amplifyframework.storage.options.StorageUploadInputStreamOptions) StorageTransferProgress(com.amplifyframework.storage.result.StorageTransferProgress) Test(org.junit.Test)

Example 3 with StorageTransferProgress

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);
}
Also used : StorageDownloadFileResult(com.amplifyframework.storage.result.StorageDownloadFileResult) StorageDownloadFileOptions(com.amplifyframework.storage.options.StorageDownloadFileOptions) File(java.io.File) StorageTransferProgress(com.amplifyframework.storage.result.StorageTransferProgress) Test(org.junit.Test)

Aggregations

StorageTransferProgress (com.amplifyframework.storage.result.StorageTransferProgress)3 Test (org.junit.Test)3 StorageDownloadFileOptions (com.amplifyframework.storage.options.StorageDownloadFileOptions)1 StorageUploadFileOptions (com.amplifyframework.storage.options.StorageUploadFileOptions)1 StorageUploadInputStreamOptions (com.amplifyframework.storage.options.StorageUploadInputStreamOptions)1 StorageDownloadFileResult (com.amplifyframework.storage.result.StorageDownloadFileResult)1 StorageUploadFileResult (com.amplifyframework.storage.result.StorageUploadFileResult)1 StorageUploadInputStreamResult (com.amplifyframework.storage.result.StorageUploadInputStreamResult)1 File (java.io.File)1