use of com.google.logging.v2.ListSinksResponse in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListSinksEmpty.
@Test
public void testListSinksEmpty() {
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListSinksRequest request = ListSinksRequest.newBuilder().setParent(PROJECT_PB).build();
List<Sink> sinkList = ImmutableList.of();
ListSinksResponse response = ListSinksResponse.newBuilder().setNextPageToken("").addAllSinks(Lists.transform(sinkList, SINK_TO_PB_FUNCTION)).build();
ApiFuture<ListSinksResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
Page<Sink> page = logging.listSinks();
assertNull(page.getNextPageToken());
assertNull(page.getNextPage());
assertArrayEquals(sinkList.toArray(), Iterables.toArray(page.getValues(), Sink.class));
}
use of com.google.logging.v2.ListSinksResponse in project google-cloud-java by GoogleCloudPlatform.
the class ConfigClientTest method listSinksTest.
@Test
@SuppressWarnings("all")
public void listSinksTest() {
String nextPageToken = "";
LogSink sinksElement = LogSink.newBuilder().build();
List<LogSink> sinks = Arrays.asList(sinksElement);
ListSinksResponse expectedResponse = ListSinksResponse.newBuilder().setNextPageToken(nextPageToken).addAllSinks(sinks).build();
mockConfigServiceV2.addResponse(expectedResponse);
ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
ListSinksPagedResponse pagedListResponse = client.listSinks(parent);
List<LogSink> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSinksList().get(0), resources.get(0));
List<GeneratedMessageV3> actualRequests = mockConfigServiceV2.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSinksRequest actualRequest = (ListSinksRequest) actualRequests.get(0);
Assert.assertEquals(parent, actualRequest.getParentAsParentNameOneof());
}
use of com.google.logging.v2.ListSinksResponse in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListSinksAsyncEmpty.
@Test
public void testListSinksAsyncEmpty() throws ExecutionException, InterruptedException {
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListSinksRequest request = ListSinksRequest.newBuilder().setParent(PROJECT_PB).build();
List<Sink> sinkList = ImmutableList.of();
ListSinksResponse response = ListSinksResponse.newBuilder().setNextPageToken("").addAllSinks(Lists.transform(sinkList, SINK_TO_PB_FUNCTION)).build();
ApiFuture<ListSinksResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
AsyncPage<Sink> page = logging.listSinksAsync().get();
assertNull(page.getNextPageToken());
assertNull(page.getNextPage());
assertArrayEquals(sinkList.toArray(), Iterables.toArray(page.getValues(), Sink.class));
}
use of com.google.logging.v2.ListSinksResponse in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListSinksNextPage.
@Test
public void testListSinksNextPage() {
String cursor1 = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListSinksRequest request1 = ListSinksRequest.newBuilder().setParent(PROJECT_PB).build();
ListSinksRequest request2 = ListSinksRequest.newBuilder().setParent(PROJECT_PB).setPageToken(cursor1).build();
List<Sink> sinkList1 = ImmutableList.of(new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)), new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)));
List<Sink> sinkList2 = ImmutableList.of(new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)));
ListSinksResponse response1 = ListSinksResponse.newBuilder().setNextPageToken(cursor1).addAllSinks(Lists.transform(sinkList1, SINK_TO_PB_FUNCTION)).build();
String cursor2 = "nextCursor";
ListSinksResponse response2 = ListSinksResponse.newBuilder().setNextPageToken(cursor2).addAllSinks(Lists.transform(sinkList2, SINK_TO_PB_FUNCTION)).build();
ApiFuture<ListSinksResponse> futureResponse1 = ApiFutures.immediateFuture(response1);
ApiFuture<ListSinksResponse> futureResponse2 = ApiFutures.immediateFuture(response2);
EasyMock.expect(loggingRpcMock.list(request1)).andReturn(futureResponse1);
EasyMock.expect(loggingRpcMock.list(request2)).andReturn(futureResponse2);
EasyMock.replay(loggingRpcMock);
Page<Sink> page = logging.listSinks();
assertEquals(cursor1, page.getNextPageToken());
assertArrayEquals(sinkList1.toArray(), Iterables.toArray(page.getValues(), Sink.class));
page = page.getNextPage();
assertEquals(cursor2, page.getNextPageToken());
assertArrayEquals(sinkList2.toArray(), Iterables.toArray(page.getValues(), Sink.class));
}
use of com.google.logging.v2.ListSinksResponse in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImpl method listSinksAsync.
private static ApiFuture<AsyncPage<Sink>> listSinksAsync(final LoggingOptions serviceOptions, final Map<Option.OptionType, ?> options) {
final ListSinksRequest request = listSinksRequest(serviceOptions, options);
ApiFuture<ListSinksResponse> list = serviceOptions.getLoggingRpcV2().list(request);
return transform(list, new Function<ListSinksResponse, AsyncPage<Sink>>() {
@Override
public AsyncPage<Sink> apply(ListSinksResponse listSinksResponse) {
List<Sink> sinks = listSinksResponse.getSinksList() == null ? ImmutableList.<Sink>of() : Lists.transform(listSinksResponse.getSinksList(), Sink.fromPbFunction(serviceOptions.getService()));
String cursor = listSinksResponse.getNextPageToken().equals("") ? null : listSinksResponse.getNextPageToken();
return new AsyncPageImpl<>(new SinkPageFetcher(serviceOptions, cursor, options), cursor, sinks);
}
});
}
Aggregations