Search in sources :

Example 1 with ListBucketsRequest

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

the class StorageClientTest method listBucketsTest.

@Test
public void listBucketsTest() throws Exception {
    Bucket responsesElement = Bucket.newBuilder().build();
    ListBucketsResponse expectedResponse = ListBucketsResponse.newBuilder().setNextPageToken("").addAllBuckets(Arrays.asList(responsesElement)).build();
    mockStorage.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    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.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListBucketsPagedResponse(com.google.storage.v2.StorageClient.ListBucketsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 2 with ListBucketsRequest

use of com.google.storage.v2.ListBucketsRequest in project gapic-generator-java 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)

Example 3 with ListBucketsRequest

use of com.google.storage.v2.ListBucketsRequest in project gapic-generator-java 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 4 with ListBucketsRequest

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

the class AsyncListBuckets method asyncListBuckets.

public static void asyncListBuckets() throws Exception {
    // It may require modifications to work in your environment.
    try (ConfigClient configClient = ConfigClient.create()) {
        ListBucketsRequest request = ListBucketsRequest.newBuilder().setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()).setPageToken("pageToken873572522").setPageSize(883849137).build();
        ApiFuture<LogBucket> future = configClient.listBucketsPagedCallable().futureCall(request);
        // Do something.
        for (LogBucket element : future.get().iterateAll()) {
        // doThingsWith(element);
        }
    }
}
Also used : ConfigClient(com.google.cloud.logging.v2.ConfigClient) ListBucketsRequest(com.google.logging.v2.ListBucketsRequest) LogBucket(com.google.logging.v2.LogBucket)

Example 5 with ListBucketsRequest

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

the class AsyncListBuckets method asyncListBuckets.

public static void asyncListBuckets() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        ListBucketsRequest request = ListBucketsRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").setPrefix("prefix-980110702").setReadMask(FieldMask.newBuilder().build()).setCommonRequestParams(CommonRequestParams.newBuilder().build()).build();
        ApiFuture<Bucket> future = storageClient.listBucketsPagedCallable().futureCall(request);
        // Do something.
        for (Bucket element : future.get().iterateAll()) {
        // doThingsWith(element);
        }
    }
}
Also used : Bucket(com.google.storage.v2.Bucket) ListBucketsRequest(com.google.storage.v2.ListBucketsRequest) StorageClient(com.google.storage.v2.StorageClient)

Aggregations

AbstractMessage (com.google.protobuf.AbstractMessage)14 Test (org.junit.Test)14 ListBucketsRequest (com.google.logging.v2.ListBucketsRequest)12 LogBucket (com.google.logging.v2.LogBucket)12 ListBucketsResponse (com.google.logging.v2.ListBucketsResponse)11 ListBucketsPagedResponse (com.google.cloud.logging.v2.ConfigClient.ListBucketsPagedResponse)10 BillingAccountLocationName (com.google.logging.v2.BillingAccountLocationName)4 FolderLocationName (com.google.logging.v2.FolderLocationName)4 OrganizationLocationName (com.google.logging.v2.OrganizationLocationName)4 ListBucketsPagedResponse (com.google.storage.v2.StorageClient.ListBucketsPagedResponse)4 ConfigClient (com.google.cloud.logging.v2.ConfigClient)2 LocationName (com.google.logging.v2.LocationName)2 ByteString (com.google.protobuf.ByteString)2 Bucket (com.google.storage.v2.Bucket)2 ListBucketsRequest (com.google.storage.v2.ListBucketsRequest)2 StorageClient (com.google.storage.v2.StorageClient)2 ListBucketsResponse (com.google.storage.v2.ListBucketsResponse)1