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 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:
  • Constructor Details

    • MockVaadinSession

      public MockVaadinSession(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()
      Description copied from class: VaadinSession
      Sets this session to be closed and all UI state to be discarded at the end of the current request, or at the end of the next request if there is no ongoing one.

      After the session has been discarded, any UIs that have been left open will give a Session Expired error and a new session will be created for serving new UIs.

      Note that this method only closes the VaadinSession which is not the same as HttpSession. To invalidate the underlying HTTP session getSession().invalidate(); needs to be called.

      The method is usually called to perform logout. If user data is stored inside HTTP session then getSession().invalidate(); should be called instead (most common case). It makes sense to call VaadinSession.close() only if user data is stored inside a VaadinSession. Use the Page.setLocation(String) method to navigate to some page after session is closed to avoid session expired message.

      Overrides:
      close in class VaadinSession
      See Also: