RemoteStorageHelper
contains convenience methods to make setting up and cleaning up the test buckets easier. To use this class:
-
Create a test Google Cloud project.
-
Download a JSON service account credentials file from the Google Developer's Console. See more about this on the [Google Cloud Platform Storage Authentication page][cloud-platform-storage-authentication].
-
Create a
RemoteStorageHelper
object using your project ID and JSON key. Here is an example that uses theRemoteStorageHelper
to create a bucket.RemoteStorageHelper helper = RemoteStorageHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json")); Storage storage = helper.getOptions().getService(); String bucket = RemoteStorageHelper.generateBucketName(); storage.create(BucketInfo.of(bucket));
-
Run your tests.
-
Clean up the test project by using
forceDelete
to clear any buckets used. Here is an example that clears the bucket created in Step 3 with a timeout of 5 seconds.RemoteStorageHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);