use of org.springframework.data.querydsl.QSort in project spring-data-mongodb by spring-projects.
the class AbstractPersonRepositoryIntegrationTests method shouldSupportSortingWithQSortByQueryDslOrderSpecifier.
// DATAMONGO-1085
@Test
public void shouldSupportSortingWithQSortByQueryDslOrderSpecifier() throws Exception {
repository.deleteAll();
List<Person> persons = new ArrayList<Person>();
for (int i = 0; i < 3; i++) {
Person person = new Person(String.format("Siggi %s", i), "Bar", 30);
person.setAddress(new Address(String.format("Street %s", i), "12345", "SinCity"));
persons.add(person);
}
repository.saveAll(persons);
PageRequest pageRequest = PageRequest.of(0, 2, new QSort(person.address.street.desc()));
Iterable<Person> result = repository.findAll(pageRequest);
assertThat(result, is(Matchers.<Person>iterableWithSize(2)));
assertThat(result.iterator().next().getFirstname(), is("Siggi 2"));
}
use of org.springframework.data.querydsl.QSort in project spring-data-mongodb by spring-projects.
the class AbstractPersonRepositoryIntegrationTests method shouldSupportSortingWithQSort.
// DATAMONGO-1085
@Test
public void shouldSupportSortingWithQSort() throws Exception {
repository.deleteAll();
List<Person> persons = new ArrayList<Person>();
for (int i = 0; i < 3; i++) {
Person person = new Person(String.format("Siggi %s", i), "Bar", 30);
person.setAddress(new Address(String.format("Street %s", i), "12345", "SinCity"));
persons.add(person);
}
repository.saveAll(persons);
Iterable<Person> result = repository.findAll(new QSort(person.address.street.desc()));
assertThat(result, is(Matchers.<Person>iterableWithSize(persons.size())));
assertThat(result.iterator().next().getFirstname(), is("Siggi 2"));
}
Aggregations