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();
}
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;
}
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();
}
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);
}
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());
}
Aggregations