Class ApplicationContainer
- java.lang.Object
-
- org.testcontainers.containers.FailureDetectingExternalResource
-
- org.testcontainers.containers.GenericContainer<ApplicationContainer>
-
- org.microshed.testing.testcontainers.ApplicationContainer
-
- All Implemented Interfaces:
java.lang.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.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringMP_HEALTH_READINESS_PATHA path representing the MicroProfile Health 2.0 readiness check
-
Constructor Summary
Constructors Constructor Description ApplicationContainer()Builds an instance based on a Dockerfile located atApplicationContainer(java.lang.String dockerImageName)Builds an instance based on an existing docker image.ApplicationContainer(java.nio.file.Path dockerfilePath)Builds an instance using the supplied Dockerfile pathApplicationContainer(java.util.concurrent.Future<java.lang.String> dockerImageName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidconfigure()protected voidcontainerIsStarting(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)protected voiddoStart()java.lang.StringgetApplicationURL()java.lang.StringgetBaseURL()com.github.dockerjava.api.command.InspectContainerResponsegetContainerInfo()java.lang.StringgetContainerIpAddress()java.lang.StringgetDockerImageName()java.lang.IntegergetMappedPort(int originalPort)ServerAdaptergetServerAdapter()booleanisCreated()booleanisHealthy()booleanisRunning()voidsetContainerIpAddress(java.lang.String ipAddress)voidsetExposedPorts(java.util.List<java.lang.Integer> exposedPorts)voidsetFirstMappedPort(int port)voidsetWaitStrategy(org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy)java.lang.StringtoStringSimple()ApplicationContainerwaitingFor(org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy)ApplicationContainerwithAppContextRoot(java.lang.String appContextRoot)ApplicationContainerwithHttpPort(int httpPort)ApplicationContainerwithMpRestClient(java.lang.Class<?> restClientClass, java.lang.String hostUri)Configures the application container with the supplied MicroProfile REST Client class that will reference the suppliedhostUrlApplicationContainerwithMpRestClient(java.lang.String restClientClass, java.lang.String hostUri)Configures the application container with the supplied MicroProfile REST Client class that will reference the suppliedhostUrlApplicationContainerwithReadinessPath(java.lang.String readinessUrl)Sets the path to be used to determine container readiness.ApplicationContainerwithReadinessPath(java.lang.String readinessUrl, int timeoutSeconds)Sets the path to be used to determine container readiness.ApplicationContainerwithReadinessPath(java.lang.String readinessUrl, int timeoutSeconds, java.lang.Integer port)Sets the path to be used to determine container readiness.ApplicationContainerwithReuse(boolean reusable)-
Methods inherited from class org.testcontainers.containers.GenericContainer
addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, apply, canBeReused, containerIsCreated, containerIsStarted, containerIsStarted, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, equals, failed, fetchDockerDaemonInfo, finished, getBinds, getCommandParts, getContainerId, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerDaemonInfo, 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, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExtraHosts, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWorkingDirectory, start, starting, stop, succeeded, toString, waitUntilContainerStarted, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectory
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.testcontainers.containers.Container
addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBind
-
-
-
-
Field Detail
-
MP_HEALTH_READINESS_PATH
public static final java.lang.String MP_HEALTH_READINESS_PATH
A path representing the MicroProfile Health 2.0 readiness check- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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
public ApplicationContainer(java.nio.file.Path dockerfilePath)
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
public ApplicationContainer(java.util.concurrent.Future<java.lang.String> dockerImageName)
-
ApplicationContainer
public ApplicationContainer(java.lang.String dockerImageName)
Builds an instance based on an existing docker image.- Parameters:
dockerImageName- The docker image to be used for this instance
-
-
Method Detail
-
configure
protected void configure()
- Overrides:
configurein classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
setContainerIpAddress
public void setContainerIpAddress(java.lang.String ipAddress)
-
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
public java.lang.String getContainerIpAddress()
-
getMappedPort
public java.lang.Integer getMappedPort(int originalPort)
-
setExposedPorts
public void setExposedPorts(java.util.List<java.lang.Integer> exposedPorts)
- Specified by:
setExposedPortsin interfaceorg.testcontainers.containers.Container<ApplicationContainer>- Overrides:
setExposedPortsin classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
withHttpPort
public ApplicationContainer withHttpPort(int httpPort)
- 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
public ApplicationContainer withAppContextRoot(java.lang.String appContextRoot)
- 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
public ApplicationContainer withReadinessPath(java.lang.String readinessUrl)
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
public ApplicationContainer withReadinessPath(java.lang.String readinessUrl, int timeoutSeconds)
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(java.lang.String readinessUrl, int timeoutSeconds, java.lang.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
public ApplicationContainer withMpRestClient(java.lang.Class<?> restClientClass, java.lang.String hostUri)
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:
java.lang.IllegalArgumentException- If the provided restClientClass is not an interface or not annotated with@RegisterRestClientjava.lang.IllegalArgumentException- If hostUri is not a valid URI
-
withMpRestClient
public ApplicationContainer withMpRestClient(java.lang.String restClientClass, java.lang.String hostUri)
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:
java.lang.IllegalArgumentException- If hostUri is not a valid URI
-
withReuse
public ApplicationContainer withReuse(boolean reusable)
- Overrides:
withReusein classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
getApplicationURL
public java.lang.String 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
public java.lang.String 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
public java.lang.String getDockerImageName()
- Specified by:
getDockerImageNamein interfaceorg.testcontainers.containers.Container<ApplicationContainer>- Overrides:
getDockerImageNamein classorg.testcontainers.containers.GenericContainer<ApplicationContainer>
-
getServerAdapter
public ServerAdapter getServerAdapter()
- Returns:
- The
ServerAdapterthat is currently applied for this instance
-
toStringSimple
public java.lang.String toStringSimple()
-
-