Enum HttpClientStrategy

java.lang.Object
java.lang.Enum<HttpClientStrategy>
com.github.mjeanroy.junit.servers.client.HttpClientStrategy
All Implemented Interfaces:
Serializable, Comparable<HttpClientStrategy>, java.lang.constant.Constable

public enum HttpClientStrategy extends Enum<HttpClientStrategy>
Available strategies that can be used to build appropriate implementation of http client.

Currently, following strategies are available:

How the "best" strategy is selected:
Classpath detection is implemented in this order:

  1. If OkHttp library is detected, this strategy is automatically selected.
  2. If async-http-client is detected, this strategy is automatically (note that this strategy will be skipped with a jdk < 8, since this library requires Java 8).
  3. Third test is ning-async-http-client, and it will be selected if library is detected.
  4. Finally, apache httpcomponent will be selected if available.
  5. If none of these libraries are available, an exception will be thrown.
  • Enum Constant Details

  • Method Details

    • values

      public static HttpClientStrategy[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static HttpClientStrategy valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • build

      public HttpClient build(EmbeddedServer<? extends AbstractConfiguration> server)
      Return the http client implementation.
      Parameters:
      server - Embedded server.
      Returns:
      Http client.
      Throws:
      UnsupportedOperationException - If the runtime environment does not allow the strategy (such as: the library has not been imported).
    • build

      public HttpClient build(HttpClientConfiguration configuration, EmbeddedServer<? extends AbstractConfiguration> server)
      Return the http client implementation.
      Parameters:
      configuration - HTTP Client configuration.
      server - Embedded server.
      Returns:
      Http client.
      Throws:
      UnsupportedOperationException - If the runtime environment does not allow the strategy (such as: the library has not been imported).
    • support

      public abstract boolean support()
      Check if the strategy can be used as it is supported by the runtime environment.
      Returns:
      true if the strategy can be instantiated, false otherwise.