Class DefaultTestClientFactory

java.lang.Object
ru.vyarus.dropwizard.guice.test.client.DefaultTestClientFactory
All Implemented Interfaces:
TestClientFactory
Direct Known Subclasses:
ApacheTestClientFactory

public class DefaultTestClientFactory extends Object implements TestClientFactory
Default client factory for ClientSupport. Enables INFO logging of all requests and responses into ClientSupport logger. Auto register multipart feature if it's available in classpath (through dropwizard-froms).

By default, log all requests and responses into system out (console). This could be disabled with disableConsoleLog() method (system property).

NOTE: default HttpUrlConnectorProvider does not support PATCH method on jdk > 16 (requires additional --add-opens). To workaround it, use apache or connection provider.

If client customization is required, extend this class and override configure(org.glassfish.jersey.client.JerseyClientBuilder, io.dropwizard.testing.DropwizardTestSupport) method.

Since:
15.11.2023
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    "Hacked" logger to print everything directly into system out.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    System property name used to disable direct console logs.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    configure(org.glassfish.jersey.client.JerseyClientBuilder builder, io.dropwizard.testing.DropwizardTestSupport<?> support)
    Provides the ability to customize default client in extending class.
    org.glassfish.jersey.client.JerseyClient
    create(io.dropwizard.testing.DropwizardTestSupport<?> support)
    Creates client instance forClientSupport (once per support instance).
    protected jakarta.ws.rs.core.Feature
    Configure logging feature.
    static void
    Disable client logs into system out.
    static void
    Enable client logs into system out.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • USE_LOGGER

      public static final String USE_LOGGER
      System property name used to disable direct console logs.
      See Also:
  • Constructor Details

    • DefaultTestClientFactory

      public DefaultTestClientFactory()
  • Method Details

    • disableConsoleLog

      public static void disableConsoleLog()
      Disable client logs into system out. Instead, logs would go into ClientSupport logger.
    • enableConsoleLog

      public static void enableConsoleLog()
      Enable client logs into system out. Could be used to revert disableConsoleLog() action.
    • create

      public org.glassfish.jersey.client.JerseyClient create(io.dropwizard.testing.DropwizardTestSupport<?> support)
      Description copied from interface: TestClientFactory
      Creates client instance forClientSupport (once per support instance). Called lazily (only before jersey client is actually required to perform call), so the support object should be already initialized.
      Specified by:
      create in interface TestClientFactory
      Parameters:
      support - support object
      Returns:
      client instance
    • createLogger

      protected jakarta.ws.rs.core.Feature createLogger()
      Configure logging feature.
      Returns:
      logging feature
    • configure

      protected void configure(org.glassfish.jersey.client.JerseyClientBuilder builder, io.dropwizard.testing.DropwizardTestSupport<?> support)
      Provides the ability to customize default client in extending class.
      Parameters:
      builder - client builder (pre-configured)
      support - dropwizard support instance (for accessing environment and configuration)