|
28 | 28 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
29 | 29 | import org.springframework.context.annotation.Configuration;
|
30 | 30 | import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
31 |
| -import org.springframework.data.couchbase.core.CouchbaseTemplate; |
32 | 31 | import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
|
33 | 32 | import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
|
34 | 33 | import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
|
|
55 | 54 | * @author Michael Nitschinger
|
56 | 55 | * @author Michael Reiche
|
57 | 56 | */
|
58 |
| -class StringN1qlQueryCreatorMockedTests extends ClusterAwareIntegrationTests { |
| 57 | +class StringN1qlQueryCreatorMockedTests { |
59 | 58 |
|
60 | 59 | MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> context;
|
61 | 60 | CouchbaseConverter converter;
|
62 |
| - CouchbaseTemplate couchbaseTemplate; |
63 | 61 | static NamedQueries namedQueries = new PropertiesBasedNamedQueries(new Properties());
|
64 | 62 |
|
65 | 63 | @BeforeEach
|
66 | 64 | public void beforeEach() {
|
67 | 65 | context = new CouchbaseMappingContext();
|
68 | 66 | converter = new MappingCouchbaseConverter(context);
|
69 |
| - ApplicationContext ac = new AnnotationConfigApplicationContext(Config.class); |
70 |
| - couchbaseTemplate = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE); |
71 |
| - } |
72 |
| - |
73 |
| - @Test |
74 |
| - void createsQueryCorrectly() throws Exception { |
75 |
| - String input = "getByFirstnameAndLastname"; |
76 |
| - Method method = UserRepository.class.getMethod(input, String.class, String.class); |
77 |
| - |
78 |
| - CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, |
79 |
| - new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory(), |
80 |
| - converter.getMappingContext()); |
81 |
| - |
82 |
| - StringN1qlQueryCreator creator = new StringN1qlQueryCreator(getAccessor(getParameters(method), "Oliver", "Twist"), |
83 |
| - queryMethod, converter, "travel-sample", new SpelExpressionParser(), |
84 |
| - QueryMethodEvaluationContextProvider.DEFAULT, namedQueries); |
85 |
| - |
86 |
| - Query query = creator.createQuery(); |
87 |
| - assertEquals( |
88 |
| - "SELECT META(`travel-sample`).id AS __id, META(`travel-sample`).cas AS __cas, `travel-sample`.* FROM `travel-sample` where `_class` = \"org.springframework.data.couchbase.domain.User\" and firstname = $1 and lastname = $2", |
89 |
| - query.toN1qlSelectString(couchbaseTemplate.reactive(), User.class, false)); |
90 |
| - } |
91 |
| - |
92 |
| - @Test |
93 |
| - void createsQueryCorrectly2() throws Exception { |
94 |
| - String input = "getByFirstnameOrLastname"; |
95 |
| - Method method = UserRepository.class.getMethod(input, String.class, String.class); |
96 |
| - |
97 |
| - CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, |
98 |
| - new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory(), |
99 |
| - converter.getMappingContext()); |
100 |
| - |
101 |
| - StringN1qlQueryCreator creator = new StringN1qlQueryCreator(getAccessor(getParameters(method), "Oliver", "Twist"), |
102 |
| - queryMethod, converter, "travel-sample", new SpelExpressionParser(), |
103 |
| - QueryMethodEvaluationContextProvider.DEFAULT, namedQueries); |
104 |
| - |
105 |
| - Query query = creator.createQuery(); |
106 |
| - assertEquals( |
107 |
| - "SELECT META(`travel-sample`).id AS __id, META(`travel-sample`).cas AS __cas, `travel-sample`.* FROM `travel-sample` where `_class` = \"org.springframework.data.couchbase.domain.User\" and (firstname = $first or lastname = $last)", |
108 |
| - query.toN1qlSelectString(couchbaseTemplate.reactive(), User.class, false)); |
109 | 67 | }
|
110 | 68 |
|
111 | 69 | @Test
|
@@ -153,29 +111,4 @@ private ParameterAccessor getAccessor(Parameters<?, ?> params, Object... values)
|
153 | 111 | return new DefaultParameters(method);
|
154 | 112 | }
|
155 | 113 |
|
156 |
| - @Configuration |
157 |
| - @EnableCouchbaseRepositories("org.springframework.data.couchbase") |
158 |
| - static class Config extends AbstractCouchbaseConfiguration { |
159 |
| - |
160 |
| - @Override |
161 |
| - public String getConnectionString() { |
162 |
| - return connectionString(); |
163 |
| - } |
164 |
| - |
165 |
| - @Override |
166 |
| - public String getUserName() { |
167 |
| - return config().adminUsername(); |
168 |
| - } |
169 |
| - |
170 |
| - @Override |
171 |
| - public String getPassword() { |
172 |
| - return config().adminPassword(); |
173 |
| - } |
174 |
| - |
175 |
| - @Override |
176 |
| - public String getBucketName() { |
177 |
| - return bucketName(); |
178 |
| - } |
179 |
| - |
180 |
| - } |
181 | 114 | }
|
0 commit comments