Search in sources :

Example 1 with ListLocationsRequest

use of com.google.cloud.location.ListLocationsRequest in project gapic-generator-java by googleapis.

the class KeyManagementServiceClientTest method listLocationsExceptionTest.

@Test
public void listLocationsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockLocations.addException(exception);
    try {
        ListLocationsRequest request = ListLocationsRequest.newBuilder().setName("name3373707").setFilter("filter-1274492040").setPageSize(883849137).setPageToken("pageToken873572522").build();
        client.listLocations(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ListLocationsRequest(com.google.cloud.location.ListLocationsRequest) Test(org.junit.Test)

Example 2 with ListLocationsRequest

use of com.google.cloud.location.ListLocationsRequest in project gapic-generator-java by googleapis.

the class AsyncListLocations method asyncListLocations.

public static void asyncListLocations() throws Exception {
    // It may require modifications to work in your environment.
    try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
        ListLocationsRequest request = ListLocationsRequest.newBuilder().setName("name3373707").setFilter("filter-1274492040").setPageSize(883849137).setPageToken("pageToken873572522").build();
        ApiFuture<Location> future = keyManagementServiceClient.listLocationsPagedCallable().futureCall(request);
        // Do something.
        for (Location element : future.get().iterateAll()) {
        // doThingsWith(element);
        }
    }
}
Also used : ListLocationsRequest(com.google.cloud.location.ListLocationsRequest) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient) Location(com.google.cloud.location.Location)

Example 3 with ListLocationsRequest

use of com.google.cloud.location.ListLocationsRequest in project gapic-generator-java by googleapis.

the class AsyncListLocationsPaged method asyncListLocationsPaged.

public static void asyncListLocationsPaged() throws Exception {
    // It may require modifications to work in your environment.
    try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
        ListLocationsRequest request = ListLocationsRequest.newBuilder().setName("name3373707").setFilter("filter-1274492040").setPageSize(883849137).setPageToken("pageToken873572522").build();
        while (true) {
            ListLocationsResponse response = keyManagementServiceClient.listLocationsCallable().call(request);
            for (Location element : response.getResponsesList()) {
            // doThingsWith(element);
            }
            String nextPageToken = response.getNextPageToken();
            if (!Strings.isNullOrEmpty(nextPageToken)) {
                request = request.toBuilder().setPageToken(nextPageToken).build();
            } else {
                break;
            }
        }
    }
}
Also used : ListLocationsResponse(com.google.cloud.location.ListLocationsResponse) ListLocationsRequest(com.google.cloud.location.ListLocationsRequest) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient) Location(com.google.cloud.location.Location)

Example 4 with ListLocationsRequest

use of com.google.cloud.location.ListLocationsRequest in project gapic-generator-java by googleapis.

the class KeyManagementServiceClientTest method listLocationsTest.

@Test
public void listLocationsTest() throws Exception {
    Location responsesElement = Location.newBuilder().build();
    ListLocationsResponse expectedResponse = ListLocationsResponse.newBuilder().setNextPageToken("").addAllLocations(Arrays.asList(responsesElement)).build();
    mockLocations.addResponse(expectedResponse);
    ListLocationsRequest request = ListLocationsRequest.newBuilder().setName("name3373707").setFilter("filter-1274492040").setPageSize(883849137).setPageToken("pageToken873572522").build();
    ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
    List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockLocations.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListLocationsRequest actualRequest = ((ListLocationsRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertEquals(request.getFilter(), actualRequest.getFilter());
    Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
    Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListLocationsPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListLocationsPagedResponse) ListLocationsResponse(com.google.cloud.location.ListLocationsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListLocationsRequest(com.google.cloud.location.ListLocationsRequest) Location(com.google.cloud.location.Location) Test(org.junit.Test)

Example 5 with ListLocationsRequest

use of com.google.cloud.location.ListLocationsRequest in project java-datastream by googleapis.

the class DatastreamClientTest method listLocationsTest.

@Test
public void listLocationsTest() throws Exception {
    Location responsesElement = Location.newBuilder().build();
    ListLocationsResponse expectedResponse = ListLocationsResponse.newBuilder().setNextPageToken("").addAllLocations(Arrays.asList(responsesElement)).build();
    mockLocations.addResponse(expectedResponse);
    ListLocationsRequest request = ListLocationsRequest.newBuilder().setName("name3373707").setFilter("filter-1274492040").setPageSize(883849137).setPageToken("pageToken873572522").build();
    ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
    List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockLocations.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListLocationsRequest actualRequest = ((ListLocationsRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertEquals(request.getFilter(), actualRequest.getFilter());
    Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
    Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListLocationsPagedResponse(com.google.cloud.datastream.v1.DatastreamClient.ListLocationsPagedResponse) ListLocationsResponse(com.google.cloud.location.ListLocationsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListLocationsRequest(com.google.cloud.location.ListLocationsRequest) Location(com.google.cloud.location.Location) Test(org.junit.Test)

Aggregations

ListLocationsRequest (com.google.cloud.location.ListLocationsRequest)8 Test (org.junit.Test)6 Location (com.google.cloud.location.Location)5 ListLocationsResponse (com.google.cloud.location.ListLocationsResponse)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 KeyManagementServiceClient (com.google.cloud.kms.v1.KeyManagementServiceClient)2 ListLocationsPagedResponse (com.google.cloud.datastream.v1.DatastreamClient.ListLocationsPagedResponse)1 ListLocationsPagedResponse (com.google.cloud.kms.v1.KeyManagementServiceClient.ListLocationsPagedResponse)1 ListLocationsPagedResponse (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.ListLocationsPagedResponse)1