|
19 | 19 |
|
20 | 20 | import lombok.Data;
|
21 | 21 | import lombok.Value;
|
| 22 | +import lombok.With; |
22 | 23 |
|
23 | 24 | import java.util.Arrays;
|
24 | 25 | import java.util.Collections;
|
25 | 26 | import java.util.List;
|
26 | 27 | import java.util.Optional;
|
27 | 28 |
|
28 |
| -import lombok.With; |
29 | 29 | import org.junit.jupiter.api.BeforeEach;
|
30 | 30 | import org.junit.jupiter.api.Test;
|
31 | 31 |
|
|
36 | 36 | import org.springframework.data.domain.Page;
|
37 | 37 | import org.springframework.data.domain.PageRequest;
|
38 | 38 | import org.springframework.data.domain.Pageable;
|
| 39 | +import org.springframework.data.domain.Sort; |
39 | 40 | import org.springframework.data.geo.Distance;
|
40 | 41 | import org.springframework.data.geo.Metrics;
|
41 | 42 | import org.springframework.data.geo.Point;
|
@@ -117,6 +118,45 @@ void simpleFindByMultipleProperties() {
|
117 | 118 | assertThat(repo.findByFirstnameAndLastname("egwene", "al'vere").get(0)).isEqualTo(egwene);
|
118 | 119 | }
|
119 | 120 |
|
| 121 | + @Test // GH-2080 |
| 122 | + void simpleFindAndSort() { |
| 123 | + |
| 124 | + Person egwene = new Person(); |
| 125 | + egwene.firstname = "egwene"; |
| 126 | + egwene.lastname = "al'vere"; |
| 127 | + |
| 128 | + Person marin = new Person(); |
| 129 | + marin.firstname = "marin"; |
| 130 | + marin.lastname = "al'vere"; |
| 131 | + |
| 132 | + repo.saveAll(Arrays.asList(egwene, marin)); |
| 133 | + |
| 134 | + assertThat(repo.findByLastname("al'vere", Sort.by(Sort.Direction.ASC, "firstname"))).containsSequence(egwene, |
| 135 | + marin); |
| 136 | + assertThat(repo.findByLastname("al'vere", Sort.by(Sort.Direction.DESC, "firstname"))).containsSequence(marin, |
| 137 | + egwene); |
| 138 | + |
| 139 | + assertThat(repo.findByLastnameOrderByFirstnameAsc("al'vere")).containsSequence(egwene, marin); |
| 140 | + assertThat(repo.findByLastnameOrderByFirstnameDesc("al'vere")).containsSequence(marin, egwene); |
| 141 | + } |
| 142 | + |
| 143 | + @Test // GH-2080 |
| 144 | + void simpleFindAllWithSort() { |
| 145 | + |
| 146 | + Person egwene = new Person(); |
| 147 | + egwene.firstname = "egwene"; |
| 148 | + egwene.lastname = "al'vere"; |
| 149 | + |
| 150 | + Person marin = new Person(); |
| 151 | + marin.firstname = "marin"; |
| 152 | + marin.lastname = "al'vere"; |
| 153 | + |
| 154 | + repo.saveAll(Arrays.asList(egwene, marin)); |
| 155 | + |
| 156 | + assertThat(repo.findAll(Sort.by(Sort.Direction.ASC, "firstname"))).containsSequence(egwene, marin); |
| 157 | + assertThat(repo.findAll(Sort.by(Sort.Direction.DESC, "firstname"))).containsSequence(marin, egwene); |
| 158 | + } |
| 159 | + |
120 | 160 | @Test // DATAREDIS-425
|
121 | 161 | void findReturnsReferenceDataCorrectly() {
|
122 | 162 |
|
@@ -441,6 +481,12 @@ public static interface PersonRepository
|
441 | 481 |
|
442 | 482 | List<Person> findByLastname(String lastname);
|
443 | 483 |
|
| 484 | + List<Person> findByLastname(String lastname, Sort sort); |
| 485 | + |
| 486 | + List<Person> findByLastnameOrderByFirstnameAsc(String lastname); |
| 487 | + |
| 488 | + List<Person> findByLastnameOrderByFirstnameDesc(String lastname); |
| 489 | + |
444 | 490 | Page<Person> findPersonByLastname(String lastname, Pageable page);
|
445 | 491 |
|
446 | 492 | List<Person> findPersonByAliveIsTrue();
|
|
0 commit comments