Class BrowserlessTestSpringLookupInitializer
- All Implemented Interfaces:
AbstractLookupInitializer,org.springframework.test.context.TestExecutionListener
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.di.LookupInitializer
LookupInitializer.AppShellPredicateImpl, LookupInitializer.LookupImpl, 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(VaadinContext context, Map<Class<?>, Collection<Class<?>>> services, VaadinApplicationInitializationBootstrap bootstrap) Creates a newLookupinstance, initializes it and passes it to the providedbootstrap.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(VaadinContext context, Map<Class<?>, Collection<Class<?>>> services, VaadinApplicationInitializationBootstrap bootstrap) throws jakarta.servlet.ServletExceptionDescription copied from interface:AbstractLookupInitializerCreates a newLookupinstance, initializes it and passes it to the providedbootstrap.The method should creates a new initialized
Lookupinstance. In some cases it's not possible to create the instance right away when the method is called. To be able to support this usecase the method contract doesn't require to return theLookupinstance. Instead the created instance should be passed to the providedbootstrapconsumer once the instance is created and completely initialized. Thebootstrapwill start the application initialization which otherwise is postponed until aLookupbecomes available.The implementation must use the provided
bootstrapto pass theLookupinstance otherwise the web application based on thisLookupInitializerwill never be bootstrapped.The provided
servicesmap contains service implementations found in application classpath using@HandlesTypesannotation declared forLookupServletContainerInitializer.- Specified by:
initializein interfaceAbstractLookupInitializer- Overrides:
initializein classSpringLookupInitializer- Parameters:
context- a Vaadin context to run initialization forservices- the map of internal services with their implementations found in the application classpathbootstrap- the web application bootstrap- Throws:
jakarta.servlet.ServletException- if initialization failed
-