|
20 | 20 | import java.util.Arrays;
|
21 | 21 | import java.util.Collection;
|
22 | 22 | import java.util.Collections;
|
| 23 | +import java.util.regex.Pattern; |
23 | 24 |
|
| 25 | +import org.bson.BsonRegularExpression; |
24 | 26 | import org.bson.Document;
|
25 | 27 | import org.junit.Test;
|
26 | 28 | import org.springframework.data.geo.Point;
|
@@ -50,6 +52,44 @@ public void testSimpleCriteria() {
|
50 | 52 | assertThat(c.getCriteriaObject()).isEqualTo("{ \"name\" : \"Bubba\"}");
|
51 | 53 | }
|
52 | 54 |
|
| 55 | + @Test // GH-4850 |
| 56 | + public void testCombiningSimpleCriteria() { |
| 57 | + |
| 58 | + Document expected = Document.parse("{ name : { $eq : 123, $type : ['long'] } }"); |
| 59 | + |
| 60 | + Criteria c = Criteria.where("name") // |
| 61 | + .is(123) // |
| 62 | + .type(Type.INT_64); |
| 63 | + |
| 64 | + assertThat(c.getCriteriaObject()).isEqualTo(expected); |
| 65 | + |
| 66 | + c = Criteria.where("name") // |
| 67 | + .type(Type.INT_64) |
| 68 | + .is(123); |
| 69 | + |
| 70 | + assertThat(c.getCriteriaObject()).isEqualTo(expected); |
| 71 | + } |
| 72 | + |
| 73 | + @Test // GH-4850 |
| 74 | + public void testCombiningBsonRegexCriteria() { |
| 75 | + |
| 76 | + Criteria c = Criteria.where("name") |
| 77 | + .regex(new BsonRegularExpression("^spring$")) |
| 78 | + .type(Type.INT_64); |
| 79 | + |
| 80 | + assertThat(c.getCriteriaObject()).isEqualTo(Document.parse("{ name : { $regex : RegExp('^spring$'), $type : ['long'] } }")); |
| 81 | + } |
| 82 | + |
| 83 | + @Test // GH-4850 |
| 84 | + public void testCombiningRegexCriteria() { |
| 85 | + |
| 86 | + Criteria c = Criteria.where("name") |
| 87 | + .regex("^spring$") |
| 88 | + .type(Type.INT_64); |
| 89 | + |
| 90 | + assertThat(c.getCriteriaObject()).hasEntrySatisfying("name.$regex", it -> assertThat(it).isInstanceOf(Pattern.class)); |
| 91 | + } |
| 92 | + |
53 | 93 | @Test
|
54 | 94 | public void testNotEqualCriteria() {
|
55 | 95 | Criteria c = new Criteria("name").ne("Bubba");
|
|
0 commit comments