|
29 | 29 | import java.util.Arrays;
|
30 | 30 | import java.util.Collections;
|
31 | 31 | import java.util.Map;
|
| 32 | +import java.util.stream.IntStream; |
32 | 33 |
|
33 | 34 | import javax.sql.DataSource;
|
34 | 35 |
|
|
40 | 41 | import org.springframework.dao.DataAccessException;
|
41 | 42 | import org.springframework.data.annotation.Id;
|
42 | 43 | import org.springframework.data.annotation.PersistenceConstructor;
|
| 44 | +import org.springframework.data.domain.PageRequest; |
| 45 | +import org.springframework.data.domain.Pageable; |
43 | 46 | import org.springframework.data.r2dbc.connectionfactory.R2dbcTransactionManager;
|
44 | 47 | import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
|
45 | 48 | import org.springframework.data.r2dbc.testing.R2dbcIntegrationTestSupport;
|
@@ -179,6 +182,53 @@ public void shouldDeleteUsingQueryMethod() {
|
179 | 182 | assertThat(count).hasEntrySatisfying("count", numberOf(1));
|
180 | 183 | }
|
181 | 184 |
|
| 185 | + @Test // gh-335 |
| 186 | + public void shouldFindByPageable() { |
| 187 | + |
| 188 | + Flux<LegoSet> sets = Flux.fromStream(IntStream.range(0, 100).mapToObj(value -> { |
| 189 | + return new LegoSet(null, "Set " + value, value); |
| 190 | + })); |
| 191 | + |
| 192 | + repository.saveAll(sets) // |
| 193 | + .as(StepVerifier::create) // |
| 194 | + .expectNextCount(100) // |
| 195 | + .verifyComplete(); |
| 196 | + |
| 197 | + repository.findAllByOrderByManual(PageRequest.of(0, 10)) // |
| 198 | + .collectList() // |
| 199 | + .as(StepVerifier::create) // |
| 200 | + .consumeNextWith(actual -> { |
| 201 | + |
| 202 | + assertThat(actual).hasSize(10).extracting(LegoSet::getManual).containsSequence(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); |
| 203 | + }).verifyComplete(); |
| 204 | + |
| 205 | + repository.findAllByOrderByManual(PageRequest.of(19, 5)) // |
| 206 | + .collectList() // |
| 207 | + .as(StepVerifier::create) // |
| 208 | + .consumeNextWith(actual -> { |
| 209 | + |
| 210 | + assertThat(actual).hasSize(5).extracting(LegoSet::getManual).containsSequence(95, 96, 97, 98, 99); |
| 211 | + }).verifyComplete(); |
| 212 | + } |
| 213 | + |
| 214 | + @Test // gh-335 |
| 215 | + public void shouldFindTop10() { |
| 216 | + |
| 217 | + Flux<LegoSet> sets = Flux.fromStream(IntStream.range(0, 100).mapToObj(value -> { |
| 218 | + return new LegoSet(null, "Set " + value, value); |
| 219 | + })); |
| 220 | + |
| 221 | + repository.saveAll(sets) // |
| 222 | + .as(StepVerifier::create) // |
| 223 | + .expectNextCount(100) // |
| 224 | + .verifyComplete(); |
| 225 | + |
| 226 | + repository.findFirst10By() // |
| 227 | + .as(StepVerifier::create) // |
| 228 | + .expectNextCount(10) // |
| 229 | + .verifyComplete(); |
| 230 | + } |
| 231 | + |
182 | 232 | @Test
|
183 | 233 | public void shouldInsertItemsTransactional() {
|
184 | 234 |
|
@@ -212,6 +262,10 @@ interface LegoSetRepository extends ReactiveCrudRepository<LegoSet, Integer> {
|
212 | 262 |
|
213 | 263 | Flux<LegoSet> findByNameContains(String name);
|
214 | 264 |
|
| 265 | + Flux<LegoSet> findFirst10By(); |
| 266 | + |
| 267 | + Flux<LegoSet> findAllByOrderByManual(Pageable pageable); |
| 268 | + |
215 | 269 | Flux<Named> findAsProjection();
|
216 | 270 |
|
217 | 271 | Mono<LegoSet> findByManual(int manual);
|
|
0 commit comments