Class BrowserlessApplicationContext.Builder
-
- All Implemented Interfaces:
public class BrowserlessApplicationContext.BuilderBuilder for creating a customized BrowserlessApplicationContext.
Calling withSecurityContextHandler transitions to a SecuredBrowserlessApplicationContext.Builder whose build() returns the credential-typed SecuredBrowserlessApplicationContext.
-
-
Constructor Summary
Constructors Constructor Description BrowserlessApplicationContext.Builder()Creates a builder with no pre-seeded routes.
-
Method Summary
Modifier and Type Method Description BrowserlessApplicationContext.BuilderwithoutRoutes()Disables @Routediscovery for this builder by seeding an empty Routes instance.BrowserlessApplicationContext.BuilderwithViewPackages(Array<String> packages)Adds packages to scan for @Route-annotated views.BrowserlessApplicationContext.BuilderwithViewPackages(Array<Class<out Object>> classes)Adds the packages of the given classes to the set of packages to scan for @Route-annotated views.BrowserlessApplicationContext.BuilderwithComponentTesterPackages(Array<String> packages)Adds packages to scan for ComponentTester implementations annotated with Tests. BrowserlessApplicationContext.BuilderwithComponentTesterPackages(Array<Class<out Object>> classes)Adds the packages of the given classes to the set of packages to scan for ComponentTester implementations annotated with Tests. <C> SecuredBrowserlessApplicationContext.Builder<C>withSecurityContextHandler(SecurityContextHandler<C> handler)Sets the security context handler for multi-user auth isolation and transitions to a credential-typed SecuredBrowserlessApplicationContext.Builder. BrowserlessApplicationContext.BuilderwithServletFactory(BiFunction<Routes, UIFactory, VaadinServlet> factory)Sets a custom servlet factory. BrowserlessApplicationContext.BuilderwithUIFactory(UIFactory uiFactory)Sets the UI factory used when creating UI instances for this application's windows. BrowserlessApplicationContext.BuilderwithLookupServices(Array<Class<out Object>> services)Adds the given Vaadin Lookup service classes to the set configured for this builder. BrowserlessApplicationContext.BuilderwithApplicationProperty(String name, String value)Sets a Vaadin application property (init parameter) for this application. BrowserlessApplicationContext.BuilderwithApplicationProperties(Map<String, String> properties)Sets Vaadin application properties (init parameters) for this application. BrowserlessApplicationContext.BuilderwithFeatureFlags(Array<String> featureIds)Enables the given Vaadin feature flags for this application, overriding the values potentially defined in the vaadin-featureflags. BrowserlessApplicationContext.BuilderwithFeatureFlags(Array<Feature> features)Enables the given Vaadin feature flags for this application, overriding the values potentially defined in the vaadin-featureflags. BrowserlessApplicationContext.BuilderwithFeatureFlag(String featureId, boolean enabled)Enables or disables the given Vaadin feature flag for this application, overriding the value potentially defined in the vaadin-featureflags. BrowserlessApplicationContext.BuilderwithFeatureFlag(Feature feature, boolean enabled)Enables or disables the given Vaadin feature flag for this application, overriding the value potentially defined in the vaadin-featureflags. BrowserlessApplicationContext.BuilderwithConfiguration(BrowserlessConfiguration testConfiguration)Applies the given custom Vaadin configuration to this builder, replacing previously set entries with the same names. BrowserlessApplicationContext.BuilderwithCloseHook(Runnable hook)Registers a hook to be invoked when the built application context is closed. BrowserlessApplicationContextbuild()Builds the application context. -
-
Constructor Detail
-
BrowserlessApplicationContext.Builder
BrowserlessApplicationContext.Builder()
Creates a builder with no pre-seeded routes. Routes are derived from the view packages configured on this builder (or from a full classpath scan when none are configured) at build time.
-
-
Method Detail
-
withoutRoutes
BrowserlessApplicationContext.Builder withoutRoutes()
Disables
@Routediscovery for this builder by seeding an empty Routes instance. build then skips the classpath scan entirely, which is the desired behaviour for ad-hoc component testing where no routed views are needed. Any view packages configured via withViewPackages are ignored once this is set (an explicit Routes instance always wins).- Returns:
this builder
-
withViewPackages
BrowserlessApplicationContext.Builder withViewPackages(Array<String> packages)
Adds packages to scan for
@Route-annotated views. Successive calls accumulate. Ignored when this builder was created with an explicit Routes instance.- Parameters:
packages- package names to scan- Returns:
this builder
-
withViewPackages
BrowserlessApplicationContext.Builder withViewPackages(Array<Class<out Object>> classes)
Adds the packages of the given classes to the set of packages to scan for
@Route-annotated views. Successive calls accumulate. Ignored when this builder was created with an explicit Routes instance.- Parameters:
classes- classes whose packages should be scanned- Returns:
this builder
-
withComponentTesterPackages
BrowserlessApplicationContext.Builder withComponentTesterPackages(Array<String> packages)
Adds packages to scan for ComponentTester implementations annotated with Tests. Successive calls accumulate. Each package is scanned at most once per JVM (see TesterRegistry).
- Parameters:
packages- package names to scan for testers- Returns:
this builder
-
withComponentTesterPackages
BrowserlessApplicationContext.Builder withComponentTesterPackages(Array<Class<out Object>> classes)
Adds the packages of the given classes to the set of packages to scan for ComponentTester implementations annotated with Tests. Successive calls accumulate.
- Parameters:
classes- classes whose packages should be scanned for testers- Returns:
this builder
-
withSecurityContextHandler
<C> SecuredBrowserlessApplicationContext.Builder<C> withSecurityContextHandler(SecurityContextHandler<C> handler)
Sets the security context handler for multi-user auth isolation and transitions to a credential-typed SecuredBrowserlessApplicationContext.Builder. The base builder's accumulated state (servlet factory, UI factory, lookup services, close hooks) is carried over.
- Parameters:
handler- the handler; must not benull- Returns:
a secured builder configured with the given handler
-
withServletFactory
BrowserlessApplicationContext.Builder withServletFactory(BiFunction<Routes, UIFactory, VaadinServlet> factory)
Sets a custom servlet factory. The factory receives the routes and the UIFactory configured via withUIFactory (or its default), and must return a fully configured VaadinServlet. Wiring the
UIFactorythrough the builder ensures the servlet uses the same factory as BrowserlessUIContext window creation, so paths like the legacyafterSessionClosesession-recreation hook don't end up producing UIs of a different type. When unset, a default servlet that uses the configuredUIFactoryis created by build.- Parameters:
factory- the servlet factory- Returns:
this builder
-
withUIFactory
BrowserlessApplicationContext.Builder withUIFactory(UIFactory uiFactory)
Sets the UI factory used when creating UI instances for this application's windows. Defaults to a factory producing MockedUI instances.
- Parameters:
uiFactory- the UI factory- Returns:
this builder
-
withLookupServices
BrowserlessApplicationContext.Builder withLookupServices(Array<Class<out Object>> services)
Adds the given Vaadin Lookup service classes to the set configured for this builder. Successive calls accumulate; the builder starts with an empty set. Calling with no arguments is a no-op.
- Parameters:
services- the service implementation classes to add- Returns:
this builder
-
withApplicationProperty
BrowserlessApplicationContext.Builder withApplicationProperty(String name, String value)
Sets a Vaadin application property (init parameter) for this application. A previously set value for the same name is replaced.
- Parameters:
name- the property name; must not benullvalue- the property value; must not benull- Returns:
this builder
- Since:
25.3
-
withApplicationProperties
BrowserlessApplicationContext.Builder withApplicationProperties(Map<String, String> properties)
Sets Vaadin application properties (init parameters) for this application. Previously set values for the same names are replaced.
- Parameters:
properties- the properties to set; must not benull- Returns:
this builder
- Since:
25.3
-
withFeatureFlags
BrowserlessApplicationContext.Builder withFeatureFlags(Array<String> featureIds)
Enables the given Vaadin feature flags for this application, overriding the values potentially defined in the vaadin-featureflags.properties file or in system properties.
- Parameters:
featureIds- the identifiers of the features to enable; must not benull- Returns:
this builder
- Since:
25.3
-
withFeatureFlags
BrowserlessApplicationContext.Builder withFeatureFlags(Array<Feature> features)
Enables the given Vaadin feature flags for this application, overriding the values potentially defined in the vaadin-featureflags.properties file or in system properties.
- Parameters:
features- the features to enable; must not benull- Returns:
this builder
- Since:
25.3
-
withFeatureFlag
BrowserlessApplicationContext.Builder withFeatureFlag(String featureId, boolean enabled)
Enables or disables the given Vaadin feature flag for this application, overriding the value potentially defined in the vaadin-featureflags.properties file or in system properties.
- Parameters:
featureId- the identifier of the feature; must not benullenabled-trueto enable the feature,falseto disable it- Returns:
this builder
- Since:
25.3
-
withFeatureFlag
BrowserlessApplicationContext.Builder withFeatureFlag(Feature feature, boolean enabled)
Enables or disables the given Vaadin feature flag for this application, overriding the value potentially defined in the vaadin-featureflags.properties file or in system properties.
- Parameters:
feature- the feature; must not benullenabled-trueto enable the feature,falseto disable it- Returns:
this builder
- Since:
25.3
-
withConfiguration
BrowserlessApplicationContext.Builder withConfiguration(BrowserlessConfiguration testConfiguration)
Applies the given custom Vaadin configuration to this builder, replacing previously set entries with the same names.
Useful to reuse a configuration declared with BrowserlessTestConfig on a test class:
BrowserlessApplicationContext.create(b -> b.withViewPackages(MyView.class) .withConfiguration(BrowserlessConfiguration.from(getClass())));- Parameters:
testConfiguration- the configuration to apply; must not benull- Returns:
this builder
- Since:
25.3
-
withCloseHook
BrowserlessApplicationContext.Builder withCloseHook(Runnable hook)
Registers a hook to be invoked when the built application context is closed.
Hooks run in registration order, after users and the Vaadin service have been torn down, exactly once (subsequent
close()calls are no-ops). They are intended for releasing framework-specific state attached during context creation — for example, Spring's lookup-initializer ThreadLocal. A throwing hook does not prevent the remaining hooks from running; any thrown RuntimeExceptions are collected and surfaced fromclose()as a single RuntimeException with the originals attached as suppressed exceptions.- Parameters:
hook- the hook to register; must not benull- Returns:
this builder
-
build
BrowserlessApplicationContext build()
Builds the application context.
- Returns:
a new application context
-
-
-
-