use of com.google.logging.v2.ListExclusionsRequest in project java-logging by googleapis.
the class LoggingImpl method listExclusionAsync.
private static ApiFuture<AsyncPage<Exclusion>> listExclusionAsync(final LoggingOptions serviceOptions, final Map<Option.OptionType, ?> options) {
final ListExclusionsRequest request = listExclusionsRequest(serviceOptions, options);
ApiFuture<ListExclusionsResponse> list = serviceOptions.getLoggingRpcV2().list(request);
return transform(list, new Function<ListExclusionsResponse, AsyncPage<Exclusion>>() {
@Override
public AsyncPage<Exclusion> apply(ListExclusionsResponse listExclusionsResponse) {
List<Exclusion> exclusions = listExclusionsResponse.getExclusionsList() == null ? ImmutableList.<Exclusion>of() : Lists.transform(listExclusionsResponse.getExclusionsList(), Exclusion.FROM_PROTOBUF_FUNCTION);
String cursor = listExclusionsResponse.getNextPageToken().equals("") ? null : listExclusionsResponse.getNextPageToken();
return new AsyncPageImpl<>(new ExclusionPageFetcher(serviceOptions, cursor, options), cursor, exclusions);
}
});
}
use of com.google.logging.v2.ListExclusionsRequest in project java-logging by googleapis.
the class LoggingImplTest method testListExclusionsAsync.
@Test
public void testListExclusionsAsync() throws ExecutionException, InterruptedException {
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListExclusionsRequest request = ListExclusionsRequest.newBuilder().setParent(PROJECT_PARENT).build();
List<Exclusion> exclusionList = ImmutableList.of(Exclusion.of(EXCLUSION_NAME, EXCLUSION_FILTER), Exclusion.of(EXCLUSION_NAME, EXCLUSION_FILTER));
ListExclusionsResponse response = ListExclusionsResponse.newBuilder().setNextPageToken(CURSOR).addAllExclusions(Lists.transform(exclusionList, Exclusion.TO_PROTOBUF_FUNCTION)).build();
ApiFuture<ListExclusionsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
AsyncPage<Exclusion> page = logging.listExclusionsAsync().get();
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(exclusionList.toArray(), Iterables.toArray(page.getValues(), Exclusion.class));
}
use of com.google.logging.v2.ListExclusionsRequest in project java-logging by googleapis.
the class LoggingImplTest method testListExclusionAsyncEmpty.
@Test
public void testListExclusionAsyncEmpty() throws ExecutionException, InterruptedException {
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListExclusionsRequest request = ListExclusionsRequest.newBuilder().setParent(PROJECT_PARENT).build();
List<Exclusion> exclusionList = ImmutableList.of();
ListExclusionsResponse response = ListExclusionsResponse.newBuilder().setNextPageToken("").addAllExclusions(Lists.transform(exclusionList, Exclusion.TO_PROTOBUF_FUNCTION)).build();
ApiFuture<ListExclusionsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
AsyncPage<Exclusion> page = logging.listExclusionsAsync().get();
assertNull(page.getNextPageToken());
assertNull(page.getNextPage());
assertArrayEquals(exclusionList.toArray(), Iterables.toArray(page.getValues(), Exclusion.class));
}
use of com.google.logging.v2.ListExclusionsRequest in project java-logging by googleapis.
the class ConfigClientTest method listExclusionsTest4.
@Test
public void listExclusionsTest4() throws Exception {
LogExclusion responsesElement = LogExclusion.newBuilder().build();
ListExclusionsResponse expectedResponse = ListExclusionsResponse.newBuilder().setNextPageToken("").addAllExclusions(Arrays.asList(responsesElement)).build();
mockConfigServiceV2.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
ListExclusionsPagedResponse pagedListResponse = client.listExclusions(parent);
List<LogExclusion> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getExclusionsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockConfigServiceV2.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListExclusionsRequest actualRequest = ((ListExclusionsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.logging.v2.ListExclusionsRequest in project java-logging by googleapis.
the class LoggingImplTest method testListExclusionAsyncWithOptions.
@Test
public void testListExclusionAsyncWithOptions() throws ExecutionException, InterruptedException {
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListExclusionsRequest request = ListExclusionsRequest.newBuilder().setPageToken(CURSOR).setPageSize(42).setParent(PROJECT_PARENT).build();
List<Exclusion> exclusionList = ImmutableList.of(Exclusion.of(EXCLUSION_NAME, EXCLUSION_FILTER), Exclusion.of(EXCLUSION_NAME, EXCLUSION_FILTER));
ListExclusionsResponse response = ListExclusionsResponse.newBuilder().setNextPageToken(CURSOR).addAllExclusions(Lists.transform(exclusionList, Exclusion.TO_PROTOBUF_FUNCTION)).build();
ApiFuture<ListExclusionsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
AsyncPage<Exclusion> page = logging.listExclusionsAsync(ListOption.pageSize(42), ListOption.pageToken(CURSOR)).get();
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(exclusionList.toArray(), Iterables.toArray(page.getValues(), Exclusion.class));
}
Aggregations