Search in sources :

Example 1 with ListMonitoredResourceDescriptorsRequest

use of com.google.logging.v2.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());
}
Also used : ListMonitoredResourceDescriptorsResponse(com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse) ProjectName(com.google.monitoring.v3.ProjectName) ListMonitoredResourceDescriptorsRequest(com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor) ListMonitoredResourceDescriptorsPagedResponse(com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMonitoredResourceDescriptorsPagedResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 2 with ListMonitoredResourceDescriptorsRequest

use of com.google.logging.v2.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));
}
Also used : ListMonitoredResourceDescriptorsResponse(com.google.logging.v2.ListMonitoredResourceDescriptorsResponse) ListMonitoredResourceDescriptorsRequest(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.cloud.MonitoredResourceDescriptor) Test(org.junit.Test)

Example 3 with ListMonitoredResourceDescriptorsRequest

use of com.google.logging.v2.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));
}
Also used : ListMonitoredResourceDescriptorsResponse(com.google.logging.v2.ListMonitoredResourceDescriptorsResponse) ListMonitoredResourceDescriptorsRequest(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.cloud.MonitoredResourceDescriptor) Test(org.junit.Test)

Example 4 with ListMonitoredResourceDescriptorsRequest

use of com.google.logging.v2.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));
}
Also used : ListMonitoredResourceDescriptorsResponse(com.google.logging.v2.ListMonitoredResourceDescriptorsResponse) ListMonitoredResourceDescriptorsRequest(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.cloud.MonitoredResourceDescriptor) Test(org.junit.Test)

Example 5 with ListMonitoredResourceDescriptorsRequest

use of com.google.logging.v2.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));
}
Also used : ListMonitoredResourceDescriptorsResponse(com.google.logging.v2.ListMonitoredResourceDescriptorsResponse) ListMonitoredResourceDescriptorsRequest(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.cloud.MonitoredResourceDescriptor) Test(org.junit.Test)

Aggregations

MonitoredResourceDescriptor (com.google.cloud.MonitoredResourceDescriptor)9 ListMonitoredResourceDescriptorsRequest (com.google.logging.v2.ListMonitoredResourceDescriptorsRequest)9 ListMonitoredResourceDescriptorsResponse (com.google.logging.v2.ListMonitoredResourceDescriptorsResponse)9 Test (org.junit.Test)9 MonitoredResourceDescriptor (com.google.api.MonitoredResourceDescriptor)1 AsyncPage (com.google.api.gax.paging.AsyncPage)1 ListMonitoredResourceDescriptorsPagedResponse (com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMonitoredResourceDescriptorsPagedResponse)1 ImmutableList (com.google.common.collect.ImmutableList)1 ListMonitoredResourceDescriptorsRequest (com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest)1 ListMonitoredResourceDescriptorsResponse (com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse)1 ProjectName (com.google.monitoring.v3.ProjectName)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1