Search in sources :

Example 1 with VaadinServiceInitListener

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

the class VaadinServiceTest method testBootstrapListenersCreation.

@Test
public void testBootstrapListenersCreation() throws ServiceException {
    // in this test the actual behavior of the listeners is not evaluated.
    // That test can be found at the BootstrapHandlerTest.
    AtomicBoolean listener1Run = new AtomicBoolean(false);
    AtomicBoolean listener2Run = new AtomicBoolean(false);
    BootstrapListener listener1 = evt -> listener1Run.set(true);
    BootstrapListener listener2 = evt -> listener2Run.set(true);
    VaadinServiceInitListener initListener = evt -> evt.addBootstrapListener(listener1);
    MockInstantiator instantiator = new MockInstantiator(initListener) {

        @Override
        public Stream<BootstrapListener> getBootstrapListeners(Stream<BootstrapListener> serviceInitListeners) {
            List<BootstrapListener> defaultListeners = serviceInitListeners.collect(Collectors.toList());
            assertEquals(Collections.singletonList(listener1), defaultListeners);
            return Stream.of(listener2);
        }
    };
    MockVaadinServletService service = new MockVaadinServletService();
    service.init(instantiator);
    Assert.assertFalse(listener1Run.get());
    Assert.assertFalse(listener2Run.get());
    service.modifyBootstrapPage(null);
    Assert.assertFalse(listener1Run.get());
    Assert.assertTrue(listener2Run.get());
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServletConfig(javax.servlet.ServletConfig) StreamRequestHandler(com.vaadin.flow.server.communication.StreamRequestHandler) ServletException(javax.servlet.ServletException) CurrentInstance(com.vaadin.flow.internal.CurrentInstance) SessionDestroyListener(com.vaadin.flow.server.SessionDestroyListener) VaadinServlet(com.vaadin.flow.server.VaadinServlet) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SessionDestroyEvent(com.vaadin.flow.server.SessionDestroyEvent) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) VaadinServiceInitListener(com.vaadin.flow.server.VaadinServiceInitListener) NotThreadSafe(net.jcip.annotations.NotThreadSafe) BootstrapListener(com.vaadin.flow.server.BootstrapListener) List(java.util.List) HttpSessionBindingEvent(javax.servlet.http.HttpSessionBindingEvent) Stream(java.util.stream.Stream) VaadinService(com.vaadin.flow.server.VaadinService) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ServiceException(com.vaadin.flow.server.ServiceException) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VaadinServiceInitListener(com.vaadin.flow.server.VaadinServiceInitListener) BootstrapListener(com.vaadin.flow.server.BootstrapListener) Stream(java.util.stream.Stream) Test(org.junit.Test)

Aggregations

CurrentInstance (com.vaadin.flow.internal.CurrentInstance)1 BootstrapListener (com.vaadin.flow.server.BootstrapListener)1 ServiceException (com.vaadin.flow.server.ServiceException)1 SessionDestroyEvent (com.vaadin.flow.server.SessionDestroyEvent)1 SessionDestroyListener (com.vaadin.flow.server.SessionDestroyListener)1 VaadinService (com.vaadin.flow.server.VaadinService)1 VaadinServiceInitListener (com.vaadin.flow.server.VaadinServiceInitListener)1 VaadinServlet (com.vaadin.flow.server.VaadinServlet)1 StreamRequestHandler (com.vaadin.flow.server.communication.StreamRequestHandler)1 Collections (java.util.Collections)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 ServletConfig (javax.servlet.ServletConfig)1 ServletException (javax.servlet.ServletException)1 HttpSessionBindingEvent (javax.servlet.http.HttpSessionBindingEvent)1 NotThreadSafe (net.jcip.annotations.NotThreadSafe)1 EasyMock (org.easymock.EasyMock)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1