Class MockVaadinSession
- All Implemented Interfaces:
jakarta.servlet.http.HttpSessionBindingListener,Serializable,EventListener
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
ConstructorsConstructorDescriptionMockVaadinSession(VaadinService service, UIFactory uiFactory) Creates a session for the given service. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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.Returns the factory producing theUIof 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
-
Constructor Details
-
MockVaadinSession
Creates a session for the given service.- Parameters:
service- the service owning this sessionuiFactory- produces the UI of the replacement session; it must return a fresh instance, not one already attached to a session
-
-
Method Details
-
getUiFactory
Returns the factory producing theUIof the session that replaces this one once it is closed.- Returns:
- the UI factory
-
close
public void close()Description copied from class:VaadinSessionSets 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
VaadinSessionwhich is not the same asHttpSession. To invalidate the underlying HTTP sessiongetSession().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 callVaadinSession.close()only if user data is stored inside aVaadinSession. Use thePage.setLocation(String)method to navigate to some page after session is closed to avoid session expired message.- Overrides:
closein classVaadinSession- See Also:
-