Search in sources :

Example 1 with ListObjectsResponse

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

the class StorageClientTest method listObjectsTest.

@Test
public void listObjectsTest() throws Exception {
    Object responsesElement = Object.newBuilder().build();
    ListObjectsResponse expectedResponse = ListObjectsResponse.newBuilder().setNextPageToken("").addAllObjects(Arrays.asList(responsesElement)).build();
    mockStorage.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    ListObjectsPagedResponse pagedListResponse = client.listObjects(parent);
    List<Object> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getObjectsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockStorage.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListObjectsRequest actualRequest = ((ListObjectsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListObjectsPagedResponse(com.google.storage.v2.StorageClient.ListObjectsPagedResponse) Test(org.junit.Test)

Example 2 with ListObjectsResponse

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

the class StorageClientTest method listObjectsTest.

@Test
public void listObjectsTest() throws Exception {
    Object responsesElement = Object.newBuilder().build();
    ListObjectsResponse expectedResponse = ListObjectsResponse.newBuilder().setNextPageToken("").addAllObjects(Arrays.asList(responsesElement)).build();
    mockStorage.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    ListObjectsPagedResponse pagedListResponse = client.listObjects(parent);
    List<Object> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getObjectsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockStorage.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListObjectsRequest actualRequest = ((ListObjectsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListObjectsPagedResponse(com.google.storage.v2.StorageClient.ListObjectsPagedResponse) Test(org.junit.Test)

Example 3 with ListObjectsResponse

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

the class StorageClientTest method listObjectsTest2.

@Test
public void listObjectsTest2() throws Exception {
    Object responsesElement = Object.newBuilder().build();
    ListObjectsResponse expectedResponse = ListObjectsResponse.newBuilder().setNextPageToken("").addAllObjects(Arrays.asList(responsesElement)).build();
    mockStorage.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListObjectsPagedResponse pagedListResponse = client.listObjects(parent);
    List<Object> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getObjectsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockStorage.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListObjectsRequest actualRequest = ((ListObjectsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListObjectsPagedResponse(com.google.storage.v2.StorageClient.ListObjectsPagedResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 4 with ListObjectsResponse

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

the class AsyncListObjectsPaged method asyncListObjectsPaged.

public static void asyncListObjectsPaged() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        ListObjectsRequest request = ListObjectsRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").setDelimiter("delimiter-250518009").setIncludeTrailingDelimiter(true).setPrefix("prefix-980110702").setVersions(true).setReadMask(FieldMask.newBuilder().build()).setLexicographicStart("lexicographicStart-2093413008").setLexicographicEnd("lexicographicEnd1646968169").setCommonRequestParams(CommonRequestParams.newBuilder().build()).build();
        while (true) {
            ListObjectsResponse response = storageClient.listObjectsCallable().call(request);
            for (Object element : response.getResponsesList()) {
            // doThingsWith(element);
            }
            String nextPageToken = response.getNextPageToken();
            if (!Strings.isNullOrEmpty(nextPageToken)) {
                request = request.toBuilder().setPageToken(nextPageToken).build();
            } else {
                break;
            }
        }
    }
}
Also used : ListObjectsRequest(com.google.storage.v2.ListObjectsRequest) StorageClient(com.google.storage.v2.StorageClient) ListObjectsResponse(com.google.storage.v2.ListObjectsResponse) Object(com.google.storage.v2.Object)

Example 5 with ListObjectsResponse

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

the class StorageClientTest method listObjectsTest2.

@Test
public void listObjectsTest2() throws Exception {
    Object responsesElement = Object.newBuilder().build();
    ListObjectsResponse expectedResponse = ListObjectsResponse.newBuilder().setNextPageToken("").addAllObjects(Arrays.asList(responsesElement)).build();
    mockStorage.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListObjectsPagedResponse pagedListResponse = client.listObjects(parent);
    List<Object> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getObjectsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockStorage.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListObjectsRequest actualRequest = ((ListObjectsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListObjectsPagedResponse(com.google.storage.v2.StorageClient.ListObjectsPagedResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

AbstractMessage (com.google.protobuf.AbstractMessage)4 ListObjectsPagedResponse (com.google.storage.v2.StorageClient.ListObjectsPagedResponse)4 Test (org.junit.Test)4 ByteString (com.google.protobuf.ByteString)2 ListObjectsRequest (com.google.storage.v2.ListObjectsRequest)1 ListObjectsResponse (com.google.storage.v2.ListObjectsResponse)1 Object (com.google.storage.v2.Object)1 StorageClient (com.google.storage.v2.StorageClient)1