use of com.vaadin.flow.server.VaadinContext 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.VaadinContext 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