Class ApplicationContainer
java.lang.Object
org.testcontainers.containers.FailureDetectingExternalResource
org.testcontainers.containers.GenericContainer<ApplicationContainer>
org.microshed.testing.testcontainers.ApplicationContainer
- All Implemented Interfaces:
AutoCloseable,org.junit.rules.TestRule,org.testcontainers.containers.Container<ApplicationContainer>,org.testcontainers.containers.ContainerState,org.testcontainers.containers.traits.LinkableContainer,org.testcontainers.containers.wait.strategy.WaitStrategyTarget,org.testcontainers.lifecycle.Startable
public class ApplicationContainer
extends org.testcontainers.containers.GenericContainer<ApplicationContainer>
Represents a MicroProfile, JavaEE, or JakartaEE application running inside a Docker
container.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.testcontainers.containers.Container
org.testcontainers.containers.Container.ExecResult -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA path representing the MicroProfile Health 2.0 readiness checkFields inherited from class org.testcontainers.containers.GenericContainer
CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategyFields inherited from interface org.testcontainers.containers.ContainerState
STATE_HEALTHY -
Constructor Summary
ConstructorsConstructorDescriptionBuilds an instance based on a Dockerfile located atApplicationContainer(String dockerImageName) Builds an instance based on an existing docker image.ApplicationContainer(Path dockerfilePath) Builds an instance using the supplied Dockerfile pathApplicationContainer(Future<String> dockerImageName) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFileSystemBind(String hostPath, String containerPath, org.testcontainers.containers.BindMode mode) voidaddFileSystemBind(String hostPath, String containerPath, org.testcontainers.containers.BindMode mode, org.testcontainers.containers.SelinuxContext selinuxContext) protected voidprotected voidcontainerIsStarting(com.github.dockerjava.api.command.InspectContainerResponse containerInfo) protected voiddoStart()com.github.dockerjava.api.command.InspectContainerResponsegetMappedPort(int originalPort) booleanbooleanbooleanvoidsetContainerIpAddress(String ipAddress) voidsetExposedPorts(List<Integer> exposedPorts) voidsetFirstMappedPort(int port) voidsetWaitStrategy(org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy) waitingFor(org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy) withAppContextRoot(String appContextRoot) withFileSystemBind(String hostPath, String containerPath) withFileSystemBind(String hostPath, String containerPath, org.testcontainers.containers.BindMode mode) withHttpPort(int httpPort) withMpRestClient(Class<?> restClientClass, String hostUri) Configures the application container with the supplied MicroProfile REST Client class that will reference the suppliedhostUrlwithMpRestClient(String restClientClass, String hostUri) Configures the application container with the supplied MicroProfile REST Client class that will reference the suppliedhostUrlwithReadinessPath(String readinessUrl) Sets the path to be used to determine container readiness.withReadinessPath(String readinessUrl, int timeoutSeconds) Sets the path to be used to determine container readiness.withReadinessPath(String readinessUrl, int timeoutSeconds, Integer port) Sets the path to be used to determine container readiness.withReuse(boolean reusable) Methods inherited from class org.testcontainers.containers.GenericContainer
addEnv, addExposedPort, addExposedPorts, addFixedExposedPort, addFixedExposedPort, addLink, apply, canBeReused, containerIsCreated, containerIsStarted, containerIsStarted, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, equals, failed, finished, getBinds, getCommandParts, getContainerId, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getEnv, getEnvMap, getExposedPorts, getExtraHosts, getImage, getIpAddress, getLabels, getLinkedContainers, getLivenessCheckPort, getLivenessCheckPortNumbers, getLivenessCheckPorts, getLogConsumers, getNetwork, getNetworkAliases, getNetworkMode, getPortBindings, getShmSize, getStartupAttempts, getStartupCheckStrategy, getTestHostIpAddress, getTmpFsMapping, getVolumesFroms, getWaitStrategy, getWorkingDirectory, hashCode, isHostAccessible, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWorkingDirectory, start, starting, stop, succeeded, toString, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectoryMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.testcontainers.containers.Container
followOutput, followOutput, self, withEnvMethods inherited from interface org.testcontainers.containers.ContainerState
copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogsMethods inherited from interface org.testcontainers.lifecycle.Startable
close
-
Field Details
-
MP_HEALTH_READINESS_PATH
A path representing the MicroProfile Health 2.0 readiness check- See Also:
-
-
Constructor Details
-
ApplicationContainer
public ApplicationContainer()Builds an instance based on a Dockerfile located at${user.dir}/Dockerfile}or${user.dir}/src/main/docker/Dockerfile. If no Dockerfile can be discovered, aServerAdaptermay be used to supply a default Dockerfile. A docker build will be performed before the resulting container image is started. -
ApplicationContainer
Builds an instance using the supplied Dockerfile path- Parameters:
dockerfilePath- APathindicating the Dockerfile to be used to build the container image. A docker build will be performed before the resulting container image is started.
-
ApplicationContainer
-
ApplicationContainer
Builds an instance based on an existing docker image.- Parameters:
dockerImageName- The docker image to be used for this instance
-
-
Method Details
-
configure
protected void configure()- Overrides:
configurein classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
setContainerIpAddress
-
setFirstMappedPort
public void setFirstMappedPort(int port) -
containerIsStarting
protected void containerIsStarting(com.github.dockerjava.api.command.InspectContainerResponse containerInfo) - Overrides:
containerIsStartingin classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
doStart
protected void doStart()- Overrides:
doStartin classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
isCreated
public boolean isCreated() -
isHealthy
public boolean isHealthy() -
isRunning
public boolean isRunning() -
getContainerIpAddress
-
getMappedPort
-
setExposedPorts
- Specified by:
setExposedPortsin interfaceorg.testcontainers.containers.Container<ApplicationContainer>- Overrides:
setExposedPortsin classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
withHttpPort
- Parameters:
httpPort- The HTTP port used for the ApplicationContainer. This will set the port used to construct the base application URL for all injectedRESTClients as well as the port used to determine container readiness (unless specified otherwise inwithReadinessPath(String, int, Integer)- Returns:
- the current instance
-
withAppContextRoot
- Parameters:
appContextRoot- the application context root. The protocol, hostname, and port do not need to be included in theappContextRootparameter. For example, an application "foo.war" is available athttp://localhost:8080/foo/the context root can be set usingwithAppContextRoot("/foo")Setting the app context root effectsgetApplicationURL()which in turn effects the base URL of all injectedRESTClients.- Returns:
- the current instance
-
withReadinessPath
Sets the path to be used to determine container readiness. The readiness check will timeout after a sensible amount of time has elapsed. If unspecified, the readiness path with defailt to the application context root- Parameters:
readinessUrl- The HTTP endpoint to be polled for readiness. Once the endpoint returns HTTP 200 (OK), the container is considered to be ready.- Returns:
- the current instance
-
withReadinessPath
Sets the path to be used to determine container readiness. The readiness check will timeout after a sensible amount of time has elapsed. If unspecified, the readiness path with defailt to the application context root- Parameters:
readinessUrl- The HTTP endpoint to be polled for readiness. Once the endpoint returns HTTP 200 (OK), the container is considered to be ready.timeoutSeconds- The amount of time (in seconds) to wait for the container to be ready.- Returns:
- the current instance
-
withReadinessPath
public ApplicationContainer withReadinessPath(String readinessUrl, int timeoutSeconds, Integer port) Sets the path to be used to determine container readiness. The readiness check will timeout after a sensible amount of time has elapsed. If unspecified, the readiness path with defailt to the application context root- Parameters:
readinessUrl- The HTTP endpoint to be polled for readiness. Once the endpoint returns HTTP 200 (OK), the container is considered to be ready.timeoutSeconds- The amount of time (in seconds) to wait for the container to be ready.port- The port that should be used for the readiness check.- Returns:
- the current instance
-
waitingFor
public ApplicationContainer waitingFor(org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy) - Specified by:
waitingForin interfaceorg.testcontainers.containers.Container<ApplicationContainer>- Overrides:
waitingForin classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
setWaitStrategy
public void setWaitStrategy(org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy) - Specified by:
setWaitStrategyin interfaceorg.testcontainers.containers.Container<ApplicationContainer>- Overrides:
setWaitStrategyin classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
withMpRestClient
Configures the application container with the supplied MicroProfile REST Client class that will reference the suppliedhostUrl- Parameters:
restClientClass- The MicroProfile REST Client interface, which must be annotated with@RegisterRestClienthostUri- The URL that therestClientClasswill act as a REST client for- Returns:
- the current instance
- Throws:
IllegalArgumentException- If the provided restClientClass is not an interface or not annotated with@RegisterRestClientIllegalArgumentException- If hostUri is not a valid URI
-
withMpRestClient
Configures the application container with the supplied MicroProfile REST Client class that will reference the suppliedhostUrl- Parameters:
restClientClass- The MicroProfile REST Client classhostUri- The URL that therestClientClasswill act as a REST client for- Returns:
- the current instance
- Throws:
IllegalArgumentException- If hostUri is not a valid URI
-
withReuse
- Overrides:
withReusein classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
withFileSystemBind
-
withFileSystemBind
public ApplicationContainer withFileSystemBind(String hostPath, String containerPath, org.testcontainers.containers.BindMode mode) - Specified by:
withFileSystemBindin interfaceorg.testcontainers.containers.Container<ApplicationContainer>- Overrides:
withFileSystemBindin classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
addFileSystemBind
-
addFileSystemBind
public void addFileSystemBind(String hostPath, String containerPath, org.testcontainers.containers.BindMode mode, org.testcontainers.containers.SelinuxContext selinuxContext) - Specified by:
addFileSystemBindin interfaceorg.testcontainers.containers.Container<ApplicationContainer>- Overrides:
addFileSystemBindin classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
getApplicationURL
- Returns:
- The URL where the application is currently running at. The application URL is comprised
of the baseURL (as defined by
getBaseURL()) concatenated with the appContextRoot (as defined bywithAppContextRoot(String). This will be the base URL for all injectedRESTClients
-
getBaseURL
- Returns:
- The base URL of the application container. For example, if the application is running on
'localhost' on port 8080 (inside the container), port 8080 inside of the container will be mapped
to a random external port (usually in the 32XXX range). The base URL would be something like:
http://<container-ip-address>:<mapped-port>
-
getContainerInfo
public com.github.dockerjava.api.command.InspectContainerResponse getContainerInfo()- Specified by:
getContainerInfoin interfaceorg.testcontainers.containers.ContainerState- Overrides:
getContainerInfoin classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
getDockerImageName
- Specified by:
getDockerImageNamein interfaceorg.testcontainers.containers.Container<ApplicationContainer>- Overrides:
getDockerImageNamein classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
getServerAdapter
- Returns:
- The
ServerAdapterthat is currently applied for this instance
-
toStringSimple
-