25
25
import java .util .List ;
26
26
import java .util .Locale ;
27
27
28
+ import com .couchbase .client .core .deps .com .fasterxml .jackson .databind .node .ArrayNode ;
29
+ import com .couchbase .client .java .query .QueryOptions ;
28
30
import org .junit .jupiter .api .BeforeEach ;
29
31
import org .junit .jupiter .api .Test ;
30
32
import org .springframework .data .couchbase .core .convert .CouchbaseConverter ;
31
33
import org .springframework .data .couchbase .core .convert .MappingCouchbaseConverter ;
32
34
import org .springframework .data .couchbase .core .mapping .CouchbaseMappingContext ;
33
35
import org .springframework .data .couchbase .core .mapping .CouchbasePersistentEntity ;
34
36
import org .springframework .data .couchbase .core .mapping .CouchbasePersistentProperty ;
37
+ import org .springframework .data .couchbase .core .query .OptionsBuilder ;
35
38
import org .springframework .data .couchbase .core .query .Query ;
36
39
import org .springframework .data .couchbase .domain .Person ;
37
40
import org .springframework .data .couchbase .domain .PersonRepository ;
@@ -119,18 +122,17 @@ void queryParametersArray() throws Exception {
119
122
QueryMethod queryMethod = new QueryMethod (method , new DefaultRepositoryMetadata (UserRepository .class ),
120
123
new SpelAwareProxyProjectionFactory ());
121
124
Query expected = (new Query ()).addCriteria (where (i ("firstname" )).in ("Oliver" , "Charles" ));
125
+ JsonArray parameters = JsonArray .create ().add (JsonArray .create ().add ("Oliver" ).add ("Charles" ));
126
+ QueryOptions expectedQOptions = QueryOptions .queryOptions ().parameters (parameters );
122
127
N1qlQueryCreator creator = new N1qlQueryCreator (tree ,
123
128
getAccessor (getParameters (method ), new Object [] { new Object [] { "Oliver" , "Charles" } }), queryMethod ,
124
129
converter , bucketName );
125
130
Query query = creator .createQuery ();
126
131
127
- // Query expected = (new Query()).addCriteria(where("firstname").in("Oliver", "Charles"));
128
132
assertEquals (" WHERE `firstname` in $1" , query .export (new int [1 ]));
129
- JsonObject expectedOptions = JsonObject .create ();
130
- expected .buildQueryOptions (null , null ).build ().injectParams (expectedOptions );
131
- JsonObject actualOptions = JsonObject .create ();
132
- expected .buildQueryOptions (null , null ).build ().injectParams (actualOptions );
133
- assertEquals (expectedOptions .removeKey ("client_context_id" ), actualOptions .removeKey ("client_context_id" ));
133
+ ArrayNode expectedOptions = expected .buildQueryOptions (expectedQOptions , null ).build ().positionalParameters ();
134
+ ArrayNode actualOptions = query .buildQueryOptions (null , null ).build ().positionalParameters ();
135
+ assertEquals (expectedOptions .toString (), actualOptions .toString ());
134
136
}
135
137
136
138
@ Test
@@ -148,12 +150,12 @@ void queryParametersJsonArray() throws Exception {
148
150
Query query = creator .createQuery ();
149
151
150
152
Query expected = (new Query ()).addCriteria (where (i ("firstname" )).in ("Oliver" , "Charles" ));
153
+ JsonArray parameters = JsonArray .create ().add (JsonArray .create ().add ("Oliver" ).add ("Charles" ));
154
+ QueryOptions expectedQOptions = QueryOptions .queryOptions ().parameters (parameters );
151
155
assertEquals (" WHERE `firstname` in $1" , query .export (new int [1 ]));
152
- JsonObject expectedOptions = JsonObject .create ();
153
- expected .buildQueryOptions (null , null ).build ().injectParams (expectedOptions );
154
- JsonObject actualOptions = JsonObject .create ();
155
- expected .buildQueryOptions (null , null ).build ().injectParams (actualOptions );
156
- assertEquals (expectedOptions .removeKey ("client_context_id" ), actualOptions .removeKey ("client_context_id" ));
156
+ ArrayNode expectedOptions = expected .buildQueryOptions (expectedQOptions , null ).build ().positionalParameters ();
157
+ ArrayNode actualOptions = query .buildQueryOptions (null , null ).build ().positionalParameters ();
158
+ assertEquals (expectedOptions .toString (), actualOptions .toString ());
157
159
}
158
160
159
161
@ Test
@@ -171,13 +173,13 @@ void queryParametersList() throws Exception {
171
173
Query query = creator .createQuery ();
172
174
173
175
Query expected = (new Query ()).addCriteria (where (i ("firstname" )).in ("Oliver" , "Charles" ));
176
+ JsonArray parameters = JsonArray .create ().add (JsonArray .create ().add ("Oliver" ).add ("Charles" ));
177
+ QueryOptions expectedQOptions = QueryOptions .queryOptions ().parameters (parameters );
174
178
175
179
assertEquals (" WHERE `firstname` in $1" , query .export (new int [1 ]));
176
- JsonObject expectedOptions = JsonObject .create ();
177
- expected .buildQueryOptions (null , null ).build ().injectParams (expectedOptions );
178
- JsonObject actualOptions = JsonObject .create ();
179
- expected .buildQueryOptions (null , null ).build ().injectParams (actualOptions );
180
- assertEquals (expectedOptions .removeKey ("client_context_id" ), actualOptions .removeKey ("client_context_id" ));
180
+ ArrayNode expectedOptions = expected .buildQueryOptions (expectedQOptions , null ).build ().positionalParameters ();
181
+ ArrayNode actualOptions = query .buildQueryOptions (null , null ).build ().positionalParameters ();
182
+ assertEquals (expectedOptions .toString (), actualOptions .toString ());
181
183
}
182
184
183
185
@ Test
0 commit comments