ACL examples by jerjou · Pull Request #1399 · googleapis/google-cloud-java · GitHub
Skip to content
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 @@ -27,6 +27,7 @@

import com.google.cloud.Page;
import com.google.cloud.storage.Acl;
import com.google.cloud.storage.Acl.Role;
import com.google.cloud.storage.Acl.User;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class ITStorageSnippets {

private static final Logger log = Logger.getLogger(ITStorageSnippets.class.getName());
private static final String BUCKET = RemoteStorageHelper.generateBucketName();
private static final String USER_EMAIL = "google-cloud-java-tests@"
+ "java-docs-samples-tests.iam.gserviceaccount.com";

private static Storage storage;
private static StorageSnippets storageSnippets;
Expand Down Expand Up @@ -290,6 +293,14 @@ public void testBucketAcl() {
assertEquals(Acl.Role.OWNER, updatedAcl.getRole());
Set<Acl> acls = Sets.newHashSet(storageSnippets.listBucketAcls(BUCKET));
assertTrue(acls.contains(updatedAcl));

assertNotNull(storageSnippets.getBucketAcl(BUCKET));
assertNull(storageSnippets.getBucketAcl(BUCKET, USER_EMAIL));
storage.createAcl(BUCKET, Acl.of(new User(USER_EMAIL), Role.READER));
Acl userAcl = storageSnippets.getBucketAcl(BUCKET, USER_EMAIL);
assertNotNull(userAcl);
assertEquals(USER_EMAIL, ((User)userAcl.getEntity()).getEmail());

assertTrue(storageSnippets.deleteBucketAcl(BUCKET));
assertNull(storageSnippets.getBucketAcl(BUCKET));
}
Expand Down Expand Up @@ -321,13 +332,20 @@ public void testBlobAcl() {
storageSnippets.listBlobAcls(BUCKET, blobName, createdBlob.getGeneration()));
assertTrue(acls.contains(updatedAcl));

assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, USER_EMAIL));
storage.createAcl(BlobId.of(BUCKET, blobName), Acl.of(new User(USER_EMAIL), Role.READER));
Acl userAcl = storageSnippets.getBlobAcl(BUCKET, blobName, USER_EMAIL);
assertNotNull(userAcl);
assertEquals(USER_EMAIL, ((User)userAcl.getEntity()).getEmail());

updatedAcl = storageSnippets.blobToPublicRead(BUCKET, blobName, createdBlob.getGeneration());
assertEquals(Acl.Role.READER, updatedAcl.getRole());
assertEquals(User.ofAllUsers(), updatedAcl.getEntity());
acls = Sets.newHashSet(
storageSnippets.listBlobAcls(BUCKET, blobName, createdBlob.getGeneration()));
assertTrue(acls.contains(updatedAcl));

assertNotNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
assertTrue(storageSnippets.deleteBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
// test non-existing blob
Expand Down