|
41 | 41 | import org.springframework.data.mongodb.core.DBObjectTestUtils;
|
42 | 42 | import org.springframework.data.mongodb.core.mapping.Field;
|
43 | 43 | import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
| 44 | +import org.springframework.data.mongodb.core.query.Criteria; |
| 45 | +import org.springframework.data.mongodb.core.query.Query; |
44 | 46 | import org.springframework.data.mongodb.core.query.Update;
|
45 | 47 |
|
46 | 48 | import com.mongodb.BasicDBList;
|
47 | 49 | import com.mongodb.BasicDBObject;
|
| 50 | +import com.mongodb.BasicDBObjectBuilder; |
48 | 51 | import com.mongodb.DBObject;
|
49 | 52 | import com.mongodb.DBRef;
|
50 | 53 |
|
@@ -471,6 +474,40 @@ public void updateOnDbrefPropertyOfInterfaceTypeWithoutExplicitGetterForIdShould
|
471 | 474 | assertThat(model, allOf(instanceOf(DBRef.class), IsEqual.<Object> equalTo(expectedDBRef)));
|
472 | 475 | }
|
473 | 476 |
|
| 477 | + /** |
| 478 | + * @see DATAMONGO-847 |
| 479 | + */ |
| 480 | + @Test |
| 481 | + public void updateMapperConvertsNestedQueryCorrectly() { |
| 482 | + |
| 483 | + Update update = new Update().pull("list", Query.query(Criteria.where("value").in("foo", "bar"))); |
| 484 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 485 | + context.getPersistentEntity(ParentClass.class)); |
| 486 | + |
| 487 | + DBObject $pull = DBObjectTestUtils.getAsDBObject(mappedUpdate, "$pull"); |
| 488 | + DBObject list = DBObjectTestUtils.getAsDBObject($pull, "aliased"); |
| 489 | + DBObject value = DBObjectTestUtils.getAsDBObject(list, "value"); |
| 490 | + BasicDBList $in = DBObjectTestUtils.getAsDBList(value, "$in"); |
| 491 | + |
| 492 | + assertThat($in, IsIterableContainingInOrder.<Object> contains("foo", "bar")); |
| 493 | + } |
| 494 | + |
| 495 | + /** |
| 496 | + * @see DATAMONGO-847 |
| 497 | + */ |
| 498 | + @Test |
| 499 | + public void updateMapperConvertsPullWithNestedQuerfyOnDBRefCorrectly() { |
| 500 | + |
| 501 | + Update update = new Update().pull("dbRefAnnotatedList", Query.query(Criteria.where("id").is("1"))); |
| 502 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 503 | + context.getPersistentEntity(DocumentWithDBRefCollection.class)); |
| 504 | + |
| 505 | + DBObject $pull = DBObjectTestUtils.getAsDBObject(mappedUpdate, "$pull"); |
| 506 | + DBObject list = DBObjectTestUtils.getAsDBObject($pull, "dbRefAnnotatedList"); |
| 507 | + |
| 508 | + assertThat(list, equalTo(new BasicDBObjectBuilder().add("_id", "1").get())); |
| 509 | + } |
| 510 | + |
474 | 511 | @org.springframework.data.mongodb.core.mapping.Document(collection = "DocumentWithReferenceToInterface")
|
475 | 512 | static interface DocumentWithReferenceToInterface {
|
476 | 513 |
|
|
0 commit comments