|
42 | 42 | import com.vaadin.flow.component.ComponentEvent; |
43 | 43 | import com.vaadin.flow.component.Tag; |
44 | 44 | import com.vaadin.flow.component.UI; |
| 45 | +import com.vaadin.flow.component.WebComponentExporter; |
45 | 46 | import com.vaadin.flow.component.page.AppShellConfigurator; |
| 47 | +import com.vaadin.flow.component.webcomponent.WebComponent; |
| 48 | +import com.vaadin.flow.i18n.I18NProvider; |
46 | 49 | import com.vaadin.flow.router.BeforeEnterEvent; |
47 | 50 | import com.vaadin.flow.router.BeforeEvent; |
48 | 51 | import com.vaadin.flow.router.ErrorParameter; |
|
53 | 56 | import com.vaadin.flow.router.RouteAlias; |
54 | 57 | import com.vaadin.flow.router.RouterLayout; |
55 | 58 | import com.vaadin.flow.server.PWA; |
| 59 | +import com.vaadin.flow.server.auth.MenuAccessControl; |
56 | 60 |
|
57 | 61 | import static org.assertj.core.api.Assertions.assertThat; |
58 | 62 | import static org.mockito.ArgumentMatchers.any; |
@@ -621,6 +625,76 @@ void getSubtypesOf_excludesParentType() { |
621 | 625 | .isNotEmpty().doesNotContain(RouterLayout.class); |
622 | 626 | } |
623 | 627 |
|
| 628 | + @Test |
| 629 | + void getSubtypesOf_findsWebComponentExporterSubclasses() { |
| 630 | + VaadinBeanFactoryInitializationAotProcessor processor = new VaadinBeanFactoryInitializationAotProcessor(); |
| 631 | + |
| 632 | + String packageName = getClass().getPackageName(); |
| 633 | + Collection<Class<?>> exporters = processor.getSubtypesOf( |
| 634 | + new Reflections(packageName), WebComponentExporter.class); |
| 635 | + |
| 636 | + assertThat(exporters).as("Should find WebComponentExporter subclasses") |
| 637 | + .contains(TestWebComponentExporter.class); |
| 638 | + } |
| 639 | + |
| 640 | + @Test |
| 641 | + void getSubtypesOf_findsI18NProviderImplementations() { |
| 642 | + VaadinBeanFactoryInitializationAotProcessor processor = new VaadinBeanFactoryInitializationAotProcessor(); |
| 643 | + |
| 644 | + String packageName = getClass().getPackageName(); |
| 645 | + Collection<Class<?>> providers = processor.getSubtypesOf( |
| 646 | + new Reflections(packageName), I18NProvider.class); |
| 647 | + |
| 648 | + assertThat(providers).as("Should find I18NProvider implementations") |
| 649 | + .contains(TestI18NProvider.class); |
| 650 | + } |
| 651 | + |
| 652 | + @Test |
| 653 | + void getSubtypesOf_findsMenuAccessControlImplementations() { |
| 654 | + VaadinBeanFactoryInitializationAotProcessor processor = new VaadinBeanFactoryInitializationAotProcessor(); |
| 655 | + |
| 656 | + String packageName = getClass().getPackageName(); |
| 657 | + Collection<Class<?>> accessControls = processor.getSubtypesOf( |
| 658 | + new Reflections(packageName), MenuAccessControl.class); |
| 659 | + |
| 660 | + assertThat(accessControls) |
| 661 | + .as("Should find MenuAccessControl implementations") |
| 662 | + .contains(TestMenuAccessControl.class); |
| 663 | + } |
| 664 | + |
| 665 | + @Test |
| 666 | + void processAheadOfTime_webComponentExporterSubtype_reflectionHintRegistered() { |
| 667 | + RuntimeHints hints = processAotForHintsWithSubtypes( |
| 668 | + TestWebComponentExporter.class, WebComponentExporter.class); |
| 669 | + |
| 670 | + assertThat(RuntimeHintsPredicates.reflection() |
| 671 | + .onType(TestWebComponentExporter.class)) |
| 672 | + .as("WebComponentExporter subtype should be registered for reflection") |
| 673 | + .accepts(hints); |
| 674 | + } |
| 675 | + |
| 676 | + @Test |
| 677 | + void processAheadOfTime_i18nProviderSubtype_reflectionHintRegistered() { |
| 678 | + RuntimeHints hints = processAotForHintsWithSubtypes( |
| 679 | + TestI18NProvider.class, I18NProvider.class); |
| 680 | + |
| 681 | + assertThat(RuntimeHintsPredicates.reflection() |
| 682 | + .onType(TestI18NProvider.class)) |
| 683 | + .as("I18NProvider subtype should be registered for reflection") |
| 684 | + .accepts(hints); |
| 685 | + } |
| 686 | + |
| 687 | + @Test |
| 688 | + void processAheadOfTime_menuAccessControlSubtype_reflectionHintRegistered() { |
| 689 | + RuntimeHints hints = processAotForHintsWithSubtypes( |
| 690 | + TestMenuAccessControl.class, MenuAccessControl.class); |
| 691 | + |
| 692 | + assertThat(RuntimeHintsPredicates.reflection() |
| 693 | + .onType(TestMenuAccessControl.class)) |
| 694 | + .as("MenuAccessControl subtype should be registered for reflection") |
| 695 | + .accepts(hints); |
| 696 | + } |
| 697 | + |
624 | 698 | @Test |
625 | 699 | void getAnnotatedClasses_findsClassesWithSpecificAnnotation() { |
626 | 700 | VaadinBeanFactoryInitializationAotProcessor processor = new VaadinBeanFactoryInitializationAotProcessor(); |
@@ -903,4 +977,41 @@ public static class RouteWithUILayout extends Component { |
903 | 977 | @Tag("div") |
904 | 978 | public static class RouteWithDefaultLayout extends Component { |
905 | 979 | } |
| 980 | + |
| 981 | + public static class TestWebComponentExporter |
| 982 | + extends WebComponentExporter<Component> { |
| 983 | + public TestWebComponentExporter() { |
| 984 | + super("test-exporter"); |
| 985 | + } |
| 986 | + |
| 987 | + @Override |
| 988 | + protected void configureInstance(WebComponent<Component> webComponent, |
| 989 | + Component component) { |
| 990 | + } |
| 991 | + } |
| 992 | + |
| 993 | + public static class TestI18NProvider implements I18NProvider { |
| 994 | + @Override |
| 995 | + public java.util.List<java.util.Locale> getProvidedLocales() { |
| 996 | + return java.util.List.of(java.util.Locale.ENGLISH); |
| 997 | + } |
| 998 | + |
| 999 | + @Override |
| 1000 | + public String getTranslation(String key, java.util.Locale locale, |
| 1001 | + Object... params) { |
| 1002 | + return key; |
| 1003 | + } |
| 1004 | + } |
| 1005 | + |
| 1006 | + public static class TestMenuAccessControl implements MenuAccessControl { |
| 1007 | + @Override |
| 1008 | + public void setPopulateClientSideMenu( |
| 1009 | + PopulateClientMenu populateClientMenu) { |
| 1010 | + } |
| 1011 | + |
| 1012 | + @Override |
| 1013 | + public PopulateClientMenu getPopulateClientSideMenu() { |
| 1014 | + return PopulateClientMenu.AUTOMATIC; |
| 1015 | + } |
| 1016 | + } |
906 | 1017 | } |
0 commit comments