|
25 | 25 | import java.util.Arrays;
|
26 | 26 | import java.util.Collections;
|
27 | 27 | import java.util.List;
|
| 28 | +import java.util.Map; |
28 | 29 |
|
29 | 30 | import org.hamcrest.Matcher;
|
30 | 31 | import org.hamcrest.collection.IsIterableContainingInOrder;
|
@@ -610,8 +611,85 @@ public void mappingShouldRetainTypeInformationOfNestedListWhenUpdatingConcreteyP
|
610 | 611 | context.getPersistentEntity(DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes.class));
|
611 | 612 |
|
612 | 613 | assertThat(mappedUpdate, isBsonObject().notContaining("$set.concreteTypeWithListAttributeOfInterfaceType._class"));
|
613 |
| - assertThat(mappedUpdate, isBsonObject() |
614 |
| - .containing("$set.concreteTypeWithListAttributeOfInterfaceType.models.[0]._class", ModelImpl.class.getName())); |
| 614 | + assertThat( |
| 615 | + mappedUpdate, |
| 616 | + isBsonObject().containing("$set.concreteTypeWithListAttributeOfInterfaceType.models.[0]._class", |
| 617 | + ModelImpl.class.getName())); |
| 618 | + } |
| 619 | + |
| 620 | + /** |
| 621 | + * @see DATAMONGO-1236 |
| 622 | + */ |
| 623 | + @Test |
| 624 | + public void mappingShouldRetainTypeInformationForObjectValues() { |
| 625 | + |
| 626 | + Update update = new Update().set("value", new NestedDocument("kaladin")); |
| 627 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 628 | + context.getPersistentEntity(EntityWithObject.class)); |
| 629 | + |
| 630 | + assertThat(mappedUpdate, isBsonObject().containing("$set.value.name", "kaladin")); |
| 631 | + assertThat(mappedUpdate, isBsonObject().containing("$set.value._class", NestedDocument.class.getName())); |
| 632 | + } |
| 633 | + |
| 634 | + /** |
| 635 | + * @see DATAMONGO-1236 |
| 636 | + */ |
| 637 | + @Test |
| 638 | + public void mappingShouldNotRetainTypeInformationForConcreteValues() { |
| 639 | + |
| 640 | + Update update = new Update().set("concreteValue", new NestedDocument("shallan")); |
| 641 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 642 | + context.getPersistentEntity(EntityWithObject.class)); |
| 643 | + |
| 644 | + assertThat(mappedUpdate, isBsonObject().containing("$set.concreteValue.name", "shallan")); |
| 645 | + assertThat(mappedUpdate, isBsonObject().notContaining("$set.concreteValue._class")); |
| 646 | + } |
| 647 | + |
| 648 | + /** |
| 649 | + * @see DATAMONGO-1236 |
| 650 | + */ |
| 651 | + @Test |
| 652 | + public void mappingShouldRetainTypeInformationForObjectValuesWithAlias() { |
| 653 | + |
| 654 | + Update update = new Update().set("value", new NestedDocument("adolin")); |
| 655 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 656 | + context.getPersistentEntity(EntityWithAliasedObject.class)); |
| 657 | + |
| 658 | + assertThat(mappedUpdate, isBsonObject().containing("$set.renamed-value.name", "adolin")); |
| 659 | + assertThat(mappedUpdate, isBsonObject().containing("$set.renamed-value._class", NestedDocument.class.getName())); |
| 660 | + } |
| 661 | + |
| 662 | + /** |
| 663 | + * @see DATAMONGO-1236 |
| 664 | + */ |
| 665 | + @Test |
| 666 | + public void mappingShouldRetrainTypeInformationWhenValueTypeOfMapDoesNotMatchItsDeclaration() { |
| 667 | + |
| 668 | + Map<Object, Object> map = Collections.<Object, Object> singletonMap("szeth", new NestedDocument("son-son-vallano")); |
| 669 | + |
| 670 | + Update update = new Update().set("map", map); |
| 671 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 672 | + context.getPersistentEntity(EntityWithObjectMap.class)); |
| 673 | + |
| 674 | + assertThat(mappedUpdate, isBsonObject().containing("$set.map.szeth.name", "son-son-vallano")); |
| 675 | + assertThat(mappedUpdate, isBsonObject().containing("$set.map.szeth._class", NestedDocument.class.getName())); |
| 676 | + } |
| 677 | + |
| 678 | + /** |
| 679 | + * @see DATAMONGO-1236 |
| 680 | + */ |
| 681 | + @Test |
| 682 | + public void mappingShouldNotContainTypeInformationWhenValueTypeOfMapMatchesDeclaration() { |
| 683 | + |
| 684 | + Map<Object, NestedDocument> map = Collections.<Object, NestedDocument> singletonMap("jasnah", new NestedDocument( |
| 685 | + "kholin")); |
| 686 | + |
| 687 | + Update update = new Update().set("concreteMap", map); |
| 688 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 689 | + context.getPersistentEntity(EntityWithObjectMap.class)); |
| 690 | + |
| 691 | + assertThat(mappedUpdate, isBsonObject().containing("$set.concreteMap.jasnah.name", "kholin")); |
| 692 | + assertThat(mappedUpdate, isBsonObject().notContaining("$set.concreteMap.jasnah._class")); |
615 | 693 | }
|
616 | 694 |
|
617 | 695 | static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
|
@@ -819,4 +897,21 @@ public NestedDocument(String name) {
|
819 | 897 | this.name = name;
|
820 | 898 | }
|
821 | 899 | }
|
| 900 | + |
| 901 | + static class EntityWithObject { |
| 902 | + |
| 903 | + Object value; |
| 904 | + NestedDocument concreteValue; |
| 905 | + } |
| 906 | + |
| 907 | + static class EntityWithAliasedObject { |
| 908 | + |
| 909 | + @Field("renamed-value") Object value; |
| 910 | + } |
| 911 | + |
| 912 | + static class EntityWithObjectMap { |
| 913 | + |
| 914 | + Map<Object, Object> map; |
| 915 | + Map<Object, NestedDocument> concreteMap; |
| 916 | + } |
822 | 917 | }
|
0 commit comments