Class BrowserlessTestSpringLookupInitializer

All Implemented Interfaces:
AbstractLookupInitializer, org.springframework.test.context.TestExecutionListener

public class BrowserlessTestSpringLookupInitializer extends 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.
  • 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(VaadinContext context, Map<Class<?>,Collection<Class<?>>> services, VaadinApplicationInitializationBootstrap bootstrap) throws jakarta.servlet.ServletException
      Description copied from interface: AbstractLookupInitializer
      Creates a new Lookup instance, initializes it and passes it to the provided bootstrap.

      The method should creates a new initialized Lookup instance. 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 the Lookup instance. Instead the created instance should be passed to the provided bootstrap consumer once the instance is created and completely initialized. The bootstrap will start the application initialization which otherwise is postponed until a Lookup becomes available.

      The implementation must use the provided bootstrap to pass the Lookup instance otherwise the web application based on this LookupInitializer will never be bootstrapped.

      The provided services map contains service implementations found in application classpath using @HandlesTypes annotation declared for LookupServletContainerInitializer.

      Specified by:
      initialize in interface AbstractLookupInitializer
      Overrides:
      initialize in class SpringLookupInitializer
      Parameters:
      context - a Vaadin context to run initialization for
      services - the map of internal services with their implementations found in the application classpath
      bootstrap - the web application bootstrap
      Throws:
      jakarta.servlet.ServletException - if initialization failed