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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterTestMethod(org.springframework.test.context.TestContext testContext)
     
    void
    beforeTestMethod(org.springframework.test.context.TestContext testContext)
     
    static void
    Clears the application context for the current thread.
    static org.springframework.context.ApplicationContext
    Returns the application context currently registered for this thread, or null if none is set.
    void
    initialize(com.vaadin.flow.server.VaadinContext context, Map<Class<?>,Collection<Class<?>>> services, com.vaadin.flow.function.VaadinApplicationInitializationBootstrap bootstrap)
     
    void
    prepareTestInstance(org.springframework.test.context.TestContext testContext)
     
    static void
    setApplicationContext(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

    createLookup

    Methods inherited from class com.vaadin.flow.di.LookupInitializer

    ensureService, getDefaultImplementations, instantiate

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods 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:
      prepareTestInstance in interface org.springframework.test.context.TestExecutionListener
      Throws:
      Exception
    • beforeTestMethod

      public void beforeTestMethod(org.springframework.test.context.TestContext testContext) throws Exception
      Specified by:
      beforeTestMethod in interface org.springframework.test.context.TestExecutionListener
      Throws:
      Exception
    • afterTestMethod

      public void afterTestMethod(org.springframework.test.context.TestContext testContext) throws Exception
      Specified by:
      afterTestMethod in interface org.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 SpringBrowserlessApplicationContext to configure the Spring context for multi-user testing without relying on the TestExecutionListener lifecycle.

      Parameters:
      appCtx - the Spring application context
    • clearApplicationContext

      public static void clearApplicationContext()
      Clears the application context for the current thread.

      Companion to setApplicationContext(ApplicationContext) used by SpringBrowserlessApplicationContext to release the ThreadLocal when an application context is closed outside the TestExecutionListener lifecycle.

    • getApplicationContext

      public static org.springframework.context.ApplicationContext getApplicationContext()
      Returns the application context currently registered for this thread, or null if 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:
      initialize in interface com.vaadin.flow.di.AbstractLookupInitializer
      Overrides:
      initialize in class com.vaadin.flow.spring.SpringLookupInitializer
      Throws:
      jakarta.servlet.ServletException