Search in sources :

Example 1 with BillingAccountLocationName

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

the class ConfigClientTest method listBucketsExceptionTest.

@Test
public void listBucketsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConfigServiceV2.addException(exception);
    try {
        BillingAccountLocationName parent = BillingAccountLocationName.of("[BILLING_ACCOUNT]", "[LOCATION]");
        client.listBuckets(parent);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) BillingAccountLocationName(com.google.logging.v2.BillingAccountLocationName) Test(org.junit.Test)

Example 2 with BillingAccountLocationName

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

the class ConfigClientTest method listBucketsTest.

@Test
public void listBucketsTest() throws Exception {
    LogBucket responsesElement = LogBucket.newBuilder().build();
    ListBucketsResponse expectedResponse = ListBucketsResponse.newBuilder().setNextPageToken("").addAllBuckets(Arrays.asList(responsesElement)).build();
    mockConfigServiceV2.addResponse(expectedResponse);
    BillingAccountLocationName parent = BillingAccountLocationName.of("[BILLING_ACCOUNT]", "[LOCATION]");
    ListBucketsPagedResponse pagedListResponse = client.listBuckets(parent);
    List<LogBucket> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getBucketsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListBucketsRequest actualRequest = ((ListBucketsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListBucketsResponse(com.google.logging.v2.ListBucketsResponse) ListBucketsPagedResponse(com.google.cloud.logging.v2.ConfigClient.ListBucketsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListBucketsRequest(com.google.logging.v2.ListBucketsRequest) BillingAccountLocationName(com.google.logging.v2.BillingAccountLocationName) LogBucket(com.google.logging.v2.LogBucket) Test(org.junit.Test)

Aggregations

BillingAccountLocationName (com.google.logging.v2.BillingAccountLocationName)2 Test (org.junit.Test)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 ListBucketsPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListBucketsPagedResponse)1 ListBucketsRequest (com.google.logging.v2.ListBucketsRequest)1 ListBucketsResponse (com.google.logging.v2.ListBucketsResponse)1 LogBucket (com.google.logging.v2.LogBucket)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1