From 4491301c578b00bcd866e4274274be167f9038a5 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 26 Aug 2021 12:20:11 +0200 Subject: [PATCH 1/3] Polishing. Add support for Pattern. Extract Regex flags translation from Criteria into RegexFlags utility class. Add since and author tags. Simplify tests. Update reference documentation. See #3725. Original pull request: #3781. --- .../core/aggregation/StringOperators.java | 371 ++++++++++----- .../data/mongodb/core/query/Criteria.java | 58 +-- .../data/mongodb/util/RegexFlags.java | 110 +++++ .../ProjectionOperationUnitTests.java | 433 +++++++++--------- .../SpelExpressionTransformerUnitTests.java | 89 ++-- .../aggregation/StringOperatorsUnitTests.java | 226 +++++---- .../reference/aggregation-framework.adoc | 2 +- 7 files changed, 770 insertions(+), 519 deletions(-) create mode 100644 spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/RegexFlags.java diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/StringOperators.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/StringOperators.java index 710c6c855e..8b6bb03875 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/StringOperators.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/StringOperators.java @@ -18,8 +18,11 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; import org.springframework.data.domain.Range; +import org.springframework.data.mongodb.util.RegexFlags; import org.springframework.util.Assert; /** @@ -27,6 +30,7 @@ * * @author Christoph Strobl * @author Mark Paluch + * @author Divya Srivastava * @since 1.10 */ public class StringOperators { @@ -515,117 +519,170 @@ public RTrim rtrim(AggregationExpression expression) { private RTrim createRTrim() { return usesFieldRef() ? RTrim.valueOf(fieldReference) : RTrim.valueOf(expression); } - + /** - * Creates new {@link AggregationExpression} that takes the associated string representation and applies the given + * Creates new {@link AggregationExpression} that takes the associated string representation and applies the given * regular expression to find the document with the first match.
* NOTE: Requires MongoDB 4.0 or later. * + * @param regex must not be {@literal null}. * @return new instance of {@link RegexFind}. + * @since 3.3 */ public RegexFind regexFind(String regex) { return createRegexFind().regex(regex); } - + /** - * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular - * expression resulting from the given {@link AggregationExpression} to find the document with the first match.
+ * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular + * expression resulting from the given {@link AggregationExpression} to find the document with the first + * match.
* NOTE: Requires MongoDB 4.0 or later. * + * @param expression must not be {@literal null}. * @return new instance of {@link RegexFind}. + * @since 3.3 */ public RegexFind regexFind(AggregationExpression expression) { return createRegexFind().regexOf(expression); } - + + /** + * Creates new {@link AggregationExpression} that takes the {@link Pattern} and applies the regular expression with + * the options specified in the argument to find the document with the first match. + * + * @param pattern the pattern object to apply. + * @return new instance of {@link RegexFind}. + * @since 3.3 + */ + public RegexFind regexFind(Pattern pattern) { + return createRegexFind().pattern(pattern); + } + /** - * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular + * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular * expression with the options specified in the argument to find the document with the first match. * - * @param regex the regular expression to apply - * @param options the options to use + * @param regex the regular expression to apply. + * @param options the options to use. * @return new instance of {@link RegexFind}. + * @since 3.3 */ - public RegexFind regexFind(String regex,String options) { + public RegexFind regexFind(String regex, String options) { return createRegexFind().regex(regex).options(options); } - + private RegexFind createRegexFind() { return usesFieldRef() ? RegexFind.valueOf(fieldReference) : RegexFind.valueOf(expression); } - + /** - * Creates new {@link AggregationExpression} that takes the associated string representation and applies the given + * Creates new {@link AggregationExpression} that takes the associated string representation and applies the given * regular expression to find all the documents with the match.
* NOTE: Requires MongoDB 4.0 or later. * + * @param regex must not be {@literal null}. * @return new instance of {@link RegexFindAll}. + * @since 3.3 */ public RegexFindAll regexFindAll(String regex) { return createRegexFindAll().regex(regex); } - + /** - * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular - * expression resulting from the given {@link AggregationExpression} to find all the documents with the match..
+ * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular + * expression resulting from the given {@link AggregationExpression} to find all the documents with the + * match..
* NOTE: Requires MongoDB 4.0 or later. * + * @param expression must not be {@literal null}. * @return new instance of {@link RegexFindAll}. + * @since 3.3 */ public RegexFindAll regexFindAll(AggregationExpression expression) { return createRegexFindAll().regexOf(expression); } - + /** - * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular - * expression with the options specified in the argument to find all the documents with the match.. + * Creates new {@link AggregationExpression} that takes a {@link Pattern} and applies the regular expression with + * the options specified in the argument to find all the documents with the match. * - * @param regex the regular expression to apply - * @param options the options to use + * @param pattern the pattern object to apply. * @return new instance of {@link RegexFindAll}. + * @since 3.3 */ - public RegexFindAll regexFindAll(String regex,String options) { + public RegexFindAll regexFindAll(Pattern pattern) { + return createRegexFindAll().pattern(pattern); + } + + /** + * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular + * expression with the options specified in the argument to find all the documents with the match. + * + * @param regex the regular expression to apply. + * @param options the options to use. + * @return new instance of {@link RegexFindAll}. + * @since 3.3 + */ + public RegexFindAll regexFindAll(String regex, String options) { return createRegexFindAll().regex(regex).options(options); } - + private RegexFindAll createRegexFindAll() { return usesFieldRef() ? RegexFindAll.valueOf(fieldReference) : RegexFindAll.valueOf(expression); } - + /** - * Creates new {@link AggregationExpression} that takes the associated string representation and applies the given + * Creates new {@link AggregationExpression} that takes the associated string representation and applies the given * regular expression to find if a match is found or not.
* NOTE: Requires MongoDB 4.0 or later. * + * @param regex must not be {@literal null}. * @return new instance of {@link RegexMatch}. + * @since 3.3 */ public RegexMatch regexMatch(String regex) { return createRegexMatch().regex(regex); } - + /** - * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular + * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular * expression resulting from the given {@link AggregationExpression} to find if a match is found or not.
* NOTE: Requires MongoDB 4.0 or later. * + * @param expression must not be {@literal null}. * @return new instance of {@link RegexMatch}. + * @since 3.3 */ public RegexMatch regexMatch(AggregationExpression expression) { return createRegexMatch().regexOf(expression); } - + + /** + * Creates new {@link AggregationExpression} that takes a {@link Pattern} and applies the regular expression with + * the options specified in the argument to find if a match is found or not. + * + * @param pattern the pattern object to apply. + * @return new instance of {@link RegexMatch}. + * @since 3.3 + */ + public RegexMatch regexMatch(Pattern pattern) { + return createRegexMatch().pattern(pattern); + } + /** - * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular + * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular * expression with the options specified in the argument to find if a match is found or not. * - * @param regex the regular expression to apply - * @param options the options to use + * @param regex the regular expression to apply. + * @param options the options to use. * @return new instance of {@link RegexMatch}. + * @since 3.3 */ - public RegexMatch regexMatch(String regex,String options) { + public RegexMatch regexMatch(String regex, String options) { return createRegexMatch().regex(regex).options(options); } - + private RegexMatch createRegexMatch() { return usesFieldRef() ? RegexMatch.valueOf(fieldReference) : RegexMatch.valueOf(expression); } @@ -1591,35 +1648,35 @@ protected String getMongoMethod() { return "$rtrim"; } } - + /** - * {@link AggregationExpression} for {@code $regexFind} which applies a regular expression (regex) to a string and + * {@link AggregationExpression} for {@code $regexFind} which applies a regular expression (regex) to a string and * returns information on the first matched substring.
* NOTE: Requires MongoDB 4.0 or later. * + * @author Divya Srivastava + * @since 3.3 */ public static class RegexFind extends AbstractAggregationExpression { - + protected RegexFind(Object value) { super(value); } - @Override - protected String getMongoMethod() { - return "$regexFind"; - } - /** - * Creates new {@link RegexFind} using the value of the provided {@link Field fieldReference} as {@literal input} value. + * Creates new {@link RegexFind} using the value of the provided {@link Field fieldReference} as {@literal input} + * value. * * @param fieldReference must not be {@literal null}. * @return new instance of {@link RegexFind}. */ public static RegexFind valueOf(String fieldReference) { + Assert.notNull(fieldReference, "FieldReference must not be null!"); + return new RegexFind(Collections.singletonMap("input", Fields.field(fieldReference))); } - + /** * Creates new {@link RegexFind} using the result of the provided {@link AggregationExpression} as {@literal input} * value. @@ -1628,10 +1685,12 @@ public static RegexFind valueOf(String fieldReference) { * @return new instance of {@link RegexFind}. */ public static RegexFind valueOf(AggregationExpression expression) { + Assert.notNull(expression, "Expression must not be null!"); + return new RegexFind(Collections.singletonMap("input", expression)); } - + /** * Optional specify the options to use with the regular expression. * @@ -1639,72 +1698,108 @@ public static RegexFind valueOf(AggregationExpression expression) { * @return new instance of {@link RegexFind}. */ public RegexFind options(String options) { + Assert.notNull(options, "Options must not be null!"); + return new RegexFind(append("options", options)); } - + /** - * Optional specify the reference to the {@link Field field} holding the options values to use with the regular expression. + * Optional specify the reference to the {@link Field field} holding the options values to use with the regular + * expression. * * @param fieldReference must not be {@literal null}. * @return new instance of {@link RegexFind}. */ public RegexFind optionsOf(String fieldReference) { + Assert.notNull(fieldReference, "FieldReference must not be null!"); + return new RegexFind(append("options", Fields.field(fieldReference))); } - + /** - * Optional specify the {@link AggregationExpression} evaluating to the options values to use with the regular expression. + * Optional specify the {@link AggregationExpression} evaluating to the options values to use with the regular + * expression. * * @param expression must not be {@literal null}. * @return new instance of {@link RegexFind}. */ public RegexFind optionsOf(AggregationExpression expression) { + Assert.notNull(expression, "Expression must not be null!"); + return new RegexFind(append("options", expression)); } - + /** - * Optional specify the regular expression to apply. + * Specify the regular expression to apply. * * @param regex must not be {@literal null}. * @return new instance of {@link RegexFind}. */ public RegexFind regex(String regex) { + Assert.notNull(regex, "Regex must not be null!"); - return new RegexFind(append("regex",regex)); + + return new RegexFind(append("regex", regex)); } - + /** - * Optional specify the reference to the {@link Field field} holding the regular expression to apply. + * Apply a {@link Pattern} into {@code regex} and {@code options} fields. + * + * @param pattern must not be {@literal null}. + * @return new instance of {@link RegexFind}. + */ + public RegexFind pattern(Pattern pattern) { + + Assert.notNull(pattern, "Pattern must not be null!"); + + Map regex = append("regex", pattern.pattern()); + regex.put("options", RegexFlags.toRegexOptions(pattern.flags())); + + return new RegexFind(regex); + } + + /** + * Specify the reference to the {@link Field field} holding the regular expression to apply. * * @param fieldReference must not be {@literal null}. * @return new instance of {@link RegexFind}. */ public RegexFind regexOf(String fieldReference) { + Assert.notNull(fieldReference, "fieldReference must not be null!"); - return new RegexFind(append("regex",Fields.field(fieldReference))); + + return new RegexFind(append("regex", Fields.field(fieldReference))); } - + /** - * Optional specify the {@link AggregationExpression} evaluating to the regular expression to apply. + * Specify the {@link AggregationExpression} evaluating to the regular expression to apply. * * @param expression must not be {@literal null}. * @return new instance of {@link RegexFind}. */ public RegexFind regexOf(AggregationExpression expression) { + Assert.notNull(expression, "Expression must not be null!"); - return new RegexFind(append("regex",expression)); + + return new RegexFind(append("regex", expression)); } + @Override + protected String getMongoMethod() { + return "$regexFind"; + } } - + /** - * {@link AggregationExpression} for {@code $regexFindAll} which applies a regular expression (regex) to a string and + * {@link AggregationExpression} for {@code $regexFindAll} which applies a regular expression (regex) to a string and * returns information on all the matched substrings.
* NOTE: Requires MongoDB 4.0 or later. * + * @author Divya Srivastava + * @since 3.3 */ public static class RegexFindAll extends AbstractAggregationExpression { @@ -1712,13 +1807,9 @@ protected RegexFindAll(Object value) { super(value); } - @Override - protected String getMongoMethod() { - return "$regexFindAll"; - } - /** - * Creates new {@link RegexFindAll} using the value of the provided {@link Field fieldReference} as {@literal input} value. + * Creates new {@link RegexFindAll} using the value of the provided {@link Field fieldReference} as {@literal input} + * value. * * @param fieldReference must not be {@literal null}. * @return new instance of {@link RegexFindAll}. @@ -1727,19 +1818,21 @@ public static RegexFindAll valueOf(String fieldReference) { Assert.notNull(fieldReference, "FieldReference must not be null!"); return new RegexFindAll(Collections.singletonMap("input", Fields.field(fieldReference))); } - + /** - * Creates new {@link RegexFindAll} using the result of the provided {@link AggregationExpression} as {@literal input} - * value. + * Creates new {@link RegexFindAll} using the result of the provided {@link AggregationExpression} as + * {@literal input} value. * * @param expression must not be {@literal null}. * @return new instance of {@link RegexFindAll}. */ public static RegexFindAll valueOf(AggregationExpression expression) { + Assert.notNull(expression, "Expression must not be null!"); + return new RegexFindAll(Collections.singletonMap("input", expression)); } - + /** * Optional specify the options to use with the regular expression. * @@ -1747,72 +1840,108 @@ public static RegexFindAll valueOf(AggregationExpression expression) { * @return new instance of {@link RegexFindAll}. */ public RegexFindAll options(String options) { + Assert.notNull(options, "Options must not be null!"); + return new RegexFindAll(append("options", options)); } - + /** - * Optional specify the reference to the {@link Field field} holding the options values to use with the regular expression. + * Optional specify the reference to the {@link Field field} holding the options values to use with the regular + * expression. * * @param fieldReference must not be {@literal null}. * @return new instance of {@link RegexFindAll}. */ public RegexFindAll optionsOf(String fieldReference) { + Assert.notNull(fieldReference, "fieldReference must not be null!"); + return new RegexFindAll(append("options", Fields.field(fieldReference))); } - + /** - * Optional specify the {@link AggregationExpression} evaluating to the options values to use with the regular expression. + * Optional specify the {@link AggregationExpression} evaluating to the options values to use with the regular + * expression. * * @param expression must not be {@literal null}. * @return new instance of {@link RegexFindAll}. */ public RegexFindAll optionsOf(AggregationExpression expression) { + Assert.notNull(expression, "Expression must not be null!"); + return new RegexFindAll(append("options", expression)); } - + /** - * Optional specify the regular expression to apply. + * Apply a {@link Pattern} into {@code regex} and {@code options} fields. + * + * @param pattern must not be {@literal null}. + * @return new instance of {@link RegexFindAll}. + */ + public RegexFindAll pattern(Pattern pattern) { + + Assert.notNull(pattern, "Pattern must not be null!"); + + Map regex = append("regex", pattern.pattern()); + regex.put("options", RegexFlags.toRegexOptions(pattern.flags())); + + return new RegexFindAll(regex); + } + + /** + * Specify the regular expression to apply. * * @param regex must not be {@literal null}. * @return new instance of {@link RegexFindAll}. */ public RegexFindAll regex(String regex) { + Assert.notNull(regex, "Regex must not be null!"); - return new RegexFindAll(append("regex",regex)); + + return new RegexFindAll(append("regex", regex)); } - + /** - * Optional specify the reference to the {@link Field field} holding the regular expression to apply. + * Specify the reference to the {@link Field field} holding the regular expression to apply. * * @param fieldReference must not be {@literal null}. * @return new instance of {@link RegexFindAll}. */ public RegexFindAll regexOf(String fieldReference) { + Assert.notNull(fieldReference, "fieldReference must not be null!"); - return new RegexFindAll(append("regex",Fields.field(fieldReference))); + + return new RegexFindAll(append("regex", Fields.field(fieldReference))); } - + /** - * Optional specify the {@link AggregationExpression} evaluating to the regular expression to apply. + * Specify the {@link AggregationExpression} evaluating to the regular expression to apply. * * @param expression must not be {@literal null}. * @return new instance of {@link RegexFindAll}. */ public RegexFindAll regexOf(AggregationExpression expression) { + Assert.notNull(expression, "Expression must not be null!"); - return new RegexFindAll(append("regex",expression)); + + return new RegexFindAll(append("regex", expression)); } + @Override + protected String getMongoMethod() { + return "$regexFindAll"; + } } - + /** - * {@link AggregationExpression} for {@code $regexMatch} which applies a regular expression (regex) to a string and + * {@link AggregationExpression} for {@code $regexMatch} which applies a regular expression (regex) to a string and * returns a boolean that indicates if a match is found or not.
* NOTE: Requires MongoDB 4.0 or later. * + * @author Divya Srivastava + * @since 3.3 */ public static class RegexMatch extends AbstractAggregationExpression { @@ -1820,22 +1949,20 @@ protected RegexMatch(Object value) { super(value); } - @Override - protected String getMongoMethod() { - return "$regexMatch"; - } - /** - * Creates new {@link RegexMatch} using the value of the provided {@link Field fieldReference} as {@literal input} value. + * Creates new {@link RegexMatch} using the value of the provided {@link Field fieldReference} as {@literal input} + * value. * * @param fieldReference must not be {@literal null}. * @return new instance of {@link RegexMatch}. */ public static RegexMatch valueOf(String fieldReference) { + Assert.notNull(fieldReference, "FieldReference must not be null!"); + return new RegexMatch(Collections.singletonMap("input", Fields.field(fieldReference))); } - + /** * Creates new {@link RegexMatch} using the result of the provided {@link AggregationExpression} as {@literal input} * value. @@ -1844,10 +1971,12 @@ public static RegexMatch valueOf(String fieldReference) { * @return new instance of {@link RegexMatch}. */ public static RegexMatch valueOf(AggregationExpression expression) { + Assert.notNull(expression, "Expression must not be null!"); + return new RegexMatch(Collections.singletonMap("input", expression)); } - + /** * Optional specify the options to use with the regular expression. * @@ -1855,54 +1984,82 @@ public static RegexMatch valueOf(AggregationExpression expression) { * @return new instance of {@link RegexMatch}. */ public RegexMatch options(String options) { + Assert.notNull(options, "Options must not be null!"); + return new RegexMatch(append("options", options)); } - + /** - * Optional specify the reference to the {@link Field field} holding the options values to use with the regular expression. + * Optional specify the reference to the {@link Field field} holding the options values to use with the regular + * expression. * * @param fieldReference must not be {@literal null}. * @return new instance of {@link RegexMatch}. */ public RegexMatch optionsOf(String fieldReference) { + Assert.notNull(fieldReference, "FieldReference must not be null!"); + return new RegexMatch(append("options", Fields.field(fieldReference))); } - + /** - * Optional specify the {@link AggregationExpression} evaluating to the options values to use with the regular expression. + * Optional specify the {@link AggregationExpression} evaluating to the options values to use with the regular + * expression. * * @param expression must not be {@literal null}. * @return new instance of {@link RegexMatch}. */ public RegexMatch optionsOf(AggregationExpression expression) { + Assert.notNull(expression, "Expression must not be null!"); + return new RegexMatch(append("options", expression)); } - + /** - * Optional specify the regular expression to apply. + * Apply a {@link Pattern} into {@code regex} and {@code options} fields. + * + * @param pattern must not be {@literal null}. + * @return new instance of {@link RegexMatch}. + */ + public RegexMatch pattern(Pattern pattern) { + + Assert.notNull(pattern, "Pattern must not be null!"); + + Map regex = append("regex", pattern.pattern()); + regex.put("options", RegexFlags.toRegexOptions(pattern.flags())); + + return new RegexMatch(regex); + } + + /** + * Specify the regular expression to apply. * * @param regex must not be {@literal null}. * @return new instance of {@link RegexMatch}. */ public RegexMatch regex(String regex) { + Assert.notNull(regex, "Regex must not be null!"); - return new RegexMatch(append("regex",regex)); + + return new RegexMatch(append("regex", regex)); } - + /** - * Optional specify the reference to the {@link Field field} holding the regular expression to apply. + * Specify the reference to the {@link Field field} holding the regular expression to apply. * * @param fieldReference must not be {@literal null}. * @return new instance of {@link RegexMatch}. */ public RegexMatch regexOf(String fieldReference) { + Assert.notNull(fieldReference, "FieldReference must not be null!"); - return new RegexMatch(append("regex",Fields.field(fieldReference))); + + return new RegexMatch(append("regex", Fields.field(fieldReference))); } - + /** * Optional specify the {@link AggregationExpression} evaluating to the regular expression to apply. * @@ -1910,9 +2067,15 @@ public RegexMatch regexOf(String fieldReference) { * @return new instance of {@link RegexMatch}. */ public RegexMatch regexOf(AggregationExpression expression) { + Assert.notNull(expression, "Expression must not be null!"); - return new RegexMatch(append("regex",expression)); + + return new RegexMatch(append("regex", expression)); } + @Override + protected String getMongoMethod() { + return "$regexMatch"; + } } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java index 9b1e8df940..f9a354c38f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java @@ -42,6 +42,7 @@ import org.springframework.data.mongodb.core.schema.JsonSchemaObject.Type; import org.springframework.data.mongodb.core.schema.JsonSchemaProperty; import org.springframework.data.mongodb.core.schema.MongoJsonSchema; +import org.springframework.data.mongodb.util.RegexFlags; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.Base64Utils; @@ -71,20 +72,6 @@ public class Criteria implements CriteriaDefinition { */ private static final Object NOT_SET = new Object(); - private static final int[] FLAG_LOOKUP = new int[Character.MAX_VALUE]; - - static { - FLAG_LOOKUP['g'] = 256; - FLAG_LOOKUP['i'] = Pattern.CASE_INSENSITIVE; - FLAG_LOOKUP['m'] = Pattern.MULTILINE; - FLAG_LOOKUP['s'] = Pattern.DOTALL; - FLAG_LOOKUP['c'] = Pattern.CANON_EQ; - FLAG_LOOKUP['x'] = Pattern.COMMENTS; - FLAG_LOOKUP['d'] = Pattern.UNIX_LINES; - FLAG_LOOKUP['t'] = Pattern.LITERAL; - FLAG_LOOKUP['u'] = Pattern.UNICODE_CASE; - } - private @Nullable String key; private List criteriaChain; private LinkedHashMap criteria = new LinkedHashMap(); @@ -530,7 +517,7 @@ private Pattern toPattern(String regex, @Nullable String options) { Assert.notNull(regex, "Regex string must not be null!"); - return Pattern.compile(regex, regexFlags(options)); + return Pattern.compile(regex, RegexFlags.toRegexFlags(options)); } /** @@ -1099,47 +1086,6 @@ private static boolean requiresGeoJsonFormat(Object value) { || (value instanceof GeoCommand && ((GeoCommand) value).getShape() instanceof GeoJson); } - /** - * Lookup the MongoDB specific flags for a given regex option string. - * - * @param s the Regex option/flag to look up. Can be {@literal null}. - * @return zero if given {@link String} is {@literal null} or empty. - * @since 2.2 - */ - private static int regexFlags(@Nullable String s) { - - int flags = 0; - - if (s == null) { - return flags; - } - - for (final char f : s.toLowerCase().toCharArray()) { - flags |= regexFlag(f); - } - - return flags; - } - - /** - * Lookup the MongoDB specific flags for a given character. - * - * @param c the Regex option/flag to look up. - * @return - * @throws IllegalArgumentException for unknown flags - * @since 2.2 - */ - private static int regexFlag(char c) { - - int flag = FLAG_LOOKUP[c]; - - if (flag == 0) { - throw new IllegalArgumentException(String.format("Unrecognized flag [%c]", c)); - } - - return flag; - } - /** * MongoDB specific bitwise query * operators like {@code $bitsAllClear, $bitsAllSet,...} for usage with {@link Criteria#bits()} and {@link Query}. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/RegexFlags.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/RegexFlags.java new file mode 100644 index 0000000000..beaa4f2f8b --- /dev/null +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/RegexFlags.java @@ -0,0 +1,110 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.mongodb.util; + +import java.util.regex.Pattern; + +/** + * Utility to translate {@link Pattern#flags() regex flags} to MongoDB regex options and vice versa. + * + * @author Mark Paluch + * @since 3.3 + */ +public abstract class RegexFlags { + + private static final int[] FLAG_LOOKUP = new int[Character.MAX_VALUE]; + + static { + FLAG_LOOKUP['g'] = 256; + FLAG_LOOKUP['i'] = Pattern.CASE_INSENSITIVE; + FLAG_LOOKUP['m'] = Pattern.MULTILINE; + FLAG_LOOKUP['s'] = Pattern.DOTALL; + FLAG_LOOKUP['c'] = Pattern.CANON_EQ; + FLAG_LOOKUP['x'] = Pattern.COMMENTS; + FLAG_LOOKUP['d'] = Pattern.UNIX_LINES; + FLAG_LOOKUP['t'] = Pattern.LITERAL; + FLAG_LOOKUP['u'] = Pattern.UNICODE_CASE; + } + + private RegexFlags() { + + } + + /** + * Lookup the MongoDB specific options from given {@link Pattern#flags() flags}. + * + * @param flags the Regex flags to look up. + * @return the options string. May be empty. + */ + public static String toRegexOptions(int flags) { + + if (flags == 0) { + return ""; + } + + StringBuilder buf = new StringBuilder(); + + for (int i = 'a'; i < 'z'; i++) { + + if (FLAG_LOOKUP[i] == 0) { + continue; + } + + if ((flags & FLAG_LOOKUP[i]) > 0) { + buf.append((char) i); + } + } + + return buf.toString(); + } + + /** + * Lookup the MongoDB specific flags for a given regex option string. + * + * @param s the Regex option/flag to look up. Can be {@literal null}. + * @return zero if given {@link String} is {@literal null} or empty. + * @since 2.2 + */ + public static int toRegexFlags(String s) { + + int flags = 0; + + for (char f : s.toLowerCase().toCharArray()) { + flags |= toRegexFlag(f); + } + + return flags; + } + + /** + * Lookup the MongoDB specific flags for a given character. + * + * @param c the Regex option/flag to look up. + * @return + * @throws IllegalArgumentException for unknown flags + * @since 2.2 + */ + public static int toRegexFlag(char c) { + + int flag = FLAG_LOOKUP[c]; + + if (flag == 0) { + throw new IllegalArgumentException(String.format("Unrecognized flag [%c]", c)); + } + + return flag; + } +} diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java index ff6771d9f1..9ef207c9ad 100755 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java @@ -55,24 +55,25 @@ * @author Oliver Gierke * @author Thomas Darimont * @author Christoph Strobl + * @author Divya Srivastava * @author Mark Paluch */ public class ProjectionOperationUnitTests { - static final String MOD = "$mod"; - static final String ADD = "$add"; - static final String SUBTRACT = "$subtract"; - static final String MULTIPLY = "$multiply"; - static final String DIVIDE = "$divide"; - static final String PROJECT = "$project"; + private static final String MOD = "$mod"; + private static final String ADD = "$add"; + private static final String SUBTRACT = "$subtract"; + private static final String MULTIPLY = "$multiply"; + private static final String DIVIDE = "$divide"; + private static final String PROJECT = "$project"; @Test // DATAMONGO-586 - public void rejectsNullFields() { + void rejectsNullFields() { assertThatIllegalArgumentException().isThrownBy(() -> new ProjectionOperation((Fields) null)); } @Test // DATAMONGO-586 - public void declaresBackReferenceCorrectly() { + void declaresBackReferenceCorrectly() { ProjectionOperation operation = new ProjectionOperation(); operation = operation.and("prop").previousOperation(); @@ -83,7 +84,7 @@ public void declaresBackReferenceCorrectly() { } @Test // DATAMONGO-586 - public void alwaysUsesExplicitReference() { + void alwaysUsesExplicitReference() { ProjectionOperation operation = new ProjectionOperation(Fields.fields("foo").and("bar", "foobar")); @@ -95,7 +96,7 @@ public void alwaysUsesExplicitReference() { } @Test // DATAMONGO-586 - public void aliasesSimpleFieldProjection() { + void aliasesSimpleFieldProjection() { ProjectionOperation operation = new ProjectionOperation(); @@ -106,7 +107,7 @@ public void aliasesSimpleFieldProjection() { } @Test // DATAMONGO-586 - public void aliasesArithmeticProjection() { + void aliasesArithmeticProjection() { ProjectionOperation operation = new ProjectionOperation(); @@ -121,7 +122,7 @@ public void aliasesArithmeticProjection() { } @Test // DATAMONGO-586 - public void arithmeticProjectionOperationWithoutAlias() { + void arithmeticProjectionOperationWithoutAlias() { String fieldName = "a"; ProjectionOperationBuilder operation = new ProjectionOperation().and(fieldName).plus(1); @@ -134,7 +135,7 @@ public void arithmeticProjectionOperationWithoutAlias() { } @Test // DATAMONGO-586 - public void arithmeticProjectionOperationPlus() { + void arithmeticProjectionOperationPlus() { String fieldName = "a"; String fieldAlias = "b"; @@ -148,7 +149,7 @@ public void arithmeticProjectionOperationPlus() { } @Test // DATAMONGO-586 - public void arithmeticProjectionOperationMinus() { + void arithmeticProjectionOperationMinus() { String fieldName = "a"; String fieldAlias = "b"; @@ -162,7 +163,7 @@ public void arithmeticProjectionOperationMinus() { } @Test // DATAMONGO-586 - public void arithmeticProjectionOperationMultiply() { + void arithmeticProjectionOperationMultiply() { String fieldName = "a"; String fieldAlias = "b"; @@ -176,7 +177,7 @@ public void arithmeticProjectionOperationMultiply() { } @Test // DATAMONGO-586 - public void arithmeticProjectionOperationDivide() { + void arithmeticProjectionOperationDivide() { String fieldName = "a"; String fieldAlias = "b"; @@ -190,12 +191,12 @@ public void arithmeticProjectionOperationDivide() { } @Test // DATAMONGO-586 - public void arithmeticProjectionOperationDivideByZeroException() { + void arithmeticProjectionOperationDivideByZeroException() { assertThatIllegalArgumentException().isThrownBy(() -> new ProjectionOperation().and("a").divide(0)); } @Test // DATAMONGO-586 - public void arithmeticProjectionOperationMod() { + void arithmeticProjectionOperationMod() { String fieldName = "a"; String fieldAlias = "b"; @@ -209,7 +210,7 @@ public void arithmeticProjectionOperationMod() { } @Test // DATAMONGO-758, DATAMONGO-1893 - public void excludeShouldAllowExclusionOfFieldsOtherThanUnderscoreId/* since MongoDB 3.4 */() { + void excludeShouldAllowExclusionOfFieldsOtherThanUnderscoreId/* since MongoDB 3.4 */() { ProjectionOperation projectionOp = new ProjectionOperation().andExclude("foo"); Document document = projectionOp.toDocument(Aggregation.DEFAULT_CONTEXT); @@ -220,7 +221,7 @@ public void arithmeticProjectionOperationMod() { } @Test // DATAMONGO-1893 - public void includeShouldNotInheritFields() { + void includeShouldNotInheritFields() { ProjectionOperation projectionOp = new ProjectionOperation().andInclude("foo"); @@ -228,7 +229,7 @@ public void includeShouldNotInheritFields() { } @Test // DATAMONGO-758 - public void excludeShouldAllowExclusionOfUnderscoreId() { + void excludeShouldAllowExclusionOfUnderscoreId() { ProjectionOperation projectionOp = new ProjectionOperation().andExclude(Fields.UNDERSCORE_ID); Document document = projectionOp.toDocument(Aggregation.DEFAULT_CONTEXT); @@ -237,7 +238,7 @@ public void excludeShouldAllowExclusionOfUnderscoreId() { } @Test // DATAMONGO-1906 - public void rendersConditionalProjectionCorrectly() { + void rendersConditionalProjectionCorrectly() { TypedAggregation aggregation = Aggregation.newAggregation(Book.class, Aggregation.project("title") @@ -252,7 +253,7 @@ public void rendersConditionalProjectionCorrectly() { } @Test // DATAMONGO-757 - public void usesImplictAndExplicitFieldAliasAndIncludeExclude() { + void usesImplictAndExplicitFieldAliasAndIncludeExclude() { ProjectionOperation operation = Aggregation.project("foo").and("foobar").as("bar").andInclude("inc1", "inc2") .andExclude("_id"); @@ -268,12 +269,12 @@ public void usesImplictAndExplicitFieldAliasAndIncludeExclude() { } @Test - public void arithmeticProjectionOperationModByZeroException() { + void arithmeticProjectionOperationModByZeroException() { assertThatIllegalArgumentException().isThrownBy(() -> new ProjectionOperation().and("a").mod(0)); } @Test // DATAMONGO-769 - public void allowArithmeticOperationsWithFieldReferences() { + void allowArithmeticOperationsWithFieldReferences() { ProjectionOperation operation = Aggregation.project() // .and("foo").plus("bar").as("fooPlusBar") // @@ -298,7 +299,7 @@ public void allowArithmeticOperationsWithFieldReferences() { } @Test // DATAMONGO-774 - public void projectionExpressions() { + void projectionExpressions() { ProjectionOperation operation = Aggregation.project() // .andExpression("(netPrice + surCharge) * taxrate * [0]", 2).as("grossSalesPrice") // @@ -310,7 +311,7 @@ public void projectionExpressions() { } @Test // DATAMONGO-975 - public void shouldRenderDateTimeFragmentExtractionsForSimpleFieldProjectionsCorrectly() { + void shouldRenderDateTimeFragmentExtractionsForSimpleFieldProjectionsCorrectly() { ProjectionOperation operation = Aggregation.project() // .and("date").extractHour().as("hour") // @@ -343,7 +344,7 @@ public void shouldRenderDateTimeFragmentExtractionsForSimpleFieldProjectionsCorr } @Test // DATAMONGO-975 - public void shouldRenderDateTimeFragmentExtractionsForExpressionProjectionsCorrectly() throws Exception { + void shouldRenderDateTimeFragmentExtractionsForExpressionProjectionsCorrectly() throws Exception { ProjectionOperation operation = Aggregation.project() // .andExpression("date + 86400000") // @@ -360,7 +361,7 @@ public void shouldRenderDateTimeFragmentExtractionsForExpressionProjectionsCorre } @Test // DATAMONGO-979 - public void shouldRenderSizeExpressionInProjection() { + void shouldRenderSizeExpressionInProjection() { ProjectionOperation operation = Aggregation // .project() // @@ -375,7 +376,7 @@ public void shouldRenderSizeExpressionInProjection() { } @Test // DATAMONGO-979 - public void shouldRenderGenericSizeExpressionInProjection() { + void shouldRenderGenericSizeExpressionInProjection() { ProjectionOperation operation = Aggregation // .project() // @@ -389,7 +390,7 @@ public void shouldRenderGenericSizeExpressionInProjection() { } @Test // DATAMONGO-1457 - public void shouldRenderSliceCorrectly() throws Exception { + void shouldRenderSliceCorrectly() throws Exception { ProjectionOperation operation = Aggregation.project().and("field").slice(10).as("renamed"); @@ -400,7 +401,7 @@ public void shouldRenderSliceCorrectly() throws Exception { } @Test // DATAMONGO-1457 - public void shouldRenderSliceWithPositionCorrectly() throws Exception { + void shouldRenderSliceWithPositionCorrectly() throws Exception { ProjectionOperation operation = Aggregation.project().and("field").slice(10, 5).as("renamed"); @@ -411,7 +412,7 @@ public void shouldRenderSliceWithPositionCorrectly() throws Exception { } @Test // DATAMONGO-784 - public void shouldRenderCmpCorrectly() { + void shouldRenderCmpCorrectly() { ProjectionOperation operation = Aggregation.project().and("field").cmp(10).as("cmp10"); @@ -420,7 +421,7 @@ public void shouldRenderCmpCorrectly() { } @Test // DATAMONGO-784 - public void shouldRenderEqCorrectly() { + void shouldRenderEqCorrectly() { ProjectionOperation operation = Aggregation.project().and("field").eq(10).as("eq10"); @@ -429,7 +430,7 @@ public void shouldRenderEqCorrectly() { } @Test // DATAMONGO-784 - public void shouldRenderGtCorrectly() { + void shouldRenderGtCorrectly() { ProjectionOperation operation = Aggregation.project().and("field").gt(10).as("gt10"); @@ -438,7 +439,7 @@ public void shouldRenderGtCorrectly() { } @Test // DATAMONGO-784 - public void shouldRenderGteCorrectly() { + void shouldRenderGteCorrectly() { ProjectionOperation operation = Aggregation.project().and("field").gte(10).as("gte10"); @@ -447,7 +448,7 @@ public void shouldRenderGteCorrectly() { } @Test // DATAMONGO-784 - public void shouldRenderLtCorrectly() { + void shouldRenderLtCorrectly() { ProjectionOperation operation = Aggregation.project().and("field").lt(10).as("lt10"); @@ -456,7 +457,7 @@ public void shouldRenderLtCorrectly() { } @Test // DATAMONGO-784 - public void shouldRenderLteCorrectly() { + void shouldRenderLteCorrectly() { ProjectionOperation operation = Aggregation.project().and("field").lte(10).as("lte10"); @@ -465,7 +466,7 @@ public void shouldRenderLteCorrectly() { } @Test // DATAMONGO-784 - public void shouldRenderNeCorrectly() { + void shouldRenderNeCorrectly() { ProjectionOperation operation = Aggregation.project().and("field").ne(10).as("ne10"); @@ -474,7 +475,7 @@ public void shouldRenderNeCorrectly() { } @Test // DATAMONGO-1536 - public void shouldRenderSetEquals() { + void shouldRenderSetEquals() { Document agg = project("A", "B").and("A").equalsArrays("B").as("sameElements") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -484,7 +485,7 @@ public void shouldRenderSetEquals() { } @Test // DATAMONGO-1536 - public void shouldRenderSetEqualsAggregationExpresssion() { + void shouldRenderSetEqualsAggregationExpresssion() { Document agg = project("A", "B").and(SetOperators.arrayAsSet("A").isEqualTo("B")).as("sameElements") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -494,7 +495,7 @@ public void shouldRenderSetEqualsAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderSetIntersection() { + void shouldRenderSetIntersection() { Document agg = project("A", "B").and("A").intersectsArrays("B").as("commonToBoth") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -504,7 +505,7 @@ public void shouldRenderSetIntersection() { } @Test // DATAMONGO-1536 - public void shouldRenderSetIntersectionAggregationExpresssion() { + void shouldRenderSetIntersectionAggregationExpresssion() { Document agg = project("A", "B").and(SetOperators.arrayAsSet("A").intersects("B")).as("commonToBoth") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -514,7 +515,7 @@ public void shouldRenderSetIntersectionAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderSetUnion() { + void shouldRenderSetUnion() { Document agg = project("A", "B").and("A").unionArrays("B").as("allValues").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -523,7 +524,7 @@ public void shouldRenderSetUnion() { } @Test // DATAMONGO-1536 - public void shouldRenderSetUnionAggregationExpresssion() { + void shouldRenderSetUnionAggregationExpresssion() { Document agg = project("A", "B").and(SetOperators.arrayAsSet("A").union("B")).as("allValues") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -533,7 +534,7 @@ public void shouldRenderSetUnionAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderSetDifference() { + void shouldRenderSetDifference() { Document agg = project("A", "B").and("B").differenceToArray("A").as("inBOnly") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -543,7 +544,7 @@ public void shouldRenderSetDifference() { } @Test // DATAMONGO-1536 - public void shouldRenderSetDifferenceAggregationExpresssion() { + void shouldRenderSetDifferenceAggregationExpresssion() { Document agg = project("A", "B").and(SetOperators.arrayAsSet("B").differenceTo("A")).as("inBOnly") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -553,7 +554,7 @@ public void shouldRenderSetDifferenceAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderSetIsSubset() { + void shouldRenderSetIsSubset() { Document agg = project("A", "B").and("A").subsetOfArray("B").as("aIsSubsetOfB") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -563,7 +564,7 @@ public void shouldRenderSetIsSubset() { } @Test // DATAMONGO-1536 - public void shouldRenderSetIsSubsetAggregationExpresssion() { + void shouldRenderSetIsSubsetAggregationExpresssion() { Document agg = project("A", "B").and(SetOperators.arrayAsSet("A").isSubsetOf("B")).as("aIsSubsetOfB") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -573,7 +574,7 @@ public void shouldRenderSetIsSubsetAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderAnyElementTrue() { + void shouldRenderAnyElementTrue() { Document agg = project("responses").and("responses").anyElementInArrayTrue().as("isAnyTrue") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -583,7 +584,7 @@ public void shouldRenderAnyElementTrue() { } @Test // DATAMONGO-1536 - public void shouldRenderAnyElementTrueAggregationExpresssion() { + void shouldRenderAnyElementTrueAggregationExpresssion() { Document agg = project("responses").and(SetOperators.arrayAsSet("responses").anyElementTrue()).as("isAnyTrue") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -593,7 +594,7 @@ public void shouldRenderAnyElementTrueAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderAllElementsTrue() { + void shouldRenderAllElementsTrue() { Document agg = project("responses").and("responses").allElementsInArrayTrue().as("isAllTrue") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -603,7 +604,7 @@ public void shouldRenderAllElementsTrue() { } @Test // DATAMONGO-1536 - public void shouldRenderAllElementsTrueAggregationExpresssion() { + void shouldRenderAllElementsTrueAggregationExpresssion() { Document agg = project("responses").and(SetOperators.arrayAsSet("responses").allElementsTrue()).as("isAllTrue") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -613,7 +614,7 @@ public void shouldRenderAllElementsTrueAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderAbs() { + void shouldRenderAbs() { Document agg = project().and("anyNumber").absoluteValue().as("absoluteValue") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -622,7 +623,7 @@ public void shouldRenderAbs() { } @Test // DATAMONGO-1536 - public void shouldRenderAbsAggregationExpresssion() { + void shouldRenderAbsAggregationExpresssion() { Document agg = project() .and( @@ -634,7 +635,7 @@ public void shouldRenderAbsAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderAddAggregationExpresssion() { + void shouldRenderAddAggregationExpresssion() { Document agg = project().and(ArithmeticOperators.valueOf("price").add("fee")).as("total") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -643,7 +644,7 @@ public void shouldRenderAddAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderCeil() { + void shouldRenderCeil() { Document agg = project().and("anyNumber").ceil().as("ceilValue").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -651,7 +652,7 @@ public void shouldRenderCeil() { } @Test // DATAMONGO-1536 - public void shouldRenderCeilAggregationExpresssion() { + void shouldRenderCeilAggregationExpresssion() { Document agg = project().and( ArithmeticOperators.valueOf(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))).ceil()) @@ -662,7 +663,7 @@ public void shouldRenderCeilAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderDivide() { + void shouldRenderDivide() { Document agg = project().and("value") .divide(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))).as("result") @@ -673,7 +674,7 @@ public void shouldRenderDivide() { } @Test // DATAMONGO-1536 - public void shouldRenderDivideAggregationExpresssion() { + void shouldRenderDivideAggregationExpresssion() { Document agg = project() .and(ArithmeticOperators.valueOf("anyNumber") @@ -685,7 +686,7 @@ public void shouldRenderDivideAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderExp() { + void shouldRenderExp() { Document agg = project().and("value").exp().as("result").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -693,7 +694,7 @@ public void shouldRenderExp() { } @Test // DATAMONGO-1536 - public void shouldRenderExpAggregationExpresssion() { + void shouldRenderExpAggregationExpresssion() { Document agg = project() .and( @@ -705,7 +706,7 @@ public void shouldRenderExpAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderFloor() { + void shouldRenderFloor() { Document agg = project().and("value").floor().as("result").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -713,7 +714,7 @@ public void shouldRenderFloor() { } @Test // DATAMONGO-1536 - public void shouldRenderFloorAggregationExpresssion() { + void shouldRenderFloorAggregationExpresssion() { Document agg = project().and( ArithmeticOperators.valueOf(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))).floor()) @@ -724,7 +725,7 @@ public void shouldRenderFloorAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderLn() { + void shouldRenderLn() { Document agg = project().and("value").ln().as("result").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -732,7 +733,7 @@ public void shouldRenderLn() { } @Test // DATAMONGO-1536 - public void shouldRenderLnAggregationExpresssion() { + void shouldRenderLnAggregationExpresssion() { Document agg = project() .and(ArithmeticOperators.valueOf(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))).ln()) @@ -743,7 +744,7 @@ public void shouldRenderLnAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderLog() { + void shouldRenderLog() { Document agg = project().and("value").log(2).as("result").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -751,7 +752,7 @@ public void shouldRenderLog() { } @Test // DATAMONGO-1536 - public void shouldRenderLogAggregationExpresssion() { + void shouldRenderLogAggregationExpresssion() { Document agg = project().and( ArithmeticOperators.valueOf(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))).log(2)) @@ -762,7 +763,7 @@ public void shouldRenderLogAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderLog10() { + void shouldRenderLog10() { Document agg = project().and("value").log10().as("result").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -770,7 +771,7 @@ public void shouldRenderLog10() { } @Test // DATAMONGO-1536 - public void shouldRenderLog10AggregationExpresssion() { + void shouldRenderLog10AggregationExpresssion() { Document agg = project().and( ArithmeticOperators.valueOf(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))).log10()) @@ -781,7 +782,7 @@ public void shouldRenderLog10AggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderMod() { + void shouldRenderMod() { Document agg = project().and("value").mod(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))) .as("result").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -791,7 +792,7 @@ public void shouldRenderMod() { } @Test // DATAMONGO-1536 - public void shouldRenderModAggregationExpresssion() { + void shouldRenderModAggregationExpresssion() { Document agg = project().and( ArithmeticOperators.valueOf(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))).mod(2)) @@ -802,7 +803,7 @@ public void shouldRenderModAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderMultiply() { + void shouldRenderMultiply() { Document agg = project().and("value") .multiply(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))).as("result") @@ -813,7 +814,7 @@ public void shouldRenderMultiply() { } @Test // DATAMONGO-1536 - public void shouldRenderMultiplyAggregationExpresssion() { + void shouldRenderMultiplyAggregationExpresssion() { Document agg = project() .and(ArithmeticOperators.valueOf(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))) @@ -825,7 +826,7 @@ public void shouldRenderMultiplyAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderPow() { + void shouldRenderPow() { Document agg = project().and("value").pow(2).as("result").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -833,7 +834,7 @@ public void shouldRenderPow() { } @Test // DATAMONGO-1536 - public void shouldRenderPowAggregationExpresssion() { + void shouldRenderPowAggregationExpresssion() { Document agg = project().and( ArithmeticOperators.valueOf(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))).pow(2)) @@ -844,7 +845,7 @@ public void shouldRenderPowAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderSqrt() { + void shouldRenderSqrt() { Document agg = project().and("value").sqrt().as("result").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -852,7 +853,7 @@ public void shouldRenderSqrt() { } @Test // DATAMONGO-1536 - public void shouldRenderSqrtAggregationExpresssion() { + void shouldRenderSqrtAggregationExpresssion() { Document agg = project().and( ArithmeticOperators.valueOf(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))).sqrt()) @@ -863,7 +864,7 @@ public void shouldRenderSqrtAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderSubtract() { + void shouldRenderSubtract() { Document agg = project().and("numericField").minus(AggregationFunctionExpressions.SIZE.of(field("someArray"))) .as("result").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -873,7 +874,7 @@ public void shouldRenderSubtract() { } @Test // DATAMONGO-1536 - public void shouldRenderSubtractAggregationExpresssion() { + void shouldRenderSubtractAggregationExpresssion() { Document agg = project() .and(ArithmeticOperators.valueOf("numericField") @@ -885,7 +886,7 @@ public void shouldRenderSubtractAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderTrunc() { + void shouldRenderTrunc() { Document agg = project().and("value").trunc().as("result").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -893,7 +894,7 @@ public void shouldRenderTrunc() { } @Test // DATAMONGO-1536 - public void shouldRenderTruncAggregationExpresssion() { + void shouldRenderTruncAggregationExpresssion() { Document agg = project().and( ArithmeticOperators.valueOf(AggregationFunctionExpressions.SUBTRACT.of(field("start"), field("end"))).trunc()) @@ -904,7 +905,7 @@ public void shouldRenderTruncAggregationExpresssion() { } @Test // DATAMONGO-1536 - public void shouldRenderConcat() { + void shouldRenderConcat() { Document agg = project().and("item").concat(" - ", field("description")).as("itemDescription") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -915,7 +916,7 @@ public void shouldRenderConcat() { } @Test // DATAMONGO-1536 - public void shouldRenderConcatAggregationExpression() { + void shouldRenderConcatAggregationExpression() { Document agg = project().and(StringOperators.valueOf("item").concat(" - ").concatValueOf("description")) .as("itemDescription").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -926,7 +927,7 @@ public void shouldRenderConcatAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderSubstr() { + void shouldRenderSubstr() { Document agg = project().and("quarter").substring(0, 2).as("yearSubstring").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -934,7 +935,7 @@ public void shouldRenderSubstr() { } @Test // DATAMONGO-1536 - public void shouldRenderSubstrAggregationExpression() { + void shouldRenderSubstrAggregationExpression() { Document agg = project().and(StringOperators.valueOf("quarter").substring(0, 2)).as("yearSubstring") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -943,7 +944,7 @@ public void shouldRenderSubstrAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderToLower() { + void shouldRenderToLower() { Document agg = project().and("item").toLower().as("item").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -951,7 +952,7 @@ public void shouldRenderToLower() { } @Test // DATAMONGO-1536 - public void shouldRenderToLowerAggregationExpression() { + void shouldRenderToLowerAggregationExpression() { Document agg = project().and(StringOperators.valueOf("item").toLower()).as("item") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -960,7 +961,7 @@ public void shouldRenderToLowerAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderToUpper() { + void shouldRenderToUpper() { Document agg = project().and("item").toUpper().as("item").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -968,7 +969,7 @@ public void shouldRenderToUpper() { } @Test // DATAMONGO-1536 - public void shouldRenderToUpperAggregationExpression() { + void shouldRenderToUpperAggregationExpression() { Document agg = project().and(StringOperators.valueOf("item").toUpper()).as("item") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -977,7 +978,7 @@ public void shouldRenderToUpperAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderStrCaseCmp() { + void shouldRenderStrCaseCmp() { Document agg = project().and("quarter").strCaseCmp("13q4").as("comparisonResult") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -987,7 +988,7 @@ public void shouldRenderStrCaseCmp() { } @Test // DATAMONGO-1536 - public void shouldRenderStrCaseCmpAggregationExpression() { + void shouldRenderStrCaseCmpAggregationExpression() { Document agg = project().and(StringOperators.valueOf("quarter").strCaseCmp("13q4")).as("comparisonResult") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -997,7 +998,7 @@ public void shouldRenderStrCaseCmpAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderArrayElementAt() { + void shouldRenderArrayElementAt() { Document agg = project().and("favorites").arrayElementAt(0).as("first").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1005,7 +1006,7 @@ public void shouldRenderArrayElementAt() { } @Test // DATAMONGO-1536 - public void shouldRenderArrayElementAtAggregationExpression() { + void shouldRenderArrayElementAtAggregationExpression() { Document agg = project().and(ArrayOperators.arrayOf("favorites").elementAt(0)).as("first") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1014,7 +1015,7 @@ public void shouldRenderArrayElementAtAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderConcatArrays() { + void shouldRenderConcatArrays() { Document agg = project().and("instock").concatArrays("ordered").as("items").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1023,7 +1024,7 @@ public void shouldRenderConcatArrays() { } @Test // DATAMONGO-1536 - public void shouldRenderConcatArraysAggregationExpression() { + void shouldRenderConcatArraysAggregationExpression() { Document agg = project().and(ArrayOperators.arrayOf("instock").concat("ordered")).as("items") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1033,7 +1034,7 @@ public void shouldRenderConcatArraysAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderIsArray() { + void shouldRenderIsArray() { Document agg = project().and("instock").isArray().as("isAnArray").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1041,7 +1042,7 @@ public void shouldRenderIsArray() { } @Test // DATAMONGO-1536 - public void shouldRenderIsArrayAggregationExpression() { + void shouldRenderIsArrayAggregationExpression() { Document agg = project().and(ArrayOperators.arrayOf("instock").isArray()).as("isAnArray") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1050,7 +1051,7 @@ public void shouldRenderIsArrayAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderSizeAggregationExpression() { + void shouldRenderSizeAggregationExpression() { Document agg = project().and(ArrayOperators.arrayOf("instock").length()).as("arraySize") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1059,7 +1060,7 @@ public void shouldRenderSizeAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderSliceAggregationExpression() { + void shouldRenderSliceAggregationExpression() { Document agg = project().and(ArrayOperators.arrayOf("favorites").slice().itemCount(3)).as("threeFavorites") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1068,7 +1069,7 @@ public void shouldRenderSliceAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderSliceWithPositionAggregationExpression() { + void shouldRenderSliceWithPositionAggregationExpression() { Document agg = project().and(ArrayOperators.arrayOf("favorites").slice().offset(2).itemCount(3)) .as("threeFavorites").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1077,7 +1078,7 @@ public void shouldRenderSliceWithPositionAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderLiteral() { + void shouldRenderLiteral() { Document agg = project().and("$1").asLiteral().as("literalOnly").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1085,7 +1086,7 @@ public void shouldRenderLiteral() { } @Test // DATAMONGO-1536 - public void shouldRenderLiteralAggregationExpression() { + void shouldRenderLiteralAggregationExpression() { Document agg = project().and(LiteralOperators.valueOf("$1").asLiteral()).as("literalOnly") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1094,7 +1095,7 @@ public void shouldRenderLiteralAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderDayOfYearAggregationExpression() { + void shouldRenderDayOfYearAggregationExpression() { Document agg = project().and(DateOperators.dateOf("date").dayOfYear()).as("dayOfYear") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1103,7 +1104,7 @@ public void shouldRenderDayOfYearAggregationExpression() { } @Test // DATAMONGO-1834 - public void shouldRenderDayOfYearAggregationExpressionWithTimezone() { + void shouldRenderDayOfYearAggregationExpressionWithTimezone() { Document agg = project() .and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).dayOfYear()).as("dayOfYear") @@ -1114,7 +1115,7 @@ public void shouldRenderDayOfYearAggregationExpressionWithTimezone() { } @Test // DATAMONGO-1834 - public void shouldRenderTimeZoneFromField() { + void shouldRenderTimeZoneFromField() { Document agg = project().and(DateOperators.dateOf("date").withTimezone(Timezone.ofField("tz")).dayOfYear()) .as("dayOfYear").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1124,7 +1125,7 @@ public void shouldRenderTimeZoneFromField() { } @Test // DATAMONGO-1834 - public void shouldRenderTimeZoneFromExpression() { + void shouldRenderTimeZoneFromExpression() { Document agg = project() .and(DateOperators.dateOf("date") @@ -1136,7 +1137,7 @@ public void shouldRenderTimeZoneFromExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderDayOfMonthAggregationExpression() { + void shouldRenderDayOfMonthAggregationExpression() { Document agg = project().and(DateOperators.dateOf("date").dayOfMonth()).as("day") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1145,7 +1146,7 @@ public void shouldRenderDayOfMonthAggregationExpression() { } @Test // DATAMONGO-1834 - public void shouldRenderDayOfMonthAggregationExpressionWithTimezone() { + void shouldRenderDayOfMonthAggregationExpressionWithTimezone() { Document agg = project() .and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).dayOfMonth()).as("day") @@ -1156,7 +1157,7 @@ public void shouldRenderDayOfMonthAggregationExpressionWithTimezone() { } @Test // DATAMONGO-1536 - public void shouldRenderDayOfWeekAggregationExpression() { + void shouldRenderDayOfWeekAggregationExpression() { Document agg = project().and(DateOperators.dateOf("date").dayOfWeek()).as("dayOfWeek") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1165,7 +1166,7 @@ public void shouldRenderDayOfWeekAggregationExpression() { } @Test // DATAMONGO-1834 - public void shouldRenderDayOfWeekAggregationExpressionWithTimezone() { + void shouldRenderDayOfWeekAggregationExpressionWithTimezone() { Document agg = project() .and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).dayOfWeek()).as("dayOfWeek") @@ -1176,7 +1177,7 @@ public void shouldRenderDayOfWeekAggregationExpressionWithTimezone() { } @Test // DATAMONGO-1536 - public void shouldRenderYearAggregationExpression() { + void shouldRenderYearAggregationExpression() { Document agg = project().and(DateOperators.dateOf("date").year()).as("year") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1185,7 +1186,7 @@ public void shouldRenderYearAggregationExpression() { } @Test // DATAMONGO-1834 - public void shouldRenderYearAggregationExpressionWithTimezone() { + void shouldRenderYearAggregationExpressionWithTimezone() { Document agg = project().and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).year()) .as("year").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1195,7 +1196,7 @@ public void shouldRenderYearAggregationExpressionWithTimezone() { } @Test // DATAMONGO-1536 - public void shouldRenderMonthAggregationExpression() { + void shouldRenderMonthAggregationExpression() { Document agg = project().and(DateOperators.dateOf("date").month()).as("month") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1204,7 +1205,7 @@ public void shouldRenderMonthAggregationExpression() { } @Test // DATAMONGO-1834 - public void shouldRenderMonthAggregationExpressionWithTimezone() { + void shouldRenderMonthAggregationExpressionWithTimezone() { Document agg = project().and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).month()) .as("month").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1214,7 +1215,7 @@ public void shouldRenderMonthAggregationExpressionWithTimezone() { } @Test // DATAMONGO-1536 - public void shouldRenderWeekAggregationExpression() { + void shouldRenderWeekAggregationExpression() { Document agg = project().and(DateOperators.dateOf("date").week()).as("week") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1223,7 +1224,7 @@ public void shouldRenderWeekAggregationExpression() { } @Test // DATAMONGO-1834 - public void shouldRenderWeekAggregationExpressionWithTimezone() { + void shouldRenderWeekAggregationExpressionWithTimezone() { Document agg = project().and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).week()) .as("week").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1233,7 +1234,7 @@ public void shouldRenderWeekAggregationExpressionWithTimezone() { } @Test // DATAMONGO-1536 - public void shouldRenderHourAggregationExpression() { + void shouldRenderHourAggregationExpression() { Document agg = project().and(DateOperators.dateOf("date").hour()).as("hour") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1242,7 +1243,7 @@ public void shouldRenderHourAggregationExpression() { } @Test // DATAMONGO-1834 - public void shouldRenderHourAggregationExpressionWithTimezone() { + void shouldRenderHourAggregationExpressionWithTimezone() { Document agg = project().and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).hour()) .as("hour").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1252,7 +1253,7 @@ public void shouldRenderHourAggregationExpressionWithTimezone() { } @Test // DATAMONGO-1536 - public void shouldRenderMinuteAggregationExpression() { + void shouldRenderMinuteAggregationExpression() { Document agg = project().and(DateOperators.dateOf("date").minute()).as("minute") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1261,7 +1262,7 @@ public void shouldRenderMinuteAggregationExpression() { } @Test // DATAMONGO-1834 - public void shouldRenderMinuteAggregationExpressionWithTimezone() { + void shouldRenderMinuteAggregationExpressionWithTimezone() { Document agg = project() .and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).minute()).as("minute") @@ -1272,7 +1273,7 @@ public void shouldRenderMinuteAggregationExpressionWithTimezone() { } @Test // DATAMONGO-1536 - public void shouldRenderSecondAggregationExpression() { + void shouldRenderSecondAggregationExpression() { Document agg = project().and(DateOperators.dateOf("date").second()).as("second") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1281,7 +1282,7 @@ public void shouldRenderSecondAggregationExpression() { } @Test // DATAMONGO-1834 - public void shouldRenderSecondAggregationExpressionWithTimezone() { + void shouldRenderSecondAggregationExpressionWithTimezone() { Document agg = project() .and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).second()).as("second") @@ -1292,7 +1293,7 @@ public void shouldRenderSecondAggregationExpressionWithTimezone() { } @Test // DATAMONGO-1536 - public void shouldRenderMillisecondAggregationExpression() { + void shouldRenderMillisecondAggregationExpression() { Document agg = project().and(DateOperators.dateOf("date").millisecond()).as("msec") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1301,7 +1302,7 @@ public void shouldRenderMillisecondAggregationExpression() { } @Test // DATAMONGO-1834 - public void shouldRenderMillisecondAggregationExpressionWithTimezone() { + void shouldRenderMillisecondAggregationExpressionWithTimezone() { Document agg = project() .and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).millisecond()).as("msec") @@ -1312,7 +1313,7 @@ public void shouldRenderMillisecondAggregationExpressionWithTimezone() { } @Test // DATAMONGO-1536 - public void shouldRenderDateToString() { + void shouldRenderDateToString() { Document agg = project().and("date").dateAsFormattedString("%H:%M:%S:%L").as("time") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1322,7 +1323,7 @@ public void shouldRenderDateToString() { } @Test // DATAMONGO-2047 - public void shouldRenderDateToStringWithoutFormatOption() { + void shouldRenderDateToStringWithoutFormatOption() { Document agg = project().and("date").dateAsFormattedString().as("time").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1330,7 +1331,7 @@ public void shouldRenderDateToStringWithoutFormatOption() { } @Test // DATAMONGO-1536 - public void shouldRenderDateToStringAggregationExpression() { + void shouldRenderDateToStringAggregationExpression() { Document agg = project().and(DateOperators.dateOf("date").toString("%H:%M:%S:%L")).as("time") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1340,7 +1341,7 @@ public void shouldRenderDateToStringAggregationExpression() { } @Test // DATAMONGO-1834, DATAMONGO-2047 - public void shouldRenderDateToStringAggregationExpressionWithTimezone() { + void shouldRenderDateToStringAggregationExpressionWithTimezone() { Document agg = project() .and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).toString("%H:%M:%S:%L")) @@ -1358,7 +1359,7 @@ public void shouldRenderDateToStringAggregationExpressionWithTimezone() { } @Test // DATAMONGO-2047 - public void shouldRenderDateToStringWithOnNull() { + void shouldRenderDateToStringWithOnNull() { Document agg = project() .and(DateOperators.dateOf("date").toStringWithDefaultFormat().onNullReturnValueOf("fallback-field")).as("time") @@ -1369,7 +1370,7 @@ public void shouldRenderDateToStringWithOnNull() { } @Test // DATAMONGO-2047 - public void shouldRenderDateToStringWithOnNullExpression() { + void shouldRenderDateToStringWithOnNullExpression() { Document agg = project() .and(DateOperators.dateOf("date").toStringWithDefaultFormat() @@ -1381,7 +1382,7 @@ public void shouldRenderDateToStringWithOnNullExpression() { } @Test // DATAMONGO-2047 - public void shouldRenderDateToStringWithOnNullAndTimezone() { + void shouldRenderDateToStringWithOnNullAndTimezone() { Document agg = project().and(DateOperators.dateOf("date").toStringWithDefaultFormat() .onNullReturnValueOf("fallback-field").withTimezone(Timezone.ofField("foo"))).as("time") @@ -1392,7 +1393,7 @@ public void shouldRenderDateToStringWithOnNullAndTimezone() { } @Test // DATAMONGO-1536 - public void shouldRenderSumAggregationExpression() { + void shouldRenderSumAggregationExpression() { Document agg = project().and(ArithmeticOperators.valueOf("quizzes").sum()).as("quizTotal") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1401,7 +1402,7 @@ public void shouldRenderSumAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderSumWithMultipleArgsAggregationExpression() { + void shouldRenderSumWithMultipleArgsAggregationExpression() { Document agg = project().and(ArithmeticOperators.valueOf("final").sum().and("midterm")).as("examTotal") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1410,7 +1411,7 @@ public void shouldRenderSumWithMultipleArgsAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderAvgAggregationExpression() { + void shouldRenderAvgAggregationExpression() { Document agg = project().and(ArithmeticOperators.valueOf("quizzes").avg()).as("quizAvg") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1419,7 +1420,7 @@ public void shouldRenderAvgAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderAvgWithMultipleArgsAggregationExpression() { + void shouldRenderAvgWithMultipleArgsAggregationExpression() { Document agg = project().and(ArithmeticOperators.valueOf("final").avg().and("midterm")).as("examAvg") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1428,7 +1429,7 @@ public void shouldRenderAvgWithMultipleArgsAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderMaxAggregationExpression() { + void shouldRenderMaxAggregationExpression() { Document agg = project().and(ArithmeticOperators.valueOf("quizzes").max()).as("quizMax") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1437,7 +1438,7 @@ public void shouldRenderMaxAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderMaxWithMultipleArgsAggregationExpression() { + void shouldRenderMaxWithMultipleArgsAggregationExpression() { Document agg = project().and(ArithmeticOperators.valueOf("final").max().and("midterm")).as("examMax") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1446,7 +1447,7 @@ public void shouldRenderMaxWithMultipleArgsAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderMinAggregationExpression() { + void shouldRenderMinAggregationExpression() { Document agg = project().and(ArithmeticOperators.valueOf("quizzes").min()).as("quizMin") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1455,7 +1456,7 @@ public void shouldRenderMinAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderMinWithMultipleArgsAggregationExpression() { + void shouldRenderMinWithMultipleArgsAggregationExpression() { Document agg = project().and(ArithmeticOperators.valueOf("final").min().and("midterm")).as("examMin") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1464,7 +1465,7 @@ public void shouldRenderMinWithMultipleArgsAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderStdDevPopAggregationExpression() { + void shouldRenderStdDevPopAggregationExpression() { Document agg = project().and(ArithmeticOperators.valueOf("scores").stdDevPop()).as("stdDev") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1473,7 +1474,7 @@ public void shouldRenderStdDevPopAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderStdDevSampAggregationExpression() { + void shouldRenderStdDevSampAggregationExpression() { Document agg = project().and(ArithmeticOperators.valueOf("scores").stdDevSamp()).as("stdDev") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1482,7 +1483,7 @@ public void shouldRenderStdDevSampAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderCmpAggregationExpression() { + void shouldRenderCmpAggregationExpression() { Document agg = project().and(ComparisonOperators.valueOf("qty").compareToValue(250)).as("cmp250") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1491,7 +1492,7 @@ public void shouldRenderCmpAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderEqAggregationExpression() { + void shouldRenderEqAggregationExpression() { Document agg = project().and(ComparisonOperators.valueOf("qty").equalToValue(250)).as("eq250") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1500,7 +1501,7 @@ public void shouldRenderEqAggregationExpression() { } @Test // DATAMONGO-2513 - public void shouldRenderEqAggregationExpressionWithListComparison() { + void shouldRenderEqAggregationExpressionWithListComparison() { Document agg = project().and(ComparisonOperators.valueOf("qty").equalToValue(Arrays.asList(250))).as("eq250") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1509,7 +1510,7 @@ public void shouldRenderEqAggregationExpressionWithListComparison() { } @Test // DATAMONGO-1536 - public void shouldRenderGtAggregationExpression() { + void shouldRenderGtAggregationExpression() { Document agg = project().and(ComparisonOperators.valueOf("qty").greaterThanValue(250)).as("gt250") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1518,7 +1519,7 @@ public void shouldRenderGtAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderGteAggregationExpression() { + void shouldRenderGteAggregationExpression() { Document agg = project().and(ComparisonOperators.valueOf("qty").greaterThanEqualToValue(250)).as("gte250") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1527,7 +1528,7 @@ public void shouldRenderGteAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderLtAggregationExpression() { + void shouldRenderLtAggregationExpression() { Document agg = project().and(ComparisonOperators.valueOf("qty").lessThanValue(250)).as("lt250") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1536,7 +1537,7 @@ public void shouldRenderLtAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderLteAggregationExpression() { + void shouldRenderLteAggregationExpression() { Document agg = project().and(ComparisonOperators.valueOf("qty").lessThanEqualToValue(250)).as("lte250") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1545,7 +1546,7 @@ public void shouldRenderLteAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderNeAggregationExpression() { + void shouldRenderNeAggregationExpression() { Document agg = project().and(ComparisonOperators.valueOf("qty").notEqualToValue(250)).as("ne250") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1554,7 +1555,7 @@ public void shouldRenderNeAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderLogicAndAggregationExpression() { + void shouldRenderLogicAndAggregationExpression() { Document agg = project() .and(BooleanOperators.valueOf(ComparisonOperators.valueOf("qty").greaterThanValue(100)) @@ -1566,7 +1567,7 @@ public void shouldRenderLogicAndAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderLogicOrAggregationExpression() { + void shouldRenderLogicOrAggregationExpression() { Document agg = project() .and(BooleanOperators.valueOf(ComparisonOperators.valueOf("qty").greaterThanValue(250)) @@ -1578,7 +1579,7 @@ public void shouldRenderLogicOrAggregationExpression() { } @Test // DATAMONGO-1536 - public void shouldRenderNotAggregationExpression() { + void shouldRenderNotAggregationExpression() { Document agg = project().and(BooleanOperators.not(ComparisonOperators.valueOf("qty").greaterThanValue(250))) .as("result").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1587,7 +1588,7 @@ public void shouldRenderNotAggregationExpression() { } @Test // DATAMONGO-1540 - public void shouldRenderMapAggregationExpression() { + void shouldRenderMapAggregationExpression() { Document agg = Aggregation.project() .and(VariableOperators.mapItemsOf("quizzes").as("grade") @@ -1599,7 +1600,7 @@ public void shouldRenderMapAggregationExpression() { } @Test // DATAMONGO-1540 - public void shouldRenderMapAggregationExpressionOnExpression() { + void shouldRenderMapAggregationExpressionOnExpression() { Document agg = Aggregation.project() .and(VariableOperators.mapItemsOf(AggregationFunctionExpressions.SIZE.of("foo")).as("grade") @@ -1611,7 +1612,7 @@ public void shouldRenderMapAggregationExpressionOnExpression() { } @Test // DATAMONGO-861, DATAMONGO-1542 - public void shouldRenderIfNullConditionAggregationExpression() { + void shouldRenderIfNullConditionAggregationExpression() { Document agg = project().and( ConditionalOperators.ifNull(ArrayOperators.arrayOf("array").elementAt(1)).then("a more sophisticated value")) @@ -1622,7 +1623,7 @@ public void shouldRenderIfNullConditionAggregationExpression() { } @Test // DATAMONGO-1542 - public void shouldRenderIfNullValueAggregationExpression() { + void shouldRenderIfNullValueAggregationExpression() { Document agg = project() .and(ConditionalOperators.ifNull("field").then(ArrayOperators.arrayOf("array").elementAt(1))).as("result") @@ -1633,7 +1634,7 @@ public void shouldRenderIfNullValueAggregationExpression() { } @Test // DATAMONGO-861, DATAMONGO-1542 - public void fieldReplacementIfNullShouldRenderCorrectly() { + void fieldReplacementIfNullShouldRenderCorrectly() { Document agg = project().and(ConditionalOperators.ifNull("optional").thenValueOf("$never-null")).as("result") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1643,7 +1644,7 @@ public void fieldReplacementIfNullShouldRenderCorrectly() { } @Test // DATAMONGO-1538 - public void shouldRenderLetExpressionCorrectly() { + void shouldRenderLetExpressionCorrectly() { Document agg = Aggregation.project() .and(VariableOperators @@ -1665,7 +1666,7 @@ public void shouldRenderLetExpressionCorrectly() { } @Test // DATAMONGO-1538 - public void shouldRenderLetExpressionCorrectlyWhenUsingLetOnProjectionBuilder() { + void shouldRenderLetExpressionCorrectlyWhenUsingLetOnProjectionBuilder() { ExpressionVariable var1 = newVariable("total") .forExpression(AggregationFunctionExpressions.ADD.of(Fields.field("price"), Fields.field("tax"))); @@ -1688,7 +1689,7 @@ public void shouldRenderLetExpressionCorrectlyWhenUsingLetOnProjectionBuilder() } @Test // DATAMONGO-1548 - public void shouldRenderIndexOfBytesCorrectly() { + void shouldRenderIndexOfBytesCorrectly() { Document agg = project().and(StringOperators.valueOf("item").indexOf("foo")).as("byteLocation") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1698,7 +1699,7 @@ public void shouldRenderIndexOfBytesCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderIndexOfBytesWithRangeCorrectly() { + void shouldRenderIndexOfBytesWithRangeCorrectly() { Document agg = project() .and(StringOperators.valueOf("item").indexOf("foo") @@ -1710,7 +1711,7 @@ public void shouldRenderIndexOfBytesWithRangeCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderIndexOfCPCorrectly() { + void shouldRenderIndexOfCPCorrectly() { Document agg = project().and(StringOperators.valueOf("item").indexOfCP("foo")).as("cpLocation") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1719,7 +1720,7 @@ public void shouldRenderIndexOfCPCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderIndexOfCPWithRangeCorrectly() { + void shouldRenderIndexOfCPWithRangeCorrectly() { Document agg = project() .and(StringOperators.valueOf("item").indexOfCP("foo") @@ -1731,7 +1732,7 @@ public void shouldRenderIndexOfCPWithRangeCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderSplitCorrectly() { + void shouldRenderSplitCorrectly() { Document agg = project().and(StringOperators.valueOf("city").split(", ")).as("city_state") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1740,7 +1741,7 @@ public void shouldRenderSplitCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderStrLenBytesCorrectly() { + void shouldRenderStrLenBytesCorrectly() { Document agg = project().and(StringOperators.valueOf("name").length()).as("length") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1749,7 +1750,7 @@ public void shouldRenderStrLenBytesCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderStrLenCPCorrectly() { + void shouldRenderStrLenCPCorrectly() { Document agg = project().and(StringOperators.valueOf("name").lengthCP()).as("length") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1758,7 +1759,7 @@ public void shouldRenderStrLenCPCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderSubstrCPCorrectly() { + void shouldRenderSubstrCPCorrectly() { Document agg = project().and(StringOperators.valueOf("quarter").substringCP(0, 2)).as("yearSubstring") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1766,27 +1767,27 @@ public void shouldRenderSubstrCPCorrectly() { assertThat(agg) .isEqualTo(Document.parse("{ $project : { yearSubstring: { $substrCP: [ \"$quarter\", 0, 2 ] } } }")); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFindCorrectly() { + + @Test // GH-3725 + void shouldRenderRegexFindCorrectly() { Document agg = project().and(StringOperators.valueOf("field1").regexFind("e")).as("regex") .toDocument(Aggregation.DEFAULT_CONTEXT); assertThat(agg).isEqualTo(Document.parse("{ $project : { regex: { $regexFind: { \"input\" : \"$field1\", \"regex\" : \"e\" } } } }")); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFindAllCorrectly() { + + @Test // GH-3725 + void shouldRenderRegexFindAllCorrectly() { Document agg = project().and(StringOperators.valueOf("field1").regexFindAll("e")).as("regex") .toDocument(Aggregation.DEFAULT_CONTEXT); assertThat(agg).isEqualTo(Document.parse("{ $project : { regex: { $regexFindAll: { \"input\" : \"$field1\", \"regex\" : \"e\" } } } }")); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexMatchCorrectly() { + + @Test // GH-3725 + void shouldRenderRegexMatchCorrectly() { Document agg = project().and(StringOperators.valueOf("field1").regexMatch("e")).as("regex") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1795,7 +1796,7 @@ public void shouldRenderRegexMatchCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderIndexOfArrayCorrectly() { + void shouldRenderIndexOfArrayCorrectly() { Document agg = project().and(ArrayOperators.arrayOf("items").indexOf(2)).as("index") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1804,7 +1805,7 @@ public void shouldRenderIndexOfArrayCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderRangeCorrectly() { + void shouldRenderRangeCorrectly() { Document agg = project().and(ArrayOperators.RangeOperator.rangeStartingAt(0L).to("distance").withStepSize(25L)) .as("rest_stops").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1815,7 +1816,7 @@ public void shouldRenderRangeCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderReverseArrayCorrectly() { + void shouldRenderReverseArrayCorrectly() { Document agg = project().and(ArrayOperators.arrayOf("favorites").reverse()).as("reverseFavorites") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1824,7 +1825,7 @@ public void shouldRenderReverseArrayCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderReduceWithSimpleObjectCorrectly() { + void shouldRenderReduceWithSimpleObjectCorrectly() { Document agg = project() .and(ArrayOperators.arrayOf("probabilityArr") @@ -1836,7 +1837,7 @@ public void shouldRenderReduceWithSimpleObjectCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderReduceWithComplexObjectCorrectly() { + void shouldRenderReduceWithComplexObjectCorrectly() { PropertyExpression sum = PropertyExpression.property("sum").definedAs( ArithmeticOperators.valueOf(Variable.VALUE.referringTo("sum").getName()).add(Variable.THIS.getName())); @@ -1853,7 +1854,7 @@ public void shouldRenderReduceWithComplexObjectCorrectly() { } @Test // DATAMONGO-1843 - public void shouldRenderReduceWithInputAndInExpressionsCorrectly() { + void shouldRenderReduceWithInputAndInExpressionsCorrectly() { Document expected = Document.parse( "{ \"$project\" : { \"results\" : { \"$reduce\" : { \"input\" : { \"$slice\" : [\"$array\", 5] }, \"initialValue\" : \"\", \"in\" : { \"$concat\" : [\"$$value\", \"/\", \"$$this\"] } } } } }"); @@ -1874,7 +1875,7 @@ public void shouldRenderReduceWithInputAndInExpressionsCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderZipCorrectly() { + void shouldRenderZipCorrectly() { AggregationExpression elemAt0 = ArrayOperators.arrayOf("matrix").elementAt(0); AggregationExpression elemAt1 = ArrayOperators.arrayOf("matrix").elementAt(1); @@ -1889,7 +1890,7 @@ public void shouldRenderZipCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderInCorrectly() { + void shouldRenderInCorrectly() { Document agg = project().and(ArrayOperators.arrayOf("in_stock").containsValue("bananas")).as("has_bananas") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1899,7 +1900,7 @@ public void shouldRenderInCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderIsoDayOfWeekCorrectly() { + void shouldRenderIsoDayOfWeekCorrectly() { Document agg = project().and(DateOperators.dateOf("birthday").isoDayOfWeek()).as("dayOfWeek") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1908,7 +1909,7 @@ public void shouldRenderIsoDayOfWeekCorrectly() { } @Test // DATAMONGO-1834 - public void shouldRenderIsoDayOfWeekWithTimezoneCorrectly() { + void shouldRenderIsoDayOfWeekWithTimezoneCorrectly() { Document agg = project() .and(DateOperators.dateOf("birthday").withTimezone(Timezone.valueOf("America/Chicago")).isoDayOfWeek()) @@ -1919,7 +1920,7 @@ public void shouldRenderIsoDayOfWeekWithTimezoneCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderIsoWeekCorrectly() { + void shouldRenderIsoWeekCorrectly() { Document agg = project().and(DateOperators.dateOf("date").isoWeek()).as("weekNumber") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1928,7 +1929,7 @@ public void shouldRenderIsoWeekCorrectly() { } @Test // DATAMONGO-1834 - public void shouldRenderIsoWeekWithTimezoneCorrectly() { + void shouldRenderIsoWeekWithTimezoneCorrectly() { Document agg = project() .and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).isoWeek()).as("weekNumber") @@ -1939,7 +1940,7 @@ public void shouldRenderIsoWeekWithTimezoneCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderIsoWeekYearCorrectly() { + void shouldRenderIsoWeekYearCorrectly() { Document agg = project().and(DateOperators.dateOf("date").isoWeekYear()).as("yearNumber") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -1948,7 +1949,7 @@ public void shouldRenderIsoWeekYearCorrectly() { } @Test // DATAMONGO-1834 - public void shouldRenderIsoWeekYearWithTimezoneCorrectly() { + void shouldRenderIsoWeekYearWithTimezoneCorrectly() { Document agg = project() .and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).isoWeekYear()) @@ -1959,7 +1960,7 @@ public void shouldRenderIsoWeekYearWithTimezoneCorrectly() { } @Test // DATAMONGO-1548 - public void shouldRenderSwitchCorrectly() { + void shouldRenderSwitchCorrectly() { String expected = "$switch:\n" + // "{\n" + // @@ -2001,7 +2002,7 @@ public void shouldRenderSwitchCorrectly() { } @Test // DATAMONGO-1548 - public void shouldTypeCorrectly() { + void shouldTypeCorrectly() { Document agg = project().and(DataTypeOperators.Type.typeOf("a")).as("a").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -2009,7 +2010,7 @@ public void shouldTypeCorrectly() { } @Test // DATAMONGO-1834 - public void shouldRenderDateFromPartsWithJustTheYear() { + void shouldRenderDateFromPartsWithJustTheYear() { Document agg = project().and(DateOperators.dateFromParts().year(2018)).as("newDate") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -2018,7 +2019,7 @@ public void shouldRenderDateFromPartsWithJustTheYear() { } @Test // DATAMONGO-1834, DATAMONGO-2671 - public void shouldRenderDateFromParts() { + void shouldRenderDateFromParts() { Document agg = project() .and(DateOperators.dateFromParts().year(2018).month(3).day(23).hour(14).minute(25).second(10).millisecond(2)) @@ -2029,7 +2030,7 @@ public void shouldRenderDateFromParts() { } @Test // DATAMONGO-1834 - public void shouldRenderDateFromPartsWithTimezone() { + void shouldRenderDateFromPartsWithTimezone() { Document agg = project() .and(DateOperators.dateFromParts().withTimezone(Timezone.valueOf("America/Chicago")).year(2018)).as("newDate") @@ -2040,7 +2041,7 @@ public void shouldRenderDateFromPartsWithTimezone() { } @Test // DATAMONGO-1834 - public void shouldRenderIsoDateFromPartsWithJustTheYear() { + void shouldRenderIsoDateFromPartsWithJustTheYear() { Document agg = project().and(DateOperators.dateFromParts().isoWeekYear(2018)).as("newDate") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -2049,7 +2050,7 @@ public void shouldRenderIsoDateFromPartsWithJustTheYear() { } @Test // DATAMONGO-1834, DATAMONGO-2671 - public void shouldRenderIsoDateFromParts() { + void shouldRenderIsoDateFromParts() { Document agg = project().and(DateOperators.dateFromParts().isoWeekYear(2018).isoWeek(12).isoDayOfWeek(5).hour(14) .minute(30).second(42).millisecond(2)).as("newDate").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -2059,7 +2060,7 @@ public void shouldRenderIsoDateFromParts() { } @Test // DATAMONGO-1834 - public void shouldRenderIsoDateFromPartsWithTimezone() { + void shouldRenderIsoDateFromPartsWithTimezone() { Document agg = project() .and(DateOperators.dateFromParts().withTimezone(Timezone.valueOf("America/Chicago")).isoWeekYear(2018)) @@ -2070,7 +2071,7 @@ public void shouldRenderIsoDateFromPartsWithTimezone() { } @Test // DATAMONGO-1834 - public void shouldRenderDateToParts() { + void shouldRenderDateToParts() { Document agg = project().and(DateOperators.dateOf("date").toParts()).as("newDate") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -2079,7 +2080,7 @@ public void shouldRenderDateToParts() { } @Test // DATAMONGO-1834 - public void shouldRenderDateToIsoParts() { + void shouldRenderDateToIsoParts() { Document agg = project().and(DateOperators.dateOf("date").toParts().iso8601()).as("newDate") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -2089,7 +2090,7 @@ public void shouldRenderDateToIsoParts() { } @Test // DATAMONGO-1834 - public void shouldRenderDateToPartsWithTimezone() { + void shouldRenderDateToPartsWithTimezone() { Document agg = project() .and(DateOperators.dateOf("date").withTimezone(Timezone.valueOf("America/Chicago")).toParts()).as("newDate") @@ -2100,7 +2101,7 @@ public void shouldRenderDateToPartsWithTimezone() { } @Test // DATAMONGO-1834 - public void shouldRenderDateFromString() { + void shouldRenderDateFromString() { Document agg = project().and(DateOperators.dateFromString("2017-02-08T12:10:40.787")).as("newDate") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -2110,7 +2111,7 @@ public void shouldRenderDateFromString() { } @Test // DATAMONGO-1834 - public void shouldRenderDateFromStringWithFieldReference() { + void shouldRenderDateFromStringWithFieldReference() { Document agg = project().and(DateOperators.dateOf("date").fromString()).as("newDate") .toDocument(Aggregation.DEFAULT_CONTEXT); @@ -2120,7 +2121,7 @@ public void shouldRenderDateFromStringWithFieldReference() { } @Test // DATAMONGO-1834 - public void shouldRenderDateFromStringWithTimezone() { + void shouldRenderDateFromStringWithTimezone() { Document agg = project() .and(DateOperators.dateFromString("2017-02-08T12:10:40.787").withTimezone(Timezone.valueOf("America/Chicago"))) @@ -2131,7 +2132,7 @@ public void shouldRenderDateFromStringWithTimezone() { } @Test // DATAMONGO-2047 - public void shouldRenderDateFromStringWithFormat() { + void shouldRenderDateFromStringWithFormat() { Document agg = project().and(DateOperators.dateFromString("2017-02-08T12:10:40.787").withFormat("dd/mm/yyyy")) .as("newDate").toDocument(Aggregation.DEFAULT_CONTEXT); @@ -2141,7 +2142,7 @@ public void shouldRenderDateFromStringWithFormat() { } @Test // DATAMONGO-2200 - public void typeProjectionShouldIncludeTopLevelFieldsOfType() { + void typeProjectionShouldIncludeTopLevelFieldsOfType() { ProjectionOperation operation = Aggregation.project(Book.class); @@ -2155,7 +2156,7 @@ public void typeProjectionShouldIncludeTopLevelFieldsOfType() { } @Test // DATAMONGO-2200 - public void typeProjectionShouldMapFieldNames() { + void typeProjectionShouldMapFieldNames() { MongoMappingContext mappingContext = new MongoMappingContext(); MongoConverter converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext); @@ -2171,7 +2172,7 @@ public void typeProjectionShouldMapFieldNames() { } @Test // DATAMONGO-2200 - public void typeProjectionShouldIncludeInterfaceProjectionValues() { + void typeProjectionShouldIncludeInterfaceProjectionValues() { ProjectionOperation operation = Aggregation.project(ProjectionInterface.class); @@ -2184,7 +2185,7 @@ public void typeProjectionShouldIncludeInterfaceProjectionValues() { } @Test // DATAMONGO-2200 - public void typeProjectionShouldBeEmptyIfNoPropertiesFound() { + void typeProjectionShouldBeEmptyIfNoPropertiesFound() { ProjectionOperation operation = Aggregation.project(EmptyType.class); @@ -2195,7 +2196,7 @@ public void typeProjectionShouldBeEmptyIfNoPropertiesFound() { } @Test // DATAMONGO-2312 - public void simpleFieldReferenceAsArray() { + void simpleFieldReferenceAsArray() { org.bson.Document doc = Aggregation.newAggregation(project("x", "y", "someField").asArray("myArray")) .toDocument("coll", Aggregation.DEFAULT_CONTEXT); @@ -2205,7 +2206,7 @@ public void simpleFieldReferenceAsArray() { } @Test // DATAMONGO-2312 - public void mappedFieldReferenceAsArray() { + void mappedFieldReferenceAsArray() { MongoMappingContext mappingContext = new MongoMappingContext(); @@ -2219,7 +2220,7 @@ public void mappedFieldReferenceAsArray() { } @Test // DATAMONGO-2312 - public void arrayWithNullValue() { + void arrayWithNullValue() { Document doc = project() // .andArrayOf(Fields.field("field-1"), null, "value").as("myArray") // @@ -2229,7 +2230,7 @@ public void arrayWithNullValue() { } @Test // DATAMONGO-2312 - public void nestedArrayField() { + void nestedArrayField() { Document doc = project("_id", "value") // .andArrayOf(Fields.field("field-1"), "plain - string", ArithmeticOperators.valueOf("field-1").sum().and(10)) @@ -2241,7 +2242,7 @@ public void nestedArrayField() { } @Test // DATAMONGO-2312 - public void nestedMappedFieldReferenceInArrayField() { + void nestedMappedFieldReferenceInArrayField() { MongoMappingContext mappingContext = new MongoMappingContext(); @@ -2289,7 +2290,7 @@ interface ProjectionInterface { String getTitle(); } - static class EmptyType { + private static class EmptyType { } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java index 41b0323636..e92ea38336 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java @@ -32,6 +32,7 @@ * @author Thomas Darimont * @author Oliver Gierke * @author Christoph Strobl + * @author Divya Srivastava */ public class SpelExpressionTransformerUnitTests { @@ -800,68 +801,68 @@ void shouldRenderRtrimWithCharsFromFieldReference() { assertThat(transform("rtrim(field1, field2)")) .isEqualTo("{ \"$rtrim\" : {\"input\" : \"$field1\", \"chars\" : \"$field2\" }}"); } - - @Test // DATAMONGO-3725 - public void shouldRenderRegexFindWithoutOptions() { - + + @Test // GH-3725 + void shouldRenderRegexFindWithoutOptions() { + assertThat(transform("regexFind(field1,'e')")) - .isEqualTo(Document.parse("{ \"$regexFind\" : {\"input\" : \"$field1\" , \"regex\" : \"e\"}}")); + .isEqualTo("{ \"$regexFind\" : {\"input\" : \"$field1\" , \"regex\" : \"e\"}}"); } - - @Test // DATAMONGO-3725 - public void shouldRenderRegexFindWithOptions() { - + + @Test // GH-3725 + void shouldRenderRegexFindWithOptions() { + assertThat(transform("regexFind(field1,'e','i')")) - .isEqualTo(Document.parse("{ \"$regexFind\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"i\"}}")); + .isEqualTo("{ \"$regexFind\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"i\"}}"); } - - @Test // DATAMONGO-3725 - public void shouldRenderRegexFindWithOptionsFromFieldReference() { - + + @Test // GH-3725 + void shouldRenderRegexFindWithOptionsFromFieldReference() { + assertThat(transform("regexFind(field1,'e',field2)")) - .isEqualTo(Document.parse("{ \"$regexFind\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"$field2\"}}")); + .isEqualTo("{ \"$regexFind\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"$field2\"}}"); } - - @Test // DATAMONGO-3725 - public void shouldRenderRegexFindAllWithoutOptions() { - + + @Test // GH-3725 + void shouldRenderRegexFindAllWithoutOptions() { + assertThat(transform("regexFindAll(field1,'e')")) - .isEqualTo(Document.parse("{ \"$regexFindAll\" : {\"input\" : \"$field1\" , \"regex\" : \"e\"}}")); + .isEqualTo("{ \"$regexFindAll\" : {\"input\" : \"$field1\" , \"regex\" : \"e\"}}"); } - - @Test // DATAMONGO-3725 - public void shouldRenderRegexFindAllWithOptions() { - + + @Test // GH-3725 + void shouldRenderRegexFindAllWithOptions() { + assertThat(transform("regexFindAll(field1,'e','i')")) - .isEqualTo(Document.parse("{ \"$regexFindAll\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"i\"}}")); + .isEqualTo("{ \"$regexFindAll\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"i\"}}"); } - - @Test // DATAMONGO-3725 - public void shouldRenderRegexFindAllWithOptionsFromFieldReference() { - + + @Test // GH-3725 + void shouldRenderRegexFindAllWithOptionsFromFieldReference() { + assertThat(transform("regexFindAll(field1,'e',field2)")) - .isEqualTo(Document.parse("{ \"$regexFindAll\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"$field2\"}}")); + .isEqualTo("{ \"$regexFindAll\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"$field2\"}}"); } - @Test // DATAMONGO-3725 - public void shouldRenderRegexMatchWithoutOptions() { - + @Test // GH-3725 + void shouldRenderRegexMatchWithoutOptions() { + assertThat(transform("regexMatch(field1,'e')")) - .isEqualTo(Document.parse("{ \"$regexMatch\" : {\"input\" : \"$field1\" , \"regex\" : \"e\"}}")); + .isEqualTo("{ \"$regexMatch\" : {\"input\" : \"$field1\" , \"regex\" : \"e\"}}"); } - - @Test // DATAMONGO-3725 - public void shouldRenderRegexMatchWithOptions() { - + + @Test // GH-3725 + void shouldRenderRegexMatchWithOptions() { + assertThat(transform("regexMatch(field1,'e','i')")) - .isEqualTo(Document.parse("{ \"$regexMatch\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"i\"}}")); + .isEqualTo("{ \"$regexMatch\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"i\"}}"); } - - @Test // DATAMONGO-3725 - public void shouldRenderRegexMatchWithOptionsFromFieldReference() { - + + @Test // GH-3725 + void shouldRenderRegexMatchWithOptionsFromFieldReference() { + assertThat(transform("regexMatch(field1,'e',field2)")) - .isEqualTo(Document.parse("{ \"$regexMatch\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"$field2\"}}")); + .isEqualTo("{ \"$regexMatch\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"$field2\"}}"); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/StringOperatorsUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/StringOperatorsUnitTests.java index cdd0b38dbc..d8ba5129e0 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/StringOperatorsUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/StringOperatorsUnitTests.java @@ -15,7 +15,9 @@ */ package org.springframework.data.mongodb.core.aggregation; -import static org.assertj.core.api.Assertions.*; +import static org.springframework.data.mongodb.test.util.Assertions.*; + +import java.util.regex.Pattern; import org.bson.Document; import org.junit.jupiter.api.Test; @@ -25,230 +27,258 @@ * * @author Christoph Strobl * @author Mark Paluch + * @author Divya Srivastava * @currentRead Royal Assassin - Robin Hobb */ -public class StringOperatorsUnitTests { +class StringOperatorsUnitTests { - static final String EXPRESSION_STRING = "{ \"$fitz\" : \"chivalry\" }"; - static final Document EXPRESSION_DOC = Document.parse(EXPRESSION_STRING); - static final AggregationExpression EXPRESSION = context -> EXPRESSION_DOC; + private static final String EXPRESSION_STRING = "{ \"$fitz\" : \"chivalry\" }"; + private static final Document EXPRESSION_DOC = Document.parse(EXPRESSION_STRING); + private static final AggregationExpression EXPRESSION = context -> EXPRESSION_DOC; @Test // DATAMONGO-2049 - public void shouldRenderTrim() { + void shouldRenderTrim() { assertThat(StringOperators.valueOf("shrewd").trim().toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $trim: { \"input\" : \"$shrewd\" } } ")); + .isEqualTo("{ $trim: { \"input\" : \"$shrewd\" } } "); } @Test // DATAMONGO-2049 - public void shouldRenderTrimForExpression() { + void shouldRenderTrimForExpression() { assertThat(StringOperators.valueOf(EXPRESSION).trim().toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $trim: { \"input\" : " + EXPRESSION_STRING + " } } ")); + .isEqualTo("{ $trim: { \"input\" : " + EXPRESSION_STRING + " } } "); } @Test // DATAMONGO-2049 - public void shouldRenderTrimWithChars() { + void shouldRenderTrimWithChars() { assertThat(StringOperators.valueOf("shrewd").trim("sh").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $trim: { \"input\" : \"$shrewd\", \"chars\" : \"sh\" } } ")); + .isEqualTo("{ $trim: { \"input\" : \"$shrewd\", \"chars\" : \"sh\" } } "); } @Test // DATAMONGO-2049 - public void shouldRenderTrimWithCharsExpression() { + void shouldRenderTrimWithCharsExpression() { assertThat(StringOperators.valueOf("shrewd").trim(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $trim: { \"input\" : \"$shrewd\", \"chars\" : " + EXPRESSION_STRING + " } } ")); + .isEqualTo("{ $trim: { \"input\" : \"$shrewd\", \"chars\" : " + EXPRESSION_STRING + " } } "); } @Test // DATAMONGO-2049 - public void shouldRenderTrimLeft() { + void shouldRenderTrimLeft() { assertThat(StringOperators.valueOf("shrewd").trim().left().toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $ltrim: { \"input\" : \"$shrewd\" } } ")); + .isEqualTo("{ $ltrim: { \"input\" : \"$shrewd\" } } "); } @Test // DATAMONGO-2049 - public void shouldRenderTrimLeftWithChars() { + void shouldRenderTrimLeftWithChars() { assertThat(StringOperators.valueOf("shrewd").trim("sh").left().toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $ltrim: { \"input\" : \"$shrewd\", \"chars\" : \"sh\" } } ")); + .isEqualTo("{ $ltrim: { \"input\" : \"$shrewd\", \"chars\" : \"sh\" } } "); } @Test // DATAMONGO-2049 - public void shouldRenderTrimRight() { + void shouldRenderTrimRight() { assertThat(StringOperators.valueOf("shrewd").trim().right().toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $rtrim: { \"input\" : \"$shrewd\" } } ")); + .isEqualTo("{ $rtrim: { \"input\" : \"$shrewd\" } } "); } @Test // DATAMONGO-2049 - public void shouldRenderTrimRightWithChars() { + void shouldRenderTrimRightWithChars() { assertThat(StringOperators.valueOf("shrewd").trim("sh").right().toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $rtrim: { \"input\" : \"$shrewd\", \"chars\" : \"sh\" } } ")); + .isEqualTo("{ $rtrim: { \"input\" : \"$shrewd\", \"chars\" : \"sh\" } } "); } @Test // DATAMONGO-2049 - public void shouldRenderLTrim() { + void shouldRenderLTrim() { assertThat(StringOperators.valueOf("shrewd").ltrim().toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $ltrim: { \"input\" : \"$shrewd\" } } ")); + .isEqualTo("{ $ltrim: { \"input\" : \"$shrewd\" } } "); } @Test // DATAMONGO-2049 - public void shouldRenderLTrimForExpression() { + void shouldRenderLTrimForExpression() { assertThat(StringOperators.valueOf(EXPRESSION).ltrim().toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $ltrim: { \"input\" : " + EXPRESSION_STRING + " } } ")); + .isEqualTo("{ $ltrim: { \"input\" : " + EXPRESSION_STRING + " } } "); } @Test // DATAMONGO-2049 - public void shouldRenderLTrimWithChars() { + void shouldRenderLTrimWithChars() { assertThat(StringOperators.valueOf("shrewd").ltrim("sh").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $ltrim: { \"input\" : \"$shrewd\", \"chars\" : \"sh\" } } ")); + .isEqualTo("{ $ltrim: { \"input\" : \"$shrewd\", \"chars\" : \"sh\" } } "); } @Test // DATAMONGO-2049 - public void shouldRenderLTrimWithCharsExpression() { + void shouldRenderLTrimWithCharsExpression() { assertThat(StringOperators.valueOf("shrewd").ltrim(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $ltrim: { \"input\" : \"$shrewd\", \"chars\" : " + EXPRESSION_STRING + " } } ")); + .isEqualTo("{ $ltrim: { \"input\" : \"$shrewd\", \"chars\" : " + EXPRESSION_STRING + " } } "); } @Test // DATAMONGO-2049 - public void shouldRenderRTrim() { + void shouldRenderRTrim() { assertThat(StringOperators.valueOf("shrewd").rtrim().toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $rtrim: { \"input\" : \"$shrewd\" } } ")); + .isEqualTo("{ $rtrim: { \"input\" : \"$shrewd\" } } "); } @Test // DATAMONGO-2049 - public void shouldRenderRTrimForExpression() { + void shouldRenderRTrimForExpression() { assertThat(StringOperators.valueOf(EXPRESSION).rtrim().toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $rtrim: { \"input\" : " + EXPRESSION_STRING + " } } ")); + .isEqualTo("{ $rtrim: { \"input\" : " + EXPRESSION_STRING + " } } "); } @Test // DATAMONGO-2049 - public void shouldRenderRTrimWithChars() { + void shouldRenderRTrimWithChars() { assertThat(StringOperators.valueOf("shrewd").rtrim("sh").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $rtrim: { \"input\" : \"$shrewd\", \"chars\" : \"sh\" } } ")); + .isEqualTo("{ $rtrim: { \"input\" : \"$shrewd\", \"chars\" : \"sh\" } } "); } @Test // DATAMONGO-2049 - public void shouldRenderRTrimWithCharsExpression() { + void shouldRenderRTrimWithCharsExpression() { assertThat(StringOperators.valueOf("shrewd").rtrim(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $rtrim: { \"input\" : \"$shrewd\", \"chars\" : " + EXPRESSION_STRING + " } } ")); + .isEqualTo("{ $rtrim: { \"input\" : \"$shrewd\", \"chars\" : " + EXPRESSION_STRING + " } } "); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFindAll() { + + @Test // GH-3725 + void shouldRenderRegexFindAll() { assertThat(StringOperators.valueOf("shrewd").regexFindAll("e").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexFindAll: { \"input\" : \"$shrewd\" , \"regex\" : \"e\" } }")); + .isEqualTo("{ $regexFindAll: { \"input\" : \"$shrewd\" , \"regex\" : \"e\" } }"); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFindAllForExpression() { + + @Test // GH-3725 + void shouldRenderRegexFindAllForExpression() { assertThat(StringOperators.valueOf(EXPRESSION).regexFindAll("e").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexFindAll: { \"input\" : " + EXPRESSION_STRING + " , \"regex\" : \"e\" } } ")); + .isEqualTo("{ $regexFindAll: { \"input\" : " + EXPRESSION_STRING + " , \"regex\" : \"e\" } } "); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFindAllForRegexExpression() { + + @Test // GH-3725 + void shouldRenderRegexFindAllForRegexExpression() { assertThat(StringOperators.valueOf("shrewd").regexFindAll(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexFindAll: { \"input\" : \"$shrewd\" , \"regex\" : " + EXPRESSION_STRING + " } } ")); + .isEqualTo("{ $regexFindAll: { \"input\" : \"$shrewd\" , \"regex\" : " + EXPRESSION_STRING + " } } "); + } + + @Test // GH-3725 + void shouldRenderRegexFindAllWithPattern() { + + assertThat(StringOperators.valueOf("shrewd") + .regexFindAll( + Pattern.compile("foo", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL | Pattern.COMMENTS)) + .toDocument(Aggregation.DEFAULT_CONTEXT)) + .isEqualTo("{ $regexFindAll: { \"input\" : \"$shrewd\", \"regex\" : \"foo\" , \"options\" : \"imsx\" } } "); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFindAllWithOptions() { + + @Test // GH-3725 + void shouldRenderRegexFindAllWithOptions() { assertThat(StringOperators.valueOf("shrewd").regexFindAll("e").options("i").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexFindAll: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : \"i\" } } ")); + .isEqualTo("{ $regexFindAll: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : \"i\" } } "); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFindAllWithOptionsExpression() { + + @Test // GH-3725 + void shouldRenderRegexFindAllWithOptionsExpression() { assertThat(StringOperators.valueOf("shrewd").regexFindAll("e").optionsOf(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexFindAll: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : " + EXPRESSION_STRING + " } } ")); + .isEqualTo("{ $regexFindAll: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : " + EXPRESSION_STRING + + " } } "); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexMatch() { + + @Test // GH-3725 + void shouldRenderRegexMatch() { assertThat(StringOperators.valueOf("shrewd").regexMatch("e").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexMatch: { \"input\" : \"$shrewd\" , \"regex\" : \"e\" } }")); + .isEqualTo("{ $regexMatch: { \"input\" : \"$shrewd\" , \"regex\" : \"e\" } }"); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexMatchForExpression() { + + @Test // GH-3725 + void shouldRenderRegexMatchForExpression() { assertThat(StringOperators.valueOf(EXPRESSION).regexMatch("e").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexMatch: { \"input\" : " + EXPRESSION_STRING + " , \"regex\" : \"e\" } } ")); + .isEqualTo("{ $regexMatch: { \"input\" : " + EXPRESSION_STRING + " , \"regex\" : \"e\" } } "); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexMatchForRegexExpression() { + + @Test // GH-3725 + void shouldRenderRegexMatchForRegexExpression() { assertThat(StringOperators.valueOf("shrewd").regexMatch(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexMatch: { \"input\" : \"$shrewd\" , \"regex\" : " + EXPRESSION_STRING + " } } ")); + .isEqualTo("{ $regexMatch: { \"input\" : \"$shrewd\" , \"regex\" : " + EXPRESSION_STRING + " } } "); + } + + @Test // GH-3725 + void shouldRenderRegexMatchForPattern() { + + assertThat(StringOperators.valueOf("shrewd").regexMatch(Pattern.compile("foo", Pattern.CASE_INSENSITIVE)) + .toDocument(Aggregation.DEFAULT_CONTEXT)) + .isEqualTo("{ $regexMatch: { \"input\" : \"$shrewd\" , \"regex\" : \"foo\", \"options\" : \"i\"} } "); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexMatchWithOptions() { + + @Test // GH-3725 + void shouldRenderRegexMatchWithOptions() { assertThat(StringOperators.valueOf("shrewd").regexMatch("e").options("i").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexMatch: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : \"i\" } } ")); + .isEqualTo("{ $regexMatch: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : \"i\" } } "); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexMatchWithOptionsExpression() { + + @Test // GH-3725 + void shouldRenderRegexMatchWithOptionsExpression() { assertThat(StringOperators.valueOf("shrewd").regexMatch("e").optionsOf(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexMatch: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : " + EXPRESSION_STRING + " } } ")); + .isEqualTo("{ $regexMatch: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : " + EXPRESSION_STRING + + " } } "); } - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFind() { + @Test // GH-3725 + void shouldRenderRegexFind() { assertThat(StringOperators.valueOf("shrewd").regexFind("e").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexFind: { \"input\" : \"$shrewd\" , \"regex\" : \"e\" } }")); + .isEqualTo("{ $regexFind: { \"input\" : \"$shrewd\" , \"regex\" : \"e\" } }"); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFindForExpression() { + + @Test // GH-3725 + void shouldRenderRegexFindForExpression() { assertThat(StringOperators.valueOf(EXPRESSION).regexFind("e").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexFind: { \"input\" : " + EXPRESSION_STRING + " , \"regex\" : \"e\" } } ")); + .isEqualTo("{ $regexFind: { \"input\" : " + EXPRESSION_STRING + " , \"regex\" : \"e\" } } "); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFindForRegexExpression() { + + @Test // GH-3725 + void shouldRenderRegexFindForRegexExpression() { assertThat(StringOperators.valueOf("shrewd").regexFind(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexFind: { \"input\" : \"$shrewd\" , \"regex\" : " + EXPRESSION_STRING + " } } ")); + .isEqualTo("{ $regexFind: { \"input\" : \"$shrewd\" , \"regex\" : " + EXPRESSION_STRING + " } } "); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFindWithOptions() { - assertThat(StringOperators.valueOf("shrewd").regexFind("e").options("i").toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexFind: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : \"i\" } } ")); + @Test // GH-3725 + void shouldRenderRegexFindForPattern() { + + assertThat(StringOperators.valueOf("shrewd").regexFind(Pattern.compile("foo", Pattern.MULTILINE)) + .toDocument(Aggregation.DEFAULT_CONTEXT)) + .isEqualTo("{ $regexFind: { \"input\" : \"$shrewd\" , \"regex\" : \"foo\", \"options\" : \"m\"} } "); } - - @Test // DATAMONGO - 3725 - public void shouldRenderRegexFindWithOptionsExpression() { - assertThat(StringOperators.valueOf("shrewd").regexFind("e").optionsOf(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT)) - .isEqualTo(Document.parse("{ $regexFind: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : " + EXPRESSION_STRING + " } } ")); + @Test // GH-3725 + void shouldRenderRegexFindWithOptions() { + + assertThat(StringOperators.valueOf("shrewd").regexFind("e").options("i").toDocument(Aggregation.DEFAULT_CONTEXT)) + .isEqualTo("{ $regexFind: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : \"i\" } } "); } + @Test // GH-3725 + void shouldRenderRegexFindWithOptionsExpression() { + assertThat(StringOperators.valueOf("shrewd").regexFind("e").optionsOf(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT)) + .isEqualTo("{ $regexFind: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : " + EXPRESSION_STRING + + " } } "); + } } diff --git a/src/main/asciidoc/reference/aggregation-framework.adoc b/src/main/asciidoc/reference/aggregation-framework.adoc index f96719adde..75ed415096 100644 --- a/src/main/asciidoc/reference/aggregation-framework.adoc +++ b/src/main/asciidoc/reference/aggregation-framework.adoc @@ -88,7 +88,7 @@ At the time of this writing, we provide support for the following Aggregation Op | `abs`, `add` (+++*+++ via `plus`), `ceil`, `cos`, `cosh`, `derivative`, `divide`, `exp`, `floor`, `integral`, `ln`, `log`, `log10`, `mod`, `multiply`, `pow`, `round`, `sqrt`, `subtract` (+++*+++ via `minus`), `sin`, `sinh`, `tan`, `tanh`, `trunc` | String Aggregation Operators -| `concat`, `substr`, `toLower`, `toUpper`, `strcasecmp`, `indexOfBytes`, `indexOfCP`, `split`, `strLenBytes`, `strLenCP`, `substrCP`, `trim`, `ltrim`, `rtim` +| `concat`, `substr`, `toLower`, `toUpper`, `strcasecmp`, `indexOfBytes`, `indexOfCP`, `regexFind`, `regexFindAll`, `regexMatch`, `split`, `strLenBytes`, `strLenCP`, `substrCP`, `trim`, `ltrim`, `rtim` | Comparison Aggregation Operators | `eq` (+++*+++ via `is`), `gt`, `gte`, `lt`, `lte`, `ne` From 2d8d66db9790b89caff713bc75201cbfcaad2bee Mon Sep 17 00:00:00 2001 From: divya srivastava Date: Sun, 29 Aug 2021 19:07:14 +0530 Subject: [PATCH 2/3] taking latest from main. --- .../springframework/data/mongodb/util/RegexFlags.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/RegexFlags.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/RegexFlags.java index beaa4f2f8b..ba6531e93c 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/RegexFlags.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/RegexFlags.java @@ -17,6 +17,8 @@ import java.util.regex.Pattern; +import org.springframework.lang.Nullable; + /** * Utility to translate {@link Pattern#flags() regex flags} to MongoDB regex options and vice versa. * @@ -78,10 +80,14 @@ public static String toRegexOptions(int flags) { * @return zero if given {@link String} is {@literal null} or empty. * @since 2.2 */ - public static int toRegexFlags(String s) { + public static int toRegexFlags(@Nullable String s) { int flags = 0; + if (s == null) { + return flags; + } + for (char f : s.toLowerCase().toCharArray()) { flags |= toRegexFlag(f); } @@ -107,4 +113,4 @@ public static int toRegexFlag(char c) { return flag; } -} +} \ No newline at end of file From f5c13328fc69f3a6dd6047b1eed61b91b648c4ae Mon Sep 17 00:00:00 2001 From: divyajnu08 Date: Wed, 1 Sep 2021 13:02:43 +0530 Subject: [PATCH 3/3] DATAMONGO-3708 - Add support for $asin & $asinh aggregation operators. --- .../core/aggregation/ArithmeticOperators.java | 116 ++++++++++++++++++ .../core/spel/MethodReferenceNode.java | 2 + .../ArithmeticOperatorsUnitTests.java | 14 +++ .../SpelExpressionTransformerUnitTests.java | 10 ++ 4 files changed, 142 insertions(+) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperators.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperators.java index 8fe3d9120c..15301bc737 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperators.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperators.java @@ -735,6 +735,24 @@ public Sinh sinh(AngularUnit unit) { return usesFieldRef() ? Sinh.sinhOf(fieldReference, unit) : Sinh.sinhOf(expression, unit); } + /** + * Creates new {@link AggregationExpression} that calculates the inverse sine of a numeric value. + * + * @return new instance of {@link ASin}. + */ + public ASin asin() { + return usesFieldRef() ? ASin.asinOf(fieldReference) : ASin.asinOf(expression); + } + + /** + * Creates new {@link AggregationExpression} that calculates the inverse hyperbolic sine of a numeric value. + * + * @return new instance of {@link ASinh}. + */ + public ASinh asinh() { + return usesFieldRef() ? ASinh.asinhOf(fieldReference) : ASinh.asinhOf(expression); + } + /** * Creates new {@link AggregationExpression} that calculates the cosine of a numeric value given in * {@link AngularUnit#RADIANS radians}. @@ -2272,6 +2290,104 @@ protected String getMongoMethod() { return "$sinh"; } } + + /** + * An {@link AggregationExpression expression} that calculates the inverse sine of a value. + * + */ + public static class ASin extends AbstractAggregationExpression { + + private ASin(Object value) { + super(value); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse sine of a value. + * + * @param fieldReference the name of the {@link Field field} that resolves to a numeric value. + * @return new instance of {@link ASin}. + */ + public static ASin asinOf(String fieldReference) { + + Assert.notNull(fieldReference, "FieldReference must not be null!"); + return new ASin(Fields.field(fieldReference)); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse sine of a value. + *

+ * + * @param expression the {@link AggregationExpression expression} that resolves to a numeric value. + * @return new instance of {@link ASin}. + */ + public static ASin asinOf(AggregationExpression expression) { + return new ASin(expression); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse sine of a value. + * + * @param value anything ({@link Field field}, {@link AggregationExpression expression}, ...) that resolves to a + * numeric value. + * @return new instance of {@link ASin}. + */ + public static ASin asinOf(Number value) { + return new ASin(value); + } + + @Override + protected String getMongoMethod() { + return "$asin"; + } + } + + /** + * An {@link AggregationExpression expression} that calculates the inverse hyperbolic sine of a value + */ + public static class ASinh extends AbstractAggregationExpression { + + private ASinh(Object value) { + super(value); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse hyperbolic sine of a value. + * + * @param fieldReference the name of the {@link Field field} that resolves to a numeric value. + * @return new instance of {@link ASinh}. + */ + public static ASinh asinhOf(String fieldReference) { + return new ASinh(Fields.field(fieldReference)); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse hyperbolic sine of a value. + *

+ * + * @param expression the {@link AggregationExpression expression} that resolves to a numeric value. + * @return new instance of {@link ASinh}. + */ + public static ASinh asinhOf(AggregationExpression expression) { + return new ASinh(expression); + } + + /** + * Creates a new {@link AggregationExpression} that calculates the inverse hyperbolic sine of a value. + * + * @param value anything ({@link Field field}, {@link AggregationExpression expression}, ...) that resolves to a + * numeric value. + * @return new instance of {@link ASinh}. + */ + public static ASinh asinhOf(Object value) { + return new ASinh(value); + } + + @Override + protected String getMongoMethod() { + return "$asinh"; + } + } + /** * An {@link AggregationExpression expression} that calculates the cosine of a value that is measured in radians. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/MethodReferenceNode.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/MethodReferenceNode.java index 0fbfe51f09..1b4b74b1a3 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/MethodReferenceNode.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/MethodReferenceNode.java @@ -95,6 +95,8 @@ public class MethodReferenceNode extends ExpressionNode { map.put("integral", mapArgRef().forOperator("$integral").mappingParametersTo("input", "unit")); map.put("sin", singleArgRef().forOperator("$sin")); map.put("sinh", singleArgRef().forOperator("$sinh")); + map.put("asin", singleArgRef().forOperator("$asin")); + map.put("asinh", singleArgRef().forOperator("$asinh")); map.put("cos", singleArgRef().forOperator("$cos")); map.put("cosh", singleArgRef().forOperator("$cosh")); map.put("tan", singleArgRef().forOperator("$tan")); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperatorsUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperatorsUnitTests.java index 02f76d5c10..5bf857d5f3 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperatorsUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ArithmeticOperatorsUnitTests.java @@ -110,6 +110,20 @@ void rendersSinhWithValueInDegrees() { assertThat(valueOf("angle").sinh(AngularUnit.DEGREES).toDocument(Aggregation.DEFAULT_CONTEXT)) .isEqualTo("{ $sinh : { $degreesToRadians : \"$angle\" } }"); } + + @Test // DATAMONGO - 3708 + void rendersASin() { + + assertThat(valueOf("field").asin().toDocument(Aggregation.DEFAULT_CONTEXT)) + .isEqualTo("{ $asin : \"$field\" }"); + } + + @Test // DATAMONGO - 3708 + void rendersASinh() { + + assertThat(valueOf("field").asinh().toDocument(Aggregation.DEFAULT_CONTEXT)) + .isEqualTo("{ $asinh : \"$field\" }"); + } @Test // GH-3710 void rendersCos() { diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java index e92ea38336..3c72d62eef 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java @@ -1078,6 +1078,16 @@ void shouldRenderSin() { void shouldRenderSinh() { assertThat(transform("sinh(angle)")).isEqualTo("{ \"$sinh\" : \"$angle\"}"); } + + @Test // DATAMONGO-3708 + void shouldRenderASin() { + assertThat(transform("asin(number)")).isEqualTo("{ \"$asin\" : \"$number\"}"); + } + + @Test // DATAMONGO-3708 + void shouldRenderASinh() { + assertThat(transform("asinh(number)")).isEqualTo("{ \"$asinh\" : \"$number\"}"); + } @Test // GH-3710 void shouldRenderCos() {