|
15 | 15 | */
|
16 | 16 | package org.springframework.data.mongodb.repository.support;
|
17 | 17 |
|
| 18 | +import static com.querydsl.core.types.ExpressionUtils.path; |
| 19 | +import static com.querydsl.core.types.ExpressionUtils.predicate; |
| 20 | +import static com.querydsl.core.types.dsl.Expressions.*; |
18 | 21 | import static org.hamcrest.Matchers.*;
|
19 | 22 | import static org.junit.Assert.*;
|
20 |
| -import static org.springframework.data.mongodb.core.DocumentTestUtils.*; |
21 | 23 |
|
22 |
| -import java.util.ArrayList; |
23 | 24 | import java.util.Collections;
|
24 |
| -import java.util.List; |
25 | 25 |
|
26 | 26 | import org.bson.Document;
|
27 | 27 | import org.bson.types.ObjectId;
|
28 |
| -import org.hamcrest.collection.IsIterableContainingInOrder; |
29 | 28 | import org.junit.Before;
|
30 | 29 | import org.junit.Test;
|
31 | 30 | import org.junit.runner.RunWith;
|
|
43 | 42 | import org.springframework.data.mongodb.repository.QAddress;
|
44 | 43 | import org.springframework.data.mongodb.repository.QPerson;
|
45 | 44 |
|
| 45 | +import com.querydsl.core.types.Ops; |
| 46 | +import com.querydsl.core.types.PredicateOperation; |
46 | 47 | import com.querydsl.core.types.dsl.BooleanExpression;
|
47 | 48 | import com.querydsl.core.types.dsl.BooleanOperation;
|
48 | 49 | import com.querydsl.core.types.dsl.PathBuilder;
|
|
55 | 56 | * @author Oliver Gierke
|
56 | 57 | * @author Christoph Strobl
|
57 | 58 | * @author Mark Paluch
|
| 59 | + * @author Mikhail Kaduchka |
58 | 60 | */
|
59 | 61 | @RunWith(MockitoJUnitRunner.class)
|
60 | 62 | public class SpringDataMongodbSerializerUnitTests {
|
@@ -192,6 +194,21 @@ public void shouldRemarshallListsAndDocuments() {
|
192 | 194 | + "\"$ne\" : \"\"}}} , { \"firstname\" : { \"$not\" : { \"$regex\" : \".*\\\\Qfoo\\\\E.*\" , \"$options\" : \"i\"}}}]}"))));
|
193 | 195 | }
|
194 | 196 |
|
| 197 | + @Test // DATAMONGO-2228 |
| 198 | + public void retainsOpsInAndExpression() { |
| 199 | + |
| 200 | + PredicateOperation testExpression = predicate(Ops.AND, |
| 201 | + predicate(Ops.OR, predicate(Ops.EQ, path(Object.class, "firstname"), constant("John")), |
| 202 | + predicate(Ops.EQ, path(Object.class, "firstname"), constant("Sarah"))), |
| 203 | + predicate(Ops.OR, predicate(Ops.EQ, path(Object.class, "lastname"), constant("Smith")), |
| 204 | + predicate(Ops.EQ, path(Object.class, "lastname"), constant("Connor")))); |
| 205 | + |
| 206 | + Document result = (Document) serializer.visit(testExpression, null); |
| 207 | + |
| 208 | + assertThat(result.toJson(), is( |
| 209 | + "{\"$and\": [{\"$or\": [{\"firstname\": \"John\"}, {\"firstname\": \"Sarah\"}]}, {\"$or\": [{\"lastname\": \"Smith\"}, {\"lastname\": \"Connor\"}]}]}")); |
| 210 | + } |
| 211 | + |
195 | 212 | class Address {
|
196 | 213 | String id;
|
197 | 214 | String street;
|
|
0 commit comments