Search in sources :

Example 1 with ListCryptoKeysResponse

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

the class KeyManagementServiceClientTest method listCryptoKeysTest.

@Test
public void listCryptoKeysTest() throws Exception {
    CryptoKey responsesElement = CryptoKey.newBuilder().build();
    ListCryptoKeysResponse expectedResponse = ListCryptoKeysResponse.newBuilder().setNextPageToken("").addAllCryptoKeys(Arrays.asList(responsesElement)).build();
    mockKeyManagementService.addResponse(expectedResponse);
    KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
    ListCryptoKeysPagedResponse pagedListResponse = client.listCryptoKeys(parent);
    List<CryptoKey> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getCryptoKeysList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockKeyManagementService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListCryptoKeysRequest actualRequest = ((ListCryptoKeysRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListCryptoKeysPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListCryptoKeysPagedResponse) Test(org.junit.Test)

Example 2 with ListCryptoKeysResponse

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

the class KeyManagementServiceClientTest method listCryptoKeysTest.

@Test
public void listCryptoKeysTest() throws Exception {
    CryptoKey responsesElement = CryptoKey.newBuilder().build();
    ListCryptoKeysResponse expectedResponse = ListCryptoKeysResponse.newBuilder().setNextPageToken("").addAllCryptoKeys(Arrays.asList(responsesElement)).build();
    mockKeyManagementService.addResponse(expectedResponse);
    KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
    ListCryptoKeysPagedResponse pagedListResponse = client.listCryptoKeys(parent);
    List<CryptoKey> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getCryptoKeysList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockKeyManagementService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListCryptoKeysRequest actualRequest = ((ListCryptoKeysRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListCryptoKeysPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListCryptoKeysPagedResponse) Test(org.junit.Test)

Example 3 with ListCryptoKeysResponse

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

the class KeyManagementServiceClientTest method listCryptoKeysTest2.

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

Example 4 with ListCryptoKeysResponse

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

the class AsyncListCryptoKeysPaged method asyncListCryptoKeysPaged.

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

Example 5 with ListCryptoKeysResponse

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

the class KeyManagementServiceClientTest method listCryptoKeysTest2.

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

Aggregations

ListCryptoKeysPagedResponse (com.google.cloud.kms.v1.KeyManagementServiceClient.ListCryptoKeysPagedResponse)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 Test (org.junit.Test)4 ByteString (com.google.protobuf.ByteString)2 CryptoKey (com.google.cloud.kms.v1.CryptoKey)1 KeyManagementServiceClient (com.google.cloud.kms.v1.KeyManagementServiceClient)1 ListCryptoKeysRequest (com.google.cloud.kms.v1.ListCryptoKeysRequest)1 ListCryptoKeysResponse (com.google.cloud.kms.v1.ListCryptoKeysResponse)1