Search in sources :

Example 6 with Bucket

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());
}
Also used : Bucket(com.google.cloud.storage.Bucket) Test(org.junit.Test)

Example 7 with Bucket

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());
}
Also used : Blob(com.google.cloud.storage.Blob) Bucket(com.google.cloud.storage.Bucket) Acl(com.google.cloud.storage.Acl) Test(org.junit.Test)

Example 8 with Bucket

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);
}
Also used : Bucket(com.google.cloud.storage.Bucket) Test(org.junit.Test)

Example 9 with 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;
}
Also used : Bucket(com.google.cloud.storage.Bucket) BucketInfo(com.google.cloud.storage.BucketInfo)

Aggregations

Bucket (com.google.cloud.storage.Bucket)9 Test (org.junit.Test)7 Blob (com.google.cloud.storage.Blob)3 Acl (com.google.cloud.storage.Acl)1 BlobInfo (com.google.cloud.storage.BlobInfo)1 BucketInfo (com.google.cloud.storage.BucketInfo)1 Storage (com.google.cloud.storage.Storage)1