Skip to content

Commit e01ada6

Browse files
committed
Move tests needing server to IntegrationTests.
Closes #1472.
1 parent 995608a commit e01ada6

File tree

3 files changed

+97
-76
lines changed

3 files changed

+97
-76
lines changed

src/test/java/org/springframework/data/couchbase/domain/FluxTest.java renamed to src/test/java/org/springframework/data/couchbase/domain/FluxTestIntegrationTests.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.data.couchbase.domain;
218

319
import com.couchbase.client.java.query.QueryOptions;
@@ -40,20 +56,25 @@
4056
import com.couchbase.client.java.ReactiveCollection;
4157
import com.couchbase.client.java.json.JsonObject;
4258
import com.couchbase.client.java.kv.GetResult;
59+
import com.couchbase.client.java.query.QueryOptions;
60+
import com.couchbase.client.java.query.QueryProfile;
61+
import com.couchbase.client.java.query.QueryResult;
62+
import com.couchbase.client.java.query.QueryScanConsistency;
4363

44-
import static org.junit.jupiter.api.Assertions.assertEquals;
45-
46-
@SpringJUnitConfig(FluxTest.Config.class)
64+
/**
65+
* @author Michael Reiche
66+
*/
67+
@SpringJUnitConfig(FluxTestIntegrationTests.Config.class)
4768
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
48-
public class FluxTest extends JavaIntegrationTests {
69+
public class FluxTestIntegrationTests extends JavaIntegrationTests {
4970

5071
@BeforeAll
5172
public static void beforeEverything() {
5273
/**
5374
* The couchbaseTemplate inherited from JavaIntegrationTests uses org.springframework.data.couchbase.domain.Config
5475
* It has typeName = 't' (instead of _class). Don't use it.
5576
*/
56-
ApplicationContext ac = new AnnotationConfigApplicationContext(FluxTest.Config.class);
77+
ApplicationContext ac = new AnnotationConfigApplicationContext(FluxTestIntegrationTests.Config.class);
5778
couchbaseTemplate = (CouchbaseTemplate) ac.getBean(BeanNames.COUCHBASE_TEMPLATE);
5879
reactiveCouchbaseTemplate = (ReactiveCouchbaseTemplate) ac.getBean(BeanNames.REACTIVE_COUCHBASE_TEMPLATE);
5980
collection = couchbaseTemplate.getCouchbaseClientFactory().getBucket().defaultCollection();
@@ -127,7 +148,9 @@ public void cbse() {
127148
throw e;
128149
}
129150
List<Airport> airports = airportRepository.findAll().collectList().block();
130-
assertEquals(0, airports.size(), "should have been all deleted");
151+
if (airports.size() != 0){
152+
throw new RuntimeException("should have been all deleted");
153+
}
131154
}
132155

133156
@Test

src/test/java/org/springframework/data/couchbase/repository/query/StringN1qlQueryCreatorTests.java renamed to src/test/java/org/springframework/data/couchbase/repository/query/StringN1qlQueryCreatorIntegrationTests.java

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.springframework.data.couchbase.core.query.Query;
4040
import org.springframework.data.couchbase.domain.Airline;
4141
import org.springframework.data.couchbase.domain.AirlineRepository;
42+
import org.springframework.data.couchbase.domain.User;
43+
import org.springframework.data.couchbase.domain.UserRepository;
4244
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
4345
import org.springframework.data.couchbase.util.Capabilities;
4446
import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
@@ -61,9 +63,9 @@
6163
* @author Michael Nitschinger
6264
* @author Michael Reiche
6365
*/
64-
@SpringJUnitConfig(StringN1qlQueryCreatorTests.Config.class)
66+
@SpringJUnitConfig(StringN1qlQueryCreatorIntegrationTests.Config.class)
6567
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
66-
class StringN1qlQueryCreatorTests extends ClusterAwareIntegrationTests {
68+
class StringN1qlQueryCreatorIntegrationTests extends ClusterAwareIntegrationTests {
6769

6870
MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> context;
6971
CouchbaseConverter converter;
@@ -114,6 +116,68 @@ queryMethod, converter, config().bucketname(), new SpelExpressionParser(),
114116
}
115117
}
116118

119+
120+
@Test
121+
void createsQueryCorrectly() throws Exception {
122+
String input = "getByFirstnameAndLastname";
123+
Method method = UserRepository.class.getMethod(input, String.class, String.class);
124+
125+
CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method,
126+
new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory(),
127+
converter.getMappingContext());
128+
129+
StringN1qlQueryCreator creator = new StringN1qlQueryCreator(getAccessor(getParameters(method), "Oliver", "Twist"),
130+
queryMethod, converter, config().bucketname(), new SpelExpressionParser(), QueryMethodEvaluationContextProvider.DEFAULT, namedQueries);
131+
132+
Query query = creator.createQuery();
133+
assertEquals(
134+
"SELECT `_class`, META(`" + bucketName()
135+
+ "`).`cas` AS __cas, `createdBy`, `createdDate`, `lastModifiedBy`, `lastModifiedDate`, META(`"
136+
+ bucketName() + "`).`id` AS __id, `firstname`, `lastname`, `subtype` FROM `" + bucketName()
137+
+ "` where `_class` = \"abstractuser\" and firstname = $1 and lastname = $2",
138+
query.toN1qlSelectString(couchbaseTemplate.reactive(), config().bucketname(), User.class, false));
139+
}
140+
141+
@Test
142+
void createsQueryCorrectly2() throws Exception {
143+
String input = "getByFirstnameOrLastname";
144+
Method method = UserRepository.class.getMethod(input, String.class, String.class);
145+
146+
CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method,
147+
new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory(),
148+
converter.getMappingContext());
149+
150+
StringN1qlQueryCreator creator = new StringN1qlQueryCreator(getAccessor(getParameters(method), "Oliver", "Twist"),
151+
queryMethod, converter, config().bucketname(), new SpelExpressionParser(), QueryMethodEvaluationContextProvider.DEFAULT, namedQueries);
152+
153+
Query query = creator.createQuery();
154+
assertEquals(
155+
"SELECT `_class`, META(`" + bucketName()
156+
+ "`).`cas` AS __cas, `createdBy`, `createdDate`, `lastModifiedBy`, `lastModifiedDate`, META(`"
157+
+ bucketName() + "`).`id` AS __id, `firstname`, `lastname`, `subtype` FROM `" + bucketName()
158+
+ "` where `_class` = \"abstractuser\" and (firstname = $first or lastname = $last)",
159+
query.toN1qlSelectString(couchbaseTemplate.reactive(), config().bucketname(), User.class, false));
160+
}
161+
162+
@Test
163+
void spelTests() throws Exception {
164+
String input = "spelTests";
165+
Method method = UserRepository.class.getMethod(input);
166+
CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method,
167+
new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory(),
168+
converter.getMappingContext());
169+
170+
StringN1qlQueryCreator creator = new StringN1qlQueryCreator(getAccessor(getParameters(method)), queryMethod,
171+
converter, config().bucketname(), new SpelExpressionParser(), QueryMethodEvaluationContextProvider.DEFAULT, namedQueries);
172+
173+
Query query = creator.createQuery();
174+
175+
String s = query.toN1qlSelectString(couchbaseTemplate.reactive(), "myCollection", User.class,
176+
false );
177+
System.out.println("query: " + s);
178+
179+
}
180+
117181
private ParameterAccessor getAccessor(Parameters<?, ?> params, Object... values) {
118182
return new ParametersParameterAccessor(params, values);
119183
}

src/test/java/org/springframework/data/couchbase/repository/query/StringN1qlQueryCreatorMockedTests.java

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,57 +55,16 @@
5555
* @author Michael Nitschinger
5656
* @author Michael Reiche
5757
*/
58-
class StringN1qlQueryCreatorMockedTests extends ClusterAwareIntegrationTests {
58+
class StringN1qlQueryCreatorMockedTests {
5959

6060
MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> context;
6161
CouchbaseConverter converter;
62-
CouchbaseTemplate couchbaseTemplate;
6362
static NamedQueries namedQueries = new PropertiesBasedNamedQueries(new Properties());
6463

6564
@BeforeEach
6665
public void beforeEach() {
6766
context = new CouchbaseMappingContext();
6867
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));
10968
}
11069

11170
@Test
@@ -153,29 +112,4 @@ private ParameterAccessor getAccessor(Parameters<?, ?> params, Object... values)
153112
return new DefaultParameters(method);
154113
}
155114

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-
}
181115
}

0 commit comments

Comments
 (0)