Class TestResourcesClientFactory

java.lang.Object
io.micronaut.testresources.client.TestResourcesClientFactory

public final class TestResourcesClientFactory extends Object
A factory responsible for creating a 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 Details

    • findByConvention

      public static Optional<TestResourcesClient> 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

      public static Optional<TestResourcesClient> fromFileSystem(Path location)
      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

      public static Optional<TestResourcesClient> fromSystemProperties()
      Returns a test resources client configured via system properties.

      The micronaut.test.resources.enabled system property is read on every call, before any cached client: while it is set to anything other than true (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.uri is not set.
    • extractFrom

      public static @Nullable TestResourcesClient extractFrom(io.micronaut.context.ApplicationContext context)
      Extracts the TestResourcesClient from the given ApplicationContext.
      Parameters:
      context - the application context
      Returns:
      the test resources client