use of com.vaadin.flow.server.StaticFileHandlerFactory in project flow by vaadin.
the class SpringInstantiatorTest method getService.
public static VaadinService getService(ApplicationContext context, Properties configProperties, boolean rootMapping) throws ServletException {
SpringServlet servlet = new SpringServlet(context, rootMapping) {
@Override
protected DeploymentConfiguration createDeploymentConfiguration(Properties initParameters) {
if (configProperties != null) {
configProperties.putAll(initParameters);
return super.createDeploymentConfiguration(configProperties);
}
return super.createDeploymentConfiguration(initParameters);
}
};
ServletConfig config = Mockito.mock(ServletConfig.class);
ServletContext servletContext = Mockito.mock(ServletContext.class);
Mockito.when(servletContext.getClassLoader()).thenReturn(servlet.getClass().getClassLoader());
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(appConfig.getContext()).thenReturn(new VaadinServletContext(servletContext));
Mockito.when(servletContext.getAttribute(ApplicationConfiguration.class.getName())).thenReturn(appConfig);
Lookup lookup = Mockito.mock(Lookup.class);
ResourceProvider provider = Mockito.mock(ResourceProvider.class);
Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(provider);
StaticFileHandlerFactory staticFileHandlerFactory = vaadinService -> new StaticFileServer((VaadinServletService) vaadinService);
Mockito.when(lookup.lookup(StaticFileHandlerFactory.class)).thenReturn(staticFileHandlerFactory);
Mockito.when(servletContext.getAttribute(Lookup.class.getName())).thenReturn(lookup);
Mockito.when(config.getServletContext()).thenReturn(servletContext);
Mockito.when(config.getInitParameterNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(servletContext.getInitParameterNames()).thenReturn(Collections.emptyEnumeration());
servlet.init(config);
return servlet.getService();
}
use of com.vaadin.flow.server.StaticFileHandlerFactory in project flow by vaadin.
the class LookupInitializerTest method initialize_noStaticFileHandlerFactory_defaultStaticFileHandlerFactoryCreated.
@Test
public void initialize_noStaticFileHandlerFactory_defaultStaticFileHandlerFactoryCreated() throws ServletException {
AtomicReference<Lookup> capture = new AtomicReference<>();
initializer.initialize(null, new HashMap<>(), capture::set);
Lookup lookup = capture.get();
StaticFileHandlerFactory factory = lookup.lookup(StaticFileHandlerFactory.class);
VaadinService service = Mockito.mock(VaadinService.class);
DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
ClassLoader loader = Mockito.mock(ClassLoader.class);
Mockito.when(service.getClassLoader()).thenReturn(loader);
StaticFileHandler handler = factory.createHandler(service);
Assert.assertNotNull(handler);
Assert.assertEquals(StaticFileServer.class, handler.getClass());
}
Aggregations