use of com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method listMonitoredResourceDescriptorsTest.
@Test
@SuppressWarnings("all")
public void listMonitoredResourceDescriptorsTest() {
String nextPageToken = "";
MonitoredResourceDescriptor resourceDescriptorsElement = MonitoredResourceDescriptor.newBuilder().build();
List<MonitoredResourceDescriptor> resourceDescriptors = Arrays.asList(resourceDescriptorsElement);
ListMonitoredResourceDescriptorsResponse expectedResponse = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(nextPageToken).addAllResourceDescriptors(resourceDescriptors).build();
mockMetricService.addResponse(expectedResponse);
ProjectName name = ProjectName.create("[PROJECT]");
ListMonitoredResourceDescriptorsPagedResponse pagedListResponse = client.listMonitoredResourceDescriptors(name);
List<MonitoredResourceDescriptor> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getResourceDescriptorsList().get(0), resources.get(0));
List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListMonitoredResourceDescriptorsRequest actualRequest = (ListMonitoredResourceDescriptorsRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsProjectName());
}
use of com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListResourceDescriptorAsyncNextPage.
@Test
public void testListResourceDescriptorAsyncNextPage() throws ExecutionException, InterruptedException {
String cursor1 = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListMonitoredResourceDescriptorsRequest request1 = ListMonitoredResourceDescriptorsRequest.newBuilder().build();
ListMonitoredResourceDescriptorsRequest request2 = ListMonitoredResourceDescriptorsRequest.newBuilder().setPageToken(cursor1).build();
List<MonitoredResourceDescriptor> descriptorList1 = ImmutableList.of(DESCRIPTOR, DESCRIPTOR);
List<MonitoredResourceDescriptor> descriptorList2 = ImmutableList.of(DESCRIPTOR);
ListMonitoredResourceDescriptorsResponse response1 = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(cursor1).addAllResourceDescriptors(Lists.transform(descriptorList1, DESCRIPTOR_TO_PB_FUNCTION)).build();
String cursor2 = "nextCursor";
ListMonitoredResourceDescriptorsResponse response2 = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(cursor2).addAllResourceDescriptors(Lists.transform(descriptorList2, DESCRIPTOR_TO_PB_FUNCTION)).build();
ApiFuture<ListMonitoredResourceDescriptorsResponse> futureResponse1 = ApiFutures.immediateFuture(response1);
ApiFuture<ListMonitoredResourceDescriptorsResponse> futureResponse2 = ApiFutures.immediateFuture(response2);
EasyMock.expect(loggingRpcMock.list(request1)).andReturn(futureResponse1);
EasyMock.expect(loggingRpcMock.list(request2)).andReturn(futureResponse2);
EasyMock.replay(loggingRpcMock);
AsyncPage<MonitoredResourceDescriptor> page = logging.listMonitoredResourceDescriptorsAsync().get();
assertEquals(cursor1, page.getNextPageToken());
assertArrayEquals(descriptorList1.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
page = page.getNextPageAsync().get();
assertEquals(cursor2, page.getNextPageToken());
assertArrayEquals(descriptorList2.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
use of com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListResourceDescriptorAsyncWithOptions.
@Test
public void testListResourceDescriptorAsyncWithOptions() throws ExecutionException, InterruptedException {
String cursor = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().setPageToken(cursor).setPageSize(42).build();
List<MonitoredResourceDescriptor> descriptorList = ImmutableList.of(DESCRIPTOR, DESCRIPTOR);
ListMonitoredResourceDescriptorsResponse response = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(cursor).addAllResourceDescriptors(Lists.transform(descriptorList, DESCRIPTOR_TO_PB_FUNCTION)).build();
ApiFuture<ListMonitoredResourceDescriptorsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
AsyncPage<MonitoredResourceDescriptor> page = logging.listMonitoredResourceDescriptorsAsync(ListOption.pageSize(42), ListOption.pageToken(cursor)).get();
assertEquals(cursor, page.getNextPageToken());
assertArrayEquals(descriptorList.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
use of com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListResourceDescriptorWithOptions.
@Test
public void testListResourceDescriptorWithOptions() {
String cursor = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().setPageToken(cursor).setPageSize(42).build();
List<MonitoredResourceDescriptor> descriptorList = ImmutableList.of(DESCRIPTOR, DESCRIPTOR);
ListMonitoredResourceDescriptorsResponse response = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(cursor).addAllResourceDescriptors(Lists.transform(descriptorList, DESCRIPTOR_TO_PB_FUNCTION)).build();
ApiFuture<ListMonitoredResourceDescriptorsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
Page<MonitoredResourceDescriptor> page = logging.listMonitoredResourceDescriptors(ListOption.pageSize(42), ListOption.pageToken(cursor));
assertEquals(cursor, page.getNextPageToken());
assertArrayEquals(descriptorList.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
use of com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListResourceDescriptor.
@Test
public void testListResourceDescriptor() {
String cursor = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().build();
List<MonitoredResourceDescriptor> descriptorList = ImmutableList.of(DESCRIPTOR, DESCRIPTOR);
ListMonitoredResourceDescriptorsResponse response = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(cursor).addAllResourceDescriptors(Lists.transform(descriptorList, DESCRIPTOR_TO_PB_FUNCTION)).build();
ApiFuture<ListMonitoredResourceDescriptorsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
Page<MonitoredResourceDescriptor> page = logging.listMonitoredResourceDescriptors();
assertEquals(cursor, page.getNextPageToken());
assertArrayEquals(descriptorList.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
Aggregations