|
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;
|
@@ -680,8 +681,85 @@ public void mappingShouldRetainTypeInformationOfNestedListWhenUpdatingConcreteyP
|
680 | 681 | context.getPersistentEntity(DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes.class));
|
681 | 682 |
|
682 | 683 | assertThat(mappedUpdate, isBsonObject().notContaining("$set.concreteTypeWithListAttributeOfInterfaceType._class"));
|
683 |
| - assertThat(mappedUpdate, isBsonObject() |
684 |
| - .containing("$set.concreteTypeWithListAttributeOfInterfaceType.models.[0]._class", ModelImpl.class.getName())); |
| 684 | + assertThat( |
| 685 | + mappedUpdate, |
| 686 | + isBsonObject().containing("$set.concreteTypeWithListAttributeOfInterfaceType.models.[0]._class", |
| 687 | + ModelImpl.class.getName())); |
| 688 | + } |
| 689 | + |
| 690 | + /** |
| 691 | + * @see DATAMONGO-1236 |
| 692 | + */ |
| 693 | + @Test |
| 694 | + public void mappingShouldRetainTypeInformationForObjectValues() { |
| 695 | + |
| 696 | + Update update = new Update().set("value", new NestedDocument("kaladin")); |
| 697 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 698 | + context.getPersistentEntity(EntityWithObject.class)); |
| 699 | + |
| 700 | + assertThat(mappedUpdate, isBsonObject().containing("$set.value.name", "kaladin")); |
| 701 | + assertThat(mappedUpdate, isBsonObject().containing("$set.value._class", NestedDocument.class.getName())); |
| 702 | + } |
| 703 | + |
| 704 | + /** |
| 705 | + * @see DATAMONGO-1236 |
| 706 | + */ |
| 707 | + @Test |
| 708 | + public void mappingShouldNotRetainTypeInformationForConcreteValues() { |
| 709 | + |
| 710 | + Update update = new Update().set("concreteValue", new NestedDocument("shallan")); |
| 711 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 712 | + context.getPersistentEntity(EntityWithObject.class)); |
| 713 | + |
| 714 | + assertThat(mappedUpdate, isBsonObject().containing("$set.concreteValue.name", "shallan")); |
| 715 | + assertThat(mappedUpdate, isBsonObject().notContaining("$set.concreteValue._class")); |
| 716 | + } |
| 717 | + |
| 718 | + /** |
| 719 | + * @see DATAMONGO-1236 |
| 720 | + */ |
| 721 | + @Test |
| 722 | + public void mappingShouldRetainTypeInformationForObjectValuesWithAlias() { |
| 723 | + |
| 724 | + Update update = new Update().set("value", new NestedDocument("adolin")); |
| 725 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 726 | + context.getPersistentEntity(EntityWithAliasedObject.class)); |
| 727 | + |
| 728 | + assertThat(mappedUpdate, isBsonObject().containing("$set.renamed-value.name", "adolin")); |
| 729 | + assertThat(mappedUpdate, isBsonObject().containing("$set.renamed-value._class", NestedDocument.class.getName())); |
| 730 | + } |
| 731 | + |
| 732 | + /** |
| 733 | + * @see DATAMONGO-1236 |
| 734 | + */ |
| 735 | + @Test |
| 736 | + public void mappingShouldRetrainTypeInformationWhenValueTypeOfMapDoesNotMatchItsDeclaration() { |
| 737 | + |
| 738 | + Map<Object, Object> map = Collections.<Object, Object> singletonMap("szeth", new NestedDocument("son-son-vallano")); |
| 739 | + |
| 740 | + Update update = new Update().set("map", map); |
| 741 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 742 | + context.getPersistentEntity(EntityWithObjectMap.class)); |
| 743 | + |
| 744 | + assertThat(mappedUpdate, isBsonObject().containing("$set.map.szeth.name", "son-son-vallano")); |
| 745 | + assertThat(mappedUpdate, isBsonObject().containing("$set.map.szeth._class", NestedDocument.class.getName())); |
| 746 | + } |
| 747 | + |
| 748 | + /** |
| 749 | + * @see DATAMONGO-1236 |
| 750 | + */ |
| 751 | + @Test |
| 752 | + public void mappingShouldNotContainTypeInformationWhenValueTypeOfMapMatchesDeclaration() { |
| 753 | + |
| 754 | + Map<Object, NestedDocument> map = Collections.<Object, NestedDocument> singletonMap("jasnah", new NestedDocument( |
| 755 | + "kholin")); |
| 756 | + |
| 757 | + Update update = new Update().set("concreteMap", map); |
| 758 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 759 | + context.getPersistentEntity(EntityWithObjectMap.class)); |
| 760 | + |
| 761 | + assertThat(mappedUpdate, isBsonObject().containing("$set.concreteMap.jasnah.name", "kholin")); |
| 762 | + assertThat(mappedUpdate, isBsonObject().notContaining("$set.concreteMap.jasnah._class")); |
685 | 763 | }
|
686 | 764 |
|
687 | 765 | static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
|
@@ -889,4 +967,21 @@ public NestedDocument(String name) {
|
889 | 967 | this.name = name;
|
890 | 968 | }
|
891 | 969 | }
|
| 970 | + |
| 971 | + static class EntityWithObject { |
| 972 | + |
| 973 | + Object value; |
| 974 | + NestedDocument concreteValue; |
| 975 | + } |
| 976 | + |
| 977 | + static class EntityWithAliasedObject { |
| 978 | + |
| 979 | + @Field("renamed-value") Object value; |
| 980 | + } |
| 981 | + |
| 982 | + static class EntityWithObjectMap { |
| 983 | + |
| 984 | + Map<Object, Object> map; |
| 985 | + Map<Object, NestedDocument> concreteMap; |
| 986 | + } |
892 | 987 | }
|
0 commit comments