Skip to content

Commit

Permalink
Merge branch 'main' into mattcreaser/apollo-readme-update
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcreaser authored Sep 18, 2024
2 parents 212c8fe + 639ef96 commit b493020
Show file tree
Hide file tree
Showing 68 changed files with 3,086 additions and 535 deletions.
1,088 changes: 797 additions & 291 deletions apollo/apollo-appsync-amplify/src/androidTest/backend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apollo/apollo-appsync/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ plugins {

java {
withSourcesJar()
withJavadocJar()
}

kotlin {
Expand Down
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

0 comments on commit b493020

Please sign in to comment.