Search in sources :

Example 1 with StorageGetUrlOptions

use of com.amplifyframework.storage.options.StorageGetUrlOptions in project amplify-android by aws-amplify.

the class RxStorageBindingTest method getUrlEmitsFailure.

/**
 * When the delegate emits a failure from the
 * {@link StorageCategoryBehavior#getUrl(String, StorageGetUrlOptions, Consumer, Consumer)},
 * the binding should emit a failure to its single observer.
 */
@Test
public void getUrlEmitsFailure() {
    StorageException expectedException = new StorageException("oh", "boy!");
    doAnswer(invocation -> {
        int indexOfErrorConsumer = 3;
        Consumer<StorageException> onError = invocation.getArgument(indexOfErrorConsumer);
        onError.accept(expectedException);
        return mock(StorageGetUrlOperation.class);
    }).when(delegate).getUrl(eq(remoteKey), any(StorageGetUrlOptions.class), anyConsumer(), anyConsumer());
    rxStorage.getUrl(remoteKey, StorageGetUrlOptions.defaultInstance()).test().awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS).assertError(expectedException);
}
Also used : StorageGetUrlOptions(com.amplifyframework.storage.options.StorageGetUrlOptions) StorageException(com.amplifyframework.storage.StorageException) Test(org.junit.Test)

Example 2 with StorageGetUrlOptions

use of com.amplifyframework.storage.options.StorageGetUrlOptions in project amplify-android by aws-amplify.

the class RxStorageBindingTest method getUrlReturnsResult.

/**
 * When the delegate returns a result from the
 * {@link StorageCategoryBehavior#getUrl(String, StorageGetUrlOptions, Consumer, Consumer)},
 * the binding should emit the result via the single.
 * @throws MalformedURLException Not expected; it's part of the URL constructor signature, though
 */
@Test
public void getUrlReturnsResult() throws MalformedURLException {
    URL someRandomUrl = new URL("https://bogus.tld/foo");
    StorageGetUrlResult expectedResult = StorageGetUrlResult.fromUrl(someRandomUrl);
    doAnswer(invocation -> {
        int indexOfResultConsumer = 2;
        Consumer<StorageGetUrlResult> onResult = invocation.getArgument(indexOfResultConsumer);
        onResult.accept(expectedResult);
        return mock(StorageGetUrlOperation.class);
    }).when(delegate).getUrl(eq(remoteKey), any(StorageGetUrlOptions.class), anyConsumer(), anyConsumer());
    rxStorage.getUrl(remoteKey, StorageGetUrlOptions.defaultInstance()).test().awaitCount(1).assertNoErrors().assertValue(expectedResult);
}
Also used : StorageGetUrlOptions(com.amplifyframework.storage.options.StorageGetUrlOptions) URL(java.net.URL) StorageGetUrlResult(com.amplifyframework.storage.result.StorageGetUrlResult) Test(org.junit.Test)

Aggregations

StorageGetUrlOptions (com.amplifyframework.storage.options.StorageGetUrlOptions)2 Test (org.junit.Test)2 StorageException (com.amplifyframework.storage.StorageException)1 StorageGetUrlResult (com.amplifyframework.storage.result.StorageGetUrlResult)1 URL (java.net.URL)1