use of com.google.cloud.security.privateca.v1.ListCertificatesRequest in project java-security-private-ca by googleapis.
the class CertificateAuthorityServiceClientTest method listCertificatesTest2.
@Test
public void listCertificatesTest2() throws Exception {
Certificate responsesElement = Certificate.newBuilder().build();
ListCertificatesResponse expectedResponse = ListCertificatesResponse.newBuilder().setNextPageToken("").addAllCertificates(Arrays.asList(responsesElement)).build();
mockCertificateAuthorityService.addResponse(expectedResponse);
String parent = "parent-995424086";
ListCertificatesPagedResponse pagedListResponse = client.listCertificates(parent);
List<Certificate> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getCertificatesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockCertificateAuthorityService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListCertificatesRequest actualRequest = ((ListCertificatesRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.security.privateca.v1.ListCertificatesRequest in project java-security-private-ca by googleapis.
the class CertificateAuthorityServiceClientTest method listCertificatesTest.
@Test
public void listCertificatesTest() throws Exception {
Certificate responsesElement = Certificate.newBuilder().build();
ListCertificatesResponse expectedResponse = ListCertificatesResponse.newBuilder().setNextPageToken("").addAllCertificates(Arrays.asList(responsesElement)).build();
mockCertificateAuthorityService.addResponse(expectedResponse);
CaPoolName parent = CaPoolName.of("[PROJECT]", "[LOCATION]", "[CA_POOL]");
ListCertificatesPagedResponse pagedListResponse = client.listCertificates(parent);
List<Certificate> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getCertificatesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockCertificateAuthorityService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListCertificatesRequest actualRequest = ((ListCertificatesRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.security.privateca.v1.ListCertificatesRequest in project java-security-private-ca by googleapis.
the class FilterCertificates method filterCertificates.
// Filter certificates based on a condition and list them.
public static void filterCertificates(String project, String location, String pool_Id) throws IOException {
// clean up any remaining background resources.
try (CertificateAuthorityServiceClient certificateAuthorityServiceClient = CertificateAuthorityServiceClient.create()) {
CaPoolName caPool = CaPoolName.newBuilder().setProject(project).setLocation(location).setCaPool(pool_Id).build();
// Create the certificate request and set the filter condition.
ListCertificatesRequest listCertificatesRequest = ListCertificatesRequest.newBuilder().setParent(caPool.toString()).setFilter("certificate_description.subject_description.subject.organization=csr-org-name").build();
// Retrieve and print the certificate names.
System.out.println("Available certificates: ");
for (Certificate certificate : certificateAuthorityServiceClient.listCertificates(listCertificatesRequest).iterateAll()) {
System.out.println(certificate.getName());
}
}
}
Aggregations