|
27 | 27 |
|
28 | 28 | import com.google.cloud.Page; |
29 | 29 | import com.google.cloud.storage.Acl; |
| 30 | +import com.google.cloud.storage.Acl.Role; |
30 | 31 | import com.google.cloud.storage.Acl.User; |
31 | 32 | import com.google.cloud.storage.Blob; |
32 | 33 | import com.google.cloud.storage.BlobId; |
@@ -63,6 +64,8 @@ public class ITStorageSnippets { |
63 | 64 |
|
64 | 65 | private static final Logger log = Logger.getLogger(ITStorageSnippets.class.getName()); |
65 | 66 | private static final String BUCKET = RemoteStorageHelper.generateBucketName(); |
| 67 | + private static final String USER_EMAIL = "google-cloud-java-tests@" |
| 68 | + + "java-docs-samples-tests.iam.gserviceaccount.com"; |
66 | 69 |
|
67 | 70 | private static Storage storage; |
68 | 71 | private static StorageSnippets storageSnippets; |
@@ -290,6 +293,14 @@ public void testBucketAcl() { |
290 | 293 | assertEquals(Acl.Role.OWNER, updatedAcl.getRole()); |
291 | 294 | Set<Acl> acls = Sets.newHashSet(storageSnippets.listBucketAcls(BUCKET)); |
292 | 295 | assertTrue(acls.contains(updatedAcl)); |
| 296 | + |
| 297 | + assertNotNull(storageSnippets.getBucketAcl(BUCKET)); |
| 298 | + assertNull(storageSnippets.getBucketAcl(BUCKET, USER_EMAIL)); |
| 299 | + storage.createAcl(BUCKET, Acl.of(new User(USER_EMAIL), Role.READER)); |
| 300 | + Acl userAcl = storageSnippets.getBucketAcl(BUCKET, USER_EMAIL); |
| 301 | + assertNotNull(userAcl); |
| 302 | + assertEquals(USER_EMAIL, ((User)userAcl.getEntity()).getEmail()); |
| 303 | + |
293 | 304 | assertTrue(storageSnippets.deleteBucketAcl(BUCKET)); |
294 | 305 | assertNull(storageSnippets.getBucketAcl(BUCKET)); |
295 | 306 | } |
@@ -321,13 +332,20 @@ public void testBlobAcl() { |
321 | 332 | storageSnippets.listBlobAcls(BUCKET, blobName, createdBlob.getGeneration())); |
322 | 333 | assertTrue(acls.contains(updatedAcl)); |
323 | 334 |
|
| 335 | + assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, USER_EMAIL)); |
| 336 | + storage.createAcl(BlobId.of(BUCKET, blobName), Acl.of(new User(USER_EMAIL), Role.READER)); |
| 337 | + Acl userAcl = storageSnippets.getBlobAcl(BUCKET, blobName, USER_EMAIL); |
| 338 | + assertNotNull(userAcl); |
| 339 | + assertEquals(USER_EMAIL, ((User)userAcl.getEntity()).getEmail()); |
| 340 | + |
324 | 341 | updatedAcl = storageSnippets.blobToPublicRead(BUCKET, blobName, createdBlob.getGeneration()); |
325 | 342 | assertEquals(Acl.Role.READER, updatedAcl.getRole()); |
326 | 343 | assertEquals(User.ofAllUsers(), updatedAcl.getEntity()); |
327 | 344 | acls = Sets.newHashSet( |
328 | 345 | storageSnippets.listBlobAcls(BUCKET, blobName, createdBlob.getGeneration())); |
329 | 346 | assertTrue(acls.contains(updatedAcl)); |
330 | 347 |
|
| 348 | + assertNotNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration())); |
331 | 349 | assertTrue(storageSnippets.deleteBlobAcl(BUCKET, blobName, createdBlob.getGeneration())); |
332 | 350 | assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration())); |
333 | 351 | // test non-existing blob |
|
0 commit comments