|
39 | 39 | import com.vaadin.flow.component.ComponentEvent; |
40 | 40 | import com.vaadin.flow.component.Tag; |
41 | 41 | import com.vaadin.flow.component.UI; |
| 42 | +import com.vaadin.flow.component.WebComponentExporter; |
42 | 43 | import com.vaadin.flow.component.page.AppShellConfigurator; |
| 44 | +import com.vaadin.flow.component.webcomponent.WebComponent; |
| 45 | +import com.vaadin.flow.i18n.I18NProvider; |
43 | 46 | import com.vaadin.flow.router.BeforeEnterEvent; |
44 | 47 | import com.vaadin.flow.router.BeforeEvent; |
45 | 48 | import com.vaadin.flow.router.ErrorParameter; |
|
50 | 53 | import com.vaadin.flow.router.RouteAlias; |
51 | 54 | import com.vaadin.flow.router.RouterLayout; |
52 | 55 | import com.vaadin.flow.server.PWA; |
| 56 | +import com.vaadin.flow.server.auth.MenuAccessControl; |
53 | 57 |
|
54 | 58 | import static org.assertj.core.api.Assertions.assertThat; |
55 | 59 | import static org.mockito.ArgumentMatchers.any; |
@@ -550,6 +554,73 @@ void getSubtypesOf_excludesParentType() { |
550 | 554 | .isNotEmpty().doesNotContain(RouterLayout.class); |
551 | 555 | } |
552 | 556 |
|
| 557 | + @Test |
| 558 | + void getSubtypesOf_findsWebComponentExporterSubclasses() { |
| 559 | + VaadinBeanFactoryInitializationAotProcessor processor = new VaadinBeanFactoryInitializationAotProcessor(); |
| 560 | + |
| 561 | + Collection<Class<?>> exporters = processor.getSubtypesOf( |
| 562 | + getClass().getPackageName(), WebComponentExporter.class); |
| 563 | + |
| 564 | + assertThat(exporters).as("Should find WebComponentExporter subclasses") |
| 565 | + .contains(TestWebComponentExporter.class); |
| 566 | + } |
| 567 | + |
| 568 | + @Test |
| 569 | + void getSubtypesOf_findsI18NProviderImplementations() { |
| 570 | + VaadinBeanFactoryInitializationAotProcessor processor = new VaadinBeanFactoryInitializationAotProcessor(); |
| 571 | + |
| 572 | + Collection<Class<?>> providers = processor |
| 573 | + .getSubtypesOf(getClass().getPackageName(), I18NProvider.class); |
| 574 | + |
| 575 | + assertThat(providers).as("Should find I18NProvider implementations") |
| 576 | + .contains(TestI18NProvider.class); |
| 577 | + } |
| 578 | + |
| 579 | + @Test |
| 580 | + void getSubtypesOf_findsMenuAccessControlImplementations() { |
| 581 | + VaadinBeanFactoryInitializationAotProcessor processor = new VaadinBeanFactoryInitializationAotProcessor(); |
| 582 | + |
| 583 | + Collection<Class<?>> accessControls = processor.getSubtypesOf( |
| 584 | + getClass().getPackageName(), MenuAccessControl.class); |
| 585 | + |
| 586 | + assertThat(accessControls) |
| 587 | + .as("Should find MenuAccessControl implementations") |
| 588 | + .contains(TestMenuAccessControl.class); |
| 589 | + } |
| 590 | + |
| 591 | + @Test |
| 592 | + void processAheadOfTime_webComponentExporterSubtype_reflectionHintRegistered() { |
| 593 | + RuntimeHints hints = processAotForHintsWithSubtypes( |
| 594 | + TestWebComponentExporter.class, WebComponentExporter.class); |
| 595 | + |
| 596 | + assertThat(RuntimeHintsPredicates.reflection() |
| 597 | + .onType(TestWebComponentExporter.class)) |
| 598 | + .as("WebComponentExporter subtype should be registered for reflection") |
| 599 | + .accepts(hints); |
| 600 | + } |
| 601 | + |
| 602 | + @Test |
| 603 | + void processAheadOfTime_i18nProviderSubtype_reflectionHintRegistered() { |
| 604 | + RuntimeHints hints = processAotForHintsWithSubtypes( |
| 605 | + TestI18NProvider.class, I18NProvider.class); |
| 606 | + |
| 607 | + assertThat(RuntimeHintsPredicates.reflection() |
| 608 | + .onType(TestI18NProvider.class)) |
| 609 | + .as("I18NProvider subtype should be registered for reflection") |
| 610 | + .accepts(hints); |
| 611 | + } |
| 612 | + |
| 613 | + @Test |
| 614 | + void processAheadOfTime_menuAccessControlSubtype_reflectionHintRegistered() { |
| 615 | + RuntimeHints hints = processAotForHintsWithSubtypes( |
| 616 | + TestMenuAccessControl.class, MenuAccessControl.class); |
| 617 | + |
| 618 | + assertThat(RuntimeHintsPredicates.reflection() |
| 619 | + .onType(TestMenuAccessControl.class)) |
| 620 | + .as("MenuAccessControl subtype should be registered for reflection") |
| 621 | + .accepts(hints); |
| 622 | + } |
| 623 | + |
553 | 624 | @Test |
554 | 625 | void getAnnotatedClasses_findsClassesWithSpecificAnnotation() { |
555 | 626 | VaadinBeanFactoryInitializationAotProcessor processor = new VaadinBeanFactoryInitializationAotProcessor(); |
@@ -809,4 +880,41 @@ public static class RouteWithUILayout extends Component { |
809 | 880 | @Tag("div") |
810 | 881 | public static class RouteWithDefaultLayout extends Component { |
811 | 882 | } |
| 883 | + |
| 884 | + public static class TestWebComponentExporter |
| 885 | + extends WebComponentExporter<Component> { |
| 886 | + public TestWebComponentExporter() { |
| 887 | + super("test-exporter"); |
| 888 | + } |
| 889 | + |
| 890 | + @Override |
| 891 | + protected void configureInstance(WebComponent<Component> webComponent, |
| 892 | + Component component) { |
| 893 | + } |
| 894 | + } |
| 895 | + |
| 896 | + public static class TestI18NProvider implements I18NProvider { |
| 897 | + @Override |
| 898 | + public java.util.List<java.util.Locale> getProvidedLocales() { |
| 899 | + return java.util.List.of(java.util.Locale.ENGLISH); |
| 900 | + } |
| 901 | + |
| 902 | + @Override |
| 903 | + public String getTranslation(String key, java.util.Locale locale, |
| 904 | + Object... params) { |
| 905 | + return key; |
| 906 | + } |
| 907 | + } |
| 908 | + |
| 909 | + public static class TestMenuAccessControl implements MenuAccessControl { |
| 910 | + @Override |
| 911 | + public void setPopulateClientSideMenu( |
| 912 | + PopulateClientMenu populateClientMenu) { |
| 913 | + } |
| 914 | + |
| 915 | + @Override |
| 916 | + public PopulateClientMenu getPopulateClientSideMenu() { |
| 917 | + return PopulateClientMenu.AUTOMATIC; |
| 918 | + } |
| 919 | + } |
812 | 920 | } |
0 commit comments