@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
@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)); }
@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)); }
@Test public void testListSinks() { String cursor = "cursor"; EasyMock.replay(rpcFactoryMock); logging = options.getService(); ListSinksRequest request = ListSinksRequest.newBuilder().setParent(PROJECT_PB).build(); List<Sink> sinkList = ImmutableList.of( new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)), new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO))); ListSinksResponse response = ListSinksResponse.newBuilder() .setNextPageToken(cursor) .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(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(sinkList.toArray(), Iterables.toArray(page.getValues(), Sink.class)); }
@Test public void testListSinksAsync() throws ExecutionException, InterruptedException { String cursor = "cursor"; EasyMock.replay(rpcFactoryMock); logging = options.getService(); ListSinksRequest request = ListSinksRequest.newBuilder().setParent(PROJECT_PB).build(); List<Sink> sinkList = ImmutableList.of( new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)), new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO))); ListSinksResponse response = ListSinksResponse.newBuilder() .setNextPageToken(cursor) .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(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(sinkList.toArray(), Iterables.toArray(page.getValues(), Sink.class)); }
@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); ParentName parent = ProjectName.of("[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, ParentNames.parse(actualRequest.getParent())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
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)) String cursor2 = "nextCursor"; ListSinksResponse response2 = ListSinksResponse.newBuilder() .setNextPageToken(cursor2) .addAllSinks(Lists.transform(sinkList2, SINK_TO_PB_FUNCTION))
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)) String cursor2 = "nextCursor"; ListSinksResponse response2 = ListSinksResponse.newBuilder() .setNextPageToken(cursor2) .addAllSinks(Lists.transform(sinkList2, SINK_TO_PB_FUNCTION))
@Test public void testListSinksWithOptions() { String cursor = "cursor"; EasyMock.replay(rpcFactoryMock); logging = options.getService(); ListSinksRequest request = ListSinksRequest.newBuilder() .setPageToken(cursor) .setPageSize(42) .setParent(PROJECT_PB) .build(); List<Sink> sinkList = ImmutableList.of( new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)), new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO))); ListSinksResponse response = ListSinksResponse.newBuilder() .setNextPageToken(cursor) .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(ListOption.pageSize(42), ListOption.pageToken(cursor)); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(sinkList.toArray(), Iterables.toArray(page.getValues(), Sink.class)); }
@Test public void testListSinksWithOptionsAsync() throws ExecutionException, InterruptedException { String cursor = "cursor"; EasyMock.replay(rpcFactoryMock); logging = options.getService(); ListSinksRequest request = ListSinksRequest.newBuilder() .setPageToken(cursor) .setPageSize(42) .setParent(PROJECT_PB) .build(); List<Sink> sinkList = ImmutableList.of( new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)), new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO))); ListSinksResponse response = ListSinksResponse.newBuilder() .setNextPageToken(cursor) .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(ListOption.pageSize(42), ListOption.pageToken(cursor)).get(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(sinkList.toArray(), Iterables.toArray(page.getValues(), Sink.class)); }