use of com.vaadin.flow.server.DefaultDeploymentConfiguration in project flow by vaadin.
the class AbstractDnDUnitTest method setup.
@Before
public void setup() {
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(appConfig.getBuildFolder()).thenReturn(".");
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(appConfig.getContext()).thenReturn(context);
Lookup lookup = Mockito.mock(Lookup.class);
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
DefaultDeploymentConfiguration configuration = new DefaultDeploymentConfiguration(appConfig, VaadinServlet.class, new Properties());
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(service.resolveResource(Mockito.anyString())).thenReturn("");
VaadinSession session = Mockito.mock(VaadinSession.class);
Mockito.when(session.getConfiguration()).thenReturn(configuration);
Mockito.when(session.getService()).thenReturn(service);
ui = new MockUI(session);
}
use of com.vaadin.flow.server.DefaultDeploymentConfiguration in project flow by vaadin.
the class WebComponentProviderTest method webComponentGenerator_responseGetsResult.
@Test
public void webComponentGenerator_responseGetsResult() throws IOException {
registry = setupConfigurations(MyComponentExporter.class);
ByteArrayOutputStream out = Mockito.mock(ByteArrayOutputStream.class);
DefaultDeploymentConfiguration configuration = Mockito.mock(DefaultDeploymentConfiguration.class);
Mockito.when(response.getOutputStream()).thenReturn(out);
Mockito.when(session.getConfiguration()).thenReturn(configuration);
Mockito.when(request.getPathInfo()).thenReturn("/web-component/my-component.js");
Assert.assertTrue("Provider should handle web-component request", provider.synchronizedHandleRequest(session, request, response));
Mockito.verify(response).getOutputStream();
Mockito.verify(out).write(Mockito.any());
}
use of com.vaadin.flow.server.DefaultDeploymentConfiguration in project flow by vaadin.
the class ApplicationRunnerServlet method findDeploymentConfiguration.
private DeploymentConfiguration findDeploymentConfiguration(DeploymentConfiguration originalConfiguration) throws Exception {
// First level of cache
DeploymentConfiguration configuration = CurrentInstance.get(DeploymentConfiguration.class);
if (configuration == null) {
// Not in cache, try to find a VaadinSession to get it from
VaadinSession session = VaadinSession.getCurrent();
if (session == null) {
/*
* There's no current session, request or response when serving
* static resources, but there's still the current request
* maintained by ApplicationRunnerServlet, and there's most
* likely also a HttpSession containing a VaadinSession for that
* request.
*/
HttpServletRequest currentRequest = VaadinServletService.getCurrentServletRequest();
if (currentRequest != null) {
HttpSession httpSession = currentRequest.getSession(false);
if (httpSession != null) {
Map<Class<?>, CurrentInstance> oldCurrent = CurrentInstance.setCurrent((VaadinSession) null);
try {
VaadinServletService service = (VaadinServletService) VaadinService.getCurrent();
session = service.findVaadinSession(new VaadinServletRequest(currentRequest, service));
} finally {
/*
* Clear some state set by findVaadinSession to
* avoid accidentally depending on it when coding on
* e.g. static request handling.
*/
CurrentInstance.restoreInstances(oldCurrent);
currentRequest.removeAttribute(VaadinSession.class.getName());
}
}
}
}
if (session != null) {
String name = ApplicationRunnerServlet.class.getName() + ".deploymentConfiguration";
try {
session.getLockInstance().lock();
/*
* Read attribute using reflection to bypass
* VaadinSesison.getAttribute which would cause an infinite
* loop when checking the production mode setting for
* determining whether to check that the session is locked.
*/
Field attributesField = VaadinSession.class.getDeclaredField("attributes");
attributesField.setAccessible(true);
Attributes sessionAttributes = (Attributes) attributesField.get(session);
configuration = (DeploymentConfiguration) sessionAttributes.getAttribute(name);
if (configuration == null) {
ApplicationRunnerServlet servlet = (ApplicationRunnerServlet) VaadinServlet.getCurrent();
Class<?> classToRun;
try {
classToRun = servlet.getClassToRun();
} catch (ClassNotFoundException e) {
/*
* This happens e.g. if the UI class defined in the
* URL is not found or if this servlet just serves
* static resources while there's some other servlet
* that serves the UI (e.g. when using /run-push/).
*/
return originalConfiguration;
}
CustomDeploymentConfiguration customDeploymentConfiguration = classToRun.getAnnotation(CustomDeploymentConfiguration.class);
if (customDeploymentConfiguration != null) {
Properties initParameters = new Properties(originalConfiguration.getInitParameters());
for (Conf entry : customDeploymentConfiguration.value()) {
initParameters.put(entry.name(), entry.value());
}
initParameters.put(VaadinSession.UI_PARAMETER, getApplicationRunnerApplicationClassName(request.get()));
configuration = new DefaultDeploymentConfiguration(ApplicationConfiguration.get(getService().getContext()), servlet.getClass(), initParameters);
} else {
configuration = originalConfiguration;
}
sessionAttributes.setAttribute(name, configuration);
}
} finally {
session.getLockInstance().unlock();
}
CurrentInstance.set(DeploymentConfiguration.class, configuration);
} else {
configuration = originalConfiguration;
}
}
return configuration;
}
use of com.vaadin.flow.server.DefaultDeploymentConfiguration in project flow by vaadin.
the class AbstractScopeTest method mockSession.
@SuppressWarnings("unchecked")
protected VaadinSession mockSession() {
SpringVaadinSession session = Mockito.mock(TestSession.class, Mockito.withSettings().useConstructor());
doCallRealMethod().when(session).setAttribute(Mockito.any(Class.class), Mockito.any());
doCallRealMethod().when(session).getAttribute(Mockito.any(Class.class));
doCallRealMethod().when(session).getAttribute(Mockito.any(String.class));
doCallRealMethod().when(session).addUI(Mockito.any());
doCallRealMethod().when(session).removeUI(Mockito.any());
doCallRealMethod().when(session).getService();
doCallRealMethod().when(session).getUIs();
when(session.getState()).thenReturn(VaadinSessionState.OPEN);
final Properties initParameters = new Properties();
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
VaadinContext context = Mockito.mock(VaadinContext.class);
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(session.getConfiguration()).thenReturn(config);
VaadinSession.setCurrent(session);
when(session.hasLock()).thenReturn(true);
// keep a reference to the session so that it cannot be GCed.
this.session = session;
return session;
}
use of com.vaadin.flow.server.DefaultDeploymentConfiguration in project flow by vaadin.
the class SpringClassesSerializableTest method createStore.
private TestBeanStore createStore() {
final Properties initParameters = new Properties();
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(context.getAttribute(Mockito.eq(ApplicationConfiguration.class), Mockito.any())).thenReturn(appConfig);
Mockito.when(appConfig.getContext()).thenReturn(context);
Lookup lookup = Mockito.mock(Lookup.class);
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
VaadinService service = new VaadinServletService(new VaadinServlet(), new DefaultDeploymentConfiguration(appConfig, getClass(), initParameters)) {
@Override
public VaadinContext getContext() {
return context;
}
};
VaadinSession session = new TestSession(service);
TestBeanStore store = new TestBeanStore(session);
return store;
}
Aggregations