use of com.google.recaptchaenterprise.v1beta1.UpdateKeyRequest in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceClientTest method updateKeyTest.
@Test
public void updateKeyTest() throws Exception {
Key expectedResponse = Key.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).setTestingOptions(TestingOptions.newBuilder().build()).build();
mockRecaptchaEnterpriseService.addResponse(expectedResponse);
UpdateKeyRequest request = UpdateKeyRequest.newBuilder().setKey(Key.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
Key actualResponse = client.updateKey(request);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateKeyRequest actualRequest = ((UpdateKeyRequest) actualRequests.get(0));
Assert.assertEquals(request.getKey(), actualRequest.getKey());
Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.recaptchaenterprise.v1beta1.UpdateKeyRequest in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceV1Beta1ClientTest method updateKeyExceptionTest.
@Test
public void updateKeyExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockRecaptchaEnterpriseServiceV1Beta1.addException(exception);
try {
UpdateKeyRequest request = UpdateKeyRequest.newBuilder().setKey(Key.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
client.updateKey(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.recaptchaenterprise.v1beta1.UpdateKeyRequest in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceV1Beta1ClientTest method updateKeyTest.
@Test
public void updateKeyTest() throws Exception {
Key expectedResponse = Key.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).setDisplayName("displayName1714148973").build();
mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
UpdateKeyRequest request = UpdateKeyRequest.newBuilder().setKey(Key.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
Key actualResponse = client.updateKey(request);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateKeyRequest actualRequest = ((UpdateKeyRequest) actualRequests.get(0));
Assert.assertEquals(request.getKey(), actualRequest.getKey());
Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.recaptchaenterprise.v1beta1.UpdateKeyRequest in project java-recaptchaenterprise by googleapis.
the class UpdateSiteKey method updateSiteKey.
/**
* Update the properties of the given site key present under the project id.
*
* @param projectID: GCloud Project ID.
* @param recaptchaSiteKeyID: Specify the site key.
* @param domainName: Specify the domain name for which the settings should be updated.
*/
public static void updateSiteKey(String projectID, String recaptchaSiteKeyID, String domainName) throws IOException, InterruptedException, ExecutionException, TimeoutException {
// clean up any remaining background resources.
try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
// Set the name and the new settings for the key.
UpdateKeyRequest updateKeyRequest = UpdateKeyRequest.newBuilder().setKey(Key.newBuilder().setDisplayName("any descriptive name for the key").setName(KeyName.of(projectID, recaptchaSiteKeyID).toString()).setWebSettings(WebKeySettings.newBuilder().setAllowAmpTraffic(true).addAllowedDomains(domainName).build()).build()).build();
client.updateKeyCallable().futureCall(updateKeyRequest).get();
// Check if the key has been updated.
GetKeyRequest getKeyRequest = GetKeyRequest.newBuilder().setName(KeyName.of(projectID, recaptchaSiteKeyID).toString()).build();
Key response = client.getKey(getKeyRequest);
// Get the changed property.
boolean allowedAmpTraffic = response.getWebSettings().getAllowAmpTraffic();
if (!allowedAmpTraffic) {
System.out.println("Error! reCAPTCHA Site key property hasn't been updated. Please try again !");
return;
}
System.out.println("reCAPTCHA Site key successfully updated !");
}
}
use of com.google.recaptchaenterprise.v1beta1.UpdateKeyRequest in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceClientTest method updateKeyExceptionTest.
@Test
public void updateKeyExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockRecaptchaEnterpriseService.addException(exception);
try {
UpdateKeyRequest request = UpdateKeyRequest.newBuilder().setKey(Key.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
client.updateKey(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations