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()
      Creates a new test resources client configured via system properties.
      Returns:
      a new test resources client, if system properties were found.
    • extractFrom

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