Search in sources :

Example 6 with MockServletServiceSessionSetup

use of com.vaadin.flow.server.MockServletServiceSessionSetup in project flow by vaadin.

the class PublishedServerEventHandlerRpcHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    Assert.assertNull(System.getSecurityManager());
    MockServletServiceSessionSetup setup = new MockServletServiceSessionSetup();
    service = setup.getService();
    MockDeploymentConfiguration configuration = setup.getDeploymentConfiguration();
    configuration.setProductionMode(false);
    VaadinService.setCurrent(service);
    session = setup.getSession();
    Mockito.when(session.hasLock()).thenReturn(true);
}
Also used : MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) MockServletServiceSessionSetup(com.vaadin.flow.server.MockServletServiceSessionSetup) Before(org.junit.Before)

Example 7 with MockServletServiceSessionSetup

use of com.vaadin.flow.server.MockServletServiceSessionSetup in project flow by vaadin.

the class VaadinAppShellInitializerTest method setup.

@Before
public void setup() throws Exception {
    logger = mockLog(VaadinAppShellInitializer.class);
    mocks = new MockServletServiceSessionSetup();
    servletContext = mocks.getServletContext();
    appConfig = mockApplicationConfiguration();
    Lookup lookup = (Lookup) servletContext.getAttribute(Lookup.class.getName());
    Mockito.when(lookup.lookup(AppShellPredicate.class)).thenReturn(AppShellConfigurator.class::isAssignableFrom);
    attributeMap.put(Lookup.class.getName(), servletContext.getAttribute(Lookup.class.getName()));
    attributeMap.put(ApplicationConfiguration.class.getName(), appConfig);
    service = mocks.getService();
    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());
    ServletRegistration registration = Mockito.mock(ServletRegistration.class);
    context = new VaadinServletContext(servletContext);
    classes = new HashSet<>();
    Map<String, ServletRegistration> registry = new HashMap<>();
    registry.put("foo", registration);
    Mockito.when(servletContext.getServletRegistrations()).thenReturn((Map) registry);
    Mockito.when(servletContext.getInitParameterNames()).thenReturn(Collections.emptyEnumeration());
    initializer = new VaadinAppShellInitializer();
    document = Document.createShell("");
    pushConfiguration = Mockito.mock(PushConfiguration.class);
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) PushConfiguration(com.vaadin.flow.component.PushConfiguration) AppShellConfigurator(com.vaadin.flow.component.page.AppShellConfigurator) ServletRegistration(javax.servlet.ServletRegistration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Lookup(com.vaadin.flow.di.Lookup) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MockServletServiceSessionSetup(com.vaadin.flow.server.MockServletServiceSessionSetup) Before(org.junit.Before)

Aggregations

MockServletServiceSessionSetup (com.vaadin.flow.server.MockServletServiceSessionSetup)7 Before (org.junit.Before)6 Lookup (com.vaadin.flow.di.Lookup)2 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)2 VaadinSession (com.vaadin.flow.server.VaadinSession)2 PushConfiguration (com.vaadin.flow.component.PushConfiguration)1 AppShellConfigurator (com.vaadin.flow.component.page.AppShellConfigurator)1 RouteConfiguration (com.vaadin.flow.router.RouteConfiguration)1 RoutePathProviderImpl (com.vaadin.flow.server.MockVaadinContext.RoutePathProviderImpl)1 VaadinContext (com.vaadin.flow.server.VaadinContext)1 VaadinResponse (com.vaadin.flow.server.VaadinResponse)1 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)1 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)1 MockUI (com.vaadin.tests.util.MockUI)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ServletRegistration (javax.servlet.ServletRegistration)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1