Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(storage): add integration tests for multi-bucket support #2900

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.amplifyframework.storage.StorageCategory;
import com.amplifyframework.storage.StorageException;
import com.amplifyframework.storage.options.StorageDownloadFileOptions;
import com.amplifyframework.storage.options.StorageRemoveOptions;
import com.amplifyframework.storage.options.StorageUploadFileOptions;
import com.amplifyframework.storage.s3.UserCredentials.Credential;
import com.amplifyframework.storage.s3.UserCredentials.IdentityIdSource;
Expand All @@ -33,6 +34,7 @@
import com.amplifyframework.testutils.sync.SynchronousAuth;
import com.amplifyframework.testutils.sync.SynchronousStorage;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -85,6 +87,15 @@ public static void setUpOnce() throws Exception {
uploadTestFile();
}

/**
* Clean up test resources from test suite.
* @throws Exception from failure to remove test resources.
*/
@AfterClass
public static void tearDownOnce() throws Exception {
removeUploadedTestFiles();
}

/**
* Signs out by default and sets up download file destination.
*
Expand Down Expand Up @@ -263,4 +274,39 @@ private static void uploadTestFile() throws Exception {
.build();
storage.uploadFile(key, uploadFile, options);
}

private static void removeUploadedTestFiles() throws Exception {
final String key = UPLOAD_NAME;

synchronousAuth.signOut();
synchronousAuth.signIn(userOne.getUsername(), userOne.getPassword());

StorageRemoveOptions options;
options = StorageRemoveOptions.builder()
.accessLevel(StorageAccessLevel.PUBLIC)
.build();
storage.remove(key, options);

options = StorageRemoveOptions.builder()
.accessLevel(StorageAccessLevel.PROTECTED)
.build();
storage.remove(key, options);

options = StorageRemoveOptions.builder()
.accessLevel(StorageAccessLevel.PRIVATE)
.build();
storage.remove(key, options);

// Upload as user two
synchronousAuth.signOut();
synchronousAuth.signIn(userTwo.getUsername(), userTwo.getPassword());
options = StorageRemoveOptions.builder()
.accessLevel(StorageAccessLevel.PROTECTED)
.build();
storage.remove(key, options);
options = StorageRemoveOptions.builder()
.accessLevel(StorageAccessLevel.PRIVATE)
.build();
storage.remove(key, options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import android.content.Context;

import com.amplifyframework.auth.AuthPlugin;
import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin;
import com.amplifyframework.core.Amplify;
import com.amplifyframework.core.async.Cancelable;
Expand All @@ -31,6 +30,7 @@
import com.amplifyframework.storage.TransferState;
import com.amplifyframework.storage.operation.StorageDownloadFileOperation;
import com.amplifyframework.storage.options.StorageDownloadFileOptions;
import com.amplifyframework.storage.options.StorageRemoveOptions;
import com.amplifyframework.storage.options.StorageUploadFileOptions;
import com.amplifyframework.storage.s3.options.AWSS3StorageDownloadFileOptions;
import com.amplifyframework.storage.s3.test.R;
Expand All @@ -41,6 +41,7 @@
import com.amplifyframework.testutils.sync.SynchronousStorage;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -89,7 +90,7 @@ public final class AWSS3StorageDownloadTest {
public static void setUpOnce() throws Exception {
Context context = getApplicationContext();
WorkmanagerTestUtils.INSTANCE.initializeWorkmanagerTestUtil(context);
SynchronousAuth.delegatingToCognito(context, (AuthPlugin) new AWSCognitoAuthPlugin());
SynchronousAuth.delegatingToCognito(context, new AWSCognitoAuthPlugin());

// Get a handle to storage
storageCategory = TestStorageCategory.create(context, R.raw.amplifyconfiguration);
Expand All @@ -112,6 +113,21 @@ public static void setUpOnce() throws Exception {
synchronousStorage.uploadFile(key, smallFile, uploadOptions);
}

/**
* Clean up test resources from test suite.
* @throws Exception from failure to remove test resources.
*/
@AfterClass
public static void tearDownOnce() throws Exception {
StorageRemoveOptions options = StorageRemoveOptions
.builder()
.accessLevel(TESTING_ACCESS_LEVEL)
.build();

synchronousStorage.remove(SMALL_FILE_NAME, options);
synchronousStorage.remove(LARGE_FILE_NAME, options);
}

/**
* Sets up the options to use for transfer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.content.Context;

import com.amplifyframework.auth.AuthException;
import com.amplifyframework.auth.AuthPlugin;
import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin;
import com.amplifyframework.storage.StorageAccessLevel;
Expand All @@ -25,6 +26,7 @@
import com.amplifyframework.storage.StorageItem;
import com.amplifyframework.storage.options.StorageListOptions;
import com.amplifyframework.storage.options.StoragePagedListOptions;
import com.amplifyframework.storage.options.StorageRemoveOptions;
import com.amplifyframework.storage.options.StorageUploadFileOptions;
import com.amplifyframework.storage.result.StorageListResult;
import com.amplifyframework.storage.s3.UserCredentials.IdentityIdSource;
Expand All @@ -35,6 +37,7 @@
import com.amplifyframework.testutils.sync.SynchronousAuth;
import com.amplifyframework.testutils.sync.SynchronousStorage;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -91,6 +94,16 @@ public static void setUpOnce() throws Exception {
uploadTestFiles();
}

/**
* Remove upload test files from test suite.
*
* @throws Exception from failure to remove test resources.
*/
@AfterClass
public static void tearDownOnce() throws Exception {
removeUploadedTestFiles();
}

/**
* Signs out by default.
*
Expand Down Expand Up @@ -326,4 +339,44 @@ private static void uploadMultipleTestFiles() throws Exception {
// Upload as user one
synchronousAuth.signOut();
}

private static void removeUploadedTestFiles() throws AuthException, StorageException {
// remove PUBLIC test files
synchronousAuth.signOut();
synchronousAuth.signIn(userOne.getUsername(), userOne.getPassword());
StorageRemoveOptions options = StorageRemoveOptions.builder()
.accessLevel(StorageAccessLevel.PUBLIC)
.build();
for (int i = 0; i < 10; i++) {
storage.remove(pagedUploadKeyPrefix + i, options);
}
storage.remove(uploadKey, options);

// remove PROTECTED test files
options = StorageRemoveOptions.builder()
.accessLevel(StorageAccessLevel.PROTECTED)
.build();
storage.remove(uploadKey, options);

// remove PRIVATE test files
options = StorageRemoveOptions.builder()
.accessLevel(StorageAccessLevel.PRIVATE)
.build();
storage.remove(uploadKey, options);

synchronousAuth.signOut();
synchronousAuth.signIn(userTwo.getUsername(), userTwo.getPassword());
options = StorageRemoveOptions.builder()
.accessLevel(StorageAccessLevel.PROTECTED)
.build();
storage.remove(uploadKey, options);

// remove PRIVATE test files
options = StorageRemoveOptions.builder()
.accessLevel(StorageAccessLevel.PRIVATE)
.build();
storage.remove(uploadKey, options);

synchronousAuth.signOut();
}
}
Loading