use of com.amplifyframework.storage.StorageException in project amplify-android by aws-amplify.
the class StorageComponentTest method testDownloadError.
/**
* Test that calling download file method from Storage category fails
* successfully when {@link TransferListener} emits an error.
*
* @throws IOException when the temporary file cannot be created
*/
@Test
public void testDownloadError() throws IOException {
final StorageException testError = new StorageException("Test error message", "Test recovery message");
final String fromRemoteKey = RandomString.string();
final File toLocalFile = new RandomTempFile();
TransferObserver observer = mock(TransferObserver.class);
when(storageService.downloadToFile(anyString(), any(File.class))).thenReturn(observer);
doAnswer(invocation -> {
TransferListener listener = invocation.getArgument(0);
listener.onError(0, testError);
return null;
}).when(observer).setTransferListener(any(TransferListener.class));
StorageException error = Await.<StorageDownloadFileResult, StorageException>error((onResult, onError) -> storage.downloadFile(fromRemoteKey, toLocalFile, onResult, onError));
assertEquals(testError, error.getCause());
}
use of com.amplifyframework.storage.StorageException in project amplify-android by aws-amplify.
the class RxStorageBindingTest method uploadInputStreamReturnsError.
/**
* When {@link StorageCategoryBehavior#uploadInputStream(String, InputStream, Consumer, Consumer)} returns
* an {@link StorageException}, then the {@link Single} returned by
* {@link RxStorageCategoryBehavior#uploadInputStream(String, InputStream)} should emit a {@link StorageException}.
*/
@Test
public void uploadInputStreamReturnsError() {
StorageException error = new StorageException("Error uploading.", "Expected.");
doAnswer(invocation -> {
// 0 key, 1 local, 2 options, 3 onProgress 4 onResult, 5 onError
final int indexOfResultConsumer = 5;
Consumer<StorageException> errorConsumer = invocation.getArgument(indexOfResultConsumer);
errorConsumer.accept(error);
return mock(StorageUploadInputStreamOperation.class);
}).when(delegate).uploadInputStream(eq(remoteKey), eq(localInputStream), any(StorageUploadInputStreamOptions.class), anyConsumer(), anyConsumer(), anyConsumer());
rxStorage.uploadInputStream(remoteKey, localInputStream).observeResult().test().assertError(error);
}
use of com.amplifyframework.storage.StorageException in project amplify-android by aws-amplify.
the class RxStorageBindingTest method listReturnsError.
/**
* When the {@link StorageCategoryBehavior#list(String, Consumer, Consumer)} emits an error,
* the {@link Single} returned by {@link RxStorageCategoryBehavior#list(String)} should emit an
* {@link StorageException}.
*/
@Test
public void listReturnsError() {
StorageException error = new StorageException("Error removing item.", "Expected.");
doAnswer(invocation -> {
// 0 localPath, 1 onResult, 2 onError
final int indexOfErrorConsumer = 2;
Consumer<StorageException> errorConsumer = invocation.getArgument(indexOfErrorConsumer);
errorConsumer.accept(error);
return mock(StorageListOperation.class);
}).when(delegate).list(eq(remoteKey), anyConsumer(), anyConsumer());
rxStorage.list(remoteKey).test().assertError(error);
}
use of com.amplifyframework.storage.StorageException in project amplify-android by aws-amplify.
the class RxStorageBindingTest method removeReturnsError.
/**
* When {@link StorageCategoryBehavior#remove(String, Consumer, Consumer)} calls its
* error consumer, then the {@link Single} returned by {@link RxStorageCategoryBehavior#remove(String)}
* should emit an error.
*/
@Test
public void removeReturnsError() {
StorageException error = new StorageException("Error removing item.", "Expected.");
doAnswer(invocation -> {
// 0 remoteKey, 1 onResult, 2 onError
final int indexOfErrorConsumer = 2;
Consumer<StorageException> errorConsumer = invocation.getArgument(indexOfErrorConsumer);
errorConsumer.accept(error);
return mock(StorageRemoveOperation.class);
}).when(delegate).remove(eq(remoteKey), anyConsumer(), anyConsumer());
rxStorage.remove(remoteKey).test().assertError(error);
}
Aggregations