Class MockSpringVaadinSession

All Implemented Interfaces:
jakarta.servlet.http.HttpSessionBindingListener, Serializable, EventListener

public class MockSpringVaadinSession extends SpringVaadinSession
A Vaadin Session with one important difference:
  • Creates a new session when this one is closed. This is used to simulate a logout which closes the session - we need to have a new fresh session to be able to continue testing. In order to do that, simply override close(), call `super.close()` then call MockVaadin.afterSessionClose(com.vaadin.flow.server.VaadinSession, kotlin.jvm.functions.Function0<? extends com.vaadin.flow.component.UI>).
Author:
mavi
See Also:
  • Constructor Details

    • MockSpringVaadinSession

      public MockSpringVaadinSession(@NotNull VaadinService service, @NotNull kotlin.jvm.functions.Function0<UI> uiFactory)
  • Method Details

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