Interface ConfigurationProvider
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
SeBootstrap.Configuration for test instances.
Implementations of this interface can customize how the SeBootstrap instance is
configured for tests. This allows control over port, host, protocol, root path, and other server configuration
options.
Usage
Specify a custom provider on the @RestBootstrap
annotation:
public class CustomPortProvider implements ConfigurationProvider {
@Override
public Configuration getConfiguration(ExtensionContext context) {
return Configuration.builder()
.port(9090)
.build();
}
}
@RestBootstrap(value = MyApp.class, configFactory = CustomPortProvider.class)
public class MyTest {
// SeBootstrap instance will run on port 9090
}
Global Provider via ServiceLoader
Instead of specifying the provider on each test, you can register a global provider via
ServiceLoader. Create a file
META-INF/services/dev.resteasy.junit.extension.api.ConfigurationProvider
containing your implementation's fully-qualified class name.
When a global provider is registered and no explicit configFactory is specified on @RestBootstrap,
the global provider will be used automatically for all tests.
SSL Support
When the test class is annotated with
@SelfSignedCert, implementations can receive the
generated certificate by declaring a field annotated with
@SslCert:
public class CustomSslConfigProvider implements ConfigurationProvider {
@SslCert
private SelfSignedCertificate certificate;
@Override
public Configuration getConfiguration(ExtensionContext context) {
return Configuration.builder()
.port(9090)
.protocol("HTTPS")
.sslContext(certificate.serverSslContext())
.build();
}
}
Requirements
- Must have a public no-argument constructor
- The
getConfiguration(ExtensionContext)method must return a non-null Configuration - Can be registered globally via ServiceLoader or specified per-test via
@RestBootstrap(configFactory = ...)
- Since:
- 1.0
- Author:
- James R. Perkins
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionjakarta.ws.rs.SeBootstrap.ConfigurationgetConfiguration(org.junit.jupiter.api.extension.ExtensionContext context) Provides the configuration for starting aSeBootstrap.Instance.
-
Method Details
-
getConfiguration
jakarta.ws.rs.SeBootstrap.Configuration getConfiguration(org.junit.jupiter.api.extension.ExtensionContext context) Provides the configuration for starting aSeBootstrap.Instance.The default implementation checks for a globally registered provider via
ServiceLoader. If found, that provider's configuration is used. Otherwise, returns the default configuration created bySeBootstrap.Configuration.builder().build().Implementations should override this method to provide custom configuration values such as port, host, protocol, or root path.
- Parameters:
context- the JUnit extension context- Returns:
- the configuration to use for starting the SeBootstrap instance, must not be
null
-