Class GuiceyTestSupport<C extends io.dropwizard.Configuration>

  • Type Parameters:
    C - configuration type

    public class GuiceyTestSupport<C extends io.dropwizard.Configuration>
    extends io.dropwizard.testing.DropwizardTestSupport<C>
    An alternative to DropwizardTestSupport which does not run jetty (web part) allowing to test only guice context. Internally, TestCommand used instead of ServerCommand.

    Supposed to be used in cases when application startup fail must be tested: new GuiceyTestSupport(MyApp.class, (String) null).before().

    Since:
    03.02.2022
    • Nested Class Summary

      • Nested classes/interfaces inherited from class io.dropwizard.testing.DropwizardTestSupport

        io.dropwizard.testing.DropwizardTestSupport.ServiceListener<T extends io.dropwizard.Configuration>
    • Field Summary

      • Fields inherited from class io.dropwizard.testing.DropwizardTestSupport

        application, applicationClass, commandInstantiator, configOverrides, configPath, configSourceProvider, configuration, customPropertyPrefix, environment, explicitConfig, jettyServer, listeners
    • Constructor Summary

      Constructors 
      Constructor Description
      GuiceyTestSupport​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass, C configuration)  
      GuiceyTestSupport​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass, java.lang.String configPath, io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, io.dropwizard.testing.ConfigOverride... configOverrides)  
      GuiceyTestSupport​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass, java.lang.String configPath, io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, java.lang.String customPropertyPrefix, io.dropwizard.testing.ConfigOverride... configOverrides)  
      GuiceyTestSupport​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass, java.lang.String configPath, io.dropwizard.testing.ConfigOverride... configOverrides)  
      GuiceyTestSupport​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass, java.lang.String configPath, java.lang.String customPropertyPrefix, io.dropwizard.testing.ConfigOverride... configOverrides)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void after()  
      <T> T getBean​(com.google.inject.Key<T> key)
      Shortcut for accessing guice beans.
      <T> T getBean​(java.lang.Class<T> type)
      Shortcut for accessing guice beans.
      <T> T run​(TestSupport.RunCallback<T> callback)
      Normally, DropwizardTestSupport.before() and after() methods are called separately.
      • Methods inherited from class io.dropwizard.testing.DropwizardTestSupport

        addListener, before, getAdminPort, getApplication, getConfiguration, getEnvironment, getLocalPort, getObjectMapper, getPort, manage, newApplication
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GuiceyTestSupport

        public GuiceyTestSupport​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass,
                                 @Nullable
                                 java.lang.String configPath,
                                 io.dropwizard.testing.ConfigOverride... configOverrides)
      • GuiceyTestSupport

        public GuiceyTestSupport​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass,
                                 @Nullable
                                 java.lang.String configPath,
                                 @Nullable
                                 io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider,
                                 io.dropwizard.testing.ConfigOverride... configOverrides)
      • GuiceyTestSupport

        public GuiceyTestSupport​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass,
                                 @Nullable
                                 java.lang.String configPath,
                                 @Nullable
                                 io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider,
                                 @Nullable
                                 java.lang.String customPropertyPrefix,
                                 io.dropwizard.testing.ConfigOverride... configOverrides)
      • GuiceyTestSupport

        public GuiceyTestSupport​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass,
                                 @Nullable
                                 java.lang.String configPath,
                                 @Nullable
                                 java.lang.String customPropertyPrefix,
                                 io.dropwizard.testing.ConfigOverride... configOverrides)
      • GuiceyTestSupport

        public GuiceyTestSupport​(java.lang.Class<? extends io.dropwizard.Application<C>> applicationClass,
                                 C configuration)
    • Method Detail

      • run

        public <T> T run​(@Nullable
                         TestSupport.RunCallback<T> callback)
                  throws java.lang.Exception
        Normally, DropwizardTestSupport.before() and after() methods are called separately. This method is a shortcut mostly for errors testing when DropwizardTestSupport.before() assumed to fail to make sure after() will be called in any case: testSupport.run(null).
        Type Parameters:
        T - result type
        Parameters:
        callback - callback (may be null)
        Returns:
        callback result
        Throws:
        java.lang.Exception - any appeared exception
      • getBean

        public <T> T getBean​(java.lang.Class<T> type)
        Shortcut for accessing guice beans.
        Type Parameters:
        T - bean type
        Parameters:
        type - target bean type
        Returns:
        bean instance
      • getBean

        public <T> T getBean​(com.google.inject.Key<T> key)
        Shortcut for accessing guice beans.
        Type Parameters:
        T - bean type
        Parameters:
        key - binding key
        Returns:
        bean instance
      • after

        public void after()
        Overrides:
        after in class io.dropwizard.testing.DropwizardTestSupport<C extends io.dropwizard.Configuration>