|
25 | 25 | import lombok.Setter;
|
26 | 26 | import lombok.ToString;
|
27 | 27 |
|
| 28 | +import java.util.ArrayList; |
28 | 29 | import java.util.Arrays;
|
29 | 30 | import java.util.Collections;
|
30 | 31 | import java.util.LinkedHashMap;
|
@@ -679,6 +680,41 @@ void loadCollectionReferenceWithMissingRefs() {
|
679 | 680 | assertThat(result.getSimpleValueRef()).containsExactly(new SimpleObjectRef("ref-2", "me-the-2-referenced-object"));
|
680 | 681 | }
|
681 | 682 |
|
| 683 | + @Test // GH-3805 |
| 684 | + void loadEmptyCollectionReference() { |
| 685 | + |
| 686 | + String rootCollectionName = template.getCollectionName(CollectionRefRoot.class); |
| 687 | + |
| 688 | + // an empty reference array. |
| 689 | + Document source = new Document("_id", "id-1").append("value", "v1").append("simplePreinitializedValueRef", |
| 690 | + Collections.emptyList()); |
| 691 | + |
| 692 | + template.execute(db -> { |
| 693 | + db.getCollection(rootCollectionName).insertOne(source); |
| 694 | + return null; |
| 695 | + }); |
| 696 | + |
| 697 | + CollectionRefRoot result = template.findOne(query(where("id").is("id-1")), CollectionRefRoot.class); |
| 698 | + assertThat(result.simplePreinitializedValueRef).isEmpty(); |
| 699 | + } |
| 700 | + |
| 701 | + @Test // GH-3805 |
| 702 | + void loadNoExistingCollectionReference() { |
| 703 | + |
| 704 | + String rootCollectionName = template.getCollectionName(CollectionRefRoot.class); |
| 705 | + |
| 706 | + // no reference array at all |
| 707 | + Document source = new Document("_id", "id-1").append("value", "v1"); |
| 708 | + |
| 709 | + template.execute(db -> { |
| 710 | + db.getCollection(rootCollectionName).insertOne(source); |
| 711 | + return null; |
| 712 | + }); |
| 713 | + |
| 714 | + CollectionRefRoot result = template.findOne(query(where("id").is("id-1")), CollectionRefRoot.class); |
| 715 | + assertThat(result.simplePreinitializedValueRef).isEmpty(); |
| 716 | + } |
| 717 | + |
682 | 718 | @Test // GH-3602
|
683 | 719 | void queryForReference() {
|
684 | 720 |
|
@@ -1122,6 +1158,9 @@ static class CollectionRefRoot {
|
1122 | 1158 | @DocumentReference(lookup = "{ '_id' : '?#{#target}' }") //
|
1123 | 1159 | List<SimpleObjectRef> simpleValueRef;
|
1124 | 1160 |
|
| 1161 | + @DocumentReference |
| 1162 | + List<SimpleObjectRef> simplePreinitializedValueRef = new ArrayList<>(); |
| 1163 | + |
1125 | 1164 | @DocumentReference(lookup = "{ '_id' : '?#{#target}' }", sort = "{ '_id' : -1 } ") //
|
1126 | 1165 | List<SimpleObjectRef> simpleSortedValueRef;
|
1127 | 1166 |
|
|
0 commit comments