/** * Lists sinks. * * <p>Sample code: * * <pre><code> * try (ConfigClient configClient = ConfigClient.create()) { * ParentName parent = ProjectName.of("[PROJECT]"); * for (LogSink element : configClient.listSinks(parent).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param parent Required. The parent resource whose sinks are to be listed: * <p>"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListSinksPagedResponse listSinks(ParentName parent) { ListSinksRequest request = ListSinksRequest.newBuilder().setParent(parent == null ? null : parent.toString()).build(); return listSinks(request); }
@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)); }
/** * Lists sinks. * * <p>Sample code: * * <pre><code> * try (ConfigClient configClient = ConfigClient.create()) { * ParentName parent = ProjectName.of("[PROJECT]"); * for (LogSink element : configClient.listSinks(parent).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param parent Required. The parent resource whose sinks are to be listed: * <p>"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListSinksPagedResponse listSinks(ParentName parent) { ListSinksRequest request = ListSinksRequest.newBuilder().setParent(parent == null ? null : parent.toString()).build(); return listSinks(request); }
/** * Lists sinks. * * <p>Sample code: * * <pre><code> * try (ConfigClient configClient = ConfigClient.create()) { * ParentName parent = ProjectName.of("[PROJECT]"); * for (LogSink element : configClient.listSinks(parent.toString()).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param parent Required. The parent resource whose sinks are to be listed: * <p>"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListSinksPagedResponse listSinks(String parent) { ListSinksRequest request = ListSinksRequest.newBuilder().setParent(parent).build(); return listSinks(request); }
private static ListSinksRequest listSinksRequest( LoggingOptions serviceOptions, Map<Option.OptionType, ?> options) { ListSinksRequest.Builder builder = ListSinksRequest.newBuilder(); builder.setParent(ProjectName.of(serviceOptions.getProjectId()).toString()); Integer pageSize = PAGE_SIZE.get(options); String pageToken = PAGE_TOKEN.get(options); if (pageSize != null) { builder.setPageSize(pageSize); } if (pageToken != null) { builder.setPageToken(pageToken); } return builder.build(); }
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(
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(
@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)); }
@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)); }
/** * Lists sinks. * * <p>Sample code: * * <pre><code> * try (ConfigClient configClient = ConfigClient.create()) { * ParentName parent = ProjectName.of("[PROJECT]"); * for (LogSink element : configClient.listSinks(parent.toString()).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param parent Required. The parent resource whose sinks are to be listed: * <p>"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListSinksPagedResponse listSinks(String parent) { ListSinksRequest request = ListSinksRequest.newBuilder().setParent(parent).build(); return listSinks(request); }
@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)); }
private static ListSinksRequest listSinksRequest( LoggingOptions serviceOptions, Map<Option.OptionType, ?> options) { ListSinksRequest.Builder builder = ListSinksRequest.newBuilder(); builder.setParent(ProjectName.of(serviceOptions.getProjectId()).toString()); Integer pageSize = PAGE_SIZE.get(options); String pageToken = PAGE_TOKEN.get(options); if (pageSize != null) { builder.setPageSize(pageSize); } if (pageToken != null) { builder.setPageToken(pageToken); } return builder.build(); }