Restore StringQuery constructor that takes only string. (#1770)

Closes #1769.
This commit is contained in:
Michael Reiche
2023-06-29 11:55:48 -07:00
committed by GitHub
parent 0ee1f8a0d3
commit 0ba6423f2b
3 changed files with 116 additions and 13 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.data.couchbase.repository.query;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import java.lang.reflect.Method;
@@ -29,6 +30,7 @@ import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
import org.springframework.data.couchbase.core.query.Query;
import org.springframework.data.couchbase.core.query.StringQuery;
import org.springframework.data.couchbase.domain.User;
import org.springframework.data.couchbase.domain.UserRepository;
import org.springframework.data.mapping.context.MappingContext;
@@ -138,6 +140,59 @@ class StringN1qlQueryCreatorTests {
query.toN1qlSelectString(converter, bucketName(), null, null, User.class, User.class, false, null, null));
}
@Test
void stringQuerycreatesQueryCorrectly() throws Exception {
String queryString = "a b c";
Query query = new StringQuery(queryString);
assertEquals(queryString, query.toN1qlSelectString(converter, bucketName(), null, null, User.class, User.class,
false, null, null));
}
@Test
void stringQueryNoPositionalParameters() {
String queryString = " $1";
Query query = new StringQuery(queryString);
assertThrows(IllegalArgumentException.class, () -> query.toN1qlSelectString(converter, bucketName(), null, null,
User.class, User.class, false, null, null));
}
@Test
void stringQueryNoNamedParameters() {
String queryString = " $george";
Query query = new StringQuery(queryString);
assertThrows(IllegalArgumentException.class, () -> query.toN1qlSelectString(converter, bucketName(), null, null,
User.class, User.class, false, null, null));
}
@Test
void stringQueryNoSpelExpressions() {
String queryString = "#{#n1ql.filter}";
Query query = new StringQuery(queryString);
assertThrows(IllegalArgumentException.class, () -> query.toN1qlSelectString(converter, bucketName(), null, null,
User.class, User.class, false, null, null));
}
@Test
void stringQueryNoPositionalParametersQuotes() {
String queryString = " '$1'";
Query query = new StringQuery(queryString);
query.toN1qlSelectString(converter, bucketName(), null, null, User.class, User.class, false, null, null);
}
@Test
void stringQueryNoNamedParametersQuotes() {
String queryString = " '$george'";
Query query = new StringQuery(queryString);
query.toN1qlSelectString(converter, bucketName(), null, null, User.class, User.class, false, null, null);
}
@Test
void stringQueryNoSpelExpressionsQuotes() {
String queryString = "'#{#n1ql.filter}'";
Query query = new StringQuery(queryString);
query.toN1qlSelectString(converter, bucketName(), null, null, User.class, User.class, false, null, null);
}
@Test
void spelTests() throws Exception {
String input = "spelTests";