Overview
Service is the abstract base class for all TNB services. It provides a common structure for managing accounts, clients, and validation components. Services implement JUnit 5 lifecycle callbacks for setup and teardown.
Class signature
software.tnb.common.service
Type parameters:
A- Account type that extendsAccountC- Client type (service-specific)V- Validation type that extendsValidation
Properties
The account instance containing credentials and connection details for the service
The client instance used to interact with the service
The validation instance providing test utilities and assertion methods
Methods
account()
Returns the account instance for this service. The account is lazily initialized using AccountFactory.The Account instance for this service
client()
Returns the client instance for this service.The client instance for interacting with the service
This method is protected and typically used internally by service implementations.
validation()
Returns the validation instance for this service, which provides methods for testing and verification.The Validation instance for this service
Lifecycle methods
Service implements JUnit 5 extension callbacks:beforeAll(ExtensionContext)
Called before all tests. Override this method to set up the service (deploy containers, initialize clients, etc.).afterAll(ExtensionContext)
Called after all tests. Override this method to clean up the service (stop containers, close connections, etc.).Implementation example
Here’s how to extend the Service class:Generic type resolution
The Service class uses reflection to automatically determine the generic type parameters at runtime. This enables:- Automatic account creation via AccountFactory
- Type-safe client initialization
- Proper validation instance creation
Account instances are created lazily on first access using the AccountFactory.
Common service patterns
Related
- ServiceFactory - Factory for creating Service instances
- ConfigurableService - Extended service with configuration support
- AccountFactory - Factory for creating Account instances