Search in sources :

Example 16 with AggregatedListPagedResponse

use of com.google.cloud.compute.v1.MachineTypesClient.AggregatedListPagedResponse in project java-compute by googleapis.

the class AddressesClientTest method aggregatedListTest.

@Test
public void aggregatedListTest() throws Exception {
    AddressesScopedList responsesElement = AddressesScopedList.newBuilder().build();
    AddressAggregatedList expectedResponse = AddressAggregatedList.newBuilder().setNextPageToken("").putAllItems(Collections.singletonMap("items", responsesElement)).build();
    mockService.addResponse(expectedResponse);
    String project = "project-6911";
    AggregatedListPagedResponse pagedListResponse = client.aggregatedList(project);
    List<Map.Entry<String, AddressesScopedList>> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getItemsMap().entrySet().iterator().next(), resources.get(0));
    List<String> actualRequests = mockService.getRequestPaths();
    Assert.assertEquals(1, actualRequests.size());
    String apiClientHeaderKey = mockService.getRequestHeaders().get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()).iterator().next();
    Assert.assertTrue(GaxHttpJsonProperties.getDefaultApiClientHeaderPattern().matcher(apiClientHeaderKey).matches());
}
Also used : AggregatedListPagedResponse(com.google.cloud.compute.v1.AddressesClient.AggregatedListPagedResponse) Test(org.junit.Test)

Example 17 with AggregatedListPagedResponse

use of com.google.cloud.compute.v1.MachineTypesClient.AggregatedListPagedResponse in project java-compute by googleapis.

the class AutoscalersClientTest method aggregatedListTest.

@Test
public void aggregatedListTest() throws Exception {
    AutoscalersScopedList responsesElement = AutoscalersScopedList.newBuilder().build();
    AutoscalerAggregatedList expectedResponse = AutoscalerAggregatedList.newBuilder().setNextPageToken("").putAllItems(Collections.singletonMap("items", responsesElement)).build();
    mockService.addResponse(expectedResponse);
    String project = "project-6911";
    AggregatedListPagedResponse pagedListResponse = client.aggregatedList(project);
    List<Map.Entry<String, AutoscalersScopedList>> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getItemsMap().entrySet().iterator().next(), resources.get(0));
    List<String> actualRequests = mockService.getRequestPaths();
    Assert.assertEquals(1, actualRequests.size());
    String apiClientHeaderKey = mockService.getRequestHeaders().get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()).iterator().next();
    Assert.assertTrue(GaxHttpJsonProperties.getDefaultApiClientHeaderPattern().matcher(apiClientHeaderKey).matches());
}
Also used : AggregatedListPagedResponse(com.google.cloud.compute.v1.AutoscalersClient.AggregatedListPagedResponse) Test(org.junit.Test)

Example 18 with AggregatedListPagedResponse

use of com.google.cloud.compute.v1.MachineTypesClient.AggregatedListPagedResponse in project java-docs-samples by GoogleCloudPlatform.

the class ListAllInstances method listAllInstances.

// List all instances in the specified project ID.
public static AggregatedListPagedResponse listAllInstances(String project) throws IOException {
    // safely clean up any remaining background resources.
    try (InstancesClient instancesClient = InstancesClient.create()) {
        // Use the `setMaxResults` parameter to limit the number of results
        // that the API returns per response page.
        AggregatedListInstancesRequest aggregatedListInstancesRequest = AggregatedListInstancesRequest.newBuilder().setProject(project).setMaxResults(5).build();
        InstancesClient.AggregatedListPagedResponse response = instancesClient.aggregatedList(aggregatedListInstancesRequest);
        // automatically, requesting next pages as you iterate over the results.
        for (Map.Entry<String, InstancesScopedList> zoneInstances : response.iterateAll()) {
            // Instances scoped by each zone
            String zone = zoneInstances.getKey();
            if (!zoneInstances.getValue().getInstancesList().isEmpty()) {
                // zoneInstances.getKey() returns the fully qualified address.
                // Hence, strip it to get the zone name only
                System.out.printf("Instances at %s: ", zone.substring(zone.lastIndexOf('/') + 1));
                for (Instance instance : zoneInstances.getValue().getInstancesList()) {
                    System.out.println(instance.getName());
                }
            }
        }
        System.out.println("####### Listing all instances complete #######");
        return response;
    }
}
Also used : InstancesScopedList(com.google.cloud.compute.v1.InstancesScopedList) Instance(com.google.cloud.compute.v1.Instance) AggregatedListPagedResponse(com.google.cloud.compute.v1.InstancesClient.AggregatedListPagedResponse) InstancesClient(com.google.cloud.compute.v1.InstancesClient) AggregatedListInstancesRequest(com.google.cloud.compute.v1.AggregatedListInstancesRequest) Map(java.util.Map)

Example 19 with AggregatedListPagedResponse

use of com.google.cloud.compute.v1.MachineTypesClient.AggregatedListPagedResponse in project java-compute by googleapis.

the class InstancesClientTest method aggregatedListTest.

@Test
public void aggregatedListTest() throws Exception {
    InstancesScopedList responsesElement = InstancesScopedList.newBuilder().build();
    InstanceAggregatedList expectedResponse = InstanceAggregatedList.newBuilder().setNextPageToken("").putAllItems(Collections.singletonMap("items", responsesElement)).build();
    mockService.addResponse(expectedResponse);
    String project = "project-6911";
    AggregatedListPagedResponse pagedListResponse = client.aggregatedList(project);
    List<Map.Entry<String, InstancesScopedList>> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getItemsMap().entrySet().iterator().next(), resources.get(0));
    List<String> actualRequests = mockService.getRequestPaths();
    Assert.assertEquals(1, actualRequests.size());
    String apiClientHeaderKey = mockService.getRequestHeaders().get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()).iterator().next();
    Assert.assertTrue(GaxHttpJsonProperties.getDefaultApiClientHeaderPattern().matcher(apiClientHeaderKey).matches());
}
Also used : AggregatedListPagedResponse(com.google.cloud.compute.v1.InstancesClient.AggregatedListPagedResponse) Test(org.junit.Test)

Example 20 with AggregatedListPagedResponse

use of com.google.cloud.compute.v1.MachineTypesClient.AggregatedListPagedResponse in project java-compute by googleapis.

the class InterconnectAttachmentsClientTest method aggregatedListTest.

@Test
public void aggregatedListTest() throws Exception {
    InterconnectAttachmentsScopedList responsesElement = InterconnectAttachmentsScopedList.newBuilder().build();
    InterconnectAttachmentAggregatedList expectedResponse = InterconnectAttachmentAggregatedList.newBuilder().setNextPageToken("").putAllItems(Collections.singletonMap("items", responsesElement)).build();
    mockService.addResponse(expectedResponse);
    String project = "project-6911";
    AggregatedListPagedResponse pagedListResponse = client.aggregatedList(project);
    List<Map.Entry<String, InterconnectAttachmentsScopedList>> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getItemsMap().entrySet().iterator().next(), resources.get(0));
    List<String> actualRequests = mockService.getRequestPaths();
    Assert.assertEquals(1, actualRequests.size());
    String apiClientHeaderKey = mockService.getRequestHeaders().get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()).iterator().next();
    Assert.assertTrue(GaxHttpJsonProperties.getDefaultApiClientHeaderPattern().matcher(apiClientHeaderKey).matches());
}
Also used : AggregatedListPagedResponse(com.google.cloud.compute.v1.InterconnectAttachmentsClient.AggregatedListPagedResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)35 AggregatedListPagedResponse (com.google.cloud.compute.v1.InstancesClient.AggregatedListPagedResponse)2 AggregatedListPagedResponse (com.google.cloud.compute.v1.AcceleratorTypesClient.AggregatedListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.AddressesClient.AggregatedListPagedResponse)1 AggregatedListInstancesRequest (com.google.cloud.compute.v1.AggregatedListInstancesRequest)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.AutoscalersClient.AggregatedListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.BackendServicesClient.AggregatedListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.DiskTypesClient.AggregatedListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.DisksClient.AggregatedListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.ForwardingRulesClient.AggregatedListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.GlobalOperationsClient.AggregatedListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.HealthChecksClient.AggregatedListPagedResponse)1 Instance (com.google.cloud.compute.v1.Instance)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.InstanceGroupManagersClient.AggregatedListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.InstanceGroupsClient.AggregatedListPagedResponse)1 InstancesClient (com.google.cloud.compute.v1.InstancesClient)1 InstancesScopedList (com.google.cloud.compute.v1.InstancesScopedList)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.InterconnectAttachmentsClient.AggregatedListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.MachineTypesClient.AggregatedListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.NetworkEndpointGroupsClient.AggregatedListPagedResponse)1