Search in sources :

Example 1 with ListKeysRequest

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

the class RecaptchaEnterpriseServiceClientTest method listKeysTest.

@Test
public void listKeysTest() throws Exception {
    Key responsesElement = Key.newBuilder().build();
    ListKeysResponse expectedResponse = ListKeysResponse.newBuilder().setNextPageToken("").addAllKeys(Arrays.asList(responsesElement)).build();
    mockRecaptchaEnterpriseService.addResponse(expectedResponse);
    ListKeysRequest request = ListKeysRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").build();
    ListKeysPagedResponse pagedListResponse = client.listKeys(request);
    List<Key> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getKeysList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListKeysRequest actualRequest = ((ListKeysRequest) actualRequests.get(0));
    Assert.assertEquals(request.getParent(), actualRequest.getParent());
    Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
    Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListKeysPagedResponse(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.ListKeysPagedResponse) ListKeysRequest(com.google.recaptchaenterprise.v1.ListKeysRequest) ListKeysResponse(com.google.recaptchaenterprise.v1.ListKeysResponse) Key(com.google.recaptchaenterprise.v1.Key) Test(org.junit.Test)

Example 2 with ListKeysRequest

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

the class RecaptchaEnterpriseServiceV1Beta1ClientTest method listKeysExceptionTest.

@Test
public void listKeysExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockRecaptchaEnterpriseServiceV1Beta1.addException(exception);
    try {
        ListKeysRequest request = ListKeysRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").build();
        client.listKeys(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ListKeysRequest(com.google.recaptchaenterprise.v1beta1.ListKeysRequest) Test(org.junit.Test)

Example 3 with ListKeysRequest

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

the class RecaptchaEnterpriseServiceV1Beta1ClientTest method listKeysTest.

@Test
public void listKeysTest() throws Exception {
    Key responsesElement = Key.newBuilder().build();
    ListKeysResponse expectedResponse = ListKeysResponse.newBuilder().setNextPageToken("").addAllKeys(Arrays.asList(responsesElement)).build();
    mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
    ListKeysRequest request = ListKeysRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").build();
    ListKeysPagedResponse pagedListResponse = client.listKeys(request);
    List<Key> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getKeysList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListKeysRequest actualRequest = ((ListKeysRequest) actualRequests.get(0));
    Assert.assertEquals(request.getParent(), actualRequest.getParent());
    Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
    Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListKeysPagedResponse(com.google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client.ListKeysPagedResponse) ListKeysRequest(com.google.recaptchaenterprise.v1beta1.ListKeysRequest) ListKeysResponse(com.google.recaptchaenterprise.v1beta1.ListKeysResponse) Key(com.google.recaptchaenterprise.v1beta1.Key) Test(org.junit.Test)

Example 4 with ListKeysRequest

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

the class ListSiteKeys method listSiteKeys.

/**
 * List all keys present under the given project ID.
 *
 * @param projectID : GCloud Project ID.
 */
public static ListKeysPagedResponse listSiteKeys(String projectID) throws IOException {
    // clean up any remaining background resources.
    try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
        // Set the project ID to list the keys present in it.
        ListKeysRequest listKeysRequest = ListKeysRequest.newBuilder().setParent(ProjectName.of(projectID).toString()).build();
        ListKeysPagedResponse response = client.listKeys(listKeysRequest);
        System.out.println("Listing reCAPTCHA site keys: ");
        for (Key key : response.iterateAll()) {
            System.out.println(key.getName());
        }
        return response;
    }
}
Also used : ListKeysPagedResponse(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.ListKeysPagedResponse) ListKeysRequest(com.google.recaptchaenterprise.v1.ListKeysRequest) Key(com.google.recaptchaenterprise.v1.Key) RecaptchaEnterpriseServiceClient(com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)

Example 5 with ListKeysRequest

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

the class RecaptchaEnterpriseServiceClientTest method listKeysExceptionTest.

@Test
public void listKeysExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockRecaptchaEnterpriseService.addException(exception);
    try {
        ListKeysRequest request = ListKeysRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").build();
        client.listKeys(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ListKeysRequest(com.google.recaptchaenterprise.v1.ListKeysRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 ListKeysRequest (com.google.recaptchaenterprise.v1.ListKeysRequest)3 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 ListKeysPagedResponse (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.ListKeysPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Key (com.google.recaptchaenterprise.v1.Key)2 ListKeysRequest (com.google.recaptchaenterprise.v1beta1.ListKeysRequest)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 RecaptchaEnterpriseServiceClient (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)1 ListKeysPagedResponse (com.google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client.ListKeysPagedResponse)1 ListKeysResponse (com.google.recaptchaenterprise.v1.ListKeysResponse)1 Key (com.google.recaptchaenterprise.v1beta1.Key)1 ListKeysResponse (com.google.recaptchaenterprise.v1beta1.ListKeysResponse)1