use of com.google.cloud.spring.data.datastore.core.DatastoreResultsIterable in project spring-cloud-gcp by GoogleCloudPlatform.
the class SimpleDatastoreRepositoryTests method findAllByExamplePageCursor.
@Test
void findAllByExamplePageCursor() {
Example<Object> example = Example.of(new Object());
Sort sort = Sort.by("id");
Cursor cursor = Cursor.copyFrom("abc".getBytes());
doAnswer(invocationOnMock -> new DatastoreResultsIterable(Arrays.asList(1, 2), cursor)).when(this.datastoreTemplate).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(2).setOffset(0).setSort(sort).build()));
doAnswer(invocationOnMock -> new DatastoreResultsIterable(Arrays.asList(3, 4), null)).when(this.datastoreTemplate).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(2).setOffset(2).setSort(sort).setCursor(cursor).build()));
doAnswer(invocationOnMock -> new DatastoreResultsIterable(Arrays.asList(1, 2, 3, 4, 5), null)).when(this.datastoreTemplate).keyQueryByExample(same(example), isNull());
Page<Object> result = this.simpleDatastoreRepository.findAll(example, PageRequest.of(0, 2, sort));
assertThat(result).containsExactly(1, 2);
assertThat(result.getTotalElements()).isEqualTo(5);
Page<Object> resultNext = this.simpleDatastoreRepository.findAll(example, result.getPageable().next());
assertThat(resultNext).containsExactly(3, 4);
assertThat(resultNext.getTotalElements()).isEqualTo(5);
verify(this.datastoreTemplate).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(2).setOffset(0).setSort(sort).build()));
verify(this.datastoreTemplate).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(2).setOffset(2).setSort(sort).setCursor(cursor).build()));
verify(this.datastoreTemplate).keyQueryByExample(same(example), isNull());
}
use of com.google.cloud.spring.data.datastore.core.DatastoreResultsIterable in project spring-cloud-gcp by GoogleCloudPlatform.
the class SimpleDatastoreRepositoryTests method findAllByExamplePage.
@Test
void findAllByExamplePage() {
Example<Object> example = Example.of(new Object());
Sort sort = Sort.by("id");
doAnswer(invocationOnMock -> new DatastoreResultsIterable(Arrays.asList(1, 2), null)).when(this.datastoreTemplate).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(2).setOffset(2).setSort(sort).build()));
doAnswer(invocationOnMock -> new DatastoreResultsIterable(Arrays.asList(1, 2, 3, 4, 5), null)).when(this.datastoreTemplate).keyQueryByExample(same(example), isNull());
Page<Object> result = this.simpleDatastoreRepository.findAll(example, PageRequest.of(1, 2, sort));
assertThat(result).containsExactly(1, 2);
assertThat(result.getTotalElements()).isEqualTo(5);
verify(this.datastoreTemplate).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(2).setOffset(2).setSort(sort).build()));
verify(this.datastoreTemplate).keyQueryByExample(same(example), isNull());
}
use of com.google.cloud.spring.data.datastore.core.DatastoreResultsIterable in project spring-cloud-gcp by GoogleCloudPlatform.
the class SimpleDatastoreRepositoryTests method findByExampleFluentQuerySortAndFirstValue.
@Test
void findByExampleFluentQuerySortAndFirstValue() {
Example<Object> example = Example.of(new Object());
Sort sort = Sort.by("id");
Iterable entities = Arrays.asList(1);
doAnswer(invocationOnMock -> new DatastoreResultsIterable(entities, null)).when(this.datastoreTemplate).queryByExample(same(example), any());
this.spyRepo.findBy(example, q -> q.sortBy(sort).firstValue());
verify(this.spyRepo).findFirstSorted(same(example), same(sort));
verify(this.datastoreTemplate).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setSort(sort).setLimit(1).build()));
}
use of com.google.cloud.spring.data.datastore.core.DatastoreResultsIterable in project spring-cloud-gcp by GoogleCloudPlatform.
the class SimpleDatastoreRepositoryTests method findOneByExample.
@Test
void findOneByExample() {
Example<Object> example = Example.of(new Object());
doAnswer(invocationOnMock -> new DatastoreResultsIterable(Arrays.asList(1), null)).when(this.datastoreTemplate).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(1).build()));
assertThat(this.simpleDatastoreRepository.findOne(example)).contains(1);
verify(this.datastoreTemplate).queryByExample(same(example), eq(new DatastoreQueryOptions.Builder().setLimit(1).build()));
}
Aggregations