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()));
}
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()));
}
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()));
}
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);
}
}
}
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;
}
}
}
}
Aggregations