Search in sources :

Example 1 with ListKeyRingsRequest

use of com.google.cloud.kms.v1.ListKeyRingsRequest in project gapic-generator-java by googleapis.

the class KeyManagementServiceClientTest method listKeyRingsTest2.

@Test
public void listKeyRingsTest2() throws Exception {
    KeyRing responsesElement = KeyRing.newBuilder().build();
    ListKeyRingsResponse expectedResponse = ListKeyRingsResponse.newBuilder().setNextPageToken("").addAllKeyRings(Arrays.asList(responsesElement)).build();
    mockKeyManagementService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListKeyRingsPagedResponse pagedListResponse = client.listKeyRings(parent);
    List<KeyRing> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getKeyRingsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockKeyManagementService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListKeyRingsRequest actualRequest = ((ListKeyRingsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListKeyRingsPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 2 with ListKeyRingsRequest

use of com.google.cloud.kms.v1.ListKeyRingsRequest in project gapic-generator-java by googleapis.

the class KeyManagementServiceClientTest method listKeyRingsTest.

@Test
public void listKeyRingsTest() throws Exception {
    KeyRing responsesElement = KeyRing.newBuilder().build();
    ListKeyRingsResponse expectedResponse = ListKeyRingsResponse.newBuilder().setNextPageToken("").addAllKeyRings(Arrays.asList(responsesElement)).build();
    mockKeyManagementService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListKeyRingsPagedResponse pagedListResponse = client.listKeyRings(parent);
    List<KeyRing> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getKeyRingsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockKeyManagementService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListKeyRingsRequest actualRequest = ((ListKeyRingsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListKeyRingsPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 3 with ListKeyRingsRequest

use of com.google.cloud.kms.v1.ListKeyRingsRequest in project gapic-generator-java by googleapis.

the class AsyncListKeyRingsPaged method asyncListKeyRingsPaged.

public static void asyncListKeyRingsPaged() throws Exception {
    // It may require modifications to work in your environment.
    try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
        ListKeyRingsRequest request = ListKeyRingsRequest.newBuilder().setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").setFilter("filter-1274492040").setOrderBy("orderBy-1207110587").build();
        while (true) {
            ListKeyRingsResponse response = keyManagementServiceClient.listKeyRingsCallable().call(request);
            for (KeyRing element : response.getResponsesList()) {
            // doThingsWith(element);
            }
            String nextPageToken = response.getNextPageToken();
            if (!Strings.isNullOrEmpty(nextPageToken)) {
                request = request.toBuilder().setPageToken(nextPageToken).build();
            } else {
                break;
            }
        }
    }
}
Also used : KeyRing(com.google.cloud.kms.v1.KeyRing) ListKeyRingsResponse(com.google.cloud.kms.v1.ListKeyRingsResponse) ListKeyRingsRequest(com.google.cloud.kms.v1.ListKeyRingsRequest) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient)

Example 4 with ListKeyRingsRequest

use of com.google.cloud.kms.v1.ListKeyRingsRequest in project java-kms by googleapis.

the class KeyManagementServiceClientTest method listKeyRingsTest2.

@Test
public void listKeyRingsTest2() throws Exception {
    KeyRing responsesElement = KeyRing.newBuilder().build();
    ListKeyRingsResponse expectedResponse = ListKeyRingsResponse.newBuilder().setNextPageToken("").addAllKeyRings(Arrays.asList(responsesElement)).build();
    mockKeyManagementService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListKeyRingsPagedResponse pagedListResponse = client.listKeyRings(parent);
    List<KeyRing> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getKeyRingsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockKeyManagementService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListKeyRingsRequest actualRequest = ((ListKeyRingsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListKeyRingsPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 5 with ListKeyRingsRequest

use of com.google.cloud.kms.v1.ListKeyRingsRequest in project java-kms by googleapis.

the class KeyManagementServiceClientTest method listKeyRingsTest.

@Test
public void listKeyRingsTest() throws Exception {
    KeyRing responsesElement = KeyRing.newBuilder().build();
    ListKeyRingsResponse expectedResponse = ListKeyRingsResponse.newBuilder().setNextPageToken("").addAllKeyRings(Arrays.asList(responsesElement)).build();
    mockKeyManagementService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListKeyRingsPagedResponse pagedListResponse = client.listKeyRings(parent);
    List<KeyRing> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getKeyRingsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockKeyManagementService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListKeyRingsRequest actualRequest = ((ListKeyRingsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListKeyRingsPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Aggregations

ListKeyRingsPagedResponse (com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 Test (org.junit.Test)4 KeyManagementServiceClient (com.google.cloud.kms.v1.KeyManagementServiceClient)2 KeyRing (com.google.cloud.kms.v1.KeyRing)2 ListKeyRingsRequest (com.google.cloud.kms.v1.ListKeyRingsRequest)2 ByteString (com.google.protobuf.ByteString)2 ListKeyRingsResponse (com.google.cloud.kms.v1.ListKeyRingsResponse)1