Search in sources :

Example 6 with Builder

use of com.vaadin.flow.server.frontend.NodeTasks.Builder in project flow by vaadin.

the class NodeTasksTest method should_UseDefaultFolders.

@Test
public void should_UseDefaultFolders() throws Exception {
    Lookup mockedLookup = Mockito.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);
    Assert.assertEquals(new File(userDir, DEFAULT_FRONTEND_DIR).getAbsolutePath(), ((File) getFieldValue(builder, "frontendDirectory")).getAbsolutePath());
    Assert.assertEquals(Paths.get(userDir, TARGET, DEFAULT_GENERATED_DIR).toFile().getAbsolutePath(), ((File) getFieldValue(builder, "generatedFolder")).getAbsolutePath());
    builder.build().execute();
    Assert.assertTrue(Paths.get(userDir, TARGET, DEFAULT_GENERATED_DIR, IMPORTS_NAME).toFile().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 Builder

use of com.vaadin.flow.server.frontend.NodeTasks.Builder in project flow by vaadin.

the class NodeTasksTest method should_IncludeExperimentalComponent_WhenFeatureEnabled.

@Test
public void should_IncludeExperimentalComponent_WhenFeatureEnabled() throws Exception {
    Class<?>[] classes = { FlagView.class, ExampleExperimentalComponent.class };
    File propertiesDir = temporaryFolder.newFolder();
    FileUtils.write(new File(propertiesDir, FeatureFlags.PROPERTIES_FILENAME), "com.vaadin.experimental.exampleFeatureFlag=true\n", StandardCharsets.UTF_8);
    Lookup mockedLookup = Mockito.mock(Lookup.class);
    ClassFinder finder = NodeUpdateTestUtil.getClassFinder(classes);
    Mockito.doReturn(finder).when(mockedLookup).lookup(ClassFinder.class);
    Builder builder = new Builder(mockedLookup, new File(userDir), TARGET).enablePackagesUpdate(false).enableImportsUpdate(true).runNpmInstall(false).withEmbeddableWebComponents(false).setJavaResourceFolder(propertiesDir);
    builder.build().execute();
    File importsFile = Paths.get(userDir, TARGET, DEFAULT_GENERATED_DIR, IMPORTS_NAME).toFile();
    String content = FileUtils.readFileToString(importsFile, Charset.defaultCharset());
    assertTrue(content.contains("@vaadin/example-flag/experimental-module-1.js"));
    assertTrue(content.contains("@vaadin/example-flag/experimental-module-2.js"));
    assertTrue(content.contains("experimental-Connector.js"));
}
Also used : Builder(com.vaadin.flow.server.frontend.NodeTasks.Builder) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass) Lookup(com.vaadin.flow.di.Lookup) File(java.io.File) Test(org.junit.Test)

Example 8 with Builder

use of com.vaadin.flow.server.frontend.NodeTasks.Builder in project flow by vaadin.

the class NodeTasksTest method should_ExcludeExperimentalComponent_WhenFeatureDisabled.

@Test
public void should_ExcludeExperimentalComponent_WhenFeatureDisabled() throws Exception {
    Class<?>[] classes = { FlagView.class, ExampleExperimentalComponent.class };
    Lookup mockedLookup = Mockito.mock(Lookup.class);
    ClassFinder finder = NodeUpdateTestUtil.getClassFinder(classes);
    Mockito.doReturn(finder).when(mockedLookup).lookup(ClassFinder.class);
    Builder builder = new Builder(mockedLookup, new File(userDir), TARGET).enablePackagesUpdate(false).enableImportsUpdate(true).runNpmInstall(false).withEmbeddableWebComponents(false);
    assertEquals(1, finder.getAnnotatedClasses(JsModule.class).size());
    assertEquals(1, finder.getAnnotatedClasses(JavaScript.class).size());
    builder.build().execute();
    File importsFile = Paths.get(userDir, TARGET, DEFAULT_GENERATED_DIR, IMPORTS_NAME).toFile();
    String content = FileUtils.readFileToString(importsFile, Charset.defaultCharset());
    assertFalse(content.contains("@vaadin/example-flag/experimental-module-1.js"));
    assertFalse(content.contains("@vaadin/example-flag/experimental-module-2.js"));
    assertFalse(content.contains("experimental-Connector.js"));
}
Also used : Builder(com.vaadin.flow.server.frontend.NodeTasks.Builder) DefaultClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass) Lookup(com.vaadin.flow.di.Lookup) File(java.io.File) Test(org.junit.Test)

Example 9 with Builder

use of com.vaadin.flow.server.frontend.NodeTasks.Builder 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 10 with Builder

use of com.vaadin.flow.server.frontend.NodeTasks.Builder 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)

Aggregations

Lookup (com.vaadin.flow.di.Lookup)10 Builder (com.vaadin.flow.server.frontend.NodeTasks.Builder)10 File (java.io.File)10 DefaultClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder)9 Test (org.junit.Test)7 ClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder)2 AfterClass (org.junit.AfterClass)2 BeforeClass (org.junit.BeforeClass)2 ViteHandler (com.vaadin.base.devserver.ViteHandler)1 WebpackHandler (com.vaadin.base.devserver.WebpackHandler)1 StatisticsSender (com.vaadin.base.devserver.stats.StatisticsSender)1 StatisticsStorage (com.vaadin.base.devserver.stats.StatisticsStorage)1 NodeTasks (com.vaadin.flow.server.frontend.NodeTasks)1 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)1 JsonObject (elemental.json.JsonObject)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Before (org.junit.Before)1