|
15 | 15 | */
|
16 | 16 | package org.springframework.data.mongodb.repository.support;
|
17 | 17 |
|
18 |
| -import static org.hamcrest.Matchers.*; |
19 |
| -import static org.junit.Assert.*; |
20 |
| -import static org.springframework.data.mongodb.core.DocumentTestUtils.*; |
21 |
| - |
22 |
| -import java.util.ArrayList; |
23 |
| -import java.util.Collections; |
24 |
| -import java.util.List; |
25 |
| - |
| 18 | +import com.querydsl.core.types.Ops; |
| 19 | +import com.querydsl.core.types.PredicateOperation; |
| 20 | +import com.querydsl.core.types.dsl.*; |
26 | 21 | import org.bson.Document;
|
27 | 22 | import org.bson.types.ObjectId;
|
28 |
| -import org.hamcrest.collection.IsIterableContainingInOrder; |
29 | 23 | import org.junit.Before;
|
30 | 24 | import org.junit.Test;
|
31 | 25 | import org.junit.runner.RunWith;
|
|
43 | 37 | import org.springframework.data.mongodb.repository.QAddress;
|
44 | 38 | import org.springframework.data.mongodb.repository.QPerson;
|
45 | 39 |
|
46 |
| -import com.querydsl.core.types.dsl.BooleanExpression; |
47 |
| -import com.querydsl.core.types.dsl.BooleanOperation; |
48 |
| -import com.querydsl.core.types.dsl.PathBuilder; |
49 |
| -import com.querydsl.core.types.dsl.SimplePath; |
50 |
| -import com.querydsl.core.types.dsl.StringPath; |
| 40 | +import java.util.Collections; |
| 41 | + |
| 42 | +import static com.querydsl.core.types.ExpressionUtils.path; |
| 43 | +import static com.querydsl.core.types.ExpressionUtils.predicate; |
| 44 | +import static com.querydsl.core.types.dsl.Expressions.constant; |
| 45 | +import static org.hamcrest.Matchers.*; |
| 46 | +import static org.junit.Assert.assertThat; |
51 | 47 |
|
52 | 48 | /**
|
53 | 49 | * Unit tests for {@link SpringDataMongodbSerializer}.
|
54 | 50 | *
|
55 | 51 | * @author Oliver Gierke
|
56 | 52 | * @author Christoph Strobl
|
57 | 53 | * @author Mark Paluch
|
| 54 | + * @author Mikhail Kaduchka |
58 | 55 | */
|
59 | 56 | @RunWith(MockitoJUnitRunner.class)
|
60 | 57 | public class SpringDataMongodbSerializerUnitTests {
|
@@ -163,6 +160,23 @@ public void shouldRemarshallListsAndDocuments() {
|
163 | 160 | + "\"$ne\" : \"\"}}} , { \"firstname\" : { \"$not\" : { \"$regex\" : \".*\\\\Qfoo\\\\E.*\" , \"$options\" : \"i\"}}}]}"))));
|
164 | 161 | }
|
165 | 162 |
|
| 163 | + @Test // DATAMONGO-2228 |
| 164 | + public void retainsOpsInAndExpression() { |
| 165 | + |
| 166 | + PredicateOperation testExpression = predicate(Ops.AND, |
| 167 | + predicate(Ops.OR, |
| 168 | + predicate(Ops.EQ, path(Object.class, "firstname"), constant("John")), |
| 169 | + predicate(Ops.EQ, path(Object.class, "firstname"), constant("Sarah"))), |
| 170 | + predicate(Ops.OR, |
| 171 | + predicate(Ops.EQ, path(Object.class, "lastname"), constant("Smith")), |
| 172 | + predicate(Ops.EQ, path(Object.class, "lastname"), constant("Connor"))) |
| 173 | + ); |
| 174 | + |
| 175 | + Document result = (Document) serializer.visit(testExpression, null); |
| 176 | + |
| 177 | + assertThat(result.toJson(), is("{\"$and\": [{\"$or\": [{\"firstname\": \"John\"}, {\"firstname\": \"Sarah\"}]}, {\"$or\": [{\"lastname\": \"Smith\"}, {\"lastname\": \"Connor\"}]}]}")); |
| 178 | + } |
| 179 | + |
166 | 180 | class Address {
|
167 | 181 | String id;
|
168 | 182 | String street;
|
|
0 commit comments