Class ExtensionBuilder<T extends ExtensionBuilder,​C extends ExtensionConfig>

    • Constructor Detail

      • ExtensionBuilder

        public ExtensionBuilder​(C cfg)
    • Method Detail

      • configOverrides

        public T configOverrides​(java.lang.String... values)
        Specifies configuration overrides pairs in format: "key: value". Might be called multiple times (values appended).

        Note that overrides order is not predictable so don't specify multiple values for the same property (see DropwizardTestSupport holds overrides in Set).

        Parameters:
        values - overriding configuration values in "key: value" format
        Returns:
        builder instance for chained calls
        See Also:
        for using objects directly
      • configOverrides

        @SafeVarargs
        public final <K extends io.dropwizard.testing.ConfigOverride & ConfigurablePrefixT configOverrides​(K... values)
        Direct ConfigOverride objects support. In most cases, it is simpler to use pure strings with configOverrides(String...). Direct objects may be useful when provided value must be lazy evaluated (e.g. it is obtained from some other junit extension).

        IMPORTANT: provided values must implement ConfigurablePrefix interface so guicey could insert correct prefix, used by current test (required for parallel tests as all config overrides eventually stored in system properties).

        May be called multiple times (values appended).

        Type Parameters:
        K - value type
        Parameters:
        values - overriding configuration values
        Returns:
        builder instance for chained calls
        See Also:
        for an exmample of required implementation, for supplier shortcut
      • configOverride

        public T configOverride​(java.lang.String key,
                                java.util.function.Supplier<java.lang.String> supplier)
        Register config override with a supplier. Useful for values with delayed resolution (e.g. provided by some other extension).

        Note that overrides order is not predictable so don't specify multiple values for the same property (see DropwizardTestSupport holds overrides in Set).

        Parameters:
        key - configuration key
        supplier - value supplier
        Returns:
        builder instance for chained calls
      • configOverrideByExtension

        public T configOverrideByExtension​(org.junit.jupiter.api.extension.ExtensionContext.Namespace namespace,
                                           java.lang.String key)
        Shortcut for configOverrideByExtension( org.junit.jupiter.api.extension.ExtensionContext.Namespace, String, String) for cases when storage key and configuration path is the same. If possible, prefer this method for simplicity.
        Parameters:
        namespace - junit storage namespace to resolve value in
        key - value name in namespace and overriding property name
        Returns:
        builder instance for chained calls
      • configOverrideByExtension

        public T configOverrideByExtension​(org.junit.jupiter.api.extension.ExtensionContext.Namespace namespace,
                                           java.lang.String storageKey,
                                           java.lang.String configPath)
        Override configuration value from 3rd party junit extension. Such value must be stored by extension in the junit store with provided namespace (for simple cases use ExtensionContext.Namespace.GLOBAL). It is advised to use the same storage key as configuration path (for simplicity). Value must be initialized in BeforeAllCallback because guicey initialize config overrides under this stage.

        WARNING: keep in mind that your extension must be executed before guicey because otherwise value would not be taken into account. To highlight such cases, guicey would put a warning in logs indicating absent value in configured storage.

        Such complication is required for a very special cases when parallel tests execution must be used together with some common extension (for example, starting database) declared in base class with a static field. Using test storage is the only way to guarantee different values in parallel tests.

        As an alternative, you can use TestEnvironmentSetup implementation, registered directly into guicey extensions (would be called exactly before and after test support object creation and destruction).

        Parameters:
        namespace - junit storage namespace to resolve value in
        storageKey - value name in namespace
        configPath - overriding property name
        Returns:
        builder instance for chained calls
      • hooks

        @SafeVarargs
        public final T hooks​(java.lang.Class<? extends GuiceyConfigurationHook>... hooks)
        Hooks provide access to guice builder allowing application-level customization of application context in tests.

        Anonymous implementation could be simply declared as field: @EnableHook static GuiceyConfigurationHook hook = builder -> builder.disableExtension( Something.class). Non-static fields may be used only when extension is registered with non-static field (static fields would be also counted in this case). All annotated fields will be detected automatically and objects registered. Fields declared in base test classes are also counted.

        Parameters:
        hooks - hook classes to use
        Returns:
        builder instance for chained calls
      • hooks

        public T hooks​(GuiceyConfigurationHook... hooks)
        May be used for quick configurations with lambda:
        
         .hooks(builder -> builder.modules(new DebugModule()))
         
        May be called multiple times (values appended).

        Anonymous implementation could be simply declared as field: @EnableHook static GuiceyConfigurationHook hook = builder -> builder.disableExtension( Something.class). Non-static fields may be used only when extension is registered with non-static field (static fields would be also counted in this case). All annotated fields will be detected automatically and objects registered. Fields declared in base test classes are also counted.

        Parameters:
        hooks - hook instances (may be lambdas)
        Returns:
        builder instance for chained calls
      • debug

        public T debug()
        Enables debug output for extension: used setup objects, hooks and applied config overrides. Might be useful for concurrent tests too because each message includes configuration prefix (exactly pointing to context test or method).

        Configuration overrides are printed after application startup (but before the test) because overridden values are resolved from system properties (applied by DropwizardTestSupport.before()). If application startup failed, no configuration overrides would be printed (because dropwizard would immediately clean up system properties). Using system properties is the only way to receive actually applied configuration value because property overrides might be implemented as value providers and potentially return different values.

        System property might be used to enable debug mode: -Dguicey.extensions.debug=true. Or alias in code: TestSupport.debugExtensions().

        Returns:
        builder instance for chained calls
      • reuseApplication

        public T reuseApplication()
        By default, new application instance is started for each test. If you want to re-use the same application instance between several tests then put extension declaration in BASE test class and enable reuse option: all tests derived from this base class would use the same application instance.

        You may have multiple base classes with reusable application declaration (different test hierarchies) - in this case, multiple applications would be kept running during tests execution.

        All other extensions (without enabled re-use) will start new applications: take this into account to prevent port clashes with already started reusable apps.

        Reused application instance would be stopped after all tests execution.

        Returns:
        builder instance for chained calls
      • clientFactory

        public T clientFactory​(TestClientFactory factory)
        Use custom jersey client builder for ClientSupport object.
        Parameters:
        factory - factory implementation
        Returns:
        builder instance for chained calls