Search in sources :

Example 1 with GetBucketRequest

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

the class ConfigClientTest method getBucketExceptionTest.

@Test
public void getBucketExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        GetBucketRequest request = GetBucketRequest.newBuilder().setName(LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]").toString()).build();
        client.getBucket(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) GetBucketRequest(com.google.logging.v2.GetBucketRequest) Test(org.junit.Test)

Example 2 with GetBucketRequest

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

the class ConfigClientTest method getBucketTest.

@Test
public void getBucketTest() 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);
    GetBucketRequest request = GetBucketRequest.newBuilder().setName(LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]").toString()).build();
    LogBucket actualResponse = client.getBucket(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetBucketRequest actualRequest = ((GetBucketRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) LogBucket(com.google.logging.v2.LogBucket) GetBucketRequest(com.google.logging.v2.GetBucketRequest) Test(org.junit.Test)

Example 3 with GetBucketRequest

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

the class ConfigClientTest method getBucketTest.

@Test
public void getBucketTest() 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)).addAllRestrictedFields(new ArrayList<String>()).setCmekSettings(CmekSettings.newBuilder().build()).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    GetBucketRequest request = GetBucketRequest.newBuilder().setName(LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]").toString()).build();
    LogBucket actualResponse = client.getBucket(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetBucketRequest actualRequest = ((GetBucketRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) LogBucket(com.google.logging.v2.LogBucket) GetBucketRequest(com.google.logging.v2.GetBucketRequest) Test(org.junit.Test)

Example 4 with GetBucketRequest

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

the class ConfigClientTest method getBucketExceptionTest.

@Test
public void getBucketExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        GetBucketRequest request = GetBucketRequest.newBuilder().setName(LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]").toString()).build();
        client.getBucket(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) GetBucketRequest(com.google.logging.v2.GetBucketRequest) Test(org.junit.Test)

Example 5 with GetBucketRequest

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

the class AsyncGetBucket method asyncGetBucket.

public static void asyncGetBucket() throws Exception {
    // It may require modifications to work in your environment.
    try (ConfigClient configClient = ConfigClient.create()) {
        GetBucketRequest request = GetBucketRequest.newBuilder().setName(LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]").toString()).build();
        ApiFuture<LogBucket> future = configClient.getBucketCallable().futureCall(request);
        // Do something.
        LogBucket response = future.get();
    }
}
Also used : ConfigClient(com.google.cloud.logging.v2.ConfigClient) LogBucket(com.google.logging.v2.LogBucket) GetBucketRequest(com.google.logging.v2.GetBucketRequest)

Aggregations

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