use of com.google.recaptchaenterprise.v1.Key in project beam by apache.
the class DatastoreV1Test method testDeleteEntities.
/**
* Test that entities with valid keys are transformed to delete mutations.
*/
@Test
public void testDeleteEntities() throws Exception {
Key key = makeKey("bird", "finch").build();
Entity entity = Entity.newBuilder().setKey(key).build();
DeleteEntityFn deleteEntityFn = new DeleteEntityFn();
Mutation expectedMutation = makeDelete(entity.getKey()).build();
assertEquals(expectedMutation, deleteEntityFn.apply(entity));
}
use of com.google.recaptchaenterprise.v1.Key in project beam by apache.
the class DatastoreV1Test method testHasNameOrId.
/**
* Test the detection of complete and incomplete keys.
*/
@Test
public void testHasNameOrId() {
Key key;
// Complete with name, no ancestor
key = makeKey("bird", "finch").build();
assertTrue(isValidKey(key));
// Complete with id, no ancestor
key = makeKey("bird", 123).build();
assertTrue(isValidKey(key));
// Incomplete, no ancestor
key = makeKey("bird").build();
assertFalse(isValidKey(key));
// Complete with name and ancestor
key = makeKey("bird", "owl").build();
key = makeKey(key, "bird", "horned").build();
assertTrue(isValidKey(key));
// Complete with id and ancestor
key = makeKey("bird", "owl").build();
key = makeKey(key, "bird", 123).build();
assertTrue(isValidKey(key));
// Incomplete with ancestor
key = makeKey("bird", "owl").build();
key = makeKey(key, "bird").build();
assertFalse(isValidKey(key));
key = makeKey().build();
assertFalse(isValidKey(key));
}
use of com.google.recaptchaenterprise.v1.Key in project beam by apache.
the class DatastoreV1Test method testDeleteEntitiesWithIncompleteKeys.
/**
* Test that entities with incomplete keys cannot be deleted.
*/
@Test
public void testDeleteEntitiesWithIncompleteKeys() throws Exception {
Key key = makeKey("bird").build();
Entity entity = Entity.newBuilder().setKey(key).build();
DeleteEntityFn deleteEntityFn = new DeleteEntityFn();
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Entities to be deleted from the Cloud Datastore must have complete keys");
deleteEntityFn.apply(entity);
}
use of com.google.recaptchaenterprise.v1.Key in project beam by apache.
the class V1ReadIT method writeEntitiesToDatastore.
// Creates entities and write them to datastore
private static void writeEntitiesToDatastore(V1TestOptions options, String project, String ancestor, long numEntities) throws Exception {
Datastore datastore = getDatastore(options, project);
// Write test entities to datastore
V1TestWriter writer = new V1TestWriter(datastore, new UpsertMutationBuilder());
Key ancestorKey = makeAncestorKey(options.getNamespace(), options.getKind(), ancestor);
for (long i = 0; i < numEntities; i++) {
Entity entity = makeEntity(i, ancestorKey, options.getKind(), options.getNamespace(), 0);
writer.write(entity);
}
writer.close();
}
use of com.google.recaptchaenterprise.v1.Key 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()));
}
Aggregations