Search in sources :

Example 21 with ClassFinder

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

the class AbstractUpdateImportsTest method assertFullSortOrder.

@Test
public void assertFullSortOrder() throws MalformedURLException {
    Class[] testClasses = { MainView.class, NodeTestComponents.TranslatedImports.class, NodeTestComponents.LocalP3Template.class, NodeTestComponents.JavaScriptOrder.class, UI.class };
    ClassFinder classFinder = getClassFinder(testClasses);
    updater = new UpdateImports(classFinder, getScanner(classFinder), tmpRoot, new File(tmpRoot, TOKEN_FILE), true);
    updater.run();
    // Imports are collected as
    // - theme and css
    // - JsModules (external e.g. in node_modules/)
    // - JavaScript
    // - Generated webcompoents
    // - JsModules (internal e.g. in frontend/)
    List<String> expectedImports = new ArrayList<>();
    expectedImports.addAll(updater.getExportLines());
    expectedImports.addAll(updater.getThemeLines());
    getAnntotationsAsStream(JsModule.class, testClasses).map(JsModule::value).map(this::updateToImport).sorted().forEach(expectedImports::add);
    getAnntotationsAsStream(JavaScript.class, testClasses).map(JavaScript::value).map(this::updateToImport).sorted().forEach(expectedImports::add);
    List<String> internals = expectedImports.stream().filter(importValue -> importValue.contains(FrontendUtils.WEBPACK_PREFIX_ALIAS)).sorted().collect(Collectors.toList());
    updater.getGeneratedModules().stream().map(this::updateToImport).forEach(expectedImports::add);
    // Remove internals from the full list
    expectedImports.removeAll(internals);
    // Add internals to end of list
    expectedImports.addAll(internals);
    Assert.assertEquals(expectedImports, updater.resultingLines);
}
Also used : ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 22 with ClassFinder

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

the class AbstractUpdateImportsTest method getModuleLines_oneFrontendDependencyAndFrontendDirectoryDontExist_throwExceptionAdvisingUserToRunPrepareFrontend.

@Test
public void getModuleLines_oneFrontendDependencyAndFrontendDirectoryDontExist_throwExceptionAdvisingUserToRunPrepareFrontend() throws Exception {
    ClassFinder classFinder = getClassFinder();
    updater = new UpdateImports(classFinder, getScanner(classFinder), tmpRoot, null, true);
    Files.move(frontendDirectory.toPath(), new File(tmpRoot, "_frontend").toPath());
    try {
        updater.run();
        Assert.fail("Execute should have failed with advice to run `prepare-frontend`");
    } catch (IllegalStateException e) {
        assertThat(e.getMessage(), CoreMatchers.containsString("Unable to locate frontend resources and missing token file. " + "Please run the `prepare-frontend` Vaadin plugin goal before deploying the application"));
    }
}
Also used : ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) File(java.io.File) Test(org.junit.Test)

Example 23 with ClassFinder

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

the class FrontendResourcesAreCopiedAfterCleaningTest method performPackageClean.

private void performPackageClean() throws ExecutionFailedException {
    ClassFinder classFinder = new ClassFinder.DefaultClassFinder(FrontendResourcesAreCopiedAfterCleaningTest.class.getClassLoader());
    Lookup mockLookup = Mockito.mock(Lookup.class);
    Mockito.doReturn(classFinder).when(mockLookup).lookup(ClassFinder.class);
    NodeTasks.Builder builder = new NodeTasks.Builder(mockLookup, npmFolder, TARGET);
    File resourcesFolder = new File(npmFolder, Paths.get(TARGET, DEFAULT_FLOW_RESOURCES_FOLDER).toString());
    builder.withEmbeddableWebComponents(false).enableImportsUpdate(false).createMissingPackageJson(true).enableImportsUpdate(true).runNpmInstall(false).enableNpmFileCleaning(true).withFlowResourcesFolder(resourcesFolder).copyResources(Collections.emptySet()).enablePackagesUpdate(true).build().execute();
}
Also used : ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) Lookup(com.vaadin.flow.di.Lookup) File(java.io.File)

Aggregations

ClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder)23 File (java.io.File)20 Test (org.junit.Test)14 FeatureFlags (com.vaadin.experimental.FeatureFlags)9 Before (org.junit.Before)9 Lookup (com.vaadin.flow.di.Lookup)8 DefaultClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder)8 IOException (java.io.IOException)8 TARGET (com.vaadin.flow.server.Constants.TARGET)7 DEFAULT_FRONTEND_DIR (com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR)7 DEFAULT_GENERATED_DIR (com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR)7 IMPORTS_NAME (com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME)7 NODE_MODULES (com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES)7 Charset (java.nio.charset.Charset)7 Paths (java.nio.file.Paths)7 Set (java.util.Set)7 FileUtils (org.apache.commons.io.FileUtils)7 Assert (org.junit.Assert)7 Rule (org.junit.Rule)7 ExpectedException (org.junit.rules.ExpectedException)7