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());
}
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"));
}
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"));
}
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();
}
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;"));
}
Aggregations