Comprehensive testing framework and utilities for Dropwizard applications including JUnit 5 extensions, resource testing, and DAO helpers
—
Runtime configuration modification system enabling test-specific settings including random port assignment and property overrides without modifying configuration files. Essential for creating isolated test environments.
Abstract base class providing configuration override functionality for modifying Dropwizard application settings at runtime during testing.
/**
* Abstract base class for runtime configuration overrides
*/
public abstract class ConfigOverride {
// Static factory methods for simple key-value overrides
/**
* Create a simple configuration override with default prefix
* @param key Configuration property key (will be prefixed with "dw.")
* @param value Configuration property value
* @return ConfigOverride instance for the key-value pair
*/
public static ConfigOverride config(String key, String value);
/**
* Create a configuration override with custom prefix
* @param propertyPrefix Custom prefix for the configuration property
* @param key Configuration property key
* @param value Configuration property value
* @return ConfigOverride instance for the prefixed key-value pair
*/
public static ConfigOverride config(String propertyPrefix, String key, String value);
// Static factory methods for lazy-evaluated overrides
/**
* Create a configuration override with lazy-evaluated value
* @param key Configuration property key (will be prefixed with "dw.")
* @param value Supplier providing the configuration value when needed
* @return ConfigOverride instance with lazy evaluation
*/
public static ConfigOverride config(String key, Supplier<String> value);
/**
* Create a configuration override with custom prefix and lazy evaluation
* @param propertyPrefix Custom prefix for the configuration property
* @param key Configuration property key
* @param value Supplier providing the configuration value when needed
* @return ConfigOverride instance with custom prefix and lazy evaluation
*/
public static ConfigOverride config(String propertyPrefix, String key, Supplier<String> value);
// Static factory methods for random port assignment
/**
* Create random port assignments for server.applicationConnectors[0].port and
* server.adminConnectors[0].port using default prefix
* @return ConfigOverride instance for random port assignment
*/
public static ConfigOverride randomPorts();
/**
* Create random port assignments with custom property prefix
* @param propertyPrefix Custom prefix for port configuration properties
* @return ConfigOverride instance for random port assignment with custom prefix
*/
public static ConfigOverride randomPorts(String propertyPrefix);
// Abstract lifecycle methods
/**
* Apply the configuration override to system properties
* Called before application startup
*/
public abstract void addToSystemProperties();
/**
* Remove the configuration override from system properties
* Called after application shutdown for cleanup
*/
public abstract void removeFromSystemProperties();
// Constants
/**
* Default property prefix used by Dropwizard configuration system
*/
public static final String DEFAULT_PREFIX = "dw.";
}Usage Examples:
// Simple property override
ConfigOverride dbOverride = ConfigOverride.config("database.url", "jdbc:h2:mem:test");
// Custom prefix override
ConfigOverride customOverride = ConfigOverride.config("myapp.", "feature.enabled", "true");
// Lazy evaluation for dynamic values
ConfigOverride dynamicOverride = ConfigOverride.config("timestamp",
() -> String.valueOf(System.currentTimeMillis()));
// Random port assignment (most common use case)
ConfigOverride randomPorts = ConfigOverride.randomPorts();
// Random ports with custom prefix
ConfigOverride customRandomPorts = ConfigOverride.randomPorts("myapp.");
// Use with DropwizardTestSupport
DropwizardTestSupport<MyConfiguration> testSupport =
new DropwizardTestSupport<>(
MyApplication.class,
"test-config.yml",
ConfigOverride.randomPorts(),
ConfigOverride.config("database.url", "jdbc:h2:mem:test"),
ConfigOverride.config("redis.enabled", "false")
);
// Multiple overrides for complex test scenarios
ConfigOverride[] overrides = {
ConfigOverride.randomPorts(),
ConfigOverride.config("database.url", "jdbc:h2:mem:test"),
ConfigOverride.config("database.user", "sa"),
ConfigOverride.config("database.password", ""),
ConfigOverride.config("logging.level", "DEBUG"),
ConfigOverride.config("metrics.enabled", "false")
};
DropwizardTestSupport<MyConfiguration> testSupport =
new DropwizardTestSupport<>(MyApplication.class, "test-config.yml", overrides);Concrete implementation of ConfigOverride for specific key-value configuration overrides. This class is package-private but is created by the ConfigOverride.config() factory methods.
/**
* Concrete implementation for key-value configuration overrides
* Created by ConfigOverride.config() factory methods
*/
class ConfigOverrideValue extends ConfigOverride {
// Package-private implementation class
// Use ConfigOverride.config() factory methods to create instances
}Concrete implementation of ConfigOverride for automatic random port assignment. This class is package-private but is created by the ConfigOverride.randomPorts() factory methods.
/**
* Concrete implementation for random port assignment
* Created by ConfigOverride.randomPorts() factory methods
*/
class ConfigOverrideRandomPorts extends ConfigOverride {
// Package-private implementation class
// Use ConfigOverride.randomPorts() factory methods to create instances
}// H2 in-memory database for testing
ConfigOverride.config("database.url", "jdbc:h2:mem:test"),
ConfigOverride.config("database.user", "sa"),
ConfigOverride.config("database.password", ""),
ConfigOverride.config("database.driverClass", "org.h2.Driver")
// PostgreSQL test database
ConfigOverride.config("database.url", "jdbc:postgresql://localhost:5432/test_db"),
ConfigOverride.config("database.user", "test_user"),
ConfigOverride.config("database.password", "test_password")// Enable debug logging for tests
ConfigOverride.config("logging.level", "DEBUG"),
ConfigOverride.config("logging.loggers.com.mycompany", "TRACE")
// Disable logging for performance tests
ConfigOverride.config("logging.level", "OFF")// Disable external service integrations
ConfigOverride.config("externalServices.enabled", "false"),
ConfigOverride.config("caching.enabled", "false"),
ConfigOverride.config("metrics.enabled", "false")
// Enable test-specific features
ConfigOverride.config("testMode.enabled", "true"),
ConfigOverride.config("testData.autoLoad", "true")// Random ports (most common)
ConfigOverride.randomPorts()
// Specific ports for integration tests
ConfigOverride.config("server.applicationConnectors[0].port", "8080"),
ConfigOverride.config("server.adminConnectors[0].port", "8081")
// Custom connector configurations
ConfigOverride.config("server.applicationConnectors[0].type", "http"),
ConfigOverride.config("server.applicationConnectors[0].bindHost", "localhost")// Disable authentication for testing
ConfigOverride.config("auth.enabled", "false"),
ConfigOverride.config("csrf.enabled", "false")
// Test-specific authentication
ConfigOverride.config("auth.testMode", "true"),
ConfigOverride.config("auth.testUser", "test@example.com")Install with Tessl CLI
npx tessl i tessl/maven-io-dropwizard--dropwizard-testing