use of com.google.recaptchaenterprise.v1.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()));
}
use of com.google.recaptchaenterprise.v1.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.
}
}
use of com.google.recaptchaenterprise.v1.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()));
}
use of com.google.recaptchaenterprise.v1.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;
}
}
use of com.google.recaptchaenterprise.v1.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.
}
}
Aggregations