Search in sources :

Example 1 with ListKeyRingsPagedResponse

use of com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse 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 2 with ListKeyRingsPagedResponse

use of com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse in project java-docs-samples by GoogleCloudPlatform.

the class Quickstart method quickstart.

public void quickstart(String projectId, String locationId) throws IOException {
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
        // Build the parent from the project and location.
        LocationName parent = LocationName.of(projectId, locationId);
        // Call the API.
        ListKeyRingsPagedResponse response = client.listKeyRings(parent);
        // Iterate over each key ring and print its name.
        System.out.println("key rings:");
        for (KeyRing keyRing : response.iterateAll()) {
            System.out.printf("%s%n", keyRing.getName());
        }
    }
}
Also used : ListKeyRingsPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse) KeyRing(com.google.cloud.kms.v1.KeyRing) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient) LocationName(com.google.cloud.kms.v1.LocationName)

Example 3 with ListKeyRingsPagedResponse

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

the class Quickstart method quickstart.

public void quickstart(String projectId, String locationId) throws IOException {
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
        // Build the parent from the project and location.
        LocationName parent = LocationName.of(projectId, locationId);
        // Call the API.
        ListKeyRingsPagedResponse response = client.listKeyRings(parent);
        // Iterate over each key ring and print its name.
        System.out.println("key rings:");
        for (KeyRing keyRing : response.iterateAll()) {
            System.out.printf("%s%n", keyRing.getName());
        }
    }
}
Also used : ListKeyRingsPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse) KeyRing(com.google.cloud.kms.v1.KeyRing) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient) LocationName(com.google.cloud.kms.v1.LocationName)

Example 4 with ListKeyRingsPagedResponse

use of com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse 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 KeyManagementServiceClient (com.google.cloud.kms.v1.KeyManagementServiceClient)2 KeyRing (com.google.cloud.kms.v1.KeyRing)2 LocationName (com.google.cloud.kms.v1.LocationName)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 ByteString (com.google.protobuf.ByteString)1