Search in sources :

Example 1 with StorageListResult

use of com.amplifyframework.storage.result.StorageListResult in project amplify-android by aws-amplify.

the class RxStorageBindingTest method listReturnsResult.

/**
 * When {@link StorageCategoryBehavior#list(String, Consumer, Consumer)} emits a result,
 * then the {@link Single} returned by {@link RxStorageCategoryBehavior#list(String)}
 * should emit an {@link StorageListResult}.
 */
@Test
public void listReturnsResult() {
    StorageListResult result = StorageListResult.fromItems(Collections.emptyList());
    doAnswer(invocation -> {
        // 0 localPath, 1 onResult, 2 onError
        final int indexOfResultConsumer = 1;
        Consumer<StorageListResult> resultConsumer = invocation.getArgument(indexOfResultConsumer);
        resultConsumer.accept(result);
        return mock(StorageListOperation.class);
    }).when(delegate).list(eq(remoteKey), anyConsumer(), anyConsumer());
    rxStorage.list(remoteKey).test().assertValues(result);
}
Also used : StorageListResult(com.amplifyframework.storage.result.StorageListResult) Test(org.junit.Test)

Example 2 with StorageListResult

use of com.amplifyframework.storage.result.StorageListResult in project amplify-android by aws-amplify.

the class AWSS3StorageListAccessLevelTest method testListUnauthenticatedProtectedAccess.

/**
 * Test listing files with protected access without signing in.
 *
 * A protected resource is READ-ONLY to guest users. List is
 * allowed even without authentication.
 *
 * @throws Exception if list is unsuccessful
 */
@Test
public void testListUnauthenticatedProtectedAccess() throws Exception {
    listOptions = StorageListOptions.builder().accessLevel(StorageAccessLevel.PROTECTED).targetIdentityId(userOne.getIdentityId()).build();
    StorageListResult result = storage.list(TEST_DIR_NAME, listOptions);
    assertListContainsUploadedFile(result);
}
Also used : StorageListResult(com.amplifyframework.storage.result.StorageListResult) Test(org.junit.Test)

Example 3 with StorageListResult

use of com.amplifyframework.storage.result.StorageListResult in project amplify-android by aws-amplify.

the class AWSS3StorageListAccessLevelTest method testListUnauthenticatedPrivateAccess.

/**
 * Test listing files with private access without signing in.
 *
 * A user cannot list any private access file without proper
 * authentication. Private resources are only accessible to owners.
 * This test will throw an exception.
 *
 * @throws Exception if list is unsuccessful
 */
@Test(expected = StorageException.class)
public void testListUnauthenticatedPrivateAccess() throws Exception {
    listOptions = StorageListOptions.builder().accessLevel(StorageAccessLevel.PRIVATE).targetIdentityId(userOne.getIdentityId()).build();
    StorageListResult result = storage.list(TEST_DIR_NAME, listOptions);
    assertListContainsUploadedFile(result);
}
Also used : StorageListResult(com.amplifyframework.storage.result.StorageListResult) Test(org.junit.Test)

Example 4 with StorageListResult

use of com.amplifyframework.storage.result.StorageListResult in project amplify-android by aws-amplify.

the class AWSS3StorageListAccessLevelTest method testListUnauthenticatedPublicAccess.

/**
 * Test listing files with public access without signing in.
 *
 * @throws Exception if list is unsuccessful
 */
@Test
public void testListUnauthenticatedPublicAccess() throws Exception {
    listOptions = StorageListOptions.builder().accessLevel(StorageAccessLevel.PUBLIC).build();
    StorageListResult result = storage.list(TEST_DIR_NAME, listOptions);
    assertListContainsUploadedFile(result);
}
Also used : StorageListResult(com.amplifyframework.storage.result.StorageListResult) Test(org.junit.Test)

Example 5 with StorageListResult

use of com.amplifyframework.storage.result.StorageListResult in project amplify-android by aws-amplify.

the class AWSS3StorageListAccessLevelTest method testListAuthenticatedProtectedAccess.

/**
 * Test listing files with protected access after signing in.
 *
 * @throws Exception if list is unsuccessful
 */
@Test
public void testListAuthenticatedProtectedAccess() throws Exception {
    mobileClient.signIn(userOne.getUsername(), userOne.getPassword());
    listOptions = StorageListOptions.builder().accessLevel(StorageAccessLevel.PROTECTED).targetIdentityId(userOne.getIdentityId()).build();
    StorageListResult result = storage.list(TEST_DIR_NAME, listOptions);
    assertListContainsUploadedFile(result);
}
Also used : StorageListResult(com.amplifyframework.storage.result.StorageListResult) Test(org.junit.Test)

Aggregations

StorageListResult (com.amplifyframework.storage.result.StorageListResult)9 Test (org.junit.Test)9 StorageException (com.amplifyframework.storage.StorageException)1 StorageItem (com.amplifyframework.storage.StorageItem)1 RandomString (com.amplifyframework.testutils.random.RandomString)1 Date (java.util.Date)1 Mockito.anyString (org.mockito.Mockito.anyString)1