23
23
import static org .junit .jupiter .api .Assertions .assertThrows ;
24
24
import static org .junit .jupiter .api .Assertions .assertTrue ;
25
25
26
+ import java .lang .reflect .Method ;
26
27
import java .util .ArrayList ;
27
28
import java .util .Arrays ;
28
29
import java .util .List ;
40
41
import org .springframework .dao .DataIntegrityViolationException ;
41
42
import org .springframework .data .couchbase .CouchbaseClientFactory ;
42
43
import org .springframework .data .couchbase .config .AbstractCouchbaseConfiguration ;
44
+ import org .springframework .data .couchbase .core .CouchbaseTemplate ;
43
45
import org .springframework .data .couchbase .domain .Address ;
44
46
import org .springframework .data .couchbase .domain .Airport ;
45
47
import org .springframework .data .couchbase .domain .AirportRepository ;
48
50
import org .springframework .data .couchbase .domain .User ;
49
51
import org .springframework .data .couchbase .domain .UserRepository ;
50
52
import org .springframework .data .couchbase .repository .config .EnableCouchbaseRepositories ;
53
+ import org .springframework .data .couchbase .repository .query .CouchbaseQueryMethod ;
54
+ import org .springframework .data .couchbase .repository .query .CouchbaseRepositoryQuery ;
51
55
import org .springframework .data .couchbase .util .Capabilities ;
52
56
import org .springframework .data .couchbase .util .ClusterAwareIntegrationTests ;
53
57
import org .springframework .data .couchbase .util .ClusterType ;
54
58
import org .springframework .data .couchbase .util .IgnoreWhen ;
55
59
import org .springframework .data .domain .Page ;
56
60
import org .springframework .data .domain .PageRequest ;
57
61
import org .springframework .data .domain .Pageable ;
62
+ import org .springframework .data .projection .SpelAwareProxyProjectionFactory ;
63
+ import org .springframework .data .repository .core .support .DefaultRepositoryMetadata ;
58
64
import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
59
65
60
66
import com .couchbase .client .core .error .IndexExistsException ;
@@ -76,6 +82,8 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
76
82
77
83
@ Autowired UserRepository userRepository ;
78
84
85
+ @ Autowired CouchbaseTemplate couchbaseTemplate ;
86
+
79
87
@ BeforeEach
80
88
public void beforeEach () {
81
89
try {
@@ -305,6 +313,21 @@ void deleteAllById() {
305
313
}
306
314
}
307
315
316
+ @ Test
317
+ void couchbaseRepositoryQuery () throws Exception {
318
+ User user = new User ("1" , "Dave" , "Wilson" );
319
+ userRepository .save (user );
320
+ String input = "findByFirstname" ;
321
+ Method method = UserRepository .class .getMethod (input , String .class );
322
+ CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod (method ,
323
+ new DefaultRepositoryMetadata (UserRepository .class ), new SpelAwareProxyProjectionFactory (),
324
+ couchbaseTemplate .getConverter ().getMappingContext ());
325
+
326
+ CouchbaseRepositoryQuery query = new CouchbaseRepositoryQuery (couchbaseTemplate , queryMethod , null );
327
+ List <User > users = (List <User >)query .execute (new String [] { "Dave" });
328
+ assertEquals (user , users .get (0 ));
329
+ }
330
+
308
331
private void sleep (int millis ) {
309
332
try {
310
333
Thread .sleep (millis ); // so they are executed out-of-order
0 commit comments