Search in sources :

Example 41 with VaadinContext

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;
}
Also used : SpringVaadinSession(com.vaadin.flow.spring.SpringVaadinSession) VaadinContext(com.vaadin.flow.server.VaadinContext) Lookup(com.vaadin.flow.di.Lookup) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 42 with VaadinContext

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;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) TestBeanStore(com.vaadin.flow.spring.scopes.TestBeanStore) VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) VaadinServlet(com.vaadin.flow.server.VaadinServlet) VaadinServletService(com.vaadin.flow.server.VaadinServletService) Lookup(com.vaadin.flow.di.Lookup) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Aggregations

VaadinContext (com.vaadin.flow.server.VaadinContext)42 Test (org.junit.Test)16 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)15 VaadinService (com.vaadin.flow.server.VaadinService)11 Lookup (com.vaadin.flow.di.Lookup)8 ResourceProvider (com.vaadin.flow.di.ResourceProvider)8 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)5 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)5 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)5 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)5 Properties (java.util.Properties)5 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)4 VaadinConfig (com.vaadin.flow.server.VaadinConfig)4 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)4 File (java.io.File)4 Before (org.junit.Before)4 VaadinSession (com.vaadin.flow.server.VaadinSession)3 WebComponentConfigurationRegistry (com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry)3 AppShellRegistry (com.vaadin.flow.server.AppShellRegistry)2 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)2