Package com.vaadin.testbench.unit.mocks
Class MockSpringVaadinSession
java.lang.Object
com.vaadin.flow.server.VaadinSession
com.vaadin.flow.spring.SpringVaadinSession
com.vaadin.testbench.unit.mocks.MockSpringVaadinSession
- All Implemented Interfaces:
jakarta.servlet.http.HttpSessionBindingListener
,Serializable
,EventListener
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 callMockVaadin.afterSessionClose(com.vaadin.flow.server.VaadinSession, kotlin.jvm.functions.Function0<? extends com.vaadin.flow.component.UI>)
.
- Author:
- mavi
- See Also:
-
Field Summary
Fields inherited from class com.vaadin.flow.server.VaadinSession
browser
-
Constructor Summary
ConstructorDescriptionMockSpringVaadinSession
(VaadinService service, kotlin.jvm.functions.Function0<UI> uiFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
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.Methods inherited from class com.vaadin.flow.spring.SpringVaadinSession
addDestroyListener, fireSessionDestroy
Methods inherited from class com.vaadin.flow.server.VaadinSession
access, accessSynchronously, addRequestHandler, addUI, checkHasLock, checkHasLock, createStreamResourceRegistry, findElement, getAllSessions, getAttribute, getAttribute, getBrowser, getConfiguration, getCumulativeRequestDuration, getCurrent, getErrorHandler, getLastLocked, getLastRequestDuration, getLastRequestTimestamp, getLastUnlocked, getLocale, getLockInstance, getNextUIid, getPendingAccessQueue, getPushId, getRequestHandlers, getResourceRegistry, getService, getSession, getState, getUIById, getUIs, hasLock, hasLock, lock, refreshTransients, removeRequestHandler, removeUI, setAttribute, setAttribute, setBrowser, setConfiguration, setCurrent, setErrorHandler, setLastRequestDuration, setLastRequestTimestamp, setLocale, setState, unlock, valueBound, valueUnbound
-
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 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:
close
in classVaadinSession
- See Also:
-