Search in sources :

Example 1 with ListNotificationsRequest

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

the class StorageClientTest method listNotificationsTest.

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

Example 2 with ListNotificationsRequest

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

the class StorageClientTest method listNotificationsTest2.

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

Example 3 with ListNotificationsRequest

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

the class StorageClientTest method listNotificationsTest2.

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

Example 4 with ListNotificationsRequest

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

the class AsyncListNotifications method asyncListNotifications.

public static void asyncListNotifications() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        ListNotificationsRequest request = ListNotificationsRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").build();
        ApiFuture<Notification> future = storageClient.listNotificationsPagedCallable().futureCall(request);
        // Do something.
        for (Notification element : future.get().iterateAll()) {
        // doThingsWith(element);
        }
    }
}
Also used : StorageClient(com.google.storage.v2.StorageClient) ListNotificationsRequest(com.google.storage.v2.ListNotificationsRequest) Notification(com.google.storage.v2.Notification)

Example 5 with ListNotificationsRequest

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

the class AsyncListNotificationsPaged method asyncListNotificationsPaged.

public static void asyncListNotificationsPaged() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        ListNotificationsRequest request = ListNotificationsRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").build();
        while (true) {
            ListNotificationsResponse response = storageClient.listNotificationsCallable().call(request);
            for (Notification element : response.getResponsesList()) {
            // doThingsWith(element);
            }
            String nextPageToken = response.getNextPageToken();
            if (!Strings.isNullOrEmpty(nextPageToken)) {
                request = request.toBuilder().setPageToken(nextPageToken).build();
            } else {
                break;
            }
        }
    }
}
Also used : StorageClient(com.google.storage.v2.StorageClient) ListNotificationsRequest(com.google.storage.v2.ListNotificationsRequest) Notification(com.google.storage.v2.Notification) ListNotificationsResponse(com.google.storage.v2.ListNotificationsResponse)

Aggregations

AbstractMessage (com.google.protobuf.AbstractMessage)4 ListNotificationsPagedResponse (com.google.storage.v2.StorageClient.ListNotificationsPagedResponse)4 Test (org.junit.Test)4 ByteString (com.google.protobuf.ByteString)2 ListNotificationsRequest (com.google.storage.v2.ListNotificationsRequest)2 Notification (com.google.storage.v2.Notification)2 StorageClient (com.google.storage.v2.StorageClient)2 ListNotificationsResponse (com.google.storage.v2.ListNotificationsResponse)1