|
32 | 32 | import org.bson.BsonValue;
|
33 | 33 | import org.bson.Document;
|
34 | 34 | import org.junit.jupiter.api.BeforeEach;
|
| 35 | +import org.junit.jupiter.api.Disabled; |
35 | 36 | import org.junit.jupiter.api.Test;
|
36 | 37 | import org.junit.jupiter.api.extension.ExtendWith;
|
37 | 38 |
|
|
44 | 45 | import org.springframework.data.mongodb.core.ExecutableFindOperation.TerminatingFind;
|
45 | 46 | import org.springframework.data.mongodb.core.index.GeoSpatialIndexType;
|
46 | 47 | import org.springframework.data.mongodb.core.index.GeospatialIndex;
|
| 48 | +import org.springframework.data.mongodb.core.mapping.DBRef; |
| 49 | +import org.springframework.data.mongodb.core.mapping.DocumentReference; |
47 | 50 | import org.springframework.data.mongodb.core.mapping.Field;
|
48 | 51 | import org.springframework.data.mongodb.core.query.BasicQuery;
|
49 | 52 | import org.springframework.data.mongodb.core.query.NearQuery;
|
@@ -549,6 +552,71 @@ void distinctAppliesFilterQuery() {
|
549 | 552 | ).containsExactlyInAnyOrder("luke");
|
550 | 553 | }
|
551 | 554 |
|
| 555 | + @Test // GH-2860 |
| 556 | + void projectionOnDbRef() { |
| 557 | + |
| 558 | + WithRefs source = new WithRefs(); |
| 559 | + source.id = "id-1"; |
| 560 | + source.noRef = "value"; |
| 561 | + source.planetDbRef = alderan; |
| 562 | + |
| 563 | + template.save(source); |
| 564 | + |
| 565 | + WithDbRefProjection target = template.query(WithRefs.class).as(WithDbRefProjection.class) |
| 566 | + .matching(where("id").is(source.id)).oneValue(); |
| 567 | + |
| 568 | + assertThat(target.getPlanetDbRef()).isEqualTo(alderan); |
| 569 | + } |
| 570 | + |
| 571 | + @Test // GH-2860 |
| 572 | + @Disabled("GH-3913") |
| 573 | + void propertyProjectionOnDbRef() { |
| 574 | + |
| 575 | + WithRefs source = new WithRefs(); |
| 576 | + source.id = "id-1"; |
| 577 | + source.noRef = "value"; |
| 578 | + source.planetDbRef = alderan; |
| 579 | + |
| 580 | + template.save(source); |
| 581 | + |
| 582 | + WithDbRefPropertyProjection target = template.query(WithRefs.class).as(WithDbRefPropertyProjection.class) |
| 583 | + .matching(where("id").is(source.id)).oneValue(); |
| 584 | + |
| 585 | + assertThat(target.getPlanetDbRef().getName()).isEqualTo(alderan.getName()); |
| 586 | + } |
| 587 | + |
| 588 | + @Test // GH-2860 |
| 589 | + void projectionOnDocRef() { |
| 590 | + |
| 591 | + WithRefs source = new WithRefs(); |
| 592 | + source.id = "id-1"; |
| 593 | + source.noRef = "value"; |
| 594 | + source.planetDocRef = alderan; |
| 595 | + |
| 596 | + template.save(source); |
| 597 | + |
| 598 | + WithDocumentRefProjection target = template.query(WithRefs.class).as(WithDocumentRefProjection.class) |
| 599 | + .matching(where("id").is(source.id)).oneValue(); |
| 600 | + |
| 601 | + assertThat(target.getPlanetDocRef()).isEqualTo(alderan); |
| 602 | + } |
| 603 | + |
| 604 | + @Test // GH-2860 |
| 605 | + void propertyProjectionOnDocRef() { |
| 606 | + |
| 607 | + WithRefs source = new WithRefs(); |
| 608 | + source.id = "id-1"; |
| 609 | + source.noRef = "value"; |
| 610 | + source.planetDocRef = alderan; |
| 611 | + |
| 612 | + template.save(source); |
| 613 | + |
| 614 | + WithDocRefPropertyProjection target = template.query(WithRefs.class).as(WithDocRefPropertyProjection.class) |
| 615 | + .matching(where("id").is(source.id)).oneValue(); |
| 616 | + |
| 617 | + assertThat(target.getPlanetDocRef().getName()).isEqualTo(alderan.getName()); |
| 618 | + } |
| 619 | + |
552 | 620 | interface Contact {}
|
553 | 621 |
|
554 | 622 | @Data
|
@@ -618,6 +686,34 @@ interface PlanetSpELProjection {
|
618 | 686 | String getId();
|
619 | 687 | }
|
620 | 688 |
|
| 689 | + @Data |
| 690 | + static class WithRefs { |
| 691 | + |
| 692 | + @Id String id; |
| 693 | + |
| 694 | + String noRef; |
| 695 | + |
| 696 | + @DBRef Planet planetDbRef; |
| 697 | + |
| 698 | + @DocumentReference Planet planetDocRef; |
| 699 | + } |
| 700 | + |
| 701 | + interface WithDbRefProjection { |
| 702 | + Planet getPlanetDbRef(); |
| 703 | + } |
| 704 | + |
| 705 | + interface WithDocumentRefProjection { |
| 706 | + Planet getPlanetDocRef(); |
| 707 | + } |
| 708 | + |
| 709 | + interface WithDbRefPropertyProjection { |
| 710 | + PlanetProjection getPlanetDbRef(); |
| 711 | + } |
| 712 | + |
| 713 | + interface WithDocRefPropertyProjection { |
| 714 | + PlanetProjection getPlanetDocRef(); |
| 715 | + } |
| 716 | + |
621 | 717 | private void initPersons() {
|
622 | 718 |
|
623 | 719 | han = new Person();
|
|
0 commit comments