16
16
17
17
package org .springframework .data .couchbase .repository ;
18
18
19
- import static java .util .Arrays .*;
20
- import static org .assertj .core .api .Assertions .*;
21
- import static org .junit .jupiter .api .Assertions .*;
19
+ import static java .util .Arrays .asList ;
20
+ import static org .assertj .core .api .Assertions .assertThat ;
21
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
22
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
23
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
24
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
22
25
23
26
import java .util .ArrayList ;
24
27
import java .util .Arrays ;
49
52
import org .springframework .data .couchbase .util .ClusterAwareIntegrationTests ;
50
53
import org .springframework .data .couchbase .util .ClusterType ;
51
54
import org .springframework .data .couchbase .util .IgnoreWhen ;
52
- import org .springframework .data .util .StreamUtils ;
53
55
import org .springframework .data .domain .Page ;
54
56
import org .springframework .data .domain .PageRequest ;
55
57
import org .springframework .data .domain .Pageable ;
56
58
import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
57
59
58
60
import com .couchbase .client .core .error .IndexExistsException ;
59
- import reactor .core .publisher .Flux ;
61
+ import com .couchbase .client .java .query .QueryOptions ;
62
+ import com .couchbase .client .java .query .QueryScanConsistency ;
60
63
61
64
/**
62
65
* Repository tests
@@ -112,6 +115,22 @@ void nestedFind() {
112
115
personRepository .save (person );
113
116
List <Person > persons = personRepository .findByAddressStreet ("Maple" );
114
117
assertEquals (1 , persons .size ());
118
+ List <Person > persons2 = personRepository .findByMiddlename ("Nick" );
119
+ assertEquals (1 , persons2 .size ());
120
+ } finally {
121
+ personRepository .deleteById (person .getId ().toString ());
122
+ }
123
+ }
124
+
125
+ @ Test
126
+ void annotatedFieldFind () {
127
+ Person person = null ;
128
+ try {
129
+ person = new Person (1 , "first" , "last" );
130
+ person .setMiddlename ("Nick" ); // middlename is stored as nickname
131
+ personRepository .save (person );
132
+ List <Person > persons2 = personRepository .findByMiddlename ("Nick" );
133
+ assertEquals (1 , persons2 .size ());
115
134
} finally {
116
135
personRepository .deleteById (person .getId ().toString ());
117
136
}
@@ -145,12 +164,15 @@ void findBySimpleProperty() {
145
164
try {
146
165
vie = new Airport ("airports::vie" , "vie" , "loww" );
147
166
vie = airportRepository .save (vie );
167
+ Airport airport2 = airportRepository .findByIata (vie .getIata (),
168
+ QueryOptions .queryOptions ().scanConsistency (QueryScanConsistency .NOT_BOUNDED ));
169
+ assertEquals (airport2 .getId (), vie .getId ());
170
+
148
171
List <Airport > airports = airportRepository .findAllByIata ("vie" );
149
172
assertEquals (1 , airports .size ());
150
173
Airport airport1 = airportRepository .findById (airports .get (0 ).getId ()).get ();
151
174
assertEquals (airport1 .getIata (), vie .getIata ());
152
- Airport airport2 = airportRepository .findByIata (airports .get (0 ).getIata ());
153
- assertEquals (airport1 .getId (), vie .getId ());
175
+
154
176
} finally {
155
177
airportRepository .delete (vie );
156
178
}
@@ -173,7 +195,9 @@ void count() {
173
195
174
196
try {
175
197
176
- airportRepository .saveAll ( Arrays .stream (iatas ).map ((iata ) -> new Airport ("airports::" +iata , iata , iata .toLowerCase (Locale .ROOT ))).collect (Collectors .toSet ()));
198
+ airportRepository .saveAll (
199
+ Arrays .stream (iatas ).map ((iata ) -> new Airport ("airports::" + iata , iata , iata .toLowerCase (Locale .ROOT )))
200
+ .collect (Collectors .toSet ()));
177
201
Long count = airportRepository .countFancyExpression (asList ("JFK" ), asList ("jfk" ), false );
178
202
assertEquals (1 , count );
179
203
@@ -198,7 +222,8 @@ void count() {
198
222
assertEquals (0 , airportCount );
199
223
200
224
} finally {
201
- airportRepository .deleteAllById (Arrays .stream (iatas ).map ((iata ) -> "airports::" +iata ).collect (Collectors .toSet ()));
225
+ airportRepository
226
+ .deleteAllById (Arrays .stream (iatas ).map ((iata ) -> "airports::" + iata ).collect (Collectors .toSet ()));
202
227
}
203
228
}
204
229
@@ -295,7 +320,6 @@ void deleteAllById() {
295
320
296
321
airportRepository .deleteAllById (asList (vienna .getId (), losAngeles .getId ()));
297
322
298
-
299
323
assertThat (airportRepository .findAll ()).containsExactly (frankfurt );
300
324
} finally {
301
325
airportRepository .deleteAll ();
0 commit comments