59
59
* @author Michael Nitschinger
60
60
* @author Michael Reiche
61
61
*/
62
- class StringN1qlQueryCreatorMockedTests extends ClusterAwareIntegrationTests {
62
+ class StringN1qlQueryCreatorMockedTests {
63
63
64
64
MappingContext <? extends CouchbasePersistentEntity <?>, CouchbasePersistentProperty > context ;
65
65
CouchbaseConverter converter ;
66
- CouchbaseTemplate couchbaseTemplate ;
67
66
static NamedQueries namedQueries = new PropertiesBasedNamedQueries (new Properties ());
68
67
69
68
@ BeforeEach
70
69
public void beforeEach () {
71
70
context = new CouchbaseMappingContext ();
72
71
converter = new MappingCouchbaseConverter (context );
73
- ApplicationContext ac = new AnnotationConfigApplicationContext (Config .class );
74
- couchbaseTemplate = (CouchbaseTemplate ) ac .getBean (COUCHBASE_TEMPLATE );
75
- }
76
-
77
- @ Test
78
- void createsQueryCorrectly () throws Exception {
79
- String input = "getByFirstnameAndLastname" ;
80
- Method method = UserRepository .class .getMethod (input , String .class , String .class );
81
-
82
- CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod (method ,
83
- new DefaultRepositoryMetadata (UserRepository .class ), new SpelAwareProxyProjectionFactory (),
84
- converter .getMappingContext ());
85
-
86
- StringN1qlQueryCreator creator = new StringN1qlQueryCreator (getAccessor (getParameters (method ), "Oliver" , "Twist" ),
87
- queryMethod , converter , new SpelExpressionParser (), QueryMethodEvaluationContextProvider .DEFAULT , namedQueries );
88
-
89
- Query query = creator .createQuery ();
90
- assertEquals (
91
- "SELECT `_class`, META(`" + bucketName ()
92
- + "`).`cas` AS __cas, `createdBy`, `createdDate`, `lastModifiedBy`, `lastModifiedDate`, META(`"
93
- + bucketName () + "`).`id` AS __id, `firstname`, `lastname`, `subtype` FROM `" + bucketName ()
94
- + "` where `_class` = \" abstractuser\" and firstname = $1 and lastname = $2" ,
95
- query .toN1qlSelectString (couchbaseTemplate .reactive (), null , null , User .class , User .class , false , null , null ));
96
- }
97
-
98
- @ Test
99
- void createsQueryCorrectly2 () throws Exception {
100
- String input = "getByFirstnameOrLastname" ;
101
- Method method = UserRepository .class .getMethod (input , String .class , String .class );
102
-
103
- CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod (method ,
104
- new DefaultRepositoryMetadata (UserRepository .class ), new SpelAwareProxyProjectionFactory (),
105
- converter .getMappingContext ());
106
-
107
- StringN1qlQueryCreator creator = new StringN1qlQueryCreator (getAccessor (getParameters (method ), "Oliver" , "Twist" ),
108
- queryMethod , converter , new SpelExpressionParser (), QueryMethodEvaluationContextProvider .DEFAULT , namedQueries );
109
-
110
- Query query = creator .createQuery ();
111
- assertEquals (
112
- "SELECT `_class`, META(`" + bucketName ()
113
- + "`).`cas` AS __cas, `createdBy`, `createdDate`, `lastModifiedBy`, `lastModifiedDate`, META(`"
114
- + bucketName () + "`).`id` AS __id, `firstname`, `lastname`, `subtype` FROM `" + bucketName ()
115
- + "` where `_class` = \" abstractuser\" and (firstname = $first or lastname = $last)" ,
116
- query .toN1qlSelectString (couchbaseTemplate .reactive (), null , null , User .class , User .class , false , null , null ));
117
72
}
118
73
119
74
@ Test
@@ -153,25 +108,6 @@ queryMethod, converter, new SpelExpressionParser(), QueryMethodEvaluationContext
153
108
fail ("should have failed with IllegalArgumentException: query has no inline Query or named Query not found" );
154
109
}
155
110
156
- @ Test
157
- void spelTests () throws Exception {
158
- String input = "spelTests" ;
159
- Method method = UserRepository .class .getMethod (input );
160
- CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod (method ,
161
- new DefaultRepositoryMetadata (UserRepository .class ), new SpelAwareProxyProjectionFactory (),
162
- converter .getMappingContext ());
163
-
164
- StringN1qlQueryCreator creator = new StringN1qlQueryCreator (getAccessor (getParameters (method )), queryMethod ,
165
- converter , new SpelExpressionParser (), QueryMethodEvaluationContextProvider .DEFAULT , namedQueries );
166
-
167
- Query query = creator .createQuery ();
168
-
169
- String s = query .toN1qlSelectString (couchbaseTemplate .reactive (), "myScope" , "myCollection" , User .class , null ,
170
- false , null , null );
171
- System .out .println ("query: " + s );
172
-
173
- }
174
-
175
111
private ParameterAccessor getAccessor (Parameters <?, ?> params , Object ... values ) {
176
112
return new ParametersParameterAccessor (params , values );
177
113
}
@@ -180,37 +116,4 @@ private ParameterAccessor getAccessor(Parameters<?, ?> params, Object... values)
180
116
return new DefaultParameters (method );
181
117
}
182
118
183
- @ Configuration
184
- @ EnableCouchbaseRepositories ("org.springframework.data.couchbase" )
185
- static class Config extends AbstractCouchbaseConfiguration {
186
-
187
- @ Override
188
- public String getConnectionString () {
189
- return connectionString ();
190
- }
191
-
192
- @ Override
193
- public String getUserName () {
194
- return config ().adminUsername ();
195
- }
196
-
197
- @ Override
198
- public String getPassword () {
199
- return config ().adminPassword ();
200
- }
201
-
202
- @ Override
203
- public String getBucketName () {
204
- return bucketName ();
205
- }
206
-
207
- @ Override
208
- protected void configureEnvironment (ClusterEnvironment .Builder builder ) {
209
- if (config ().isUsingCloud ()) {
210
- builder .securityConfig (
211
- SecurityConfig .builder ().trustManagerFactory (InsecureTrustManagerFactory .INSTANCE ).enableTls (true ));
212
- }
213
- }
214
-
215
- }
216
119
}
0 commit comments