Search in sources :

Example 1 with ListCertificateTemplatesResponse

use of com.google.cloud.security.privateca.v1.ListCertificateTemplatesResponse in project java-security-private-ca by googleapis.

the class CertificateAuthorityServiceClientTest method listCertificateTemplatesTest2.

@Test
public void listCertificateTemplatesTest2() throws Exception {
    CertificateTemplate responsesElement = CertificateTemplate.newBuilder().build();
    ListCertificateTemplatesResponse expectedResponse = ListCertificateTemplatesResponse.newBuilder().setNextPageToken("").addAllCertificateTemplates(Arrays.asList(responsesElement)).build();
    mockCertificateAuthorityService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListCertificateTemplatesPagedResponse pagedListResponse = client.listCertificateTemplates(parent);
    List<CertificateTemplate> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getCertificateTemplatesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockCertificateAuthorityService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListCertificateTemplatesRequest actualRequest = ((ListCertificateTemplatesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListCertificateTemplatesPagedResponse(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.ListCertificateTemplatesPagedResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 2 with ListCertificateTemplatesResponse

use of com.google.cloud.security.privateca.v1.ListCertificateTemplatesResponse in project java-security-private-ca by googleapis.

the class CertificateAuthorityServiceClientTest method listCertificateTemplatesTest.

@Test
public void listCertificateTemplatesTest() throws Exception {
    CertificateTemplate responsesElement = CertificateTemplate.newBuilder().build();
    ListCertificateTemplatesResponse expectedResponse = ListCertificateTemplatesResponse.newBuilder().setNextPageToken("").addAllCertificateTemplates(Arrays.asList(responsesElement)).build();
    mockCertificateAuthorityService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListCertificateTemplatesPagedResponse pagedListResponse = client.listCertificateTemplates(parent);
    List<CertificateTemplate> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getCertificateTemplatesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockCertificateAuthorityService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListCertificateTemplatesRequest actualRequest = ((ListCertificateTemplatesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListCertificateTemplatesPagedResponse(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.ListCertificateTemplatesPagedResponse) Test(org.junit.Test)

Example 3 with ListCertificateTemplatesResponse

use of com.google.cloud.security.privateca.v1.ListCertificateTemplatesResponse in project java-security-private-ca by googleapis.

the class ListCertificateTemplates method listCertificateTemplates.

// Lists the certificate templates present in the given project and location.
public static void listCertificateTemplates(String project, String location) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    /* Initialize client that will be used to send requests. This client only needs to be created
    once, and can be reused for multiple requests. After completing all of your requests, call
    the `certificateAuthorityServiceClient.close()` method on the client to safely
    clean up any remaining background resources. */
    try (CertificateAuthorityServiceClient certificateAuthorityServiceClient = CertificateAuthorityServiceClient.create()) {
        // Set the parent name to list the certificate templates.
        ListCertificateTemplatesRequest request = ListCertificateTemplatesRequest.newBuilder().setParent(LocationName.of(project, location).toString()).build();
        ApiFuture<ListCertificateTemplatesResponse> futureCall = certificateAuthorityServiceClient.listCertificateTemplatesCallable().futureCall(request);
        // Get the response.
        ListCertificateTemplatesResponse response = futureCall.get(60, TimeUnit.SECONDS);
        // List all templates.
        for (CertificateTemplate template : response.getCertificateTemplatesList()) {
            System.out.println(template.getName());
        }
    }
}
Also used : CertificateTemplate(com.google.cloud.security.privateca.v1.CertificateTemplate) ListCertificateTemplatesResponse(com.google.cloud.security.privateca.v1.ListCertificateTemplatesResponse) CertificateAuthorityServiceClient(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient) ListCertificateTemplatesRequest(com.google.cloud.security.privateca.v1.ListCertificateTemplatesRequest)

Aggregations

ListCertificateTemplatesPagedResponse (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.ListCertificateTemplatesPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 CertificateAuthorityServiceClient (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient)1 CertificateTemplate (com.google.cloud.security.privateca.v1.CertificateTemplate)1 ListCertificateTemplatesRequest (com.google.cloud.security.privateca.v1.ListCertificateTemplatesRequest)1 ListCertificateTemplatesResponse (com.google.cloud.security.privateca.v1.ListCertificateTemplatesResponse)1 ByteString (com.google.protobuf.ByteString)1