Search in sources :

Example 1 with StorageCategory

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

the class AWSS3StorageListAccessLevelTest method setUpOnce.

/**
 * Upload the required resources in cloud prior to running the tests.
 * @throws Exception from failure to sign in with Cognito User Pools
 */
@BeforeClass
public static void setUpOnce() throws Exception {
    Context context = getApplicationContext();
    // Init auth stuff
    mobileClient = SynchronousMobileClient.instance();
    mobileClient.initialize();
    IdentityIdSource identityIdSource = MobileClientIdentityIdSource.create(mobileClient);
    UserCredentials credentials = UserCredentials.create(context, identityIdSource);
    Iterator<Credential> users = credentials.iterator();
    userOne = users.next();
    userTwo = users.next();
    // Get a handle to storage
    StorageCategory asyncDelegate = TestStorageCategory.create(context, R.raw.amplifyconfiguration);
    storage = SynchronousStorage.delegatingTo(asyncDelegate);
    // Upload test file in S3 ahead of time
    uploadTestFiles();
}
Also used : Context(android.content.Context) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) Credential(com.amplifyframework.storage.s3.UserCredentials.Credential) IdentityIdSource(com.amplifyframework.storage.s3.UserCredentials.IdentityIdSource) StorageCategory(com.amplifyframework.storage.StorageCategory) BeforeClass(org.junit.BeforeClass)

Example 2 with StorageCategory

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

the class TestStorageCategory method create.

/**
 * Creates an instance of {@link StorageCategory} using the provided configuration resource.
 * @param context Android Context
 * @param resourceId Android resource ID for a configuration file
 * @return A StorageCategory instance using the provided configuration
 */
static StorageCategory create(@NonNull Context context, @RawRes int resourceId) {
    Objects.requireNonNull(context);
    final StorageCategory storageCategory = new StorageCategory();
    try {
        storageCategory.addPlugin(new AWSS3StoragePlugin(new TestCognitoAuthProvider()));
        CategoryConfiguration storageConfiguration = AmplifyConfiguration.fromConfigFile(context, resourceId).forCategoryType(CategoryType.STORAGE);
        storageCategory.configure(storageConfiguration, context);
    // storageCategory.initialize(context); // Doesn't do anything right now.
    } catch (AmplifyException initializationFailure) {
        throw new RuntimeException(initializationFailure);
    }
    return storageCategory;
}
Also used : AmplifyException(com.amplifyframework.AmplifyException) StorageCategory(com.amplifyframework.storage.StorageCategory) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration)

Example 3 with StorageCategory

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

the class AWSS3StorageDownloadAccessLevelTest method setUpOnce.

/**
 * Upload the required resources in cloud prior to running the tests.
 * @throws Exception from failure to sign in with Cognito User Pools
 */
@BeforeClass
public static void setUpOnce() throws Exception {
    Context context = getApplicationContext();
    mobileClient = SynchronousMobileClient.instance();
    mobileClient.initialize();
    IdentityIdSource identityIdSource = MobileClientIdentityIdSource.create(mobileClient);
    UserCredentials userCredentials = UserCredentials.create(context, identityIdSource);
    Iterator<Credential> users = userCredentials.iterator();
    userOne = users.next();
    userTwo = users.next();
    StorageCategory asyncDelegate = TestStorageCategory.create(context, R.raw.amplifyconfiguration);
    storage = SynchronousStorage.delegatingTo(asyncDelegate);
    // Upload test file in S3 ahead of time
    uploadTestFile();
}
Also used : Context(android.content.Context) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) Credential(com.amplifyframework.storage.s3.UserCredentials.Credential) IdentityIdSource(com.amplifyframework.storage.s3.UserCredentials.IdentityIdSource) StorageCategory(com.amplifyframework.storage.StorageCategory) BeforeClass(org.junit.BeforeClass)

Example 4 with StorageCategory

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

the class AWSS3StorageUploadAccessLevelTest method setUpOnce.

/**
 * Obtain the user IDs prior to running the tests.
 * @throws MobileClientException On failure to initialize mobile client
 */
@BeforeClass
public static void setUpOnce() throws MobileClientException {
    Context context = getApplicationContext();
    // Initialize identity. Bundle username, password, Identity Id up into a UserCredentials.
    mobileClient = SynchronousMobileClient.instance();
    mobileClient.initialize();
    IdentityIdSource identityIdSource = MobileClientIdentityIdSource.create(mobileClient);
    UserCredentials userCredentials = UserCredentials.create(context, identityIdSource);
    Iterator<Credential> iterator = userCredentials.iterator();
    userOne = iterator.next();
    userTwo = iterator.next();
    // Setup storage.
    StorageCategory asyncDelegate = TestStorageCategory.create(context, R.raw.amplifyconfiguration);
    storage = SynchronousStorage.delegatingTo(asyncDelegate);
}
Also used : Context(android.content.Context) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) Credential(com.amplifyframework.storage.s3.UserCredentials.Credential) IdentityIdSource(com.amplifyframework.storage.s3.UserCredentials.IdentityIdSource) StorageCategory(com.amplifyframework.storage.StorageCategory) BeforeClass(org.junit.BeforeClass)

Example 5 with StorageCategory

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

the class StorageComponentTest method setup.

/**
 * Sets up Storage category by registering a mock AWSS3StoragePlugin
 * instance to Amplify and configuring.
 *
 * @throws AmplifyException if Amplify fails to configure with mock
 *                          Storage category configuration.
 */
@Before
public void setup() throws AmplifyException {
    this.storage = new StorageCategory();
    this.storageService = mock(StorageService.class);
    StorageService.Factory storageServiceFactory = (context, region, bucket) -> storageService;
    CognitoAuthProvider cognitoAuthProvider = mock(CognitoAuthProvider.class);
    doReturn(RandomString.string()).when(cognitoAuthProvider).getIdentityId();
    this.storage.addPlugin(new AWSS3StoragePlugin(storageServiceFactory, cognitoAuthProvider, new AWSS3StoragePluginConfiguration.Builder().build()));
    this.storage.configure(buildConfiguration(), getApplicationContext());
    this.storage.initialize(getApplicationContext());
}
Also used : TransferState(com.amazonaws.mobileconnectors.s3.transferutility.TransferState) AmplifyException(com.amplifyframework.AmplifyException) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) StorageCategory(com.amplifyframework.storage.StorageCategory) StorageDownloadFileResult(com.amplifyframework.storage.result.StorageDownloadFileResult) StorageListResult(com.amplifyframework.storage.result.StorageListResult) URL(java.net.URL) Date(java.util.Date) RunWith(org.junit.runner.RunWith) RandomBytes(com.amplifyframework.testutils.random.RandomBytes) StorageUploadInputStreamResult(com.amplifyframework.storage.result.StorageUploadInputStreamResult) TransferListener(com.amazonaws.mobileconnectors.s3.transferutility.TransferListener) StorageItem(com.amplifyframework.storage.StorageItem) StorageException(com.amplifyframework.storage.StorageException) JSONException(org.json.JSONException) StorageUploadFileResult(com.amplifyframework.storage.result.StorageUploadFileResult) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Mockito.doAnswer(org.mockito.Mockito.doAnswer) StorageService(com.amplifyframework.storage.s3.service.StorageService) AWSS3StoragePluginConfiguration(com.amplifyframework.storage.s3.configuration.AWSS3StoragePluginConfiguration) TransferObserver(com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver) Mockito.anyString(org.mockito.Mockito.anyString) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) MalformedURLException(java.net.MalformedURLException) StorageRemoveResult(com.amplifyframework.storage.result.StorageRemoveResult) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) File(java.io.File) StorageCategoryConfiguration(com.amplifyframework.storage.StorageCategoryConfiguration) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) Await(com.amplifyframework.testutils.Await) RandomString(com.amplifyframework.testutils.random.RandomString) StorageGetUrlResult(com.amplifyframework.storage.result.StorageGetUrlResult) Mockito.anyInt(org.mockito.Mockito.anyInt) Mockito.any(org.mockito.Mockito.any) RandomTempFile(com.amplifyframework.testutils.random.RandomTempFile) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Mockito.mock(org.mockito.Mockito.mock) StorageCategory(com.amplifyframework.storage.StorageCategory) AWSS3StoragePluginConfiguration(com.amplifyframework.storage.s3.configuration.AWSS3StoragePluginConfiguration) StorageService(com.amplifyframework.storage.s3.service.StorageService) Before(org.junit.Before)

Aggregations

StorageCategory (com.amplifyframework.storage.StorageCategory)6 Context (android.content.Context)4 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)4 Credential (com.amplifyframework.storage.s3.UserCredentials.Credential)3 IdentityIdSource (com.amplifyframework.storage.s3.UserCredentials.IdentityIdSource)3 BeforeClass (org.junit.BeforeClass)3 AmplifyException (com.amplifyframework.AmplifyException)2 StorageCategoryConfiguration (com.amplifyframework.storage.StorageCategoryConfiguration)2 Before (org.junit.Before)2 TransferListener (com.amazonaws.mobileconnectors.s3.transferutility.TransferListener)1 TransferObserver (com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver)1 TransferState (com.amazonaws.mobileconnectors.s3.transferutility.TransferState)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 CategoryConfiguration (com.amplifyframework.core.category.CategoryConfiguration)1 StorageException (com.amplifyframework.storage.StorageException)1 StorageItem (com.amplifyframework.storage.StorageItem)1 StoragePlugin (com.amplifyframework.storage.StoragePlugin)1 StorageDownloadFileResult (com.amplifyframework.storage.result.StorageDownloadFileResult)1 StorageGetUrlResult (com.amplifyframework.storage.result.StorageGetUrlResult)1 StorageListResult (com.amplifyframework.storage.result.StorageListResult)1