Search in sources :

Example 6 with ListSinksRequest

use of com.google.logging.v2.ListSinksRequest 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));
}
Also used : ListSinksResponse(com.google.logging.v2.ListSinksResponse) LogSink(com.google.logging.v2.LogSink) ListSinksRequest(com.google.logging.v2.ListSinksRequest) Test(org.junit.Test)

Example 7 with ListSinksRequest

use of com.google.logging.v2.ListSinksRequest 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());
}
Also used : LogSink(com.google.logging.v2.LogSink) ListSinksResponse(com.google.logging.v2.ListSinksResponse) ListSinksPagedResponse(com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListSinksPagedResponse) ParentNameOneof(com.google.logging.v2.ParentNameOneof) ListSinksRequest(com.google.logging.v2.ListSinksRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 8 with ListSinksRequest

use of com.google.logging.v2.ListSinksRequest 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));
}
Also used : ListSinksResponse(com.google.logging.v2.ListSinksResponse) LogSink(com.google.logging.v2.LogSink) ListSinksRequest(com.google.logging.v2.ListSinksRequest) Test(org.junit.Test)

Example 9 with ListSinksRequest

use of com.google.logging.v2.ListSinksRequest 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));
}
Also used : ListSinksResponse(com.google.logging.v2.ListSinksResponse) LogSink(com.google.logging.v2.LogSink) ListSinksRequest(com.google.logging.v2.ListSinksRequest) Test(org.junit.Test)

Example 10 with ListSinksRequest

use of com.google.logging.v2.ListSinksRequest 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);
        }
    });
}
Also used : ListSinksResponse(com.google.logging.v2.ListSinksResponse) ListSinksRequest(com.google.logging.v2.ListSinksRequest) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) AsyncPage(com.google.api.gax.paging.AsyncPage)

Aggregations

ListSinksRequest (com.google.logging.v2.ListSinksRequest)10 ListSinksResponse (com.google.logging.v2.ListSinksResponse)10 LogSink (com.google.logging.v2.LogSink)9 Test (org.junit.Test)9 AsyncPage (com.google.api.gax.paging.AsyncPage)1 ListSinksPagedResponse (com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListSinksPagedResponse)1 ImmutableList (com.google.common.collect.ImmutableList)1 ParentNameOneof (com.google.logging.v2.ParentNameOneof)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1