|
37 | 37 | import java.util.TreeMap;
|
38 | 38 | import java.util.function.Supplier;
|
39 | 39 |
|
| 40 | +import org.aopalliance.aop.Advice; |
40 | 41 | import org.junit.jupiter.api.BeforeEach;
|
41 | 42 | import org.junit.jupiter.api.Test;
|
| 43 | +import org.springframework.aop.Advisor; |
| 44 | +import org.springframework.aop.SpringProxy; |
| 45 | +import org.springframework.aop.TargetSource; |
| 46 | +import org.springframework.aop.framework.Advised; |
| 47 | +import org.springframework.aop.framework.AopConfigException; |
42 | 48 | import org.springframework.context.ApplicationContext;
|
43 | 49 | import org.springframework.context.ApplicationEvent;
|
44 | 50 | import org.springframework.data.annotation.Id;
|
|
54 | 60 | import org.springframework.data.util.ClassTypeInformation;
|
55 | 61 | import org.springframework.data.util.StreamUtils;
|
56 | 62 | import org.springframework.data.util.TypeInformation;
|
| 63 | +import org.springframework.lang.Nullable; |
57 | 64 |
|
58 | 65 | /**
|
59 | 66 | * Unit test for {@link AbstractMappingContext}.
|
@@ -323,6 +330,40 @@ void shouldNotCreatePersistentEntityForMapButItsGenericTypeArguments() {
|
323 | 330 | .doesNotContain(List.class, Map.class, String.class, Integer.class);
|
324 | 331 | }
|
325 | 332 |
|
| 333 | + @Test // GH-2485 |
| 334 | + void contextSeesUserTypeBeforeProxy() { |
| 335 | + |
| 336 | + SampleMappingContext context = new SampleMappingContext(); |
| 337 | + BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntity = context.getPersistentEntity(Base.class); |
| 338 | + persistentEntity.getTypeInformation().getType().equals(Base.class); |
| 339 | + |
| 340 | + assertThat(context.hasPersistentEntityFor(Base.class)).isTrue(); |
| 341 | + assertThat(context.hasPersistentEntityFor(Base$$SpringProxy$873fa2e.class)).isFalse(); |
| 342 | + |
| 343 | + BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntityForProxy = context.getPersistentEntity(Base$$SpringProxy$873fa2e.class); |
| 344 | + persistentEntityForProxy.getTypeInformation().getType().equals(Base.class); |
| 345 | + assertThat(context.hasPersistentEntityFor(Base$$SpringProxy$873fa2e.class)).isTrue(); |
| 346 | + |
| 347 | + assertThat(context.getPersistentEntities()).hasSize(1); // only one distinct instance |
| 348 | + } |
| 349 | + |
| 350 | + @Test // GH-2485 |
| 351 | + void contextSeesProxyBeforeUserType() { |
| 352 | + |
| 353 | + SampleMappingContext context = new SampleMappingContext(); |
| 354 | + |
| 355 | + BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntityForProxy = context.getPersistentEntity(Base$$SpringProxy$873fa2e.class); |
| 356 | + persistentEntityForProxy.getTypeInformation().getType().equals(Base.class); |
| 357 | + |
| 358 | + assertThat(context.hasPersistentEntityFor(Base$$SpringProxy$873fa2e.class)).isTrue(); |
| 359 | + assertThat(context.hasPersistentEntityFor(Base.class)).isTrue(); |
| 360 | + |
| 361 | + BasicPersistentEntity<Object, SamplePersistentProperty> persistentEntity = context.getPersistentEntity(Base.class); |
| 362 | + persistentEntity.getTypeInformation().getType().equals(Base.class); |
| 363 | + |
| 364 | + assertThat(context.getPersistentEntities()).hasSize(1); // only one distinct instance |
| 365 | + } |
| 366 | + |
326 | 367 | private static void assertHasEntityFor(Class<?> type, SampleMappingContext context, boolean expected) {
|
327 | 368 |
|
328 | 369 | boolean found = false;
|
@@ -505,4 +546,123 @@ class WithMap {
|
505 | 546 | Map<MapKey, Integer> mapOfKeyToPerson;
|
506 | 547 | }
|
507 | 548 |
|
| 549 | + static class Base$$SpringProxy$873fa2e extends Base implements SpringProxy, Advised { |
| 550 | + |
| 551 | + @Override |
| 552 | + public boolean isFrozen() { |
| 553 | + return false; |
| 554 | + } |
| 555 | + |
| 556 | + @Override |
| 557 | + public boolean isProxyTargetClass() { |
| 558 | + return false; |
| 559 | + } |
| 560 | + |
| 561 | + @Override |
| 562 | + public Class<?>[] getProxiedInterfaces() { |
| 563 | + return new Class[0]; |
| 564 | + } |
| 565 | + |
| 566 | + @Override |
| 567 | + public boolean isInterfaceProxied(Class<?> intf) { |
| 568 | + return false; |
| 569 | + } |
| 570 | + |
| 571 | + @Override |
| 572 | + public void setTargetSource(TargetSource targetSource) { |
| 573 | + |
| 574 | + } |
| 575 | + |
| 576 | + @Override |
| 577 | + public TargetSource getTargetSource() { |
| 578 | + return null; |
| 579 | + } |
| 580 | + |
| 581 | + @Override |
| 582 | + public void setExposeProxy(boolean exposeProxy) { |
| 583 | + |
| 584 | + } |
| 585 | + |
| 586 | + @Override |
| 587 | + public boolean isExposeProxy() { |
| 588 | + return false; |
| 589 | + } |
| 590 | + |
| 591 | + @Override |
| 592 | + public void setPreFiltered(boolean preFiltered) { |
| 593 | + |
| 594 | + } |
| 595 | + |
| 596 | + @Override |
| 597 | + public boolean isPreFiltered() { |
| 598 | + return false; |
| 599 | + } |
| 600 | + |
| 601 | + @Override |
| 602 | + public Advisor[] getAdvisors() { |
| 603 | + return new Advisor[0]; |
| 604 | + } |
| 605 | + |
| 606 | + @Override |
| 607 | + public void addAdvisor(Advisor advisor) throws AopConfigException { |
| 608 | + |
| 609 | + } |
| 610 | + |
| 611 | + @Override |
| 612 | + public void addAdvisor(int pos, Advisor advisor) throws AopConfigException { |
| 613 | + |
| 614 | + } |
| 615 | + |
| 616 | + @Override |
| 617 | + public boolean removeAdvisor(Advisor advisor) { |
| 618 | + return false; |
| 619 | + } |
| 620 | + |
| 621 | + @Override |
| 622 | + public void removeAdvisor(int index) throws AopConfigException { |
| 623 | + |
| 624 | + } |
| 625 | + |
| 626 | + @Override |
| 627 | + public int indexOf(Advisor advisor) { |
| 628 | + return 0; |
| 629 | + } |
| 630 | + |
| 631 | + @Override |
| 632 | + public boolean replaceAdvisor(Advisor a, Advisor b) throws AopConfigException { |
| 633 | + return false; |
| 634 | + } |
| 635 | + |
| 636 | + @Override |
| 637 | + public void addAdvice(Advice advice) throws AopConfigException { |
| 638 | + |
| 639 | + } |
| 640 | + |
| 641 | + @Override |
| 642 | + public void addAdvice(int pos, Advice advice) throws AopConfigException { |
| 643 | + |
| 644 | + } |
| 645 | + |
| 646 | + @Override |
| 647 | + public boolean removeAdvice(Advice advice) { |
| 648 | + return false; |
| 649 | + } |
| 650 | + |
| 651 | + @Override |
| 652 | + public int indexOf(Advice advice) { |
| 653 | + return 0; |
| 654 | + } |
| 655 | + |
| 656 | + @Override |
| 657 | + public String toProxyConfigString() { |
| 658 | + return null; |
| 659 | + } |
| 660 | + |
| 661 | + @Nullable |
| 662 | + @Override |
| 663 | + public Class<?> getTargetClass() { |
| 664 | + return null; |
| 665 | + } |
| 666 | + } |
| 667 | + |
508 | 668 | }
|
0 commit comments