use of org.springframework.data.repository.query.FluentQuery.FetchableFluentQuery in project spring-cloud-gcp by GoogleCloudPlatform.
the class SimpleDatastoreRepositoryTests method findByExampleFluentQueryAll.
@Test
void findByExampleFluentQueryAll() {
Example<Object> example = Example.of(new Object());
Sort sort = Sort.by("id");
Iterable entities = Arrays.asList();
doAnswer(invocationOnMock -> new DatastoreResultsIterable(entities, null)).when(this.datastoreTemplate).queryByExample(same(example), any());
this.spyRepo.findBy(example, FetchableFluentQuery::all);
verify(this.spyRepo).findAll(same(example), eq(Sort.unsorted()));
this.spyRepo.findBy(example, query -> query.sortBy(sort).all());
verify(this.spyRepo).findAll(same(example), eq(sort));
}
use of org.springframework.data.repository.query.FluentQuery.FetchableFluentQuery in project spring-cloud-gcp by GoogleCloudPlatform.
the class Employee method testFindByExampleFluent.
@Test
void testFindByExampleFluent() {
Example<TestEntity> exampleRedCircle = Example.of(new TestEntity(null, "red", null, Shape.CIRCLE, null));
Example<TestEntity> exampleRed = Example.of(new TestEntity(null, "red", null, null, null));
List<TestEntity> entityRedAll = this.testEntityRepository.findBy(exampleRed, q -> q.all());
assertThat(entityRedAll).containsExactlyInAnyOrder(this.testEntityA, this.testEntityC, this.testEntityD);
List<TestEntity> entityRedAllReverseSortedById = this.testEntityRepository.findBy(exampleRed, q -> q.sortBy(Sort.by("id").descending()).all());
assertThat(entityRedAllReverseSortedById).containsExactly(this.testEntityD, this.testEntityC, this.testEntityA);
long countRedCircle = this.testEntityRepository.findBy(exampleRedCircle, FetchableFluentQuery::count);
assertThat(countRedCircle).isEqualTo(2);
boolean existsRed = this.testEntityRepository.findBy(exampleRed, FetchableFluentQuery::exists);
assertThat(existsRed).isTrue();
TestEntity firstValueRed = this.testEntityRepository.findBy(exampleRed, FetchableFluentQuery::firstValue);
assertThat(firstValueRed).isEqualTo(testEntityA);
TestEntity oneValueRed = this.testEntityRepository.findBy(exampleRed, q -> q.oneValue());
assertThat(oneValueRed.getColor()).isEqualTo("red");
Optional<TestEntity> onePurple = this.testEntityRepository.findBy(Example.of(new TestEntity(null, "purple", null, null, null)), FetchableFluentQuery::one);
assertThat(onePurple).isNotPresent();
Pageable pageable = PageRequest.of(0, 2);
Page<TestEntity> pagedResults = this.testEntityRepository.findBy(exampleRed, q -> q.page(pageable));
assertThat(pagedResults).containsExactly(this.testEntityA, this.testEntityC);
Optional<TestEntity> oneRed = this.testEntityRepository.findBy(exampleRed, q -> q.sortBy(Sort.by("id")).one());
assertThat(oneRed).isPresent().get().isEqualTo(testEntityA);
long firstValueReverseSortedById = this.testEntityRepository.findBy(exampleRed, q -> q.sortBy(Sort.by("id").descending()).firstValue().getId());
assertThat(firstValueReverseSortedById).isEqualTo(4L);
List<String> redIdListReverseSorted = this.testEntityRepository.findBy(exampleRed, q -> q.sortBy(Sort.by("id").descending()).stream().map(x -> x.getId().toString()).collect(Collectors.toList()));
assertThat(redIdListReverseSorted).containsExactly("4", "3", "1");
}
use of org.springframework.data.repository.query.FluentQuery.FetchableFluentQuery in project spring-cloud-gcp by GoogleCloudPlatform.
the class SimpleDatastoreRepositoryTests method findByExampleFluentQueryOneValue.
@Test
void findByExampleFluentQueryOneValue() {
Example<Object> example = Example.of(new Object());
Iterable entities = Arrays.asList();
doAnswer(invocationOnMock -> new DatastoreResultsIterable(entities, null)).when(this.datastoreTemplate).queryByExample(same(example), any());
this.spyRepo.findBy(example, FetchableFluentQuery::oneValue);
verify(this.spyRepo).findOne(same(example));
}
Aggregations