Search in sources :

Example 1 with Key

use of com.google.recaptchaenterprise.v1beta1.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()));
}
Also used : GetKeyRequest(com.google.recaptchaenterprise.v1.GetKeyRequest) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) Key(com.google.recaptchaenterprise.v1.Key) Test(org.junit.Test)

Example 2 with Key

use of com.google.recaptchaenterprise.v1beta1.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()));
}
Also used : UpdateKeyRequest(com.google.recaptchaenterprise.v1.UpdateKeyRequest) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) Key(com.google.recaptchaenterprise.v1.Key) Test(org.junit.Test)

Example 3 with Key

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

the class RecaptchaEnterpriseServiceV1Beta1ClientTest method getKeyExceptionTest.

@Test
public void getKeyExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockRecaptchaEnterpriseServiceV1Beta1.addException(exception);
    try {
        GetKeyRequest request = GetKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
        client.getKey(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : GetKeyRequest(com.google.recaptchaenterprise.v1beta1.GetKeyRequest) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 4 with Key

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

the class RecaptchaEnterpriseServiceV1Beta1ClientTest method deleteKeyTest.

@Test
public void deleteKeyTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
    DeleteKeyRequest request = DeleteKeyRequest.newBuilder().setName(KeyName.of("[PROJECT]", "[KEY]").toString()).build();
    client.deleteKey(request);
    List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteKeyRequest actualRequest = ((DeleteKeyRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteKeyRequest(com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest) Test(org.junit.Test)

Example 5 with Key

use of com.google.recaptchaenterprise.v1beta1.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()));
}
Also used : UpdateKeyRequest(com.google.recaptchaenterprise.v1beta1.UpdateKeyRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Key(com.google.recaptchaenterprise.v1beta1.Key) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)23 Key (com.google.datastore.v1.Key)17 DatastoreHelper.makeKey (com.google.datastore.v1.client.DatastoreHelper.makeKey)11 AbstractMessage (com.google.protobuf.AbstractMessage)10 Key (com.google.recaptchaenterprise.v1.Key)10 Entity (com.google.datastore.v1.Entity)7 DeleteKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKey)7 DatastoreV1.isValidKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.isValidKey)7 RecaptchaEnterpriseServiceClient (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient)5 Mutation (com.google.datastore.v1.Mutation)5 Key (com.google.recaptchaenterprise.v1beta1.Key)4 HashMap (java.util.HashMap)4 DeleteEntity (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity)4 Query (com.google.datastore.v1.Query)3 GetKeyRequest (com.google.recaptchaenterprise.v1.GetKeyRequest)3 ArrayList (java.util.ArrayList)3 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 ListKeysPagedResponse (com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.ListKeysPagedResponse)2 PathElement (com.google.datastore.v1.Key.PathElement)2 PartitionId (com.google.datastore.v1.PartitionId)2