Class MockVaadinSession

java.lang.Object
com.vaadin.flow.server.VaadinSession
com.vaadin.browserless.mocks.MockVaadinSession
All Implemented Interfaces:
jakarta.servlet.http.HttpSessionBindingListener, Serializable, EventListener

public class MockVaadinSession extends com.vaadin.flow.server.VaadinSession
A VaadinSession that is replaced by a fresh one when it is closed.

Closing the session is how an application logs a user out: it then tells the browser to reload, and the servlet container hands the reloaded page a brand new session. There is no browser here, so close() does that itself and the test can go on to assert that a login view is shown.

A subclass that overrides close() has to keep both halves: call super.close(), then MockVaadin.afterSessionClose(VaadinSession, UIFactory).

For internal use only. May be renamed or removed in a future release.

See Also:
  • Field Summary

    Fields inherited from class com.vaadin.flow.server.VaadinSession

    browser
  • Constructor Summary

    Constructors
    Constructor
    Description
    MockVaadinSession(com.vaadin.flow.server.VaadinService service, UIFactory uiFactory)
    Creates a session for the given service.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    Returns the factory producing the UI of the session that replaces this one once it is closed.

    Methods inherited from class com.vaadin.flow.server.VaadinSession

    access, accessSynchronously, addRequestHandler, addSessionDestroyListener, addUI, applyLockStrategy, checkHasLock, checkHasLock, createStreamResourceRegistry, findElement, getAllSessions, getAttribute, getAttribute, getBrowser, getConfiguration, getCumulativeRequestDuration, getCurrent, getCurrentOrThrow, getErrorHandler, getLastLocked, getLastRequestDuration, getLastRequestTimestamp, getLastUnlocked, getLocale, getLockInstance, getNextUIid, getPendingAccessQueue, getPushId, getRequestHandlers, getResourceRegistry, getService, getSession, getState, getUIById, getUIs, hasLock, hasLock, localeSignal, lock, refreshTransients, removeRequestHandler, removeUI, setAttribute, setAttribute, setBrowser, setCurrent, setErrorHandler, setLastRequestDuration, setLastRequestTimestamp, setLocale, setState, unlock, valueBound, valueUnbound

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MockVaadinSession

      public MockVaadinSession(com.vaadin.flow.server.VaadinService service, UIFactory uiFactory)
      Creates a session for the given service.
      Parameters:
      service - the service owning this session
      uiFactory - produces the UI of the replacement session; it must return a fresh instance, not one already attached to a session
  • Method Details

    • getUiFactory

      public UIFactory getUiFactory()
      Returns the factory producing the UI of the session that replaces this one once it is closed.
      Returns:
      the UI factory
    • close

      public void close()
      Overrides:
      close in class com.vaadin.flow.server.VaadinSession