use of com.google.cloud.compute.v1.AcceleratorTypesClient.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());
}
use of com.google.cloud.compute.v1.AcceleratorTypesClient.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());
}
use of com.google.cloud.compute.v1.AcceleratorTypesClient.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;
}
}
use of com.google.cloud.compute.v1.AcceleratorTypesClient.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());
}
use of com.google.cloud.compute.v1.AcceleratorTypesClient.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());
}
Aggregations