Search in sources :

Example 1 with DeleteKeyRequest

use of com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceV1Beta1ClientTest method deleteKeyTest.

@Test
public void deleteKeyTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
    DeleteKeyRequest request = DeleteKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
    client.deleteKey(request);
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteKeyRequest actualRequest = ((DeleteKeyRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteKeyRequest(com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest) Test(org.junit.Test)

Example 2 with DeleteKeyRequest

use of com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceV1Beta1ClientTest method deleteKeyExceptionTest.

@Test
public void deleteKeyExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockRecaptchaEnterpriseServiceV1Beta1.addException(exception);
    try {
        DeleteKeyRequest request = DeleteKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
        client.deleteKey(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) DeleteKeyRequest(com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest) Test(org.junit.Test)

Example 3 with DeleteKeyRequest

use of com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest in project java-recaptchaenterprise by googleapis.

the class DeleteSiteKey method deleteSiteKey.

/**
 * Delete the given reCAPTCHA site key present under the project ID.
 *
 * @param projectID: GCloud Project ID.
 * @param recaptchaSiteKey: Specify the site key to be deleted.
 */
public static void deleteSiteKey(String projectID, String recaptchaSiteKey) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // clean up any remaining background resources.
    try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
        // Set the project ID and reCAPTCHA site key.
        DeleteKeyRequest deleteKeyRequest = DeleteKeyRequest.newBuilder().setName(KeyName.of(projectID, recaptchaSiteKey).toString()).build();
        client.deleteKeyCallable().futureCall(deleteKeyRequest).get(5, TimeUnit.SECONDS);
        System.out.println("reCAPTCHA Site key successfully deleted !");
    }
}
Also used : DeleteKeyRequest(com.google.recaptchaenterprise.v1.DeleteKeyRequest) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Example 4 with DeleteKeyRequest

use of com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceClientTest method deleteKeyTest.

@Test
public void deleteKeyTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockRecaptchaEnterpriseService.addResponse(expectedResponse);
    DeleteKeyRequest request = DeleteKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
    client.deleteKey(request);
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteKeyRequest actualRequest = ((DeleteKeyRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteKeyRequest(com.google.recaptchaenterprise.v1.DeleteKeyRequest) Test(org.junit.Test)

Example 5 with DeleteKeyRequest

use of com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceClientTest method deleteKeyExceptionTest.

@Test
public void deleteKeyExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockRecaptchaEnterpriseService.addException(exception);
    try {
        DeleteKeyRequest request = DeleteKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
        client.deleteKey(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) DeleteKeyRequest(com.google.recaptchaenterprise.v1.DeleteKeyRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 DeleteKeyRequest (com.google.recaptchaenterprise.v1.DeleteKeyRequest)3 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Empty (com.google.protobuf.Empty)2 DeleteKeyRequest (com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 RecaptchaEnterpriseServiceClient (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)1