use of com.google.cloud.storage.Bucket in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testGetBucketAllSelectedFields.
@Test
public void testGetBucketAllSelectedFields() {
Bucket remoteBucket = storage.get(BUCKET, Storage.BucketGetOption.fields(BucketField.values()));
assertEquals(BUCKET, remoteBucket.getName());
assertNotNull(remoteBucket.getCreateTime());
assertNotNull(remoteBucket.getSelfLink());
}
use of com.google.cloud.storage.Bucket in project google-cloud-java by GoogleCloudPlatform.
the class ITBucketSnippets method testBucket.
@Test
public void testBucket() throws InterruptedException {
assertTrue(bucketSnippets.exists());
Bucket bucket = bucketSnippets.reload();
assertNotNull(bucket);
Bucket updatedBucket = bucketSnippets.update();
assertTrue(updatedBucket.versioningEnabled());
Blob blob1 = bucketSnippets.createBlobFromByteArray(BLOB1);
assertNotNull(blob1);
Blob blob2 = bucketSnippets.createBlobFromByteArrayWithContentType(BLOB2);
assertNotNull(blob2);
Blob blob3 = bucketSnippets.createBlobFromInputStream(BLOB3);
assertNotNull(blob3);
Blob blob4 = bucketSnippets.createBlobFromInputStreamWithContentType(BLOB4);
assertNotNull(blob4);
Set<Blob> blobSet = Sets.newHashSet(bucketSnippets.listBlobs().iterateAll());
while (blobSet.size() < 4) {
Thread.sleep(500);
blobSet = Sets.newHashSet(bucketSnippets.listBlobs().iterateAll());
}
assertTrue(blobSet.contains(blob1));
assertTrue(blobSet.contains(blob2));
assertTrue(blobSet.contains(blob3));
assertTrue(blobSet.contains(blob4));
blob1 = bucketSnippets.getBlob(BLOB1, blob1.getGeneration());
assertEquals(BLOB1, blob1.getName());
List<Blob> blobs = bucketSnippets.getBlobFromStrings(BLOB2, BLOB3);
assertEquals(BLOB2, blobs.get(0).getName());
assertEquals(BLOB3, blobs.get(1).getName());
blobs = bucketSnippets.getBlobFromStringIterable(BLOB3, BLOB4);
assertEquals(BLOB3, blobs.get(0).getName());
assertEquals(BLOB4, blobs.get(1).getName());
// test ACLs
assertNull(bucketSnippets.getAcl());
assertNotNull(bucketSnippets.createAcl());
Acl updatedAcl = bucketSnippets.updateAcl();
assertEquals(Role.OWNER, updatedAcl.getRole());
Set<Acl> acls = Sets.newHashSet(bucketSnippets.listAcls());
assertTrue(acls.contains(updatedAcl));
assertTrue(bucketSnippets.deleteAcl());
assertNull(bucketSnippets.getAcl());
// test default ACLs
assertNull(bucketSnippets.getDefaultAcl());
assertNotNull(bucketSnippets.createDefaultAcl());
updatedAcl = bucketSnippets.updateDefaultAcl();
assertEquals(Role.OWNER, updatedAcl.getRole());
acls = Sets.newHashSet(bucketSnippets.listDefaultAcls());
assertTrue(acls.contains(updatedAcl));
assertTrue(bucketSnippets.deleteDefaultAcl());
assertNull(bucketSnippets.getDefaultAcl());
thrown.expect(StorageException.class);
assertTrue(bucketSnippets.delete());
}
use of com.google.cloud.storage.Bucket in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageSnippets method testCreateBucketWithStorageClassAndLocation.
@Test
public void testCreateBucketWithStorageClassAndLocation() throws ExecutionException, InterruptedException {
String tempBucket = RemoteStorageHelper.generateBucketName();
bucketsToCleanUp.add(tempBucket);
Bucket bucket = storageSnippets.createBucketWithStorageClassAndLocation(tempBucket);
assertNotNull(bucket);
}
use of com.google.cloud.storage.Bucket in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method updateBucket.
/**
* Example of updating bucket information.
*/
// [TARGET update(BucketInfo, BucketTargetOption...)]
// [VARIABLE "my_unique_bucket"]
public Bucket updateBucket(String bucketName) {
// [START updateBucket]
BucketInfo bucketInfo = BucketInfo.newBuilder(bucketName).setVersioningEnabled(true).build();
Bucket bucket = storage.update(bucketInfo);
// [END updateBucket]
return bucket;
}