|
13 | 13 | import org.junit.Test; |
14 | 14 | import org.junit.runner.RunWith; |
15 | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | +import org.springframework.data.domain.Sort; |
16 | 17 | import org.springframework.test.context.ContextConfiguration; |
17 | 18 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
18 | 19 | import reactor.core.publisher.Flux; |
19 | 20 | import reactor.core.publisher.Mono; |
20 | 21 | import reactor.test.StepVerifier; |
21 | 22 |
|
| 23 | +import java.util.ArrayList; |
22 | 24 | import java.util.Arrays; |
| 25 | +import java.util.List; |
23 | 26 |
|
24 | 27 | @RunWith(SpringJUnit4ClassRunner.class) |
25 | 28 | @ContextConfiguration(classes = TestRepositoryConfig.class) |
26 | 29 | public class ReactiveTeacherRepositoryIT { |
27 | 30 |
|
28 | 31 | private static final String TEACHER_ID_1 = "1"; |
29 | 32 |
|
| 33 | + private static final String TEACHER_ID_2 = "2"; |
| 34 | + |
| 35 | + private static final String TEACHER_ID_3 = "3"; |
| 36 | + |
30 | 37 | private static final String TEACHER_FIRST_NAME_1 = "FirstName1"; |
31 | 38 |
|
| 39 | + private static final String TEACHER_FIRST_NAME_2 = "FirstName2"; |
| 40 | + |
32 | 41 | private static final String DEPARTMENT_LAST_NAME_1 = "LastName1"; |
33 | 42 |
|
| 43 | + private static final String DEPARTMENT_LAST_NAME_2 = "LastName2"; |
| 44 | + |
34 | 45 | private static final ReactiveTeacher TEACHER_1 = new ReactiveTeacher(TEACHER_ID_1, TEACHER_FIRST_NAME_1, DEPARTMENT_LAST_NAME_1); |
35 | 46 |
|
| 47 | + private static final ReactiveTeacher TEACHER_2 = new ReactiveTeacher(TEACHER_ID_2, TEACHER_FIRST_NAME_1, DEPARTMENT_LAST_NAME_2); |
| 48 | + |
| 49 | + private static final ReactiveTeacher TEACHER_3 = new ReactiveTeacher(TEACHER_ID_3, TEACHER_FIRST_NAME_2, DEPARTMENT_LAST_NAME_1); |
| 50 | + |
36 | 51 | @ClassRule |
37 | 52 | public static final ReactiveIntegrationTestCollectionManager collectionManager = new ReactiveIntegrationTestCollectionManager(); |
38 | 53 |
|
@@ -67,4 +82,58 @@ public void testSaveWithSuppressedNullValue() { |
67 | 82 | final Mono<Boolean> existLastNameMono = repository.existsByLastNameIsNull(); |
68 | 83 | StepVerifier.create(existLastNameMono).expectNext(false).expectComplete().verify(); |
69 | 84 | } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void testAnnotatedQueryWithArrayContains() { |
| 88 | + final Mono<Void> deletedMono = repository.deleteAll(); |
| 89 | + StepVerifier.create(deletedMono).thenAwait().verifyComplete(); |
| 90 | + final Flux<ReactiveTeacher> savedFlux = repository.saveAll(Arrays.asList(TEACHER_1, TEACHER_2, TEACHER_3)); |
| 91 | + StepVerifier.create(savedFlux).thenConsumeWhile(ReactiveTeacher -> true).expectComplete().verify(); |
| 92 | + |
| 93 | + List<String> firstNames = new ArrayList<>(); |
| 94 | + firstNames.add(TEACHER_FIRST_NAME_1); |
| 95 | + final Flux<ReactiveTeacher> resultsAsc = repository.annotatedFindByFirstNames(firstNames); |
| 96 | + StepVerifier.create(resultsAsc) |
| 97 | + .expectNextMatches(teacher -> teacher.getId().equals(TEACHER_ID_1)) |
| 98 | + .expectNextMatches(teacher -> teacher.getId().equals(TEACHER_ID_2)) |
| 99 | + .verifyComplete(); |
| 100 | + |
| 101 | + List<String> firstNames2 = new ArrayList<>(); |
| 102 | + firstNames2.add(TEACHER_FIRST_NAME_1); |
| 103 | + firstNames2.add(TEACHER_FIRST_NAME_2); |
| 104 | + final Flux<ReactiveTeacher> resultsAsc2 = repository.annotatedFindByFirstNames(firstNames2); |
| 105 | + StepVerifier.create(resultsAsc2) |
| 106 | + .expectNextMatches(teacher -> teacher.getId().equals(TEACHER_ID_1)) |
| 107 | + .expectNextMatches(teacher -> teacher.getId().equals(TEACHER_ID_2)) |
| 108 | + .expectNextMatches(teacher -> teacher.getId().equals(TEACHER_ID_3)) |
| 109 | + .verifyComplete(); |
| 110 | + |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + public void testAnnotatedQueryWithArrayContainsAndSort() { |
| 115 | + final Mono<Void> deletedMono = repository.deleteAll(); |
| 116 | + StepVerifier.create(deletedMono).thenAwait().verifyComplete(); |
| 117 | + final Flux<ReactiveTeacher> savedFlux = repository.saveAll(Arrays.asList(TEACHER_1, TEACHER_2, TEACHER_3)); |
| 118 | + StepVerifier.create(savedFlux).thenConsumeWhile(ReactiveTeacher -> true).expectComplete().verify(); |
| 119 | + |
| 120 | + List<String> firstNames = new ArrayList<>(); |
| 121 | + firstNames.add(TEACHER_FIRST_NAME_1); |
| 122 | + final Flux<ReactiveTeacher> resultsAsc = repository.annotatedFindByFirstNamesWithSort(firstNames, Sort.by(Sort.Direction.DESC, "id")); |
| 123 | + StepVerifier.create(resultsAsc) |
| 124 | + .expectNextMatches(teacher -> teacher.getId().equals(TEACHER_ID_2)) |
| 125 | + .expectNextMatches(teacher -> teacher.getId().equals(TEACHER_ID_1)) |
| 126 | + .verifyComplete(); |
| 127 | + |
| 128 | + List<String> firstNames2 = new ArrayList<>(); |
| 129 | + firstNames2.add(TEACHER_FIRST_NAME_1); |
| 130 | + firstNames2.add(TEACHER_FIRST_NAME_2); |
| 131 | + final Flux<ReactiveTeacher> resultsAsc2 = repository.annotatedFindByFirstNamesWithSort(firstNames2, Sort.by(Sort.Direction.DESC, "id")); |
| 132 | + StepVerifier.create(resultsAsc2) |
| 133 | + .expectNextMatches(teacher -> teacher.getId().equals(TEACHER_ID_3)) |
| 134 | + .expectNextMatches(teacher -> teacher.getId().equals(TEACHER_ID_2)) |
| 135 | + .expectNextMatches(teacher -> teacher.getId().equals(TEACHER_ID_1)) |
| 136 | + .verifyComplete(); |
| 137 | + |
| 138 | + } |
70 | 139 | } |
0 commit comments