use of com.amplifyframework.storage.result.StorageGetUrlResult 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);
}
use of com.amplifyframework.storage.result.StorageGetUrlResult in project amplify-android by aws-amplify.
the class StorageComponentTest method testGenerateUrlGetsPresignedUrl.
/**
* Test that calling get URL method from Storage category correctly invokes
* the registered AWSS3StoragePlugin instance and returns a {@link URL}
* instance for that download.
*
* @throws StorageException when an error is encountered while generating
* URL from storage service
*/
@Test
public void testGenerateUrlGetsPresignedUrl() throws StorageException {
final String fromRemoteKey = RandomString.string();
final URL urlFromRemoteKey;
try {
// URL instance cannot be mocked so just make one
// https://{random-host}:0/{fromRemoteKey}
urlFromRemoteKey = new URL("https", RandomString.string(), 0, fromRemoteKey, null);
} catch (MalformedURLException exception) {
throw new RuntimeException(exception);
}
// Allow mock StorageService instance to return a non-null
// URL instance.
when(storageService.getPresignedUrl(anyString(), anyInt())).thenReturn(urlFromRemoteKey);
// Let Storage category invoke getUrl on mock Storage Service.
StorageGetUrlResult result = Await.<StorageGetUrlResult, StorageException>result((onResult, onError) -> storage.getUrl(fromRemoteKey, onResult, onError));
assertEquals(urlFromRemoteKey, result.getUrl());
}
Aggregations