Search in sources :

Example 1 with DevModeStartupListener

use of com.vaadin.base.devserver.startup.DevModeStartupListener 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();
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) ServletRegistration(javax.servlet.ServletRegistration) EndpointGeneratorTaskFactoryImpl(dev.hilla.frontend.EndpointGeneratorTaskFactoryImpl) HashMap(java.util.HashMap) DevModeStartupListener(com.vaadin.base.devserver.startup.DevModeStartupListener) ResourceProvider(com.vaadin.flow.di.ResourceProvider) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Aggregations

DevModeStartupListener (com.vaadin.base.devserver.startup.DevModeStartupListener)1 ResourceProvider (com.vaadin.flow.di.ResourceProvider)1 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)1 EndpointGeneratorTaskFactoryImpl (dev.hilla.frontend.EndpointGeneratorTaskFactoryImpl)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ServletRegistration (javax.servlet.ServletRegistration)1 Before (org.junit.Before)1