Search in sources :

Example 1 with ListSinksResponse

use of com.google.logging.v2.ListSinksResponse in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testListSinksAsyncNextPage.

@Test
public void testListSinksAsyncNextPage() throws ExecutionException, InterruptedException {
    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);
    AsyncPage<Sink> page = logging.listSinksAsync().get();
    assertEquals(cursor1, page.getNextPageToken());
    assertArrayEquals(sinkList1.toArray(), Iterables.toArray(page.getValues(), Sink.class));
    page = page.getNextPageAsync().get();
    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 2 with ListSinksResponse

use of com.google.logging.v2.ListSinksResponse in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testListSinks.

@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));
}
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 3 with ListSinksResponse

use of com.google.logging.v2.ListSinksResponse in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testListSinksAsync.

@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));
}
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 4 with ListSinksResponse

use of com.google.logging.v2.ListSinksResponse in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testListSinksWithOptionsAsync.

@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));
}
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 5 with ListSinksResponse

use of com.google.logging.v2.ListSinksResponse in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testListSinksWithOptions.

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

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