Search in sources :

Example 6 with StorageListResult

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

the class AWSS3StorageListAccessLevelTest method testListDifferentUsersProtectedAccess.

/**
 * Test listing files with protected access after signing in
 * as another user.
 *
 * A protected resource is READ-ONLY to all users. List is
 * allowed even if signed-in user does not own the resource.
 *
 * @throws Exception if list is unsuccessful
 */
@Test
public void testListDifferentUsersProtectedAccess() throws Exception {
    mobileClient.signIn(userOne.getUsername(), userOne.getPassword());
    listOptions = StorageListOptions.builder().accessLevel(StorageAccessLevel.PROTECTED).targetIdentityId(userTwo.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 7 with StorageListResult

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

the class AWSS3StorageListAccessLevelTest method testListAuthenticatedPrivateAccess.

/**
 * Test listing files with private access after signing in.
 *
 * @throws Exception if list is unsuccessful
 */
@Test
public void testListAuthenticatedPrivateAccess() throws Exception {
    mobileClient.signIn(userOne.getUsername(), userOne.getPassword());
    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 8 with StorageListResult

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

the class AWSS3StorageListAccessLevelTest method testListDifferentUsersPrivateAccess.

/**
 * Test listing files with private access after signing in
 * as another user.
 *
 * 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 testListDifferentUsersPrivateAccess() throws Exception {
    mobileClient.signIn(userOne.getUsername(), userTwo.getPassword());
    listOptions = StorageListOptions.builder().accessLevel(StorageAccessLevel.PRIVATE).targetIdentityId(userTwo.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 9 with StorageListResult

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

the class StorageComponentTest method testListObject.

/**
 * Test that calling list method from Storage category correctly
 * invokes the registered AWSS3StoragePlugin instance and returns a
 * {@link StorageListResult} with list of stored items.
 *
 * @throws StorageException when an error is encountered while listing
 *                          files inside storage
 */
@Test
public void testListObject() throws StorageException {
    final String path = RandomString.string();
    final StorageItem item = new StorageItem(RandomString.string(), 0L, new Date(), RandomString.string(), null);
    when(storageService.listFiles(anyString(), anyString())).thenReturn(Collections.singletonList(item));
    StorageListResult result = Await.<StorageListResult, StorageException>result((onResult, onError) -> storage.list(path, onResult, onError));
    assertEquals(item, result.getItems().get(0));
}
Also used : StorageListResult(com.amplifyframework.storage.result.StorageListResult) Mockito.anyString(org.mockito.Mockito.anyString) RandomString(com.amplifyframework.testutils.random.RandomString) StorageException(com.amplifyframework.storage.StorageException) Date(java.util.Date) StorageItem(com.amplifyframework.storage.StorageItem) 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