use of dev.hilla.frontend.EndpointGeneratorTaskFactoryImpl in project flow by vaadin.
the class BuildFrontendMojoTest method setup.
@Before
public void setup() throws Exception {
MavenProject project = Mockito.mock(MavenProject.class);
Mockito.when(project.getRuntimeClasspathElements()).thenReturn(getClassPath());
List<String> packages = Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparatorChar + "")).collect(Collectors.toList());
Mockito.when(project.getRuntimeClasspathElements()).thenReturn(packages);
Mockito.when(project.getCompileClasspathElements()).thenReturn(Collections.emptyList());
projectBase = temporaryFolder.getRoot();
tokenFile = new File(temporaryFolder.getRoot(), VAADIN_SERVLET_RESOURCES + TOKEN_FILE);
File npmFolder = temporaryFolder.getRoot();
generatedFolder = new File(npmFolder, "target/" + DEFAULT_GENERATED_DIR);
importsFile = new File(generatedFolder, IMPORTS_NAME);
nodeModulesPath = new File(npmFolder, NODE_MODULES);
flowResourcesFolder = new File(npmFolder, "target/" + DEFAULT_FLOW_RESOURCES_FOLDER);
File frontendDirectory = new File(npmFolder, DEFAULT_FRONTEND_DIR);
packageJson = new File(npmFolder, PACKAGE_JSON).getAbsolutePath();
webpackConfig = new File(npmFolder, WEBPACK_CONFIG).getAbsolutePath();
webpackGenerated = new File(npmFolder, WEBPACK_GENERATED).getAbsolutePath();
webpackOutputDirectory = new File(projectBase, VAADIN_WEBAPP_RESOURCES);
resourceOutputDirectory = new File(projectBase, VAADIN_SERVLET_RESOURCES);
projectFrontendResourcesDirectory = new File(npmFolder, "flow_resources");
defaultJavaSource = new File(".", "src/test/java");
openApiJsonFile = new File(npmFolder, "target/generated-resources/openapi.json");
generatedTsFolder = new File(npmFolder, "frontend/generated");
Assert.assertTrue("Failed to create a test project resources", projectFrontendResourcesDirectory.mkdirs());
Assert.assertTrue("Failed to create a test project file", new File(projectFrontendResourcesDirectory, TEST_PROJECT_RESOURCE_JS).createNewFile());
ReflectionUtils.setVariableValueInObject(mojo, "frontendResourcesDirectory", projectFrontendResourcesDirectory);
ReflectionUtils.setVariableValueInObject(mojo, "project", project);
ReflectionUtils.setVariableValueInObject(mojo, "webpackOutputDirectory", webpackOutputDirectory);
ReflectionUtils.setVariableValueInObject(mojo, "resourceOutputDirectory", resourceOutputDirectory);
ReflectionUtils.setVariableValueInObject(mojo, "generatedFolder", generatedFolder);
ReflectionUtils.setVariableValueInObject(mojo, "frontendDirectory", frontendDirectory);
ReflectionUtils.setVariableValueInObject(mojo, "generateEmbeddableWebComponents", false);
ReflectionUtils.setVariableValueInObject(mojo, "npmFolder", npmFolder);
ReflectionUtils.setVariableValueInObject(mojo, "generateBundle", false);
ReflectionUtils.setVariableValueInObject(mojo, "runNpmInstall", false);
ReflectionUtils.setVariableValueInObject(mojo, "optimizeBundle", true);
ReflectionUtils.setVariableValueInObject(mojo, "openApiJsonFile", openApiJsonFile);
ReflectionUtils.setVariableValueInObject(mojo, "applicationProperties", new File(npmFolder, "src/main/resources/application.properties"));
ReflectionUtils.setVariableValueInObject(mojo, "javaSourceFolder", defaultJavaSource);
ReflectionUtils.setVariableValueInObject(mojo, "generatedTsFolder", generatedTsFolder);
ReflectionUtils.setVariableValueInObject(mojo, "nodeVersion", FrontendTools.DEFAULT_NODE_VERSION);
ReflectionUtils.setVariableValueInObject(mojo, "nodeDownloadRoot", NodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOT);
ReflectionUtils.setVariableValueInObject(mojo, "projectBasedir", projectBase);
ReflectionUtils.setVariableValueInObject(mojo, "projectBuildDir", Paths.get(projectBase.toString(), "target").toString());
flowResourcesFolder.mkdirs();
generatedFolder.mkdirs();
setProject(mojo, npmFolder);
// Install all imports used in the tests on node_modules so as we don't
// need to run `npm install`
createExpectedImports(frontendDirectory, nodeModulesPath);
FileUtils.fileWrite(packageJson, "UTF-8", TestUtils.getInitalPackageJson().toJson());
Lookup lookup = Mockito.mock(Lookup.class);
Mockito.doReturn(new EndpointGeneratorTaskFactoryImpl()).when(lookup).lookup(EndpointGeneratorTaskFactory.class);
Mockito.doAnswer(invocation -> {
Mockito.doReturn((ClassFinder) invocation.getArguments()[0]).when(lookup).lookup(ClassFinder.class);
return lookup;
}).when(mojo).createLookup(Mockito.any(ClassFinder.class));
}
use of dev.hilla.frontend.EndpointGeneratorTaskFactoryImpl in project flow by vaadin.
the class DevModeEndpointTest method setup.
@Before
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setup() throws Exception {
super.setup();
assertFalse("No DevModeHandler should be available at test start", DevModeHandlerManager.getDevModeHandler(new VaadinServletContext(servletContext)).isPresent());
createStubNode(false, true, baseDir);
createStubWebpackServer("Compiled", 500, baseDir, true);
// Prevent TaskRunNpmInstall#cleanUp from deleting node_modules
new File(baseDir, "node_modules/.modules.yaml").createNewFile();
ServletRegistration vaadinServletRegistration = Mockito.mock(ServletRegistration.class);
Mockito.doReturn(new EndpointGeneratorTaskFactoryImpl()).when(lookup).lookup(EndpointGeneratorTaskFactory.class);
ResourceProvider resourceProvider = Mockito.mock(ResourceProvider.class);
Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(resourceProvider);
Mockito.when(vaadinServletRegistration.getClassName()).thenReturn(VaadinServletSubClass.class.getName());
classes = new HashSet<>();
classes.add(this.getClass());
Map registry = new HashMap();
// Adding extra registrations to make sure that
// DevModeInitializer picks
// the correct registration which is a VaadinServlet
// registration.
registry.put("extra1", Mockito.mock(ServletRegistration.class));
registry.put("foo", vaadinServletRegistration);
registry.put("extra2", Mockito.mock(ServletRegistration.class));
Mockito.when(servletContext.getServletRegistrations()).thenReturn(registry);
Mockito.when(servletContext.getInitParameterNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(servletContext.getClassLoader()).thenReturn(this.getClass().getClassLoader());
FileUtils.forceMkdir(new File(baseDir, DEFAULT_CONNECT_JAVA_SOURCE_FOLDER));
devModeStartupListener = new DevModeStartupListener();
}
Aggregations