Package com.vaadin.browserless.mocks
Class MockService
java.lang.Object
com.vaadin.flow.server.VaadinService
com.vaadin.flow.server.VaadinServletService
com.vaadin.browserless.mocks.MockService
- All Implemented Interfaces:
Serializable
public class MockService
extends com.vaadin.flow.server.VaadinServletService
The
VaadinServletService of the mocked environment.
It stands in for a deployed service in the three places a browserless test has nothing to offer:
isAtmosphereAvailable()reports that Atmosphere is absent, which it is. Vaadin initializes push duringVaadinService.init()and crashes otherwise.getMainDivId(VaadinSession, VaadinRequest)returns a fixed root id, since there is no bootstrap page to read one from.createVaadinSession(VaadinRequest)returns aMockVaadinSession, which recreates the session after it is closed, the way a servlet container does when the browser reloads after a logout.
Instantiator the environment's
Lookup provides, which is how views and beans
still come from the real container.
The class is not final, so a custom service can be registered by overriding
MockVaadinServlet.createServletService(DeploymentConfiguration), but
the shape of what it overrides is not part of the published API.
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.VaadinService
ATMOSPHERE_MISSING_ERROR, INVALID_ATMOSPHERE_VERSION_WARNING -
Constructor Summary
ConstructorsConstructorDescriptionMockService(com.vaadin.flow.server.VaadinServlet servlet, com.vaadin.flow.function.DeploymentConfiguration deploymentConfiguration) Creates a service whose sessions produceMockedUIinstances.MockService(com.vaadin.flow.server.VaadinServlet servlet, com.vaadin.flow.function.DeploymentConfiguration deploymentConfiguration, UIFactory uiFactory) Creates a service whose sessions produce UIs from the given factory. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.vaadin.flow.server.VaadinSessioncreateVaadinSession(com.vaadin.flow.server.VaadinRequest request) getMainDivId(com.vaadin.flow.server.VaadinSession session, com.vaadin.flow.server.VaadinRequest request) Returns the factory creating theUIof the session that replaces a closed session of this service.protected booleanMethods inherited from class com.vaadin.flow.server.VaadinServletService
constructVaadinContext, createRequestHandlers, createSessionlessRequestHandlers, getContextRootRelativePath, getCurrentResponse, getCurrentServletRequest, getMimeType, getPwaRegistry, getResource, getResourceAsStream, getResourceInServletContext, getRouteRegistry, getServiceName, getServlet, getStaticResource, requestCanCreateSession, resolveResource, setDefaultClassLoaderMethods inherited from class com.vaadin.flow.server.VaadinService
accessSession, addRpcInvocationListener, addServiceDestroyListener, addSessionDestroyListener, addSessionInitListener, addSessionLockListener, addUIInitListener, applySessionLockCheckStrategy, closeSession, createCriticalNotificationJSON, createCriticalNotificationJSON, createDefaultExecutor, createDefaultObjectMapper, createInstantiator, createSessionExpiredJSON, createUINotFoundJSON, createVaadinRequestInterceptors, destroy, ensureAccessQueuePurged, ensurePushAvailable, findUI, findVaadinSession, fireSessionDestroy, fireUIInitListeners, getBootstrapInitialPredicate, getBootstrapUrlPredicate, getClassLoader, getContext, getCsrfTokenAttributeName, getCurrent, getCurrentOrThrow, getCurrentRequest, getDependencyFilters, getDeploymentConfiguration, getEventBus, getExecutor, getExistingSession, getInstantiator, getRequestHandlers, getRouter, getSessionAttributeName, getSessionlessRequestHandlers, getSessionLock, getSystemMessages, getSystemMessagesProvider, getVaadinRequestInterceptors, handleRequest, handleSessionExpired, init, isCsrfTokenValid, isInitialized, isOtherSessionLocked, isResourceAvailable, isUIActive, loadInstantiators, loadSession, lockSession, modifyIndexHtmlResponse, readFromHttpSession, recordRequestFailure, reinitializeSession, removeFromHttpSession, removeSession, requestEnd, requestStart, runPendingAccessTasks, setBootstrapInitialPredicate, setBootstrapUrlPredicate, setClassLoader, setCurrent, setCurrentInstances, setSystemMessagesProvider, storeSession, unlockSession, verifyNoOtherSessionLocked, whenInitialized, writeStringResponse, writeToHttpSession, writeUncachedStringResponse
-
Constructor Details
-
MockService
public MockService(com.vaadin.flow.server.VaadinServlet servlet, com.vaadin.flow.function.DeploymentConfiguration deploymentConfiguration) Creates a service whose sessions produceMockedUIinstances.- Parameters:
servlet- the servlet owning this servicedeploymentConfiguration- the configuration to run with
-
MockService
public MockService(com.vaadin.flow.server.VaadinServlet servlet, com.vaadin.flow.function.DeploymentConfiguration deploymentConfiguration, UIFactory uiFactory) Creates a service whose sessions produce UIs from the given factory.- Parameters:
servlet- the servlet owning this servicedeploymentConfiguration- the configuration to run withuiFactory- creates the UI of the session that replaces a closed session; it must return a new instance every time, or a test inherits the previous test's state
-
-
Method Details
-
getUiFactory
Returns the factory creating theUIof the session that replaces a closed session of this service.- Returns:
- the UI factory
-
isAtmosphereAvailable
protected boolean isAtmosphereAvailable()- Overrides:
isAtmosphereAvailablein classcom.vaadin.flow.server.VaadinService
-
getMainDivId
public String getMainDivId(com.vaadin.flow.server.VaadinSession session, com.vaadin.flow.server.VaadinRequest request) - Overrides:
getMainDivIdin classcom.vaadin.flow.server.VaadinServletService
-
createVaadinSession
protected com.vaadin.flow.server.VaadinSession createVaadinSession(com.vaadin.flow.server.VaadinRequest request) - Overrides:
createVaadinSessionin classcom.vaadin.flow.server.VaadinService
-