Search in sources :

Example 6 with CreateBucketRequest

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

the class ConfigClientTest method createBucketTest.

@Test
public void createBucketTest() throws Exception {
    LogBucket expectedResponse = LogBucket.newBuilder().setName(LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]").toString()).setDescription("description-1724546052").setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).setRetentionDays(1544391896).setLocked(true).setLifecycleState(LifecycleState.forNumber(0)).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    CreateBucketRequest request = CreateBucketRequest.newBuilder().setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()).setBucketId("bucketId-1603305307").setBucket(LogBucket.newBuilder().build()).build();
    LogBucket actualResponse = client.createBucket(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateBucketRequest actualRequest = ((CreateBucketRequest) actualRequests.get(0));
    Assert.assertEquals(request.getParent(), actualRequest.getParent());
    Assert.assertEquals(request.getBucketId(), actualRequest.getBucketId());
    Assert.assertEquals(request.getBucket(), actualRequest.getBucket());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) CreateBucketRequest(com.google.logging.v2.CreateBucketRequest) LogBucket(com.google.logging.v2.LogBucket) Test(org.junit.Test)

Example 7 with CreateBucketRequest

use of com.google.storage.v2.CreateBucketRequest 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 8 with CreateBucketRequest

use of com.google.storage.v2.CreateBucketRequest 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)

Aggregations

CreateBucketRequest (com.google.logging.v2.CreateBucketRequest)6 LogBucket (com.google.logging.v2.LogBucket)4 Test (org.junit.Test)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 ConfigClient (com.google.cloud.logging.v2.ConfigClient)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Bucket (com.google.storage.v2.Bucket)2 CreateBucketRequest (com.google.storage.v2.CreateBucketRequest)2 StorageClient (com.google.storage.v2.StorageClient)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2