Search in sources :

Example 1 with CreateBucketRequest

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

the class ConfigClientTest method createBucketExceptionTest.

@Test
public void createBucketExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        CreateBucketRequest request = CreateBucketRequest.newBuilder().setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()).setBucketId("bucketId-1603305307").setBucket(LogBucket.newBuilder().build()).build();
        client.createBucket(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) CreateBucketRequest(com.google.logging.v2.CreateBucketRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 2 with CreateBucketRequest

use of com.google.logging.v2.CreateBucketRequest in project java-logging 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)).addAllRestrictedFields(new ArrayList<String>()).setCmekSettings(CmekSettings.newBuilder().build()).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)

Aggregations

CreateBucketRequest (com.google.logging.v2.CreateBucketRequest)2 Test (org.junit.Test)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 LogBucket (com.google.logging.v2.LogBucket)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1