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 , "travel-sample" , new SpelExpressionParser (),
88
- QueryMethodEvaluationContextProvider .DEFAULT , namedQueries );
89
-
90
- Query query = creator .createQuery ();
91
- assertEquals (
92
- "SELECT `_class`, META(`travel-sample`).`cas` AS __cas, `createdBy`, `createdDate`, `lastModifiedBy`, `lastModifiedDate`, META(`travel-sample`).`id` AS __id, `firstname`, `lastname`, `subtype` FROM `travel-sample` where `_class` = \" abstractuser\" and firstname = $1 and lastname = $2" ,
93
- query .toN1qlSelectString (couchbaseTemplate .reactive (), User .class , false ));
94
- }
95
-
96
- @ Test
97
- void createsQueryCorrectly2 () throws Exception {
98
- String input = "getByFirstnameOrLastname" ;
99
- Method method = UserRepository .class .getMethod (input , String .class , String .class );
100
-
101
- CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod (method ,
102
- new DefaultRepositoryMetadata (UserRepository .class ), new SpelAwareProxyProjectionFactory (),
103
- converter .getMappingContext ());
104
-
105
- StringN1qlQueryCreator creator = new StringN1qlQueryCreator (getAccessor (getParameters (method ), "Oliver" , "Twist" ),
106
- queryMethod , converter , "travel-sample" , new SpelExpressionParser (),
107
- QueryMethodEvaluationContextProvider .DEFAULT , namedQueries );
108
-
109
- Query query = creator .createQuery ();
110
- assertEquals (
111
- "SELECT `_class`, META(`travel-sample`).`cas` AS __cas, `createdBy`, `createdDate`, `lastModifiedBy`, `lastModifiedDate`, META(`travel-sample`).`id` AS __id, `firstname`, `lastname`, `subtype` FROM `travel-sample` where `_class` = \" abstractuser\" and (firstname = $first or lastname = $last)" ,
112
- query .toN1qlSelectString (couchbaseTemplate .reactive (), User .class , false ));
113
72
}
114
73
115
74
@ Test
@@ -123,8 +82,8 @@ void wrongNumberArgs() throws Exception {
123
82
124
83
try {
125
84
StringN1qlQueryCreator creator = new StringN1qlQueryCreator (getAccessor (getParameters (method ), "Oliver" ),
126
- queryMethod , converter , "travel-sample" , new SpelExpressionParser (),
127
- QueryMethodEvaluationContextProvider . DEFAULT , namedQueries );
85
+ queryMethod , converter , "travel-sample" , new SpelExpressionParser (), QueryMethodEvaluationContextProvider . DEFAULT ,
86
+ namedQueries );
128
87
} catch (IllegalArgumentException e ) {
129
88
return ;
130
89
}
@@ -141,8 +100,8 @@ void doesNotHaveAnnotation() throws Exception {
141
100
142
101
try {
143
102
StringN1qlQueryCreator creator = new StringN1qlQueryCreator (getAccessor (getParameters (method ), "Oliver" ),
144
- queryMethod , converter , "travel-sample" , new SpelExpressionParser (),
145
- QueryMethodEvaluationContextProvider . DEFAULT , namedQueries );
103
+ queryMethod , converter , "travel-sample" , new SpelExpressionParser (), QueryMethodEvaluationContextProvider . DEFAULT ,
104
+ namedQueries );
146
105
} catch (IllegalArgumentException e ) {
147
106
return ;
148
107
}
@@ -157,37 +116,4 @@ private ParameterAccessor getAccessor(Parameters<?, ?> params, Object... values)
157
116
return new DefaultParameters (method );
158
117
}
159
118
160
- @ Configuration
161
- @ EnableCouchbaseRepositories ("org.springframework.data.couchbase" )
162
- static class Config extends AbstractCouchbaseConfiguration {
163
-
164
- @ Override
165
- public String getConnectionString () {
166
- return connectionString ();
167
- }
168
-
169
- @ Override
170
- public String getUserName () {
171
- return config ().adminUsername ();
172
- }
173
-
174
- @ Override
175
- public String getPassword () {
176
- return config ().adminPassword ();
177
- }
178
-
179
- @ Override
180
- public String getBucketName () {
181
- return bucketName ();
182
- }
183
-
184
- @ Override
185
- protected void configureEnvironment (ClusterEnvironment .Builder builder ) {
186
- if (config ().isUsingCloud ()) {
187
- builder .securityConfig (
188
- SecurityConfig .builder ().trustManagerFactory (InsecureTrustManagerFactory .INSTANCE ).enableTls (true ));
189
- }
190
- }
191
-
192
- }
193
119
}
0 commit comments