Package com.vaadin.browserless
Class BrowserlessTestSpringLookupInitializer
java.lang.Object
com.vaadin.flow.di.LookupInitializer
com.vaadin.flow.spring.SpringLookupInitializer
com.vaadin.browserless.BrowserlessTestSpringLookupInitializer
- All Implemented Interfaces:
com.vaadin.flow.di.AbstractLookupInitializer,org.springframework.test.context.TestExecutionListener
public class BrowserlessTestSpringLookupInitializer
extends com.vaadin.flow.spring.SpringLookupInitializer
implements org.springframework.test.context.TestExecutionListener
A SpringLookupInitializer that adapts Spring ApplicationContext to
WebApplicationContext and registers it into ServletContext so that lookup can
be initialized correctly.
For internal use only.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.di.LookupInitializer
com.vaadin.flow.di.LookupInitializer.AppShellPredicateImpl, com.vaadin.flow.di.LookupInitializer.LookupImpl, com.vaadin.flow.di.LookupInitializer.ResourceProviderImpl -
Field Summary
Fields inherited from class com.vaadin.flow.di.LookupInitializer
ONE_IMPL_REQUIRED, SEVERAL_IMPLS, SPI -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterTestMethod(org.springframework.test.context.TestContext testContext) voidbeforeTestMethod(org.springframework.test.context.TestContext testContext) static voidClears the application context for the current thread.static org.springframework.context.ApplicationContextReturns the application context currently registered for this thread, ornullif none is set.voidinitialize(com.vaadin.flow.server.VaadinContext context, Map<Class<?>, Collection<Class<?>>> services, com.vaadin.flow.function.VaadinApplicationInitializationBootstrap bootstrap) voidprepareTestInstance(org.springframework.test.context.TestContext testContext) static voidsetApplicationContext(org.springframework.context.ApplicationContext appCtx) Sets the application context to be used by the lookup initializer.Methods inherited from class com.vaadin.flow.spring.SpringLookupInitializer
createLookupMethods inherited from class com.vaadin.flow.di.LookupInitializer
ensureService, getDefaultImplementations, instantiateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.test.context.TestExecutionListener
afterTestClass, afterTestExecution, beforeTestClass, beforeTestExecution
-
Constructor Details
-
BrowserlessTestSpringLookupInitializer
public BrowserlessTestSpringLookupInitializer()
-
-
Method Details
-
prepareTestInstance
public void prepareTestInstance(org.springframework.test.context.TestContext testContext) throws Exception - Specified by:
prepareTestInstancein interfaceorg.springframework.test.context.TestExecutionListener- Throws:
Exception
-
beforeTestMethod
public void beforeTestMethod(org.springframework.test.context.TestContext testContext) throws Exception - Specified by:
beforeTestMethodin interfaceorg.springframework.test.context.TestExecutionListener- Throws:
Exception
-
afterTestMethod
public void afterTestMethod(org.springframework.test.context.TestContext testContext) throws Exception - Specified by:
afterTestMethodin interfaceorg.springframework.test.context.TestExecutionListener- Throws:
Exception
-
setApplicationContext
public static void setApplicationContext(org.springframework.context.ApplicationContext appCtx) Sets the application context to be used by the lookup initializer.This is used by
SpringBrowserlessApplicationContextto configure the Spring context for multi-user testing without relying on theTestExecutionListenerlifecycle.- Parameters:
appCtx- the Spring application context
-
clearApplicationContext
public static void clearApplicationContext()Clears the application context for the current thread.Companion to
setApplicationContext(ApplicationContext)used bySpringBrowserlessApplicationContextto release the ThreadLocal when an application context is closed outside theTestExecutionListenerlifecycle. -
getApplicationContext
public static org.springframework.context.ApplicationContext getApplicationContext()Returns the application context currently registered for this thread, ornullif none is set.- Returns:
- the registered application context, or
null
-
initialize
public void initialize(com.vaadin.flow.server.VaadinContext context, Map<Class<?>, Collection<Class<?>>> services, com.vaadin.flow.function.VaadinApplicationInitializationBootstrap bootstrap) throws jakarta.servlet.ServletException- Specified by:
initializein interfacecom.vaadin.flow.di.AbstractLookupInitializer- Overrides:
initializein classcom.vaadin.flow.spring.SpringLookupInitializer- Throws:
jakarta.servlet.ServletException
-