Polishing.
Add tests to verify expected behaviour of quoted expressions and string that look like expressions. Remove comments that look like old merge conflict left overs and apply code format. Original Pull Request: #4807
This commit is contained in:
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.util.json;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
@@ -30,7 +31,6 @@ import org.bson.BsonRegularExpression;
|
||||
import org.bson.Document;
|
||||
import org.bson.codecs.DecoderContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.expression.ValueExpressionParser;
|
||||
import org.springframework.data.spel.EvaluationContextProvider;
|
||||
import org.springframework.data.spel.ExpressionDependencies;
|
||||
@@ -104,6 +104,22 @@ class ParameterBindingJsonReaderUnitTests {
|
||||
assertThat(pattern.getOptions()).isEqualTo("i");
|
||||
}
|
||||
|
||||
@Test // GH-4806
|
||||
void treatsQuotedValueThatLooksLikeRegexAsPlainString() {
|
||||
|
||||
Document target = parse("{ 'c': '/^?0$/i' }", "foo");
|
||||
|
||||
assertThat(target.get("c")).isInstanceOf(String.class);
|
||||
}
|
||||
|
||||
@Test // GH-4806
|
||||
void treatsStringParameterValueThatLooksLikeRegexAsPlainString() {
|
||||
|
||||
Document target = parse("{ 'c': ?0 }", "/^foo$/i");
|
||||
|
||||
assertThat(target.get("c")).isInstanceOf(String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindValueToRegex() {
|
||||
|
||||
@@ -147,7 +163,6 @@ class ParameterBindingJsonReaderUnitTests {
|
||||
@Test
|
||||
void bindListValue() {
|
||||
|
||||
//
|
||||
Document target = parse("{ 'lastname' : { $in : ?0 } }", Arrays.asList("Kohlin", "Davar"));
|
||||
assertThat(target).isEqualTo(Document.parse("{ 'lastname' : { $in : ['Kohlin', 'Davar' ]} }"));
|
||||
}
|
||||
@@ -155,7 +170,6 @@ class ParameterBindingJsonReaderUnitTests {
|
||||
@Test
|
||||
void bindListOfBinaryValue() {
|
||||
|
||||
//
|
||||
byte[] value = "Kohlin".getBytes(StandardCharsets.UTF_8);
|
||||
List<byte[]> args = Collections.singletonList(value);
|
||||
|
||||
@@ -170,12 +184,9 @@ class ParameterBindingJsonReaderUnitTests {
|
||||
assertThat(target).isEqualTo(Document.parse("{ \"id\" : { \"$exists\" : true}}"));
|
||||
}
|
||||
|
||||
// {'id':?#{ [0] ? { $exists :true} : [1] }}
|
||||
|
||||
@Test
|
||||
void bindDocumentValue() {
|
||||
|
||||
//
|
||||
Document target = parse("{ 'lastname' : ?0 }", new Document("$eq", "Kohlin"));
|
||||
assertThat(target).isEqualTo(Document.parse("{ 'lastname' : { '$eq' : 'Kohlin' } }"));
|
||||
}
|
||||
@@ -183,7 +194,6 @@ class ParameterBindingJsonReaderUnitTests {
|
||||
@Test
|
||||
void arrayWithoutBinding() {
|
||||
|
||||
//
|
||||
Document target = parse("{ 'lastname' : { $in : [\"Kohlin\", \"Davar\"] } }");
|
||||
assertThat(target).isEqualTo(Document.parse("{ 'lastname' : { $in : ['Kohlin', 'Davar' ]} }"));
|
||||
}
|
||||
@@ -191,7 +201,6 @@ class ParameterBindingJsonReaderUnitTests {
|
||||
@Test
|
||||
void bindSpEL() {
|
||||
|
||||
// "{ arg0 : ?#{[0]} }"
|
||||
Document target = parse("{ arg0 : ?#{[0]} }", 100.01D);
|
||||
assertThat(target).isEqualTo(new Document("arg0", 100.01D));
|
||||
}
|
||||
@@ -331,9 +340,8 @@ class ParameterBindingJsonReaderUnitTests {
|
||||
|
||||
String json = "{ $and : [?#{ [0] == null ? { '$where' : 'true' } : { 'v1' : { '$in' : {[0]} } } }]}";
|
||||
|
||||
ExpressionDependencies expressionDependencies = new ParameterBindingDocumentCodec()
|
||||
.captureExpressionDependencies(json, it -> new Object(),
|
||||
ValueExpressionParser.create(SpelExpressionParser::new));
|
||||
ExpressionDependencies expressionDependencies = new ParameterBindingDocumentCodec().captureExpressionDependencies(
|
||||
json, it -> new Object(), ValueExpressionParser.create(SpelExpressionParser::new));
|
||||
|
||||
assertThat(expressionDependencies).isEqualTo(ExpressionDependencies.none());
|
||||
}
|
||||
@@ -343,9 +351,8 @@ class ParameterBindingJsonReaderUnitTests {
|
||||
|
||||
String json = "{ hello: ?#{hasRole('foo')} }";
|
||||
|
||||
ExpressionDependencies expressionDependencies = new ParameterBindingDocumentCodec()
|
||||
.captureExpressionDependencies(json, it -> new Object(),
|
||||
ValueExpressionParser.create(SpelExpressionParser::new));
|
||||
ExpressionDependencies expressionDependencies = new ParameterBindingDocumentCodec().captureExpressionDependencies(
|
||||
json, it -> new Object(), ValueExpressionParser.create(SpelExpressionParser::new));
|
||||
|
||||
assertThat(expressionDependencies).isNotEmpty();
|
||||
assertThat(expressionDependencies.get()).hasSize(1);
|
||||
|
||||
Reference in New Issue
Block a user