use of com.vaadin.flow.server.startup.ApplicationConfiguration 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.startup.ApplicationConfiguration in project flow by vaadin.
the class AbstractUIScopedTest method mockUI.
protected UI mockUI() {
VaadinSession session = mockSession();
Router router = mock(Router.class);
VaadinService service = session.getService();
when(service.getRouter()).thenReturn(router);
Properties initParameters = new Properties();
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
when(service.getMainDivId(Mockito.any(), Mockito.any())).thenReturn(" - ");
final Map<String, Object> attributeMap = new HashMap<>();
ServletContext servletContext = Mockito.mock(ServletContext.class);
Mockito.when(servletContext.getAttribute(Mockito.anyString())).then(invocationOnMock -> attributeMap.get(invocationOnMock.getArguments()[0].toString()));
Mockito.doAnswer(invocationOnMock -> attributeMap.put(invocationOnMock.getArguments()[0].toString(), invocationOnMock.getArguments()[1])).when(servletContext).setAttribute(Mockito.anyString(), Mockito.any());
VaadinServletContext context = new VaadinServletContext(servletContext);
Mockito.when(service.getContext()).thenReturn(context);
Lookup lookup = Mockito.mock(Lookup.class);
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
Mockito.when(appConfig.getContext()).thenReturn(context);
DefaultDeploymentConfiguration config = new DefaultDeploymentConfiguration(appConfig, getClass(), initParameters);
when(service.getDeploymentConfiguration()).thenReturn(config);
ui = new UI();
ui.getInternals().setSession(session);
ui.doInit(null, 1);
UI.setCurrent(ui);
return ui;
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class SpringApplicationConfigurationFactoryTest method doCreate_vaadinApplicationConfigurationHasSpringPropertiesPrefixedByVaadin.
@Test
public void doCreate_vaadinApplicationConfigurationHasSpringPropertiesPrefixedByVaadin() {
String prefix = "foo_";
SpringServlet.PROPERTY_NAMES.stream().forEach(name -> Mockito.when(env.getProperty("vaadin." + name)).thenReturn(prefix + name));
Map<String, String> props = new HashMap<>();
ApplicationConfiguration config = factory.doCreate(context, null, props);
for (String prop : SpringServlet.PROPERTY_NAMES) {
Assert.assertEquals("'" + prop + "' property is not available via " + ApplicationConfiguration.class, prefix + prop, config.getStringProperty(prop, null));
Assert.assertEquals("'" + prop + "' property is not set in the properties map passed to the " + ApplicationConfiguration.class.getSimpleName() + " CTOR", prefix + prop, props.get(prop));
}
Assert.assertEquals(SpringServlet.PROPERTY_NAMES.size(), props.size());
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class DefaultDeploymentConfigurationTest method useV14Bootstrap_v14ModeIsSetViaParentOnly_v14ModeIsTakenFromParent.
@Test
public void useV14Bootstrap_v14ModeIsSetViaParentOnly_v14ModeIsTakenFromParent() {
ApplicationConfiguration appConfig = setupAppConfig();
Mockito.when(appConfig.useV14Bootstrap()).thenReturn(true);
// Note: application configuration doesn't contain production mode
// parameter !
Assert.assertNull(appConfig.getStringProperty(InitParameters.SERVLET_PARAMETER_USE_V14_BOOTSTRAP, null));
DefaultDeploymentConfiguration config = createDeploymentConfig(appConfig, new Properties());
Assert.assertTrue(config.useV14Bootstrap());
Assert.assertTrue(config.getProperties().isEmpty());
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class DefaultDeploymentConfigurationTest method testGetSystemProperty.
@Test
public void testGetSystemProperty() {
String value = "value";
String prop = "prop";
System.setProperty(DefaultDeploymentConfigurationTest.class.getPackage().getName() + '.' + prop, value);
Properties initParameters = new Properties();
ApplicationConfiguration appConfig = setupAppConfig();
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
DefaultDeploymentConfiguration config = new DefaultDeploymentConfiguration(appConfig, DefaultDeploymentConfigurationTest.class, initParameters);
assertEquals(value, config.getSystemProperty(prop));
}
Aggregations