Package no.mnemonic.commons.junit.docker
Class DockerResource.Builder<T extends DockerResource.Builder<?>>
java.lang.Object
no.mnemonic.commons.junit.docker.DockerResource.Builder<T>
- Direct Known Subclasses:
CassandraDockerResource.Builder
,ElasticSearchDockerResource.Builder
,MariaDBDockerResource.Builder
- Enclosing class:
- DockerResource
Builder to create a DockerResource.
Subclasses of DockerResource can also define own builders extending this builder in order to be able to configure
the same properties. The configurable properties are exposed as protected fields which can be passed to the
constructor of a subclass. This constructor in turn should pass them to the constructor}.
See CassandraDockerResource.Builder
as an example.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddApplicationPort
(int applicationPort) Add a single application port which will be used inside the container and exposed outside of the container by mapping to a port inside the range specified withsetExposedPortsRange(String)
or a random port.addEnvironmentVariable
(String key, String value) Add an additional environment variable for the container.build()
Build a configured DockerResource.setApplicationPorts
(Set<Integer> applicationPorts) Set application ports which will be used inside the container and exposed outside of the container by mapping to ports inside the range specified withsetExposedPortsRange(String)
or random ports.setDockerClientResolver
(Supplier<org.mandas.docker.client.DockerClient> dockerClientResolver) Override the default behaviour of how a DockerClient will be created by providing a custom resolver function.setEnvironmentVariables
(MapUtils.Pair<String, String>... variables) Set multiple environment variables for the container.setExposedPortsRange
(String exposedPortsRange) Set port range which will be used for exposing ports inside the container to the outside of the container.setImageName
(String imageName) Set image name of container to use.setReachabilityTimeout
(int reachabilityTimeout) Set timeout in seconds until test for container reachability stops.setSkipPullDockerImage
(boolean skipPullDockerImage) Skip pulling the image if set to true.Configure DockerResource to skip test for container reachability.
-
Field Details
-
imageName
-
applicationPorts
-
exposedPortsRange
-
reachabilityTimeout
protected int reachabilityTimeout -
skipReachabilityCheck
protected boolean skipReachabilityCheck -
skipPullDockerImage
protected boolean skipPullDockerImage -
dockerClientResolver
-
environmentVariables
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
build
Build a configured DockerResource.- Returns:
- Configured DockerResource
-
setImageName
Set image name of container to use. The image must be available in Docker, it is not automatically pulled!- Parameters:
imageName
- Image name- Returns:
- Builder
-
setApplicationPorts
Set application ports which will be used inside the container and exposed outside of the container by mapping to ports inside the range specified withsetExposedPortsRange(String)
or random ports.Also see
DockerResource.getExposedHostPort(int)
for more information.- Parameters:
applicationPorts
- Set of application ports- Returns:
- Builder
-
addApplicationPort
Add a single application port which will be used inside the container and exposed outside of the container by mapping to a port inside the range specified withsetExposedPortsRange(String)
or a random port.Also see
DockerResource.getExposedHostPort(int)
for more information.- Parameters:
applicationPort
- Single application port- Returns:
- Builder
-
setExposedPortsRange
Set port range which will be used for exposing ports inside the container to the outside of the container.- Parameters:
exposedPortsRange
- String in format "firstPort-lastPort" which is used for setting a range of ports- Returns:
- Builder
-
setReachabilityTimeout
Set timeout in seconds until test for container reachability stops. Defaults to 30 seconds if not set.Also see
DockerResource.isContainerReachable()
for more information.- Parameters:
reachabilityTimeout
- Timeout in seconds- Returns:
- Builder
-
skipReachabilityCheck
Configure DockerResource to skip test for container reachability. Useful if application code implements similar functionality.- Returns:
- Builder
-
setSkipPullDockerImage
Skip pulling the image if set to true. Default is to pull the image before running- Parameters:
skipPullDockerImage
- whether to pull the image- Returns:
- Builder
-
setDockerClientResolver
public T setDockerClientResolver(Supplier<org.mandas.docker.client.DockerClient> dockerClientResolver) Override the default behaviour of how a DockerClient will be created by providing a custom resolver function. Should be used with care, but useful for providing a mock during unit testing, for instance.- Parameters:
dockerClientResolver
- Customer DockerClient resolver function- Returns:
- Builder
-
setEnvironmentVariables
Set multiple environment variables for the container.- Parameters:
variables
- Array of key-value pairs- Returns:
- Builder
-
addEnvironmentVariable
Add an additional environment variable for the container.- Parameters:
key
- Variable namevalue
- Variable value- Returns:
- Builder
-