use of com.google.recaptchaenterprise.v1.MigrateKeyRequest in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceClientTest method migrateKeyExceptionTest.
@Test
public void migrateKeyExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockRecaptchaEnterpriseService.addException(exception);
try {
MigrateKeyRequest request = MigrateKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
client.migrateKey(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.recaptchaenterprise.v1.MigrateKeyRequest in project java-recaptchaenterprise by googleapis.
the class MigrateKey method migrateKey.
/**
* Migrate a key from reCAPTCHA (non-Enterprise) to reCAPTCHA Enterprise. If you created the key
* using Admin console: https://www.google.com/recaptcha/admin/site, then use this API to migrate
* to reCAPTCHA Enterprise. For more info, see:
* https://cloud.google.com/recaptcha-enterprise/docs/migrate-recaptcha
*
* @param projectId: Google Cloud Project Id.
* @param recaptchaSiteKey: Specify the site key to migrate.
*/
public static void migrateKey(String projectId, String recaptchaSiteKey) throws IOException {
// clean up any remaining background resources.
try (RecaptchaEnterpriseServiceClient client = RecaptchaEnterpriseServiceClient.create()) {
// Specify the key name to migrate.
MigrateKeyRequest migrateKeyRequest = MigrateKeyRequest.newBuilder().setName(KeyName.of(projectId, recaptchaSiteKey).toString()).build();
Key response = client.migrateKey(migrateKeyRequest);
// key is present.
for (Key key : recaptcha.ListSiteKeys.listSiteKeys(projectId).iterateAll()) {
if (key.equals(response)) {
System.out.printf("Key migrated successfully: %s", recaptchaSiteKey);
}
}
}
}
use of com.google.recaptchaenterprise.v1.MigrateKeyRequest in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceClientTest method migrateKeyTest.
@Test
public void migrateKeyTest() 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);
MigrateKeyRequest request = MigrateKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
Key actualResponse = client.migrateKey(request);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
Assert.assertEquals(1, actualRequests.size());
MigrateKeyRequest actualRequest = ((MigrateKeyRequest) actualRequests.get(0));
Assert.assertEquals(request.getName(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations