Search in sources :

Example 16 with DefaultClassFinder

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

the class NodeTasksTest method verifyEndpointGeneratorWithHillaTask.

private void verifyEndpointGeneratorWithHillaTask(boolean withHillaTask) 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).enableImportsUpdate(true).runNpmInstall(false).withEmbeddableWebComponents(false).withFrontendGeneratedFolder(new File(userDir)).withEndpointSourceFolder(new File(userDir)).withEndpointGeneratedOpenAPIFile(new File(userDir));
    EndpointGeneratorTaskFactory endpointGeneratorFactory = mock(EndpointGeneratorTaskFactory.class);
    TaskGenerateOpenAPI mockGenerateOpenAPI = mock(TaskGenerateOpenAPI.class);
    TaskGenerateEndpoint mockGenerateEndpoint = mock(TaskGenerateEndpoint.class);
    Mockito.doReturn(mockGenerateOpenAPI).when(endpointGeneratorFactory).createTaskGenerateOpenAPI(any(), any(), any(), any());
    Mockito.doReturn(mockGenerateEndpoint).when(endpointGeneratorFactory).createTaskGenerateEndpoint(any(), any(), any(), any());
    Mockito.doReturn(endpointGeneratorFactory).when(mockedLookup).lookup(EndpointGeneratorTaskFactory.class);
    TaskGenerateHilla hillaTask = withHillaTask ? mock(TaskGenerateHilla.class) : null;
    Mockito.doReturn(hillaTask).when(mockedLookup).lookup(TaskGenerateHilla.class);
    builder.build().execute();
    if (withHillaTask) {
        Mockito.verify(hillaTask, times(1)).execute();
    }
    Mockito.verify(endpointGeneratorFactory, withHillaTask ? never() : times(1)).createTaskGenerateEndpoint(any(), any(), any(), any());
    Mockito.verify(endpointGeneratorFactory, withHillaTask ? never() : times(1)).createTaskGenerateOpenAPI(any(), any(), any(), any());
    Mockito.verify(mockGenerateOpenAPI, withHillaTask ? never() : times(1)).execute();
    Mockito.verify(mockGenerateEndpoint, withHillaTask ? never() : times(1)).execute();
}
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)

Example 17 with DefaultClassFinder

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

the class NodeTasksTest method should_SetIsClientBootstrapMode_When_EnableClientSideBootstrapMode.

@Test
public void should_SetIsClientBootstrapMode_When_EnableClientSideBootstrapMode() throws ExecutionFailedException, IOException {
    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).withWebpack(new File(userDir, TARGET + "webapp"), new File(userDir, TARGET + "classes")).enableImportsUpdate(true).runNpmInstall(false).withEmbeddableWebComponents(false).useV14Bootstrap(false).withFlowResourcesFolder(new File(userDir, TARGET + "flow-frontend")).withFrontendGeneratedFolder(new File(userDir, DEFAULT_PROJECT_FRONTEND_GENERATED_DIR));
    builder.build().execute();
    String webpackGeneratedContent = Files.lines(new File(userDir, WEBPACK_GENERATED).toPath()).collect(Collectors.joining("\n"));
    Assert.assertTrue("useClientSideIndexFileForBootstrapping should be true", webpackGeneratedContent.contains("const useClientSideIndexFileForBootstrapping = true;"));
}
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 18 with DefaultClassFinder

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

the class ClassFinderTest method should_LoadClasses_when_NoClassListProvided.

@Test
public void should_LoadClasses_when_NoClassListProvided() throws Exception {
    DefaultClassFinder finder = new DefaultClassFinder(Collections.emptySet());
    Assert.assertNotNull(finder.loadClass(Component1.class.getName()));
}
Also used : DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) Test(org.junit.Test)

Example 19 with DefaultClassFinder

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

the class ClassFinderTest method getSubTypesOf_returnsPlainSubtypes.

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

Example 20 with DefaultClassFinder

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

the class ClassFinderTest method should_LoadClasses.

@Test
public void should_LoadClasses() throws Exception {
    DefaultClassFinder finder = new DefaultClassFinder(new HashSet<>(Arrays.asList(Component1.class)));
    Assert.assertNotNull(finder.loadClass(Component1.class.getName()));
}
Also used : DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) 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