Skip to main content

Overview

The Deployable interface defines the contract for managing the complete lifecycle of a service deployment in TNB. It extends JUnit’s BeforeAllCallback and AfterAllCallback to integrate seamlessly with test execution. Package: software.tnb.common.deployment Extends: BeforeAllCallback, AfterAllCallback

Core methods

deploy()

void deploy()
Deploys the service. This method is responsible for starting and initializing the service in the target environment.
This method is called automatically by beforeAll() when used as a JUnit extension.

undeploy()

void undeploy()
Undeploys the service. This method tears down and removes the service from the target environment.
This method is called automatically by afterAll() when used as a JUnit extension.

openResources()

void openResources()
Opens all resources needed after the service is deployed, such as initializing clients and establishing connections.
This method is called after deploy() completes successfully.

closeResources()

void closeResources()
Closes all resources before the service is undeployed, performing cleanup of clients and connections.
This method is called before undeploy() is invoked.

getLogs()

String getLogs()
Retrieves logs from the deployed service.
return
String
The service logs as a string.

Lifecycle methods

beforeAll()

default void beforeAll(ExtensionContext extensionContext) throws Exception
JUnit extension hook that executes before all tests. Automatically calls deploy() followed by openResources().
extensionContext
ExtensionContext
The JUnit extension context.
Exceptions are caught and printed before re-throwing to prevent JUnit from swallowing stack traces.

afterAll()

default void afterAll(ExtensionContext extensionContext) throws Exception
JUnit extension hook that executes after all tests. Automatically calls closeResources() followed by undeploy().
extensionContext
ExtensionContext
The JUnit extension context.

Utility methods

restart()

default void restart()
Restarts the service by executing the full lifecycle: close resources, undeploy, deploy, and open resources.
The restart sequence is: closeResources()undeploy()deploy()openResources()

enabled()

default boolean enabled()
Determines whether this deployable is enabled for the current environment.
return
boolean
default:"true"
Returns true by default, indicating the deployable is enabled.

priority()

default int priority()
Defines the deployment priority. Lower values indicate higher priority.
return
int
default:"0"
Returns 0 by default, indicating neutral priority.

Usage example

public class MyService implements Deployable {
    @Override
    public void deploy() {
        // Deploy service logic
    }

    @Override
    public void undeploy() {
        // Undeploy service logic
    }

    @Override
    public void openResources() {
        // Initialize clients
    }

    @Override
    public void closeResources() {
        // Clean up clients
    }

    @Override
    public String getLogs() {
        return "service logs";
    }
}

Implementation notes

Implementations must provide concrete behavior for all abstract methods: deploy(), undeploy(), openResources(), closeResources(), and getLogs().
The interface provides sensible defaults for JUnit lifecycle hooks, making it easy to use deployables as test extensions.

Build docs developers (and LLMs) love