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()));
}
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());
}
}
}
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());
}
}
}
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()));
}
Aggregations