use of com.google.recaptchaenterprise.v1.Key in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceClientTest method getKeyTest.
@Test
public void getKeyTest() 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);
GetKeyRequest request = GetKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
Key actualResponse = client.getKey(request);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseService.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetKeyRequest actualRequest = ((GetKeyRequest) actualRequests.get(0));
Assert.assertEquals(request.getName(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.recaptchaenterprise.v1.Key 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.v1.Key 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.Key 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.v1.Key in project java-recaptchaenterprise by googleapis.
the class RecaptchaEnterpriseServiceV1Beta1ClientTest method createKeyTest.
@Test
public void createKeyTest() throws Exception {
Key expectedResponse = Key.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).setDisplayName("displayName1714148973").build();
mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
CreateKeyRequest request = CreateKeyRequest.newBuilder().setParent(ProjectName.of("[PROJECT]").toString()).setKey(Key.newBuilder().build()).build();
Key actualResponse = client.createKey(request);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateKeyRequest actualRequest = ((CreateKeyRequest) actualRequests.get(0));
Assert.assertEquals(request.getParent(), actualRequest.getParent());
Assert.assertEquals(request.getKey(), actualRequest.getKey());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations