Search in sources :

Example 6 with DefaultClassFinder

use of com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder in project flow by vaadin.

the class NodeTasksTest method should_GenerateTsConfigAndTsDefinitions_When_Vaadin14BootstrapMode.

@Test
public void should_GenerateTsConfigAndTsDefinitions_When_Vaadin14BootstrapMode() throws ExecutionFailedException {
    Lookup mockedLookup = mock(Lookup.class);
    Mockito.doReturn(new DefaultClassFinder(this.getClass().getClassLoader())).when(mockedLookup).lookup(ClassFinder.class);
    Builder builder = new Builder(mockedLookup, new File(userDir), TARGET).enablePackagesUpdate(false).useV14Bootstrap(true).enableImportsUpdate(true).runNpmInstall(false).withEmbeddableWebComponents(false).useV14Bootstrap(false);
    builder.build().execute();
    Assert.assertTrue(new File(userDir, "tsconfig.json").exists());
    Assert.assertTrue(new File(userDir, "types.d.ts").exists());
}
Also used : DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) Builder(com.vaadin.flow.server.frontend.NodeTasks.Builder) Lookup(com.vaadin.flow.di.Lookup) File(java.io.File) Test(org.junit.Test)

Example 7 with DefaultClassFinder

use of com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder in project flow by vaadin.

the class ClassFinderTest method should_Fail_when_DifferentClasLoader.

@Test
public void should_Fail_when_DifferentClasLoader() throws Exception {
    ClassLoader loader = new ClassLoader() {

        @Override
        public Class<?> loadClass(String name) throws ClassNotFoundException {
            throw new ClassNotFoundException();
        }
    };
    exception.expect(ClassNotFoundException.class);
    DefaultClassFinder finder = new DefaultClassFinder(loader, Component1.class);
    finder.loadClass(Component1.class.getName());
}
Also used : DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) Component1(com.vaadin.flow.server.frontend.scanner.ScannerTestComponents.Component1) Test(org.junit.Test)

Example 8 with DefaultClassFinder

use of com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder in project flow by vaadin.

the class ClassFinderTest method orderIsDeterministic.

@Test
public void orderIsDeterministic() {
    Set<Class<?>> testClasses = new HashSet<>();
    testClasses.add(NodeTestComponents.ExtraImport.class);
    testClasses.add(NodeTestComponents.VaadinBowerComponent.class);
    testClasses.add(NodeTestComponents.TranslatedImports.class);
    Set<Class<?>> allClasses = new DefaultClassFinder(testClasses).getSubTypesOf(Object.class);
    LinkedHashSet<Class<?>> expected = new LinkedHashSet<>();
    expected.add(NodeTestComponents.ExtraImport.class);
    expected.add(NodeTestComponents.TranslatedImports.class);
    expected.add(NodeTestComponents.VaadinBowerComponent.class);
    Assert.assertEquals(expected, allClasses);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) NodeTestComponents(com.vaadin.flow.server.frontend.NodeTestComponents) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 9 with DefaultClassFinder

use of com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder in project flow by vaadin.

the class ClassFinderTest method getSubTypesOf_returnsGenericSubtypes.

@Test
public void getSubTypesOf_returnsGenericSubtypes() {
    DefaultClassFinder finder = new DefaultClassFinder(new HashSet<>(Arrays.asList(ArrayList.class, TestList.class, String.class)));
    Set<Class<? extends List>> subTypes = finder.getSubTypesOf(List.class);
    Assert.assertEquals(2, subTypes.size());
    Assert.assertTrue(subTypes.contains(ArrayList.class));
    Assert.assertTrue(subTypes.contains(TestList.class));
}
Also used : DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 10 with DefaultClassFinder

use of com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder in project flow by vaadin.

the class ScannerThemeTest method should_visitDefaultTheme_when_noThemeAnnotationIsGiven.

@Test
public void should_visitDefaultTheme_when_noThemeAnnotationIsGiven() throws Exception {
    DefaultClassFinder finder = spy(new DefaultClassFinder(Collections.singleton(RootViewWithoutThemeAnnotation.class)));
    // we'll do a partial mock here since we want to keep the other
    // behavior of the DefaultClassFinder. Theme4 is used as a fake Lumo
    // since it has @JsModule annotation which makes it easy to verify
    // that the Theme was actually visited and modules collected
    Mockito.doReturn(Theme4.class).when(finder).loadClass(FrontendDependencies.LUMO);
    FrontendDependencies deps = new FrontendDependencies(finder);
    assertEquals("Theme4 should have been returned when default theme was selected", Theme4.class, deps.getThemeDefinition().getTheme());
    assertTrue("Theme4 should have been visited and JsModule collected", deps.getModules().contains("./theme-4.js"));
}
Also used : DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) ScannerDependenciesTest.getFrontendDependencies(com.vaadin.flow.server.frontend.scanner.ScannerDependenciesTest.getFrontendDependencies) Test(org.junit.Test)

Aggregations

DefaultClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder)22 Test (org.junit.Test)19 File (java.io.File)12 Lookup (com.vaadin.flow.di.Lookup)7 Builder (com.vaadin.flow.server.frontend.NodeTasks.Builder)7 HashSet (java.util.HashSet)7 ClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder)6 Before (org.junit.Before)6 FeatureFlags (com.vaadin.experimental.FeatureFlags)5 TARGET (com.vaadin.flow.server.Constants.TARGET)5 DEFAULT_FRONTEND_DIR (com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR)5 DEFAULT_GENERATED_DIR (com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR)5 FLOW_NPM_PACKAGE_NAME (com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME)5 IMPORTS_D_TS_NAME (com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_D_TS_NAME)5 IMPORTS_NAME (com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME)5 NODE_MODULES (com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES)5 FrontendDependenciesScannerFactory (com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner.FrontendDependenciesScannerFactory)5 Json (elemental.json.Json)5 JsonArray (elemental.json.JsonArray)5 JsonObject (elemental.json.JsonObject)5