Search in sources :

Example 41 with ListPagedResponse

use of com.google.cloud.compute.v1.DiskTypesClient.ListPagedResponse in project java-compute by googleapis.

the class SnapshotsClientTest method listTest.

@Test
public void listTest() throws Exception {
    Snapshot responsesElement = Snapshot.newBuilder().build();
    SnapshotList expectedResponse = SnapshotList.newBuilder().setNextPageToken("").addAllItems(Arrays.asList(responsesElement)).build();
    mockService.addResponse(expectedResponse);
    String project = "project-6911";
    ListPagedResponse pagedListResponse = client.list(project);
    List<Snapshot> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getItemsList().get(0), 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 : ListPagedResponse(com.google.cloud.compute.v1.SnapshotsClient.ListPagedResponse) Test(org.junit.Test)

Example 42 with ListPagedResponse

use of com.google.cloud.compute.v1.DiskTypesClient.ListPagedResponse in project java-compute by googleapis.

the class AcceleratorTypesClientTest method listTest.

@Test
public void listTest() throws Exception {
    AcceleratorType responsesElement = AcceleratorType.newBuilder().build();
    AcceleratorTypeList expectedResponse = AcceleratorTypeList.newBuilder().setNextPageToken("").addAllItems(Arrays.asList(responsesElement)).build();
    mockService.addResponse(expectedResponse);
    String project = "project-6911";
    String zone = "zone-5246";
    ListPagedResponse pagedListResponse = client.list(project, zone);
    List<AcceleratorType> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getItemsList().get(0), 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 : ListPagedResponse(com.google.cloud.compute.v1.AcceleratorTypesClient.ListPagedResponse) AggregatedListPagedResponse(com.google.cloud.compute.v1.AcceleratorTypesClient.AggregatedListPagedResponse) Test(org.junit.Test)

Example 43 with ListPagedResponse

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

the class PreemptibleIT method testListZoneOperations.

@Test
public void testListZoneOperations() throws IOException {
    String filter = String.format("targetLink=\"https://www.googleapis.com/compute/v1/projects/%s/zones/%s/instances/%s\"", PROJECT_ID, ZONE, INSTANCE_NAME);
    ListPagedResponse response = ListZoneOperations.listZoneOperations(PROJECT_ID, ZONE, filter);
    boolean elementPresent = false;
    for (Operation operation : response.iterateAll()) {
        elementPresent = true;
        break;
    }
    assertWithMessage("There should be at least one operation for this instance at this point.").that(elementPresent).isTrue();
}
Also used : ListPagedResponse(com.google.cloud.compute.v1.ZoneOperationsClient.ListPagedResponse) Operation(com.google.cloud.compute.v1.Operation) Test(org.junit.jupiter.api.Test)

Example 44 with ListPagedResponse

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

the class ListInstanceTemplates method listInstanceTemplates.

// Get a list of InstanceTemplate objects available in a project.
public static ListPagedResponse listInstanceTemplates(String projectId) throws IOException {
    try (InstanceTemplatesClient instanceTemplatesClient = InstanceTemplatesClient.create()) {
        int count = 0;
        System.out.println("Listing instance templates...");
        ListPagedResponse templates = instanceTemplatesClient.list(projectId);
        for (InstanceTemplate instanceTemplate : templates.iterateAll()) {
            System.out.printf("%s. %s%n", ++count, instanceTemplate.getName());
        }
        return templates;
    }
}
Also used : ListPagedResponse(com.google.cloud.compute.v1.InstanceTemplatesClient.ListPagedResponse) InstanceTemplatesClient(com.google.cloud.compute.v1.InstanceTemplatesClient) InstanceTemplate(com.google.cloud.compute.v1.InstanceTemplate)

Example 45 with ListPagedResponse

use of com.google.cloud.compute.v1.DiskTypesClient.ListPagedResponse in project java-compute by googleapis.

the class ImagesClientTest method listTest.

@Test
public void listTest() throws Exception {
    Image responsesElement = Image.newBuilder().build();
    ImageList expectedResponse = ImageList.newBuilder().setNextPageToken("").addAllItems(Arrays.asList(responsesElement)).build();
    mockService.addResponse(expectedResponse);
    String project = "project-6911";
    ListPagedResponse pagedListResponse = client.list(project);
    List<Image> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getItemsList().get(0), 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 : ListPagedResponse(com.google.cloud.compute.v1.ImagesClient.ListPagedResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)77 ListPagedResponse (com.google.cloud.compute.v1.InstanceTemplatesClient.ListPagedResponse)2 ListPagedResponse (com.google.cloud.compute.v1.ZoneOperationsClient.ListPagedResponse)2 AggregatedListPagedResponse (com.google.cloud.compute.v1.AcceleratorTypesClient.AggregatedListPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.AcceleratorTypesClient.ListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.AddressesClient.AggregatedListPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.AddressesClient.ListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.AutoscalersClient.AggregatedListPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.AutoscalersClient.ListPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.BackendBucketsClient.ListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.BackendServicesClient.AggregatedListPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.BackendServicesClient.ListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.DiskTypesClient.AggregatedListPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.DiskTypesClient.ListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.DisksClient.AggregatedListPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.DisksClient.ListPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.ExternalVpnGatewaysClient.ListPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.FirewallPoliciesClient.ListPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.FirewallsClient.ListPagedResponse)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.ForwardingRulesClient.AggregatedListPagedResponse)1