Class TestResourcesClientFactory
TestResourcesClient.
Because this client is used in services which are loaded via
service loading during application context building, we can't use
regular dependency injection, so this factory creates an application
context to create the client.-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable TestResourcesClientextractFrom(io.micronaut.context.ApplicationContext context) Extracts theTestResourcesClientfrom the givenApplicationContext.static Optional<TestResourcesClient> Tries to configure a test resources client by looking for configuration in conventional places.static Optional<TestResourcesClient> fromFileSystem(Path location) Tries to configure a test resources client from properties configuration file found on a specific file system location.static Optional<TestResourcesClient> Returns a test resources client configured via system properties.
-
Method Details
-
findByConvention
Tries to configure a test resources client by looking for configuration in conventional places. It will first look for the configuration as system properties, which is the most reliable way for the client to figure out how to connect to the server.If not found, then it will try to read configuration from the working directory, and then, from the user home. It is recommended that consumers prefer passing the configuration via system properties in order to support all possible options to configure the client (in particular, shared mode or namespaces, which is not possible to figure out via standard file system lookups).
- Returns:
- a configured client, or an empty optional.
-
fromFileSystem
Tries to configure a test resources client from properties configuration file found on a specific file system location.- Parameters:
location- the path to the configuration file- Returns:
- a configured client if found, otherwise an empty optional
-
fromSystemProperties
Returns a test resources client configured via system properties.The
micronaut.test.resources.enabledsystem property is read on every call, before any cached client: while it is set to anything other thantrue(ignoring case), this method returns a no-op client and leaves the cached client in place. Since it is a system property, it applies to every lookup made in the JVM while it is set, including those of application contexts starting on other threads.- Returns:
- the cached client or a newly created one, a no-op client if test
resources are disabled, or an empty optional if no client is cached and
micronaut.test.resources.server.uriis not set.
-
extractFrom
public static @Nullable TestResourcesClient extractFrom(io.micronaut.context.ApplicationContext context) Extracts theTestResourcesClientfrom the givenApplicationContext.- Parameters:
context- the application context- Returns:
- the test resources client
-