use of org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterDeleteEvent in project spring-cloud-gcp by spring-cloud.
the class DatastoreTemplateTests method deleteByIdTest.
@Test
public void deleteByIdTest() {
when(this.objectToKeyFactory.getKeyFromId(same(this.key1), any())).thenReturn(this.key1);
verifyBeforeAndAfterEvents(new BeforeDeleteEvent(new Key[] { this.key1 }, TestEntity.class, Collections.singletonList(this.key1), null), new AfterDeleteEvent(new Key[] { this.key1 }, TestEntity.class, Collections.singletonList(this.key1), null), () -> this.datastoreTemplate.deleteById(this.key1, TestEntity.class), x -> x.verify(this.datastore, times(1)).delete(same(this.key1)));
}
use of org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterDeleteEvent in project spring-cloud-gcp by spring-cloud.
the class DatastoreTemplate method performDelete.
private void performDelete(Key[] keys, Iterable ids, Iterable entities, Class entityClass) {
maybeEmitEvent(new BeforeDeleteEvent(keys, entityClass, ids, entities));
SliceUtil.sliceAndExecute(keys, this.maxWriteSize, getDatastoreReadWriter()::delete);
maybeEmitEvent(new AfterDeleteEvent(keys, entityClass, ids, entities));
}
use of org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterDeleteEvent in project spring-cloud-gcp by spring-cloud.
the class DatastoreTemplateTests method deleteAllByIdTest.
@Test
public void deleteAllByIdTest() {
when(this.objectToKeyFactory.getKeyFromId(same(this.key1), any())).thenReturn(this.key1);
when(this.objectToKeyFactory.getKeyFromId(same(this.key2), any())).thenReturn(this.key2);
verifyBeforeAndAfterEvents(new BeforeDeleteEvent(new Key[] { this.key2, this.key1 }, TestEntity.class, Arrays.asList(this.key1, this.key2), null), new AfterDeleteEvent(new Key[] { this.key2, this.key1 }, TestEntity.class, Arrays.asList(this.key1, this.key2), null), () -> this.datastoreTemplate.deleteAllById(Arrays.asList(this.key1, this.key2), TestEntity.class), x -> x.verify(this.datastore, times(1)).delete(same(this.key2), same(this.key1)));
}
use of org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterDeleteEvent in project spring-cloud-gcp by spring-cloud.
the class DatastoreTemplateTests method deleteAllTest.
@Test
public void deleteAllTest() {
QueryResults<Key> queryResults = mock(QueryResults.class);
when(queryResults.getResultClass()).thenReturn((Class) Key.class);
doAnswer((invocation) -> {
Arrays.asList(this.key1, this.key2).iterator().forEachRemaining(invocation.getArgument(0));
return null;
}).when(queryResults).forEachRemaining(any());
when(this.datastore.run(eq(Query.newKeyQueryBuilder().setKind("custom_test_kind").build()))).thenReturn(queryResults);
verifyBeforeAndAfterEvents(new BeforeDeleteEvent(new Key[] { this.key1, this.key2 }, TestEntity.class, null, null), new AfterDeleteEvent(new Key[] { this.key1, this.key2 }, TestEntity.class, null, null), () -> assertThat(this.datastoreTemplate.deleteAll(TestEntity.class)).isEqualTo(2), x -> x.verify(this.datastore, times(1)).delete(same(this.key1), same(this.key2)));
}
Aggregations