Search in sources :

Example 16 with Bucket

use of com.google.storage.v2.Bucket in project java-storage by googleapis.

the class StorageClientTest method listBucketsTest2.

@Test
public void listBucketsTest2() throws Exception {
    Bucket responsesElement = Bucket.newBuilder().build();
    ListBucketsResponse expectedResponse = ListBucketsResponse.newBuilder().setNextPageToken("").addAllBuckets(Arrays.asList(responsesElement)).build();
    mockStorage.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListBucketsPagedResponse pagedListResponse = client.listBuckets(parent);
    List<Bucket> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getBucketsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockStorage.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListBucketsRequest actualRequest = ((ListBucketsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListBucketsPagedResponse(com.google.storage.v2.StorageClient.ListBucketsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 17 with Bucket

use of com.google.storage.v2.Bucket in project gapic-generator-java by googleapis.

the class AsyncCreateBucket method asyncCreateBucket.

public static void asyncCreateBucket() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        CreateBucketRequest request = CreateBucketRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setBucket(Bucket.newBuilder().build()).setBucketId("bucketId-1603305307").setPredefinedAcl(PredefinedBucketAcl.forNumber(0)).setPredefinedDefaultObjectAcl(PredefinedObjectAcl.forNumber(0)).build();
        ApiFuture<Bucket> future = storageClient.createBucketCallable().futureCall(request);
        // Do something.
        Bucket response = future.get();
    }
}
Also used : Bucket(com.google.storage.v2.Bucket) CreateBucketRequest(com.google.storage.v2.CreateBucketRequest) StorageClient(com.google.storage.v2.StorageClient)

Example 18 with Bucket

use of com.google.storage.v2.Bucket in project gapic-generator-java by googleapis.

the class SyncCreateBucket method syncCreateBucket.

public static void syncCreateBucket() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        CreateBucketRequest request = CreateBucketRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setBucket(Bucket.newBuilder().build()).setBucketId("bucketId-1603305307").setPredefinedAcl(PredefinedBucketAcl.forNumber(0)).setPredefinedDefaultObjectAcl(PredefinedObjectAcl.forNumber(0)).build();
        Bucket response = storageClient.createBucket(request);
    }
}
Also used : Bucket(com.google.storage.v2.Bucket) CreateBucketRequest(com.google.storage.v2.CreateBucketRequest) StorageClient(com.google.storage.v2.StorageClient)

Example 19 with Bucket

use of com.google.storage.v2.Bucket in project gapic-generator-java by googleapis.

the class SyncCreateBucketProjectnameBucketString method syncCreateBucketProjectnameBucketString.

public static void syncCreateBucketProjectnameBucketString() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        ProjectName parent = ProjectName.of("[PROJECT]");
        Bucket bucket = Bucket.newBuilder().build();
        String bucketId = "bucketId-1603305307";
        Bucket response = storageClient.createBucket(parent, bucket, bucketId);
    }
}
Also used : ProjectName(com.google.storage.v2.ProjectName) Bucket(com.google.storage.v2.Bucket) StorageClient(com.google.storage.v2.StorageClient)

Example 20 with Bucket

use of com.google.storage.v2.Bucket in project gapic-generator-java by googleapis.

the class SyncCreateBucketStringBucketString method syncCreateBucketStringBucketString.

public static void syncCreateBucketStringBucketString() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        String parent = ProjectName.of("[PROJECT]").toString();
        Bucket bucket = Bucket.newBuilder().build();
        String bucketId = "bucketId-1603305307";
        Bucket response = storageClient.createBucket(parent, bucket, bucketId);
    }
}
Also used : Bucket(com.google.storage.v2.Bucket) StorageClient(com.google.storage.v2.StorageClient)

Aggregations

StorageClient (com.google.storage.v2.StorageClient)39 Bucket (com.google.storage.v2.Bucket)17 AbstractMessage (com.google.protobuf.AbstractMessage)4 BucketName (com.google.storage.v2.BucketName)4 Notification (com.google.storage.v2.Notification)4 Object (com.google.storage.v2.Object)4 ListBucketsPagedResponse (com.google.storage.v2.StorageClient.ListBucketsPagedResponse)4 Test (org.junit.Test)4 Empty (com.google.protobuf.Empty)3 ByteString (com.google.protobuf.ByteString)2 CreateBucketRequest (com.google.storage.v2.CreateBucketRequest)2 DeleteNotificationRequest (com.google.storage.v2.DeleteNotificationRequest)2 DeleteObjectRequest (com.google.storage.v2.DeleteObjectRequest)2 GetBucketRequest (com.google.storage.v2.GetBucketRequest)2 GetNotificationRequest (com.google.storage.v2.GetNotificationRequest)2 GetObjectRequest (com.google.storage.v2.GetObjectRequest)2 ListBucketsRequest (com.google.storage.v2.ListBucketsRequest)2 LockBucketRetentionPolicyRequest (com.google.storage.v2.LockBucketRetentionPolicyRequest)2 RewriteObjectRequest (com.google.storage.v2.RewriteObjectRequest)2 RewriteResponse (com.google.storage.v2.RewriteResponse)2